This commit is contained in:
2024-08-11 17:00:30 +03:00
parent b04ffdcd3c
commit a4474416ac
3 changed files with 35 additions and 15 deletions

View File

@@ -483,7 +483,7 @@ bool SDLInput::HandleEvent(SDLWindow* window, SDL_Event& event)
else else
{ {
const Float2 mousePos = window->ClientToScreen({ event.motion.x, event.motion.y }); const Float2 mousePos = window->ClientToScreen({ event.motion.x, event.motion.y });
LOG(Info, "motion {},{}, mouse: {}", event.motion.x, event.motion.y, mousePos); //LOG(Info, "motion {},{}, mouse: {}", event.motion.x, event.motion.y, mousePos);
Input::Mouse->OnMouseMove(mousePos, window); Input::Mouse->OnMouseMove(mousePos, window);
} }
return true; return true;

View File

@@ -164,6 +164,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
// The SDL window position is always relative to the parent window // The SDL window position is always relative to the parent window
//x = 5; //x = 5;
//y = 5; //y = 5;
Int2 oldpos(x, y);
if (_settings.Parent != nullptr && SDLPlatform::UsesX11()) if (_settings.Parent != nullptr && SDLPlatform::UsesX11())
{//(_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup) {//(_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup)
//if (_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup) //if (_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup)
@@ -189,9 +190,9 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
} }
else else
{ {
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); /*auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
x -= (int)monitorBounds.GetLeft(); x -= (int)monitorBounds.GetLeft();
y -= (int)monitorBounds.GetTop(); y -= (int)monitorBounds.GetTop();*/
} }
} }
@@ -218,6 +219,8 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
_handle = GetNativeWindowPointer(_window); _handle = GetNativeWindowPointer(_window);
ASSERT(_handle != nullptr); ASSERT(_handle != nullptr);
SDL_SyncWindow(_window);
#if PLATFORM_LINUX #if PLATFORM_LINUX
if (SDLPlatform::UsesWayland()) if (SDLPlatform::UsesWayland())
{ {
@@ -239,7 +242,16 @@ 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);
LOG(Info, "new window at {}, expected: {}, {}", _cachedClientRectangle.GetTopLeft(), x, y); Int2 newpos = GetPosition();
LOG(Info, "new window at {}, expected: {}", newpos, oldpos);
ASSERT(newpos == oldpos);
oldpos = newpos;
SetPosition(newpos);
newpos = GetPosition();
LOG(Info, "new window sanity set at {}", newpos);
ASSERT(newpos == oldpos);
SDL_SetWindowHitTest(_window, &OnWindowHitTest, this); SDL_SetWindowHitTest(_window, &OnWindowHitTest, this);
InitSwapChain(); InitSwapChain();
@@ -857,16 +869,16 @@ Int2 GetSDLWindowPosition(const SDLWindow* window)
{ {
Int2 parentPosition = GetSDLWindowPosition(window->GetSettings().Parent); Int2 parentPosition = GetSDLWindowPosition(window->GetSettings().Parent);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y); //SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
position -= parentPosition; position += parentPosition;
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position -= Int2(monitorBounds.GetTopLeft()); //position += Int2(monitorBounds.GetTopLeft());
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); //auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position += Int2(monitorBounds.GetTopLeft()); //position += Int2(monitorBounds.GetTopLeft());
} }
else else
{ {
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); //auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
position -= Int2(monitorBounds.GetTopLeft()); //position -= Int2(monitorBounds.GetTopLeft());
} }
} }
#endif #endif
@@ -896,12 +908,12 @@ void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition,
SDLWindow* parent = window->GetSettings().Parent; SDLWindow* parent = window->GetSettings().Parent;
while (parent != nullptr) while (parent != nullptr)
{ {
if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup) /*if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)
{ {
Int2 parentPosition = GetSDLWindowPosition(parent); Int2 parentPosition = GetSDLWindowPosition(parent);
relativePosition += parentPosition; relativePosition += parentPosition;
break; break;
} }*/
//if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)) //if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup))
// break; // break;
parent = parent->GetSettings().Parent; parent = parent->GetSettings().Parent;
@@ -990,7 +1002,7 @@ void SetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition)
{ {
Int2 parentPosition = GetSDLWindowPosition(parent); Int2 parentPosition = GetSDLWindowPosition(parent);
relativePosition -= parentPosition; relativePosition -= parentPosition;
//break; break;
} }
//if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)) //if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup))
// break; // break;
@@ -1059,18 +1071,24 @@ void SDLWindow::SetPosition(const Float2& position)
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;
SetRelativeWindowPosition(this, relativePosition); SetRelativeWindowPosition(this, relativePosition);
if (SDLPlatform::UsesX11())
{
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
relativePosition += Int2(monitorBounds.GetTopLeft());
}
SDL_SetWindowPosition(_window, relativePosition.X, relativePosition.Y); SDL_SetWindowPosition(_window, relativePosition.X, relativePosition.Y);
SDL_SyncWindow(_window); SDL_SyncWindow(_window);
Int2 newPos; Int2 newPos;
SDL_GetWindowPosition(_window, &newPos.X, &newPos.Y); SDL_GetWindowPosition(_window, &newPos.X, &newPos.Y);
if (!(newPos.X == relativePosition.X && newPos.Y == relativePosition.Y)) //if (!(newPos.X == relativePosition.X && newPos.Y == relativePosition.Y))
ASSERT(false); // ASSERT(false);
newPos = GetPosition(); newPos = GetPosition();
if (!(newPos.X == relativePosition.X && newPos.Y == relativePosition.Y)) //if (!(newPos.X == position.X && newPos.Y == position.Y))
ASSERT(false); // ASSERT(false);
} }
void SDLWindow::SetClientPosition(const Float2& position) void SDLWindow::SetClientPosition(const Float2& position)

View File

@@ -79,6 +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);
var bef = locationSS; var bef = locationSS;
// Create window // Create window
@@ -230,6 +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);
if (_window) if (_window)
_window.Position = mousePos; _window.Position = mousePos;