New module: Platform - Split window management from Utility module (#128)

* New module: Platform - Split window management from Utility module

Final touch

* NDK/SDK: Bring back initialization of Utility
This commit is contained in:
Gawaboumga
2017-08-30 10:22:50 +02:00
committed by Jérôme Leclercq
parent 41a1b5d493
commit 5aa072cee3
125 changed files with 1049 additions and 782 deletions

View File

@@ -0,0 +1,54 @@
/*
Nazara Engine - Platform module
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_PLATFORM_HPP
#define NAZARA_CONFIG_PLATFORM_HPP
/// Each modification of a parameter needs a recompilation of the module
// Use the MemoryManager to manage dynamic allocations (can detect memory leak but allocations/frees are slower)
#define NAZARA_PLATFORM_MANAGE_MEMORY 0
// Activate the security tests based on the code (Advised for development)
#define NAZARA_PLATFORM_SAFE 1
// Protect the classes against data race
//#define NAZARA_PLATFORM_THREADSAFE 1
// On Windows, ALT and F10 keys do not activate the window menu
#define NAZARA_PLATFORM_WINDOWS_DISABLE_MENU_KEYS 1
#if defined(NAZARA_STATIC)
#define NAZARA_PLATFORM_API
#else
#ifdef NAZARA_PLATFORM_BUILD
#define NAZARA_PLATFORM_API NAZARA_EXPORT
#else
#define NAZARA_PLATFORM_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_CONFIG_PLATFORM_HPP

View File

@@ -0,0 +1,23 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONFIG_CHECK_PLATFORM_HPP
#define NAZARA_CONFIG_CHECK_PLATFORM_HPP
/// This file is used to check the constant values defined in Config.hpp
#include <type_traits>
#define NazaraCheckTypeAndVal(name, type, op, val, err) static_assert(std::is_ ##type <decltype(name)>::value && name op val, #type err)
// We force the value of MANAGE_MEMORY in debug
#if defined(NAZARA_DEBUG) && !NAZARA_PLATFORM_MANAGE_MEMORY
#undef NAZARA_PLATFORM_MANAGE_MEMORY
#define NAZARA_PLATFORM_MANAGE_MEMORY 0
#endif
#undef NazaraCheckTypeAndVal
#endif // NAZARA_CONFIG_CHECK_PLATFORM_HPP

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CURSOR_HPP
#define NAZARA_CURSOR_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Utility/Image.hpp>
#include <array>
namespace Nz
{
class CursorImpl;
class Cursor;
using CursorConstRef = ObjectRef<const Cursor>;
using CursorRef = ObjectRef<Cursor>;
class NAZARA_PLATFORM_API Cursor : public RefCounted
{
friend class Platform;
friend class WindowImpl;
public:
inline Cursor();
inline Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
Cursor(const Cursor&) = delete;
Cursor(Cursor&&) = delete;
inline ~Cursor();
bool Create(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder);
void Destroy();
inline const Image& GetImage() const;
inline SystemCursor GetSystemCursor() const;
inline bool IsValid() const;
Cursor& operator=(const Cursor&) = delete;
Cursor& operator=(Cursor&&) = delete;
static inline Cursor* Get(SystemCursor cursor);
template<typename... Args> static CursorRef New(Args&&... args);
private:
inline explicit Cursor(SystemCursor systemCursor);
bool Create(SystemCursor cursor);
static bool Initialize();
static void Uninitialize();
Image m_cursorImage;
SystemCursor m_systemCursor;
CursorImpl* m_impl;
static std::array<Cursor, SystemCursor_Max + 1> s_systemCursors;
};
}
#include <Nazara/Platform/Cursor.inl>
#endif // NAZARA_CURSOR_HPP

View File

@@ -0,0 +1,69 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline Cursor::Cursor() :
m_impl(nullptr)
{
}
inline Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(cursor, hotSpot, placeholder);
}
inline Cursor* Cursor::Get(SystemCursor cursor)
{
return &s_systemCursors[cursor];
}
inline Cursor::Cursor(SystemCursor systemCursor) :
Cursor()
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(systemCursor);
}
inline Cursor::~Cursor()
{
Destroy();
}
inline const Image& Cursor::GetImage() const
{
NazaraAssert(IsValid(), "Invalid cursor");
NazaraAssert(m_cursorImage.IsValid(), "System cursors have no image");
return m_cursorImage;
}
inline SystemCursor Cursor::GetSystemCursor() const
{
NazaraAssert(IsValid(), "Invalid cursor");
return m_systemCursor;
}
inline bool Cursor::IsValid() const
{
return m_impl != nullptr;
}
template<typename... Args>
CursorRef Cursor::New(Args&&... args)
{
std::unique_ptr<Cursor> object(new Cursor(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform 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/ObjectHandle.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Enums.hpp>
namespace Nz
{
class CursorController;
using CursorControllerHandle = ObjectHandle<CursorController>;
class CursorController : public HandledObject<CursorController>
{
public:
CursorController() = default;
CursorController(const CursorController&) = delete;
CursorController(CursorController&&) = default;
~CursorController() = default;
inline void UpdateCursor(const CursorRef& cursor);
CursorController& operator=(const CursorController&) = delete;
CursorController& operator=(CursorController&&) = default;
NazaraSignal(OnCursorUpdated, const CursorController* /*cursorController*/, const CursorRef& /*cursor*/);
};
}
#include <Nazara/Platform/CursorController.inl>
#endif // NAZARA_CURSORCONTROLLER_HPP

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline void CursorController::UpdateCursor(const CursorRef& cursor)
{
OnCursorUpdated(this, cursor);
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Config.hpp>
#if NAZARA_PLATFORM_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@@ -0,0 +1,9 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// We suppose that Debug.hpp is already included, same goes for Config.hpp
#if NAZARA_PLATFORM_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_PLATFORM_HPP
#define NAZARA_ENUMS_PLATFORM_HPP
#include <Nazara/Core/Flags.hpp>
namespace Nz
{
enum SystemCursor
{
SystemCursor_Crosshair,
SystemCursor_Default,
SystemCursor_Hand,
SystemCursor_Help,
SystemCursor_Move,
SystemCursor_None,
SystemCursor_Pointer,
SystemCursor_Progress,
SystemCursor_ResizeE,
SystemCursor_ResizeN,
SystemCursor_ResizeNE,
SystemCursor_ResizeNW,
SystemCursor_ResizeS,
SystemCursor_ResizeSE,
SystemCursor_ResizeSW,
SystemCursor_ResizeW,
SystemCursor_Text,
SystemCursor_Wait,
SystemCursor_Max = SystemCursor_Wait
};
enum WindowEventType
{
WindowEventType_GainedFocus,
WindowEventType_LostFocus,
WindowEventType_KeyPressed,
WindowEventType_KeyReleased,
WindowEventType_MouseButtonDoubleClicked,
WindowEventType_MouseButtonPressed,
WindowEventType_MouseButtonReleased,
WindowEventType_MouseEntered,
WindowEventType_MouseLeft,
WindowEventType_MouseMoved,
WindowEventType_MouseWheelMoved,
WindowEventType_Moved,
WindowEventType_Quit,
WindowEventType_Resized,
WindowEventType_TextEntered,
WindowEventType_Max = WindowEventType_TextEntered
};
enum WindowStyle
{
WindowStyle_None, ///< Window has no border nor titlebar.
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
WindowStyle_Max = WindowStyle_Threaded
};
template<>
struct EnumAsFlags<WindowStyle>
{
static constexpr bool value = true;
static constexpr int max = WindowStyle_Max;
};
using WindowStyleFlags = Flags<WindowStyle>;
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
}
#endif // NAZARA_ENUMS_PLATFORM_HPP

View File

@@ -0,0 +1,121 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspired by the SFML of Laurent Gomila (and its team)
#pragma once
#ifndef NAZARA_EVENT_HPP
#define NAZARA_EVENT_HPP
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp>
namespace Nz
{
struct WindowEvent
{
// Used by:
// -WindowEventType_KeyPressed
// -WindowEventType_KeyReleased
struct KeyEvent
{
Keyboard::Key code;
bool alt;
bool control;
bool repeated;
bool shift;
bool system;
};
// Used by:
// -WindowEventType_MouseButtonDoubleClicked
// -WindowEventType_MouseButtonPressed
struct MouseButtonEvent
{
Mouse::Button button;
unsigned int x;
unsigned int y;
};
// Used by:
// -WindowEventType_MouseMoved
struct MouseMoveEvent
{
int deltaX;
int deltaY;
unsigned int x;
unsigned int y;
};
// Used by:
// -WindowEventType_MouseWheelMoved
struct MouseWheelEvent
{
float delta;
};
// Used by:
// -WindowEventType_Moved
struct PositionEvent
{
int x;
int y;
};
// Used by:
// -WindowEventType_Resized
struct SizeEvent
{
unsigned int height;
unsigned int width;
};
// Used by:
// -WindowEventType_TextEntered
struct TextEvent
{
bool repeated;
char32_t character;
};
WindowEventType type;
union
{
// Used by:
// -WindowEventType_KeyPressed
// -WindowEventType_KeyReleased
KeyEvent key;
// Used by:
// -WindowEventType_MouseButtonDoubleClicked
// -WindowEventType_MouseButtonPressed
MouseButtonEvent mouseButton;
// Used by:
// -WindowEventType_MouseMoved
MouseMoveEvent mouseMove;
// Used by:
// -WindowEventType_MouseWheelMoved
MouseWheelEvent mouseWheel;
// Used by:
// -WindowEventType_Moved
PositionEvent position;
// Used by:
// -WindowEventType_Resized
SizeEvent size;
// Used by:
// -WindowEventType_TextEntered
TextEvent text;
};
};
}
#endif // NAZARA_EVENT_HPP

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_EVENTHANDLER_HPP
#define NAZARA_EVENTHANDLER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HandledObject.hpp>
#include <Nazara/Core/ObjectHandle.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Event.hpp>
namespace Nz
{
class EventHandler;
using EventHandlerHandle = ObjectHandle<EventHandler>;
class EventHandler : public HandledObject<EventHandler>
{
public:
EventHandler() = default;
explicit EventHandler(const EventHandler&);
EventHandler(EventHandler&&) = default;
~EventHandler() = default;
inline void Dispatch(const WindowEvent& event);
EventHandler& operator=(const EventHandler&) = delete;
EventHandler& operator=(EventHandler&&) = default;
NazaraSignal(OnEvent, const EventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnKeyPressed, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnKeyReleased, const EventHandler* /*eventHandler*/, const WindowEvent::KeyEvent& /*event*/);
NazaraSignal(OnMouseButtonDoubleClicked, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonPressed, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseButtonReleased, const EventHandler* /*eventHandler*/, const WindowEvent::MouseButtonEvent& /*event*/);
NazaraSignal(OnMouseEntered, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseLeft, const EventHandler* /*eventHandler*/);
NazaraSignal(OnMouseMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseMoveEvent& /*event*/);
NazaraSignal(OnMouseWheelMoved, const EventHandler* /*eventHandler*/, const WindowEvent::MouseWheelEvent& /*event*/);
NazaraSignal(OnMoved, const EventHandler* /*eventHandler*/, const WindowEvent::PositionEvent& /*event*/);
NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
};
}
#include <Nazara/Platform/EventHandler.inl>
#endif // NAZARA_EVENTHANDLER_HPP

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/EventHandler.hpp>
#include <memory>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
inline EventHandler::EventHandler(const EventHandler& other) :
HandledObject(other)
{
}
inline void EventHandler::Dispatch(const WindowEvent& event)
{
OnEvent(this, event);
switch (event.type)
{
case WindowEventType_GainedFocus:
OnGainedFocus(this);
break;
case WindowEventType_KeyPressed:
OnKeyPressed(this, event.key);
break;
case WindowEventType_KeyReleased:
OnKeyReleased(this, event.key);
break;
case WindowEventType_LostFocus:
OnLostFocus(this);
break;
case WindowEventType_MouseButtonDoubleClicked:
OnMouseButtonDoubleClicked(this, event.mouseButton);
break;
case WindowEventType_MouseButtonPressed:
OnMouseButtonPressed(this, event.mouseButton);
break;
case WindowEventType_MouseButtonReleased:
OnMouseButtonReleased(this, event.mouseButton);
break;
case WindowEventType_MouseEntered:
OnMouseEntered(this);
break;
case WindowEventType_MouseLeft:
OnMouseLeft(this);
break;
case WindowEventType_MouseMoved:
OnMouseMoved(this, event.mouseMove);
break;
case WindowEventType_MouseWheelMoved:
OnMouseWheelMoved(this, event.mouseWheel);
break;
case WindowEventType_Moved:
OnMoved(this, event.position);
break;
case WindowEventType_Quit:
OnQuit(this);
break;
case WindowEventType_Resized:
OnResized(this, event.size);
break;
case WindowEventType_TextEntered:
OnTextEntered(this, event.text);
break;
}
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -0,0 +1,47 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ICON_HPP
#define NAZARA_ICON_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
namespace Nz
{
class Image;
class IconImpl;
class Icon;
using IconRef = ObjectRef<Icon>;
class NAZARA_PLATFORM_API Icon : public RefCounted
{
friend class WindowImpl;
public:
inline Icon();
inline explicit Icon(const Image& icon);
inline ~Icon();
bool Create(const Image& icon);
void Destroy();
inline bool IsValid() const;
template<typename... Args> static IconRef New(Args&&... args);
private:
IconImpl* m_impl;
};
}
#include <Nazara/Platform/Icon.inl>
#endif // NAZARA_ICON_HPP

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
Icon::Icon() :
m_impl(nullptr)
{
}
inline Icon::Icon(const Image& icon)
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(icon);
}
Icon::~Icon()
{
Destroy();
}
bool Icon::IsValid() const
{
return m_impl != nullptr;
}
template<typename... Args>
IconRef Icon::New(Args&&... args)
{
std::unique_ptr<Icon> object(new Icon(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_JOYSTICK_HPP
#define NAZARA_JOYSTICK_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
namespace Nz
{
class NAZARA_PLATFORM_API Joystick
{
public:
Joystick() = delete;
~Joystick() = delete;
static unsigned int GetMaxJoystickCount();
static void Update();
};
}
#endif // NAZARA_JOYSTICK_HPP

View File

@@ -0,0 +1,175 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspired by the SFML of Laurent Gomila (and its team)
#pragma once
#ifndef NAZARA_KEYBOARD_HPP
#define NAZARA_KEYBOARD_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Platform/Config.hpp>
namespace Nz
{
class NAZARA_PLATFORM_API Keyboard
{
public:
enum Key
{
Undefined = -1,
// Lettres
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
// Functional keys
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
// Directional keys
Down,
Left,
Right,
Up,
// Numerical pad
Add,
Decimal,
Divide,
Multiply,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
Subtract,
// Various
Backslash,
Backspace,
Clear,
Comma,
Dash,
Delete,
End,
Equal,
Escape,
Home,
Insert,
LAlt,
LBracket,
LControl,
LShift,
LSystem,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
PageDown,
PageUp,
Pause,
Period,
Print,
PrintScreen,
Quote,
RAlt,
RBracket,
RControl,
Return,
RShift,
RSystem,
Semicolon,
Slash,
Space,
Tab,
Tilde,
// Navigator keys
Browser_Back,
Browser_Favorites,
Browser_Forward,
Browser_Home,
Browser_Refresh,
Browser_Search,
Browser_Stop,
// Lecture control keys
Media_Next,
Media_Play,
Media_Previous,
Media_Stop,
// Volume control keys
Volume_Down,
Volume_Mute,
Volume_Up,
// Locking keys
CapsLock,
NumLock,
ScrollLock,
Count
};
Keyboard() = delete;
~Keyboard() = delete;
static String GetKeyName(Key key);
static bool IsKeyPressed(Key key);
};
}
#endif // NAZARA_KEYBOARD_HPP

View File

@@ -0,0 +1,47 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspired by the SFML of Laurent Gomila (and its team)
#pragma once
#ifndef NAZARA_MOUSE_HPP
#define NAZARA_MOUSE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
namespace Nz
{
class Window;
class NAZARA_PLATFORM_API Mouse
{
public:
enum Button
{
Left,
Middle,
Right,
XButton1,
XButton2,
Max = XButton2
};
Mouse() = delete;
~Mouse() = delete;
static Vector2i GetPosition();
static Vector2i GetPosition(const Window& relativeTo);
static bool IsButtonPressed(Button button);
static void SetPosition(const Vector2i& position);
static void SetPosition(const Vector2i& position, const Window& relativeTo, bool ignoreEvent = true);
static void SetPosition(int x, int y);
static void SetPosition(int x, int y, const Window& relativeTo, bool ignoreEvent = true);
};
}
#endif // NAZARA_MOUSE_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PLATFORM_HPP
#define NAZARA_PLATFORM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Platform/Config.hpp>
namespace Nz
{
class NAZARA_PLATFORM_API Platform
{
public:
Platform() = delete;
~Platform() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCounter;
};
}
#endif // NAZARA_PLATFORM_HPP

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_VIDEOMODE_HPP
#define NAZARA_VIDEOMODE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Platform/Config.hpp>
#include <vector>
namespace Nz
{
class NAZARA_PLATFORM_API VideoMode
{
public:
VideoMode();
VideoMode(unsigned int w, unsigned int h);
VideoMode(unsigned int w, unsigned int h, UInt8 bpp);
bool IsFullscreenValid() const;
UInt8 bitsPerPixel;
unsigned int height;
unsigned int width;
static VideoMode GetDesktopMode();
static const std::vector<VideoMode>& GetFullscreenModes();
};
bool operator==(const VideoMode& left, const VideoMode& right);
bool operator!=(const VideoMode& left, const VideoMode& right);
bool operator<(const VideoMode& left, const VideoMode& right);
bool operator<=(const VideoMode& left, const VideoMode& right);
bool operator>(const VideoMode& left, const VideoMode& right);
bool operator>=(const VideoMode& left, const VideoMode& right);
}
#endif // NAZARA_VIDEOMODE_HPP

View File

@@ -0,0 +1,143 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_WINDOW_HPP
#define NAZARA_WINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/CursorController.hpp>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/EventHandler.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/WindowHandle.hpp>
#include <queue>
namespace Nz
{
class Image;
class WindowImpl;
class NAZARA_PLATFORM_API Window
{
friend WindowImpl;
friend class Mouse;
friend class Platform;
public:
Window();
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
inline explicit Window(WindowHandle handle);
Window(const Window&) = delete;
inline Window(Window&& window) noexcept;
virtual ~Window();
inline void Close();
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
bool Create(WindowHandle handle);
void Destroy();
inline void EnableCloseOnQuit(bool closeOnQuit);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
inline void EnableEventPolling(bool enable);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
inline const CursorRef& GetCursor() const;
inline CursorController& GetCursorController();
inline EventHandler& GetEventHandler();
WindowHandle GetHandle() const;
unsigned int GetHeight() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
WindowStyleFlags GetStyle() const;
String GetTitle() const;
unsigned int GetWidth() const;
bool HasFocus() const;
bool IsMinimized() const;
inline bool IsOpen(bool checkClosed = true);
inline bool IsOpen() const;
inline bool IsValid() const;
bool IsVisible() const;
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool PollEvent(WindowEvent* event);
void ProcessEvents(bool block = false);
void SetCursor(CursorRef cursor);
inline void SetCursor(SystemCursor systemCursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(IconRef icon);
void SetMaximumSize(const Vector2i& maxSize);
void SetMaximumSize(int width, int height);
void SetMinimumSize(const Vector2i& minSize);
void SetMinimumSize(int width, int height);
void SetPosition(const Vector2i& position);
void SetPosition(int x, int y);
void SetSize(const Vector2i& size);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const String& title);
void SetVisible(bool visible);
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
bool WaitEvent(WindowEvent* event);
Window& operator=(const Window&) = delete;
inline Window& operator=(Window&& window);
protected:
virtual bool OnWindowCreated();
virtual void OnWindowDestroy();
virtual void OnWindowResized();
WindowImpl* m_impl;
private:
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
inline void HandleEvent(const WindowEvent& event);
inline void PushEvent(const WindowEvent& event);
static bool Initialize();
static void Uninitialize();
std::queue<WindowEvent> m_events;
std::vector<WindowEvent> m_pendingEvents;
ConditionVariable m_eventCondition;
CursorController m_cursorController;
CursorRef m_cursor;
EventHandler m_eventHandler;
IconRef m_icon;
Mutex m_eventMutex;
Mutex m_eventConditionMutex;
bool m_asyncWindow;
bool m_closed;
bool m_closeOnQuit;
bool m_eventPolling;
bool m_ownsWindow;
bool m_waitForEvent;
};
}
#include <Nazara/Platform/Window.inl>
#endif // NAZARA_WINDOW_HPP

View File

@@ -0,0 +1,176 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Platform/Debug.hpp>
namespace Nz
{
/*!
* \class Nz::Window
*/
inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) :
Window()
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(mode, title, style);
}
inline Window::Window(WindowHandle handle) :
Window()
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
Create(handle);
}
/*!
* \brief Constructs a Window object by moving another one
*/
inline Window::Window(Window&& window) noexcept :
m_impl(window.m_impl),
m_events(std::move(window.m_events)),
m_pendingEvents(std::move(window.m_pendingEvents)),
m_eventCondition(std::move(window.m_eventCondition)),
m_eventHandler(std::move(window.m_eventHandler)),
m_eventMutex(std::move(window.m_eventMutex)),
m_eventConditionMutex(std::move(window.m_eventConditionMutex)),
m_closed(window.m_closed),
m_closeOnQuit(window.m_closeOnQuit),
m_eventPolling(window.m_eventPolling),
m_ownsWindow(window.m_ownsWindow),
m_waitForEvent(window.m_waitForEvent)
{
window.m_impl = nullptr;
}
inline void Window::Close()
{
m_closed = true; // The window will be closed at the next non-const IsOpen() call
}
inline void Window::EnableCloseOnQuit(bool closeOnQuit)
{
m_closeOnQuit = closeOnQuit;
}
inline void Window::EnableEventPolling(bool enable)
{
m_eventPolling = enable;
if (!m_eventPolling)
{
while (!m_events.empty())
m_events.pop();
}
}
inline const CursorRef& Window::GetCursor() const
{
return m_cursor;
}
inline CursorController& Nz::Window::GetCursorController()
{
return m_cursorController;
}
inline EventHandler& Nz::Window::GetEventHandler()
{
return m_eventHandler;
}
inline bool Window::IsOpen(bool checkClosed)
{
if (!m_impl)
return false;
if (checkClosed && m_closed)
{
Destroy();
return false;
}
return true;
}
inline bool Window::IsOpen() const
{
return m_impl != nullptr;
}
inline bool Window::IsValid() const
{
return m_impl != nullptr;
}
inline void Window::SetCursor(SystemCursor systemCursor)
{
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)
HandleEvent(event);
else
{
{
LockGuard eventLock(m_eventMutex);
m_pendingEvents.push_back(event);
}
if (m_waitForEvent)
{
m_eventConditionMutex.Lock();
m_eventCondition.Signal();
m_eventConditionMutex.Unlock();
}
}
}
/*!
* \brief Moves a window to another window object
* \return A reference to the object
*/
inline Window& Window::operator=(Window&& window)
{
Destroy();
m_closed = window.m_closed;
m_closeOnQuit = window.m_closeOnQuit;
m_eventCondition = std::move(window.m_eventCondition);
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
m_eventHandler = std::move(window.m_eventHandler);
m_eventMutex = std::move(window.m_eventMutex);
m_eventPolling = window.m_eventPolling;
m_impl = window.m_impl;
m_events = std::move(window.m_events);
m_pendingEvents = std::move(window.m_pendingEvents);
m_ownsWindow = window.m_ownsWindow;
m_waitForEvent = window.m_waitForEvent;
window.m_impl = nullptr;
return *this;
}
}
#include <Nazara/Platform/DebugOff.hpp>

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_WINDOWHANDLE_HPP
#define NAZARA_WINDOWHANDLE_HPP
#include <Nazara/Prerequesites.hpp>
#if defined(NAZARA_PLATFORM_X11)
#include <xcb/xcb.h>
#endif
namespace Nz
{
#if defined(NAZARA_PLATFORM_WINDOWS)
// http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx
typedef void* WindowHandle;
#elif defined(NAZARA_PLATFORM_X11)
// http://en.wikipedia.org/wiki/Xlib#Data_types
using WindowHandle = xcb_window_t;
#else
#error Lack of implementation: WindowHandle
#endif
}
#endif // NAZARA_WINDOWHANDLE_HPP