_cleanup windowing

This commit is contained in:
2025-01-01 03:33:38 +02:00
parent 5274a96a42
commit 99d2e7d842
2 changed files with 20 additions and 582 deletions

View File

@@ -33,7 +33,6 @@
#endif
#elif PLATFORM_LINUX
#include "Engine/Platform/Linux/IncludeX11.h"
#define X11_WINDOW_POSITION_WORKAROUND 1 // Popup windows report wrong position?
#endif
#define DefaultDPI 96
@@ -49,12 +48,7 @@ namespace
void* GetNativeWindowPointer(SDL_Window* window);
SDL_HitTestResult OnWindowHitTest(SDL_Window* win, const SDL_Point* area, void* data);
Int2 GetSDLWindowPosition(const SDLWindow* window);
void SetSDLWindowPosition(SDLWindow* window, const int x, const int y);
void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition, bool clienttoscreen = true);
void SetRelativeWindowPosition(const WindowType windowType, SDLWindow* parent, int32& xRel, int32& yRel);
Int2 GetSDLWindowScreenPosition(const SDLWindow* window);
void SetSDLWindowScreenPosition(SDLWindow* window, const int x, const int y);
class SDLDropFilesData : public IGuiData
@@ -111,8 +105,6 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
int32 windowHeight = clientHeight;
_clientSize = Float2((float)clientWidth, (float)clientHeight);
if (SDLPlatform::UsesWayland())
{
// The compositor seems to crash when something is rendered to the hidden popup window surface
@@ -146,57 +138,10 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
//if (_settings.Parent != nullptr && (_settings.Type != WindowType::Tooltip && _settings.Type != WindowType::Popup))
// _settings.Parent = nullptr;
if (_settings.Parent == nullptr && (_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup))
if (_settings.Parent != nullptr && _settings.Parent->_settings.Type != WindowType::Regular && (_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup))
{
// Creating a popup window on some platforms brings the parent window on top.
// Use the currently focused window as the parent instead to avoid losing focus of it
WindowsManager::WindowsLocker.Lock();
for (auto win : WindowsManager::Windows)
{
if (win->IsForegroundWindow())
{
_settings.Parent = win;
break;
if (win->_settings.Type == WindowType::Tooltip || win->_settings.Type == WindowType::Popup)
{
auto focusedParent = win->_settings.Parent;
//_settings.Parent = win;
while (focusedParent != nullptr /*&& (focusedParent->_settings.Type == WindowType::Tooltip || focusedParent->_settings.Type == WindowType::Popup)*/)
{
if (focusedParent->_settings.Parent == nullptr)
{
_settings.Parent = focusedParent;
break;
}
focusedParent = focusedParent->_settings.Parent;
//_settings.Parent = focusedParent;
//break;
}
/*while (focusedParent != nullptr)
{
if (focusedParent->_settings.Parent == nullptr)
{
_settings.Parent = focusedParent;
break;
}
focusedParent = focusedParent->_settings.Parent;
//_settings.Parent = focusedParent;
//break;
}*/
}
else
_settings.Parent = win;
break;
}
}
WindowsManager::WindowsLocker.Unlock();
if (_settings.Parent == nullptr)
_settings.Parent = Engine::MainWindow;
}
else if (_settings.Parent != nullptr && _settings.Parent->_settings.Type != WindowType::Regular && (_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup))
{
if (SDLPlatform::UsesX11())
// Reparent popup windows to top-most regular window
#if !PLATFORM_WINDOWS
{
auto parent = _settings.Parent->GetSettings().Parent;
while (parent != nullptr)
@@ -207,16 +152,9 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
parent = _settings.Parent->GetSettings().Parent;
}
}
#endif
}
Int2 oldpos(x, y);
if (_settings.Parent != nullptr)
{
SetRelativeWindowPosition(_settings.Type, _settings.Parent, x, y);
}
Int2 oldpos2(x, y);
// It should be noted that SDL creates the window in client-space coordinates (ignoring window decorations)
SDL_PropertiesID props = SDL_CreateProperties();
@@ -242,8 +180,6 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
_handle = GetNativeWindowPointer(_window);
ASSERT(_handle != nullptr);
//SDL_SyncWindow(_window);
#if PLATFORM_LINUX
if (SDLPlatform::UsesWayland())
{
@@ -254,39 +190,11 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
#endif
SDL_DisplayID display = SDL_GetDisplayForWindow(_window);
auto displayDpi = SDL_GetDisplayContentScale(display);
_dpiScale = SDL_GetWindowDisplayScale(_window);
_dpi = (int)(_dpiScale * DefaultDPI);
SDL_SetWindowMinimumSize(_window, (int)_settings.MinimumSize.X, (int)_settings.MinimumSize.Y);
SDL_SetWindowMaximumSize(_window, (int)_settings.MaximumSize.X, (int)_settings.MaximumSize.Y);
/*if (SDLPlatform::UsesWayland())
{
SDL_SyncWindow(_window);
Int2 scaledSize = Int2(clientWidth * _dpiScale, clientHeight * _dpiScale);
SDL_SetWindowSize(_window, scaledSize.X, scaledSize.Y);
SDL_SyncWindow(_window);
}*/
SDL_SyncWindow(_window);
SDL_Rect rect, rect2;
SDL_GetWindowPosition(_window, &rect.x, &rect.y);
SDL_GetWindowSizeInPixels(_window, &rect.w, &rect.h);
SDL_GetWindowSize(_window, &rect2.w, &rect2.h);
_cachedClientRectangle = Rectangle((float)rect.x, (float)rect.y, (float)rect.w, (float)rect.h);
Int2 sdlpos(rect.x, rect.y);
Int2 newpos = GetClientPosition();
Int2 newposclient = GetSDLWindowScreenPosition(this);
LOG(Info, "new window, sdl: {}, input {}, relative: {}", sdlpos, oldpos, newposclient);
//ASSERT(newpos == oldpos || newpos == oldpos2);
/*oldpos = newpos;
SetPosition(newpos);
newpos = GetPosition();
LOG(Info, "new window sanity set at {}", newpos);
ASSERT(newpos == oldpos);*/
SDL_SetWindowHitTest(_window, &OnWindowHitTest, this);
InitSwapChain();
@@ -945,8 +853,7 @@ void SDLWindow::SetClientBounds(const Rectangle& clientArea)
{
int oldX, oldY;
int oldW, oldH;
//SDL_GetWindowPosition(_window, &oldX, &oldY);
Int2 asd = GetSDLWindowScreenPosition(this); oldX = asd.X; oldY = asd.Y;
SDL_GetWindowPosition(_window, &oldX, &oldY);
SDL_GetWindowSizeInPixels(_window, &oldW, &oldH);
int newX = (int)clientArea.GetLeft();
@@ -954,482 +861,25 @@ void SDLWindow::SetClientBounds(const Rectangle& clientArea)
int newW = (int)clientArea.GetWidth();
int newH = (int)clientArea.GetHeight();
if (newX != oldX || newY != oldY)
SetSDLWindowScreenPosition(this, newX, newY);
//SetSDLWindowPosition(this, newX, newY);
//if (newX != oldX || newY != oldY)
SetSDLWindowScreenPosition(this, newX, newY);
SDL_SetWindowSize(_window, newW, newH);
LOG(Info, "SetClientBounds changed from ({},{} {}x{}) to ({},{} {}x{})", oldX, oldY, oldW, oldH,
(int)clientArea.GetLeft(), (int)clientArea.GetTop(), (int)clientArea.GetWidth(), (int)clientArea.GetHeight());
SDL_GetWindowPosition(_window, &oldX, &oldY);
SDL_GetWindowSizeInPixels(_window, &oldW, &oldH);
LOG(Info, "- verify: actual ({},{} {}x{}) req ({},{} {}x{})", oldX, oldY, oldW, oldH,
(int)clientArea.GetLeft(), (int)clientArea.GetTop(), (int)clientArea.GetWidth(), (int)clientArea.GetHeight());
}
Int2 GetSDLWindowPosition(const SDLWindow* window)
{
Int2 position;
SDL_GetWindowPosition(window->GetSDLWindow(), &position.X, &position.Y);
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (/*window->GetSettings().Type == WindowType::Tooltip ||*/ window->GetSettings().Type == WindowType::Popup)
{
auto oldPos = position;
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
//rootParentPosition = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position += rootParentPosition;
parent = parent->GetSettings().Parent;
}
}
#endif
}
else if (SDLPlatform::UsesWayland())
{
// Wayland doesn't support reporting window position in screen-space
/*auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 parentPosition;// = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
position += parentPosition;
parent = parent->GetSettings().Parent;
}*/
//Int2 rootParentPosition = GetSDLWindowPosition(parent);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
//position += rootParentPosition;
}
#endif
#if PLATFORM_WINDOWS
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
{
auto oldPos = position;
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
//rootParentPosition = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position += rootParentPosition;
parent = parent->GetSettings().Parent;
}
}
#endif
return position;
}
void SetSDLWindowPosition(SDLWindow* window, const int x, const int y)
void SetSDLWindowScreenPosition(SDLWindow* window, const int x, const int y)
{
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (/*window->GetSettings().Type == WindowType::Tooltip ||*/ window->GetSettings().Type == WindowType::Popup)
{
Int2 position(x, y);
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position -= rootParentPosition;
parent = parent->GetSettings().Parent;
}
return;
}
#endif
}
else if (SDLPlatform::UsesWayland())
/*if (SDLPlatform::UsesWayland())
{
int oldX, oldY;
SDL_GetWindowPosition(window->GetSDLWindow(), &oldX, &oldY);
if (x == oldX && y == oldY)
return;
}
}*/
#endif
SDL_SetWindowPosition(window->GetSDLWindow(), x, y);
}
Int2 GetSDLWindowScreenPosition(const SDLWindow* window)
{
Int2 position;
SDL_GetWindowPosition(window->GetSDLWindow(), &position.X, &position.Y);
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (/*window->GetSettings().Type == WindowType::Tooltip ||*/ window->GetSettings().Type == WindowType::Popup)
{
auto oldPos = position;
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
//rootParentPosition = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position += rootParentPosition;
parent = parent->GetSettings().Parent;
}
}
#endif
}
else if (SDLPlatform::UsesWayland())
{
// Wayland doesn't support reporting window position in screen-space
/*auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 parentPosition;// = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
position += parentPosition;
parent = parent->GetSettings().Parent;
}*/
//Int2 rootParentPosition = GetSDLWindowPosition(parent);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
//position += rootParentPosition;
}
#endif
#if PLATFORM_WINDOWS
if (true)
{
Int2 rel(0, 0);
SetRelativeWindowPosition(window->GetSettings().Type, window->GetSettings().Parent, rel.X, rel.Y);
position -= rel;
}
else
//if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
{
auto oldPos = position;
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
//rootParentPosition = GetSDLWindowPosition(parent);
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position += rootParentPosition;
if (parent->GetSettings().Parent == nullptr)
position -= rootParentPosition;
parent = parent->GetSettings().Parent;
}
}
#endif
GetRelativeWindowPosition(window, position, true); // windows NOOP
return position;
}
void SetSDLWindowScreenPosition(SDLWindow* window, const int xx, const int yy)
{
Int2 relativePosition(xx, yy);
SetRelativeWindowPosition(window->GetSettings().Type, window->GetSettings().Parent, relativePosition.X, relativePosition.Y);
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (/*window->GetSettings().Type == WindowType::Tooltip ||*/ window->GetSettings().Type == WindowType::Popup)
{
Int2 position(x, y);
auto parent = window->GetSettings().Parent;
while (parent != nullptr)
{
Int2 rootParentPosition;
SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.Y);
position -= rootParentPosition;
parent = parent->GetSettings().Parent;
}
return;
}
#endif
}
else if (SDLPlatform::UsesWayland())
{
int oldX, oldY;
SDL_GetWindowPosition(window->GetSDLWindow(), &oldX, &oldY);
if (x == oldX && y == oldY)
return;
}
#endif
SDL_SetWindowPosition(window->GetSDLWindow(), relativePosition.X, relativePosition.Y);
}
void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition, bool clienttoscreen)
{
// The relative positioning of windows are very inconsistent in different platforms.
// On Windows and X11: The child position is relative to parent windows only for tooltip and popup windows.
// On X11: The child position is always relative to parent windows.
// On Wayland: The child position is relative to root parent window.
#if PLATFORM_LINUX
//clienttoscreen = false;
if (SDLPlatform::UsesX11())
{
#if false
// This is correct for ClientToScreen (mouse position transformation)
if (clienttoscreen && window->GetSettings().Type != WindowType::Tooltip && window->GetSettings().Type != WindowType::Popup)
return;
SDLWindow* parent = window->GetSettings().Parent;
while (parent != nullptr)
{
/*if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
relativePosition += parentPosition;
break;
}*/
//if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup))
// break;
parent = parent->GetSettings().Parent;
}
/*if (parent != nullptr)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
relativePosition += parentPosition;
}*/
#endif
}
else if (SDLPlatform::UsesWayland())
{
/*SDLWindow* parent = window->GetSettings().Parent;
while (parent != nullptr)
{
if (parent->GetSettings().Parent == nullptr)
break;
parent = parent->GetSettings().Parent;
}
if (parent != nullptr)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
if (SDLPlatform::UsesX11())
{
relativePosition += parentPosition;
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
relativePosition += Int2(monitorBounds.GetTopLeft());
//relativePosition += Int2(monitorBounds.GetTopLeft());
//relativePosition += Int2(monitorBounds.GetTopLeft());
}
else
relativePosition = parentPosition;
}*/
}
else
#endif
{
#if PLATFORM_WINDOWS
//relativePosition = Int2::Zero;
return;
#endif
SDLWindow* parent;
if (SDLPlatform::UsesX11())
{
parent = (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup) ? window->GetSettings().Parent : window->GetSettings().Parent;
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//relativePosition -= Int2(monitorBounds.GetTopLeft());
}
else
parent = /*(window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup) ?*/ window->GetSettings().Parent /*: nullptr*/;
if (parent != nullptr)
{
//break;
//Int2 parentPosition = GetSDLWindowPosition(parent);
//relativePosition += parentPosition;//(parent->GetSettings().Type == WindowType::Tooltip || parent->GetSettings().Type == WindowType::Popup) ? parentPosition : -parentPosition;
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//relativePosition += Int2(monitorBounds.GetTopLeft());
//relativePosition -= parentPosition;
/*if (SDLPlatform::UsesX11())
parent = (parent->GetSettings().Type == WindowType::Tooltip || parent->GetSettings().Type == WindowType::Popup) ? parent->GetSettings().Parent : nullptr;
else*/
//if (parent->GetSettings().Parent == nullptr)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
relativePosition += parentPosition;
//break;
}
parent = parent->GetSettings().Parent;
}
}
}
void SetRelativeWindowPosition(const WindowType windowType, SDLWindow* theParent, int32& xRel, int32& yRel)
{
// The relative positioning of windows are very inconsistent in different platforms.
// On Windows and X11: The child position is relative to parent windows only for tooltip and popup windows.
// On X11: The child position is always relative to parent windows.
// On Wayland: The child position is relative to root parent window.
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
/**/
if (windowType != WindowType::Tooltip && windowType != WindowType::Popup)
{
/*auto parentPosition = theParent->ClientToScreen(Float2::Zero);
xRel -= Math::TruncToInt(parentPosition.X);
yRel -= Math::TruncToInt(parentPosition.Y);
auto parentType = theParent->GetSettings().Type;
auto parentParent = theParent->GetSettings().Parent;
if (parentParent != nullptr)
{
//if (parentType != WindowType::Popup && parentType != WindowType::Tooltip)
{
auto parentParentType = parentParent->GetSettings().Type;
//if (parentParentType != WindowType::Popup && parentParentType != WindowType::Tooltip)
{
auto parentParentPosition = parentParent->ClientToScreen(Float2::Zero);
xRel -= Math::TruncToInt(parentParentPosition.X);
yRel -= Math::TruncToInt(parentParentPosition.Y);
}
}
}*/
return;
}
SDLWindow* parent = theParent;
while (parent != nullptr)
{
//if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)
//if (false)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
//Int2 parentPosition;
//SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
xRel -= parentPosition.X;
yRel -= parentPosition.Y;
//break;
}
//if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup))
// break;
parent = parent->GetSettings().Parent;
}
/*if (parent != nullptr)
{
Int2 parentPosition = GetSDLWindowPosition(parent);
//Int2 parentPosition;
//SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
xRel -= parentPosition.X;
yRel -= parentPosition.Y;
}*/
}
else if (SDLPlatform::UsesWayland())
{
SDLWindow* parent = theParent;
/*while (parent != nullptr)
{
if (parent->GetSettings().Parent == nullptr)
break;
parent = parent->GetSettings().Parent;
}*/
if (parent != nullptr)
{
//Int2 parentPosition = GetSDLWindowPosition(parent);
if (SDLPlatform::UsesX11())
{
/*relativePosition += parentPosition;
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
relativePosition += Int2(monitorBounds.GetTopLeft());*/
//relativePosition += Int2(monitorBounds.GetTopLeft());
//relativePosition += Int2(monitorBounds.GetTopLeft());
}
else
{
//relativePosition -= parentPosition;
auto parentPosition = parent->ClientToScreen(Float2::Zero);
xRel -= Math::TruncToInt(parentPosition.X);
yRel -= Math::TruncToInt(parentPosition.Y);
auto parentType = parent->GetSettings().Type;
auto parentParent = parent->GetSettings().Parent;
if (parentParent != nullptr)
{
//if (parentType != WindowType::Popup && parentType != WindowType::Tooltip)
{
auto parentParentType = parentParent->GetSettings().Type;
//if (parentParentType != WindowType::Popup && parentParentType != WindowType::Tooltip)
{
auto parentParentPosition = parentParent->ClientToScreen(Float2::Zero);
xRel -= Math::TruncToInt(parentParentPosition.X);
yRel -= Math::TruncToInt(parentParentPosition.Y);
}
}
/*else
{
// submenu of context menu
x += 0;
}*/
}
}
}
}
else
#endif
{
return;
//if (windowType != WindowType::Popup && windowType != WindowType::Tooltip)
// return;
SDLWindow* topParent = nullptr;
bool workaround = false;
while (theParent != nullptr)
{
Int2 parentPosition;// = GetSDLWindowScreenPosition(theParent);
SDL_GetWindowPosition(theParent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
xRel -= parentPosition.X;
yRel -= parentPosition.Y;
/*
if (workaround && theParent->GetSettings().Parent == nullptr)
{
topParent = theParent;
}
if (theParent->GetSettings().Parent != nullptr && (windowType == WindowType::Popup || windowType == WindowType::Tooltip || windowType == WindowType::Utility))
{
if (theParent->GetSettings().Type != WindowType::Popup && theParent->GetSettings().Type != WindowType::Tooltip && theParent->GetSettings().Type != WindowType::Utility)
workaround = true;
}*/
theParent = theParent->GetSettings().Parent;
//if (theParent != nullptr && (theParent->GetSettings().Type == WindowType::Popup || theParent->GetSettings().Type == WindowType::Tooltip))
// break;
/*if (theParent != nullptr)
{
Int2 parentPosition = GetSDLWindowPosition(theParent);
xRel -= parentPosition.X;
yRel -= parentPosition.Y;
//theParent = theParent->GetSettings().Parent;
}*/
}
if (topParent != nullptr && workaround)
{
Int2 parentPosition;// = GetSDLWindowScreenPosition(theParent);
SDL_GetWindowPosition(topParent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
xRel -= parentPosition.X;
yRel -= parentPosition.Y;
}
}
}
void SDLWindow::SetPosition(const Float2& position)
{
Int2 topLeftBorder;
@@ -1438,7 +888,6 @@ void SDLWindow::SetPosition(const Float2& position)
// The position is relative to the parent window
Int2 relativePosition(static_cast<int>(position.X), static_cast<int>(position.Y));
relativePosition += topLeftBorder;
//SetRelativeWindowPosition(GetSettings().Type, GetSettings().Parent, relativePosition.X, relativePosition.Y);
if (SDLPlatform::UsesX11())
{
@@ -1463,7 +912,7 @@ void SDLWindow::SetPosition(const Float2& position)
void SDLWindow::SetClientPosition(const Float2& position)
{
SetSDLWindowPosition(this, static_cast<int>(position.X), static_cast<int>(position.Y));
SetSDLWindowScreenPosition(this, static_cast<int>(position.X), static_cast<int>(position.Y));
}
void SDLWindow::SetIsFullscreen(bool isFullscreen)
@@ -1483,10 +932,9 @@ Float2 SDLWindow::GetPosition() const
Int2 topLeftBorder;
SDL_GetWindowBordersSize(_window, &topLeftBorder.Y, &topLeftBorder.X, nullptr, nullptr);
// The position is relative to the parent window
Int2 position = GetSDLWindowScreenPosition(this);
Int2 position;
SDL_GetWindowPosition(_window, &position.X, &position.Y);
position -= topLeftBorder;
//GetRelativeWindowPosition(this, position);
return Float2(static_cast<float>(position.X), static_cast<float>(position.Y));
}
@@ -1511,26 +959,16 @@ Float2 SDLWindow::GetClientSize() const
Float2 SDLWindow::ScreenToClient(const Float2& screenPos) const
{
// The position is relative to the parent window
Int2 position = GetSDLWindowScreenPosition(this);
//Int2 position2 = position;
//GetRelativeWindowPosition(this, position);
//LOG(Info, "{} pos {}, rel {}", String(StringAnsi(SDL_GetWindowTitle(_window))), position2, position);
if (_settings.Parent != nullptr)
{
//LOG(Info, " parent:");
//_settings.Parent->ScreenToClient(screenPos);
}
Int2 position;
SDL_GetWindowPosition(_window, &position.X, &position.Y);
return screenPos - Float2(static_cast<float>(position.X), static_cast<float>(position.Y));
}
Float2 SDLWindow::ClientToScreen(const Float2& clientPos) const
{
// The position is relative to the parent window
Int2 position = GetSDLWindowScreenPosition(this);
//GetRelativeWindowPosition(this, position, true);
Int2 position;
SDL_GetWindowPosition(_window, &position.X, &position.Y);
return clientPos + Float2(static_cast<float>(position.X), static_cast<float>(position.Y));
}

View File

@@ -229,7 +229,7 @@ namespace FlaxEngine.GUI
// Auto hide if mouse leaves control area
Hide();
}
else if (true)
else if (false)
{
if (_window)
_window.Position = _window.Position;
@@ -240,7 +240,7 @@ namespace FlaxEngine.GUI
_window.ClientSize = _window.ClientSize + new Float2(2, 2);
}
}
else if (false)
else if (true)
{
// Position tooltip when mouse moves
WrapPosition(ref mousePos, 10);