This commit is contained in:
Nomango 2019-10-12 08:54:10 +08:00
parent 3f9817a20d
commit 63cb724347
4 changed files with 47 additions and 38 deletions

View File

@ -23,6 +23,8 @@
namespace kiwano
{
// ʼþÀàÐÍ
typedef int EventType;
// 鼠标事件
struct MouseEvent
@ -36,7 +38,7 @@ namespace kiwano
{
struct // Events::MouseDown | Events::MouseUp | Events::MouseClick
{
int button;
MouseButton::Value button;
};
struct // Events::MouseWheel
@ -45,7 +47,7 @@ namespace kiwano
};
};
static bool Check(int type);
static bool Check(EventType type);
};
// 键盘事件
@ -56,7 +58,7 @@ namespace kiwano
{
struct // Events::KeyDown | Events::KeyUp
{
int code; // enum KeyCode
KeyCode::Value code;
};
struct // Events::Char
@ -65,7 +67,7 @@ namespace kiwano
};
};
static bool Check(int type);
static bool Check(EventType type);
};
// 窗口事件
@ -96,7 +98,7 @@ namespace kiwano
};
};
static bool Check(int type);
static bool Check(EventType type);
};
// 自定义事件
@ -110,7 +112,7 @@ namespace kiwano
// 事件
struct KGE_API Event
{
enum Type : int
enum Type : EventType
{
First,
@ -155,23 +157,23 @@ namespace kiwano
CustomEvent custom;
};
Event(int type = Type::First) : type(type), target(nullptr) {}
Event(EventType type = Type::First) : type(type), target(nullptr) {}
};
// Check-functions
inline bool MouseEvent::Check(int type)
inline bool MouseEvent::Check(EventType type)
{
return type > Event::MouseFirst && type < Event::MouseLast;
}
inline bool KeyboardEvent::Check(int type)
inline bool KeyboardEvent::Check(EventType type)
{
return type > Event::KeyFirst && type < Event::KeyLast;
}
inline bool WindowEvent::Check(int type)
inline bool WindowEvent::Check(EventType type)
{
return type > Event::WindowFirst && type < Event::WindowLast;
}

View File

@ -196,6 +196,17 @@ namespace kiwano
}
}
void Window::PollEvents()
{
static MSG msg = {};
if (::GetMessageW(&msg, nullptr, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
}
String Window::GetTitle() const
{
if (handle_)

View File

@ -98,6 +98,8 @@ namespace kiwano
void Prepare();
void PollEvents();
HWND GetHandle() const;
DWORD GetWindowStyle() const;

View File

@ -116,19 +116,12 @@ namespace kiwano
{
KGE_ASSERT(inited_ && "Calling Application::Run before Application::Init");
HWND hwnd = Window::GetInstance()->GetHandle();
if (hwnd)
{
end_ = false;
Window::GetInstance()->Prepare();
MSG msg = {};
while (::GetMessageW(&msg, nullptr, 0, 0) && !end_)
Window::GetInstance()->Prepare();
while (!end_)
{
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
Window::GetInstance()->PollEvents();
}
}
@ -444,6 +437,8 @@ namespace kiwano
if (!app->OnClosing())
{
Event evt(Event::WindowClosed);
app->DispatchEvent(evt);
return 0;
}
}
@ -453,8 +448,7 @@ namespace kiwano
{
KGE_LOG(L"Window was destroyed");
Event evt(Event::WindowClosed);
app->DispatchEvent(evt);
app->Quit();
app->OnDestroy();
::PostQuitMessage(0);