From 23b2f0a48dd5d84e0d7e8c30da9bacee46e26162 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 10 Mar 2019 15:50:16 +0100 Subject: [PATCH] Platform/Window: Make PushEvent public --- ChangeLog.md | 2 + include/Nazara/Platform/Window.hpp | 14 +++- include/Nazara/Platform/Window.inl | 15 +--- src/Nazara/Platform/Win32/WindowImpl.cpp | 14 ++-- src/Nazara/Platform/Win32/WindowImpl.hpp | 2 + src/Nazara/Platform/Window.cpp | 93 ++++++++++++++++++++++-- src/Nazara/Platform/X11/WindowImpl.cpp | 4 + src/Nazara/Platform/X11/WindowImpl.hpp | 2 + 8 files changed, 118 insertions(+), 28 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 712e89340..0225f87aa 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -164,6 +164,8 @@ Nazara Engine: - Fixed MouseButtonEvent and MouseMoveEvent mouse absolute position being unsigned (now signed) - Fixed Window::SetCursor changing cursor even if window was in foreground on Windows - Fixed SystemCursor_Move not showing up on Windows +- Fixed Window movement constructor/assignation operator +- Window::PushEvent is now public (useful for pushing external events ie. when using Qt or similar framework controlling window) Nazara Development Kit: - Added ImageWidget (#139) diff --git a/include/Nazara/Platform/Window.hpp b/include/Nazara/Platform/Window.hpp index 7eb5f449a..47d416930 100644 --- a/include/Nazara/Platform/Window.hpp +++ b/include/Nazara/Platform/Window.hpp @@ -40,7 +40,7 @@ namespace Nz inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default); inline explicit Window(WindowHandle handle); Window(const Window&) = delete; - Window(Window&&) = default; + Window(Window&& window); virtual ~Window(); inline void Close(); @@ -78,6 +78,8 @@ namespace Nz NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system") bool PollEvent(WindowEvent* event); + void PushEvent(const WindowEvent& event); + void ProcessEvents(bool block = false); void SetCursor(CursorRef cursor); @@ -101,7 +103,7 @@ namespace Nz bool WaitEvent(WindowEvent* event); Window& operator=(const Window&) = delete; - Window& operator=(Window&&) = default; + Window& operator=(Window&& window); protected: virtual bool OnWindowCreated(); @@ -111,13 +113,17 @@ namespace Nz MovablePtr m_impl; private: + void ConnectSlots(); + void DisconnectSlots(); + void IgnoreNextMouseEvent(int mouseX, int mouseY) const; - inline void HandleEvent(const WindowEvent& event); - inline void PushEvent(const WindowEvent& event); + void HandleEvent(const WindowEvent& event); static bool Initialize(); static void Uninitialize(); + NazaraSlot(CursorController, OnCursorUpdated, m_cursorUpdateSlot); + std::queue m_events; std::vector m_pendingEvents; ConditionVariable m_eventCondition; diff --git a/include/Nazara/Platform/Window.inl b/include/Nazara/Platform/Window.inl index 9ce95a78a..1be1a773f 100644 --- a/include/Nazara/Platform/Window.inl +++ b/include/Nazara/Platform/Window.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Platform module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -90,20 +91,6 @@ namespace Nz SetCursor(Cursor::Get(systemCursor)); } - inline void Window::HandleEvent(const WindowEvent& event) - { - if (m_eventPolling) - m_events.push(event); - - m_eventHandler.Dispatch(event); - - if (event.type == WindowEventType_Resized) - OnWindowResized(); - - if (event.type == WindowEventType_Quit && m_closeOnQuit) - Close(); - } - inline void Window::PushEvent(const WindowEvent& event) { if (!m_asyncWindow) diff --git a/src/Nazara/Platform/Win32/WindowImpl.cpp b/src/Nazara/Platform/Win32/WindowImpl.cpp index f22569872..9d7c6e9a6 100644 --- a/src/Nazara/Platform/Win32/WindowImpl.cpp +++ b/src/Nazara/Platform/Win32/WindowImpl.cpp @@ -269,6 +269,11 @@ namespace Nz return IsWindowVisible(m_handle) == TRUE; } + void WindowImpl::RefreshCursor() + { + ::SetCursor(m_cursor); + } + void WindowImpl::ProcessEvents(bool block) { if (m_ownsWindow) @@ -289,9 +294,8 @@ namespace Nz { m_cursor = cursor.m_impl->GetCursor(); - // Applies cursor only if we have focus - if (GetForegroundWindow() == m_handle) - ::SetCursor(m_cursor); + if (HasFocus()) + RefreshCursor(); } void WindowImpl::SetEventListener(bool listener) @@ -405,12 +409,12 @@ namespace Nz break; - case WM_SETCURSOR: + /*case WM_SETCURSOR: // http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx if (LOWORD(lParam) == HTCLIENT) ::SetCursor(m_cursor); - break; + break;*/ case WM_WINDOWPOSCHANGING: { diff --git a/src/Nazara/Platform/Win32/WindowImpl.hpp b/src/Nazara/Platform/Win32/WindowImpl.hpp index b9d18dcd9..e05a86fdf 100644 --- a/src/Nazara/Platform/Win32/WindowImpl.hpp +++ b/src/Nazara/Platform/Win32/WindowImpl.hpp @@ -58,6 +58,8 @@ namespace Nz bool IsMinimized() const; bool IsVisible() const; + void RefreshCursor(); + void ProcessEvents(bool block); void SetCursor(const Cursor& cursor); diff --git a/src/Nazara/Platform/Window.cpp b/src/Nazara/Platform/Window.cpp index 69758cdb0..e3b9c913c 100644 --- a/src/Nazara/Platform/Window.cpp +++ b/src/Nazara/Platform/Window.cpp @@ -33,11 +33,28 @@ namespace Nz m_eventPolling(false), m_waitForEvent(false) { - m_cursorController.OnCursorUpdated.Connect([this](const CursorController*, const CursorRef& cursor) - { - if (IsValid()) - SetCursor(cursor); - }); + ConnectSlots(); + } + + Window::Window(Window&& window) : + m_events(std::move(window.m_events)), + m_pendingEvents(std::move(window.m_pendingEvents)), + m_eventCondition(std::move(window.m_eventCondition)), + m_cursorController(std::move(window.m_cursorController)), + m_cursor(std::move(window.m_cursor)), + m_eventHandler(std::move(window.m_eventHandler)), + m_icon(std::move(window.m_icon)), + m_eventMutex(std::move(window.m_eventMutex)), + m_eventConditionMutex(std::move(window.m_eventConditionMutex)), + m_asyncWindow(window.m_asyncWindow), + m_closed(window.m_asyncWindow), + m_closeOnQuit(window.m_closeOnQuit), + m_eventPolling(window.m_eventPolling), + m_ownsWindow(window.m_asyncWindow), + m_waitForEvent(window.m_waitForEvent) + { + window.DisconnectSlots(); + ConnectSlots(); } Window::~Window() @@ -582,6 +599,30 @@ namespace Nz } } + Window& Window::operator=(Window&& window) + { + m_events = std::move(window.m_events); + m_pendingEvents = std::move(window.m_pendingEvents); + m_eventCondition = std::move(window.m_eventCondition); + m_cursorController = std::move(window.m_cursorController); + m_cursor = std::move(window.m_cursor); + m_eventHandler = std::move(window.m_eventHandler); + m_icon = std::move(window.m_icon); + m_eventMutex = std::move(window.m_eventMutex); + m_eventConditionMutex = std::move(window.m_eventConditionMutex); + m_asyncWindow = window.m_asyncWindow; + m_closed = window.m_asyncWindow; + m_closeOnQuit = window.m_closeOnQuit; + m_eventPolling = window.m_eventPolling; + m_ownsWindow = window.m_asyncWindow; + m_waitForEvent = window.m_waitForEvent; + + window.DisconnectSlots(); + ConnectSlots(); + + return *this; + } + bool Window::OnWindowCreated() { return true; @@ -595,6 +636,20 @@ namespace Nz { } + void Window::ConnectSlots() + { + m_cursorUpdateSlot.Connect(m_cursorController.OnCursorUpdated, [this](const CursorController*, const CursorRef& cursor) + { + if (IsValid()) + SetCursor(cursor); + }); + } + + void Window::DisconnectSlots() + { + m_cursorUpdateSlot.Disconnect(); + } + void Window::IgnoreNextMouseEvent(int mouseX, int mouseY) const { #if NAZARA_PLATFORM_SAFE @@ -608,6 +663,34 @@ namespace Nz m_impl->IgnoreNextMouseEvent(mouseX, mouseY); } + void Window::HandleEvent(const WindowEvent& event) + { + if (m_eventPolling) + m_events.push(event); + + m_eventHandler.Dispatch(event); + + switch (event.type) + { + case WindowEventType_MouseEntered: + m_impl->RefreshCursor(); + break; + + case WindowEventType_Resized: + OnWindowResized(); + break; + + case WindowEventType_Quit: + if (m_closeOnQuit) + Close(); + + break; + + default: + break; + } + } + bool Window::Initialize() { return WindowImpl::Initialize(); diff --git a/src/Nazara/Platform/X11/WindowImpl.cpp b/src/Nazara/Platform/X11/WindowImpl.cpp index 4a5f8208e..0e8215e37 100644 --- a/src/Nazara/Platform/X11/WindowImpl.cpp +++ b/src/Nazara/Platform/X11/WindowImpl.cpp @@ -412,6 +412,10 @@ namespace Nz } } + void WindowImpl::RefreshCursor() + { + } + void WindowImpl::SetCursor(const Cursor& cursor) { xcb_cursor_t cursorImpl = cursor.m_impl->GetCursor(); diff --git a/src/Nazara/Platform/X11/WindowImpl.hpp b/src/Nazara/Platform/X11/WindowImpl.hpp index d9e9d8652..ecf5e0233 100644 --- a/src/Nazara/Platform/X11/WindowImpl.hpp +++ b/src/Nazara/Platform/X11/WindowImpl.hpp @@ -58,6 +58,8 @@ namespace Nz bool IsMinimized() const; bool IsVisible() const; + void RefreshCursor(); + void ProcessEvents(bool block); void SetCursor(const Cursor& cursor);