refactoring

This commit is contained in:
Nomango 2019-01-24 22:22:11 +08:00 committed by Nomango
parent 1f6fa38e81
commit 59ac54063e
6 changed files with 82 additions and 57 deletions

View File

@ -337,20 +337,6 @@ namespace easy2d
case WM_SIZE: 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 width = LOWORD(lparam);
UINT height = HIWORD(lparam); UINT height = HIWORD(lparam);
@ -358,38 +344,70 @@ namespace easy2d
// 目标的大小。它可能会调用失败,但是这里可以忽略有可能的 // 目标的大小。它可能会调用失败,但是这里可以忽略有可能的
// 错误,因为这个错误将在下一次调用 EndDraw 时产生 // 错误,因为这个错误将在下一次调用 EndDraw 时产生
RenderSystem::Instance()->Resize(width, height); 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<int>(width);
evt.win.height = static_cast<int>(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; break;
case WM_ACTIVATE: case WM_ACTIVATE:
{ {
bool active = (LOWORD(wparam) != WA_INACTIVE); bool active = (LOWORD(wparam) != WA_INACTIVE);
if (active) if (app->curr_scene_)
{ {
E2D_LOG(L"Window activated"); Event evt(WindowEvent::FocusChanged);
evt.win.focus = active;
if (app->curr_scene_) app->curr_scene_->Dispatch(evt);
{
Event evt(WindowEvent::Activate);
app->curr_scene_->Dispatch(evt);
}
} }
else
{
E2D_LOG(L"Window deactivated");
if (app->curr_scene_) E2D_LOG(active ? L"Window activated" : L"Window deactivated");
{
Event evt(WindowEvent::Deavtivate);
app->curr_scene_->Dispatch(evt);
}
}
} }
break; break;
case WM_SETTEXT: case WM_SETTEXT:
{ {
E2D_LOG(L"Window title changed"); E2D_LOG(L"Window title changed");
if (app->curr_scene_)
{
Event evt(WindowEvent::TitleChanged);
evt.win.title = reinterpret_cast<const wchar_t*>(lparam);
app->curr_scene_->Dispatch(evt);
}
} }
break; break;
@ -409,7 +427,7 @@ namespace easy2d
case WM_CLOSE: case WM_CLOSE:
{ {
E2D_LOG(L"Received a message to close the window"); E2D_LOG(L"Window is closing");
if (app->curr_scene_) if (app->curr_scene_)
{ {

View File

@ -96,13 +96,40 @@ namespace easy2d
{ {
First = WM_NULL, First = WM_NULL,
Activate, // 窗口获得焦点 Moved, // 窗口移动
Deavtivate, // 窗口失去焦点 Resized, // 窗口大小变化
FocusChanged, // 获得或失去焦点
TitleChanged, // 标题变化
Closing, // 关闭窗口 Closing, // 关闭窗口
Last 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) static inline bool Check(EventType type)
{ {
return type > Type::First && type < Type::Last; return type > Type::First && type < Type::Last;

View File

@ -26,8 +26,8 @@ namespace easy2d
{ {
Scene::Scene() Scene::Scene()
{ {
AddListener(WindowEvent::Activate, Closure(this, &Scene::OnActivate)); //AddListener(WindowEvent::Activate, Closure(this, &Scene::OnActivate));
AddListener(WindowEvent::Deavtivate, Closure(this, &Scene::OnDeactivate)); //AddListener(WindowEvent::Deavtivate, Closure(this, &Scene::OnDeactivate));
scene_ = this; scene_ = this;
} }

View File

@ -35,6 +35,7 @@ namespace easy2d
void Out(std::wostream& stream, const wchar_t* output) void Out(std::wostream& stream, const wchar_t* output)
{ {
stream.imbue(std::locale("chs"));
stream << output; stream << output;
::OutputDebugStringW(output); ::OutputDebugStringW(output);
} }

View File

@ -67,24 +67,6 @@ namespace easy2d
return Duration(dur - other.dur); 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 // Duration

View File

@ -138,9 +138,6 @@ namespace easy2d
const Duration operator - (const TimePoint &) const; const Duration operator - (const TimePoint &) const;
TimePoint& operator = (const TimePoint &) E2D_NOEXCEPT;
TimePoint& operator = (TimePoint &&) E2D_NOEXCEPT;
private: private:
long dur; long dur;
}; };