From a998115414c9fac583aef95535fb3b87f71a67bb Mon Sep 17 00:00:00 2001 From: chatlanin Date: Tue, 28 Jan 2025 14:03:19 +0300 Subject: [PATCH] add double click mouse event impl --- bin/layers/test_panel/test_panel.cpp | 6 ++++++ src/event/event.hpp | 1 + src/glfw/glfw.cpp | 11 ++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/bin/layers/test_panel/test_panel.cpp b/bin/layers/test_panel/test_panel.cpp index d9e575e..364ce48 100755 --- a/bin/layers/test_panel/test_panel.cpp +++ b/bin/layers/test_panel/test_panel.cpp @@ -31,6 +31,12 @@ namespace sandbox void test_panel::on_event(VE::event e) { + if (e.m_type.type() == typeid(VE::event_type)) + { + auto t = std::any_cast(e.m_type); + if (t == VE::event_type::MOUSE_BUTTON_DOUBLE_PRESSED) hack::log()("double"); + if (t == VE::event_type::MOUSE_BUTTON_PRESSED) hack::log()("once"); + } } } diff --git a/src/event/event.hpp b/src/event/event.hpp index 8035aed..b4a3a28 100755 --- a/src/event/event.hpp +++ b/src/event/event.hpp @@ -11,6 +11,7 @@ namespace VE KEY_REPEATE, MOUSE_BUTTON_PRESSED, + MOUSE_BUTTON_DOUBLE_PRESSED, MOUSE_BUTTON_RELEASED, MOUSE_CURSOR_POSITION, diff --git a/src/glfw/glfw.cpp b/src/glfw/glfw.cpp index dfb0a61..09a82a2 100755 --- a/src/glfw/glfw.cpp +++ b/src/glfw/glfw.cpp @@ -163,7 +163,16 @@ namespace VE { case GLFW_PRESS: { - e.m_type = event_type::MOUSE_BUTTON_PRESSED; + static auto time = std::chrono::high_resolution_clock::now(); + auto local = std::chrono::high_resolution_clock::now(); + std::chrono::duration duration = local - time; + + if (duration.count() > 10 && duration.count() < 200) + e.m_type = event_type::MOUSE_BUTTON_DOUBLE_PRESSED; + else + e.m_type = event_type::MOUSE_BUTTON_PRESSED; + + time = local; break; } case GLFW_RELEASE: