_window positioning that works on windows

This commit is contained in:
2024-10-07 21:39:36 +03:00
parent 6ab6b14cb5
commit bcb7bb4396
2 changed files with 17 additions and 7 deletions

View File

@@ -196,6 +196,10 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
} }
} }
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(); SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetNumberProperty(props, "flags", flags); SDL_SetNumberProperty(props, "flags", flags);
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, settings.Title.ToStringAnsi().Get()); SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, settings.Title.ToStringAnsi().Get());
@@ -242,16 +246,17 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
SDL_GetWindowSizeInPixels(_window, &rect.w, &rect.h); SDL_GetWindowSizeInPixels(_window, &rect.w, &rect.h);
_cachedClientRectangle = Rectangle((float)rect.x, (float)rect.y, (float)rect.w, (float)rect.h); _cachedClientRectangle = Rectangle((float)rect.x, (float)rect.y, (float)rect.w, (float)rect.h);
Int2 newpos = GetPosition(); Int2 newpos = GetClientPosition();
LOG(Info, "new window at {}, expected: {}", newpos, oldpos); //Int2 newposclient = GetClientPosition();
ASSERT(newpos == oldpos); LOG(Info, "new window at {}, input {}, expected: {}", newpos, oldpos, oldpos2);
ASSERT(newpos == oldpos || newpos == oldpos2);
oldpos = newpos; /*oldpos = newpos;
SetPosition(newpos); SetPosition(newpos);
newpos = GetPosition(); newpos = GetPosition();
LOG(Info, "new window sanity set at {}", newpos); LOG(Info, "new window sanity set at {}", newpos);
ASSERT(newpos == oldpos); ASSERT(newpos == oldpos);*/
SDL_SetWindowHitTest(_window, &OnWindowHitTest, this); SDL_SetWindowHitTest(_window, &OnWindowHitTest, this);
InitSwapChain(); InitSwapChain();
@@ -952,6 +957,11 @@ void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition,
else else
#endif #endif
{ {
#if PLATFORM_WINDOWS
//relativePosition = Int2::Zero;
return;
#endif
SDLWindow* parent; SDLWindow* parent;
if (SDLPlatform::UsesX11()) if (SDLPlatform::UsesX11())
{ {

View File

@@ -79,7 +79,7 @@ namespace FlaxEngine.GUI
WrapPosition(ref mousePos, 10); WrapPosition(ref mousePos, 10);
locationSS = mousePos + new Float2(15, 10); locationSS = mousePos + new Float2(15, 10);
var ppp = Input.MouseScreenPosition; var ppp = Input.MouseScreenPosition;
locationSS = new Float2(5, 5); //locationSS = new Float2(5, 5);
var bef = locationSS; var bef = locationSS;
// Create window // Create window
@@ -231,7 +231,7 @@ namespace FlaxEngine.GUI
var bef = _window.Position; var bef = _window.Position;
WrapPosition(ref mousePos, 10); WrapPosition(ref mousePos, 10);
mousePos += new Float2(15, 10); mousePos += new Float2(15, 10);
mousePos = new Float2(5, 5); //mousePos = new Float2(5, 5);
if (_window) if (_window)
_window.Position = mousePos; _window.Position = mousePos;