Update SDL3

This commit is contained in:
2024-08-07 21:05:59 +03:00
committed by Ari Vuollet
parent 67093a0d28
commit 0f20f387fc
41 changed files with 1211 additions and 684 deletions

View File

@@ -377,7 +377,7 @@ public:
OnMouseMoved(newPosition);
}
void SetRelativeMode(bool relativeMode) final override
void SetRelativeMode(bool relativeMode, Window* window) final override
{
if (relativeMode == _relativeMode)
return;
@@ -385,15 +385,12 @@ public:
if (relativeMode)
SDL_GetGlobalMouseState(&oldPosition.X, &oldPosition.Y);
Mouse::SetRelativeMode(relativeMode);
if (SDL_SetRelativeMouseMode(relativeMode ? SDL_TRUE : SDL_FALSE) != 0)
Mouse::SetRelativeMode(relativeMode, window);
if (SDL_SetWindowRelativeMouseMode(static_cast<SDLWindow*>(window)->_window, relativeMode ? SDL_TRUE : SDL_FALSE) != 0)
LOG(Error, "Failed to set mouse relative mode: {0}", String(SDL_GetError()));
if (!relativeMode)
{
SDL_WarpMouseGlobal(oldPosition.X, oldPosition.Y);
OnMouseMoved(oldPosition);
}
SetMousePosition(oldPosition);
}
};

View File

@@ -276,6 +276,7 @@ Rectangle SDLPlatform::GetVirtualDesktopBounds()
SDL_GetDisplayBounds(display, &rect);
bounds = Rectangle::Union(bounds, Rectangle(static_cast<float>(rect.x), static_cast<float>(rect.y), static_cast<float>(rect.w), static_cast<float>(rect.h)));
}
SDL_free((void*)displays);
return bounds;
}

View File

@@ -34,7 +34,12 @@
#endif
#define DefaultDPI 96
SDLWindow* lastEventWindow = nullptr;
namespace
{
SDLWindow* LastEventWindow = nullptr;
static SDL_Cursor* Cursors[SDL_NUM_SYSTEM_CURSORS] = { nullptr };
}
void* GetNativeWindowPointer(SDL_Window* window);
SDL_HitTestResult OnWindowHitTest(SDL_Window* win, const SDL_Point* area, void* data);
@@ -236,7 +241,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
}
#endif
lastEventWindow = this;
LastEventWindow = this;
#if PLATFORM_LINUX
// Initialize using the shared Display instance from SDL
@@ -293,8 +298,8 @@ void* SDLWindow::GetX11Display() const
SDLWindow::~SDLWindow()
{
if (lastEventWindow == this)
lastEventWindow = nullptr;
if (LastEventWindow == this)
LastEventWindow = nullptr;
if (_window == nullptr)
return;
@@ -374,47 +379,20 @@ SDL_HitTestResult OnWindowHitTest(SDL_Window* win, const SDL_Point* area, void*
SDLWindow* SDLWindow::GetWindowFromEvent(const SDL_Event& event)
{
SDL_WindowID windowId;
if (event.type >= SDL_EVENT_WINDOW_FIRST && event.type <= SDL_EVENT_WINDOW_LAST)
windowId = event.window.windowID;
else if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP)
windowId = event.key.windowID;
else if (event.type == SDL_EVENT_TEXT_EDITING)
windowId = event.edit.windowID;
else if (event.type == SDL_EVENT_TEXT_INPUT)
windowId = event.text.windowID;
else if (event.type == SDL_EVENT_MOUSE_MOTION)
windowId = event.motion.windowID;
else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN || event.type == SDL_EVENT_MOUSE_BUTTON_UP)
windowId = event.button.windowID;
else if (event.type == SDL_EVENT_MOUSE_WHEEL)
windowId = event.wheel.windowID;
else if (event.type == SDL_EVENT_FINGER_MOTION || event.type == SDL_EVENT_FINGER_DOWN || event.type == SDL_EVENT_FINGER_UP)
windowId = event.tfinger.windowID;
else if (event.type == SDL_EVENT_PEN_DOWN || event.type == SDL_EVENT_PEN_UP)
windowId = event.ptip.windowID;
else if (event.type == SDL_EVENT_PEN_MOTION)
windowId = event.pmotion.windowID;
else if (event.type == SDL_EVENT_PEN_BUTTON_DOWN || event.type == SDL_EVENT_PEN_BUTTON_UP)
windowId = event.pbutton.windowID;
else if (event.type == SDL_EVENT_DROP_BEGIN || event.type == SDL_EVENT_DROP_FILE || event.type == SDL_EVENT_DROP_TEXT || event.type == SDL_EVENT_DROP_COMPLETE || event.type == SDL_EVENT_DROP_POSITION)
windowId = event.drop.windowID;
else if (event.type >= SDL_EVENT_USER && event.type <= SDL_EVENT_LAST)
windowId = event.user.windowID;
else
SDL_Window* window = SDL_GetWindowFromEvent(&event);
if (window == nullptr)
return nullptr;
if (lastEventWindow == nullptr || windowId != lastEventWindow->_windowId)
lastEventWindow = GetWindowWithId(windowId);
return lastEventWindow;
if (LastEventWindow == nullptr || window != LastEventWindow->_window)
LastEventWindow = GetWindowWithSDLWindow(window);
return LastEventWindow;
}
SDLWindow* SDLWindow::GetWindowWithId(uint32 windowId)
SDLWindow* SDLWindow::GetWindowWithSDLWindow(SDL_Window* window)
{
WindowsManager::WindowsLocker.Lock();
for (auto win : WindowsManager::Windows)
{
if (win->_windowId == windowId)
if (win->_window == window)
return win;
}
WindowsManager::WindowsLocker.Unlock();
@@ -426,7 +404,6 @@ void SDLWindow::HandleEvent(SDL_Event& event)
if (_isClosing)
return;
// NOTE: Update window handling in SDLWindow::GetWindowFromEvent when any new events are added here
switch (event.type)
{
case SDL_EVENT_WINDOW_EXPOSED:
@@ -1012,7 +989,7 @@ void SDLWindow::StartTrackingMouse(bool useMouseScreenOffset)
// For viewport camera mouse tracking we want to use relative mode for best precision
if (_cursor == CursorType::Hidden)
Input::Mouse->SetRelativeMode(true);
Input::Mouse->SetRelativeMode(true, this);
}
}
@@ -1031,7 +1008,7 @@ void SDLWindow::EndTrackingMouse()
LOG(Warning, "SDL_CaptureMouse: {0}", String(SDL_GetError()));
}
Input::Mouse->SetRelativeMode(false);
Input::Mouse->SetRelativeMode(false, this);
}
void SDLWindow::StartClippingCursor(const Rectangle& bounds)
@@ -1090,21 +1067,19 @@ void SDLWindow::CheckForWindowResize()
OnResize(width, height);
}
void SDLWindow::UpdateCursor() const
void SDLWindow::UpdateCursor()
{
static SDL_Cursor* cursors[SDL_NUM_SYSTEM_CURSORS] = { nullptr };
if (_cursor == CursorType::Hidden)
{
SDL_HideCursor();
if (_isTrackingMouse)
Input::Mouse->SetRelativeMode(true);
Input::Mouse->SetRelativeMode(true, this);
return;
}
SDL_ShowCursor();
//if (_isTrackingMouse)
// Input::Mouse->SetRelativeMode(false);
// Input::Mouse->SetRelativeMode(false, this);
int32 index = SDL_SYSTEM_CURSOR_DEFAULT;
switch (_cursor)
@@ -1147,9 +1122,9 @@ void SDLWindow::UpdateCursor() const
break;
}
if (cursors[index] == nullptr)
cursors[index] = SDL_CreateSystemCursor(static_cast<SDL_SystemCursor>(index));
SDL_SetCursor(cursors[index]);
if (Cursors[index] == nullptr)
Cursors[index] = SDL_CreateSystemCursor(static_cast<SDL_SystemCursor>(index));
SDL_SetCursor(Cursors[index]);
}
#endif

View File

@@ -21,6 +21,7 @@ class FLAXENGINE_API SDLWindow : public WindowBase
#endif
{
friend SDLPlatform;
friend class SDLMouse;
#if PLATFORM_LINUX
friend LinuxPlatform;
friend MessageBox;
@@ -55,10 +56,10 @@ public:
private:
static SDLWindow* GetWindowFromEvent(const SDL_Event& event);
static SDLWindow* GetWindowWithId(uint32 windowId);
static SDLWindow* GetWindowWithSDLWindow(SDL_Window* window);
void HandleEvent(SDL_Event& event);
void CheckForWindowResize();
void UpdateCursor() const;
void UpdateCursor();
#if PLATFORM_LINUX
DragDropEffect DoDragDropWayland(const StringView& data);