1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-21 23:03:04 +01:00

Move more Ui functions to Ui library (#22444)

* Move various methods into the ui library

* Move various zoom functions to ui
This commit is contained in:
Duncan
2024-08-01 20:09:06 +01:00
committed by GitHub
parent b1e14c676d
commit 144fa13a84
7 changed files with 189 additions and 185 deletions

View File

@@ -17,6 +17,7 @@
#include <algorithm>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Context.h>
#include <openrct2/GameState.h>
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/audio.h>
@@ -318,9 +319,9 @@ static void WindowViewportWheelInput(WindowBase& w, int32_t wheel)
return;
if (wheel < 0)
WindowZoomIn(w, true);
Windows::WindowZoomIn(w, true);
else if (wheel > 0)
WindowZoomOut(w, true);
Windows::WindowZoomOut(w, true);
}
static bool isSpinnerGroup(WindowBase& w, WidgetIndex index, WindowWidgetType buttonType)
@@ -481,48 +482,6 @@ void ApplyScreenSaverLockSetting()
Config::Get().general.DisableScreensaver ? SDL_DisableScreenSaver() : SDL_EnableScreenSaver();
}
/**
*
* rct2: 0x006EB15C
*/
void WindowDrawWidgets(WindowBase& w, DrawPixelInfo& dpi)
{
Widget* widget;
WidgetIndex widgetIndex;
if ((w.flags & WF_TRANSPARENT) && !(w.flags & WF_NO_BACKGROUND))
GfxFilterRect(
dpi, { w.windowPos, w.windowPos + ScreenCoordsXY{ w.width - 1, w.height - 1 } }, FilterPaletteID::Palette51);
// todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0;
for (widget = w.widgets; widget->type != WindowWidgetType::Last; widget++)
{
if (widget->IsVisible())
{
// Check if widget is outside the draw region
if (w.windowPos.x + widget->left < dpi.x + dpi.width && w.windowPos.x + widget->right >= dpi.x)
{
if (w.windowPos.y + widget->top < dpi.y + dpi.height && w.windowPos.y + widget->bottom >= dpi.y)
{
w.OnDrawWidget(widgetIndex, dpi);
}
}
}
widgetIndex++;
}
// todo: something missing here too? Between 006EC32B and 006EC369
if (w.flags & WF_WHITE_BORDER_MASK)
{
GfxFillRectInset(
dpi, { w.windowPos, w.windowPos + ScreenCoordsXY{ w.width - 1, w.height - 1 } }, { COLOUR_WHITE },
INSET_RECT_FLAG_FILL_NONE);
}
}
/**
*
* rct2: 0x006EA776
@@ -543,9 +502,21 @@ static void WindowInvalidatePressedImageButton(const WindowBase& w)
}
}
void Window::ScrollToViewport()
{
if (viewport == nullptr || !focus.has_value())
return;
CoordsXYZ newCoords = focus.value().GetPos();
auto mainWindow = WindowGetMain();
if (mainWindow != nullptr)
WindowScrollToLocation(*mainWindow, newCoords);
}
void Window::OnDraw(DrawPixelInfo& dpi)
{
WindowDrawWidgets(*this, dpi);
Windows::WindowDrawWidgets(*this, dpi);
}
void Window::OnDrawWidget(WidgetIndex widgetIndex, DrawPixelInfo& dpi)
@@ -605,7 +576,7 @@ void Window::SetCheckboxValue(WidgetIndex widgetIndex, bool value)
void Window::DrawWidgets(DrawPixelInfo& dpi)
{
WindowDrawWidgets(*this, dpi);
Windows::WindowDrawWidgets(*this, dpi);
}
void Window::Close()
@@ -658,6 +629,69 @@ void Window::TextInputOpen(
this, callWidget, title, description, descriptionArgs, existingText, existingArgs, maxLength);
}
void Window::ResizeFrame()
{
// Frame
widgets[0].right = width - 1;
widgets[0].bottom = height - 1;
// Title
widgets[1].right = width - 2;
// Close button
if (Config::Get().interface.WindowButtonsOnTheLeft)
{
widgets[2].left = 2;
widgets[2].right = 2 + kCloseButtonWidth;
}
else
{
widgets[2].left = width - 3 - kCloseButtonWidth;
widgets[2].right = width - 3;
}
}
void Window::ResizeFrameWithPage()
{
ResizeFrame();
// Page background
widgets[3].right = width - 1;
widgets[3].bottom = height - 1;
}
void Window::ResizeSpinner(WidgetIndex widgetIndex, const ScreenCoordsXY& origin, const ScreenSize& size)
{
auto right = origin.x + size.width - 1;
auto bottom = origin.y + size.height - 1;
widgets[widgetIndex].left = origin.x;
widgets[widgetIndex].top = origin.y;
widgets[widgetIndex].right = right;
widgets[widgetIndex].bottom = bottom;
widgets[widgetIndex + 1].left = right - size.height; // subtract height to maintain aspect ratio
widgets[widgetIndex + 1].top = origin.y + 1;
widgets[widgetIndex + 1].right = right - 1;
widgets[widgetIndex + 1].bottom = bottom - 1;
widgets[widgetIndex + 2].left = right - size.height * 2;
widgets[widgetIndex + 2].top = origin.y + 1;
widgets[widgetIndex + 2].right = right - size.height - 1;
widgets[widgetIndex + 2].bottom = bottom - 1;
}
void Window::ResizeDropdown(WidgetIndex widgetIndex, const ScreenCoordsXY& origin, const ScreenSize& size)
{
auto right = origin.x + size.width - 1;
auto bottom = origin.y + size.height - 1;
widgets[widgetIndex].left = origin.x;
widgets[widgetIndex].top = origin.y;
widgets[widgetIndex].right = right;
widgets[widgetIndex].bottom = bottom;
widgets[widgetIndex + 1].left = right - size.height + 1; // subtract height to maintain aspect ratio
widgets[widgetIndex + 1].top = origin.y + 1;
widgets[widgetIndex + 1].right = right - 1;
widgets[widgetIndex + 1].bottom = bottom - 1;
}
void WindowAlignTabs(WindowBase* w, WidgetIndex start_tab_id, WidgetIndex end_tab_id)
{
int32_t i, x = w->widgets[start_tab_id].left;
@@ -1255,4 +1289,98 @@ namespace OpenRCT2::Ui::Windows
w->OnResize();
});
}
/**
*
* rct2: 0x00685BE1
*
* @param dpi (edi)
* @param w (esi)
*/
void WindowDrawViewport(DrawPixelInfo& dpi, WindowBase& w)
{
ViewportRender(dpi, w.viewport, { { dpi.x, dpi.y }, { dpi.x + dpi.width, dpi.y + dpi.height } });
}
/**
*
* rct2: 0x006EB15C
*/
void WindowDrawWidgets(WindowBase& w, DrawPixelInfo& dpi)
{
Widget* widget;
WidgetIndex widgetIndex;
if ((w.flags & WF_TRANSPARENT) && !(w.flags & WF_NO_BACKGROUND))
GfxFilterRect(
dpi, { w.windowPos, w.windowPos + ScreenCoordsXY{ w.width - 1, w.height - 1 } }, FilterPaletteID::Palette51);
// todo: some code missing here? Between 006EB18C and 006EB260
widgetIndex = 0;
for (widget = w.widgets; widget->type != WindowWidgetType::Last; widget++)
{
if (widget->IsVisible())
{
// Check if widget is outside the draw region
if (w.windowPos.x + widget->left < dpi.x + dpi.width && w.windowPos.x + widget->right >= dpi.x)
{
if (w.windowPos.y + widget->top < dpi.y + dpi.height && w.windowPos.y + widget->bottom >= dpi.y)
{
w.OnDrawWidget(widgetIndex, dpi);
}
}
}
widgetIndex++;
}
// todo: something missing here too? Between 006EC32B and 006EC369
if (w.flags & WF_WHITE_BORDER_MASK)
{
GfxFillRectInset(
dpi, { w.windowPos, w.windowPos + ScreenCoordsXY{ w.width - 1, w.height - 1 } }, { COLOUR_WHITE },
INSET_RECT_FLAG_FILL_NONE);
}
}
/**
*
* rct2: 0x006887A6
*/
void WindowZoomIn(WindowBase& w, bool atCursor)
{
WindowZoomSet(w, w.viewport->zoom - 1, atCursor);
}
/**
*
* rct2: 0x006887E0
*/
void WindowZoomOut(WindowBase& w, bool atCursor)
{
WindowZoomSet(w, w.viewport->zoom + 1, atCursor);
}
void MainWindowZoom(bool zoomIn, bool atCursor)
{
auto* mainWindow = WindowGetMain();
if (mainWindow == nullptr)
return;
if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)
return;
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && GetGameState().EditorStep != EditorStep::LandscapeEditor)
return;
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
return;
if (zoomIn)
WindowZoomIn(*mainWindow, atCursor);
else
WindowZoomOut(*mainWindow, atCursor);
}
} // namespace OpenRCT2::Ui::Windows