Skip to content

Commit

Permalink
directvt#400 WIP: Shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Oct 24, 2023
1 parent 41b54f5 commit 9b72306
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 94 deletions.
26 changes: 10 additions & 16 deletions src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<pro::notes>(" Close application window ")
->shader(cell::shaders::color(c1), e2::form::state::mouse)
->setpad({ 2, 2, tall, tall })
->template plugin<pro::notes>(" Close application window ")
->invoke([&](auto& boss)
{
auto data_src_shadow = ptr::shadow(data_src);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<pro::notes>(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.
Expand Down Expand Up @@ -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<pro::notes>(" 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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<pro::notes>(" 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<pro::timer>()
->plugin<pro::acryl>(menu_bg_color)
->plugin<pro::acryl>(10)
->plugin<pro::cache>()
->active(menu_bg_color)
->invoke([&](auto& boss)
{
boss.mouse.template draggable<hids::buttons::left>(true);
Expand Down Expand Up @@ -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<pro::notes>(" Show/hide user list ")
->setpad({ 2, 2, tall, tall });
auto userlist_area = users_area->attach(ui::cake::ctor())
Expand Down
30 changes: 13 additions & 17 deletions src/netxs/desktopio/baseui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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); });
}
};
}
};
}
49 changes: 22 additions & 27 deletions src/netxs/desktopio/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1640,6 +1629,11 @@ namespace netxs
template<class C> constexpr inline auto operator () (C brush) const { return func<C>(brush); }
template<class D, class S> inline void operator () (D& dst, S& src) const { dst.fuse(src); }
};
struct fuseid_t : public brush_t<fuseid_t>
{
template<class C> constexpr inline auto operator () (C brush) const { return func<C>(brush); }
template<class D, class S> inline void operator () (D& dst, S& src) const { dst.fuseid(src); }
};
struct fusefull_t : public brush_t<fusefull_t>
{
template<class C> constexpr inline auto operator () (C brush) const { return func<C>(brush); }
Expand Down Expand Up @@ -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<class D>
inline void operator () (D& dst) const
{
dst.link(newid);
dst.link(id);
}
template<class D, class S>
inline void operator () (D& dst, S& src) const
{
dst.fuse(src, newid);
dst.fuse(src, id);
}
};

Expand All @@ -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{};
Expand Down
50 changes: 18 additions & 32 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
}
};
Expand Down Expand Up @@ -2308,32 +2304,15 @@ namespace netxs::ui
return backup;
}
// form: Fill object region using parametrized fx.
template<bool Postrender = faux, tier Tier = tier::release, class Fx, class Event = noop, bool fixed = std::is_same_v<Event, noop>>
template<auto RenderOrder = e2::render::prerender, tier Tier = tier::release, class Fx, class Event = noop, bool fixed = std::is_same_v<Event, noop>>
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
{
Expand All @@ -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();
}
Expand All @@ -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<class S, class ...Args>
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9b72306

Please sign in to comment.