From 59ee637c4c3389c9c1e668f256274e30617fb5d5 Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sun, 9 Sep 2018 12:21:15 +0800 Subject: [PATCH] optimize: Event --- core/Event/KeyEvent.cpp | 2 +- core/Event/MouseEvent.cpp | 19 +++++++++++-------- core/e2devent.h | 7 +------ core/e2dobject.h | 4 ++-- core/modules/Window.cpp | 4 ++-- core/objects/Node.cpp | 8 ++++---- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/core/Event/KeyEvent.cpp b/core/Event/KeyEvent.cpp index a0d627ab..ca124ab2 100644 --- a/core/Event/KeyEvent.cpp +++ b/core/Event/KeyEvent.cpp @@ -1,7 +1,7 @@ #include "..\e2devent.h" -e2d::KeyEvent::KeyEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param) +e2d::KeyEvent::KeyEvent(UINT message, WPARAM w_param, LPARAM l_param) : code_(KeyCode(w_param)) , type_(Type(message)) , count_(static_cast((DWORD)l_param & 0x0000FFFF)) diff --git a/core/Event/MouseEvent.cpp b/core/Event/MouseEvent.cpp index ae71b9f7..55aa3f4d 100644 --- a/core/Event/MouseEvent.cpp +++ b/core/Event/MouseEvent.cpp @@ -1,29 +1,32 @@ #include "..\e2devent.h" #include "..\e2dmodule.h" -e2d::MouseEvent::MouseEvent(HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param, float dpi) +e2d::MouseEvent::MouseEvent(UINT message, WPARAM w_param, LPARAM l_param) : message_(message) , w_param_(w_param) , l_param_(l_param) - , type_(Type(message)) { - pos_.x = ((float)(short)LOWORD(l_param)) * 96.f / dpi; - pos_.y = ((float)(short)HIWORD(l_param)) * 96.f / dpi; } float e2d::MouseEvent::GetX() const { - return pos_.x; + const float dpi = Window::GetInstance()->GetDpi(); + return ((float)(short)LOWORD(l_param_)) * 96.f / dpi; } float e2d::MouseEvent::GetY() const { - return pos_.y; + const float dpi = Window::GetInstance()->GetDpi(); + return ((float)(short)HIWORD(l_param_)) * 96.f / dpi; } e2d::Point e2d::MouseEvent::GetPos() const { - return pos_; + const float dpi = Window::GetInstance()->GetDpi(); + return Point( + ((float)(short)LOWORD(l_param_)) * 96.f / dpi, + ((float)(short)HIWORD(l_param_)) * 96.f / dpi + ); } bool e2d::MouseEvent::IsShiftDown() const @@ -58,5 +61,5 @@ bool e2d::MouseEvent::IsMButtonDown() const e2d::MouseEvent::Type e2d::MouseEvent::GetType() const { - return type_; + return Type(message_); } diff --git a/core/e2devent.h b/core/e2devent.h index da26f2aa..fedb137c 100644 --- a/core/e2devent.h +++ b/core/e2devent.h @@ -18,7 +18,6 @@ namespace e2d public: explicit KeyEvent( - HWND hWnd, UINT message, WPARAM w_param, LPARAM l_param @@ -67,11 +66,9 @@ namespace e2d public: explicit MouseEvent( - HWND hWnd, UINT message, WPARAM w_param, - LPARAM l_param, - float dpi + LPARAM l_param ); // 获取鼠标横坐标 @@ -107,8 +104,6 @@ namespace e2d UINT message_; WPARAM w_param_; LPARAM l_param_; - Point pos_; - MouseEvent::Type type_; }; diff --git a/core/e2dobject.h b/core/e2dobject.h index ce893f58..2c2e8c04 100644 --- a/core/e2dobject.h +++ b/core/e2dobject.h @@ -458,7 +458,7 @@ namespace e2d float GetPosY() const; // 获取节点坐标 - Point GetPos() const; + const Point& GetPos() const; // 获取节点宽度 float GetWidth() const; @@ -473,7 +473,7 @@ namespace e2d float GetRealHeight() const; // 获取节点大小(不考虑缩放) - Size GetRealSize() const; + const Size& GetRealSize() const; // 获取节点的锚点 float GetAnchorX() const; diff --git a/core/modules/Window.cpp b/core/modules/Window.cpp index feac6dd6..2bdb0f75 100644 --- a/core/modules/Window.cpp +++ b/core/modules/Window.cpp @@ -425,7 +425,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT msg, WPARAM w_param, LPARAM l_param if (game->GetCurrentScene()) { - game->GetCurrentScene()->Dispatch(MouseEvent(hWnd, msg, w_param, l_param, window->dpi_), false); + game->GetCurrentScene()->Dispatch(MouseEvent(msg, w_param, l_param), false); } } result = 0; @@ -442,7 +442,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT msg, WPARAM w_param, LPARAM l_param if (game->GetCurrentScene()) { - game->GetCurrentScene()->Dispatch(KeyEvent(hWnd, msg, w_param, l_param), false); + game->GetCurrentScene()->Dispatch(KeyEvent(msg, w_param, l_param), false); } } result = 0; diff --git a/core/objects/Node.cpp b/core/objects/Node.cpp index 6dbdb8e5..0d92e58c 100644 --- a/core/objects/Node.cpp +++ b/core/objects/Node.cpp @@ -381,9 +381,9 @@ float e2d::Node::GetPosY() const return pos_.y; } -e2d::Point e2d::Node::GetPos() const +const e2d::Point& e2d::Node::GetPos() const { - return Point(pos_.x, pos_.y); + return pos_; } float e2d::Node::GetWidth() const @@ -406,9 +406,9 @@ float e2d::Node::GetRealHeight() const return size_.height; } -e2d::Size e2d::Node::GetRealSize() const +const e2d::Size& e2d::Node::GetRealSize() const { - return Size(size_.width, size_.height); + return size_; } float e2d::Node::GetAnchorX() const