Skip to content

Commit

Permalink
directvt#571 WIP: Make mouse coords fp32 (pixel-wise)
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Apr 23, 2024
1 parent 1ddffac commit cc84bb2
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 157 deletions.
30 changes: 23 additions & 7 deletions src/netxs/apps/desk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,33 @@ namespace netxs::app::desk
->active()
->invoke([&](auto& boss)
{
auto drag_origin = ptr::shared<fp2d>();
boss.mouse.template draggable<hids::buttons::left>(true);
boss.LISTEN(tier::release, e2::form::drag::pull::_<hids::buttons::left>, gear)
boss.LISTEN(tier::release, e2::form::drag::start::_<hids::buttons::left>, gear, -, (drag_origin))
{
*drag_origin = gear.coord;
};
boss.LISTEN(tier::release, e2::form::drag::pull::_<hids::buttons::left>, gear, -, (drag_origin))
{
if (auto taskbar_grips = boss.base::parent())
{
auto delta = twod{ gear.delta.get() };
taskbar_grips->base::min_sz.x = std::max(1, taskbar_grips->base::min_sz.x + delta.x);
taskbar_grips->base::max_sz.x = taskbar_grips->base::min_sz.x;
active ? menu_max_size = taskbar_grips->base::min_sz.x
: menu_min_size = taskbar_grips->base::min_sz.x;
taskbar_grips->base::reflow();

//todo fp2d
//auto delta = twod{ gear.delta.get() };
//taskbar_grips->base::min_sz.x = std::max(1, taskbar_grips->base::min_sz.x + delta.x);
//taskbar_grips->base::max_sz.x = taskbar_grips->base::min_sz.x;
//active ? menu_max_size = taskbar_grips->base::min_sz.x
// : menu_min_size = taskbar_grips->base::min_sz.x;
//taskbar_grips->base::reflow();

if (auto delta = twod{ gear.coord - *drag_origin }[axis::X])
{
taskbar_grips->base::min_sz.x = std::max(1, taskbar_grips->base::min_sz.x + delta);
taskbar_grips->base::max_sz.x = taskbar_grips->base::min_sz.x;
active ? menu_max_size = taskbar_grips->base::min_sz.x
: menu_min_size = taskbar_grips->base::min_sz.x;
taskbar_grips->base::reflow();
}
}
};
boss.LISTEN(tier::release, events::ui::sync, state)
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/apps/tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace netxs::app::tile
master.RISEUP(tier::request, e2::config::creator, world_ptr, ());

// Take coor and detach from the tiling wm.
gear.coord -= applet.base::coor(); // Localize mouse coor.
gear.coord -= applet.base::coor(); // Rebase mouse coor.
what.square.size = applet.base::size();
applet.global(what.square.coor);
what.square.coor = -what.square.coor;
Expand Down
4 changes: 2 additions & 2 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ namespace netxs::ui
{
auto& gear = *gear_ptr;
if (gear.disabled) continue;
auto coor = gear.coord;
auto coor = twod{ gear.coord };
coor.y -= 1;
coor.x -= half_x;
header.move(coor);
Expand Down Expand Up @@ -850,7 +850,7 @@ namespace netxs::ui
props.clip_preview_time > stamp - gear.delta.stamp());
if (gear.board::shown)
{
auto coor = gear.coord + dot_21 * 2;
auto coor = twod{ gear.coord } + dot_21 * 2;
auto full = gear.board::image.full();
gear.board::image.move(coor - full.coor);
canvas.plot(gear.board::image, cell::shaders::mix);
Expand Down
5 changes: 3 additions & 2 deletions src/netxs/desktopio/consrv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,12 @@ struct impl : consrv
}
}
mstate = bttns;
if (gear.m_sys.wheeldt)
auto wheeldt = netxs::saturate_cast<si32>(gear.m_sys.wheeldt);
if (wheeldt)
{
if (gear.m_sys.wheeled) flags |= MOUSE_WHEELED;
else if (gear.m_sys.hzwheel) flags |= MOUSE_HWHEELED;
bttns |= gear.m_sys.wheeldt << 16;
bttns |= wheeldt << 16;
}
auto lock = std::lock_guard{ locker };
stream.emplace_back(INPUT_RECORD
Expand Down
88 changes: 66 additions & 22 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace netxs::ui
};
};

// pro: Resizing by dragging support.
// pro: Resizer.
class sizer
: public skill
{
Expand Down Expand Up @@ -277,18 +277,26 @@ namespace netxs::ui
{
struct sock
{
twod origin; // sock: Grab's initial coord info.
void grab(base const& master, twod curpos)
fp2d drag_origin; // sock: Drag origin.
void grab(base const& master, fp2d coord)
{
auto center = master.base::size() / 2;
origin = curpos - center;
drag_origin = coord - center;
}
void drag(base& master, twod coord)
auto drag(base& master, fp2d coord)
{
auto delta = coord - origin;
auto delta = coord - drag_origin;
auto center = master.base::size() / 2;
delta -= center;
master.base::moveby(delta);
//todo fp2d
//master.base::moveby(delta);
auto step = twod{ delta };
if (step)
{
drag_origin = coord - center;
master.base::moveby(step);
}
return step;
}
};

Expand Down Expand Up @@ -329,9 +337,14 @@ namespace netxs::ui
{
if (dest_object)
{
items.take(gear).drag(*dest_object, gear.coord);
auto delta = gear.delta.get();
dest_object->SIGNAL(tier::preview, e2::form::upon::changed, delta);
//todo fp2d
//items.take(gear).drag(*dest_object, gear.coord);
//auto delta = gear.delta.get();
//dest_object->SIGNAL(tier::preview, e2::form::upon::changed, delta);
if (auto delta = items.take(gear).drag(*dest_object, gear.coord))
{
dest_object->SIGNAL(tier::preview, e2::form::upon::changed, delta);
}
gear.dismiss();
}
};
Expand Down Expand Up @@ -3047,6 +3060,7 @@ namespace netxs::ui
bool animat; // rail: Smooth scrolling.
subs fasten; // rail: Subscriptions on masters to follow they state.
rack scinfo; // rail: Scroll info.
fp2d drag_origin; // rail: Drag origin.

si32 spd = skin::globals().spd;
si32 pls = skin::globals().pls;
Expand Down Expand Up @@ -3138,6 +3152,7 @@ namespace netxs::ui
{
if (gear.capture(bell::id))
{
drag_origin = gear.coord;
manual = xy(axes::all);
strict = xy(axes::all) - oversc; // !oversc = dot_11 - oversc
gear.dismiss();
Expand All @@ -3148,9 +3163,16 @@ namespace netxs::ui
{
if (gear.captured(bell::id))
{
auto delta = gear.mouse::delta.get();
auto value = permit * delta;
if (value) scroll(value);
//todo fp2d
//auto delta = gear.mouse::delta.get();
//auto value = permit * delta;
//if (value) scroll(value);
if (auto delta = twod{ gear.coord - drag_origin })
{
drag_origin = gear.coord;
auto value = permit * delta;
if (value) scroll(value);
}
gear.dismiss();
}
};
Expand Down Expand Up @@ -3316,9 +3338,16 @@ namespace netxs::ui
strict[Axis] = true;
robot.actify(Axis, std::forward<Fx>(func), [&](auto& p)
{
auto delta = Axis == X ? twod{ p, 0 }
: twod{ 0, p };
scroll(delta);
//todo fp2d
//auto delta = Axis == X ? twod{ p, 0 }
// : twod{ 0, p };
//scroll(delta);
if (auto step = netxs::saturate_cast<twod::type>(p))
{
auto delta = Axis == X ? twod{ step, 0 }
: twod{ 0, step };
scroll(delta);
}
});
}
// rail: Check overscroll if no auto correction.
Expand Down Expand Up @@ -3583,6 +3612,7 @@ namespace netxs::ui
hook memo; // grip: .
math calc; // grip: Scrollbar calculator.
bool on_pager = faux; // grip: .
fp2d drag_origin; // grip: Drag origin.

template<class Event>
void send()
Expand Down Expand Up @@ -3663,7 +3693,7 @@ namespace netxs::ui
};
LISTEN(tier::release, hids::events::mouse::move, gear)
{
calc.cursor_pos = gear.mouse::coord[Axis];
calc.cursor_pos = twod{ gear.coord }[Axis];
};
LISTEN(tier::release, hids::events::mouse::button::dblclick::left, gear)
{
Expand All @@ -3674,7 +3704,7 @@ namespace netxs::ui
if (!on_pager)
if (this->form::template protos<tier::release>(bttn::down::left)
|| this->form::template protos<tier::release>(bttn::down::right))
if (auto dir = calc.inside(gear.mouse::coord[Axis]))
if (auto dir = calc.inside(twod{ gear.coord }[Axis]))
{
if (gear.capture(bell::id))
{
Expand Down Expand Up @@ -3730,6 +3760,7 @@ namespace netxs::ui
{
if (gear.capture(bell::id))
{
drag_origin = gear.coord;
gear.dismiss();
}
}
Expand All @@ -3744,8 +3775,11 @@ namespace netxs::ui
{
if (gear.captured(bell::id))
{
if (auto delta = gear.mouse::delta.get()[Axis])
//todo fp2d
//if (auto delta = gear.mouse::delta.get()[Axis])
if (auto delta = twod{ gear.coord - drag_origin }[Axis])
{
drag_origin = gear.coord;
calc.stepby(delta);
send<upon::scroll::bycoor>();
gear.dismiss();
Expand Down Expand Up @@ -4192,6 +4226,7 @@ namespace netxs::ui
si32 max_val = 0;
si32 origin = 0;
si32 deltas = 0;
fp2d drag_origin;

//todo unify mint = 1/fps60 = 16ms
//it seems that 4ms is enough, there is no need to be tied to fps (an open question)
Expand Down Expand Up @@ -4317,6 +4352,7 @@ namespace netxs::ui
{
if (gear.capture(grip_ctl->id))
{
drag_origin = gear.coord;
origin = cur_val;
gear.dismiss();
}
Expand All @@ -4325,9 +4361,17 @@ namespace netxs::ui
{
if (gear.captured(grip_ctl->id))
{
deltas += gear.mouse::delta.get().x;
move_grip(next_val(deltas));
gear.dismiss();
//todo fp2d
//deltas += gear.mouse::delta.get().x;
//move_grip(next_val(deltas));
//gear.dismiss();
if (auto delta = twod{ gear.coord - drag_origin }.x)
{
drag_origin = gear.coord;
deltas += delta;
move_grip(next_val(deltas));
gear.dismiss();
}
}
};
grip_ctl->LISTEN(tier::release, hids::events::mouse::button::drag::cancel::left, gear)
Expand Down
4 changes: 2 additions & 2 deletions src/netxs/desktopio/directvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ namespace netxs::directvt
STRUCT_macro(frame_element, (blob, data))
STRUCT_macro(jgc_element, (ui64, token) (text, cluster))
STRUCT_macro(tooltip_element, (id_t, gear_id) (text, tip_text) (bool, update))
STRUCT_macro(mouse_event, (id_t, gear_id) (si32, ctlstat) (hint, cause) (twod, coord) (twod, delta) (si32, buttons))
STRUCT_macro(mouse_event, (id_t, gear_id) (si32, ctlstat) (hint, cause) (fp2d, coord) (fp2d, delta) (si32, buttons))
STRUCT_macro(keybd_event, (id_t, gear_id) (si32, ctlstat) (bool, extflag) (si32, virtcod) (si32, scancod) (bool, pressed) (text, cluster) (bool, handled))
//STRUCT_macro(focus, (id_t, gear_id) (bool, state) (bool, focus_combine) (bool, focus_force_group))
STRUCT_macro(focus_cut, (id_t, gear_id))
Expand Down Expand Up @@ -834,7 +834,7 @@ namespace netxs::directvt
(si32, buttons) // sysmouse: Buttons bit state.
(bool, wheeled) // sysmouse: Vertical scroll wheel.
(bool, hzwheel) // sysmouse: Horizontal scroll wheel.
(si32, wheeldt) // sysmouse: Scroll delta.
(fp32, wheeldt) // sysmouse: Scroll delta.
(fp2d, coordxy) // sysmouse: Pixel-wise cursor coordinates.
(time, timecod) // sysmouse: Event time code.
(ui32, changed)) // sysmouse: Update stamp.
Expand Down
2 changes: 1 addition & 1 deletion src/netxs/desktopio/generics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ namespace netxs
template<class M>
struct addref
{
using type = typename std::conditional<std::is_class<typename M::mapped_type>::value, typename M::mapped_type &, typename M::mapped_type>::type;
using type = typename std::conditional<std::is_class_v<typename M::mapped_type>, typename M::mapped_type &, typename M::mapped_type>::type;
};

template<class M, class K>
Expand Down
4 changes: 1 addition & 3 deletions src/netxs/desktopio/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ namespace netxs

xy2d divround(T n) const { return { netxs::divround(x, n ), netxs::divround(y, n ) }; }
xy2d divround(xy2d p) const { return { netxs::divround(x, p.x), netxs::divround(y, p.y) }; }
xy2d divupper(xy2d p) const { return { netxs::divupper(x, p.x), netxs::divupper(y, p.y) }; }

auto str() const
{
Expand Down Expand Up @@ -174,12 +173,11 @@ namespace netxs
static constexpr auto dot_22 = twod{ 2,2 };
static constexpr auto dot_21 = twod{ 2,1 };
static constexpr auto dot_33 = twod{ 3,3 };
static constexpr auto dot_mx = twod{ si32max / 2, si32max / 2 };
static constexpr auto dot_mx = twod{ (si32)(si32max / 2.f), (si32)(si32max / 2.f) };

twod divround(twod p, si32 n) { return { divround(p.x, n ), divround(p.y, n ) }; }
twod divround(si32 n, twod p) { return { divround(n , p.x), divround(n , p.y) }; }
twod divround(twod n, twod p) { return { divround(n.x, p.x), divround(n.y, p.y) }; }
twod divupper(twod n, twod p) { return { divupper(n.x, p.x), divupper(n.y, p.y) }; }
}

namespace std
Expand Down
Loading

0 comments on commit cc84bb2

Please sign in to comment.