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

Add Some Items to the OpenRCT2::Ui namespace (#22423)

* Put widget in the Ui namespace

* Put theme in the Ui namespace

* Put objective in Ui namespace
This commit is contained in:
Duncan
2024-07-31 05:26:53 +01:00
committed by GitHub
parent bd0dd44c10
commit 681b54dc87
11 changed files with 2043 additions and 2018 deletions

View File

@@ -36,6 +36,7 @@
#include <optional>
using namespace OpenRCT2;
using namespace OpenRCT2::Ui;
using namespace OpenRCT2::Ui::Windows;
struct RCTMouseData

View File

@@ -14,8 +14,6 @@
#include <openrct2/drawing/ImageId.hpp>
#include <openrct2/util/Util.h>
using namespace OpenRCT2;
namespace OpenRCT2::Dropdown
{
struct Item;

View File

@@ -16,6 +16,8 @@
#include <openrct2/ride/RideData.h>
#include <openrct2/scenario/Scenario.h>
namespace OpenRCT2::Ui
{
const StringId kObjectiveNames[] = {
STR_OBJECTIVE_NONE,
STR_OBJECTIVE_GUESTS_BY,
@@ -66,3 +68,4 @@ void formatObjective(Formatter& ft, Objective objective)
ft.Add<money64>(objective.Currency);
}
}
} // namespace OpenRCT2::Ui

View File

@@ -15,6 +15,9 @@
class Formatter;
struct Objective;
namespace OpenRCT2::Ui
{
void formatObjective(Formatter& ft, Objective objective);
extern const StringId kObjectiveNames[12];
} // namespace OpenRCT2::Ui

View File

@@ -32,8 +32,8 @@
#include <stdexcept>
#include <vector>
using namespace OpenRCT2;
namespace OpenRCT2::Ui
{
static constexpr uint8_t kCurrentThemeVersion = 1;
struct WindowThemeDesc;
@@ -529,7 +529,7 @@ UITheme UITheme::CreatePredefined(const std::string& name, const UIThemeWindowEn
#pragma endregion
namespace OpenRCT2::ThemeManager
namespace ThemeManager
{
struct AvailableTheme
{
@@ -689,7 +689,7 @@ namespace OpenRCT2::ThemeManager
auto env = context->GetPlatformEnvironment();
return env->GetDirectoryPath(DIRBASE::USER, DIRID::THEME);
}
} // namespace OpenRCT2::ThemeManager
} // namespace ThemeManager
void ThemeManagerLoadAvailableThemes()
{
@@ -939,3 +939,4 @@ void ColourSchemeUpdateByClass(WindowBase* window, WindowClass classification)
// There doesn't seem to be any side-effects for all windows being transparent
window->flags |= WF_TRANSPARENT;
}
} // namespace OpenRCT2::Ui

View File

@@ -12,6 +12,8 @@
#include <openrct2/interface/Colour.h>
#include <openrct2/interface/Window.h>
namespace OpenRCT2::Ui
{
enum
{
UITHEME_FLAG_PREDEFINED = 1 << 0,
@@ -46,3 +48,4 @@ void ThemeDelete();
uint8_t ThemeDescGetNumColours(WindowClass wc);
StringId ThemeDescGetName(WindowClass wc);
} // namespace OpenRCT2::Ui

View File

@@ -25,6 +25,8 @@
using namespace OpenRCT2;
namespace OpenRCT2::Ui
{
static void WidgetFrameDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
static void WidgetResizeDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
static void WidgetButtonDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widgetIndex);
@@ -197,7 +199,8 @@ static void WidgetButtonDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widg
w.windowPos + ScreenCoordsXY{ widget.right, widget.bottom } };
// Check if the button is pressed down
uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET
: 0;
auto colour = w.colours[widget.colour];
@@ -318,7 +321,8 @@ static void WidgetTextButton(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex widg
auto colour = w.colours[widget.colour];
// Border
uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET : 0;
uint8_t press = WidgetIsPressed(w, widgetIndex) || WidgetIsActiveTool(w, widgetIndex) ? INSET_RECT_FLAG_BORDER_INSET
: 0;
GfxFillRectInset(dpi, rect, colour, press);
// Button caption
@@ -610,7 +614,8 @@ static void WidgetCloseboxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wi
colour.setFlag(ColourFlag::inset, true);
;
DrawTextEllipsised(dpi, topLeft, widget.width() - 2, widget.text, Formatter::Common(), { colour, TextAlignment::CENTRE });
DrawTextEllipsised(
dpi, topLeft, widget.width() - 2, widget.text, Formatter::Common(), { colour, TextAlignment::CENTRE });
}
/**
@@ -641,7 +646,8 @@ static void WidgetCheckboxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wi
if (WidgetIsPressed(w, widgetIndex))
{
DrawText(
dpi, { midLeft - ScreenCoordsXY{ 0, 5 } }, { colour.withFlag(ColourFlag::translucent, false) }, kCheckMarkString);
dpi, { midLeft - ScreenCoordsXY{ 0, 5 } }, { colour.withFlag(ColourFlag::translucent, false) },
kCheckMarkString);
}
// draw the text
@@ -732,9 +738,11 @@ static void WidgetHScrollbarDraw(
GfxFillRect(dpi, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, ColourMapA[colour.colour].lighter);
GfxFillRect(
dpi, { { l + kScrollBarWidth, t }, { r - kScrollBarWidth, b } }, 0x1000000 | ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + kScrollBarWidth, t + 2 }, { r - kScrollBarWidth, t + 2 } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(
dpi, { { l + kScrollBarWidth, t + 2 }, { r - kScrollBarWidth, t + 2 } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + kScrollBarWidth, t + 3 }, { r - kScrollBarWidth, t + 3 } }, ColourMapA[colour.colour].lighter);
GfxFillRect(dpi, { { l + kScrollBarWidth, t + 7 }, { r - kScrollBarWidth, t + 7 } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(
dpi, { { l + kScrollBarWidth, t + 7 }, { r - kScrollBarWidth, t + 7 } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + kScrollBarWidth, t + 8 }, { r - kScrollBarWidth, t + 8 } }, ColourMapA[colour.colour].lighter);
// Left button
@@ -772,9 +780,11 @@ static void WidgetVScrollbarDraw(
GfxFillRect(dpi, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, ColourMapA[colour.colour].lighter);
GfxFillRect(
dpi, { { l, t + kScrollBarWidth }, { r, b - kScrollBarWidth } }, 0x1000000 | ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + 2, t + kScrollBarWidth }, { l + 2, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(
dpi, { { l + 2, t + kScrollBarWidth }, { l + 2, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + 3, t + kScrollBarWidth }, { l + 3, b - kScrollBarWidth } }, ColourMapA[colour.colour].lighter);
GfxFillRect(dpi, { { l + 7, t + kScrollBarWidth }, { l + 7, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(
dpi, { { l + 7, t + kScrollBarWidth }, { l + 7, b - kScrollBarWidth } }, ColourMapA[colour.colour].mid_dark);
GfxFillRect(dpi, { { l + 8, t + kScrollBarWidth }, { l + 8, b - kScrollBarWidth } }, ColourMapA[colour.colour].lighter);
// Up button
@@ -982,7 +992,8 @@ void WidgetScrollGetPart(
*output_scroll_area = SCROLL_PART_HSCROLLBAR_THUMB;
}
}
else if ((scroll.flags & VSCROLLBAR_VISIBLE) && (screenCoords.x >= w.windowPos.x + widget->right - (kScrollBarWidth + 1)))
else if (
(scroll.flags & VSCROLLBAR_VISIBLE) && (screenCoords.x >= w.windowPos.x + widget->right - (kScrollBarWidth + 1)))
{
// vertical scrollbar
int32_t bottomOffset = 0;
@@ -1170,7 +1181,8 @@ static void WidgetTextBoxDraw(DrawPixelInfo& dpi, WindowBase& w, WidgetIndex wid
// Make a new 1 character wide string for measuring the width
// of the character that the cursor is under. (NOTE: this is broken for multi byte utf8 codepoints)
width = std::max(
GfxGetStringWidthNoFormatting(u8string{ (*textInput->Buffer)[textInput->SelectionStart] }, FontStyle::Medium) - 2,
GfxGetStringWidthNoFormatting(u8string{ (*textInput->Buffer)[textInput->SelectionStart] }, FontStyle::Medium)
- 2,
4);
}
@@ -1230,3 +1242,4 @@ void WidgetProgressBarSetNewPercentage(Widget& widget, uint8_t newPercentage)
widget.content &= ~0xFF;
widget.content |= newPercentage;
}
} // namespace OpenRCT2::Ui

View File

@@ -15,8 +15,8 @@
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Widget.h>
using namespace OpenRCT2;
namespace OpenRCT2::Ui
{
// clang-format off
#define WINDOW_SHIM_RAW(TITLE, WIDTH, HEIGHT, CLOSE_STR) \
{ WindowWidgetType::Frame, 0, 0, WIDTH - 1, 0, HEIGHT - 1, 0xFFFFFFFF, STR_NONE }, \
@@ -190,3 +190,4 @@ void WidgetSetPressed(WindowBase& w, WidgetIndex widgetIndex, bool value);
void WidgetSetCheckboxValue(WindowBase& w, WidgetIndex widgetIndex, bool value);
void WidgetProgressBarSetNewPercentage(Widget& widget, uint8_t newPercentage);
} // namespace OpenRCT2::Ui

View File

@@ -30,6 +30,7 @@
#include <openrct2/world/Location.hpp>
using namespace OpenRCT2;
using namespace OpenRCT2::Ui;
// The amount of pixels to scroll per wheel click
constexpr int32_t WindowScrollPixels = 17;

View File

@@ -300,7 +300,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return WidgetIsDisabled(*w, _widgetIndex);
return Ui::WidgetIsDisabled(*w, _widgetIndex);
}
return false;
}
@@ -309,19 +309,19 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
WidgetSetDisabled(*w, _widgetIndex, value);
Ui::WidgetSetDisabled(*w, _widgetIndex, value);
auto widget = GetWidget();
if (widget != nullptr)
{
if (widget->type == WindowWidgetType::DropdownMenu)
{
WidgetSetDisabled(*w, _widgetIndex + 1, value);
Ui::WidgetSetDisabled(*w, _widgetIndex + 1, value);
}
else if (widget->type == WindowWidgetType::Spinner)
{
WidgetSetDisabled(*w, _widgetIndex + 1, value);
WidgetSetDisabled(*w, _widgetIndex + 2, value);
Ui::WidgetSetDisabled(*w, _widgetIndex + 1, value);
Ui::WidgetSetDisabled(*w, _widgetIndex + 2, value);
}
}
Invalidate(widget);
@@ -333,7 +333,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return WidgetIsVisible(*w, _widgetIndex);
return Ui::WidgetIsVisible(*w, _widgetIndex);
}
return false;
}
@@ -342,19 +342,19 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
WidgetSetVisible(*w, _widgetIndex, value);
Ui::WidgetSetVisible(*w, _widgetIndex, value);
auto widget = GetWidget();
if (widget != nullptr)
{
if (widget->type == WindowWidgetType::DropdownMenu)
{
WidgetSetVisible(*w, _widgetIndex + 1, value);
Ui::WidgetSetVisible(*w, _widgetIndex + 1, value);
}
else if (widget->type == WindowWidgetType::Spinner)
{
WidgetSetVisible(*w, _widgetIndex + 1, value);
WidgetSetVisible(*w, _widgetIndex + 2, value);
Ui::WidgetSetVisible(*w, _widgetIndex + 1, value);
Ui::WidgetSetVisible(*w, _widgetIndex + 2, value);
}
}
Invalidate(widget);
@@ -486,7 +486,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return WidgetIsPressed(*w, _widgetIndex);
return Ui::WidgetIsPressed(*w, _widgetIndex);
}
return false;
}
@@ -495,7 +495,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
WidgetSetCheckboxValue(*w, _widgetIndex, value ? 1 : 0);
Ui::WidgetSetCheckboxValue(*w, _widgetIndex, value ? 1 : 0);
Invalidate();
}
}
@@ -548,7 +548,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
return WidgetIsPressed(*w, _widgetIndex);
return Ui::WidgetIsPressed(*w, _widgetIndex);
}
return false;
}
@@ -557,7 +557,7 @@ namespace OpenRCT2::Scripting
auto w = GetWindow();
if (w != nullptr)
{
WidgetSetCheckboxValue(*w, _widgetIndex, value ? 1 : 0);
Ui::WidgetSetCheckboxValue(*w, _widgetIndex, value ? 1 : 0);
Invalidate();
}
}

View File

@@ -536,6 +536,7 @@ static constexpr colour_t kColoursDropdownOrder[] = {
} // namespace OpenRCT2::Ui::Windows
using namespace OpenRCT2::Ui::Windows;
using namespace OpenRCT2;
bool Dropdown::IsChecked(int32_t index)
{