From 9b72306b670c169cdf2c6e7b3f9b47600e17c2e5 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com> Date: Tue, 24 Oct 2023 19:25:52 +0500 Subject: [PATCH] #400 WIP: Shaders --- src/netxs/apps/desk.hpp | 26 +++++++---------- src/netxs/desktopio/baseui.hpp | 30 +++++++++---------- src/netxs/desktopio/canvas.hpp | 49 ++++++++++++++----------------- src/netxs/desktopio/controls.hpp | 50 ++++++++++++-------------------- src/netxs/desktopio/terminal.hpp | 2 +- src/vtm.xml | 2 +- 6 files changed, 65 insertions(+), 94 deletions(-) diff --git a/src/netxs/apps/desk.hpp b/src/netxs/apps/desk.hpp index 626d9ff20..e627196ef 100644 --- a/src/netxs/apps/desk.hpp +++ b/src/netxs/apps/desk.hpp @@ -68,7 +68,7 @@ namespace netxs::app::desk auto tall = si32{ skin::globals().menuwide }; auto danger_color = skin::globals().danger; auto highlight_color = skin::globals().highlight; - auto c5 = danger_color; + auto c1 = danger_color; auto fastfader = skin::globals().fader_fast; auto fader = skin::globals().fader_time; auto item_area = ui::fork::ctor() @@ -144,9 +144,9 @@ namespace netxs::app::desk ->drawdots(); auto app_close = item_area->attach(slot::_2, ui::item::ctor("×")) ->active() - ->shader(cell::shaders::color(c5), e2::form::state::mouse) - ->template plugin(" Close application window ") + ->shader(cell::shaders::color(c1), e2::form::state::mouse) ->setpad({ 2, 2, tall, tall }) + ->template plugin(" Close application window ") ->invoke([&](auto& boss) { auto data_src_shadow = ptr::shadow(data_src); @@ -177,12 +177,10 @@ namespace netxs::app::desk auto highlight_color = skin::globals().highlight; auto inactive_color = skin::globals().inactive; auto selected_color = skin::globals().selected; - auto action_color = skin::globals().action; auto danger_color = skin::globals().danger; auto c3 = highlight_color; auto c9 = selected_color; auto cA = inactive_color; - auto c6 = action_color; auto c1 = danger_color; auto apps = ui::list::ctor() @@ -215,14 +213,13 @@ namespace netxs::app::desk auto item_area = apps->attach(ui::item::ctor(obj_desc)) ->flexible() ->accented() - ->shader(cell::shaders::color(cA)) + ->colors(cA.fgc(), cA.bgc()) ->setpad({ 0, 0, tall, tall }, { 0, 0, -tall, 0 }) ->template plugin(obj_note); continue; } auto head_fork = ui::fork::ctor(axis::X, 0, 1, 0); auto block = apps->attach(ui::list::ctor()) - ->active() ->shader(cell::shaders::xlight, e2::form::state::mouse, head_fork) ->setpad({ 0, 0, 0, 0 }, { 0, 0, -tall, 0 }); if (!state) block->depend_on_collection(inst_ptr_list); // Remove not pinned apps, like Info/About. @@ -294,9 +291,9 @@ namespace netxs::app::desk auto fold_bttn = bttn_fork->attach(slot::_1, ui::item::ctor(isfolded ? "…" : "<")) ->setpad({ 2, 2, tall, tall }) ->active() - ->shader(cell::shaders::color(c6), e2::form::state::mouse) + ->shader(cell::shaders::xlight, e2::form::state::mouse) ->template plugin(" Hide active window list. \n" - " Use mouse wheel to switch it to close. ") + " Use mouse wheel to switch it to close. ") ->invoke([&](auto& boss) { insts->base::hidden = isfolded; @@ -429,13 +426,11 @@ namespace netxs::app::desk { auto tall = si32{ skin::globals().menuwide }; auto highlight_color = skin::globals().highlight; - auto action_color = skin::globals().action; auto inactive_color = skin::globals().inactive; auto warning_color = skin::globals().warning; auto danger_color = skin::globals().danger; auto cA = inactive_color; auto c3 = highlight_color; - auto c6 = action_color; auto c2 = warning_color; auto c1 = danger_color; @@ -488,7 +483,6 @@ namespace netxs::app::desk auto tall = si32{ skin::globals().menuwide }; auto highlight_color = skin::color(tone::highlight); auto c3 = highlight_color; - auto x3 = cell{ c3 }.alpha(0x00); auto user = ui::item::ctor(escx(" &").nil().add(" ") //.link(data_src->id).fgx(data_src->id == my_id ? rgba::vt256[whitelt] : 0x00).add(utf8).nil(), true)); .fgx(data_src->id == my_id ? rgba::vt256[whitelt] : 0x00).add(utf8).nil()) @@ -563,14 +557,14 @@ namespace netxs::app::desk }; }); auto taskbar_park = taskbar_viewport->attach(slot::_1, ui::cake::ctor()) - ->active() ->limits({ menu_min_size, -1 }, { menu_min_size, -1 }) ->plugin(" LeftDrag to adjust the taskbar width \n" " Ctrl+LeftDrag to adjust the folded taskbar width \n" " RightDrag or scroll wheel to slide the taskbar menu up/down ") ->plugin() - ->plugin(menu_bg_color) + ->plugin(10) ->plugin() + ->active(menu_bg_color) ->invoke([&](auto& boss) { boss.mouse.template draggable(true); @@ -664,13 +658,13 @@ namespace netxs::app::desk auto label = label_bttn->attach(slot::_1, ui::item::ctor("users")) ->flexible() ->accented() - ->shader(cell::shaders::color(cA)) + ->colors(cA.fgc(), cA.bgc()) ->setpad({ 0, 0, tall, tall }) ->limits({ 5, -1 }); auto userlist_hidden = true; auto bttn = label_bttn->attach(slot::_2, ui::item::ctor(userlist_hidden ? "…" : "<")) ->active() - ->shader(cell::shaders::color(c6), e2::form::state::mouse) + ->shader(cell::shaders::xlight, e2::form::state::mouse) ->plugin(" Show/hide user list ") ->setpad({ 2, 2, tall, tall }); auto userlist_area = users_area->attach(ui::cake::ctor()) diff --git a/src/netxs/desktopio/baseui.hpp b/src/netxs/desktopio/baseui.hpp index ee9cc8755..3cc69b0ec 100644 --- a/src/netxs/desktopio/baseui.hpp +++ b/src/netxs/desktopio/baseui.hpp @@ -590,10 +590,7 @@ namespace netxs::ui subs relyon; // base: Subscription on parent events. rect region; // base: The region occupied by the object. rect socket; // base: The region provided for the object. - - //todo deprecated cell filler; // base: Object color. - twod min_sz; // base: Minimal size. twod max_sz; // base: Maximal size. twod anchor; // base: Object balance point. Center point for any transform (on preview). @@ -628,23 +625,19 @@ namespace netxs::ui if constexpr (Absolute) area.coor += region.coor; return area; } - auto color() const { return filler; } + auto color() const { return base::filler; } void color(rgba fg_color, rgba bg_color) { - // To make an object transparent to mouse events, - // no id (cell::id = 0) is used by default in the filler. - // The bell::id is configurable only with pro::mouse. base::filler.bgc(bg_color) .fgc(fg_color) .txt(whitespace); SIGNAL(tier::release, e2::form::prop::filler, filler); } - void color(cell const& new_filler) + void color(cell const& new_filler) // Set id=0 to make the object transparent to mouse events. { base::filler = new_filler; SIGNAL(tier::release, e2::form::prop::filler, filler); } - // base: Align object. void xform(snap atcrop, snap atgrow, si32& coor, si32& size, si32& width) { @@ -998,14 +991,17 @@ namespace netxs::ui } if (parent_ptr) parent_ptr->base::reflow(); //todo too expensive. ? accumulate deferred reflow? or make it when stated? }; - //todo deprecated - //LISTEN(tier::release, e2::render::any, parent_canvas) - //{ - // if (base::filler.wdt() && !base::hidden) - // { - // parent_canvas.fill([&](cell& c) { c.fusefull(base::filler); }); - // } - //}; + LISTEN(tier::release, e2::render::any, parent_canvas) + { + if (base::filler.wdt()) + { + parent_canvas.fill([&](cell& c) { c.fusefull(base::filler); }); + } + else if (base::filler.link()) + { + parent_canvas.fill([&](cell& c) { c.link(bell::id); }); + } + }; } }; } \ No newline at end of file diff --git a/src/netxs/desktopio/canvas.hpp b/src/netxs/desktopio/canvas.hpp index 55de259a7..8b7634e3a 100644 --- a/src/netxs/desktopio/canvas.hpp +++ b/src/netxs/desktopio/canvas.hpp @@ -305,20 +305,7 @@ namespace netxs // rgba: Shift color. void xlight() { - //todo unify - if (chan.a == 0) - { - chan.a = 42; - chan.r = 0xFF; - chan.g = 0xFF; - chan.b = 0xFF; - } - else if (chan.a != 0xFF) - { - auto k = 42; - chan.a = chan.a > 0xFF - k ? 0xFF : chan.a + k; - } - else if (luma() > 140) + if (luma() > 140) { auto k = 64; chan.r = chan.r < k ? 0x00 : chan.r - k; @@ -1280,21 +1267,23 @@ namespace netxs uv.fg.mix(c.uv.fg, alpha); uv.bg.mix(c.uv.bg, alpha); } - // cell: Merge two cells and update id. + // cell: Merge two cells and set specified id. void fuse(cell const& c, id_t oid) { fuse(c); id = oid; } - // cell: Merge two cells and update ID with COOR. + // cell: Merge two cells and set id if it is. void fusefull(cell const& c) { fuse(c); if (c.id) id = c.id; - //pg = c.pg; - - //mark paragraphs - //if (c.pg) uv.param.bg.channel.blue = 0xff; + } + // cell: Merge two cells and set id. + void fuseid(cell const& c) + { + fuse(c); + id = c.id; } void meta(cell const& c) { @@ -1640,6 +1629,11 @@ namespace netxs template constexpr inline auto operator () (C brush) const { return func(brush); } template inline void operator () (D& dst, S& src) const { dst.fuse(src); } }; + struct fuseid_t : public brush_t + { + template constexpr inline auto operator () (C brush) const { return func(brush); } + template inline void operator () (D& dst, S& src) const { dst.fuseid(src); } + }; struct fusefull_t : public brush_t { template constexpr inline auto operator () (C brush) const { return func(brush); } @@ -1717,21 +1711,21 @@ namespace netxs operator()(dst); } }; - struct fullid_t + struct onlyid_t { - id_t newid; - constexpr fullid_t(id_t newid) - : newid{ newid } + id_t id; + constexpr onlyid_t(id_t id) + : id{ id } { } template inline void operator () (D& dst) const { - dst.link(newid); + dst.link(id); } template inline void operator () (D& dst, S& src) const { - dst.fuse(src, newid); + dst.fuse(src, id); } }; @@ -1740,9 +1734,10 @@ namespace netxs static constexpr auto color(T brush) { return color_t{ brush }; } static constexpr auto transparent(byte alpha) { return transparent_t{ alpha }; } static constexpr auto xlucent(byte alpha) { return xlucent_t{ alpha }; } - static constexpr auto fullid(id_t newid) { return fullid_t{ newid }; } + static constexpr auto onlyid(id_t newid) { return onlyid_t{ newid }; } static constexpr auto contrast = contrast_t{}; static constexpr auto fusefull = fusefull_t{}; + static constexpr auto fuseid = fuseid_t{}; static constexpr auto mix = mix_t{}; static constexpr auto lite = lite_t{}; static constexpr auto fuse = fuse_t{}; diff --git a/src/netxs/desktopio/controls.hpp b/src/netxs/desktopio/controls.hpp index e51a62a6e..431ec9854 100644 --- a/src/netxs/desktopio/controls.hpp +++ b/src/netxs/desktopio/controls.hpp @@ -2121,18 +2121,15 @@ namespace netxs::ui skill::memo; si32 width; // acryl: Blur radius. - cell color; // acryl: Base color. bool alive; // acryl: Is active. public: acryl(base&&) = delete; - acryl(base& boss, cell fill = {}, si32 size = 5) + acryl(base& boss, si32 size = 5) : skill{ boss }, width{ size }, - color{ fill }, alive{ true } { - color.txt(whitespace); boss.LISTEN(tier::preview, e2::form::prop::ui::acryl, state, memo) { alive = state; @@ -2143,9 +2140,8 @@ namespace netxs::ui }; boss.LISTEN(tier::release, e2::render::prerender, parent_canvas, memo) { - if (!alive) return; - if (color.set()) parent_canvas.blur(width, [&](cell& c) { c.alpha(0xFF).fuse(color); }); - else parent_canvas.blur(width, [&](cell& c) { c.alpha(0xFF); }); + if (!alive || boss.base::filler.bga() == 0xFF) return; + parent_canvas.blur(width); }; } }; @@ -2308,32 +2304,15 @@ namespace netxs::ui return backup; } // form: Fill object region using parametrized fx. - template> + template> auto shader(Fx&& fx, Event sync = {}, sptr source_ptr = {}) { - auto apply = [&](auto& param) - { - if constexpr (Postrender) - { - LISTEN(tier::release, e2::postrender, parent_canvas, -, (fx)) - { - if (fixed || param) - parent_canvas.fill(fx); - }; - } - else - { - LISTEN(tier::release, e2::render::prerender, parent_canvas, -, (fx)) - { - if (fixed || param) - parent_canvas.fill(fx); - }; - } - }; if constexpr (fixed) { - auto never_checked = true; - apply(never_checked); + LISTEN(tier::release, RenderOrder, parent_canvas, -, (fx)) + { + parent_canvas.fill(fx); + }; } else { @@ -2346,7 +2325,10 @@ namespace netxs::ui param = new_value; base::deface(); }; - apply(param); + LISTEN(tier::release, RenderOrder, parent_canvas, -, (fx)) + { + if (param) parent_canvas.fill(fx); + }; } return This(); } @@ -2365,10 +2347,14 @@ namespace netxs::ui return This(); } // form: Set the form visible for mouse. + auto active(cell brush) + { + base::color(brush.txt(whitespace).link(bell::id)); + return This(); + } auto active() { - auto fx = cell::shaders::fullid(bell::id); - return shader(fx); + return active(base::color()); } // form: Return plugin reference of specified type. Add the specified plugin (using specified args) if it is missing. template diff --git a/src/netxs/desktopio/terminal.hpp b/src/netxs/desktopio/terminal.hpp index 73c85f4db..5f65794a2 100644 --- a/src/netxs/desktopio/terminal.hpp +++ b/src/netxs/desktopio/terminal.hpp @@ -7841,7 +7841,7 @@ namespace netxs::ui if (auto parent = base::parent()) parent_id = parent->id; if (canvas.size()) { - splash.zoom(canvas, cell::shaders::fullid(parent_id)); + splash.zoom(canvas, cell::shaders::onlyid(parent_id)); splash.output(errmsg); splash.blur(2, [](cell& c) { c.fgc(rgba::transit(c.bgc(), c.fgc(), 127)); }); splash.output(errmsg); diff --git a/src/vtm.xml b/src/vtm.xml index 3a531d3b4..847f16b3f 100644 --- a/src/vtm.xml +++ b/src/vtm.xml @@ -146,7 +146,7 @@ R"==( - +