Skip to content

Commit

Permalink
directvt#393 WIP: Revise ui::form::plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Jan 3, 2025
1 parent 580b6cc commit 9f1ec0b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ namespace netxs::app::desk
->invoke([&](auto& boss)
{
auto drag_origin = ptr::shared<fp2d>();
boss.mouse.template draggable<hids::buttons::left>(true);
auto& mouse = boss.template plugins<pro::mouse>();
mouse.template draggable<hids::buttons::left>(true);
boss.LISTEN(tier::release, e2::form::drag::start::_<hids::buttons::left>, gear, -, (drag_origin))
{
*drag_origin = gear.coord;
Expand Down
16 changes: 7 additions & 9 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ namespace netxs::ui
debug_t debug; // gate: Statistics monitor.
//todo
//pro::focus focus; // gate: Focus controller.
pro::keybd keybd; // gate: Keyboard controller.
diff paint; // gate: Render.
link conio; // gate: Input data parser.
bool direct; // gate: .
Expand Down Expand Up @@ -1118,7 +1117,6 @@ namespace netxs::ui
input{ props, *this },
debug{*this },
//focus{*this },
keybd{*this, "gate" },
paint{ canal, props.vtmode },
conio{ canal, *this },
direct{ !!(vtmode & (ui::console::direct | ui::console::gui)) },
Expand All @@ -1128,6 +1126,8 @@ namespace netxs::ui
{
//todo scripting
//keybd.proc("ToggleDebugOverlay", [&](hids& gear){ gear.set_handled(); debug ? debug.stop() : debug.start(); });
auto& keybd = plugins<pro::keybd>("gate");
auto& mouse = plugins<pro::mouse>();
auto bindings = pro::keybd::load(config, "tui"); //todo -> pro::keybd("gate")
keybd.bind(bindings);

Expand Down Expand Up @@ -1436,10 +1436,6 @@ namespace netxs::ui
public:
using tick = datetime::quartz<bell, tier::general, e2::timer::tick.id>;

pro::focus focus; // host: Focus controller. Must be the first of all focus subscriptions.
//todo scripting: process gui keybd events
pro::keybd keybd; // host: Keybd controller.

tick quartz; // host: Frame rate synchronizator.
si32 maxfps; // host: Frame rate.
regs debris; // host: Wrecked regions.
Expand All @@ -1450,12 +1446,13 @@ namespace netxs::ui
std::vector<bool> user_numbering; // host: .

host(xipc server, xmls config, si32 focus_type = pro::focus::mode::hub)
: focus{ *this, focus_type, faux },
keybd{ *this, "vtm" },
quartz{ *this },
: quartz{ *this },
config{ config },
active{ true }
{
plugins<pro::focus>(focus_type, faux);
plugins<pro::keybd>("vtm");

using namespace std::chrono;
auto& canal = *server;

Expand Down Expand Up @@ -1731,6 +1728,7 @@ namespace netxs::ui
void stop()
{
auto lock = bell::sync();
auto& mouse = plugins<pro::mouse>();
mouse.reset();
tokens.reset();
}
Expand Down
37 changes: 18 additions & 19 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,13 +2657,6 @@ namespace netxs::ui
std::map<id_t, subs> memomap; // form: Token set for dependent subscriptions.

public:
pro::mouse mouse{ *this }; // form: Mouse controller.
//pro::keybd keybd{ *this }; // form: Keybd controller.

form(size_t nested_count = 0)
: base{ ui::tui_domain(), nested_count }
{ }

auto This() { return base::This<T>(); }
template<class TT = T, class ...Args>
static auto ctor(Args&&... args)
Expand All @@ -2687,6 +2680,18 @@ namespace netxs::ui
depo.erase(std::type_index(typeid(S)));
return backup;
}
// form: Return plugin reference of specified type. Add the specified plugin (using specified args) if it is missing.
template<class S, class ...Args>
auto& plugins(Args&&... args)
{
auto it = depo.find(std::type_index(typeid(S)));
if (it == depo.end())
{
it = depo.emplace(std::type_index(typeid(S)), std::make_unique<S>(*this, std::forward<Args>(args)...)).first;
}
auto ptr = static_cast<S*>(it->second.get());
return *ptr;
}
// form: Fill object region using parametrized fx.
template<auto Tier = tier::release, auto RenderOrder = e2::render::background::any, class Fx, class Event = noop, bool fixed = std::is_same_v<Event, noop>>
auto shader(Fx&& fx, Event sync = {}, sptr source_ptr = {}, netxs::sptr<subs> tokens_ptr = {})
Expand Down Expand Up @@ -2749,18 +2754,6 @@ namespace netxs::ui
{
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>
auto& plugins(Args&&... args)
{
const auto it = depo.find(std::type_index(typeid(S)));
if (it == depo.end())
{
plugin<S>(std::forward<Args>(args)...);
}
auto ptr = static_cast<S*>(depo[std::type_index(typeid(S))].get());
return *ptr;
}
// form: Invoke arbitrary functor(itself/*This/boss) in place.
template<class P>
auto invoke(P functor)
Expand Down Expand Up @@ -2884,6 +2877,12 @@ namespace netxs::ui
auto context = parent_canvas.change_basis(basis, true);
return context;
}

form(size_t nested_count = 0)
: base{ ui::tui_domain(), nested_count }
{
plugins<pro::mouse>();
}
};

// controls: Splitter.
Expand Down
10 changes: 7 additions & 3 deletions src/vtm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,14 @@ namespace netxs::app::vtm

gate(xipc uplink, view userid, si32 vtmode, xmls& config, si32 session_id)
: ui::gate{ uplink, vtmode, config, userid, session_id, true },
tooltip{*this, ansi::add(prompt::gate, props.title) }
tooltip{ *this, ansi::add(prompt::gate, props.title) }
{
//todo local=>nexthop
local = faux;
//todo scripting
//keybd.proc("RunScript", [&](hids& gear){ base::riseup(tier::preview, e2::form::proceed::action::runscript, gear); });
auto& keybd = plugins<pro::keybd>();
auto& mouse = plugins<pro::mouse>();
auto bindings = pro::keybd::load(config, "desktop");
keybd.bind(bindings);

Expand Down Expand Up @@ -1287,6 +1289,7 @@ namespace netxs::app::vtm
->limits(dot_11)
->invoke([&](auto& boss)
{
auto& mouse = boss.template plugins<pro::mouse>();
auto& keybd = boss.template plugins<pro::keybd>();
keybd.bind(window_bindings);

Expand Down Expand Up @@ -1456,7 +1459,7 @@ namespace netxs::app::vtm
};
boss.LISTEN(tier::release, e2::form::proceed::quit::any, fast)
{
boss.mouse.reset();
mouse.reset();
boss.base::detach(); // The object kills itself.
};
boss.LISTEN(tier::general, e2::conio::quit, deal) // Desktop shutdown.
Expand Down Expand Up @@ -2537,7 +2540,8 @@ namespace netxs::app::vtm
bell::dequeue(); // Wait until all cleanups are completed.
host::quartz.stop();
auto lock = bell::sync();
host::mouse.reset(); // Release the captured mouse.
auto& mouse = plugins<pro::mouse>();
mouse.reset(); // Release the captured mouse.
host::tokens.reset();
dbase.reset();
items.reset();
Expand Down

0 comments on commit 9f1ec0b

Please sign in to comment.