From d716514c0c73914b519e1dc1d1a70c7d659dde34 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:16:31 +0500 Subject: [PATCH] #571 WIP: Change colors --- src/netxs/desktopio/canvas.hpp | 16 +++++++++++++++- src/netxs/desktopio/gui.h | 19 +++++++++++++++---- src/netxs/desktopio/system.hpp | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/netxs/desktopio/canvas.hpp b/src/netxs/desktopio/canvas.hpp index fa3252cca1..987073a737 100644 --- a/src/netxs/desktopio/canvas.hpp +++ b/src/netxs/desktopio/canvas.hpp @@ -191,9 +191,15 @@ namespace netxs return chan.a && chan.a != 0xFF; } // argb: Set alpha channel. - void alpha(si32 k) + auto& alpha(si32 k) { chan.a = (byte)k; + return *this; + } + auto& alpha(fp32 k) + { + chan.a = (byte)std::clamp(k * 255.f, 0.f, 255.f); + return *this; } // argb: Return alpha channel. auto alpha() const @@ -298,6 +304,14 @@ namespace netxs (c2.chan.b * level + c1.chan.b * inverse) >> 8, (c2.chan.a * level + c1.chan.a * inverse) >> 8 }; } + static auto transit(argb c1, argb c2, fp32 level) + { + auto inverse = 1.f - level; + return argb{ (byte)std::clamp(c2.chan.r * level + c1.chan.r * inverse, 0.f, 255.f), + (byte)std::clamp(c2.chan.g * level + c1.chan.g * inverse, 0.f, 255.f), + (byte)std::clamp(c2.chan.b * level + c1.chan.b * inverse, 0.f, 255.f), + (byte)std::clamp(c2.chan.a * level + c1.chan.a * inverse, 0.f, 255.f) }; + } // argb: Alpha blending ARGB colors. void inline mix(argb c, si32 alpha) { diff --git a/src/netxs/desktopio/gui.h b/src/netxs/desktopio/gui.h index 6141c93e1e..9ad9e214c0 100644 --- a/src/netxs/desktopio/gui.h +++ b/src/netxs/desktopio/gui.h @@ -582,12 +582,23 @@ namespace netxs::gui //auto fx_black = [](auto& c){ c = 0xFF'00'00'00; }; //auto fx_blue = [](auto& c){ c = 0xFF'00'00'7f; }; canvas.step(-inner_rect.coor); + auto rtc = argb{ tint::pureblue }.alpha(0.5f); + auto ltc = argb{ tint::pureblack }; + auto rbc = argb{ tint::pureblack }; + auto lbc = argb{ tint::pureblue }.alpha(0.5f); for (c.coor.y = 0; c.coor.y < inner_rect.size.y; c.coor.y += cell_size.y) - for (c.coor.x = 0; c.coor.x < inner_rect.size.x; c.coor.x += cell_size.x) { - netxs::onrect(canvas, c, fx_blue); - netxs::misc::cage(canvas, c, lt, fx_white2); - netxs::misc::cage(canvas, c, rb, fx_black2); + auto y = (fp32)c.coor.y / (inner_rect.size.y - 1); + auto lc = argb::transit(ltc, lbc, y); + auto rc = argb::transit(rtc, rbc, y); + for (c.coor.x = 0; c.coor.x < inner_rect.size.x; c.coor.x += cell_size.x) + { + auto x = (fp32)c.coor.x / (inner_rect.size.x - 1); + auto p = argb::transit(lc, rc, x); + netxs::onrect(canvas, c, [&](auto& c){ c = p; }); + //netxs::misc::cage(canvas, c, lt, fx_white2); + //netxs::misc::cage(canvas, c, rb, fx_black2); + } } //auto c1 = rect{ dot_00, inner_rect.size - dent{ 0, inner_rect.size.x / 2, 0, 0 }}; diff --git a/src/netxs/desktopio/system.hpp b/src/netxs/desktopio/system.hpp index 8a70a01810..cd274b995f 100644 --- a/src/netxs/desktopio/system.hpp +++ b/src/netxs/desktopio/system.hpp @@ -5734,7 +5734,7 @@ namespace netxs::os { #if defined(WIN32) using window = gui::window; - if (auto w = window{{{ 200, 200 }, { 40, 10 }}, { 11, 22 }}) + if (auto w = window{{{ 200, 200 }, { 80, 20 }}, { 11, 22 }}) { w.show(); w.dispatch();