From a38866694c9b50b1b5fc1c01258469a19654d4cd Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 3 Jul 2025 23:28:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/io/event/EventDispatch.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inc/hgl/io/event/EventDispatch.h b/inc/hgl/io/event/EventDispatch.h index 40a9de0..3287ff5 100644 --- a/inc/hgl/io/event/EventDispatch.h +++ b/inc/hgl/io/event/EventDispatch.h @@ -3,6 +3,13 @@ #include #include +/* +* 现阶段事件分发流程: +* +* 操作系统事件 -> Window -> RenderFramework -> WorkManager +* +*/ + namespace hgl::io { struct EventHeader From 8e733a241536efcaff8cbff66c8a3a4f1255ed86 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 7 Jul 2025 01:24:46 +0800 Subject: [PATCH 2/6] =?UTF-8?q?Rotate=E9=87=8D=E5=91=BD=E5=90=8D=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=A2=9E=E5=8A=A0AxisXRotate/AxisYRotate/AxisZRotate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Matrix.h | 20 ++++++++++++-------- inc/hgl/math/Transform.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 178ca06..627718a 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -147,29 +147,33 @@ namespace hgl return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } - inline Matrix4f rotate(float rad,const Vector3f &axis) + inline Matrix4f AxisXRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::X);} + inline Matrix4f AxisYRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Y);} + inline Matrix4f AxisZRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Z);} + + inline Matrix4f AxisRotate(float rad,const Vector3f &axis) { return glm::rotate(Matrix4f(1.0f),rad,axis); } - inline Matrix4f rotate(float rad,float x,float y,float z) + inline Matrix4f AxisRotate(float rad,float x,float y,float z) { return glm::rotate(Matrix4f(1.0f),rad,Vector3f(x,y,z)); } - inline Matrix4f rotate(float rad,float x,float y) + inline Matrix4f AxisRotate(float rad,float x,float y) { - return rotate(rad,x,y,1.0f); + return AxisRotate(rad,x,y,1.0f); } - inline Matrix4f rotate(float rad,const Vector4f &axis) + inline Matrix4f AxisRotate(float rad,const Vector4f &axis) { - return rotate(rad,Vector3f(axis.x,axis.y,axis.z)); + return AxisRotate(rad,Vector3f(axis.x,axis.y,axis.z)); } - inline Vector3f rotate(const Vector3f &v3f,float rad,const Vector3f &axis) + inline Vector3f AxisRotate(const Vector3f &v3f,float rad,const Vector3f &axis) { - Vector4f result = rotate(rad, axis)*Vector4f(v3f, 1.0f); + Vector4f result = AxisRotate(rad, axis)*Vector4f(v3f, 1.0f); return Vector3f(result.x,result.y,result.z); } diff --git a/inc/hgl/math/Transform.h b/inc/hgl/math/Transform.h index 5fa6a08..a6b2520 100644 --- a/inc/hgl/math/Transform.h +++ b/inc/hgl/math/Transform.h @@ -215,7 +215,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=rotate(angle,axis); + mat=AxisRotate(angle,axis); } public: From 6b97ffdf79ff978fff89ca5276a21c1a18c98669 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 8 Jul 2025 01:17:13 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=9F=A9=E9=98=B5=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=94=B9=E5=90=8D=E4=BB=A5=E8=A7=84=E9=81=BF?= =?UTF-8?q?=E4=B8=8EGLM=E5=87=BD=E6=95=B0=E5=90=8D=E7=9A=84=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Matrix.h | 38 ++++++++++++++------------------------ inc/hgl/math/Transform.h | 8 ++++---- src/Math/Matrix4f.cpp | 14 +++++++------- src/Math/Transform.cpp | 2 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 627718a..6c37407 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -51,16 +51,6 @@ namespace hgl return glm::all(glm::epsilonEqual(q1,q2,err)); } - inline Matrix4f inverse(const Matrix4f &m) - { - return glm::inverse(m); - } - - inline Matrix4f transpose(const Matrix4f &m) - { - return glm::transpose(m); - } - /** * 生成一个正角视图矩阵 * @param left 左 @@ -70,7 +60,7 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho( float left, + Matrix4f OrthoMatrix( float left, float right, float bottom, float top, @@ -84,14 +74,14 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho(float width,float height,float znear,float zfar); + Matrix4f OrthoMatrix(float width,float height,float znear,float zfar); /** * 生成一个正角视图矩阵 * @param width 宽 * @param height 高 */ - Matrix4f ortho(float width,float height); + Matrix4f OrthoMatrix(float width,float height); /** * 生成一个透视矩阵 @@ -100,7 +90,7 @@ namespace hgl * @param znear 近截面 * @param zfar 远截面 */ - Matrix4f perspective( float field_of_view, + Matrix4f PerspectiveMatrix( float field_of_view, float aspect_ratio, float znear, float zfar); @@ -110,39 +100,39 @@ namespace hgl * @param target 目标位置 * @param up 向上向量 */ - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z); + Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z); - inline Matrix4f translate(const Vector3f &v) + inline Matrix4f TranslateMatrix(const Vector3f &v) { return glm::translate(Matrix4f(1.0f),v); } - inline Matrix4f translate(float x,float y,float z) + inline Matrix4f TranslateMatrix(float x,float y,float z) { return glm::translate(Matrix4f(1.0f),Vector3f(x,y,z)); } - inline Matrix4f translate(float x,float y) + inline Matrix4f TranslateMatrix(float x,float y) { - return translate(x,y,1.0f); + return glm::translate(Matrix4f(1.0f),Vector3f(x,y,1.0f)); } - inline Matrix4f scale(const Vector3f &v) + inline Matrix4f ScaleMatrix(const Vector3f &v) { return glm::scale(Matrix4f(1.0f),v); } - inline Matrix4f scale(float x,float y,float z) + inline Matrix4f ScaleMatrix(float x,float y,float z) { return glm::scale(Matrix4f(1.0f),Vector3f(x,y,z)); } - inline Matrix4f scale(float x,float y) + inline Matrix4f ScaleMatrix(float x,float y) { - return scale(x,y,1.0f); + return glm::scale(Matrix4f(1.0f),Vector3f(x,y,1.0f)); } - inline Matrix4f scale(float s) + inline Matrix4f ScaleMatrix(float s) { return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } diff --git a/inc/hgl/math/Transform.h b/inc/hgl/math/Transform.h index a6b2520..6730a4f 100644 --- a/inc/hgl/math/Transform.h +++ b/inc/hgl/math/Transform.h @@ -101,7 +101,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=translate(offset); + mat=TranslateMatrix(offset); } public: @@ -342,7 +342,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=scale(scale3f); + mat=ScaleMatrix(scale3f); } public: @@ -395,7 +395,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=lookat(eye,center,up); + mat=LookAtMatrix(eye,center,up); } public: @@ -695,7 +695,7 @@ namespace hgl const Matrix4f GetMatrix()const //不能执行UpdateMatrix时的获取 { if(matrix_dirty) - return translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector); + return TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector); else return matrix; } diff --git a/src/Math/Matrix4f.cpp b/src/Math/Matrix4f.cpp index 92e91bf..9f42908 100644 --- a/src/Math/Matrix4f.cpp +++ b/src/Math/Matrix4f.cpp @@ -14,7 +14,7 @@ namespace hgl { - Matrix4f ortho( float left, + Matrix4f OrthoMatrix( float left, float right, float bottom, float top, @@ -51,9 +51,9 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho(float width,float height,float znear,float zfar) + Matrix4f OrthoMatrix(float width,float height,float znear,float zfar) { - return ortho(0.0f,width,height,0.0f,znear,zfar); + return OrthoMatrix(0.0f,width,height,0.0f,znear,zfar); } /** @@ -61,9 +61,9 @@ namespace hgl * @param width 宽 * @param height 高 */ - Matrix4f ortho(float width,float height) + Matrix4f OrthoMatrix(float width,float height) { - return ortho(width,height,0.0f,1.0f); + return OrthoMatrix(width,height,0.0f,1.0f); } /** @@ -73,7 +73,7 @@ namespace hgl * @param znear 近截面 * @param zfar 远截面 */ - Matrix4f perspective( float field_of_view, + Matrix4f PerspectiveMatrix( float field_of_view, float aspect_ratio, float znear, float zfar) @@ -105,7 +105,7 @@ namespace hgl //经查证,此代码等于glm::perspectiveRH_ZO之后将[1][1]乘-1,在SaschaWillems的范例中,如果反转Y轴,则[1][1]确实要乘-1。 } - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up) + Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up) { Vector3f forward=normalize(target-eye); Vector3f right =normalize(cross(forward,up)); diff --git a/src/Math/Transform.cpp b/src/Math/Transform.cpp index 101e1dd..e47ca0a 100644 --- a/src/Math/Transform.cpp +++ b/src/Math/Transform.cpp @@ -52,7 +52,7 @@ namespace hgl } else { - matrix=translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector); + matrix=TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector); inverse_matrix=inverse(matrix); transpose_inverse_matrix=transpose(inverse_matrix); From 1862d04529c2ce68df3492e218916dd617052d23 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 16 Jul 2025 02:12:44 +0800 Subject: [PATCH 4/6] =?UTF-8?q?EventDispatcht=E9=87=8D=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{EventDispatch.h => EventDispatcher.h} | 32 +++++++++---------- inc/hgl/io/event/KeyboardEvent.h | 8 ++--- inc/hgl/io/event/MouseEvent.h | 8 ++--- inc/hgl/io/event/WindowEvent.h | 10 +++--- src/CMakeLists.txt | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) rename inc/hgl/io/event/{EventDispatch.h => EventDispatcher.h} (71%) diff --git a/inc/hgl/io/event/EventDispatch.h b/inc/hgl/io/event/EventDispatcher.h similarity index 71% rename from inc/hgl/io/event/EventDispatch.h rename to inc/hgl/io/event/EventDispatcher.h index 3287ff5..8caa33c 100644 --- a/inc/hgl/io/event/EventDispatch.h +++ b/inc/hgl/io/event/EventDispatcher.h @@ -30,19 +30,19 @@ namespace hgl::io Break, }; - class EventDispatch + class EventDispatcher { protected: - InputEventSource source_type; + InputEventSource source_type; - EventDispatch * parent_input_event; + EventDispatcher * parent_input_event; - SortedSet event_dispatch_subscribers; + SortedSet event_subscribers; protected: - void SetParent(EventDispatch *ie){parent_input_event=ie;} + void SetParent(EventDispatcher *ie){parent_input_event=ie;} public: @@ -53,9 +53,9 @@ namespace hgl::io if(!RangeCheck(header.type)) return(EventProcResult::Break); - if(!event_dispatch_subscribers.IsEmpty()) + if(!event_subscribers.IsEmpty()) { - for(EventDispatch *ie:event_dispatch_subscribers) + for(EventDispatcher *ie:event_subscribers) if(ie->OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; } @@ -65,25 +65,25 @@ namespace hgl::io public: - EventDispatch() + EventDispatcher() { source_type=InputEventSource::Root; parent_input_event=nullptr; } - EventDispatch(InputEventSource ies) + EventDispatcher(InputEventSource ies) { source_type=ies; parent_input_event=nullptr; } - virtual ~EventDispatch() + virtual ~EventDispatcher() { if(parent_input_event) - parent_input_event->UnregisterEventDispatch(this); + parent_input_event->UnsubscribeEventDispatcher(this); } - virtual bool RegisterEventDispatch(EventDispatch *ie) + virtual bool SubscribeEventDispatcher(EventDispatcher *ie) { if(!ie) return(false); @@ -95,10 +95,10 @@ namespace hgl::io ie->SetParent(this); - return(event_dispatch_subscribers.Add(ie)!=-1); + return(event_subscribers.Add(ie)!=-1); } - bool UnregisterEventDispatch(EventDispatch *ie) + bool UnsubscribeEventDispatcher(EventDispatcher *ie) { if(!ie)return(false); @@ -109,9 +109,9 @@ namespace hgl::io ie->SetParent(nullptr); - return event_dispatch_subscribers.Delete(ie); + return event_subscribers.Delete(ie); } virtual bool Update(){return true;} - };//class EventDispatch + };//class EventDispatcher }//namespace hgl::io diff --git a/inc/hgl/io/event/KeyboardEvent.h b/inc/hgl/io/event/KeyboardEvent.h index 21bc20f..1f0d4a2 100644 --- a/inc/hgl/io/event/KeyboardEvent.h +++ b/inc/hgl/io/event/KeyboardEvent.h @@ -1,7 +1,7 @@ #ifndef HGL_IO_KEYBOARD_EVENT_INCLUDE #define HGL_IO_KEYBOARD_EVENT_INCLUDE -#include +#include namespace hgl { namespace io @@ -158,11 +158,11 @@ namespace hgl os_char ch; }; - class KeyboardEvent:public EventDispatch + class KeyboardEvent:public EventDispatcher { public: - KeyboardEvent():EventDispatch(InputEventSource::Keyboard){} + KeyboardEvent():EventDispatcher(InputEventSource::Keyboard){} virtual ~KeyboardEvent()=default; EventProcResult OnEvent(const EventHeader &header,const uint64 data) override @@ -177,7 +177,7 @@ namespace hgl } } - if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) + if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; return EventProcResult::Continue; diff --git a/inc/hgl/io/event/MouseEvent.h b/inc/hgl/io/event/MouseEvent.h index 5853cee..ac65a35 100644 --- a/inc/hgl/io/event/MouseEvent.h +++ b/inc/hgl/io/event/MouseEvent.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace hgl::io { @@ -42,7 +42,7 @@ namespace hgl::io constexpr size_t MouseEventDataBytes=sizeof(MouseEventData); - class MouseEvent:public EventDispatch + class MouseEvent:public EventDispatcher { MouseEventData *med; @@ -52,7 +52,7 @@ namespace hgl::io public: - MouseEvent():EventDispatch(InputEventSource::Mouse) + MouseEvent():EventDispatcher(InputEventSource::Mouse) { med=nullptr; position.x=0; @@ -88,7 +88,7 @@ namespace hgl::io } } - if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) + if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; return EventProcResult::Continue; diff --git a/inc/hgl/io/event/WindowEvent.h b/inc/hgl/io/event/WindowEvent.h index 702033a..c22d5d2 100644 --- a/inc/hgl/io/event/WindowEvent.h +++ b/inc/hgl/io/event/WindowEvent.h @@ -1,7 +1,7 @@ #ifndef HGL_IO_WINDOW_EVENT_INCLUDE #define HGL_IO_WINDOW_EVENT_INCLUDE -#include +#include namespace hgl { namespace io @@ -27,13 +27,13 @@ namespace hgl constexpr size_t WindowEventDataBytes=sizeof(WindowEventData); - class WindowEvent:public EventDispatch + class WindowEvent:public EventDispatcher { WindowEventData *wed; public: - WindowEvent():EventDispatch(InputEventSource::Window){wed=nullptr;} + WindowEvent():EventDispatcher(InputEventSource::Window){wed=nullptr;} virtual ~WindowEvent()=default; virtual EventProcResult OnEvent(const EventHeader &header,const uint64 data) override @@ -50,7 +50,7 @@ namespace hgl } } - if(EventDispatch::OnEvent(header,data)==EventProcResult::Break) + if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; return EventProcResult::Continue; @@ -61,7 +61,7 @@ namespace hgl virtual void OnResize(uint w,uint h){} virtual void OnActive(bool){} virtual void OnClose (){} - };//class WindowEvent:public EventDispatch + };//class WindowEvent:public EventDispatcher }//namespace io }//namespace hgl #endif//HGL_IO_WINDOW_EVENT_INCLUDE diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f4b6f0b..d5b0efb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -193,7 +193,7 @@ SET(IO_TEXT_FILES IO/TextOutputStream.cpp SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h ${IO_INCLUDE_PATH}/event/MouseEvent.h ${IO_INCLUDE_PATH}/event/JoystickEvent.h - ${IO_INCLUDE_PATH}/event/EventDispatch.h + ${IO_INCLUDE_PATH}/event/EventDispatcher.h ${IO_INCLUDE_PATH}/event/InputMapping.h ) From 713921985587dde43b11d1e0d3d2defc6c35d541 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 17 Jul 2025 02:22:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=91=BD=E5=90=8DEventDi?= =?UTF-8?q?spatcher=E7=9A=84=E6=B7=BB=E5=8A=A0/=E8=A7=A3=E5=86=B3=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/io/event/EventDispatcher.h | 41 +++++--------------- inc/hgl/io/event/MouseEvent.h | 61 ++++++------------------------ src/CMakeLists.txt | 8 ++-- src/IO/Event/EventDispatcher.cpp | 33 ++++++++++++++++ src/IO/Event/MouseEvent.cpp | 37 ++++++++++++++++++ 5 files changed, 96 insertions(+), 84 deletions(-) create mode 100644 src/IO/Event/EventDispatcher.cpp create mode 100644 src/IO/Event/MouseEvent.cpp diff --git a/inc/hgl/io/event/EventDispatcher.h b/inc/hgl/io/event/EventDispatcher.h index 8caa33c..ee88266 100644 --- a/inc/hgl/io/event/EventDispatcher.h +++ b/inc/hgl/io/event/EventDispatcher.h @@ -30,6 +30,9 @@ namespace hgl::io Break, }; + /** + * 事件分发器 + */ class EventDispatcher { protected: @@ -38,7 +41,7 @@ namespace hgl::io EventDispatcher * parent_input_event; - SortedSet event_subscribers; + SortedSet child_dispatchers; protected: @@ -53,9 +56,9 @@ namespace hgl::io if(!RangeCheck(header.type)) return(EventProcResult::Break); - if(!event_subscribers.IsEmpty()) + if(!child_dispatchers.IsEmpty()) { - for(EventDispatcher *ie:event_subscribers) + for(EventDispatcher *ie:child_dispatchers) if(ie->OnEvent(header,data)==EventProcResult::Break) return EventProcResult::Break; } @@ -80,37 +83,11 @@ namespace hgl::io virtual ~EventDispatcher() { if(parent_input_event) - parent_input_event->UnsubscribeEventDispatcher(this); + parent_input_event->RemoveChildDispatcher(this); } - virtual bool SubscribeEventDispatcher(EventDispatcher *ie) - { - if(!ie) - return(false); - - const InputEventSource ies=ie->GetInputEventSource(); - - if(!RangeCheck(ies)) - return(false); - - ie->SetParent(this); - - return(event_subscribers.Add(ie)!=-1); - } - - bool UnsubscribeEventDispatcher(EventDispatcher *ie) - { - if(!ie)return(false); - - const InputEventSource ies=ie->GetInputEventSource(); - - if(!RangeCheck(ies)) - return(false); - - ie->SetParent(nullptr); - - return event_subscribers.Delete(ie); - } + virtual bool AddChildDispatcher(EventDispatcher *ie); + virtual bool RemoveChildDispatcher(EventDispatcher *ie); virtual bool Update(){return true;} };//class EventDispatcher diff --git a/inc/hgl/io/event/MouseEvent.h b/inc/hgl/io/event/MouseEvent.h index ac65a35..704f9b0 100644 --- a/inc/hgl/io/event/MouseEvent.h +++ b/inc/hgl/io/event/MouseEvent.h @@ -44,66 +44,29 @@ namespace hgl::io class MouseEvent:public EventDispatcher { - MouseEventData *med; + MouseEventData *med=nullptr; - Vector2i position; + Vector2i position{}; - bool pressed_statues[size_t(MouseButton::RANGE_SIZE)]; + bool pressed_statues[size_t(MouseButton::RANGE_SIZE)]{}; public: - MouseEvent():EventDispatcher(InputEventSource::Mouse) - { - med=nullptr; - position.x=0; - position.y=0;; - hgl_zero(pressed_statues); - } + MouseEvent():EventDispatcher(InputEventSource::Mouse){} virtual ~MouseEvent()=default; - - EventProcResult OnEvent(const EventHeader &header,const uint64 data) override - { - if(header.type==InputEventSource::Mouse) - { - med=(MouseEventData *)&data; - if(MouseEventID(header.id)==MouseEventID::Wheel) - { - if(OnWheel (med->x,med->y) )return EventProcResult::Break; - } - else - { - position.x=med->x; - position.y=med->y; + virtual EventProcResult OnEvent (const EventHeader &header,const uint64 data) override; - switch(MouseEventID(header.id)) - { - case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break; - case MouseEventID::Pressed: pressed_statues[med->button]=true; - if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; - case MouseEventID::Released: pressed_statues[med->button]=false; - if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; - case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; - } - } - } + virtual bool OnMove (int,int){return false;} + virtual bool OnWheel (int,int){return false;} - if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break) - return EventProcResult::Break; - - return EventProcResult::Continue; - } - - virtual bool OnMove (int,int){return false;} - virtual bool OnWheel (int,int){return false;} - - virtual bool OnPressed (int,int,MouseButton){return false;} - virtual bool OnReleased (int,int,MouseButton){return false;} - virtual bool OnDblClicked(int,int,MouseButton){return false;} + virtual bool OnPressed (int,int,MouseButton){return false;} + virtual bool OnReleased (int,int,MouseButton){return false;} + virtual bool OnDblClicked(int,int,MouseButton){return false;} /** - * 某按键是否按下 - */ + * 某按键是否按下 + */ const bool HasPressed(const MouseButton &mb)const { if(!RangeCheck(mb))return(false); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d5b0efb..18d282d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -195,6 +195,8 @@ SET(INPUT_EVENT_FILES ${IO_INCLUDE_PATH}/event/KeyboardEvent.h ${IO_INCLUDE_PATH}/event/JoystickEvent.h ${IO_INCLUDE_PATH}/event/EventDispatcher.h ${IO_INCLUDE_PATH}/event/InputMapping.h + IO/Event/MouseEvent.cpp + IO/Event/EventDispatcher.cpp ) SOURCE_GROUP("IO\\Event" FILES ${INPUT_EVENT_FILES}) @@ -247,10 +249,10 @@ SOURCE_GROUP("Thread" FILES ${BASE_THREAD_HEADER_FILES} ${BASE_THREAD_SOURCE_FILES}) FILE(GLOB BASE_EVENT_HEADER_FILES ${CMCORE_ROOT_INCLUDE_PATH}/hgl/event/*.*) -FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*) +#FILE(GLOB BASE_EVENT_SOURCE_FILES Event/*.*) -SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES} - ${BASE_EVENT_SOURCE_FILES}) +SOURCE_GROUP("Event" FILES ${BASE_EVENT_HEADER_FILES}) + #${BASE_EVENT_SOURCE_FILES}) file(GLOB BASE_PLUG_IN_HEADER ${CMCORE_ROOT_INCLUDE_PATH}/hgl/plugin/*.h) file(GLOB BASE_PLUG_IN_SOURCE PlugIn/*.cpp) diff --git a/src/IO/Event/EventDispatcher.cpp b/src/IO/Event/EventDispatcher.cpp new file mode 100644 index 0000000..69539ab --- /dev/null +++ b/src/IO/Event/EventDispatcher.cpp @@ -0,0 +1,33 @@ +#include + +namespace hgl::io +{ + bool EventDispatcher::AddChildDispatcher(EventDispatcher *ie) + { + if(!ie) + return(false); + + const InputEventSource ies=ie->GetInputEventSource(); + + if(!RangeCheck(ies)) + return(false); + + ie->SetParent(this); + + return(child_dispatchers.Add(ie)!=-1); + } + + bool EventDispatcher::RemoveChildDispatcher(EventDispatcher *ie) + { + if(!ie)return(false); + + const InputEventSource ies=ie->GetInputEventSource(); + + if(!RangeCheck(ies)) + return(false); + + ie->SetParent(nullptr); + + return child_dispatchers.Delete(ie); + } +}//namespace hgl::io diff --git a/src/IO/Event/MouseEvent.cpp b/src/IO/Event/MouseEvent.cpp new file mode 100644 index 0000000..1217b19 --- /dev/null +++ b/src/IO/Event/MouseEvent.cpp @@ -0,0 +1,37 @@ +#include + +namespace hgl::io +{ + EventProcResult MouseEvent::OnEvent(const EventHeader &header,const uint64 data) + { + if(header.type==InputEventSource::Mouse) + { + med=(MouseEventData *)&data; + + if(MouseEventID(header.id)==MouseEventID::Wheel) + { + if(OnWheel (med->x,med->y) )return EventProcResult::Break; + } + else + { + position.x=med->x; + position.y=med->y; + + switch(MouseEventID(header.id)) + { + case MouseEventID::Move: if(OnMove (med->x,med->y) )return EventProcResult::Break;break; + case MouseEventID::Pressed: pressed_statues[med->button]=true; + if(OnPressed (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; + case MouseEventID::Released: pressed_statues[med->button]=false; + if(OnReleased (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; + case MouseEventID::DblClicked: if(OnDblClicked (med->x,med->y,MouseButton(med->button)))return EventProcResult::Break;break; + } + } + } + + if(EventDispatcher::OnEvent(header,data)==EventProcResult::Break) + return EventProcResult::Break; + + return EventProcResult::Continue; + } +}//namespace hgl::io From 8d7ab8fa7e36d8652e1fd2071a81c93c26e2fc55 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 25 Jul 2025 01:01:52 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/PhysicsConst.h | 4 +- inc/hgl/type/ObjectList.h | 2 +- inc/hgl/type/StrChar.h | 9 +-- inc/hgl/type/String.h | 106 ++++++++++++++++++------------------ inc/hgl/type/StringList.h | 20 +++---- 5 files changed, 69 insertions(+), 72 deletions(-) diff --git a/inc/hgl/math/PhysicsConst.h b/inc/hgl/math/PhysicsConst.h index 7b8e4a1..119afdb 100644 --- a/inc/hgl/math/PhysicsConst.h +++ b/inc/hgl/math/PhysicsConst.h @@ -95,7 +95,7 @@ namespace hgl } /** - * 摄氏度到开氏度 + * 摄氏度到开尔文度 */ template inline T Celsius2Kelvin(const T &c) @@ -104,7 +104,7 @@ namespace hgl } /** - * 开氏度到摄氏度 + * 开尔文度到摄氏度 */ template inline T Kelvin2Celsius(const T &k) diff --git a/inc/hgl/type/ObjectList.h b/inc/hgl/type/ObjectList.h index 6175a3e..0bf3fe0 100644 --- a/inc/hgl/type/ObjectList.h +++ b/inc/hgl/type/ObjectList.h @@ -33,7 +33,7 @@ namespace hgl return ArrayList::Insert(index,obj); } - virtual void Free() override ///<清除所有数据 + virtual void Free() override ///<清除所有数据并释放缓冲区 { Clear(); ArrayList::Free(); diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index 838fff1..22ac4ca 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -1,5 +1,4 @@ -#ifndef HGL_STR_TEMPLATE_INCLUDE -#define HGL_STR_TEMPLATE_INCLUDE +#pragma once #include namespace hgl @@ -2729,7 +2728,6 @@ namespace hgl if(pna->ToNumber(sp,result)) { ++count; - result_list.Add(result); ++p; @@ -3004,7 +3002,7 @@ namespace hgl } /** - * 将一串原始数据转转成16进制数值字符串 + * 将一串原始数据转换成16进制数值字符串 * @param str 16进制数值字符串存入处 * @param src 原始的数据 * @param size 原始数据字节长度 @@ -3056,5 +3054,4 @@ namespace hgl template inline void ToUpperHexStr(T *str,const void *data,const int size,const T gap_char=0){DataToHexStr(str,(const uint8 *)data,size,UpperHexChar,gap_char);} template inline void ToLowerHexStr(T *str,const void *data,const int size,const T gap_char=0){DataToHexStr(str,(const uint8 *)data,size,LowerHexChar,gap_char);} - }//namespace hgl -#endif//HGL_STR_TEMPLATE_INCLUDE +}//namespace hgl diff --git a/inc/hgl/type/String.h b/inc/hgl/type/String.h index 0520b7a..d51a7a2 100644 --- a/inc/hgl/type/String.h +++ b/inc/hgl/type/String.h @@ -507,9 +507,9 @@ namespace hgl /** * 和一个字符串进行比较 * @param bs 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const SelfClass &bs)const { @@ -525,9 +525,9 @@ namespace hgl /** * 和一个字符串进行比较 * @param str 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const T *str)const { @@ -546,9 +546,9 @@ namespace hgl * 和一个字符串进行比较 * @param pos 起始位置 * @param bs 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const uint pos,const SelfClass &bs)const { @@ -566,9 +566,9 @@ namespace hgl * @param pos 起始位置 * @param bs 比较字符串 * @param num 比较长度 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const uint pos,const SelfClass &bs,const int num)const { @@ -585,9 +585,9 @@ namespace hgl * 和一个字符串进行比较 * @param pos 起始位置 * @param str 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const uint pos,const T *str)const { @@ -607,9 +607,9 @@ namespace hgl * @param pos 起始位置 * @param str 比较字符串 * @param num 比较长度 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const uint pos,const T *str,const int num)const { @@ -625,11 +625,11 @@ namespace hgl } /** - * 和那一个字符串进行比较,英文不区分大小写 + * 和另一个字符串进行比较,英文不区分大小写 * @param bs 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int CaseComp(const SelfClass &bs)const { @@ -645,11 +645,11 @@ namespace hgl } /** - * 和那一个字符串进行比较,英文不区分大小写 + * 和另一个字符串进行比较,英文不区分大小写 * @param str 比较字符串 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int CaseComp(const T *str)const { @@ -665,12 +665,12 @@ namespace hgl } /** - * 和那一个字符串比较指字长度的字符 + * 和另一个字符串比较指定长度的字符 * @param bs 比较字符串 - * @param num 比较字数 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @param num 比较字符数 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const SelfClass &bs,const int num)const { @@ -688,12 +688,12 @@ namespace hgl } /** - * 和那一个字符串比较指字长度的字符 + * 和另一个字符串比较指定长度的字符 * @param str 比较字符串 - * @param num 比较字数 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @param num 比较字符数 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int Comp(const T *str,const int num)const { @@ -709,12 +709,12 @@ namespace hgl } /** - * 和那一个字符串比较指字长度的字符,英文不区分大小写 + * 和另一个字符串比较指定长度的字符,英文不区分大小写 * @param bs 比较字符串 - * @param num 比较字数 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @param num 比较字符数 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int CaseComp(const SelfClass &bs,const int num)const { @@ -725,19 +725,19 @@ namespace hgl return bs.Length(); } - if(bs.Length<=0) + if(bs.Length()<=0) return 1; return data->CaseComp(bs.data->c_str(),num); } /** - * 和那一个字符串比较指字长度的字符,英文不区分大小写 + * 和另一个字符串比较指定长度的字符,英文不区分大小写 * @param str 比较字符串 - * @param num 比较字数 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @param num 比较字符数 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int CaseComp(const T *str,const int num)const { @@ -753,12 +753,12 @@ namespace hgl } /** - * 和那一个字符串比较指字长度的字符,英文不区分大小写 + * 和另一个字符串比较指定长度的字符,英文不区分大小写 * @param str 比较字符串 - * @param num 比较字数 - * @return <0 自身小 - * @return 0 等同 - * @return >0 自身大 + * @param num 比较字符数 + * @return <0 此字符串小于参数字符串 + * @return 0 相等 + * @return >0 此字符串大于参数字符串 */ int CaseComp(const uint pos,const T *str,const int num)const { @@ -932,7 +932,7 @@ namespace hgl * @param sc 新的字符串 * @param start 起始字符索引 * @param n 字符数量 - * @return 成否成功 + * @return 是否成功 */ bool SubString(SelfClass &sc,int start,int n) const ///<取字符串指定段的字符 { diff --git a/inc/hgl/type/StringList.h b/inc/hgl/type/StringList.h index 322c951..5f3a70b 100644 --- a/inc/hgl/type/StringList.h +++ b/inc/hgl/type/StringList.h @@ -192,11 +192,11 @@ namespace hgl } /** - * 查找字符串,英文无视大小写 - * @param str 要指找的字符串 + * 查找字符串,英文不区分大小写 + * @param str 要查找的字符串 * @return 查找到的字符串的索引,未找到返回-1 */ - int CaseFind(const StringClass &str) const ///<查找字符串,英文无视大小写,未找到返回-1 + int CaseFind(const StringClass &str) const ///<查找字符串,英文不区分大小写,未找到返回-1 { const int count=Items.GetCount(); StringClass** sl = Items.GetData(); @@ -211,17 +211,17 @@ namespace hgl } /** - * 确认字符串确在,英文区分大小写 + * 确认字符串存在,英文区分大小写 */ - bool Exist(const StringClass &str) const ///<确认字符串确在,英文区分大小写 + bool Exist(const StringClass &str) const ///<确认字符串存在,英文区分大小写 { return Find(str)!=-1; } /** - * 确认字符串确在,英文无视大小写 + * 确认字符串存在,英文不区分大小写 */ - bool CaseExist(const StringClass &str) const ///<确认字符串确在,英文无视大小写 + bool CaseExist(const StringClass &str) const ///<确认字符串存在,英文不区分大小写 { return CaseFind(str)!=-1; } @@ -248,12 +248,12 @@ namespace hgl } /** - * 查找字符串,英文无视大小写,并指定最大比较长度 - * @param str 要指找的字符串 + * 查找字符串,英文不区分大小写,并指定最大比较长度 + * @param str 要查找的字符串 * @param cn 限定的要查找字符串的最大长度 * @return 查找到的字符串的索引,未找到返回-1 */ - int CaseFind(const StringClass &str,const int cn) const ///<查找字符串,英文无视大小写,未找到返回-1 + int CaseFind(const StringClass &str,const int cn) const ///<查找字符串,英文不区分大小写,未找到返回-1 { const int count=Items.GetCount();