Utility: Add CursorController
This commit is contained in:
parent
282538876b
commit
b884f5783c
|
|
@ -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 <Nazara/Prerequesites.hpp>
|
||||||
|
#include <Nazara/Core/HandledObject.hpp>
|
||||||
|
#include <Nazara/Core/ObjectRef.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
|
#include <Nazara/Utility/Cursor.hpp>
|
||||||
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
class CursorController;
|
||||||
|
|
||||||
|
using CursorControllerHandle = Nz::ObjectRef<CursorController>;
|
||||||
|
|
||||||
|
class CursorController : public HandledObject<CursorController>
|
||||||
|
{
|
||||||
|
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 <Nazara/Utility/CursorController.inl>
|
||||||
|
|
||||||
|
#endif // NAZARA_CURSORCONTROLLER_HPP
|
||||||
|
|
@ -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 <Nazara/Utility/CursorController.hpp>
|
||||||
|
#include <Nazara/Utility/Debug.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
inline void CursorController::UpdateCursor(const Cursor& cursor)
|
||||||
|
{
|
||||||
|
OnCursorUpdated(this, cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <Nazara/Utility/DebugOff.hpp>
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Math/Vector2.hpp>
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
#include <Nazara/Utility/Config.hpp>
|
#include <Nazara/Utility/Config.hpp>
|
||||||
|
#include <Nazara/Utility/CursorController.hpp>
|
||||||
#include <Nazara/Utility/Enums.hpp>
|
#include <Nazara/Utility/Enums.hpp>
|
||||||
#include <Nazara/Utility/EventHandler.hpp>
|
#include <Nazara/Utility/EventHandler.hpp>
|
||||||
#include <Nazara/Utility/VideoMode.hpp>
|
#include <Nazara/Utility/VideoMode.hpp>
|
||||||
|
|
@ -35,7 +36,7 @@ namespace Nz
|
||||||
friend class Utility;
|
friend class Utility;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Window();
|
Window();
|
||||||
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||||
inline Window(WindowHandle handle);
|
inline Window(WindowHandle handle);
|
||||||
Window(const Window&) = delete;
|
Window(const Window&) = delete;
|
||||||
|
|
@ -57,7 +58,8 @@ namespace Nz
|
||||||
void EnableKeyRepeat(bool enable);
|
void EnableKeyRepeat(bool enable);
|
||||||
void EnableSmoothScrolling(bool enable);
|
void EnableSmoothScrolling(bool enable);
|
||||||
|
|
||||||
EventHandler& GetEventHandler();
|
inline CursorController& GetCursorController();
|
||||||
|
inline EventHandler& GetEventHandler();
|
||||||
WindowHandle GetHandle() const;
|
WindowHandle GetHandle() const;
|
||||||
unsigned int GetHeight() const;
|
unsigned int GetHeight() const;
|
||||||
Vector2i GetPosition() const;
|
Vector2i GetPosition() const;
|
||||||
|
|
@ -119,6 +121,7 @@ namespace Nz
|
||||||
std::queue<WindowEvent> m_events;
|
std::queue<WindowEvent> m_events;
|
||||||
std::vector<WindowEvent> m_pendingEvents;
|
std::vector<WindowEvent> m_pendingEvents;
|
||||||
ConditionVariable m_eventCondition;
|
ConditionVariable m_eventCondition;
|
||||||
|
CursorController m_cursorController;
|
||||||
EventHandler m_eventHandler;
|
EventHandler m_eventHandler;
|
||||||
Mutex m_eventMutex;
|
Mutex m_eventMutex;
|
||||||
Mutex m_eventConditionMutex;
|
Mutex m_eventConditionMutex;
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,6 @@ namespace Nz
|
||||||
/*!
|
/*!
|
||||||
* \class Nz::Window
|
* \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) :
|
inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) :
|
||||||
Window()
|
Window()
|
||||||
|
|
@ -75,6 +67,11 @@ namespace Nz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline CursorController& Nz::Window::GetCursorController()
|
||||||
|
{
|
||||||
|
return m_cursorController;
|
||||||
|
}
|
||||||
|
|
||||||
inline EventHandler& Nz::Window::GetEventHandler()
|
inline EventHandler& Nz::Window::GetEventHandler()
|
||||||
{
|
{
|
||||||
return m_eventHandler;
|
return m_eventHandler;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,20 @@ namespace Nz
|
||||||
Window* fullscreenWindow = nullptr;
|
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()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue