Merge pull request #202 from REMqb/SDL2

~ SDL2 implementation
This commit is contained in:
Jérôme Leclercq 2020-05-27 16:25:09 +02:00 committed by GitHub
commit ab6227cf1a
69 changed files with 3654 additions and 1331 deletions

2
.gitignore vendored
View File

@ -165,3 +165,5 @@ DocProject/Help/*.hhk
DocProject/Help/*.hhp DocProject/Help/*.hhp
DocProject/Help/Html2 DocProject/Help/Html2
DocProject/Help/html DocProject/Help/html
build/gmake/

View File

@ -126,6 +126,7 @@ namespace Ndk
virtual void OnMouseExit(); virtual void OnMouseExit();
virtual void OnParentResized(const Nz::Vector2f& newSize); virtual void OnParentResized(const Nz::Vector2f& newSize);
virtual void OnTextEntered(char32_t character, bool repeated); virtual void OnTextEntered(char32_t character, bool repeated);
virtual void OnTextEdited(const std::array<char, 32>& characters, int length);
inline void SetPreferredSize(const Nz::Vector2f& preferredSize); inline void SetPreferredSize(const Nz::Vector2f& preferredSize);

View File

@ -57,6 +57,7 @@ namespace Ndk
void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); void OnEventKeyPressed(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event); void OnEventKeyReleased(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::KeyEvent& event);
void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event); void OnEventTextEntered(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::TextEvent& event);
void OnEventTextEdited(const Nz::EventHandler* eventHandler, const Nz::WindowEvent::EditEvent& event);
struct WidgetEntry struct WidgetEntry
{ {
@ -73,6 +74,7 @@ namespace Ndk
NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot); NazaraSlot(Nz::EventHandler, OnMouseMoved, m_mouseMovedSlot);
NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot); NazaraSlot(Nz::EventHandler, OnMouseWheelMoved, m_mouseWheelMovedSlot);
NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot); NazaraSlot(Nz::EventHandler, OnTextEntered, m_textEnteredSlot);
NazaraSlot(Nz::EventHandler, OnTextEdited, m_textEditedSlot);
std::size_t m_keyboardOwner; std::size_t m_keyboardOwner;
std::size_t m_hoveredWidget; std::size_t m_hoveredWidget;

View File

@ -28,6 +28,7 @@ namespace Ndk
m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved); m_mouseMovedSlot.Connect(eventHandler.OnMouseMoved, this, &Canvas::OnEventMouseMoved);
m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved); m_mouseWheelMovedSlot.Connect(eventHandler.OnMouseWheelMoved, this, &Canvas::OnEventMouseWheelMoved);
m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered); m_textEnteredSlot.Connect(eventHandler.OnTextEntered, this, &Canvas::OnEventTextEntered);
m_textEditedSlot.Connect(eventHandler.OnTextEdited, this, &Canvas::OnEventTextEdited);
} }
inline Canvas::~Canvas() inline Canvas::~Canvas()

View File

@ -209,7 +209,7 @@ namespace Ndk
overlay->keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&consoleRef] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) overlay->keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&consoleRef] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event)
{ {
if (event.code == Nz::Keyboard::F9) if (event.virtualKey == Nz::Keyboard::VKey::F9)
{ {
// Toggle console visibility and focus // Toggle console visibility and focus
if (consoleRef.IsVisible()) if (consoleRef.IsVisible())

View File

@ -312,6 +312,10 @@ namespace Ndk
{ {
} }
void BaseWidget::OnTextEdited(const std::array<char, 32>& /*characters*/, int /*length*/)
{
}
void BaseWidget::ShowChildren(bool show) void BaseWidget::ShowChildren(bool show)
{ {
for (const auto& widgetPtr : m_children) for (const auto& widgetPtr : m_children)

View File

@ -157,7 +157,7 @@ namespace Ndk
if (m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event)) if (m_widgetEntries[m_keyboardOwner].widget->OnKeyPressed(event))
return; return;
if (event.code == Nz::Keyboard::Tab) if (event.virtualKey == Nz::Keyboard::VKey::Tab)
{ {
if (!event.shift) if (!event.shift)
{ {
@ -221,4 +221,10 @@ namespace Ndk
if (m_keyboardOwner != InvalidCanvasIndex) if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated); m_widgetEntries[m_keyboardOwner].widget->OnTextEntered(event.character, event.repeated);
} }
void Canvas::OnEventTextEdited(const Nz::EventHandler* /*eventHandler*/, const Nz::WindowEvent::EditEvent& event)
{
if (m_keyboardOwner != InvalidCanvasIndex)
m_widgetEntries[m_keyboardOwner].widget->OnTextEdited(event.text, event.length);
}
} }

View File

@ -17,8 +17,8 @@ namespace Ndk
/*********************************** Nz::Keyboard **********************************/ /*********************************** Nz::Keyboard **********************************/
keyboard.Reset("Keyboard"); keyboard.Reset("Keyboard");
{ {
keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName); //keyboard.BindStaticMethod("GetKeyName", &Nz::Keyboard::GetKeyName);
keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed); //keyboard.BindStaticMethod("IsKeyPressed", &Nz::Keyboard::IsKeyPressed);
} }
} }
@ -31,9 +31,9 @@ namespace Ndk
{ {
keyboard.Register(state); keyboard.Register(state);
keyboard.PushGlobalTable(state); /*keyboard.PushGlobalTable(state);
{ {
static_assert(Nz::Keyboard::Count == 121, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding"); static_assert(Nz::Keyboard::Max == 123, "Nz::Keyboard::Key has been updated but change was not reflected to Lua binding");
state.PushField("Undefined", Nz::Keyboard::Undefined); state.PushField("Undefined", Nz::Keyboard::Undefined);
@ -63,6 +63,7 @@ namespace Ndk
state.PushField("Divide", Nz::Keyboard::Divide); state.PushField("Divide", Nz::Keyboard::Divide);
state.PushField("Multiply", Nz::Keyboard::Multiply); state.PushField("Multiply", Nz::Keyboard::Multiply);
state.PushField("Subtract", Nz::Keyboard::Subtract); state.PushField("Subtract", Nz::Keyboard::Subtract);
state.PushField("NumpadReturn", Nz::Keyboard::NumpadReturn);
state.PushField("Backslash", Nz::Keyboard::Backslash); state.PushField("Backslash", Nz::Keyboard::Backslash);
state.PushField("Backspace", Nz::Keyboard::Backspace); state.PushField("Backspace", Nz::Keyboard::Backspace);
@ -98,6 +99,8 @@ namespace Ndk
state.PushField("Space", Nz::Keyboard::Space); state.PushField("Space", Nz::Keyboard::Space);
state.PushField("Tab", Nz::Keyboard::Tab); state.PushField("Tab", Nz::Keyboard::Tab);
state.PushField("Tilde", Nz::Keyboard::Tilde); state.PushField("Tilde", Nz::Keyboard::Tilde);
state.PushField("Menu", Nz::Keyboard::Menu);
state.PushField("ISOBackslash102", Nz::Keyboard::ISOBackslash102);
state.PushField("Browser_Back", Nz::Keyboard::Browser_Back); state.PushField("Browser_Back", Nz::Keyboard::Browser_Back);
state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites); state.PushField("Browser_Favorites", Nz::Keyboard::Browser_Favorites);
state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward); state.PushField("Browser_Forward", Nz::Keyboard::Browser_Forward);
@ -116,7 +119,7 @@ namespace Ndk
state.PushField("NumLock", Nz::Keyboard::NumLock); state.PushField("NumLock", Nz::Keyboard::NumLock);
state.PushField("ScrollLock", Nz::Keyboard::ScrollLock); state.PushField("ScrollLock", Nz::Keyboard::ScrollLock);
} }
state.Pop(); state.Pop();*/
static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding"); static_assert(Nz::WindowStyle_Max + 1 == 6, "Nz::WindowStyle has been updated but change was not reflected to Lua binding");
state.PushTable(0, Nz::WindowStyle_Max + 1); state.PushTable(0, Nz::WindowStyle_Max + 1);

View File

@ -24,3 +24,6 @@ ServerMode = false
-- Builds modules as one united library (useless on POSIX systems) -- Builds modules as one united library (useless on POSIX systems)
UniteModules = false UniteModules = false
-- Use SDL2 platform
PlatformSDL2 = true

View File

@ -388,6 +388,7 @@ function NazaraBuild:Initialize()
if (f) then if (f) then
MODULE = {} MODULE = {}
self:SetupModuleTable(MODULE) self:SetupModuleTable(MODULE)
Config = self.Config
f() f()
@ -530,6 +531,7 @@ function NazaraBuild:LoadConfig()
AddBoolOption("PremakeProject", "premakeproject", "Add a PremakeProject as a shortcut to call Premake") AddBoolOption("PremakeProject", "premakeproject", "Add a PremakeProject as a shortcut to call Premake")
AddBoolOption("ServerMode", "server", "Excludes client-only modules/tools/examples") AddBoolOption("ServerMode", "server", "Excludes client-only modules/tools/examples")
AddBoolOption("UniteModules", "united", "Builds all the modules as one united library") AddBoolOption("UniteModules", "united", "Builds all the modules as one united library")
AddBoolOption("PlatformSDL2", "platform-sdl2", "Use SDL2 instead of native APIs")
-- AdditionalCompilationOptions -- AdditionalCompilationOptions
do do

View File

@ -7,6 +7,19 @@ MODULE.Libraries = {
"NazaraUtility" "NazaraUtility"
} }
if (Config.PlatformSDL2) then
table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2")
table.insert(MODULE.Files, "../src/Nazara/Platform/SDL2/**.hpp")
table.insert(MODULE.Files, "../src/Nazara/Platform/SDL2/**.cpp")
table.insert(MODULE.Libraries, "SDL2")
MODULE.FilesExcluded = {
"../src/Nazara/Platform/Win32/**",
"../src/Nazara/Platform/X11/**"
}
else
MODULE.OsFiles.Windows = { MODULE.OsFiles.Windows = {
"../src/Nazara/Platform/Win32/**.hpp", "../src/Nazara/Platform/Win32/**.hpp",
"../src/Nazara/Platform/Win32/**.cpp" "../src/Nazara/Platform/Win32/**.cpp"
@ -31,3 +44,4 @@ MODULE.OsLibraries.Posix = {
"xcb-randr" "xcb-randr"
} }
end

View File

@ -12,6 +12,19 @@ MODULE.Libraries = {
"NazaraPlatform" "NazaraPlatform"
} }
if (Config.PlatformSDL2) then
table.insert(MODULE.Defines, "NAZARA_PLATFORM_SDL2")
table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.hpp")
table.insert(MODULE.Files, "../src/Nazara/Renderer/SDL2/**.cpp")
table.insert(MODULE.Libraries, "SDL2")
MODULE.FilesExcluded = {
"../src/Nazara/Renderer/Win32/**",
"../src/Nazara/Renderer/GLX/**.cpp"
}
else
MODULE.OsFiles.Windows = { MODULE.OsFiles.Windows = {
"../src/Nazara/Renderer/Win32/**.hpp", "../src/Nazara/Renderer/Win32/**.hpp",
"../src/Nazara/Renderer/Win32/**.cpp" "../src/Nazara/Renderer/Win32/**.cpp"
@ -32,3 +45,4 @@ MODULE.OsLibraries.Posix = {
"GL", "GL",
"X11" "X11"
} }
end

View File

@ -70,7 +70,7 @@ int main()
std::cout << "Sound position: " << pos << std::endl; std::cout << "Sound position: " << pos << std::endl;
// Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap
if (pos.x > Nz::Vector3f::Left().x*-50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Escape)) if (pos.x > Nz::Vector3f::Left().x*-50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape))
sound.Stop(); // On arrête le son (Stoppant également la boucle) sound.Stop(); // On arrête le son (Stoppant également la boucle)
clock.Restart(); clock.Restart();

View File

@ -9,3 +9,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = { EXAMPLE.Libraries = {
"NazaraSDK" "NazaraSDK"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -301,9 +301,9 @@ int main()
eventHandler.OnKeyPressed.Connect([&targetPos, &cameraNode, &smoothMovement, &window](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event) eventHandler.OnKeyPressed.Connect([&targetPos, &cameraNode, &smoothMovement, &window](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& event)
{ {
// Une touche a été pressée ! // Une touche a été pressée !
if (event.code == Nz::Keyboard::Key::Escape) if (event.virtualKey == Nz::Keyboard::VKey::Escape)
window.Close(); window.Close();
else if (event.code == Nz::Keyboard::F1) else if (event.virtualKey == Nz::Keyboard::VKey::F1)
{ {
if (smoothMovement) if (smoothMovement)
{ {
@ -344,34 +344,34 @@ int main()
if (move) if (move)
{ {
// Si la touche espace est enfoncée, notre vitesse de déplacement est multipliée par deux // Si la touche espace est enfoncée, notre vitesse de déplacement est multipliée par deux
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Space)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Space))
cameraSpeed *= 2.f; cameraSpeed *= 2.f;
// Pour que nos déplacement soient liés à la rotation de la caméra, nous allons utiliser // Pour que nos déplacement soient liés à la rotation de la caméra, nous allons utiliser
// les directions locales de la caméra // les directions locales de la caméra
// Si la flèche du haut ou la touche Z (vive ZQSD !!) est pressée, on avance // Si la flèche du haut ou la touche Z (vive ZQSD !!) est pressée, on avance
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Z)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Up) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Z))
targetPos += cameraNode.GetForward() * cameraSpeed; targetPos += cameraNode.GetForward() * cameraSpeed;
// Si la flèche du bas ou la touche S est pressée, on recule // Si la flèche du bas ou la touche S est pressée, on recule
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::S)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Down) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::S))
targetPos += cameraNode.GetBackward() * cameraSpeed; targetPos += cameraNode.GetBackward() * cameraSpeed;
// Etc... // Etc...
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Q)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Left) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Q))
targetPos += cameraNode.GetLeft() * cameraSpeed; targetPos += cameraNode.GetLeft() * cameraSpeed;
// Etc... // Etc...
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::D)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Right) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::D))
targetPos += cameraNode.GetRight() * cameraSpeed; targetPos += cameraNode.GetRight() * cameraSpeed;
// Majuscule pour monter, notez l'utilisation d'une direction globale (Non-affectée par la rotation) // Majuscule pour monter, notez l'utilisation d'une direction globale (Non-affectée par la rotation)
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RShift)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LShift) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RShift))
targetPos += Nz::Vector3f::Up() * cameraSpeed; targetPos += Nz::Vector3f::Up() * cameraSpeed;
// Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc... // Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc...
if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::RControl)) if (Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::LControl) || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::RControl))
targetPos += Nz::Vector3f::Down() * cameraSpeed; targetPos += Nz::Vector3f::Down() * cameraSpeed;
} }

View File

@ -16,3 +16,7 @@ EXAMPLE.Libraries = {
"NazaraRenderer", "NazaraRenderer",
"NazaraUtility" "NazaraUtility"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -12,3 +12,6 @@ EXAMPLE.Libraries = {
"NazaraUtility" "NazaraUtility"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -680,6 +680,7 @@ void SpacebattleExample::Leave(Ndk::StateMachine& fsm)
{ {
m_ambientMusic.Stop(); m_ambientMusic.Stop();
m_onMouseMoved.Disconnect(); m_onMouseMoved.Disconnect();
if (m_shared.target)
m_shared.target->SetCursor(Nz::SystemCursor_Default); m_shared.target->SetCursor(Nz::SystemCursor_Default);
m_shared.world3D->RemoveSystem<LaserBeamSystem>(); m_shared.world3D->RemoveSystem<LaserBeamSystem>();
m_shared.world3D->RemoveSystem<SpaceshipSystem>(); m_shared.world3D->RemoveSystem<SpaceshipSystem>();

View File

@ -11,3 +11,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = { EXAMPLE.Libraries = {
"NazaraSDK" "NazaraSDK"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -123,17 +123,17 @@ int main()
{ {
case Nz::WindowEventType_KeyPressed: case Nz::WindowEventType_KeyPressed:
{ {
switch (event.key.code) switch (event.key.virtualKey)
{ {
case Nz::Keyboard::Backspace: case Nz::Keyboard::VKey::Backspace:
stateMachine.ChangeState(shared.demos[demoIndex]); stateMachine.ChangeState(shared.demos[demoIndex]);
break; break;
case Nz::Keyboard::Escape: case Nz::Keyboard::VKey::Escape:
app.Quit(); app.Quit();
break; break;
case Nz::Keyboard::Left: case Nz::Keyboard::VKey::Left:
{ {
if (shared.demos.size() <= 1) if (shared.demos.size() <= 1)
break; break;
@ -146,7 +146,7 @@ int main()
break; break;
} }
case Nz::Keyboard::Right: case Nz::Keyboard::VKey::Right:
{ {
if (shared.demos.size() <= 1) if (shared.demos.size() <= 1)
break; break;
@ -159,14 +159,14 @@ int main()
break; break;
} }
case Nz::Keyboard::Pause: case Nz::Keyboard::VKey::Pause:
{ {
auto& velocitySystem = shared.world3D->GetSystem<Ndk::VelocitySystem>(); auto& velocitySystem = shared.world3D->GetSystem<Ndk::VelocitySystem>();
velocitySystem.Enable(!velocitySystem.IsEnabled()); velocitySystem.Enable(!velocitySystem.IsEnabled());
break; break;
} }
case Nz::Keyboard::F5: case Nz::Keyboard::VKey::F5:
{ {
Nz::Image screenshot; Nz::Image screenshot;
screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080); screenshot.Create(Nz::ImageType_2D, Nz::PixelFormatType_RGBA8, 1920, 1080);
@ -197,5 +197,7 @@ int main()
window.Display(); window.Display();
} }
shared.target = nullptr;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -20,3 +20,7 @@ EXAMPLE.Libraries = {
"NazaraUtility", "NazaraUtility",
"NazaraSDK" "NazaraSDK"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -9,3 +9,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = { EXAMPLE.Libraries = {
"NazaraSDK" "NazaraSDK"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -9,3 +9,7 @@ EXAMPLE.Files = {
EXAMPLE.Libraries = { EXAMPLE.Libraries = {
"NazaraSDK" "NazaraSDK"
} }
if Config.PlatformSDL2 then
table.insert(EXAMPLE.Defines, "NAZARA_PLATFORM_SDL2")
end

View File

@ -33,10 +33,10 @@ int main(int argc, char* argv[])
Nz::EventHandler& eventHandler = mainWindow.GetEventHandler(); Nz::EventHandler& eventHandler = mainWindow.GetEventHandler();
eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e) eventHandler.OnKeyPressed.Connect([](const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& e)
{ {
std::cout << Nz::Keyboard::GetKeyName(e.code) << std::endl; std::cout << Nz::Keyboard::GetKeyName(e.virtualKey) << std::endl;
// Profitons-en aussi pour nous donner un moyen de quitter le programme // Profitons-en aussi pour nous donner un moyen de quitter le programme
if (e.code == Nz::Keyboard::Escape) if (e.virtualKey == Nz::Keyboard::VKey::Escape)
Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application Ndk::Application::Instance()->Quit(); // Cette ligne casse la boucle Run() de l'application
}); });

View File

@ -51,6 +51,7 @@ namespace Nz
WindowEventType_Moved, WindowEventType_Moved,
WindowEventType_Quit, WindowEventType_Quit,
WindowEventType_Resized, WindowEventType_Resized,
WindowEventType_TextEdited,
WindowEventType_TextEntered, WindowEventType_TextEntered,
WindowEventType_Max = WindowEventType_TextEntered WindowEventType_Max = WindowEventType_TextEntered

View File

@ -9,6 +9,8 @@
#ifndef NAZARA_EVENT_HPP #ifndef NAZARA_EVENT_HPP
#define NAZARA_EVENT_HPP #define NAZARA_EVENT_HPP
#include <array>
#include <Nazara/Platform/Enums.hpp> #include <Nazara/Platform/Enums.hpp>
#include <Nazara/Platform/Keyboard.hpp> #include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp> #include <Nazara/Platform/Mouse.hpp>
@ -22,7 +24,8 @@ namespace Nz
// -WindowEventType_KeyReleased // -WindowEventType_KeyReleased
struct KeyEvent struct KeyEvent
{ {
Keyboard::Key code; Keyboard::Scancode scancode;
Keyboard::VKey virtualKey;
bool alt; bool alt;
bool control; bool control;
bool repeated; bool repeated;
@ -83,6 +86,14 @@ namespace Nz
char32_t character; char32_t character;
}; };
// Used by:
// -WindowEventType_TextEdited
struct EditEvent
{
int length;
std::array<char, 32> text;
};
WindowEventType type; WindowEventType type;
union union
@ -116,6 +127,10 @@ namespace Nz
// Used by: // Used by:
// -WindowEventType_TextEntered // -WindowEventType_TextEntered
TextEvent text; TextEvent text;
// Used by:
// -WindowEventType_TextEntered
EditEvent edit;
}; };
}; };
} }

View File

@ -49,6 +49,7 @@ namespace Nz
NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/); NazaraSignal(OnQuit, const EventHandler* /*eventHandler*/);
NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/); NazaraSignal(OnResized, const EventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& /*event*/);
NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/); NazaraSignal(OnTextEntered, const EventHandler* /*eventHandler*/, const WindowEvent::TextEvent& /*event*/);
NazaraSignal(OnTextEdited, const EventHandler* /*eventHandler*/, const WindowEvent::EditEvent& /*event*/);
}; };
} }

View File

@ -78,6 +78,10 @@ namespace Nz
case WindowEventType_TextEntered: case WindowEventType_TextEntered:
OnTextEntered(this, event.text); OnTextEntered(this, event.text);
break; break;
case WindowEventType_TextEdited:
OnTextEdited(this, event.edit);
break;
} }
} }
} }

View File

@ -18,7 +18,7 @@ namespace Nz
class NAZARA_PLATFORM_API Keyboard class NAZARA_PLATFORM_API Keyboard
{ {
public: public:
enum Key enum class Scancode
{ {
Undefined = -1, Undefined = -1,
@ -78,6 +78,7 @@ namespace Nz
Decimal, Decimal,
Divide, Divide,
Multiply, Multiply,
NumpadReturn,
Numpad0, Numpad0,
Numpad1, Numpad1,
Numpad2, Numpad2,
@ -135,6 +136,8 @@ namespace Nz
Space, Space,
Tab, Tab,
Tilde, Tilde,
Menu,
ISOBackslash102,
// Navigator keys // Navigator keys
Browser_Back, Browser_Back,
@ -161,14 +164,169 @@ namespace Nz
NumLock, NumLock,
ScrollLock, ScrollLock,
Count Max = ScrollLock
};
enum class VKey
{
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,
NumpadReturn,
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,
Menu,
ISOBackslash102,
// 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,
Max = ScrollLock
}; };
Keyboard() = delete; Keyboard() = delete;
~Keyboard() = delete; ~Keyboard() = delete;
static String GetKeyName(Key key); static String GetKeyName(Scancode scancode);
static bool IsKeyPressed(Key key); static String GetKeyName(VKey key);
static bool IsKeyPressed(Scancode scancode);
static bool IsKeyPressed(VKey key);
static void StartTextInput();
static void StopTextInput();
static Scancode ToScanCode(VKey key);
static VKey ToVirtualKey(Scancode key);
}; };
} }

View File

@ -32,12 +32,12 @@ namespace Nz
static const std::vector<VideoMode>& GetFullscreenModes(); static const std::vector<VideoMode>& GetFullscreenModes();
}; };
bool operator==(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator==(const VideoMode& left, const VideoMode& right);
bool operator!=(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator!=(const VideoMode& left, const VideoMode& right);
bool operator<(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator<(const VideoMode& left, const VideoMode& right);
bool operator<=(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator<=(const VideoMode& left, const VideoMode& right);
bool operator>(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator>(const VideoMode& left, const VideoMode& right);
bool operator>=(const VideoMode& left, const VideoMode& right); bool NAZARA_PLATFORM_API operator>=(const VideoMode& left, const VideoMode& right);
} }
#endif // NAZARA_VIDEOMODE_HPP #endif // NAZARA_VIDEOMODE_HPP

View File

@ -8,13 +8,17 @@
#define NAZARA_WINDOWHANDLE_HPP #define NAZARA_WINDOWHANDLE_HPP
#include <Nazara/Prerequisites.hpp> #include <Nazara/Prerequisites.hpp>
#if defined(NAZARA_PLATFORM_X11) #if defined(NAZARA_PLATFORM_SDL2)
#elif defined(NAZARA_PLATFORM_X11)
#include <xcb/xcb.h> #include <xcb/xcb.h>
#endif #endif
namespace Nz namespace Nz
{ {
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
// Real type is SDL_Window
using WindowHandle = void*;
#elif defined(NAZARA_PLATFORM_WINDOWS)
// http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx
using WindowHandle = void*; using WindowHandle = void*;
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)

View File

@ -117,9 +117,12 @@
#endif #endif
#elif defined(__linux__) || defined(__unix__) #elif defined(__linux__) || defined(__unix__)
#define NAZARA_PLATFORM_LINUX #define NAZARA_PLATFORM_LINUX
#define NAZARA_PLATFORM_GLX
#define NAZARA_PLATFORM_POSIX #define NAZARA_PLATFORM_POSIX
#ifndef NAZARA_PLATFORM_SDL2
#define NAZARA_PLATFORM_GLX
#define NAZARA_PLATFORM_X11 #define NAZARA_PLATFORM_X11
#endif
#define NAZARA_EXPORT __attribute__((visibility ("default"))) #define NAZARA_EXPORT __attribute__((visibility ("default")))
#define NAZARA_IMPORT __attribute__((visibility ("default"))) #define NAZARA_IMPORT __attribute__((visibility ("default")))

View File

@ -6,12 +6,11 @@
#ifndef NAZARA_OPENGL_HPP #ifndef NAZARA_OPENGL_HPP
#define NAZARA_OPENGL_HPP #define NAZARA_OPENGL_HPP
#ifdef NAZARA_RENDERER_OPENGL #ifdef NAZARA_RENDERER_OPENGL
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#include <Nazara/Math/Rect.hpp> #include <Nazara/Math/Rect.hpp>
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/Config.hpp> #include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Enums.hpp> #include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp> #include <Nazara/Utility/Enums.hpp>
@ -21,6 +20,10 @@
#include <GL/glcorearb.h> #include <GL/glcorearb.h>
#include <GL/glext.h> #include <GL/glext.h>
#if defined(NAZARA_PLATFORM_SDL2)
#include <SDL2/SDL_video.h>
#endif
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
#include <GL/wglext.h> #include <GL/wglext.h>
#elif defined(NAZARA_PLATFORM_GLX) #elif defined(NAZARA_PLATFORM_GLX)
@ -346,6 +349,8 @@ NAZARA_RENDERER_API extern GLX::PFNGLXSWAPINTERVALSGIPROC glXSwapInterva
} }
#undef None
#endif // NAZARA_RENDERER_OPENGL #endif // NAZARA_RENDERER_OPENGL
#endif // NAZARA_OPENGL_HPP #endif // NAZARA_OPENGL_HPP

View File

@ -4,7 +4,9 @@
#include <Nazara/Platform/Cursor.hpp> #include <Nazara/Platform/Cursor.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/CursorImpl.hpp> #include <Nazara/Platform/Win32/CursorImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/CursorImpl.hpp> #include <Nazara/Platform/X11/CursorImpl.hpp>

View File

@ -4,7 +4,9 @@
#include <Nazara/Platform/Icon.hpp> #include <Nazara/Platform/Icon.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/IconImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/IconImpl.hpp> #include <Nazara/Platform/Win32/IconImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/IconImpl.hpp> #include <Nazara/Platform/X11/IconImpl.hpp>

View File

@ -4,7 +4,9 @@
#include <Nazara/Platform/Keyboard.hpp> #include <Nazara/Platform/Keyboard.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/InputImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/InputImpl.hpp> #include <Nazara/Platform/Win32/InputImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/InputImpl.hpp> #include <Nazara/Platform/X11/InputImpl.hpp>
@ -16,13 +18,43 @@
namespace Nz namespace Nz
{ {
String Keyboard::GetKeyName(Key key) String Keyboard::GetKeyName(Scancode scancode)
{
return EventImpl::GetKeyName(scancode);
}
String Keyboard::GetKeyName(VKey key)
{ {
return EventImpl::GetKeyName(key); return EventImpl::GetKeyName(key);
} }
bool Keyboard::IsKeyPressed(Key key) bool Keyboard::IsKeyPressed(Scancode scancode)
{
return EventImpl::IsKeyPressed(scancode);
}
bool Keyboard::IsKeyPressed(VKey key)
{ {
return EventImpl::IsKeyPressed(key); return EventImpl::IsKeyPressed(key);
} }
void Keyboard::StartTextInput()
{
EventImpl::StartTextInput();
}
void Keyboard::StopTextInput()
{
EventImpl::StopTextInput();
}
Keyboard::Scancode Keyboard::ToScanCode(VKey key)
{
return EventImpl::ToScanCode(key);
}
Keyboard::VKey Keyboard::ToVirtualKey(Scancode scancode)
{
return EventImpl::ToVirtualKey(scancode);
}
} }

View File

@ -5,7 +5,9 @@
#include <Nazara/Platform/Mouse.hpp> #include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Platform/Window.hpp> #include <Nazara/Platform/Window.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/InputImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/InputImpl.hpp> #include <Nazara/Platform/Win32/InputImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/InputImpl.hpp> #include <Nazara/Platform/X11/InputImpl.hpp>

View File

@ -0,0 +1,108 @@
// 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/Core/Error.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
namespace Nz
{
bool CursorImpl::Create(const Image& cursor, int hotSpotX, int hotSpotY)
{
m_iconImage = cursor;
if (!m_iconImage.Convert(PixelFormatType_BGRA8))
{
NazaraError("Failed to convert icon to BGRA8");
return false;
}
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
m_iconImage.GetPixels(),
m_iconImage.GetWidth(),
m_iconImage.GetHeight(),
32,
32 * m_iconImage.GetWidth(),
SDL_PIXELFORMAT_BGRA8888
);
if (!m_icon)
{
NazaraError(SDL_GetError());
return false;
}
m_cursor = SDL_CreateColorCursor(m_icon, hotSpotX, hotSpotY);
if (!m_cursor)
{
NazaraError(SDL_GetError());
return false;
}
return true;
}
bool CursorImpl::Create(SystemCursor cursor)
{
if (cursor != SystemCursor_None)
m_cursor = SDL_CreateSystemCursor(s_systemCursorIds[cursor]);
else
m_cursor = nullptr;
m_icon = nullptr;
return true;
}
void CursorImpl::Destroy()
{
if (m_icon)
SDL_FreeSurface(m_icon);
if (m_cursor)
SDL_FreeCursor(m_cursor);
}
SDL_Cursor* CursorImpl::GetCursor()
{
return m_cursor;
}
bool CursorImpl::Initialize()
{
return true;
}
void CursorImpl::Uninitialize()
{
}
std::array<SDL_SystemCursor, SystemCursor_Max + 1> CursorImpl::s_systemCursorIds =
{
SDL_SYSTEM_CURSOR_CROSSHAIR, // SystemCursor_Crosshair
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Default
SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Hand
SDL_SYSTEM_CURSOR_ARROW, // SystemCursor_Help
SDL_SYSTEM_CURSOR_SIZEALL, // SystemCursor_Move
SDL_NUM_SYSTEM_CURSORS, // SystemCursor_None
SDL_SYSTEM_CURSOR_HAND, // SystemCursor_Pointer
SDL_SYSTEM_CURSOR_WAITARROW, // SystemCursor_Progress
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeE
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeN
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeNE
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeNW
SDL_SYSTEM_CURSOR_SIZENS, // SystemCursor_ResizeS
SDL_SYSTEM_CURSOR_SIZENWSE, // SystemCursor_ResizeSE
SDL_SYSTEM_CURSOR_SIZENESW, // SystemCursor_ResizeSW
SDL_SYSTEM_CURSOR_SIZEWE, // SystemCursor_ResizeW
SDL_SYSTEM_CURSOR_IBEAM, // SystemCursor_Text
SDL_SYSTEM_CURSOR_WAIT // SystemCursor_Wait
};
static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete");
}

View File

@ -0,0 +1,45 @@
// 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_CURSORIMPL_HPP
#define NAZARA_CURSORIMPL_HPP
#include <array>
#include <Nazara/Platform/Enums.hpp>
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
#include <SDL2/SDL_mouse.h>
namespace Nz
{
class Image;
class CursorImpl
{
friend class Cursor;
public:
bool Create(const Image& image, int hotSpotX, int hotSpotY);
bool Create(SystemCursor cursor);
void Destroy();
SDL_Cursor* GetCursor();
private:
static bool Initialize();
static void Uninitialize();
SDL_Cursor* m_cursor = nullptr;
SDL_Surface* m_icon = nullptr;
Image m_iconImage;
static std::array<SDL_SystemCursor, SystemCursor_Max + 1> s_systemCursorIds;
};
}
#endif // NAZARA_CURSORIMPL_HPP

View File

@ -0,0 +1,49 @@
// 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/Debug.hpp>
#include <Nazara/Platform/SDL2/IconImpl.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
namespace Nz
{
bool IconImpl::Create(const Image& icon)
{
m_iconImage = icon;
if (!m_iconImage.Convert(PixelFormatType_BGRA8))
{
NazaraError("Failed to convert icon to BGRA8");
return false;
}
m_icon = SDL_CreateRGBSurfaceWithFormatFrom(
m_iconImage.GetPixels(),
m_iconImage.GetWidth(),
m_iconImage.GetHeight(),
32,
32 * m_iconImage.GetWidth(),
SDL_PIXELFORMAT_BGRA8888
);
if (!m_icon)
{
NazaraError(SDL_GetError());
return false;
}
return true;
}
void IconImpl::Destroy()
{
SDL_FreeSurface(m_icon);
m_iconImage.Destroy();
}
SDL_Surface* IconImpl::GetIcon()
{
return m_icon;
}
}

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_ICONIMPL_HPP
#define NAZARA_ICONIMPL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/Image.hpp>
#include <SDL2/SDL_surface.h>
namespace Nz
{
class Image;
class IconImpl
{
public:
bool Create(const Image& image);
void Destroy();
SDL_Surface* GetIcon();
private:
SDL_Surface* m_icon = nullptr;
Image m_iconImage;
};
}
#endif // NAZARA_ICONIMPL_HPP

View File

@ -0,0 +1,122 @@
// 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/Core/Error.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/SDL2/InputImpl.hpp>
#include <Nazara/Platform/SDL2/SDLHelper.hpp>
#include <Nazara/Platform/Window.hpp>
#include <SDL2/SDL_keyboard.h>
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_mouse.h>
namespace Nz
{
String EventImpl::GetKeyName(Keyboard::Scancode key)
{
SDL_Scancode scancode = SDLHelper::ToSDL(key);
String name;
if (scancode != SDL_SCANCODE_UNKNOWN)
name = SDL_GetScancodeName(scancode);
return !name.IsEmpty() ? name : String::Unicode("Unknown");
}
String EventImpl::GetKeyName(Keyboard::VKey key)
{
SDL_Keycode vkey = SDLHelper::ToSDL(key);
String name;
if (vkey != SDLK_UNKNOWN)
name = SDL_GetKeyName(vkey);
return !name.IsEmpty() ? name : String::Unicode("Unknown");
}
Vector2i EventImpl::GetMousePosition()
{
Vector2i pos;
SDL_GetGlobalMouseState(&pos.x, &pos.y);
return pos;
}
Vector2i EventImpl::GetMousePosition(const Window& relativeTo)
{
auto handle = relativeTo.GetHandle();
if (handle)
{
auto windowPos = relativeTo.GetPosition();
auto mousePos = GetMousePosition();
return mousePos - windowPos;
}
else
{
NazaraError("Invalid window handle");
// Attention que (-1, -1) est une position tout à fait valide et ne doit pas servir de test
return Vector2i(-1, -1);
}
}
bool EventImpl::IsKeyPressed(Keyboard::Scancode key)
{
return SDL_GetKeyboardState(nullptr)[SDLHelper::ToSDL(key)];
}
bool EventImpl::IsKeyPressed(Keyboard::VKey key)
{
return IsKeyPressed(ToScanCode(key));
}
bool EventImpl::IsMouseButtonPressed(Mouse::Button button)
{
static int vButtons[Mouse::Max + 1] = {
SDL_BUTTON_LMASK, // Button::Left
SDL_BUTTON_MMASK, // Button::Middle
SDL_BUTTON_RMASK, // Button::Right
SDL_BUTTON_X1MASK, // Button::XButton1
SDL_BUTTON_X2MASK // Button::XButton2
};
return (SDL_GetGlobalMouseState(nullptr, nullptr) & vButtons[button]) != 0;
}
void EventImpl::SetMousePosition(int x, int y)
{
if (SDL_WarpMouseGlobal(x, y) != 0)
NazaraWarning(SDL_GetError());
}
void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo)
{
auto handle = static_cast<SDL_Window*>(relativeTo.GetHandle());
if (handle)
SDL_WarpMouseInWindow(handle, x, y);
else
NazaraError("Invalid window handle");
}
void EventImpl::StartTextInput()
{
SDL_StartTextInput();
}
void EventImpl::StopTextInput()
{
SDL_StopTextInput();
}
Keyboard::Scancode EventImpl::ToScanCode(Keyboard::VKey key)
{
return SDLHelper::FromSDL(SDL_GetScancodeFromKey(SDLHelper::ToSDL(key)));
}
Keyboard::VKey EventImpl::ToVirtualKey(Keyboard::Scancode scancode)
{
return SDLHelper::FromSDL(SDL_GetKeyFromScancode(SDLHelper::ToSDL(scancode)));
}
}

View File

@ -0,0 +1,36 @@
// 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_INPUTIMPL_HPP
#define NAZARA_INPUTIMPL_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp>
namespace Nz
{
class EventImpl
{
public:
static String GetKeyName(Keyboard::Scancode scancode);
static String GetKeyName(Keyboard::VKey key);
static Vector2i GetMousePosition();
static Vector2i GetMousePosition(const Window& relativeTo);
static bool IsKeyPressed(Keyboard::Scancode key);
static bool IsKeyPressed(Keyboard::VKey key);
static bool IsMouseButtonPressed(Mouse::Button button);
static void SetMousePosition(int x, int y);
static void SetMousePosition(int x, int y, const Window& relativeTo);
static void StartTextInput();
static void StopTextInput();
static Keyboard::Scancode ToScanCode(Keyboard::VKey key);
static Keyboard::VKey ToVirtualKey(Keyboard::Scancode scancode);
};
}
#endif // NAZARA_INPUTIMPL_HPP

View File

@ -0,0 +1,586 @@
// 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/SDL2/SDLHelper.hpp>
namespace Nz
{
namespace
{
SDL_Scancode nzScancodeToSDLScanCode[static_cast<std::size_t>(Keyboard::VKey::Max) + 1] = {
// Lettres
SDL_SCANCODE_A, // Key::A
SDL_SCANCODE_B, // Key::B
SDL_SCANCODE_C, // Key::C
SDL_SCANCODE_D, // Key::D
SDL_SCANCODE_E, // Key::E
SDL_SCANCODE_F, // Key::F
SDL_SCANCODE_G, // Key::G
SDL_SCANCODE_H, // Key::H
SDL_SCANCODE_I, // Key::I
SDL_SCANCODE_J, // Key::J
SDL_SCANCODE_K, // Key::K
SDL_SCANCODE_L, // Key::L
SDL_SCANCODE_M, // Key::M
SDL_SCANCODE_N, // Key::N
SDL_SCANCODE_O, // Key::O
SDL_SCANCODE_P, // Key::P
SDL_SCANCODE_Q, // Key::Q
SDL_SCANCODE_R, // Key::R
SDL_SCANCODE_S, // Key::S
SDL_SCANCODE_T, // Key::T
SDL_SCANCODE_U, // Key::U
SDL_SCANCODE_V, // Key::V
SDL_SCANCODE_W, // Key::W
SDL_SCANCODE_X, // Key::X
SDL_SCANCODE_Y, // Key::Y
SDL_SCANCODE_Z, // Key::Z
// Touches de fonction
SDL_SCANCODE_F1, // Key::F1
SDL_SCANCODE_F2, // Key::F2
SDL_SCANCODE_F3, // Key::F3
SDL_SCANCODE_F4, // Key::F4
SDL_SCANCODE_F5, // Key::F5
SDL_SCANCODE_F6, // Key::F6
SDL_SCANCODE_F7, // Key::F7
SDL_SCANCODE_F8, // Key::F8
SDL_SCANCODE_F9, // Key::F9
SDL_SCANCODE_F10, // Key::F10
SDL_SCANCODE_F11, // Key::F11
SDL_SCANCODE_F12, // Key::F12
SDL_SCANCODE_F13, // Key::F13
SDL_SCANCODE_F14, // Key::F14
SDL_SCANCODE_F15, // Key::F15
// Flèches directionnelles
SDL_SCANCODE_DOWN, // Key::Down
SDL_SCANCODE_LEFT, // Key::Left
SDL_SCANCODE_RIGHT, // Key::Right
SDL_SCANCODE_UP, // Key::Up
// Pavé numérique
SDL_SCANCODE_KP_PLUS, // Key::Add
SDL_SCANCODE_KP_PERIOD, // Key::Decimal
SDL_SCANCODE_KP_DIVIDE, // Key::Divide
SDL_SCANCODE_KP_MULTIPLY, // Key::Multiply
SDL_SCANCODE_KP_ENTER, // Key::NumpadReturn
SDL_SCANCODE_KP_0, // Key::Numpad0
SDL_SCANCODE_KP_1, // Key::Numpad1
SDL_SCANCODE_KP_2, // Key::Numpad2
SDL_SCANCODE_KP_3, // Key::Numpad3
SDL_SCANCODE_KP_4, // Key::Numpad4
SDL_SCANCODE_KP_5, // Key::Numpad5
SDL_SCANCODE_KP_6, // Key::Numpad6
SDL_SCANCODE_KP_7, // Key::Numpad7
SDL_SCANCODE_KP_8, // Key::Numpad8
SDL_SCANCODE_KP_9, // Key::Numpad9
SDL_SCANCODE_KP_MINUS, // Key::Subtract
// Divers
SDL_SCANCODE_BACKSLASH, // Key::Backslash
SDL_SCANCODE_BACKSPACE, // Key::Backspace
SDL_SCANCODE_CLEAR, // Key::Clear
SDL_SCANCODE_COMMA, // Key::Comma,
SDL_SCANCODE_MINUS, // Key::Dash
SDL_SCANCODE_DELETE, // Key::Delete
SDL_SCANCODE_END, // Key::End
SDL_SCANCODE_EQUALS, // Key::Equal
SDL_SCANCODE_ESCAPE, // Key::Escape
SDL_SCANCODE_HOME, // Key::Home
SDL_SCANCODE_INSERT, // Key::Insert
SDL_SCANCODE_LALT, // Key::LAlt
SDL_SCANCODE_LEFTBRACKET, // Key::LBracket
SDL_SCANCODE_LCTRL, // Key::LControl
SDL_SCANCODE_LSHIFT, // Key::LShift
SDL_SCANCODE_LGUI, // Key::LSystem
SDL_SCANCODE_0, // Key::Num0
SDL_SCANCODE_1, // Key::Num1
SDL_SCANCODE_2, // Key::Num2
SDL_SCANCODE_3, // Key::Num3
SDL_SCANCODE_4, // Key::Num4
SDL_SCANCODE_5, // Key::Num5
SDL_SCANCODE_6, // Key::Num6
SDL_SCANCODE_7, // Key::Num7
SDL_SCANCODE_8, // Key::Num8
SDL_SCANCODE_9, // Key::Num9
SDL_SCANCODE_PAGEDOWN, // Key::PageDown
SDL_SCANCODE_PAGEUP, // Key::PageUp
SDL_SCANCODE_PAUSE, // Key::Pause
SDL_SCANCODE_PERIOD, // Key::Period
SDL_SCANCODE_SYSREQ, // Key::Print
SDL_SCANCODE_PRINTSCREEN, // Key::PrintScreen
SDL_SCANCODE_APOSTROPHE, // Key::Quote
SDL_SCANCODE_RALT, // Key::RAlt
SDL_SCANCODE_RIGHTBRACKET, // Key::RBracket
SDL_SCANCODE_RCTRL, // Key::RControl
SDL_SCANCODE_RETURN, // Key::Return
SDL_SCANCODE_RSHIFT, // Key::RShift
SDL_SCANCODE_RGUI, // Key::RSystem
SDL_SCANCODE_SEMICOLON, // Key::Semicolon
SDL_SCANCODE_SLASH, // Key::Slash
SDL_SCANCODE_SPACE, // Key::Space
SDL_SCANCODE_TAB, // Key::Tab
SDL_SCANCODE_GRAVE, // Key::Tilde
SDL_SCANCODE_APPLICATION, // Key::Menu
SDL_SCANCODE_NONUSBACKSLASH,// Key::ISOBackslash102
// Touches navigateur
SDL_SCANCODE_AC_BACK, // Key::Browser_Back
SDL_SCANCODE_AC_BOOKMARKS, // Key::Browser_Favorites
SDL_SCANCODE_AC_FORWARD, // Key::Browser_Forward
SDL_SCANCODE_AC_HOME, // Key::Browser_Home
SDL_SCANCODE_AC_REFRESH, // Key::Browser_Refresh
SDL_SCANCODE_AC_SEARCH, // Key::Browser_Search
SDL_SCANCODE_AC_STOP, // Key::Browser_Stop
// Touches de contrôle
SDL_SCANCODE_AUDIONEXT, // Key::Media_Next,
SDL_SCANCODE_AUDIOPLAY, // Key::Media_PlayPause,
SDL_SCANCODE_AUDIOPREV, // Key::Media_Previous,
SDL_SCANCODE_AUDIOSTOP, // Key::Media_Stop,
// Touches de contrôle du volume
SDL_SCANCODE_VOLUMEDOWN, // Key::Volume_Down
SDL_SCANCODE_MUTE, // Key::Volume_Mute
SDL_SCANCODE_VOLUMEUP, // Key::Volume_Up
// Touches à verrouillage
SDL_SCANCODE_CAPSLOCK, // Key::CapsLock
SDL_SCANCODE_NUMLOCKCLEAR, // Key::NumLock
SDL_SCANCODE_SCROLLLOCK // Key::ScrollLock
};
SDL_Keycode nzVKeyToSDLVKey[static_cast<std::size_t>(Keyboard::VKey::Max) + 1] = {
// Keys
SDLK_a, // VKey::A
SDLK_b, // VKey::B
SDLK_c, // VKey::C
SDLK_d, // VKey::D
SDLK_e, // VKey::E
SDLK_f, // VKey::F
SDLK_g, // VKey::G
SDLK_h, // VKey::H
SDLK_i, // VKey::I
SDLK_j, // VKey::J
SDLK_k, // VKey::K
SDLK_l, // VKey::L
SDLK_m, // VKey::M
SDLK_n, // VKey::N
SDLK_o, // VKey::O
SDLK_p, // VKey::P
SDLK_q, // VKey::Q
SDLK_r, // VKey::R
SDLK_s, // VKey::S
SDLK_t, // VKey::T
SDLK_u, // VKey::U
SDLK_v, // VKey::V
SDLK_w, // VKey::W
SDLK_x, // VKey::X
SDLK_y, // VKey::Y
SDLK_z, // VKey::Z
// Function keys
SDLK_F1, // VKey::F1
SDLK_F2, // VKey::F2
SDLK_F3, // VKey::F3
SDLK_F4, // VKey::F4
SDLK_F5, // VKey::F5
SDLK_F6, // VKey::F6
SDLK_F7, // VKey::F7
SDLK_F8, // VKey::F8
SDLK_F9, // VKey::F9
SDLK_F10, // VKey::F10
SDLK_F11, // VKey::F11
SDLK_F12, // VKey::F12
SDLK_F13, // VKey::F13
SDLK_F14, // VKey::F14
SDLK_F15, // VKey::F15
// Arrows
SDLK_DOWN, // VKey::Down
SDLK_LEFT, // VKey::Left
SDLK_RIGHT, // VKey::Right
SDLK_UP, // VKey::Up
// Keypad
SDLK_KP_PLUS, // VKey::Add
SDLK_KP_PERIOD, // VKey::Decimal
SDLK_KP_DIVIDE, // VKey::Divide
SDLK_KP_MULTIPLY, // VKey::Multiply
SDLK_KP_ENTER, // VKey::NumpadReturn
SDLK_KP_0, // VKey::Numpad0
SDLK_KP_1, // VKey::Numpad1
SDLK_KP_2, // VKey::Numpad2
SDLK_KP_3, // VKey::Numpad3
SDLK_KP_4, // VKey::Numpad4
SDLK_KP_5, // VKey::Numpad5
SDLK_KP_6, // VKey::Numpad6
SDLK_KP_7, // VKey::Numpad7
SDLK_KP_8, // VKey::Numpad8
SDLK_KP_9, // VKey::Numpad9
SDLK_KP_MINUS, // VKey::Subtract
// Divers
SDLK_BACKSLASH, // VKey::Backslash
SDLK_BACKSPACE, // VKey::Backspace
SDLK_CLEAR, // VKey::Clear
SDLK_COMMA, // VKey::Comma,
SDLK_MINUS, // VKey::Dash
SDLK_DELETE, // VKey::Delete
SDLK_END, // VKey::End
SDLK_EQUALS, // VKey::Equal
SDLK_ESCAPE, // VKey::Escape
SDLK_HOME, // VKey::Home
SDLK_INSERT, // VKey::Insert
SDLK_LALT, // VKey::LAlt
SDLK_LEFTBRACKET, // VKey::LBracket
SDLK_LCTRL, // VKey::LControl
SDLK_LSHIFT, // VKey::LShift
SDLK_LGUI, // VKey::LSystem
SDLK_0, // VKey::Num0
SDLK_1, // VKey::Num1
SDLK_2, // VKey::Num2
SDLK_3, // VKey::Num3
SDLK_4, // VKey::Num4
SDLK_5, // VKey::Num5
SDLK_6, // VKey::Num6
SDLK_7, // VKey::Num7
SDLK_8, // VKey::Num8
SDLK_9, // VKey::Num9
SDLK_PAGEDOWN, // VKey::PageDown
SDLK_PAGEUP, // VKey::PageUp
SDLK_PAUSE, // VKey::Pause
SDLK_PERIOD, // VKey::Period
SDLK_SYSREQ, // VKey::Print
SDLK_PRINTSCREEN, // VKey::PrintScreen
SDLK_QUOTE, // VKey::Quote
SDLK_RALT, // VKey::RAlt
SDLK_RIGHTBRACKET, // VKey::RBracket
SDLK_RCTRL, // VKey::RControl
SDLK_RETURN, // VKey::Return
SDLK_RSHIFT, // VKey::RShift
SDLK_RGUI, // VKey::RSystem
SDLK_SEMICOLON, // VKey::Semicolon
SDLK_SLASH, // VKey::Slash
SDLK_SPACE, // VKey::Space
SDLK_TAB, // VKey::Tab
SDLK_BACKQUOTE, // VKey::Tilde
SDLK_APPLICATION, // VKey::Menu
SDLK_UNKNOWN, // VKey::ISOBackslash102
// Browser control
SDLK_AC_BACK, // VKey::Browser_Back
SDLK_AC_BOOKMARKS, // VKey::Browser_Favorites
SDLK_AC_FORWARD, // VKey::Browser_Forward
SDLK_AC_HOME, // VKey::Browser_Home
SDLK_AC_REFRESH, // VKey::Browser_Refresh
SDLK_AC_SEARCH, // VKey::Browser_Search
SDLK_AC_STOP, // VKey::Browser_Stop
// Audio control
SDLK_AUDIONEXT, // VKey::Media_Next,
SDLK_AUDIOPLAY, // VKey::Media_PlayPause,
SDLK_AUDIOPREV, // VKey::Media_Previous,
SDLK_AUDIOSTOP, // VKey::Media_Stop,
// Volume control
SDLK_VOLUMEDOWN, // VKey::Volume_Down
SDLK_MUTE, // VKey::Volume_Mute
SDLK_VOLUMEUP, // VKey::Volume_Up
// Lock keys
SDLK_CAPSLOCK, // VKey::CapsLock
SDLK_NUMLOCKCLEAR, // VKey::NumLock
SDLK_SCROLLLOCK // VKey::ScrollLock
};
}
Keyboard::Scancode SDLHelper::FromSDL(SDL_Scancode scancode)
{
switch (scancode)
{
case SDL_SCANCODE_LCTRL: return Keyboard::Scancode::LControl;
case SDL_SCANCODE_RCTRL: return Keyboard::Scancode::RControl;
case SDL_SCANCODE_LALT: return Keyboard::Scancode::LAlt;
case SDL_SCANCODE_RALT: return Keyboard::Scancode::RAlt;
case SDL_SCANCODE_LSHIFT: return Keyboard::Scancode::LShift;
case SDL_SCANCODE_RSHIFT: return Keyboard::Scancode::RShift;
case SDL_SCANCODE_0: return Keyboard::Scancode::Num0;
case SDL_SCANCODE_1: return Keyboard::Scancode::Num1;
case SDL_SCANCODE_2: return Keyboard::Scancode::Num2;
case SDL_SCANCODE_3: return Keyboard::Scancode::Num3;
case SDL_SCANCODE_4: return Keyboard::Scancode::Num4;
case SDL_SCANCODE_5: return Keyboard::Scancode::Num5;
case SDL_SCANCODE_6: return Keyboard::Scancode::Num6;
case SDL_SCANCODE_7: return Keyboard::Scancode::Num7;
case SDL_SCANCODE_8: return Keyboard::Scancode::Num8;
case SDL_SCANCODE_9: return Keyboard::Scancode::Num9;
case SDL_SCANCODE_A: return Keyboard::Scancode::A;
case SDL_SCANCODE_B: return Keyboard::Scancode::B;
case SDL_SCANCODE_C: return Keyboard::Scancode::C;
case SDL_SCANCODE_D: return Keyboard::Scancode::D;
case SDL_SCANCODE_E: return Keyboard::Scancode::E;
case SDL_SCANCODE_F: return Keyboard::Scancode::F;
case SDL_SCANCODE_G: return Keyboard::Scancode::G;
case SDL_SCANCODE_H: return Keyboard::Scancode::H;
case SDL_SCANCODE_I: return Keyboard::Scancode::I;
case SDL_SCANCODE_J: return Keyboard::Scancode::J;
case SDL_SCANCODE_K: return Keyboard::Scancode::K;
case SDL_SCANCODE_L: return Keyboard::Scancode::L;
case SDL_SCANCODE_M: return Keyboard::Scancode::M;
case SDL_SCANCODE_N: return Keyboard::Scancode::N;
case SDL_SCANCODE_O: return Keyboard::Scancode::O;
case SDL_SCANCODE_P: return Keyboard::Scancode::P;
case SDL_SCANCODE_Q: return Keyboard::Scancode::Q;
case SDL_SCANCODE_R: return Keyboard::Scancode::R;
case SDL_SCANCODE_S: return Keyboard::Scancode::S;
case SDL_SCANCODE_T: return Keyboard::Scancode::T;
case SDL_SCANCODE_U: return Keyboard::Scancode::U;
case SDL_SCANCODE_V: return Keyboard::Scancode::V;
case SDL_SCANCODE_W: return Keyboard::Scancode::W;
case SDL_SCANCODE_X: return Keyboard::Scancode::X;
case SDL_SCANCODE_Y: return Keyboard::Scancode::Y;
case SDL_SCANCODE_Z: return Keyboard::Scancode::Z;
case SDL_SCANCODE_KP_PLUS: return Keyboard::Scancode::Add;
case SDL_SCANCODE_BACKSPACE: return Keyboard::Scancode::Backspace;
case SDL_SCANCODE_AC_BACK: return Keyboard::Scancode::Browser_Back;
case SDL_SCANCODE_AC_BOOKMARKS: return Keyboard::Scancode::Browser_Favorites;
case SDL_SCANCODE_AC_FORWARD: return Keyboard::Scancode::Browser_Forward;
case SDL_SCANCODE_AC_HOME: return Keyboard::Scancode::Browser_Home;
case SDL_SCANCODE_AC_REFRESH: return Keyboard::Scancode::Browser_Refresh;
case SDL_SCANCODE_AC_SEARCH: return Keyboard::Scancode::Browser_Search;
case SDL_SCANCODE_AC_STOP: return Keyboard::Scancode::Browser_Stop;
case SDL_SCANCODE_CAPSLOCK: return Keyboard::Scancode::CapsLock;
case SDL_SCANCODE_CLEAR: return Keyboard::Scancode::Clear;
case SDL_SCANCODE_KP_PERIOD: return Keyboard::Scancode::Decimal;
case SDL_SCANCODE_DELETE: return Keyboard::Scancode::Delete;
case SDL_SCANCODE_KP_DIVIDE: return Keyboard::Scancode::Divide;
case SDL_SCANCODE_DOWN: return Keyboard::Scancode::Down;
case SDL_SCANCODE_END: return Keyboard::Scancode::End;
case SDL_SCANCODE_ESCAPE: return Keyboard::Scancode::Escape;
case SDL_SCANCODE_F1: return Keyboard::Scancode::F1;
case SDL_SCANCODE_F2: return Keyboard::Scancode::F2;
case SDL_SCANCODE_F3: return Keyboard::Scancode::F3;
case SDL_SCANCODE_F4: return Keyboard::Scancode::F4;
case SDL_SCANCODE_F5: return Keyboard::Scancode::F5;
case SDL_SCANCODE_F6: return Keyboard::Scancode::F6;
case SDL_SCANCODE_F7: return Keyboard::Scancode::F7;
case SDL_SCANCODE_F8: return Keyboard::Scancode::F8;
case SDL_SCANCODE_F9: return Keyboard::Scancode::F9;
case SDL_SCANCODE_F10: return Keyboard::Scancode::F10;
case SDL_SCANCODE_F11: return Keyboard::Scancode::F11;
case SDL_SCANCODE_F12: return Keyboard::Scancode::F12;
case SDL_SCANCODE_F13: return Keyboard::Scancode::F13;
case SDL_SCANCODE_F14: return Keyboard::Scancode::F14;
case SDL_SCANCODE_F15: return Keyboard::Scancode::F15;
case SDL_SCANCODE_HOME: return Keyboard::Scancode::Home;
case SDL_SCANCODE_INSERT: return Keyboard::Scancode::Insert;
case SDL_SCANCODE_LEFT: return Keyboard::Scancode::Left;
case SDL_SCANCODE_LGUI: return Keyboard::Scancode::LSystem;
case SDL_SCANCODE_AUDIONEXT: return Keyboard::Scancode::Media_Next;
case SDL_SCANCODE_AUDIOPLAY: return Keyboard::Scancode::Media_Play;
case SDL_SCANCODE_AUDIOPREV: return Keyboard::Scancode::Media_Previous;
case SDL_SCANCODE_AUDIOSTOP: return Keyboard::Scancode::Media_Stop;
case SDL_SCANCODE_KP_MULTIPLY: return Keyboard::Scancode::Multiply;
case SDL_SCANCODE_PAGEDOWN: return Keyboard::Scancode::PageDown;
case SDL_SCANCODE_KP_0: return Keyboard::Scancode::Numpad0;
case SDL_SCANCODE_KP_1: return Keyboard::Scancode::Numpad1;
case SDL_SCANCODE_KP_2: return Keyboard::Scancode::Numpad2;
case SDL_SCANCODE_KP_3: return Keyboard::Scancode::Numpad3;
case SDL_SCANCODE_KP_4: return Keyboard::Scancode::Numpad4;
case SDL_SCANCODE_KP_5: return Keyboard::Scancode::Numpad5;
case SDL_SCANCODE_KP_6: return Keyboard::Scancode::Numpad6;
case SDL_SCANCODE_KP_7: return Keyboard::Scancode::Numpad7;
case SDL_SCANCODE_KP_8: return Keyboard::Scancode::Numpad8;
case SDL_SCANCODE_KP_9: return Keyboard::Scancode::Numpad9;
case SDL_SCANCODE_NUMLOCKCLEAR: return Keyboard::Scancode::NumLock;
case SDL_SCANCODE_SEMICOLON: return Keyboard::Scancode::Semicolon;
case SDL_SCANCODE_SLASH: return Keyboard::Scancode::Slash;
case SDL_SCANCODE_GRAVE: return Keyboard::Scancode::Tilde;
case SDL_SCANCODE_APPLICATION: return Keyboard::Scancode::Menu;
case SDL_SCANCODE_NONUSBACKSLASH: return Keyboard::Scancode::ISOBackslash102;
case SDL_SCANCODE_LEFTBRACKET: return Keyboard::Scancode::LBracket;
case SDL_SCANCODE_BACKSLASH: return Keyboard::Scancode::Backslash;
case SDL_SCANCODE_RIGHTBRACKET: return Keyboard::Scancode::RBracket;
case SDL_SCANCODE_APOSTROPHE: return Keyboard::Scancode::Quote;
case SDL_SCANCODE_COMMA: return Keyboard::Scancode::Comma;
case SDL_SCANCODE_MINUS: return Keyboard::Scancode::Dash;
case SDL_SCANCODE_PERIOD: return Keyboard::Scancode::Period;
case SDL_SCANCODE_EQUALS: return Keyboard::Scancode::Equal;
case SDL_SCANCODE_RIGHT: return Keyboard::Scancode::Right;
case SDL_SCANCODE_PAGEUP: return Keyboard::Scancode::PageUp;
case SDL_SCANCODE_PAUSE: return Keyboard::Scancode::Pause;
case SDL_SCANCODE_SYSREQ: return Keyboard::Scancode::Print;
case SDL_SCANCODE_SCROLLLOCK: return Keyboard::Scancode::ScrollLock;
case SDL_SCANCODE_PRINTSCREEN: return Keyboard::Scancode::PrintScreen;
case SDL_SCANCODE_KP_MINUS: return Keyboard::Scancode::Subtract;
case SDL_SCANCODE_RETURN: return Keyboard::Scancode::Return;
case SDL_SCANCODE_KP_ENTER: return Keyboard::Scancode::NumpadReturn;
case SDL_SCANCODE_RGUI: return Keyboard::Scancode::RSystem;
case SDL_SCANCODE_SPACE: return Keyboard::Scancode::Space;
case SDL_SCANCODE_TAB: return Keyboard::Scancode::Tab;
case SDL_SCANCODE_UP: return Keyboard::Scancode::Up;
case SDL_SCANCODE_VOLUMEDOWN: return Keyboard::Scancode::Volume_Down;
case SDL_SCANCODE_MUTE: return Keyboard::Scancode::Volume_Mute;
case SDL_SCANCODE_AUDIOMUTE: return Keyboard::Scancode::Volume_Mute;
case SDL_SCANCODE_VOLUMEUP: return Keyboard::Scancode::Volume_Up;
default:
return Keyboard::Scancode::Undefined;
}
}
Keyboard::VKey SDLHelper::FromSDL(SDL_Keycode keycode)
{
switch (keycode)
{
case SDLK_LCTRL: return Keyboard::VKey::LControl;
case SDLK_RCTRL: return Keyboard::VKey::RControl;
case SDLK_LALT: return Keyboard::VKey::LAlt;
case SDLK_RALT: return Keyboard::VKey::RAlt;
case SDLK_LSHIFT: return Keyboard::VKey::LShift;
case SDLK_RSHIFT: return Keyboard::VKey::RShift;
case SDLK_0: return Keyboard::VKey::Num0;
case SDLK_1: return Keyboard::VKey::Num1;
case SDLK_2: return Keyboard::VKey::Num2;
case SDLK_3: return Keyboard::VKey::Num3;
case SDLK_4: return Keyboard::VKey::Num4;
case SDLK_5: return Keyboard::VKey::Num5;
case SDLK_6: return Keyboard::VKey::Num6;
case SDLK_7: return Keyboard::VKey::Num7;
case SDLK_8: return Keyboard::VKey::Num8;
case SDLK_9: return Keyboard::VKey::Num9;
case SDLK_a: return Keyboard::VKey::A;
case SDLK_b: return Keyboard::VKey::B;
case SDLK_c: return Keyboard::VKey::C;
case SDLK_d: return Keyboard::VKey::D;
case SDLK_e: return Keyboard::VKey::E;
case SDLK_f: return Keyboard::VKey::F;
case SDLK_g: return Keyboard::VKey::G;
case SDLK_h: return Keyboard::VKey::H;
case SDLK_i: return Keyboard::VKey::I;
case SDLK_j: return Keyboard::VKey::J;
case SDLK_k: return Keyboard::VKey::K;
case SDLK_l: return Keyboard::VKey::L;
case SDLK_m: return Keyboard::VKey::M;
case SDLK_n: return Keyboard::VKey::N;
case SDLK_o: return Keyboard::VKey::O;
case SDLK_p: return Keyboard::VKey::P;
case SDLK_q: return Keyboard::VKey::Q;
case SDLK_r: return Keyboard::VKey::R;
case SDLK_s: return Keyboard::VKey::S;
case SDLK_t: return Keyboard::VKey::T;
case SDLK_u: return Keyboard::VKey::U;
case SDLK_v: return Keyboard::VKey::V;
case SDLK_w: return Keyboard::VKey::W;
case SDLK_x: return Keyboard::VKey::X;
case SDLK_y: return Keyboard::VKey::Y;
case SDLK_z: return Keyboard::VKey::Z;
case SDLK_KP_PLUS: return Keyboard::VKey::Add;
case SDLK_BACKSPACE: return Keyboard::VKey::Backspace;
case SDLK_AC_BACK: return Keyboard::VKey::Browser_Back;
case SDLK_AC_BOOKMARKS: return Keyboard::VKey::Browser_Favorites;
case SDLK_AC_FORWARD: return Keyboard::VKey::Browser_Forward;
case SDLK_AC_HOME: return Keyboard::VKey::Browser_Home;
case SDLK_AC_REFRESH: return Keyboard::VKey::Browser_Refresh;
case SDLK_AC_SEARCH: return Keyboard::VKey::Browser_Search;
case SDLK_AC_STOP: return Keyboard::VKey::Browser_Stop;
case SDLK_CAPSLOCK: return Keyboard::VKey::CapsLock;
case SDLK_CLEAR: return Keyboard::VKey::Clear;
case SDLK_KP_PERIOD: return Keyboard::VKey::Decimal;
case SDLK_DELETE: return Keyboard::VKey::Delete;
case SDLK_KP_DIVIDE: return Keyboard::VKey::Divide;
case SDLK_DOWN: return Keyboard::VKey::Down;
case SDLK_END: return Keyboard::VKey::End;
case SDLK_ESCAPE: return Keyboard::VKey::Escape;
case SDLK_F1: return Keyboard::VKey::F1;
case SDLK_F2: return Keyboard::VKey::F2;
case SDLK_F3: return Keyboard::VKey::F3;
case SDLK_F4: return Keyboard::VKey::F4;
case SDLK_F5: return Keyboard::VKey::F5;
case SDLK_F6: return Keyboard::VKey::F6;
case SDLK_F7: return Keyboard::VKey::F7;
case SDLK_F8: return Keyboard::VKey::F8;
case SDLK_F9: return Keyboard::VKey::F9;
case SDLK_F10: return Keyboard::VKey::F10;
case SDLK_F11: return Keyboard::VKey::F11;
case SDLK_F12: return Keyboard::VKey::F12;
case SDLK_F13: return Keyboard::VKey::F13;
case SDLK_F14: return Keyboard::VKey::F14;
case SDLK_F15: return Keyboard::VKey::F15;
case SDLK_HOME: return Keyboard::VKey::Home;
case SDLK_INSERT: return Keyboard::VKey::Insert;
case SDLK_LEFT: return Keyboard::VKey::Left;
case SDLK_LGUI: return Keyboard::VKey::LSystem;
case SDLK_AUDIONEXT: return Keyboard::VKey::Media_Next;
case SDLK_AUDIOPLAY: return Keyboard::VKey::Media_Play;
case SDLK_AUDIOPREV: return Keyboard::VKey::Media_Previous;
case SDLK_AUDIOSTOP: return Keyboard::VKey::Media_Stop;
case SDLK_KP_MULTIPLY: return Keyboard::VKey::Multiply;
case SDLK_PAGEDOWN: return Keyboard::VKey::PageDown;
case SDLK_KP_0: return Keyboard::VKey::Numpad0;
case SDLK_KP_1: return Keyboard::VKey::Numpad1;
case SDLK_KP_2: return Keyboard::VKey::Numpad2;
case SDLK_KP_3: return Keyboard::VKey::Numpad3;
case SDLK_KP_4: return Keyboard::VKey::Numpad4;
case SDLK_KP_5: return Keyboard::VKey::Numpad5;
case SDLK_KP_6: return Keyboard::VKey::Numpad6;
case SDLK_KP_7: return Keyboard::VKey::Numpad7;
case SDLK_KP_8: return Keyboard::VKey::Numpad8;
case SDLK_KP_9: return Keyboard::VKey::Numpad9;
case SDLK_NUMLOCKCLEAR: return Keyboard::VKey::NumLock;
case SDLK_SEMICOLON: return Keyboard::VKey::Semicolon;
case SDLK_SLASH: return Keyboard::VKey::Slash;
case SDLK_BACKQUOTE: return Keyboard::VKey::Tilde;
case SDLK_APPLICATION: return Keyboard::VKey::Menu;
case SDLK_LEFTBRACKET: return Keyboard::VKey::LBracket;
case SDLK_BACKSLASH: return Keyboard::VKey::Backslash;
case SDLK_RIGHTBRACKET: return Keyboard::VKey::RBracket;
case SDLK_QUOTE: return Keyboard::VKey::Quote;
case SDLK_COMMA: return Keyboard::VKey::Comma;
case SDLK_MINUS: return Keyboard::VKey::Dash;
case SDLK_PERIOD: return Keyboard::VKey::Period;
case SDLK_EQUALS: return Keyboard::VKey::Equal;
case SDLK_RIGHT: return Keyboard::VKey::Right;
case SDLK_PAGEUP: return Keyboard::VKey::PageUp;
case SDLK_PAUSE: return Keyboard::VKey::Pause;
case SDLK_SYSREQ: return Keyboard::VKey::Print;
case SDLK_SCROLLLOCK: return Keyboard::VKey::ScrollLock;
case SDLK_PRINTSCREEN: return Keyboard::VKey::PrintScreen;
case SDLK_KP_MINUS: return Keyboard::VKey::Subtract;
case SDLK_RETURN: return Keyboard::VKey::Return;
case SDLK_KP_ENTER: return Keyboard::VKey::NumpadReturn;
case SDLK_RGUI: return Keyboard::VKey::RSystem;
case SDLK_SPACE: return Keyboard::VKey::Space;
case SDLK_TAB: return Keyboard::VKey::Tab;
case SDLK_UP: return Keyboard::VKey::Up;
case SDLK_VOLUMEDOWN: return Keyboard::VKey::Volume_Down;
case SDLK_MUTE: return Keyboard::VKey::Volume_Mute;
case SDLK_AUDIOMUTE: return Keyboard::VKey::Volume_Mute;
case SDLK_VOLUMEUP: return Keyboard::VKey::Volume_Up;
default:
return Keyboard::VKey::Undefined;
}
}
SDL_Scancode SDLHelper::ToSDL(Keyboard::Scancode scancode)
{
if (scancode == Keyboard::Scancode::Undefined)
return SDL_SCANCODE_UNKNOWN;
return nzScancodeToSDLScanCode[static_cast<std::size_t>(scancode)];
}
SDL_Keycode SDLHelper::ToSDL(Keyboard::VKey keycode)
{
if (keycode == Keyboard::VKey::Undefined)
return SDLK_UNKNOWN;
return nzVKeyToSDLVKey[static_cast<std::size_t>(keycode)];
}
}

View File

@ -0,0 +1,26 @@
// 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_SDL2_HELPER_HPP
#define NAZARA_SDL2_HELPER_HPP
#include <Nazara/Platform/Keyboard.hpp>
#include <SDL2/SDL_keycode.h>
#include <SDL2/SDL_scancode.h>
namespace Nz
{
class SDLHelper
{
public:
static Keyboard::Scancode FromSDL(SDL_Scancode scancode);
static Keyboard::VKey FromSDL(SDL_Keycode keycode);
static SDL_Scancode ToSDL(Keyboard::Scancode scancode);
static SDL_Keycode ToSDL(Keyboard::VKey keycode);
};
}
#endif // NAZARA_SDL2_HELPER_HPP

View File

@ -0,0 +1,51 @@
// 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 <algorithm>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/SDL2/VideoModeImpl.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <SDL2/SDL_video.h>
namespace Nz
{
VideoMode VideoModeImpl::GetDesktopMode()
{
SDL_DisplayMode mode;
if (SDL_GetDesktopDisplayMode(0, &mode) != 0) // handle multi screen ?
{
NazaraError(SDL_GetError());
return VideoMode(800, 600, static_cast<UInt8>(32)); // useless ?
}
return VideoMode(mode.w, mode.h, SDL_BITSPERPIXEL(mode.format));
}
void VideoModeImpl::GetFullscreenModes(std::vector<VideoMode>& modes)
{
SDL_DisplayMode mode;
int numModes = SDL_GetNumDisplayModes(0);
if (numModes < 0)
{
NazaraError(SDL_GetError());
return;
}
for (int i = 0; i < numModes; i++)
{
if (SDL_GetDisplayMode(0, i, &mode) != 0) // handle multi screen ?
NazaraError(SDL_GetError());
VideoMode vMode(mode.w, mode.h, SDL_BITSPERPIXEL(mode.format));
if (std::find(modes.begin(), modes.end(), vMode) == modes.end())
modes.push_back(vMode);
}
}
}

View File

@ -0,0 +1,22 @@
// 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_VIDEOMODEIMPL_HPP
#define NAZARA_VIDEOMODEIMPL_HPP
#include <Nazara/Platform/VideoMode.hpp>
namespace Nz
{
class VideoModeImpl
{
public:
static VideoMode GetDesktopMode();
static void GetFullscreenModes(std::vector<VideoMode>& modes);
};
}
#endif // NNAZARA_VIDEOMODEIMPL_HPP

View File

@ -0,0 +1,605 @@
// 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 <cstdio>
#include <memory>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/SDL2/CursorImpl.hpp>
#include <Nazara/Platform/SDL2/IconImpl.hpp>
#include <Nazara/Platform/SDL2/SDLHelper.hpp>
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
#include <Nazara/Utility/Image.hpp>
#include <SDL2/SDL.h>
namespace Nz
{
namespace
{
WindowImpl* fullscreenWindow = nullptr;
Mouse::Button SDLToNazaraButton(Uint8 sdlButton)
{
switch (sdlButton)
{
case SDL_BUTTON_LEFT:
return Mouse::Left;
case SDL_BUTTON_MIDDLE:
return Mouse::Middle;
case SDL_BUTTON_RIGHT:
return Mouse::Right;
case SDL_BUTTON_X1:
return Mouse::XButton1;
case SDL_BUTTON_X2:
return Mouse::XButton2;
default:
NazaraAssert(false, "Unkown mouse button");
return Mouse::Left;
}
}
}
WindowImpl::WindowImpl(Window* parent) :
m_cursor(nullptr),
m_handle(nullptr),
//m_callback(0),
m_style(0),
m_maxSize(-1),
m_minSize(-1),
m_parent(parent),
m_keyRepeat(true),
m_mouseInside(false),
m_smoothScrolling(false),
m_scrolling(0)
{
m_cursor = SDL_GetDefaultCursor();
}
bool WindowImpl::Create(const VideoMode& mode, const String& title, WindowStyleFlags style)
{
bool async = (style & WindowStyle_Threaded) != 0;
if (async)
{
NazaraError("SDL2 backend doesn't support asyn window for now");
return false;
}
bool fullscreen = (style & WindowStyle_Fullscreen) != 0;
Uint32 winStyle = SDL_WINDOW_OPENGL;
unsigned int x, y;
unsigned int width = mode.width;
unsigned int height = mode.height;
if (fullscreen)
winStyle |= SDL_WINDOW_FULLSCREEN;
// Testé une seconde fois car sa valeur peut changer
if (fullscreen)
{
x = 0;
y = 0;
fullscreenWindow = this;
}
else
{
if (!(style & WindowStyle_Titlebar))
winStyle |= SDL_WINDOW_BORDERLESS;
x = SDL_WINDOWPOS_CENTERED;
y = SDL_WINDOWPOS_CENTERED;
}
if (style & WindowStyle_Resizable)
winStyle |= SDL_WINDOW_RESIZABLE;
if (style & WindowStyle_Max)
winStyle |= SDL_WINDOW_MAXIMIZED;
m_eventListener = true;
m_ownsWindow = true;
m_sizemove = false;
m_style = style;
m_handle = SDL_CreateWindow(title.GetConstBuffer(), x, y, width, height, winStyle);
if (!m_handle)
{
NazaraError("Failed to create window: " + Error::GetLastSystemError());
return false;
}
PrepareWindow(fullscreen);
SDL_AddEventWatch(HandleEvent, this);
return true;
}
bool WindowImpl::Create(WindowHandle handle)
{
m_handle = static_cast<SDL_Window*>(handle);
if (!m_handle || !SDL_GetWindowID(m_handle))
{
NazaraError("Invalid handle");
return false;
}
m_eventListener = false;
m_ownsWindow = false;
m_sizemove = false;
SDL_GetWindowPosition(m_handle, &m_position.x, &m_position.y);
int width;
int height;
SDL_GetWindowSize(m_handle, &width, &height);
m_size.Set(width, height);
SDL_AddEventWatch(HandleEvent, this);
return true;
}
void WindowImpl::Destroy()
{
if (m_ownsWindow && m_handle)
SDL_DestroyWindow(m_handle);
else
SetEventListener(false);
SDL_DelEventWatch(HandleEvent, this);
}
void WindowImpl::EnableKeyRepeat(bool enable)
{
m_keyRepeat = enable;
}
void WindowImpl::EnableSmoothScrolling(bool enable)
{
m_smoothScrolling = enable;
}
WindowHandle WindowImpl::GetHandle() const
{
return m_handle;
}
Vector2i WindowImpl::GetPosition() const
{
return m_position;
}
Vector2ui WindowImpl::GetSize() const
{
return m_size;
}
WindowStyleFlags WindowImpl::GetStyle() const
{
return m_style;
}
String WindowImpl::GetTitle() const
{
return String::Unicode(SDL_GetWindowTitle(m_handle));
}
bool WindowImpl::HasFocus() const
{
return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_INPUT_FOCUS) != 0;
}
void WindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY)
{
m_ignoreNextMouseMove = true;
// Petite astuce ... probablement foireuse dans certains cas :ahde:
m_mousePos.x = mouseX;
m_mousePos.y = mouseY;
}
bool WindowImpl::IsMinimized() const
{
return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_MINIMIZED) != 0;
}
bool WindowImpl::IsVisible() const
{
return (SDL_GetWindowFlags(m_handle) & SDL_WINDOW_SHOWN) != 0;
}
void WindowImpl::RefreshCursor()
{
if (!m_cursor)
{
if (SDL_ShowCursor(SDL_DISABLE) < 0)
NazaraWarning(SDL_GetError());
}
else
{
if (SDL_ShowCursor(SDL_ENABLE) < 0)
NazaraWarning(SDL_GetError());
SDL_SetCursor(m_cursor);
}
}
void WindowImpl::ProcessEvents(bool block)
{
SDL_PumpEvents();
/*if (m_ownsWindow)
{
if (block)
WaitMessage();
MSG message;
while (PeekMessageW(&message, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&message);
DispatchMessageW(&message);
}
}*/
}
int SDLCALL WindowImpl::HandleEvent(void *userdata, SDL_Event* event)
{
try {
auto window = static_cast<WindowImpl*>(userdata);
WindowEvent evt;
evt.type = WindowEventType::WindowEventType_Max;
switch (event->type)
{
case SDL_WINDOWEVENT:
if (SDL_GetWindowID(window->m_handle) != event->window.windowID)
return 0;
switch (event->window.event)
{
case SDL_WINDOWEVENT_CLOSE:
evt.type = Nz::WindowEventType::WindowEventType_Quit;
break;
case SDL_WINDOWEVENT_RESIZED:
evt.type = Nz::WindowEventType::WindowEventType_Resized;
evt.size.width = static_cast<unsigned int>(std::max(0, event->window.data1));
evt.size.height = static_cast<unsigned int>(std::max(0, event->window.data2));
window->m_size.Set(evt.size.width, evt.size.height);
break;
case SDL_WINDOWEVENT_MOVED:
evt.type = Nz::WindowEventType::WindowEventType_Moved;
evt.position.x = event->window.data1;
evt.position.y = event->window.data2;
window->m_position.Set(event->window.data1, event->window.data2);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
evt.type = Nz::WindowEventType::WindowEventType_GainedFocus;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
evt.type = Nz::WindowEventType::WindowEventType_LostFocus;
break;
case SDL_WINDOWEVENT_ENTER:
evt.type = Nz::WindowEventType::WindowEventType_MouseEntered;
break;
case SDL_WINDOWEVENT_LEAVE:
evt.type = Nz::WindowEventType::WindowEventType_MouseLeft;
break;
}
break;
case SDL_MOUSEMOTION:
if (SDL_GetWindowID(window->m_handle) != event->motion.windowID)
return 0;
if (window->m_ignoreNextMouseMove /*&& event->motion.x == window->m_mousePos.x && event->motion.y == window->m_mousePos.y*/)
{
window->m_ignoreNextMouseMove = false;
return 0;
}
evt.type = Nz::WindowEventType::WindowEventType_MouseMoved;
evt.mouseMove.x = event->motion.x;
evt.mouseMove.y = event->motion.y;
evt.mouseMove.deltaX = event->motion.xrel;
evt.mouseMove.deltaY = event->motion.yrel;
break;
case SDL_MOUSEBUTTONDOWN:
if (SDL_GetWindowID(window->m_handle) != event->button.windowID)
return 0;
evt.mouseButton.button = SDLToNazaraButton(event->button.button);
evt.mouseButton.x = event->button.x;
evt.mouseButton.y = event->button.y;
if (event->button.clicks % 2 == 0)
{
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonDoubleClicked;
window->m_parent->PushEvent(evt);
}
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonPressed;
break;
case SDL_MOUSEBUTTONUP:
if (SDL_GetWindowID(window->m_handle) != event->button.windowID)
return 0;
evt.mouseButton.button = SDLToNazaraButton(event->button.button);
evt.mouseButton.x = event->button.x;
evt.mouseButton.y = event->button.y;
evt.type = Nz::WindowEventType::WindowEventType_MouseButtonReleased;
break;
case SDL_MOUSEWHEEL:
if (SDL_GetWindowID(window->m_handle) != event->wheel.windowID)
return 0;
evt.type = Nz::WindowEventType::WindowEventType_MouseWheelMoved;
evt.mouseWheel.delta = event->wheel.y;
break;
case SDL_KEYDOWN:
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
return 0;
evt.type = WindowEventType_KeyPressed;
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0;
evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0;
evt.key.repeated = event->key.repeat != 0;
evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0;
evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0;
// implements X11/Win32 APIs behavior for Enter and Backspace
switch (evt.key.virtualKey) {
case Nz::Keyboard::VKey::NumpadReturn:
case Nz::Keyboard::VKey::Return:
if (window->m_lastEditEventLength != 0)
break;
window->m_parent->PushEvent(evt);
evt.type = WindowEventType_TextEntered;
evt.text.character = U'\n';
evt.text.repeated = event->key.repeat != 0;
window->m_parent->PushEvent(evt);
break;
case Nz::Keyboard::VKey::Backspace:
window->m_parent->PushEvent(evt);
evt.type = WindowEventType_TextEntered;
evt.text.character = U'\b';
evt.text.repeated = event->key.repeat != 0;
window->m_parent->PushEvent(evt);
break;
default:
break;
}
break;
case SDL_KEYUP:
if (SDL_GetWindowID(window->m_handle) != event->key.windowID)
return 0;
evt.type = WindowEventType_KeyReleased;
evt.key.scancode = SDLHelper::FromSDL(event->key.keysym.scancode);
evt.key.virtualKey = SDLHelper::FromSDL(event->key.keysym.sym);
evt.key.alt = (event->key.keysym.mod & KMOD_ALT) != 0;
evt.key.control = (event->key.keysym.mod & KMOD_CTRL) != 0;
evt.key.repeated = event->key.repeat != 0;
evt.key.shift = (event->key.keysym.mod & KMOD_SHIFT) != 0;
evt.key.system = (event->key.keysym.mod & KMOD_GUI) != 0;
break;
case SDL_TEXTINPUT:
if (SDL_GetWindowID(window->m_handle) != event->text.windowID)
return 0;
evt.type = WindowEventType_TextEntered;
evt.text.repeated = false;
for (decltype(evt.text.character) codepoint : String::Unicode(event->text.text).Simplify().GetUtf32String())
{
evt.text.character = codepoint;
window->m_parent->PushEvent(evt);
}
// prevent post switch event
evt.type = WindowEventType::WindowEventType_Max;
break;
case SDL_TEXTEDITING:
if (SDL_GetWindowID(window->m_handle) != event->edit.windowID)
return 0;
evt.type = WindowEventType_TextEdited;
evt.edit.length = event->edit.length;
window->m_lastEditEventLength = evt.edit.length;
for (std::size_t i = 0; i < 32; i++)
{
evt.edit.text[i] = event->edit.text[i];
}
break;
}
if (evt.type != WindowEventType::WindowEventType_Max)
window->m_parent->PushEvent(evt);
}
catch (std::exception e)
{
NazaraError(e.what());
}
catch (...) // Don't let any exceptions go thru C calls
{
NazaraError("An unknown error happened");
}
return 0;
}
void WindowImpl::SetCursor(const Cursor& cursor)
{
m_cursor = cursor.m_impl->GetCursor();
if (HasFocus())
RefreshCursor();
}
void WindowImpl::SetEventListener(bool listener)
{
}
void WindowImpl::SetFocus()
{
SDL_RaiseWindow(m_handle);
}
void WindowImpl::SetIcon(const Icon& icon)
{
SDL_SetWindowIcon(m_handle, icon.m_impl->GetIcon());
}
void WindowImpl::SetMaximumSize(int width, int height)
{
SDL_SetWindowMaximumSize(m_handle, width, height);
}
void WindowImpl::SetMinimumSize(int width, int height)
{
SDL_SetWindowMinimumSize(m_handle, width, height);
}
void WindowImpl::SetPosition(int x, int y)
{
SDL_SetWindowPosition(m_handle, x, y);
}
void WindowImpl::SetSize(unsigned int width, unsigned int height)
{
m_size.Set(width, height);
SDL_SetWindowSize(m_handle, width, height);
}
void WindowImpl::SetStayOnTop(bool stayOnTop)
{
NazaraDebug("Stay on top isn't supported by SDL2 backend for now");
}
void WindowImpl::SetTitle(const String& title)
{
SDL_SetWindowTitle(m_handle, title.GetConstBuffer());
}
void WindowImpl::SetVisible(bool visible)
{
visible ? SDL_ShowWindow(m_handle) : SDL_HideWindow(m_handle);
}
void WindowImpl::PrepareWindow(bool fullscreen)
{
(void)fullscreen; // ignore param warning
SDL_GetWindowPosition(m_handle, &m_position.x, &m_position.y);
int width, height;
SDL_GetWindowSize(m_handle, &width, &height);
m_size.Set(width, height);
}
bool WindowImpl::Initialize()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
NazaraError(SDL_GetError());
return false;
}
if (SDL_GL_LoadLibrary(nullptr) < 0)
{
NazaraError(SDL_GetError());
SDL_Quit();
return false;
}
if (SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true) < 0)
NazaraError("Couldn't set share OpenGL contexes");
return true;
}
void WindowImpl::Uninitialize()
{
SDL_Quit();
}
// not implemented for now, wait for mainloop friendly input
//void WindowImpl::WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition)
//{
// SDL_Window& winHandle = *handle;
/*winHandle = CreateWindowExW(styleEx, className, title.GetWideString().data(), style, dimensions.x, dimensions.y, dimensions.width, dimensions.height, nullptr, nullptr, GetModuleHandle(nullptr), window);
if (winHandle)
window->PrepareWindow(fullscreen);
mutex->Lock();
condition->Signal();
mutex->Unlock(); // mutex and condition may be destroyed after this line
if (!winHandle)
return;
while (window->m_threadActive)
window->ProcessEvents(true);
DestroyWindow(winHandle);*/
//}
}

View File

@ -0,0 +1,113 @@
// 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_WINDOWIMPL_HPP
#define NAZARA_WINDOWIMPL_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Keyboard.hpp>
#include <Nazara/Platform/Mouse.hpp>
#include <Nazara/Platform/VideoMode.hpp>
#include <Nazara/Platform/Window.hpp>
#include <Nazara/Prerequisites.hpp>
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_keyboard.h>
#include <SDL2/SDL_video.h>
namespace Nz
{
class ConditionVariable;
class Mutex;
class Window;
class WindowImpl
{
public:
WindowImpl(Window* parent);
WindowImpl(const WindowImpl&) = delete;
WindowImpl(WindowImpl&&) = delete; ///TODO?
~WindowImpl() = default;
bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style);
bool Create(WindowHandle handle);
void Destroy();
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
WindowHandle GetHandle() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
WindowStyleFlags GetStyle() const;
String GetTitle() const;
bool HasFocus() const;
void IgnoreNextMouseEvent(int mouseX, int mouseY);
bool IsMinimized() const;
bool IsVisible() const;
void RefreshCursor();
void ProcessEvents(bool block);
void SetCursor(const Cursor& cursor);
void SetEventListener(bool listener);
void SetFocus();
void SetIcon(const Icon& icon);
void SetMaximumSize(int width, int height);
void SetMinimumSize(int width, int height);
void SetPosition(int x, int y);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const String& title);
void SetVisible(bool visible);
WindowImpl& operator=(const WindowImpl&) = delete;
WindowImpl& operator=(WindowImpl&&) = delete; ///TODO?
static bool Initialize();
static void Uninitialize();
private:
int static SDLCALL HandleEvent(void *userdata, SDL_Event * event);
void PrepareWindow(bool fullscreen);
//static void WindowThread(SDL_Window* handle, /*DWORD styleEx,*/ const String& title, /*DWORD style,*/ bool fullscreen, const Rectui& dimensions, WindowImpl* window, Mutex* mutex, ConditionVariable* condition);
int m_lastEditEventLength = 0;
SDL_Cursor* m_cursor;
SDL_Window* m_handle;
WindowStyleFlags m_style;
Vector2i m_maxSize;
Vector2i m_minSize;
Vector2i m_mousePos;
Vector2i m_position;
Vector2ui m_size;
//Thread m_thread;
Window* m_parent;
bool m_eventListener;
bool m_ignoreNextMouseMove = false;
bool m_keyRepeat;
bool m_mouseInside;
bool m_ownsWindow;
bool m_sizemove;
bool m_smoothScrolling;
bool m_threadActive;
short m_scrolling;
};
}
#endif // NAZARA_WINDOWIMPL_HPP

View File

@ -6,7 +6,9 @@
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/VideoModeImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/VideoModeImpl.hpp> #include <Nazara/Platform/Win32/VideoModeImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/VideoModeImpl.hpp> #include <Nazara/Platform/X11/VideoModeImpl.hpp>

View File

@ -2,11 +2,11 @@
// This file is part of the "Nazara Engine - Platform module" // This file is part of the "Nazara Engine - Platform module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Platform/Win32/InputImpl.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/Win32/InputImpl.hpp>
#include <Nazara/Platform/Window.hpp> #include <Nazara/Platform/Window.hpp>
#include <windows.h> #include <windows.h>
#include <Nazara/Platform/Debug.hpp>
namespace Nz namespace Nz
{ {
@ -69,6 +69,7 @@ namespace Nz
VK_DECIMAL, // Key::Decimal VK_DECIMAL, // Key::Decimal
VK_DIVIDE, // Key::Divide VK_DIVIDE, // Key::Divide
VK_MULTIPLY, // Key::Multiply VK_MULTIPLY, // Key::Multiply
VK_RETURN, // Key::Multiply
VK_NUMPAD0, // Key::Numpad0 VK_NUMPAD0, // Key::Numpad0
VK_NUMPAD1, // Key::Numpad1 VK_NUMPAD1, // Key::Numpad1
VK_NUMPAD2, // Key::Numpad2 VK_NUMPAD2, // Key::Numpad2
@ -126,6 +127,8 @@ namespace Nz
VK_SPACE, // Key::Space VK_SPACE, // Key::Space
VK_TAB, // Key::Tab VK_TAB, // Key::Tab
VK_OEM_3, // Key::Tilde VK_OEM_3, // Key::Tilde
VK_APPS, // Key::Menu
VK_OEM_102, // Key::ISOBackslash102
// Touches navigateur // Touches navigateur
VK_BROWSER_BACK, // Key::Browser_Back VK_BROWSER_BACK, // Key::Browser_Back
@ -192,6 +195,7 @@ namespace Nz
case VK_RIGHT: case VK_RIGHT:
case VK_RWIN: case VK_RWIN:
case VK_UP: case VK_UP:
case VK_RETURN: // TODO check
code |= 0x1000000; // 24ème bit pour l'extension code |= 0x1000000; // 24ème bit pour l'extension
break; break;
} }
@ -257,7 +261,6 @@ namespace Nz
// Gestion de l'inversement des boutons de la souris // Gestion de l'inversement des boutons de la souris
if (GetSystemMetrics(SM_SWAPBUTTON)) if (GetSystemMetrics(SM_SWAPBUTTON))
{
switch (button) switch (button)
{ {
case Mouse::Left: case Mouse::Left:
@ -271,7 +274,6 @@ namespace Nz
default: default:
break; break;
} }
}
return (GetAsyncKeyState(vButtons[button]) & 0x8000) != 0; return (GetAsyncKeyState(vButtons[button]) & 0x8000) != 0;
} }

View File

@ -12,14 +12,15 @@
#include <Nazara/Core/Thread.hpp> #include <Nazara/Core/Thread.hpp>
#include <Nazara/Platform/Config.hpp> #include <Nazara/Platform/Config.hpp>
#include <Nazara/Platform/Cursor.hpp> #include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/Icon.hpp> #include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/Win32/CursorImpl.hpp> #include <Nazara/Platform/Win32/CursorImpl.hpp>
#include <Nazara/Platform/Win32/IconImpl.hpp> #include <Nazara/Platform/Win32/IconImpl.hpp>
#include <Nazara/Platform/Win32/WindowImpl.hpp>
#include <Nazara/Utility/Image.hpp> #include <Nazara/Utility/Image.hpp>
#include <windowsx.h>
#include <cstdio> #include <cstdio>
#include <memory> #include <memory>
#include <windowsx.h>
#include <Nazara/Platform/Debug.hpp>
#ifdef _WIN64 #ifdef _WIN64
#define GCL_HCURSOR GCLP_HCURSOR #define GCL_HCURSOR GCLP_HCURSOR
@ -118,7 +119,6 @@ namespace Nz
width = rect.right - rect.left; width = rect.right - rect.left;
height = rect.bottom - rect.top; height = rect.bottom - rect.top;
// Grab desktop rect in order to center our window on the main display // Grab desktop rect in order to center our window on the main display
// TODO: Handle multiple displays // TODO: Handle multiple displays
RECT desktopRect; RECT desktopRect;
@ -201,12 +201,9 @@ namespace Nz
m_thread.Join(); m_thread.Join();
} }
} }
else else if (m_handle)
{
if (m_handle)
DestroyWindow(m_handle); DestroyWindow(m_handle);
} }
}
else else
SetEventListener(false); SetEventListener(false);
} }
@ -445,7 +442,6 @@ namespace Nz
} }
if (m_eventListener) if (m_eventListener)
{
switch (message) switch (message)
{ {
case WM_CHAR: case WM_CHAR:
@ -720,6 +716,7 @@ namespace Nz
WindowEvent event; WindowEvent event;
event.type = WindowEventType_MouseWheelMoved; event.type = WindowEventType_MouseWheelMoved;
event.mouseWheel.delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA; event.mouseWheel.delta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA;
event.mouseWheel.x = GET_X_LPARAM(lParam); event.mouseWheel.x = GET_X_LPARAM(lParam);
event.mouseWheel.y = GET_Y_LPARAM(lParam); event.mouseWheel.y = GET_Y_LPARAM(lParam);
@ -733,6 +730,7 @@ namespace Nz
WindowEvent event; WindowEvent event;
event.type = WindowEventType_MouseWheelMoved; event.type = WindowEventType_MouseWheelMoved;
event.mouseWheel.delta = static_cast<float>(m_scrolling / WHEEL_DELTA); event.mouseWheel.delta = static_cast<float>(m_scrolling / WHEEL_DELTA);
event.mouseWheel.x = GET_X_LPARAM(lParam); event.mouseWheel.x = GET_X_LPARAM(lParam);
event.mouseWheel.y = GET_Y_LPARAM(lParam); event.mouseWheel.y = GET_Y_LPARAM(lParam);
@ -916,7 +914,6 @@ namespace Nz
default: default:
break; break;
} }
}
#if NAZARA_PLATFORM_WINDOWS_DISABLE_MENU_KEYS #if NAZARA_PLATFORM_WINDOWS_DISABLE_MENU_KEYS
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
@ -1021,6 +1018,7 @@ namespace Nz
{ {
case VK_CONTROL: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RControl : Keyboard::LControl; case VK_CONTROL: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RControl : Keyboard::LControl;
case VK_MENU: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RAlt : Keyboard::LAlt; case VK_MENU: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::RAlt : Keyboard::LAlt;
case VK_RETURN: return (HIWORD(flags) & KF_EXTENDED) ? Keyboard::NumpadReturn : Keyboard::Return; // TODO Check
case VK_SHIFT: case VK_SHIFT:
{ {
static UINT scancode = MapVirtualKey(VK_SHIFT, MAPVK_VK_TO_VSC); static UINT scancode = MapVirtualKey(VK_SHIFT, MAPVK_VK_TO_VSC);
@ -1119,6 +1117,8 @@ namespace Nz
case VK_OEM_1: return Keyboard::Semicolon; case VK_OEM_1: return Keyboard::Semicolon;
case VK_OEM_2: return Keyboard::Slash; case VK_OEM_2: return Keyboard::Slash;
case VK_OEM_3: return Keyboard::Tilde; case VK_OEM_3: return Keyboard::Tilde;
case VK_APPS: return Keyboard::Menu;
case VK_OEM_102: return Keyboard::ISOBackslash102;
case VK_OEM_4: return Keyboard::LBracket; case VK_OEM_4: return Keyboard::LBracket;
case VK_OEM_5: return Keyboard::Backslash; case VK_OEM_5: return Keyboard::Backslash;
case VK_OEM_6: return Keyboard::RBracket; case VK_OEM_6: return Keyboard::RBracket;
@ -1134,7 +1134,6 @@ namespace Nz
case VK_SCROLL: return Keyboard::ScrollLock; case VK_SCROLL: return Keyboard::ScrollLock;
case VK_SNAPSHOT: return Keyboard::PrintScreen; case VK_SNAPSHOT: return Keyboard::PrintScreen;
case VK_SUBTRACT: return Keyboard::Subtract; case VK_SUBTRACT: return Keyboard::Subtract;
case VK_RETURN: return Keyboard::Return;
case VK_RWIN: return Keyboard::RSystem; case VK_RWIN: return Keyboard::RSystem;
case VK_SPACE: return Keyboard::Space; case VK_SPACE: return Keyboard::Space;
case VK_TAB: return Keyboard::Tab; case VK_TAB: return Keyboard::Tab;
@ -1197,10 +1196,8 @@ namespace Nz
RECT rect; RECT rect;
if (GetWindowRect(handle, &rect)) if (GetWindowRect(handle, &rect))
{
if (static_cast<DWORD>(rect.right - rect.left) == mode.dmPelsWidth && static_cast<DWORD>(rect.bottom - rect.top) == mode.dmPelsHeight) if (static_cast<DWORD>(rect.right - rect.left) == mode.dmPelsWidth && static_cast<DWORD>(rect.bottom - rect.top) == mode.dmPelsHeight)
style |= WindowStyle_Fullscreen; style |= WindowStyle_Fullscreen;
}
return style; return style;
} }

View File

@ -9,7 +9,9 @@
#include <Nazara/Platform/Cursor.hpp> #include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Icon.hpp> #include <Nazara/Platform/Icon.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Platform/Win32/WindowImpl.hpp> #include <Nazara/Platform/Win32/WindowImpl.hpp>
#elif defined(NAZARA_PLATFORM_X11) #elif defined(NAZARA_PLATFORM_X11)
#include <Nazara/Platform/X11/WindowImpl.hpp> #include <Nazara/Platform/X11/WindowImpl.hpp>

View File

@ -79,6 +79,7 @@ namespace Nz
case Keyboard::Decimal: keysym = XK_KP_Decimal; break; case Keyboard::Decimal: keysym = XK_KP_Decimal; break;
case Keyboard::Divide: keysym = XK_KP_Divide; break; case Keyboard::Divide: keysym = XK_KP_Divide; break;
case Keyboard::Multiply: keysym = XK_KP_Multiply; break; case Keyboard::Multiply: keysym = XK_KP_Multiply; break;
case Keyboard::NumpadReturn: keysym = XK_KP_Enter; break;
case Keyboard::Numpad0: keysym = XK_KP_0; break; case Keyboard::Numpad0: keysym = XK_KP_0; break;
case Keyboard::Numpad1: keysym = XK_KP_1; break; case Keyboard::Numpad1: keysym = XK_KP_1; break;
case Keyboard::Numpad2: keysym = XK_KP_2; break; case Keyboard::Numpad2: keysym = XK_KP_2; break;
@ -136,6 +137,8 @@ namespace Nz
case Keyboard::Space: keysym = XK_space; break; case Keyboard::Space: keysym = XK_space; break;
case Keyboard::Tab: keysym = XK_Tab; break; case Keyboard::Tab: keysym = XK_Tab; break;
case Keyboard::Tilde: keysym = XK_grave; break; case Keyboard::Tilde: keysym = XK_grave; break;
case Keyboard::Menu: keysym = XK_Menu; break;
case Keyboard::ISOBackslash102: keysym = XK_less; break;
// Touches navigateur // Touches navigateur
case Keyboard::Browser_Back: keysym = XF86XK_Back; break; case Keyboard::Browser_Back: keysym = XF86XK_Back; break;

View File

@ -4,10 +4,10 @@
// Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation // Un grand merci à Laurent Gomila pour la SFML qui m'aura bien aidé à réaliser cette implémentation
#include <Nazara/Platform/X11/WindowImpl.hpp>
#include <Nazara/Core/CallOnExit.hpp> #include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Platform/Cursor.hpp> #include <Nazara/Platform/Cursor.hpp>
#include <Nazara/Platform/Debug.hpp>
#include <Nazara/Platform/Event.hpp> #include <Nazara/Platform/Event.hpp>
#include <Nazara/Platform/Icon.hpp> #include <Nazara/Platform/Icon.hpp>
#include <Nazara/Platform/VideoMode.hpp> #include <Nazara/Platform/VideoMode.hpp>
@ -15,11 +15,11 @@
#include <Nazara/Platform/X11/CursorImpl.hpp> #include <Nazara/Platform/X11/CursorImpl.hpp>
#include <Nazara/Platform/X11/Display.hpp> #include <Nazara/Platform/X11/Display.hpp>
#include <Nazara/Platform/X11/IconImpl.hpp> #include <Nazara/Platform/X11/IconImpl.hpp>
#include <Nazara/Platform/X11/WindowImpl.hpp>
#include <xcb/xcb_keysyms.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/XF86keysym.h> #include <X11/XF86keysym.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <xcb/xcb_keysyms.h>
#include <Nazara/Platform/Debug.hpp>
/* /*
Things to do left: Things to do left:
@ -237,13 +237,11 @@ namespace Nz
if (m_ownsWindow) if (m_ownsWindow)
{ {
if (m_style & WindowStyle_Threaded) if (m_style & WindowStyle_Threaded)
{
if (m_thread.IsJoinable()) if (m_thread.IsJoinable())
{ {
m_threadActive = false; m_threadActive = false;
m_thread.Join(); m_thread.Join();
} }
}
// Destroy the window // Destroy the window
if (m_window && m_ownsWindow) if (m_window && m_ownsWindow)
@ -341,7 +339,7 @@ namespace Nz
if (error) if (error)
NazaraError("Failed to check if window has focus"); NazaraError("Failed to check if window has focus");
return (reply->focus == m_window); return reply->focus == m_window;
} }
void WindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY) void WindowImpl::IgnoreNextMouseEvent(int mouseX, int mouseY)
@ -659,9 +657,7 @@ namespace Nz
) )
NazaraError("Failed to change window visibility to visible"); NazaraError("Failed to change window visibility to visible");
} }
else else if (!X11::CheckCookie(
{
if (!X11::CheckCookie(
connection, connection,
xcb_unmap_window( xcb_unmap_window(
connection, connection,
@ -669,7 +665,6 @@ namespace Nz
)) ))
) )
NazaraError("Failed to change window visibility to invisible"); NazaraError("Failed to change window visibility to invisible");
}
xcb_flush(connection); xcb_flush(connection);
} }
@ -852,7 +847,7 @@ namespace Nz
case XK_KP_Home: return Keyboard::Numpad7; case XK_KP_Home: return Keyboard::Numpad7;
case XK_KP_Up: return Keyboard::Numpad8; case XK_KP_Up: return Keyboard::Numpad8;
case XK_KP_Page_Up: return Keyboard::Numpad9; case XK_KP_Page_Up: return Keyboard::Numpad9;
case XK_KP_Enter: return Keyboard::Return; case XK_KP_Enter: return Keyboard::NumpadReturn;
case XK_KP_Subtract: return Keyboard::Subtract; case XK_KP_Subtract: return Keyboard::Subtract;
// Divers // Divers
@ -900,6 +895,8 @@ namespace Nz
case XK_space: return Keyboard::Space; case XK_space: return Keyboard::Space;
case XK_Tab: return Keyboard::Tab; case XK_Tab: return Keyboard::Tab;
case XK_grave: return Keyboard::Tilde; case XK_grave: return Keyboard::Tilde;
case XK_Menu: return Keyboard::Menu;
case XK_less: return Keyboard::ISOBackslash102;
// Touches navigateur // Touches navigateur
case XF86XK_Back: return Keyboard::Browser_Back; case XF86XK_Back: return Keyboard::Browser_Back;
@ -1233,8 +1230,6 @@ namespace Nz
{ {
event.type = Nz::WindowEventType_MouseWheelMoved; event.type = Nz::WindowEventType_MouseWheelMoved;
event.mouseWheel.delta = (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) ? 1 : -1; event.mouseWheel.delta = (buttonReleaseEvent->detail == XCB_BUTTON_INDEX_4) ? 1 : -1;
event.mouseWheel.x = buttonReleaseEvent->event_x;
event.mouseWheel.y = buttonReleaseEvent->event_y;
break; break;
} }
default: default:

View File

@ -12,7 +12,13 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
#include <Nazara/Renderer/SDL2/ContextImpl.hpp>
#if defined(NAZARA_PLATFORM_LINUX)
#define CALLBACK
#endif
#elif defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Renderer/Win32/ContextImpl.hpp> #include <Nazara/Renderer/Win32/ContextImpl.hpp>
#elif defined(NAZARA_PLATFORM_GLX) #elif defined(NAZARA_PLATFORM_GLX)
#include <Nazara/Renderer/GLX/ContextImpl.hpp> #include <Nazara/Renderer/GLX/ContextImpl.hpp>

View File

@ -2,21 +2,23 @@
// This file is part of the "Nazara Engine - Renderer module" // This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Core/CallOnExit.hpp> #include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <Nazara/Renderer/Context.hpp> #include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/RenderStates.hpp> #include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderTarget.hpp> #include <Nazara/Renderer/RenderTarget.hpp>
#if defined(NAZARA_PLATFORM_GLX) #if defined(NAZARA_PLATFORM_SDL2)
#include <SDL2/SDL_video.h>
#elif defined(NAZARA_PLATFORM_GLX)
#include <Nazara/Platform/X11/Display.hpp> #include <Nazara/Platform/X11/Display.hpp>
#endif // NAZARA_PLATFORM_GLX #endif // NAZARA_PLATFORM_GLX
#include <Nazara/Renderer/Debug.hpp>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <unordered_map> #include <unordered_map>
#include <Nazara/Renderer/Debug.hpp>
namespace Nz namespace Nz
{ {
@ -28,7 +30,9 @@ namespace Nz
OpenGLFunc LoadEntry(const char* name, bool launchException = true) OpenGLFunc LoadEntry(const char* name, bool launchException = true)
{ {
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_SDL2)
OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(SDL_GL_GetProcAddress(name));
#elif defined(NAZARA_PLATFORM_WINDOWS)
OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(wglGetProcAddress(name)); OpenGLFunc entry = reinterpret_cast<OpenGLFunc>(wglGetProcAddress(name));
if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1 if (!entry) // wglGetProcAddress ne fonctionne pas sur les fonctions OpenGL <= 1.1
entry = reinterpret_cast<OpenGLFunc>(GetProcAddress(openGLlibrary, name)); entry = reinterpret_cast<OpenGLFunc>(GetProcAddress(openGLlibrary, name));
@ -51,7 +55,16 @@ namespace Nz
bool LoadLibrary() bool LoadLibrary()
{ {
#ifdef NAZARA_PLATFORM_WINDOWS #if defined(NAZARA_PLATFORM_SDL2)
if (SDL_GL_LoadLibrary(nullptr) != 0)
{
NazaraError(SDL_GetError());
return false;
}
return true;
#elif defined(NAZARA_PLATFORM_WINDOWS)
openGLlibrary = ::LoadLibraryA("opengl32.dll"); openGLlibrary = ::LoadLibraryA("opengl32.dll");
return openGLlibrary != nullptr; return openGLlibrary != nullptr;
@ -62,7 +75,9 @@ namespace Nz
void UnloadLibrary() void UnloadLibrary()
{ {
#ifdef NAZARA_PLATFORM_WINDOWS #if defined(NAZARA_PLATFORM_SDL2)
SDL_GL_UnloadLibrary();
#elif defined(NAZARA_PLATFORM_WINDOWS)
FreeLibrary(openGLlibrary); FreeLibrary(openGLlibrary);
#endif #endif
} }
@ -158,7 +173,6 @@ namespace Nz
// Les fonctions de blend n'a aucun intérêt sans blending // Les fonctions de blend n'a aucun intérêt sans blending
if (states.blending) if (states.blending)
{
if (currentRenderStates.dstBlend != states.dstBlend || if (currentRenderStates.dstBlend != states.dstBlend ||
currentRenderStates.srcBlend != states.srcBlend) currentRenderStates.srcBlend != states.srcBlend)
{ {
@ -166,7 +180,6 @@ namespace Nz
currentRenderStates.dstBlend = states.dstBlend; currentRenderStates.dstBlend = states.dstBlend;
currentRenderStates.srcBlend = states.srcBlend; currentRenderStates.srcBlend = states.srcBlend;
} }
}
if (states.depthBuffer) if (states.depthBuffer)
{ {
@ -187,13 +200,11 @@ namespace Nz
// Inutile de changer le mode de face culling s'il n'est pas actif // Inutile de changer le mode de face culling s'il n'est pas actif
if (states.faceCulling) if (states.faceCulling)
{
if (currentRenderStates.cullingSide != states.cullingSide) if (currentRenderStates.cullingSide != states.cullingSide)
{ {
glCullFace(FaceSide[states.cullingSide]); glCullFace(FaceSide[states.cullingSide]);
currentRenderStates.cullingSide = states.cullingSide; currentRenderStates.cullingSide = states.cullingSide;
} }
}
if (currentRenderStates.faceFilling != states.faceFilling) if (currentRenderStates.faceFilling != states.faceFilling)
{ {
@ -731,7 +742,12 @@ namespace Nz
if (s_initialized) if (s_initialized)
return true; return true;
#if defined(NAZARA_PLATFORM_GLX)
#if defined(NAZARA_PLATFORM_SDL2)
if (SDL_VideoInit(NULL) != 0)
NazaraError(SDL_GetError());
#elif defined(NAZARA_PLATFORM_GLX)
Initializer<X11> display; Initializer<X11> display;
if (!display) if (!display)
{ {
@ -768,7 +784,7 @@ namespace Nz
/****************************Chargement OpenGL****************************/ /****************************Chargement OpenGL****************************/
///FIXME: I'm really thinking this is a mistake and GLX has no need to be initialized differently (Lynix) ///FIXME: I'm really thinking this is a mistake and GLX has no need to be initialized differently (Lynix)
#if defined(NAZARA_PLATFORM_LINUX) #if defined(NAZARA_PLATFORM_LINUX) && not defined(NAZARA_PLATFORM_SDL2)
glXCreateContextAttribs = reinterpret_cast<GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC>(LoadEntry("glXCreateContextAttribsARB", false)); glXCreateContextAttribs = reinterpret_cast<GLX::PFNGLXCREATECONTEXTATTRIBSARBPROC>(LoadEntry("glXCreateContextAttribsARB", false));
#endif #endif
@ -779,7 +795,7 @@ namespace Nz
return false; return false;
} }
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS) && not defined(NAZARA_PLATFORM_SDL2)
wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(LoadEntry("wglCreateContextAttribsARB", false)); wglCreateContextAttribs = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(LoadEntry("wglCreateContextAttribsARB", false));
wglChoosePixelFormat = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(LoadEntry("wglChoosePixelFormatARB", false)); wglChoosePixelFormat = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(LoadEntry("wglChoosePixelFormatARB", false));
if (!wglChoosePixelFormat) if (!wglChoosePixelFormat)
@ -1049,7 +1065,7 @@ namespace Nz
NazaraWarning("Failed to load extension system"); NazaraWarning("Failed to load extension system");
} }
#ifdef NAZARA_PLATFORM_WINDOWS #if defined(NAZARA_PLATFORM_WINDOWS) && !defined(NAZARA_PLATFORM_SDL2)
{ {
bool loaded; bool loaded;
if (wglGetExtensionsStringARB) if (wglGetExtensionsStringARB)
@ -1232,7 +1248,11 @@ namespace Nz
bool OpenGL::IsSupported(const String& string) bool OpenGL::IsSupported(const String& string)
{ {
#ifdef NAZARA_PLATFORM_SDL2
return SDL_GL_ExtensionSupported(string.GetConstBuffer());
#else
return s_openGLextensionSet.find(string) != s_openGLextensionSet.end(); return s_openGLextensionSet.find(string) != s_openGLextensionSet.end();
#endif
} }
void OpenGL::SetBuffer(BufferType type, GLuint id) void OpenGL::SetBuffer(BufferType type, GLuint id)

View File

@ -0,0 +1,147 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// Code inspiré de NeHe (Lesson1) et de la SFML par Laurent Gomila
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/Debug.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/SDL2/ContextImpl.hpp>
#include <array>
#include <cstring>
namespace Nz
{
ContextImpl::ContextImpl()
{
}
bool ContextImpl::Activate() const
{
bool success = SDL_GL_MakeCurrent(m_window, m_context) == 0;
if (!success)
NazaraError(SDL_GetError());
else
lastActive = m_window;
return success;
}
bool ContextImpl::Create(ContextParameters& parameters)
{
if (parameters.window)
{
m_window = static_cast<SDL_Window*>(parameters.window);
m_ownsWindow = false;
}
else
{
m_window = SDL_CreateWindow("STATIC", 0, 0, 1, 1, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
if (!m_window)
{
NazaraError("Failed to create window");
return false;
}
//SDL_HideWindow(m_window);
m_ownsWindow = true;
}
// En cas d'exception, la ressource sera quand même libérée
CallOnExit onExit([this] ()
{
Destroy();
});
bool valid = true;
std::array<std::pair<SDL_GLattr, int>, 13> attributes{
std::pair<SDL_GLattr, int>
{SDL_GL_CONTEXT_PROFILE_MASK, parameters.compatibilityProfile ? SDL_GL_CONTEXT_PROFILE_COMPATIBILITY : SDL_GL_CONTEXT_PROFILE_CORE},
{SDL_GL_CONTEXT_MAJOR_VERSION, parameters.majorVersion},
{SDL_GL_CONTEXT_MINOR_VERSION, parameters.minorVersion},
{SDL_GL_CONTEXT_FLAGS, parameters.debugMode ? SDL_GL_CONTEXT_DEBUG_FLAG : 0},
{SDL_GL_SHARE_WITH_CURRENT_CONTEXT, true},
{SDL_GL_RED_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3}, // sad but I don't have a solution for now
{SDL_GL_GREEN_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3},
{SDL_GL_BLUE_SIZE, (parameters.bitsPerPixel == 32) ? 8 : parameters.bitsPerPixel / 3},
{SDL_GL_ALPHA_SIZE, (parameters.bitsPerPixel == 32) ? 8 : 0},
{SDL_GL_DEPTH_SIZE, parameters.depthBits},
{SDL_GL_STENCIL_SIZE, parameters.stencilBits},
//{SDL_GL_DOUBLEBUFFER, parameters.doubleBuffered}, // doesn't work if we dont close all windows
{SDL_GL_MULTISAMPLEBUFFERS, parameters.antialiasingLevel > 0 ? GL_TRUE : GL_FALSE},
{SDL_GL_MULTISAMPLESAMPLES, parameters.antialiasingLevel}
};
for (const auto& attribute : attributes) {
valid &= SDL_GL_SetAttribute(attribute.first, attribute.second) == 0;
if (!valid) {
NazaraWarning(SDL_GetError());
break;
}
}
if (!valid)
NazaraWarning("Could not find a format matching requirements, disabling antialiasing...");
int antialiasingLevel;
SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &antialiasingLevel);
parameters.antialiasingLevel = static_cast<decltype(antialiasingLevel)>(antialiasingLevel);
onExit.Reset();
m_context = SDL_GL_CreateContext(m_window);
if (!m_context) {
NazaraError(SDL_GetError());
return false;
}
return true;
}
void ContextImpl::Destroy()
{
if (m_context)
{
SDL_GL_DeleteContext(m_context);
m_context = nullptr;
}
if (m_ownsWindow)
{
SDL_DestroyWindow(m_window);
m_window = nullptr;
}
}
void ContextImpl::EnableVerticalSync(bool enabled)
{
if (SDL_GL_SetSwapInterval(enabled ? 1 : 0) != 0)
NazaraError("Vertical sync not supported");
}
void ContextImpl::SwapBuffers()
{
SDL_GL_SwapWindow(m_window);
}
bool ContextImpl::Desactivate()
{
return SDL_GL_MakeCurrent(nullptr, nullptr) == 0;
}
SDL_Window* ContextImpl::lastActive = nullptr;
}

View File

@ -0,0 +1,42 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONTEXTIMPL_HPP
#define NAZARA_CONTEXTIMPL_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <SDL2/SDL.h>
namespace Nz
{
class ContextImpl
{
public:
ContextImpl();
bool Activate() const;
bool Create(ContextParameters& parameters);
void Destroy();
void EnableVerticalSync(bool enabled);
void SwapBuffers();
static bool Desactivate();
private:
SDL_GLContext m_context;
SDL_Window* m_window;
bool m_ownsWindow;
static SDL_Window* lastActive;
};
}
#endif // NAZARA_CONTEXTIMPL_HPP

View File

@ -19,7 +19,7 @@ void EventState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -18,7 +18,7 @@ void FocusState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -35,9 +35,9 @@ void KeyState::DrawMenu()
void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm) void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
else if (key.code == Nz::Keyboard::Key::N && key.shift) else if (key.virtualKey == Nz::Keyboard::VKey::N && key.shift)
{ {
if (m_keyStatus == KeyStatus::Pressed) if (m_keyStatus == KeyStatus::Pressed)
m_keyStatus = KeyStatus::Released; m_keyStatus = KeyStatus::Released;
@ -52,7 +52,7 @@ void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::Ke
else else
content = "Released: "; content = "Released: ";
Nz::String keyName = Nz::Keyboard::GetKeyName(key.code); Nz::String keyName = Nz::Keyboard::GetKeyName(key.virtualKey) + " (" + Nz::Keyboard::GetKeyName(key.scancode) + ")";
if (keyName.IsEmpty()) if (keyName.IsEmpty())
{ {
m_text.SetContent("Unknown\nM for Menu"); m_text.SetContent("Unknown\nM for Menu");

View File

@ -19,9 +19,9 @@ void MenuState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [this] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [this] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code >= Nz::Keyboard::Key::A && key.code < (Nz::Keyboard::Key::A + static_cast<int>(EventStatus::Max) - 1)) if (key.virtualKey >= Nz::Keyboard::VKey::A && key.virtualKey < static_cast<Nz::Keyboard::VKey>(static_cast<int>(Nz::Keyboard::VKey::A) + static_cast<int>(EventStatus::Max) - 1))
{ {
m_selectedNextState = key.code - static_cast<int>(Nz::Keyboard::Key::A); m_selectedNextState = static_cast<int>(key.virtualKey) - static_cast<int>(Nz::Keyboard::VKey::A);
} }
}); });
} }

View File

@ -18,7 +18,7 @@ void MouseClickState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -18,7 +18,7 @@ void MouseEnterState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -18,7 +18,7 @@ void MouseMoveState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -18,7 +18,7 @@ void TextEnterState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }

View File

@ -18,7 +18,7 @@ void WindowModificationState::Enter(Ndk::StateMachine& fsm)
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler(); Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key) m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
{ {
if (key.code == Nz::Keyboard::Key::M && key.shift) if (key.virtualKey == Nz::Keyboard::VKey::M && key.shift)
{ {
fsm.ChangeState(StateFactory::Get(EventStatus::Menu)); fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
} }