refactoring
This commit is contained in:
parent
1f6fa38e81
commit
59ac54063e
|
|
@ -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<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;
|
||||
|
||||
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<const wchar_t*>(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_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ namespace easy2d
|
|||
|
||||
void Out(std::wostream& stream, const wchar_t* output)
|
||||
{
|
||||
stream.imbue(std::locale("chs"));
|
||||
stream << output;
|
||||
::OutputDebugStringW(output);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue