Fix WindowHandles
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Platform/Debug.hpp>
|
||||
#include <Nazara/Platform/SDL2/InputImpl.hpp>
|
||||
#include <Nazara/Platform/SDL2/SDLHelper.hpp>
|
||||
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#include <SDL2/SDL_keyboard.h>
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
@@ -45,21 +46,10 @@ namespace Nz
|
||||
|
||||
Vector2i EventImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
auto handle = relativeTo.GetHandle();
|
||||
if (handle)
|
||||
{
|
||||
auto windowPos = relativeTo.GetPosition();
|
||||
auto mousePos = GetMousePosition();
|
||||
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);
|
||||
}
|
||||
return mousePos - windowPos;
|
||||
}
|
||||
|
||||
bool EventImpl::IsKeyPressed(Keyboard::Scancode key)
|
||||
@@ -98,7 +88,7 @@ namespace Nz
|
||||
|
||||
void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo)
|
||||
{
|
||||
auto handle = static_cast<SDL_Window*>(relativeTo.GetHandle());
|
||||
SDL_Window* handle = static_cast<const WindowImpl*>(relativeTo.GetImpl())->GetHandle();
|
||||
if (handle)
|
||||
SDL_WarpMouseInWindow(handle, x, y);
|
||||
else
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
@@ -17,6 +18,7 @@
|
||||
#include <Nazara/Platform/SDL2/WindowImpl.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_syswm.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
@@ -124,10 +126,9 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WindowImpl::Create(WindowHandle handle)
|
||||
bool WindowImpl::Create(void* handle)
|
||||
{
|
||||
m_handle = static_cast<SDL_Window*>(handle);
|
||||
|
||||
m_handle = SDL_CreateWindowFrom(handle);
|
||||
if (!m_handle || !SDL_GetWindowID(m_handle))
|
||||
{
|
||||
NazaraError("Invalid handle");
|
||||
@@ -171,7 +172,7 @@ namespace Nz
|
||||
m_smoothScrolling = enable;
|
||||
}
|
||||
|
||||
WindowHandle WindowImpl::GetHandle() const
|
||||
SDL_Window* WindowImpl::GetHandle() const
|
||||
{
|
||||
return m_handle;
|
||||
}
|
||||
@@ -190,6 +191,56 @@ namespace Nz
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
WindowHandle WindowImpl::GetSystemHandle() const
|
||||
{
|
||||
SDL_SysWMinfo wmInfo;
|
||||
if (SDL_GetWindowWMInfo(m_handle, &wmInfo) != SDL_TRUE)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
NazaraError(std::string("failed to retrieve window manager info: ") + SDL_GetError());
|
||||
}
|
||||
|
||||
WindowHandle handle;
|
||||
|
||||
switch (wmInfo.subsystem)
|
||||
{
|
||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
||||
case SDL_SYSWM_X11:
|
||||
{
|
||||
handle.type = WindowManager::X11;
|
||||
handle.x11.display = wmInfo.info.x11.display;
|
||||
handle.x11.window = wmInfo.info.x11.window;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND)
|
||||
case SDL_SYSWM_WAYLAND:
|
||||
{
|
||||
handle.type = WindowManager::Wayland;
|
||||
handle.wayland.display = wmInfo.info.wl.display;
|
||||
handle.wayland.surface = wmInfo.info.wl.surface;
|
||||
handle.wayland.shellSurface = wmInfo.info.wl.shell_surface;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
|
||||
case SDL_SYSWM_WINDOWS:
|
||||
{
|
||||
handle.type = WindowManager::Windows;
|
||||
handle.windows.window = wmInfo.info.win.window;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
NazaraError("unhandled window subsystem");
|
||||
}
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
String WindowImpl::GetTitle() const
|
||||
{
|
||||
|
||||
@@ -38,17 +38,18 @@ namespace Nz
|
||||
~WindowImpl() = default;
|
||||
|
||||
bool Create(const VideoMode& mode, const String& title, WindowStyleFlags style);
|
||||
bool Create(WindowHandle handle);
|
||||
bool Create(void* handle);
|
||||
|
||||
void Destroy();
|
||||
|
||||
void EnableKeyRepeat(bool enable);
|
||||
void EnableSmoothScrolling(bool enable);
|
||||
|
||||
WindowHandle GetHandle() const;
|
||||
SDL_Window* GetHandle() const;
|
||||
Vector2i GetPosition() const;
|
||||
Vector2ui GetSize() const;
|
||||
WindowStyleFlags GetStyle() const;
|
||||
WindowHandle GetSystemHandle() const;
|
||||
String GetTitle() const;
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Window::Create(WindowHandle handle)
|
||||
bool Window::Create(void* handle)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
@@ -197,19 +197,6 @@ namespace Nz
|
||||
m_impl->EnableSmoothScrolling(enable);
|
||||
}
|
||||
|
||||
WindowHandle Window::GetHandle() const
|
||||
{
|
||||
#if NAZARA_PLATFORM_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Window not created");
|
||||
return static_cast<WindowHandle>(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetHandle();
|
||||
}
|
||||
|
||||
Vector2i Window::GetPosition() const
|
||||
{
|
||||
#if NAZARA_PLATFORM_SAFE
|
||||
@@ -249,6 +236,19 @@ namespace Nz
|
||||
return m_impl->GetStyle();
|
||||
}
|
||||
|
||||
WindowHandle Window::GetSystemHandle() const
|
||||
{
|
||||
#if NAZARA_PLATFORM_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Window not created");
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->GetSystemHandle();
|
||||
}
|
||||
|
||||
String Window::GetTitle() const
|
||||
{
|
||||
#if NAZARA_PLATFORM_SAFE
|
||||
@@ -613,6 +613,11 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
void* Window::GetHandle()
|
||||
{
|
||||
return (m_impl) ? m_impl->GetHandle() : nullptr;
|
||||
}
|
||||
|
||||
bool Window::OnWindowCreated()
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Nz
|
||||
Create(mode, title, style, parameters);
|
||||
}
|
||||
|
||||
RenderWindow::RenderWindow(WindowHandle handle, const ContextParameters& parameters) :
|
||||
RenderWindow::RenderWindow(void* handle, const ContextParameters& parameters) :
|
||||
RenderTarget(), Window()
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
@@ -125,7 +125,7 @@ namespace Nz
|
||||
return Window::Create(mode, title, style);
|
||||
}
|
||||
|
||||
bool RenderWindow::Create(WindowHandle handle, const ContextParameters& parameters)
|
||||
bool RenderWindow::Create(void* handle, const ContextParameters& parameters)
|
||||
{
|
||||
m_parameters = parameters;
|
||||
return Window::Create(handle);
|
||||
|
||||
Reference in New Issue
Block a user