From d1b1e4264328d126bc2d4aa2aa81435a8e974052 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 24 Feb 2024 00:23:28 +0100 Subject: [PATCH] Refactor defines in LandTool.h --- src/openrct2-ui/interface/LandTool.cpp | 2 +- src/openrct2-ui/interface/LandTool.h | 6 +++--- src/openrct2-ui/windows/ClearScenery.cpp | 12 ++++++------ src/openrct2-ui/windows/Land.cpp | 14 +++++++------- src/openrct2-ui/windows/LandRights.cpp | 16 ++++++++-------- src/openrct2-ui/windows/Map.cpp | 14 +++++++------- src/openrct2-ui/windows/PatrolArea.cpp | 14 +++++++------- src/openrct2-ui/windows/SceneryScatter.cpp | 12 ++++++------ src/openrct2-ui/windows/Water.cpp | 14 +++++++------- 9 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/openrct2-ui/interface/LandTool.cpp b/src/openrct2-ui/interface/LandTool.cpp index f1316a23a0..35a224adf9 100644 --- a/src/openrct2-ui/interface/LandTool.cpp +++ b/src/openrct2-ui/interface/LandTool.cpp @@ -47,7 +47,7 @@ money64 gWaterToolLowerCost; uint32_t LandTool::SizeToSpriteIndex(uint16_t size) { - if (size <= MAX_TOOL_SIZE_WITH_SPRITE) + if (size <= kLandToolMaximumSizeWithSprite) { return toolSizeSpriteIndices[size]; } diff --git a/src/openrct2-ui/interface/LandTool.h b/src/openrct2-ui/interface/LandTool.h index ad6f317057..db1e3145d7 100644 --- a/src/openrct2-ui/interface/LandTool.h +++ b/src/openrct2-ui/interface/LandTool.h @@ -13,10 +13,10 @@ #include #include -#define MINIMUM_TOOL_SIZE 1 -#define MAXIMUM_TOOL_SIZE 64 +constexpr uint16_t kLandToolMinimumSize = 1; +constexpr uint16_t kLandToolMaximumSize = 64; // The highest tool size to have a sprite. Bigger tool sizes simply display a number. -#define MAX_TOOL_SIZE_WITH_SPRITE 7 +constexpr uint16_t kLandToolMaximumSizeWithSprite = 7; extern uint16_t gLandToolSize; extern money64 gLandToolRaiseCost; diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index 06f8574f5e..bd06d6c4af 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -97,8 +97,8 @@ public: case WIDX_PREVIEW: { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); TextInputOpen(WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); break; } @@ -123,14 +123,14 @@ public: { case WIDX_DECREMENT: // Decrement land tool size, if it stays within the limit - gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1); + gLandToolSize = std::max(kLandToolMinimumSize, gLandToolSize - 1); // Invalidate the window Invalidate(); break; case WIDX_INCREMENT: // Increment land tool size, if it stays within the limit - gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1); + gLandToolSize = std::min(kLandToolMaximumSize, gLandToolSize + 1); // Invalidate the window Invalidate(); @@ -146,7 +146,7 @@ public: try { int32_t size = std::stol(std::string(text)); - size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE); + size = std::clamp(size, kLandToolMinimumSize, kLandToolMaximumSize); gLandToolSize = size; Invalidate(); } @@ -181,7 +181,7 @@ public: // Draw number for tool sizes bigger than 7 ScreenCoordsXY screenCoords = { windowPos.x + window_clear_scenery_widgets[WIDX_PREVIEW].midX(), windowPos.y + window_clear_scenery_widgets[WIDX_PREVIEW].midY() }; - if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gLandToolSize > kLandToolMaximumSizeWithSprite) { auto ft = Formatter(); ft.Add(gLandToolSize); diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index b44886c11e..ec548ca77b 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -62,8 +62,8 @@ private: void InputSize() { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); } @@ -132,14 +132,14 @@ public: break; case WIDX_DECREMENT: // Decrement land tool size - gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1); + gLandToolSize = std::max(kLandToolMinimumSize, gLandToolSize - 1); // Invalidate the window Invalidate(); break; case WIDX_INCREMENT: // Increment land tool size - gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1); + gLandToolSize = std::min(kLandToolMaximumSize, gLandToolSize + 1); // Invalidate the window Invalidate(); @@ -202,8 +202,8 @@ public: int32_t size = strtol(textStr.c_str(), &end, 10); if (*end == '\0') { - size = std::max(MINIMUM_TOOL_SIZE, size); - size = std::min(MAXIMUM_TOOL_SIZE, size); + size = std::max(kLandToolMinimumSize, size); + size = std::min(kLandToolMaximumSize, size); gLandToolSize = size; Invalidate(); @@ -244,7 +244,7 @@ public: DrawDropdownButtons(dpi); // Draw number for tool sizes bigger than 7 - if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gLandToolSize > kLandToolMaximumSizeWithSprite) { auto ft = Formatter(); ft.Add(gLandToolSize); diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index 01a252bf6b..38523d4daa 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -131,14 +131,14 @@ public: { case WIDX_DECREMENT: // Decrement land rights tool size - gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1); + gLandToolSize = std::max(kLandToolMinimumSize, gLandToolSize - 1); // Invalidate the window Invalidate(); break; case WIDX_INCREMENT: // Decrement land rights tool size - gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1); + gLandToolSize = std::min(kLandToolMaximumSize, gLandToolSize + 1); // Invalidate the window Invalidate(); @@ -157,10 +157,10 @@ public: const auto res = String::Parse(text); if (res.has_value()) { - int32_t size; + uint16_t size; size = res.value(); - size = std::max(MINIMUM_TOOL_SIZE, size); - size = std::min(MAXIMUM_TOOL_SIZE, size); + size = std::max(kLandToolMinimumSize, size); + size = std::min(kLandToolMaximumSize, size); gLandToolSize = size; Invalidate(); } @@ -220,7 +220,7 @@ public: DrawWidgets(dpi); // Draw number for tool sizes bigger than 7 - if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gLandToolSize > kLandToolMaximumSizeWithSprite) { auto ft = Formatter(); ft.Add(gLandToolSize); @@ -393,8 +393,8 @@ private: void InputSize() { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); } diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index ea19e56c17..1b245162d8 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -205,7 +205,7 @@ public: break; _activeTool = 2; // Prevent mountain tool size. - _landRightsToolSize = std::max(MINIMUM_TOOL_SIZE, _landRightsToolSize); + _landRightsToolSize = std::max(kLandToolMinimumSize, _landRightsToolSize); ShowGridlines(); ShowLandRights(); ShowConstructionRights(); @@ -313,13 +313,13 @@ public: break; case WIDX_LAND_TOOL_SMALLER: // Decrement land rights tool size - _landRightsToolSize = std::max(MINIMUM_TOOL_SIZE, _landRightsToolSize - 1); + _landRightsToolSize = std::max(kLandToolMinimumSize, _landRightsToolSize - 1); Invalidate(); break; case WIDX_LAND_TOOL_LARGER: // Increment land rights tool size - _landRightsToolSize = std::min(MAXIMUM_TOOL_SIZE, _landRightsToolSize + 1); + _landRightsToolSize = std::min(kLandToolMaximumSize, _landRightsToolSize + 1); Invalidate(); break; @@ -616,7 +616,7 @@ public: int32_t size = strtol(textStr.c_str(), &end, 10); if (*end == '\0') { - size = std::clamp(size, MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE); + size = std::clamp(size, kLandToolMinimumSize, kLandToolMaximumSize); _landRightsToolSize = size; Invalidate(); } @@ -865,7 +865,7 @@ public: + ScreenCoordsXY{ window_map_widgets[WIDX_LAND_TOOL].midX(), window_map_widgets[WIDX_LAND_TOOL].midY() }; // Draw land tool size - if (WidgetIsActiveTool(*this, WIDX_SET_LAND_RIGHTS) && _landRightsToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (WidgetIsActiveTool(*this, WIDX_SET_LAND_RIGHTS) && _landRightsToolSize > kLandToolMaximumSizeWithSprite) { auto ft = Formatter(); ft.Add(_landRightsToolSize); @@ -1326,8 +1326,8 @@ private: void InputLandSize() { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); TextInputOpen(WIDX_LAND_TOOL, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); } diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index e9205b9091..75e70d9834 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -86,11 +86,11 @@ public: switch (widgetIndex) { case WIDX_DECREMENT: - gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1); + gLandToolSize = std::max(kLandToolMinimumSize, gLandToolSize - 1); Invalidate(); break; case WIDX_INCREMENT: - gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1); + gLandToolSize = std::min(kLandToolMaximumSize, gLandToolSize + 1); Invalidate(); break; } @@ -109,8 +109,8 @@ public: { int32_t size; size = res.value(); - size = std::max(MINIMUM_TOOL_SIZE, size); - size = std::min(MAXIMUM_TOOL_SIZE, size); + size = std::max(kLandToolMinimumSize, size); + size = std::min(kLandToolMaximumSize, size); gLandToolSize = size; Invalidate(); } @@ -136,7 +136,7 @@ public: DrawWidgets(dpi); // Draw number for tool sizes bigger than 7 - if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gLandToolSize > kLandToolMaximumSizeWithSprite) { auto screenCoords = ScreenCoordsXY{ windowPos.x + PatrolAreaWidgets[WIDX_PREVIEW].midX(), windowPos.y + PatrolAreaWidgets[WIDX_PREVIEW].midY() }; @@ -257,8 +257,8 @@ private: void InputSize() { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); } diff --git a/src/openrct2-ui/windows/SceneryScatter.cpp b/src/openrct2-ui/windows/SceneryScatter.cpp index 6583183351..ad8107368a 100644 --- a/src/openrct2-ui/windows/SceneryScatter.cpp +++ b/src/openrct2-ui/windows/SceneryScatter.cpp @@ -80,8 +80,8 @@ public: switch (widgetIndex) { case WIDX_PREVIEW: - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); maxLength = 3; break; } @@ -120,13 +120,13 @@ public: { case WIDX_DECREMENT: // Decrement land tool size, if it stays within the limit - gWindowSceneryScatterSize = std::max(MINIMUM_TOOL_SIZE, gWindowSceneryScatterSize - 1); + gWindowSceneryScatterSize = std::max(kLandToolMinimumSize, gWindowSceneryScatterSize - 1); Invalidate(); break; case WIDX_INCREMENT: // Increment land tool size, if it stays within the limit - gWindowSceneryScatterSize = std::min(MAXIMUM_TOOL_SIZE, gWindowSceneryScatterSize + 1); + gWindowSceneryScatterSize = std::min(kLandToolMaximumSize, gWindowSceneryScatterSize + 1); Invalidate(); break; } @@ -144,7 +144,7 @@ public: switch (widgetIndex) { case WIDX_PREVIEW: - gWindowSceneryScatterSize = std::clamp(res.value(), MINIMUM_TOOL_SIZE, MAXIMUM_TOOL_SIZE); + gWindowSceneryScatterSize = std::clamp(res.value(), kLandToolMinimumSize, kLandToolMaximumSize); break; } Invalidate(); @@ -181,7 +181,7 @@ public: WindowDrawWidgets(*this, dpi); // Draw area as a number for tool sizes bigger than 7 - if (gWindowSceneryScatterSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gWindowSceneryScatterSize > kLandToolMaximumSizeWithSprite) { const auto& preview = widgets[WIDX_PREVIEW]; const auto screenCoords = ScreenCoordsXY{ windowPos.x + preview.midX(), windowPos.y + preview.midY() }; diff --git a/src/openrct2-ui/windows/Water.cpp b/src/openrct2-ui/windows/Water.cpp index f7a651abd6..9eeab3ff87 100644 --- a/src/openrct2-ui/windows/Water.cpp +++ b/src/openrct2-ui/windows/Water.cpp @@ -86,14 +86,14 @@ public: { case WIDX_DECREMENT: // Decrement land tool size - gLandToolSize = std::max(MINIMUM_TOOL_SIZE, gLandToolSize - 1); + gLandToolSize = std::max(kLandToolMinimumSize, gLandToolSize - 1); // Invalidate the window Invalidate(); break; case WIDX_INCREMENT: // Increment land tool size - gLandToolSize = std::min(MAXIMUM_TOOL_SIZE, gLandToolSize + 1); + gLandToolSize = std::min(kLandToolMaximumSize, gLandToolSize + 1); // Invalidate the window Invalidate(); @@ -124,8 +124,8 @@ public: size = strtol(textStr.c_str(), &end, 10); if (*end == '\0') { - size = std::max(MINIMUM_TOOL_SIZE, size); - size = std::min(MAXIMUM_TOOL_SIZE, size); + size = std::max(kLandToolMinimumSize, size); + size = std::min(kLandToolMaximumSize, size); gLandToolSize = size; Invalidate(); @@ -148,7 +148,7 @@ public: DrawWidgets(dpi); // Draw number for tool sizes bigger than 7 - if (gLandToolSize > MAX_TOOL_SIZE_WITH_SPRITE) + if (gLandToolSize > kLandToolMaximumSizeWithSprite) { auto ft = Formatter(); ft.Add(gLandToolSize); @@ -186,8 +186,8 @@ private: void InputSize() { Formatter ft; - ft.Add(MINIMUM_TOOL_SIZE); - ft.Add(MAXIMUM_TOOL_SIZE); + ft.Add(kLandToolMinimumSize); + ft.Add(kLandToolMaximumSize); WindowTextInputOpen(this, WIDX_PREVIEW, STR_SELECTION_SIZE, STR_ENTER_SELECTION_SIZE, ft, STR_NONE, STR_NONE, 3); } };