From 54db35397c457534d5f584e0792182b39e7597e0 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 3 Aug 2024 20:07:15 +0200 Subject: [PATCH] Introduce CursorData.h; rename constants --- src/openrct2-ui/CursorData.cpp | 112 +++++++++++++------------- src/openrct2-ui/CursorData.h | 33 ++++++++ src/openrct2-ui/CursorRepository.cpp | 10 ++- src/openrct2-ui/CursorRepository.h | 7 +- src/openrct2-ui/libopenrct2ui.vcxproj | 1 + src/openrct2/interface/Cursors.h | 16 ---- 6 files changed, 100 insertions(+), 79 deletions(-) create mode 100644 src/openrct2-ui/CursorData.h diff --git a/src/openrct2-ui/CursorData.cpp b/src/openrct2-ui/CursorData.cpp index c480757e42..391c952608 100644 --- a/src/openrct2-ui/CursorData.cpp +++ b/src/openrct2-ui/CursorData.cpp @@ -7,19 +7,20 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "CursorRepository.h" +#include "CursorData.h" #include +#include namespace OpenRCT2::Ui { // clang-format off - static constexpr CursorData BlankCursorData = + static constexpr CursorData kBlankCursorData = { { 0, 0 }, { 0 }, { 0 } }; - static constexpr CursorData UpArrowCursorData = + static constexpr CursorData kUpArrowCursorData = { { 15, 0 }, { @@ -44,7 +45,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData UpDownArrowCursorData = + static constexpr CursorData kUpDownArrowCursorData = { { 17, 15 }, { @@ -69,7 +70,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData ZZZCursorData = + static constexpr CursorData kZzzCursorData = { { 0, 0 }, { @@ -94,7 +95,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData DiagonalArrowCursorData = + static constexpr CursorData kDiagonalArrowCursorData = { { 0, 0 }, { @@ -119,7 +120,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData PickerArrowCursorData = + static constexpr CursorData kPickerArrowCursorData = { { 15, 31 }, { @@ -144,7 +145,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData TreeDownCursorData = + static constexpr CursorData kTreeDownCursorData = { { 7, 31 }, { @@ -169,7 +170,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData FountainDownCursorData = + static constexpr CursorData kFountainDownCursorData = { { 7, 31 }, { @@ -194,7 +195,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData StatueDownCursorData = + static constexpr CursorData kStatueDownCursorData = { { 7, 31 }, { @@ -219,7 +220,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData BenchDownCursorData = + static constexpr CursorData kBenchDownCursorData = { { 7, 31 }, { @@ -244,7 +245,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData CrossHairCursorData = + static constexpr CursorData kCrossHairCursorData = { { 15, 15 }, { @@ -269,7 +270,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData BinDownCursorData = + static constexpr CursorData kBinDownCursorData = { { 7, 31 }, { @@ -294,7 +295,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData LampPostDownCursorData = + static constexpr CursorData kLampPostDownCursorData = { { 7, 31 }, { @@ -319,7 +320,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData FenceDownCursorData = + static constexpr CursorData kFenceDownCursorData = { { 7, 31 }, { @@ -344,7 +345,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData FlowerDownCursorData = + static constexpr CursorData kFlowerDownCursorData = { { 7, 31 }, { @@ -369,7 +370,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData FootpathDownCursorData = + static constexpr CursorData kFootpathDownCursorData = { { 7, 31 }, { @@ -394,7 +395,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData DigDownCursorData = + static constexpr CursorData kDigDownCursorData = { { 7, 31 }, { @@ -419,7 +420,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData WaterDownCursorData = + static constexpr CursorData kWaterDownCursorData = { { 7, 31 }, { @@ -444,7 +445,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData HouseDownCursorData = + static constexpr CursorData kHouseDownCursorData = { { 7, 31 }, { @@ -469,7 +470,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData VolcanoDownCursorData = + static constexpr CursorData kVolcanoDownCursorData = { { 7, 31 }, { @@ -494,7 +495,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData WalkDownCursorData = + static constexpr CursorData kWalkDownCursorData = { { 7, 31 }, { @@ -519,7 +520,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData PaintDownCursorData = + static constexpr CursorData kPaintDownCursorData = { { 8, 30 }, { @@ -544,7 +545,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData EntranceDownCursorData = + static constexpr CursorData kEntranceDownCursorData = { { 7, 31 }, { @@ -569,7 +570,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData HandOpenDownCursorData = + static constexpr CursorData kHandOpenDownCursorData = { { 14, 15 }, { @@ -594,7 +595,7 @@ namespace OpenRCT2::Ui } }; - static constexpr CursorData HandClosedDownCursorData = + static constexpr CursorData kHandClosedDownCursorData = { { 14, 15 }, { @@ -619,39 +620,38 @@ namespace OpenRCT2::Ui } }; - static constexpr const CursorData * RawCursorData[] = - { - nullptr, // CURSOR_ARROW - &BlankCursorData, // CURSOR_BLANK - &UpArrowCursorData, // CURSOR_UP_ARROW - &UpDownArrowCursorData, // CURSOR_UP_DOWN_ARROW - nullptr, // CURSOR_HAND_POINT - &ZZZCursorData, // CURSOR_ZZZ - &DiagonalArrowCursorData, // CURSOR_DIAGONAL_ARROWS - &PickerArrowCursorData, // CURSOR_PICKER - &TreeDownCursorData, // CURSOR_TREE_DOWN - &FountainDownCursorData, // CURSOR_FOUNTAIN_DOWN - &StatueDownCursorData, // CURSOR_STATUE_DOWN - &BenchDownCursorData, // CURSOR_BENCH_DOWN - &CrossHairCursorData, // CURSOR_CROSS_HAIR - &BinDownCursorData, // CURSOR_BIN_DOWN - &LampPostDownCursorData, // CURSOR_LAMPPOST_DOWN - &FenceDownCursorData, // CURSOR_FENCE_DOWN - &FlowerDownCursorData, // CURSOR_FLOWER_DOWN - &FootpathDownCursorData, // CURSOR_PATH_DOWN - &DigDownCursorData, // CURSOR_DIG_DOWN - &WaterDownCursorData, // CURSOR_WATER_DOWN - &HouseDownCursorData, // CURSOR_HOUSE_DOWN - &VolcanoDownCursorData, // CURSOR_VOLCANO_DOWN - &WalkDownCursorData, // CURSOR_WALK_DOWN - &PaintDownCursorData, // CURSOR_PAINT_DOWN - &EntranceDownCursorData, // CURSOR_ENTRANCE_DOWN - &HandOpenDownCursorData, // CURSOR_HAND_OPEN - &HandClosedDownCursorData, // CURSOR_HAND_CLOSED + static constexpr const CursorData* RawCursorData[] = { + nullptr, // CursorID::Arrow + &kBlankCursorData, // CursorID::Blank + &kUpArrowCursorData, // CursorID::UpArrow + &kUpDownArrowCursorData, // CursorID::UpDownArrow + nullptr, // CursorID::HandPoint + &kZzzCursorData, // CursorID::ZZZ + &kDiagonalArrowCursorData, // CursorID::DiagonalArrows + &kPickerArrowCursorData, // CursorID::Picker + &kTreeDownCursorData, // CursorID::TreeDown + &kFountainDownCursorData, // CursorID::FountainDown + &kStatueDownCursorData, // CursorID::StatueDown + &kBenchDownCursorData, // CursorID::BenchDown + &kCrossHairCursorData, // CursorID::CrossHair + &kBinDownCursorData, // CursorID::BinDown + &kLampPostDownCursorData, // CursorID::LamppostDown + &kFenceDownCursorData, // CursorID::FenceDown + &kFlowerDownCursorData, // CursorID::FlowerDown + &kFootpathDownCursorData, // CursorID::PathDown + &kDigDownCursorData, // CursorID::DigDown + &kWaterDownCursorData, // CursorID::WaterDown + &kHouseDownCursorData, // CursorID::HouseDown + &kVolcanoDownCursorData, // CursorID::VolcanoDown + &kWalkDownCursorData, // CursorID::WalkDown + &kPaintDownCursorData, // CursorID::PaintDown + &kEntranceDownCursorData, // CursorID::EntranceDown + &kHandOpenDownCursorData, // CursorID::HandOpen + &kHandClosedDownCursorData, // CursorID::HandClosed }; // clang-format on - const CursorData* CursorRepository::GetCursorData(CursorID cursorId) + const CursorData* getCursorData(CursorID cursorId) { const CursorData* result = nullptr; if (cursorId != CursorID::Undefined && cursorId != CursorID::Count) diff --git a/src/openrct2-ui/CursorData.h b/src/openrct2-ui/CursorData.h new file mode 100644 index 0000000000..f0a4dc60c8 --- /dev/null +++ b/src/openrct2-ui/CursorData.h @@ -0,0 +1,33 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include + +namespace OpenRCT2::Ui +{ + constexpr size_t kCursorBitWidth = 32; + constexpr size_t kCursorHeight = 4; + constexpr size_t kRawCursorSize = kCursorBitWidth * kCursorBitWidth; + constexpr size_t kEncodedCursorSize = kRawCursorSize / 8; + + struct CursorData + { + struct HotSpot + { + int16_t X; + int16_t Y; + } HotSpot; + uint8_t Data[kEncodedCursorSize]; + uint8_t Mask[kEncodedCursorSize]; + }; + + const CursorData* getCursorData(CursorID cursorId); +} // namespace OpenRCT2::Ui diff --git a/src/openrct2-ui/CursorRepository.cpp b/src/openrct2-ui/CursorRepository.cpp index 3d06f1e42b..39067e3808 100644 --- a/src/openrct2-ui/CursorRepository.cpp +++ b/src/openrct2-ui/CursorRepository.cpp @@ -9,6 +9,8 @@ #include "CursorRepository.h" +#include "CursorData.h" + #include #include #include @@ -94,11 +96,11 @@ SDL_Cursor* CursorRepository::Create(const CursorData* cursorInfo, uint8_t scale { const auto integer_scale = static_cast(round(scale)); - auto data = ScaleDataArray(cursorInfo->Data, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast(integer_scale)); - auto mask = ScaleDataArray(cursorInfo->Mask, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast(integer_scale)); + auto data = ScaleDataArray(cursorInfo->Data, kCursorBitWidth, kCursorHeight, static_cast(integer_scale)); + auto mask = ScaleDataArray(cursorInfo->Mask, kCursorBitWidth, kCursorHeight, static_cast(integer_scale)); auto* cursor = SDL_CreateCursor( - data.data(), mask.data(), BASE_CURSOR_WIDTH * integer_scale, BASE_CURSOR_HEIGHT * integer_scale, + data.data(), mask.data(), kBaseCursorWidth * integer_scale, kBaseCursorHeight * integer_scale, cursorInfo->HotSpot.X * integer_scale, cursorInfo->HotSpot.Y * integer_scale); return cursor; @@ -126,7 +128,7 @@ void CursorRepository::GenerateScaledCursorSetHolder(uint8_t scale) case CursorID::HandPoint: return SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND); default: - return this->Create(GetCursorData(cursorId), scale); + return this->Create(getCursorData(cursorId), scale); } }; _scaledCursors.emplace(scale, cursorGenerator); diff --git a/src/openrct2-ui/CursorRepository.h b/src/openrct2-ui/CursorRepository.h index 1be1987a41..ad0efe7d05 100644 --- a/src/openrct2-ui/CursorRepository.h +++ b/src/openrct2-ui/CursorRepository.h @@ -19,6 +19,8 @@ struct SDL_Cursor; namespace OpenRCT2::Ui { + struct CursorData; + class CursorRepository { private: @@ -50,8 +52,8 @@ namespace OpenRCT2::Ui } }; - constexpr static int32_t BASE_CURSOR_WIDTH = 32; - constexpr static int32_t BASE_CURSOR_HEIGHT = 32; + constexpr static int32_t kBaseCursorWidth = 32; + constexpr static int32_t kBaseCursorHeight = 32; CursorID _currentCursor = CursorID::Undefined; uint8_t _currentCursorScale = 1; @@ -68,6 +70,5 @@ namespace OpenRCT2::Ui private: SDL_Cursor* Create(const CursorData* cursorInfo, uint8_t scale); void GenerateScaledCursorSetHolder(uint8_t scale); - static const CursorData* GetCursorData(CursorID cursorId); }; } // namespace OpenRCT2::Ui diff --git a/src/openrct2-ui/libopenrct2ui.vcxproj b/src/openrct2-ui/libopenrct2ui.vcxproj index 2ac5fd64f9..dd474ce56a 100644 --- a/src/openrct2-ui/libopenrct2ui.vcxproj +++ b/src/openrct2-ui/libopenrct2ui.vcxproj @@ -46,6 +46,7 @@ + diff --git a/src/openrct2/interface/Cursors.h b/src/openrct2/interface/Cursors.h index b18d1b43ce..4915f47e79 100644 --- a/src/openrct2/interface/Cursors.h +++ b/src/openrct2/interface/Cursors.h @@ -50,19 +50,3 @@ namespace OpenRCT2::Cursor { CursorID FromString(const std::string& s, CursorID defaultValue); } - -namespace OpenRCT2::Ui -{ - constexpr size_t CURSOR_BIT_WIDTH = 32; - constexpr size_t CURSOR_HEIGHT = 4; - struct CursorData - { - struct HotSpot - { - int16_t X; - int16_t Y; - } HotSpot; - uint8_t Data[CURSOR_BIT_WIDTH * CURSOR_HEIGHT]; - uint8_t Mask[CURSOR_BIT_WIDTH * CURSOR_HEIGHT]; - }; -} // namespace OpenRCT2::Ui