Skip to content

Commit

Permalink
directvt#571 WIP: Change colors
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Apr 18, 2024
1 parent 98edd48 commit d716514
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/netxs/desktopio/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down
19 changes: 15 additions & 4 deletions src/netxs/desktopio/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }};
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5734,7 +5734,7 @@ namespace netxs::os
{
#if defined(WIN32)
using window = gui::window<gui::w32renderer>;
if (auto w = window{{{ 200, 200 }, { 40, 10 }}, { 11, 22 }})
if (auto w = window{{{ 200, 200 }, { 80, 20 }}, { 11, 22 }})
{
w.show();
w.dispatch();
Expand Down

0 comments on commit d716514

Please sign in to comment.