optimize: Event

This commit is contained in:
Nomango 2018-09-09 12:21:15 +08:00
parent 6732adccfd
commit 59ee637c4c
6 changed files with 21 additions and 23 deletions

View File

@ -1,7 +1,7 @@
#include "..\e2devent.h" #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)) : code_(KeyCode(w_param))
, type_(Type(message)) , type_(Type(message))
, count_(static_cast<int>((DWORD)l_param & 0x0000FFFF)) , count_(static_cast<int>((DWORD)l_param & 0x0000FFFF))

View File

@ -1,29 +1,32 @@
#include "..\e2devent.h" #include "..\e2devent.h"
#include "..\e2dmodule.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) : message_(message)
, w_param_(w_param) , w_param_(w_param)
, l_param_(l_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 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 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 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 bool e2d::MouseEvent::IsShiftDown() const
@ -58,5 +61,5 @@ bool e2d::MouseEvent::IsMButtonDown() const
e2d::MouseEvent::Type e2d::MouseEvent::GetType() const e2d::MouseEvent::Type e2d::MouseEvent::GetType() const
{ {
return type_; return Type(message_);
} }

View File

@ -18,7 +18,6 @@ namespace e2d
public: public:
explicit KeyEvent( explicit KeyEvent(
HWND hWnd,
UINT message, UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param LPARAM l_param
@ -67,11 +66,9 @@ namespace e2d
public: public:
explicit MouseEvent( explicit MouseEvent(
HWND hWnd,
UINT message, UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param
float dpi
); );
// 資函報炎罪恫炎 // 資函報炎罪恫炎
@ -107,8 +104,6 @@ namespace e2d
UINT message_; UINT message_;
WPARAM w_param_; WPARAM w_param_;
LPARAM l_param_; LPARAM l_param_;
Point pos_;
MouseEvent::Type type_;
}; };

View File

@ -458,7 +458,7 @@ namespace e2d
float GetPosY() const; float GetPosY() const;
// 获取节点坐标 // 获取节点坐标
Point GetPos() const; const Point& GetPos() const;
// 获取节点宽度 // 获取节点宽度
float GetWidth() const; float GetWidth() const;
@ -473,7 +473,7 @@ namespace e2d
float GetRealHeight() const; float GetRealHeight() const;
// 获取节点大小(不考虑缩放) // 获取节点大小(不考虑缩放)
Size GetRealSize() const; const Size& GetRealSize() const;
// 获取节点的锚点 // 获取节点的锚点
float GetAnchorX() const; float GetAnchorX() const;

View File

@ -425,7 +425,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT msg, WPARAM w_param, LPARAM l_param
if (game->GetCurrentScene()) 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; result = 0;
@ -442,7 +442,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT msg, WPARAM w_param, LPARAM l_param
if (game->GetCurrentScene()) 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; result = 0;

View File

@ -381,9 +381,9 @@ float e2d::Node::GetPosY() const
return pos_.y; 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 float e2d::Node::GetWidth() const
@ -406,9 +406,9 @@ float e2d::Node::GetRealHeight() const
return size_.height; 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 float e2d::Node::GetAnchorX() const