mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-03-22 12:55:33 +07:00
dummy drag event
This commit is contained in:
@@ -10,12 +10,14 @@
|
||||
|
||||
namespace e2d::touchable_events
|
||||
{
|
||||
class mouse_drag_evt;
|
||||
class mouse_move_evt;
|
||||
class mouse_hover_evt;
|
||||
class mouse_scroll_evt;
|
||||
class mouse_button_evt;
|
||||
|
||||
using event = std::variant<std::monostate,
|
||||
mouse_drag_evt,
|
||||
mouse_move_evt,
|
||||
mouse_hover_evt,
|
||||
mouse_scroll_evt,
|
||||
@@ -27,6 +29,7 @@ namespace e2d
|
||||
class touchable final {
|
||||
public:
|
||||
class pushing final {};
|
||||
class dragging final {};
|
||||
class hovering final {};
|
||||
|
||||
class clicked final {};
|
||||
@@ -77,6 +80,10 @@ namespace e2d
|
||||
class factory_loader<touchable::pushing> final
|
||||
: public empty_factory_loader<touchable::pushing> {};
|
||||
|
||||
template <>
|
||||
class factory_loader<touchable::dragging> final
|
||||
: public empty_factory_loader<touchable::dragging> {};
|
||||
|
||||
template <>
|
||||
class factory_loader<touchable::hovering> final
|
||||
: public empty_factory_loader<touchable::hovering> {};
|
||||
@@ -127,19 +134,18 @@ namespace e2d
|
||||
|
||||
namespace e2d::touchable_events
|
||||
{
|
||||
//
|
||||
// base_evt
|
||||
//
|
||||
|
||||
namespace impl
|
||||
{
|
||||
//
|
||||
// base_evt
|
||||
//
|
||||
|
||||
template < typename Event >
|
||||
class base_evt {
|
||||
public:
|
||||
base_evt(bool bubbling)
|
||||
: bubbling_(bubbling) {}
|
||||
|
||||
base_evt(gobject target, bool bubbling)
|
||||
base_evt(
|
||||
gobject target,
|
||||
bool bubbling)
|
||||
: target_(target)
|
||||
, bubbling_(bubbling) {}
|
||||
|
||||
@@ -156,6 +162,38 @@ namespace e2d::touchable_events
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// mouse_drag_evt
|
||||
//
|
||||
|
||||
class mouse_drag_evt final : public impl::base_evt<mouse_drag_evt> {
|
||||
public:
|
||||
ENUM_HPP_CLASS_DECL(types, u8,
|
||||
(start)
|
||||
(move)
|
||||
(end))
|
||||
public:
|
||||
mouse_drag_evt(
|
||||
gobject target,
|
||||
types type,
|
||||
const v2f& local_point,
|
||||
const v2f& world_point)
|
||||
: base_evt(target, true)
|
||||
, type_(type)
|
||||
, local_point_(local_point)
|
||||
, world_point_(world_point) {}
|
||||
|
||||
[[nodiscard]] types type() const noexcept { return type_; }
|
||||
[[nodiscard]] const v2f& local_point() const noexcept { return local_point_; }
|
||||
[[nodiscard]] const v2f& world_point() const noexcept { return world_point_; }
|
||||
private:
|
||||
types type_ = types::start;
|
||||
v2f local_point_ = v2f::zero();
|
||||
v2f world_point_ = v2f::zero();
|
||||
};
|
||||
|
||||
ENUM_HPP_REGISTER_TRAITS(mouse_drag_evt::types)
|
||||
|
||||
//
|
||||
// mouse_move_evt
|
||||
//
|
||||
@@ -189,7 +227,9 @@ namespace e2d::touchable_events
|
||||
(enter)
|
||||
(leave))
|
||||
public:
|
||||
mouse_hover_evt(gobject target, types type)
|
||||
mouse_hover_evt(
|
||||
gobject target,
|
||||
types type)
|
||||
: base_evt(target, type == types::over || type == types::out)
|
||||
, type_(type) {}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ local touchable = {
|
||||
---@type boolean
|
||||
pushing = false,
|
||||
|
||||
---@type boolean
|
||||
dragging = false,
|
||||
|
||||
---@type boolean
|
||||
hovering = false,
|
||||
|
||||
@@ -68,6 +71,23 @@ local touchable_base_evt = {
|
||||
}
|
||||
touchable.touchable_base_evt = touchable_base_evt
|
||||
|
||||
--
|
||||
-- touchable_mouse_drag_evt
|
||||
--
|
||||
|
||||
---@class touchable_mouse_drag_evt : touchable_base_evt
|
||||
local touchable_mouse_drag_evt = {
|
||||
---@type string
|
||||
type = "start",
|
||||
|
||||
---@type v2f
|
||||
local_point = v2f.zero(),
|
||||
|
||||
--@type v2f
|
||||
world_point = v2f.zero()
|
||||
}
|
||||
touchable.touchable_mouse_drag_evt = touchable_mouse_drag_evt
|
||||
|
||||
--
|
||||
-- touchable_mouse_move_evt
|
||||
--
|
||||
@@ -130,7 +150,7 @@ local touchable_mouse_button_evt = {
|
||||
}
|
||||
touchable.touchable_mouse_button_evt = touchable_mouse_button_evt
|
||||
|
||||
---@alias touchable_event touchable_mouse_move_evt | touchable_mouse_hover_evt | touchable_mouse_scroll_evt | touchable_mouse_button_evt
|
||||
---@alias touchable_event touchable_mouse_drag_evt | touchable_mouse_move_evt | touchable_mouse_hover_evt | touchable_mouse_scroll_evt | touchable_mouse_button_evt
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
--
|
||||
|
||||
@@ -13,6 +13,15 @@ end
|
||||
---@param type string
|
||||
---@param event touchable_event
|
||||
function M:on_event(go, type, event)
|
||||
if type == "touchable.mouse_drag_evt" then
|
||||
the_debug:trace(string.format("event: %q\n-->type: %q\n-->target: %q\n-->local_point: %s\n-->world_point: %s",
|
||||
type,
|
||||
event.type,
|
||||
event.target.named and event.target.named.name or "[unnamed]",
|
||||
event.local_point,
|
||||
event.world_point))
|
||||
end
|
||||
|
||||
if type == "touchable.mouse_move_evt" then
|
||||
the_debug:trace(string.format("event: %q\n-->target: %q\n-->local_point: %s\n-->world_point: %s",
|
||||
type,
|
||||
|
||||
@@ -63,6 +63,19 @@ namespace e2d::bindings::high
|
||||
}
|
||||
),
|
||||
|
||||
"dragging", sol::property(
|
||||
[](const gcomponent<touchable>& c) -> bool {
|
||||
return c.component<touchable::dragging>().exists();
|
||||
},
|
||||
[](gcomponent<touchable>& c, bool yesno){
|
||||
if ( yesno ) {
|
||||
c.component<touchable::dragging>().ensure();
|
||||
} else {
|
||||
c.component<touchable::dragging>().remove();
|
||||
}
|
||||
}
|
||||
),
|
||||
|
||||
"hovering", sol::property(
|
||||
[](const gcomponent<touchable>& c) -> bool {
|
||||
return c.component<touchable::hovering>().exists();
|
||||
@@ -188,6 +201,36 @@ namespace e2d::bindings::high
|
||||
// events
|
||||
//
|
||||
|
||||
l["touchable"].get_or_create<sol::table>()
|
||||
.new_usertype<touchable_events::mouse_drag_evt>("mouse_drag_evt",
|
||||
sol::no_constructor,
|
||||
|
||||
"target", sol::property(
|
||||
[](const touchable_events::mouse_drag_evt& c) -> gobject {
|
||||
return c.target();
|
||||
}),
|
||||
|
||||
"bubbling", sol::property(
|
||||
[](const touchable_events::mouse_drag_evt& c) -> bool {
|
||||
return c.bubbling();
|
||||
}),
|
||||
|
||||
"type", sol::property(
|
||||
[](const touchable_events::mouse_drag_evt& c) -> str {
|
||||
return str(enum_hpp::to_string_or_throw(c.type()));
|
||||
}),
|
||||
|
||||
"local_point", sol::property(
|
||||
[](const touchable_events::mouse_drag_evt& c) -> v2f {
|
||||
return c.local_point();
|
||||
}),
|
||||
|
||||
"world_point", sol::property(
|
||||
[](const touchable_events::mouse_drag_evt& c) -> v2f {
|
||||
return c.world_point();
|
||||
})
|
||||
);
|
||||
|
||||
l["touchable"].get_or_create<sol::table>()
|
||||
.new_usertype<touchable_events::mouse_move_evt>("mouse_move_evt",
|
||||
sol::no_constructor,
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace e2d
|
||||
void component_inspector<touchable>::operator()(gcomponent<touchable>& c) const {
|
||||
|
||||
//
|
||||
// pushing/hovering
|
||||
// pushing/dragging/hovering
|
||||
//
|
||||
|
||||
if ( bool pushing = c.component<touchable::pushing>().exists();
|
||||
@@ -74,6 +74,18 @@ namespace e2d
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if ( bool dragging = c.component<touchable::dragging>().exists();
|
||||
ImGui::Checkbox("dragging", &dragging) )
|
||||
{
|
||||
if ( dragging ) {
|
||||
c.component<touchable::dragging>().ensure();
|
||||
} else {
|
||||
c.component<touchable::dragging>().remove();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if ( bool hovering = c.component<touchable::hovering>().exists();
|
||||
ImGui::Checkbox("hovering", &hovering) )
|
||||
{
|
||||
|
||||
@@ -234,6 +234,7 @@ namespace e2d
|
||||
.register_component<toggle::pressed>("toggle.pressed")
|
||||
.register_component<touchable>("touchable")
|
||||
.register_component<touchable::pushing>("touchable.pushing")
|
||||
.register_component<touchable::dragging>("touchable.dragging")
|
||||
.register_component<touchable::hovering>("touchable.hovering")
|
||||
.register_component<touchable::clicked>("touchable.clicked")
|
||||
.register_component<touchable::pressed>("touchable.pressed")
|
||||
@@ -279,6 +280,7 @@ namespace e2d
|
||||
//.register_component<toggle::pressed>("toggle.pressed")
|
||||
.register_component<touchable>("touchable")
|
||||
//.register_component<touchable::pushing>("touchable.pushing")
|
||||
//.register_component<touchable::dragging>("touchable.dragging")
|
||||
//.register_component<touchable::hovering>("touchable.hovering")
|
||||
//.register_component<touchable::clicked>("touchable.clicked")
|
||||
//.register_component<touchable::pressed>("touchable.pressed")
|
||||
|
||||
@@ -87,6 +87,10 @@ namespace
|
||||
behaviours::call_result r = behaviours::call_result::success;
|
||||
std::visit(utils::overloaded {
|
||||
[](std::monostate){},
|
||||
[&b,&a,&r](const touchable_events::mouse_drag_evt& e){
|
||||
r = behaviours::call_meta_method(
|
||||
b, "on_event", a.node()->owner(), "touchable.mouse_drag_evt", e);
|
||||
},
|
||||
[&b,&a,&r](const touchable_events::mouse_move_evt& e){
|
||||
r = behaviours::call_meta_method(
|
||||
b, "on_event", a.node()->owner(), "touchable.mouse_move_evt", e);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace e2d
|
||||
internal_state(input& i, window& w)
|
||||
: input_(i)
|
||||
, window_(w)
|
||||
, collector_(window_.register_event_listener<collector>()) {}
|
||||
, collector_(window_.register_event_listener<collector>(i)) {}
|
||||
|
||||
~internal_state() noexcept {
|
||||
window_.unregister_event_listener(collector_);
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
namespace e2d::touch_system_impl
|
||||
{
|
||||
collector::collector(input& i)
|
||||
: input_(i) {}
|
||||
|
||||
void collector::clear() noexcept {
|
||||
events_.clear();
|
||||
}
|
||||
@@ -37,11 +40,16 @@ namespace e2d::touch_system_impl
|
||||
}
|
||||
|
||||
void collector::on_move_cursor(const v2f& pos) noexcept {
|
||||
events_.push_back(mouse_move_event(pos));
|
||||
E2D_UNUSED(pos);
|
||||
events_.push_back(mouse_move_event(
|
||||
input_.mouse().cursor_pos()));
|
||||
}
|
||||
|
||||
void collector::on_mouse_scroll(const v2f& delta) noexcept {
|
||||
events_.push_back(mouse_scroll_event(delta));
|
||||
E2D_UNUSED(delta);
|
||||
events_.push_back(mouse_scroll_event(
|
||||
input_.mouse().cursor_pos(),
|
||||
input_.mouse().scroll_delta()));
|
||||
}
|
||||
|
||||
void collector::on_mouse_button(mouse_button button, mouse_button_action action) noexcept {
|
||||
@@ -53,6 +61,9 @@ namespace e2d::touch_system_impl
|
||||
return;
|
||||
}
|
||||
|
||||
events_.push_back(mouse_button_event(button, action));
|
||||
events_.push_back(mouse_button_event(
|
||||
input_.mouse().cursor_pos(),
|
||||
button,
|
||||
action));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,24 +12,38 @@ namespace e2d::touch_system_impl
|
||||
{
|
||||
class collector final : public window::event_listener {
|
||||
public:
|
||||
struct mouse_move_event {
|
||||
v2f pos{v2f::zero()};
|
||||
mouse_move_event(const v2f& npos)
|
||||
: pos(npos) {}
|
||||
struct mouse_event {
|
||||
v2f screen_point{v2f::zero()};
|
||||
mouse_event(
|
||||
const v2f& screen_point)
|
||||
: screen_point(screen_point) {}
|
||||
};
|
||||
|
||||
struct mouse_scroll_event {
|
||||
struct mouse_move_event : mouse_event {
|
||||
mouse_move_event(
|
||||
const v2f& screen_point)
|
||||
: mouse_event(screen_point) {}
|
||||
};
|
||||
|
||||
struct mouse_scroll_event : mouse_event {
|
||||
v2f delta{v2f::zero()};
|
||||
mouse_scroll_event(const v2f& ndelta)
|
||||
: delta(ndelta) {}
|
||||
mouse_scroll_event(
|
||||
const v2f& screen_point,
|
||||
const v2f& delta)
|
||||
: mouse_event(screen_point)
|
||||
, delta(delta) {}
|
||||
};
|
||||
|
||||
struct mouse_button_event {
|
||||
struct mouse_button_event : mouse_event {
|
||||
mouse_button button{mouse_button::unknown};
|
||||
mouse_button_action action{mouse_button_action::unknown};
|
||||
mouse_button_event(mouse_button nbutton, mouse_button_action naction)
|
||||
: button(nbutton)
|
||||
, action(naction) {}
|
||||
mouse_button_event(
|
||||
const v2f& screen_point,
|
||||
mouse_button button,
|
||||
mouse_button_action action)
|
||||
: mouse_event(screen_point)
|
||||
, button(button)
|
||||
, action(action) {}
|
||||
};
|
||||
public:
|
||||
using event = std::variant<std::monostate,
|
||||
@@ -38,7 +52,7 @@ namespace e2d::touch_system_impl
|
||||
mouse_button_event>;
|
||||
using events = vector<event>;
|
||||
public:
|
||||
collector() = default;
|
||||
collector(input& i);
|
||||
|
||||
void clear() noexcept;
|
||||
|
||||
@@ -60,6 +74,7 @@ namespace e2d::touch_system_impl
|
||||
mouse_button button,
|
||||
mouse_button_action action) noexcept final;
|
||||
private:
|
||||
input& input_;
|
||||
vector<event> events_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user