From b884f5783c87fc438cc83279ef3f7751cd57532b Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 19 Jan 2017 14:17:26 +0100 Subject: [PATCH] Utility: Add CursorController --- include/Nazara/Utility/CursorController.hpp | 42 +++++++++++++++++++++ include/Nazara/Utility/CursorController.inl | 16 ++++++++ include/Nazara/Utility/Window.hpp | 7 +++- include/Nazara/Utility/Window.inl | 13 +++---- src/Nazara/Utility/Window.cpp | 14 +++++++ 5 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 include/Nazara/Utility/CursorController.hpp create mode 100644 include/Nazara/Utility/CursorController.inl diff --git a/include/Nazara/Utility/CursorController.hpp b/include/Nazara/Utility/CursorController.hpp new file mode 100644 index 000000000..0f0e54f23 --- /dev/null +++ b/include/Nazara/Utility/CursorController.hpp @@ -0,0 +1,42 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_CURSORCONTROLLER_HPP +#define NAZARA_CURSORCONTROLLER_HPP + +#include +#include +#include +#include +#include +#include + +namespace Nz +{ + class CursorController; + + using CursorControllerHandle = Nz::ObjectRef; + + class CursorController : public HandledObject + { + public: + CursorController() = default; + CursorController(const CursorController&) = delete; + CursorController(CursorController&&) = default; + ~CursorController() = default; + + inline void UpdateCursor(const Cursor& cursor); + + CursorController& operator=(const CursorController&) = delete; + CursorController& operator=(CursorController&&) = default; + + NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const Cursor& /*cursor*/); + }; +} + +#include + +#endif // NAZARA_CURSORCONTROLLER_HPP diff --git a/include/Nazara/Utility/CursorController.inl b/include/Nazara/Utility/CursorController.inl new file mode 100644 index 000000000..0d6f2402d --- /dev/null +++ b/include/Nazara/Utility/CursorController.inl @@ -0,0 +1,16 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Utility module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include + +namespace Nz +{ + inline void CursorController::UpdateCursor(const Cursor& cursor) + { + OnCursorUpdated(this, cursor); + } +} + +#include diff --git a/include/Nazara/Utility/Window.hpp b/include/Nazara/Utility/Window.hpp index 3dbf9897b..ae7b876f9 100644 --- a/include/Nazara/Utility/Window.hpp +++ b/include/Nazara/Utility/Window.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,7 @@ namespace Nz friend class Utility; public: - inline Window(); + Window(); inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default); inline Window(WindowHandle handle); Window(const Window&) = delete; @@ -57,7 +58,8 @@ namespace Nz void EnableKeyRepeat(bool enable); void EnableSmoothScrolling(bool enable); - EventHandler& GetEventHandler(); + inline CursorController& GetCursorController(); + inline EventHandler& GetEventHandler(); WindowHandle GetHandle() const; unsigned int GetHeight() const; Vector2i GetPosition() const; @@ -119,6 +121,7 @@ namespace Nz std::queue m_events; std::vector m_pendingEvents; ConditionVariable m_eventCondition; + CursorController m_cursorController; EventHandler m_eventHandler; Mutex m_eventMutex; Mutex m_eventConditionMutex; diff --git a/include/Nazara/Utility/Window.inl b/include/Nazara/Utility/Window.inl index 0fce86ba6..cf820b8fb 100644 --- a/include/Nazara/Utility/Window.inl +++ b/include/Nazara/Utility/Window.inl @@ -12,14 +12,6 @@ namespace Nz /*! * \class Nz::Window */ - inline Window::Window() : - m_impl(nullptr), - m_asyncWindow(false), - m_closeOnQuit(true), - m_eventPolling(false), - m_waitForEvent(false) - { - } inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) : Window() @@ -75,6 +67,11 @@ namespace Nz } } + inline CursorController& Nz::Window::GetCursorController() + { + return m_cursorController; + } + inline EventHandler& Nz::Window::GetEventHandler() { return m_eventHandler; diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index 61ca49c80..043258e26 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -29,6 +29,20 @@ namespace Nz Window* fullscreenWindow = nullptr; } + Window::Window() : + m_impl(nullptr), + m_asyncWindow(false), + m_closeOnQuit(true), + m_eventPolling(false), + m_waitForEvent(false) + { + m_cursorController.OnCursorUpdated.Connect([this](const CursorController*, const Cursor& cursor) + { + if (IsValid()) + SetCursor(cursor); + }); + } + Window::~Window() { Destroy();