forked from Mirrors/openclonk
fixed wrong offset in scripted GUIs when upper-board is active
parent
36544bd56c
commit
f05345375c
|
@ -995,6 +995,9 @@ void C4ViewportList::RecalculateViewports()
|
||||||
BackgroundAreas.ClipByRect(rcOut);
|
BackgroundAreas.ClipByRect(rcOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// and finally recalculate script menus
|
||||||
|
if (::Game.ScriptGuiRoot)
|
||||||
|
::Game.ScriptGuiRoot->RequestLayoutUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t C4ViewportList::GetViewportCount()
|
int32_t C4ViewportList::GetViewportCount()
|
||||||
|
|
|
@ -1515,16 +1515,29 @@ bool C4ScriptGuiWindow::DrawChildren(C4TargetFacet &cgo, int32_t player, int32_t
|
||||||
|
|
||||||
void C4ScriptGuiWindow::RequestLayoutUpdate()
|
void C4ScriptGuiWindow::RequestLayoutUpdate()
|
||||||
{
|
{
|
||||||
|
// directly requested on the root window?
|
||||||
|
// That usually comes from another part of the engine (f.e. C4Viewport::RecalculateViewports) or from a multiple-window child
|
||||||
|
if (!GetParent())
|
||||||
|
{
|
||||||
|
mainWindowNeedsLayoutUpdate = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// are we a direct child of the root?
|
||||||
if (isMainWindow)
|
if (isMainWindow)
|
||||||
{
|
{
|
||||||
const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
|
const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
|
||||||
|
|
||||||
if (!(style & C4ScriptGuiWindowStyleFlag::Multiple)) // are we a simple centered window?
|
if (!(style & C4ScriptGuiWindowStyleFlag::Multiple)) // are we a simple centered window?
|
||||||
|
{
|
||||||
mainWindowNeedsLayoutUpdate = true;
|
mainWindowNeedsLayoutUpdate = true;
|
||||||
else // we are one of the multiple windows.. the root better do a full refresh
|
return;
|
||||||
static_cast<C4ScriptGuiWindow*>(GetParent())->mainWindowNeedsLayoutUpdate = true;
|
|
||||||
}
|
}
|
||||||
else static_cast<C4ScriptGuiWindow*>(GetParent())->RequestLayoutUpdate();
|
else // we are one of the multiple windows.. the root better do a full refresh
|
||||||
|
;
|
||||||
|
}
|
||||||
|
// propagate to parent window
|
||||||
|
static_cast<C4ScriptGuiWindow*>(GetParent())->RequestLayoutUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool C4ScriptGuiWindow::UpdateChildLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight)
|
bool C4ScriptGuiWindow::UpdateChildLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight)
|
||||||
|
@ -1542,8 +1555,8 @@ bool C4ScriptGuiWindow::UpdateLayout(C4TargetFacet &cgo)
|
||||||
assert(IsRoot()); // we are root
|
assert(IsRoot()); // we are root
|
||||||
|
|
||||||
// assume I am the root and use the a special rectangle in the viewport for drawing
|
// assume I am the root and use the a special rectangle in the viewport for drawing
|
||||||
const float fullWidth = cgo.Wdt * cgo.Zoom;
|
const float fullWidth = cgo.Wdt * cgo.Zoom - cgo.X;
|
||||||
const float fullHeight = cgo.Hgt * cgo.Zoom;
|
const float fullHeight = cgo.Hgt * cgo.Zoom - cgo.Y;
|
||||||
|
|
||||||
// golden ratio defined default size!
|
// golden ratio defined default size!
|
||||||
const float &targetWidthEm = C4ScriptGuiWindow::standardWidth;
|
const float &targetWidthEm = C4ScriptGuiWindow::standardWidth;
|
||||||
|
@ -1702,6 +1715,11 @@ bool C4ScriptGuiWindow::DrawAll(C4TargetFacet &cgo, int32_t player)
|
||||||
{
|
{
|
||||||
assert(IsRoot()); // we are root
|
assert(IsRoot()); // we are root
|
||||||
if (!IsVisible()) return false;
|
if (!IsVisible()) return false;
|
||||||
|
// if the viewport shows an upper-board, apply an offset to everything
|
||||||
|
const int oldTargetX = cgo.TargetX;
|
||||||
|
const int oldTargetY = cgo.TargetY;
|
||||||
|
cgo.TargetX += cgo.X;
|
||||||
|
cgo.TargetY += cgo.Y;
|
||||||
// this will check whether the viewport resized and we need an update
|
// this will check whether the viewport resized and we need an update
|
||||||
UpdateLayout(cgo);
|
UpdateLayout(cgo);
|
||||||
// step one: draw all multiple-tagged windows
|
// step one: draw all multiple-tagged windows
|
||||||
|
@ -1709,6 +1727,9 @@ bool C4ScriptGuiWindow::DrawAll(C4TargetFacet &cgo, int32_t player)
|
||||||
// TODO: adjust rectangle for main menu if multiple windows exist
|
// TODO: adjust rectangle for main menu if multiple windows exist
|
||||||
// step two: draw one "main" menu
|
// step two: draw one "main" menu
|
||||||
DrawChildren(cgo, player, 0);
|
DrawChildren(cgo, player, 0);
|
||||||
|
// ..and restore the offset
|
||||||
|
cgo.TargetX = oldTargetX;
|
||||||
|
cgo.TargetY = oldTargetY;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1734,16 +1755,8 @@ bool C4ScriptGuiWindow::Draw(C4TargetFacet &cgo, int32_t player, C4Rect *current
|
||||||
|
|
||||||
const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
|
const int32_t &style = props[C4ScriptGuiWindowPropertyName::style].GetInt();
|
||||||
|
|
||||||
float childOffsetY = 0.0f; // for scrolling
|
const int32_t outDrawX = cgo.X + cgo.TargetX + rcBounds.x;
|
||||||
|
const int32_t outDrawY = cgo.Y + cgo.TargetY + rcBounds.y;
|
||||||
// check whether we are scrolling
|
|
||||||
//float childHgt = lastDrawPosition.bottomMostChild - lastDrawPosition.topMostChild;
|
|
||||||
|
|
||||||
//if (scrollBar)
|
|
||||||
// childOffsetY = -1.0f * (scrollBar->offset * (childHgt - rcBounds.Hgt));
|
|
||||||
|
|
||||||
const int32_t outDrawX = cgo.TargetX + rcBounds.x;
|
|
||||||
const int32_t outDrawY = cgo.TargetY + rcBounds.y;
|
|
||||||
const int32_t outDrawWdt = rcBounds.Wdt;
|
const int32_t outDrawWdt = rcBounds.Wdt;
|
||||||
const int32_t outDrawHgt = rcBounds.Hgt;
|
const int32_t outDrawHgt = rcBounds.Hgt;
|
||||||
const int32_t outDrawRight = outDrawX + rcBounds.Wdt;
|
const int32_t outDrawRight = outDrawX + rcBounds.Wdt;
|
||||||
|
|
|
@ -199,7 +199,6 @@ public:
|
||||||
// whether this menu is the root of all script-created menus (aka of the isMainWindow windows)
|
// whether this menu is the root of all script-created menus (aka of the isMainWindow windows)
|
||||||
bool IsRoot();
|
bool IsRoot();
|
||||||
bool mainWindowNeedsLayoutUpdate;
|
bool mainWindowNeedsLayoutUpdate;
|
||||||
void RequestLayoutUpdate();
|
|
||||||
|
|
||||||
bool wasRemoved; // to notify the window that it should not inform its parent on Close() a second time
|
bool wasRemoved; // to notify the window that it should not inform its parent on Close() a second time
|
||||||
bool closeActionWasExecuted; // to prevent a window from calling the close-callback twice even if f.e. closed in the close-callback..
|
bool closeActionWasExecuted; // to prevent a window from calling the close-callback twice even if f.e. closed in the close-callback..
|
||||||
|
@ -286,6 +285,8 @@ public:
|
||||||
// calculate the width/height based on a certain property (f.e. leftMargin and relLeftMargin) and the parent's width/height
|
// calculate the width/height based on a certain property (f.e. leftMargin and relLeftMargin) and the parent's width/height
|
||||||
float CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName absoluteProperty, C4ScriptGuiWindowPropertyName relativeProperty);
|
float CalculateRelativeSize(float parentWidthOrHeight, C4ScriptGuiWindowPropertyName absoluteProperty, C4ScriptGuiWindowPropertyName relativeProperty);
|
||||||
|
|
||||||
|
// schedules a layout update for the next drawing step
|
||||||
|
void RequestLayoutUpdate();
|
||||||
// this updates the window's layout and also propagates to all children
|
// this updates the window's layout and also propagates to all children
|
||||||
bool UpdateLayout(C4TargetFacet &cgo);
|
bool UpdateLayout(C4TargetFacet &cgo);
|
||||||
bool UpdateLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight);
|
bool UpdateLayout(C4TargetFacet &cgo, float parentWidth, float parentHeight);
|
||||||
|
|
Loading…
Reference in New Issue