From 16a5297809a6207739501ee15eaef469c218f3d3 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 1 Jan 2025 13:02:44 +0200 Subject: [PATCH] _cleaning --- Source/Engine/Platform/SDL/SDLWindow.cpp | 51 ++++++------------------ 1 file changed, 13 insertions(+), 38 deletions(-) diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index d58d2f60e..96ae4ff6e 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -604,15 +604,14 @@ void SDLWindow::HandleEvent(SDL_Event& event) } case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: { - SDL_DisplayID display = SDL_GetDisplayForWindow(_window); float scale = SDL_GetWindowDisplayScale(_window); if (scale > 0.0f && _dpiScale != scale) { float oldScale = _dpiScale; _dpiScale = scale; - _dpi = (int)(_dpiScale * DefaultDPI); - int w = (int)(_cachedClientRectangle.GetWidth() * (scale / oldScale)); - int h = (int)(_cachedClientRectangle.GetHeight() * (scale / oldScale)); + _dpi = static_cast(_dpiScale * DefaultDPI); + int w = static_cast(_cachedClientRectangle.GetWidth() * (scale / oldScale)); + int h = static_cast(_cachedClientRectangle.GetHeight() * (scale / oldScale)); _cachedClientRectangle.Size = Float2(static_cast(w), static_cast(h)); SDL_SetWindowSize(_window, w, h); // TODO: Recalculate fonts @@ -690,12 +689,6 @@ void SDLWindow::HandleEvent(SDL_Event& event) if (SDLInput::HandleEvent(this, event)) return; } - - // ignored - if (event.type == SDL_EVENT_WINDOW_ICCPROF_CHANGED) - return; - - //LOG(Info, "Unhandled SDL event: {0}", event.type); } void* SDLWindow::GetNativePtr() const @@ -854,18 +847,12 @@ void SDLWindow::BringToFront(bool force) void SDLWindow::SetClientBounds(const Rectangle& clientArea) { - int oldX, oldY; - int oldW, oldH; - SDL_GetWindowPosition(_window, &oldX, &oldY); - SDL_GetWindowSizeInPixels(_window, &oldW, &oldH); + int newX = static_cast(clientArea.GetLeft()); + int newY = static_cast(clientArea.GetTop()); + int newW = static_cast(clientArea.GetWidth()); + int newH = static_cast(clientArea.GetHeight()); - int newX = (int)clientArea.GetLeft(); - int newY = (int)clientArea.GetTop(); - int newW = (int)clientArea.GetWidth(); - int newH = (int)clientArea.GetHeight(); - - //if (newX != oldX || newY != oldY) - SetSDLWindowScreenPosition(this, newX, newY); + SetSDLWindowScreenPosition(this, newX, newY); SDL_SetWindowSize(_window, newW, newH); } @@ -888,29 +875,17 @@ void SDLWindow::SetPosition(const Float2& position) Int2 topLeftBorder; SDL_GetWindowBordersSize(_window, &topLeftBorder.Y, &topLeftBorder.X, nullptr, nullptr); - // The position is relative to the parent window - Int2 relativePosition(static_cast(position.X), static_cast(position.Y)); - relativePosition += topLeftBorder; + Int2 screenPosition(static_cast(position.X), static_cast(position.Y)); + screenPosition += topLeftBorder; if (SDLPlatform::UsesX11()) { + // TODO: is this needed? auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); - relativePosition += Int2(monitorBounds.GetTopLeft()); + screenPosition += Int2(monitorBounds.GetTopLeft()); } - SetSDLWindowScreenPosition(this, relativePosition.X, relativePosition.Y); - SDL_SyncWindow(_window); - - Int2 newPos; - SDL_GetWindowPosition(_window, &newPos.X, &newPos.Y); - //if (!(newPos.X == relativePosition.X && newPos.Y == relativePosition.Y)) - // ASSERT(false); - - newPos = GetPosition(); - //if (!(newPos.X == position.X && newPos.Y == position.Y)) - // ASSERT(false); - - //LOG(Info, "SetPosition before: {}, after {}, relative {}", position, newPos, relativePosition); + SetSDLWindowScreenPosition(this, screenPosition.X, screenPosition.Y); } void SDLWindow::SetClientPosition(const Float2& position)