From da76c4b4d15816f0484d7bca40293f14e0eeca69 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 24 Jan 2020 15:35:07 +0100 Subject: [PATCH] Adding Win32EventQueue --- source/Platform/Win32/Win32EventQueue.cpp | 79 +++++++++++++++++++++++ source/Platform/Win32/Win32EventQueue.h | 22 +++++++ 2 files changed, 101 insertions(+) create mode 100644 source/Platform/Win32/Win32EventQueue.cpp create mode 100644 source/Platform/Win32/Win32EventQueue.h diff --git a/source/Platform/Win32/Win32EventQueue.cpp b/source/Platform/Win32/Win32EventQueue.cpp new file mode 100644 index 0000000..12af985 --- /dev/null +++ b/source/Platform/Win32/Win32EventQueue.cpp @@ -0,0 +1,79 @@ + +#include +#include "Win32Keyboard.h" +#include "Win32Mouse.h" +#include "Win32EventQueue.h" + +namespace sp { + +bool Win32EventQueue::poll(SysEvent& event) +{ + MSG msg; + + if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + if (processMessage(msg, event) == 0) { + return true; + } + } + return false; +} + +LRESULT Win32EventQueue::processMessage(MSG msg, SysEvent& event) +{ + switch(msg.message) { + case WM_QUIT : + event.type = SysEvent::Quit; + return 0; + // Input, Forward to devices. + case WM_KEYDOWN : + case WM_KEYUP : + OutputDebugString("WM_KEYDOWN\n"); + //SetCapture(msg.hwnd); + + if (Win32Keyboard::handleMessage(msg)) { + // Keyboard did handle the message. + return 0; + } + break; + case WM_MOUSEMOVE : + case WM_MOUSELEAVE : + + if (Win32Mouse::handleMessage(msg)) { + // Mouse did handle the message. + return 0; + } + break; + case WM_LBUTTONDOWN : + case WM_RBUTTONDOWN : + case WM_MBUTTONDOWN : + case WM_XBUTTONDOWN : + + SetCapture(msg.hwnd); + + if (Win32Mouse::handleMessage(msg)) { + // Mouse did handle the message. + return 0; + } + break; + case WM_LBUTTONUP : + case WM_RBUTTONUP : + case WM_MBUTTONUP : + case WM_XBUTTONUP : + + ReleaseCapture(); + + if (Win32Mouse::handleMessage(msg)) { + // Mouse did handle the message. + return 0; + } + break; + default : + break; + } + + // Message was not intercepted. Pass down to window. + return DispatchMessage(&msg); +} + +} // namespace sp diff --git a/source/Platform/Win32/Win32EventQueue.h b/source/Platform/Win32/Win32EventQueue.h new file mode 100644 index 0000000..9b3578d --- /dev/null +++ b/source/Platform/Win32/Win32EventQueue.h @@ -0,0 +1,22 @@ +#ifndef PLATFORM_WIN32_EVENT_QUEUE_H +#define PLATFORM_WIN32_EVENT_QUEUE_H + +#include +#include +#include + +namespace sp { + +class Win32EventQueue : public PlatformEventQueue +{ +public : + virtual bool poll(SysEvent& event); + +private : + + LRESULT processMessage(MSG msg, SysEvent& event); +}; + +} // namespace sp + +#endif /* PLATFORM_WIN32_MESSAGE_QUEUE_H */