_works 0,0 primary screen, returned positions correct but visually wrong
This commit is contained in:
@@ -855,7 +855,11 @@ Int2 GetSDLWindowPosition(const SDLWindow* window)
|
|||||||
{
|
{
|
||||||
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
|
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
|
||||||
{
|
{
|
||||||
SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &position.X, &position.Y);
|
Int2 parentPosition = GetSDLWindowPosition(window->GetSettings().Parent);
|
||||||
|
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
|
||||||
|
position -= parentPosition;
|
||||||
|
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
|
||||||
|
//position -= Int2(monitorBounds.GetTopLeft());
|
||||||
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
|
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
|
||||||
//position += Int2(monitorBounds.GetTopLeft());
|
//position += Int2(monitorBounds.GetTopLeft());
|
||||||
}
|
}
|
||||||
@@ -982,15 +986,16 @@ void SetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition)
|
|||||||
SDLWindow* parent = window->GetSettings().Parent;
|
SDLWindow* parent = window->GetSettings().Parent;
|
||||||
while (parent != nullptr)
|
while (parent != nullptr)
|
||||||
{
|
{
|
||||||
if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup))
|
if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)
|
||||||
break;
|
{
|
||||||
|
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;
|
parent = parent->GetSettings().Parent;
|
||||||
}
|
}
|
||||||
if (parent != nullptr)
|
|
||||||
{
|
|
||||||
Int2 parentPosition = GetSDLWindowPosition(parent);
|
|
||||||
relativePosition += parentPosition;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (SDLPlatform::UsesWayland())
|
else if (SDLPlatform::UsesWayland())
|
||||||
{
|
{
|
||||||
@@ -1053,9 +1058,19 @@ void SDLWindow::SetPosition(const Float2& position)
|
|||||||
// The position is relative to the parent window
|
// The position is relative to the parent window
|
||||||
Int2 relativePosition(static_cast<int>(position.X), static_cast<int>(position.Y));
|
Int2 relativePosition(static_cast<int>(position.X), static_cast<int>(position.Y));
|
||||||
relativePosition += topLeftBorder;
|
relativePosition += topLeftBorder;
|
||||||
GetRelativeWindowPosition(this, relativePosition);
|
SetRelativeWindowPosition(this, relativePosition);
|
||||||
|
|
||||||
SDL_SetWindowPosition(_window, relativePosition.X, relativePosition.Y);
|
SDL_SetWindowPosition(_window, 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 == relativePosition.X && newPos.Y == relativePosition.Y))
|
||||||
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLWindow::SetClientPosition(const Float2& position)
|
void SDLWindow::SetClientPosition(const Float2& position)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using FlaxEditor;
|
||||||
|
|
||||||
namespace FlaxEngine.GUI
|
namespace FlaxEngine.GUI
|
||||||
{
|
{
|
||||||
@@ -82,11 +83,13 @@ namespace FlaxEngine.GUI
|
|||||||
//WrapPosition(ref locationSS);
|
//WrapPosition(ref locationSS);
|
||||||
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 bef = locationSS;
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
var desc = CreateWindowSettings.Default;
|
var desc = CreateWindowSettings.Default;
|
||||||
desc.StartPosition = WindowStartPosition.Manual;
|
desc.StartPosition = WindowStartPosition.Manual;
|
||||||
desc.Position = new Vector2(5, 5);//locationSS;
|
desc.Position = locationSS;
|
||||||
desc.Size = dpiSize;
|
desc.Size = dpiSize;
|
||||||
desc.Fullscreen = false;
|
desc.Fullscreen = false;
|
||||||
desc.HasBorder = false;
|
desc.HasBorder = false;
|
||||||
@@ -110,6 +113,9 @@ namespace FlaxEngine.GUI
|
|||||||
Visible = true;
|
Visible = true;
|
||||||
_window.Show();
|
_window.Show();
|
||||||
_showTarget.OnTooltipShown(this);
|
_showTarget.OnTooltipShown(this);
|
||||||
|
|
||||||
|
var aff = _window.Position;
|
||||||
|
Editor.Log($"tooltip startpos: before: {bef}, after {aff}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -225,9 +231,15 @@ namespace FlaxEngine.GUI
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Position tooltip when mouse moves
|
// Position tooltip when mouse moves
|
||||||
//WrapPosition(ref mousePos, 10);
|
var ppp = Input.MouseScreenPosition;
|
||||||
//if (_window)
|
var bef = _window.Position;
|
||||||
// _window.Position = mousePos + new Float2(15, 10);
|
WrapPosition(ref mousePos, 10);
|
||||||
|
mousePos += new Float2(15, 10);
|
||||||
|
|
||||||
|
if (_window)
|
||||||
|
_window.Position = mousePos;
|
||||||
|
var aff = _window.Position;
|
||||||
|
Editor.Log($"tooltip updatepos: before: {bef}, new {mousePos}, after {aff}");
|
||||||
}
|
}
|
||||||
|
|
||||||
base.Update(deltaTime);
|
base.Update(deltaTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user