Platform/Window: Make PushEvent public

This commit is contained in:
Lynix
2019-03-10 15:50:16 +01:00
parent 097d16f664
commit 23b2f0a48d
8 changed files with 118 additions and 28 deletions

View File

@@ -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:
{

View File

@@ -58,6 +58,8 @@ namespace Nz
bool IsMinimized() const;
bool IsVisible() const;
void RefreshCursor();
void ProcessEvents(bool block);
void SetCursor(const Cursor& cursor);

View File

@@ -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();

View File

@@ -412,6 +412,10 @@ namespace Nz
}
}
void WindowImpl::RefreshCursor()
{
}
void WindowImpl::SetCursor(const Cursor& cursor)
{
xcb_cursor_t cursorImpl = cursor.m_impl->GetCursor();

View File

@@ -58,6 +58,8 @@ namespace Nz
bool IsMinimized() const;
bool IsVisible() const;
void RefreshCursor();
void ProcessEvents(bool block);
void SetCursor(const Cursor& cursor);