diff --git a/src/core/Application.cpp b/src/core/Application.cpp index f038b211..46ed86ec 100644 --- a/src/core/Application.cpp +++ b/src/core/Application.cpp @@ -337,20 +337,6 @@ namespace easy2d case WM_SIZE: { - if (SIZE_MAXHIDE == wparam || SIZE_MINIMIZED == wparam) - { - app->active_ = false; - - E2D_LOG(L"Window minimized"); - } - else if (SIZE_RESTORED == wparam) - { - app->active_ = true; - ::InvalidateRect(hwnd, nullptr, FALSE); - - E2D_LOG(L"Window restored"); - } - UINT width = LOWORD(lparam); UINT height = HIWORD(lparam); @@ -358,38 +344,70 @@ namespace easy2d // 目标的大小。它可能会调用失败,但是这里可以忽略有可能的 // 错误,因为这个错误将在下一次调用 EndDraw 时产生 RenderSystem::Instance()->Resize(width, height); + + if (SIZE_MAXHIDE == wparam || SIZE_MINIMIZED == wparam) + { + app->active_ = false; + + E2D_LOG(L"Window minimized"); + } + else + { + app->active_ = true; + ::InvalidateRect(hwnd, nullptr, FALSE); + + E2D_LOG(L"Window resized"); + + if (app->curr_scene_) + { + Event evt(WindowEvent::Resized); + evt.win.width = static_cast(width); + evt.win.height = static_cast(height); + app->curr_scene_->Dispatch(evt); + } + } + } + break; + + case WM_MOVE: + { + if (app->curr_scene_) + { + int x = (int)(short)LOWORD(lparam); + int y = (int)(short)HIWORD(lparam); + + Event evt(WindowEvent::Moved); + evt.win.x = x; + evt.win.y = y; + app->curr_scene_->Dispatch(evt); + } } break; case WM_ACTIVATE: { bool active = (LOWORD(wparam) != WA_INACTIVE); - if (active) + if (app->curr_scene_) { - E2D_LOG(L"Window activated"); - - if (app->curr_scene_) - { - Event evt(WindowEvent::Activate); - app->curr_scene_->Dispatch(evt); - } + Event evt(WindowEvent::FocusChanged); + evt.win.focus = active; + app->curr_scene_->Dispatch(evt); } - else - { - E2D_LOG(L"Window deactivated"); - if (app->curr_scene_) - { - Event evt(WindowEvent::Deavtivate); - app->curr_scene_->Dispatch(evt); - } - } + E2D_LOG(active ? L"Window activated" : L"Window deactivated"); } break; case WM_SETTEXT: { E2D_LOG(L"Window title changed"); + + if (app->curr_scene_) + { + Event evt(WindowEvent::TitleChanged); + evt.win.title = reinterpret_cast(lparam); + app->curr_scene_->Dispatch(evt); + } } break; @@ -409,7 +427,7 @@ namespace easy2d case WM_CLOSE: { - E2D_LOG(L"Received a message to close the window"); + E2D_LOG(L"Window is closing"); if (app->curr_scene_) { diff --git a/src/core/Event.hpp b/src/core/Event.hpp index ff2b2638..9ddfa643 100644 --- a/src/core/Event.hpp +++ b/src/core/Event.hpp @@ -96,13 +96,40 @@ namespace easy2d { First = WM_NULL, - Activate, // 窗口获得焦点 - Deavtivate, // 窗口失去焦点 + Moved, // 窗口移动 + Resized, // 窗口大小变化 + FocusChanged, // 获得或失去焦点 + TitleChanged, // 标题变化 Closing, // 关闭窗口 Last }; + union + { + struct // WindowEvent::Moved + { + int x; + int y; + }; + + struct // WindowEvent::Resized + { + int width; + int height; + }; + + struct // WindowEvent::FocusChanged + { + bool focus; + }; + + struct // WindowEvent::TitleChanged + { + const wchar_t* title; + }; + }; + static inline bool Check(EventType type) { return type > Type::First && type < Type::Last; diff --git a/src/core/Scene.cpp b/src/core/Scene.cpp index 2b415262..443fbb38 100644 --- a/src/core/Scene.cpp +++ b/src/core/Scene.cpp @@ -26,8 +26,8 @@ namespace easy2d { Scene::Scene() { - AddListener(WindowEvent::Activate, Closure(this, &Scene::OnActivate)); - AddListener(WindowEvent::Deavtivate, Closure(this, &Scene::OnDeactivate)); + //AddListener(WindowEvent::Activate, Closure(this, &Scene::OnActivate)); + //AddListener(WindowEvent::Deavtivate, Closure(this, &Scene::OnDeactivate)); scene_ = this; } diff --git a/src/core/logs.cpp b/src/core/logs.cpp index 27765486..acd47160 100644 --- a/src/core/logs.cpp +++ b/src/core/logs.cpp @@ -35,6 +35,7 @@ namespace easy2d void Out(std::wostream& stream, const wchar_t* output) { + stream.imbue(std::locale("chs")); stream << output; ::OutputDebugStringW(output); } diff --git a/src/core/time.cpp b/src/core/time.cpp index 5001d22e..4edef49d 100644 --- a/src/core/time.cpp +++ b/src/core/time.cpp @@ -67,24 +67,6 @@ namespace easy2d return Duration(dur - other.dur); } - TimePoint& TimePoint::operator=(const TimePoint & other) E2D_NOEXCEPT - { - if (this == &other) - return *this; - - dur = other.dur; - return *this; - } - - TimePoint& TimePoint::operator=(TimePoint && other) E2D_NOEXCEPT - { - if (this == &other) - return *this; - - dur = std::move(other.dur); - return *this; - } - //------------------------------------------------------- // Duration diff --git a/src/core/time.h b/src/core/time.h index 433098ef..1429c648 100644 --- a/src/core/time.h +++ b/src/core/time.h @@ -138,9 +138,6 @@ namespace easy2d const Duration operator - (const TimePoint &) const; - TimePoint& operator = (const TimePoint &) E2D_NOEXCEPT; - TimePoint& operator = (TimePoint &&) E2D_NOEXCEPT; - private: long dur; };