From 30506c7a354522a23a4e5f3ec5aa9101531b8cd5 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Fri, 22 Oct 2021 20:49:34 +0200 Subject: [PATCH] Use ScreenCoordsXY and ScreenSize structs for main toolbar --- src/openrct2-ui/windows/TileInspector.cpp | 22 ++++---- src/openrct2/world/Location.hpp | 61 ++++++++++++++--------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index a11b08a9f0..a1f14ed52c 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -180,8 +180,10 @@ constexpr int32_t MIN_WH = 130; constexpr int32_t MAX_WH = 800; // Button space for top buttons -constexpr int32_t BX = WW - 27; // Button's left side -constexpr int32_t BY = 17; // Button's Top +constexpr auto ToolbarButtonAnchor = ScreenCoordsXY{ WW - 27, 17 }; +constexpr auto ToolbarButtonSize = ScreenSize{ 24, 24 }; +constexpr auto ToolbarButtonHalfSize = ScreenSize{ 24, 12 }; +constexpr auto ToolbarButtonOffsetX = ScreenSize{ -24, 0 }; // Column offsets for the table headers constexpr int32_t COL_X_TYPE = 3; // Type @@ -221,14 +223,14 @@ constexpr int32_t BUTTONH = 17; MakeSpinnerWidgets({20, 23}, {51, 12}, WindowWidgetType::Spinner, WindowColour::Secondary), /* Spinner X (3 widgets) */ \ MakeSpinnerWidgets({90, 23}, {51, 12}, WindowWidgetType::Spinner, WindowColour::Secondary), /* Spinner Y (3 widgets) */ \ /* Top buttons */ \ - MakeWidget({BX, BY}, {24, 24}, WindowWidgetType::FlatBtn , WindowColour::Secondary, SPR_MAP, STR_INSERT_CORRUPT_TIP), /* Insert corrupt button */ \ - MakeWidget({BX - 24, BY}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_DEMOLISH, STR_REMOVE_SELECTED_ELEMENT_TIP ), /* Remove button */ \ - MakeWidget({BX - 48, BY}, {24, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_UP, STR_MOVE_SELECTED_ELEMENT_UP_TIP), /* Move up */ \ - MakeWidget({BX - 48, BY + 12}, {24, 12}, WindowWidgetType::Button, WindowColour::Secondary, STR_DOWN, STR_MOVE_SELECTED_ELEMENT_DOWN_TIP), /* Move down */ \ - MakeWidget({BX - 72, BY}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_ROTATE_ARROW, STR_ROTATE_SELECTED_ELEMENT_TIP), /* Rotate button */ \ - MakeWidget({BX - 96, BY}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_SORT, STR_TILE_INSPECTOR_SORT_TIP), /* Sort button */ \ - MakeWidget({BX - 120, BY}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_PASTE, STR_TILE_INSPECTOR_PASTE_TIP), /* Paste button */ \ - MakeWidget({BX - 144, BY}, {24, 24}, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_COPY, STR_TILE_INSPECTOR_COPY_TIP), /* Copy button */ \ + MakeWidget(ToolbarButtonAnchor, ToolbarButtonSize, WindowWidgetType::FlatBtn , WindowColour::Secondary, SPR_MAP, STR_INSERT_CORRUPT_TIP), /* Insert corrupt button */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 1, ToolbarButtonSize, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_DEMOLISH, STR_REMOVE_SELECTED_ELEMENT_TIP ), /* Remove button */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 2, ToolbarButtonHalfSize, WindowWidgetType::Button, WindowColour::Secondary, STR_UP, STR_MOVE_SELECTED_ELEMENT_UP_TIP), /* Move up */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 2 + ScreenSize{0, 12}, ToolbarButtonHalfSize, WindowWidgetType::Button, WindowColour::Secondary, STR_DOWN, STR_MOVE_SELECTED_ELEMENT_DOWN_TIP), /* Move down */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 3, ToolbarButtonSize, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_ROTATE_ARROW, STR_ROTATE_SELECTED_ELEMENT_TIP), /* Rotate button */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 4, ToolbarButtonSize, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_SORT, STR_TILE_INSPECTOR_SORT_TIP), /* Sort button */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 5, ToolbarButtonSize, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_PASTE, STR_TILE_INSPECTOR_PASTE_TIP), /* Paste button */ \ + MakeWidget(ToolbarButtonAnchor + ToolbarButtonOffsetX * 6, ToolbarButtonSize, WindowWidgetType::FlatBtn, WindowColour::Secondary, SPR_G2_COPY, STR_TILE_INSPECTOR_COPY_TIP), /* Copy button */ \ /* Column headers */ \ MakeWidget({COL_X_TYPE, 42}, {312, 14}, WindowWidgetType::TableHeader, WindowColour::Secondary, STR_TILE_INSPECTOR_ELEMENT_TYPE), /* Type */ \ MakeWidget({COL_X_BH, 42}, {20, 14}, WindowWidgetType::TableHeader, WindowColour::Secondary, STR_TILE_INSPECTOR_BASE_HEIGHT_SHORT, STR_TILE_INSPECTOR_BASE_HEIGHT), /* Base height */ \ diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 62fb7025e1..95ea7ede20 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -25,6 +25,34 @@ constexpr const auto NumOrthogonalDirections = 4; constexpr int32_t COORDS_NULL = 0xFFFF8000; +struct ScreenSize +{ + int32_t width{}; + int32_t height{}; + + constexpr ScreenSize() = default; + constexpr ScreenSize(int32_t _width, int32_t _height) + : width(_width) + , height(_height) + { + } + + constexpr bool operator==(const ScreenSize& other) const + { + return width == other.width && height == other.height; + } + + constexpr bool operator!=(const ScreenSize& other) const + { + return !(*this == other); + } + + constexpr ScreenSize operator*(int32_t scalar) const + { + return ScreenSize{ width * scalar, height * scalar }; + } +}; + struct ScreenCoordsXY { int32_t x{}; @@ -61,6 +89,16 @@ struct ScreenCoordsXY return { x + rhs.x, y + rhs.y }; } + constexpr const ScreenCoordsXY operator+(const ScreenSize& rhs) const + { + return { x + rhs.width, y + rhs.height }; + } + + constexpr const ScreenCoordsXY operator-(const ScreenSize& rhs) const + { + return { x - rhs.width, y - rhs.height }; + } + constexpr bool operator==(const ScreenCoordsXY& other) const { return x == other.x && y == other.y; @@ -72,29 +110,6 @@ struct ScreenCoordsXY } }; -struct ScreenSize -{ - int32_t width{}; - int32_t height{}; - - constexpr ScreenSize() = default; - constexpr ScreenSize(int32_t _width, int32_t _height) - : width(_width) - , height(_height) - { - } - - constexpr bool operator==(const ScreenSize& other) const - { - return width == other.width && height == other.height; - } - - constexpr bool operator!=(const ScreenSize& other) const - { - return !(*this == other); - } -}; - /** * Tile coordinates use 1 x/y increment per tile and 1 z increment per step. * Regular ('big', 'sprite') coordinates use 32 x/y increments per tile and 8 z increments per step.