mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 06:44:38 +01:00
Introduce CursorData.h; rename constants
This commit is contained in:
@@ -7,19 +7,20 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "CursorRepository.h"
|
||||
#include "CursorData.h"
|
||||
|
||||
#include <openrct2/interface/Cursors.h>
|
||||
#include <openrct2/util/Util.h>
|
||||
|
||||
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)
|
||||
|
||||
33
src/openrct2-ui/CursorData.h
Normal file
33
src/openrct2-ui/CursorData.h
Normal file
@@ -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 <openrct2/interface/Cursors.h>
|
||||
|
||||
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
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "CursorRepository.h"
|
||||
|
||||
#include "CursorData.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/core/Guard.hpp>
|
||||
@@ -94,11 +96,11 @@ SDL_Cursor* CursorRepository::Create(const CursorData* cursorInfo, uint8_t scale
|
||||
{
|
||||
const auto integer_scale = static_cast<int>(round(scale));
|
||||
|
||||
auto data = ScaleDataArray(cursorInfo->Data, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast<size_t>(integer_scale));
|
||||
auto mask = ScaleDataArray(cursorInfo->Mask, CURSOR_BIT_WIDTH, CURSOR_HEIGHT, static_cast<size_t>(integer_scale));
|
||||
auto data = ScaleDataArray(cursorInfo->Data, kCursorBitWidth, kCursorHeight, static_cast<size_t>(integer_scale));
|
||||
auto mask = ScaleDataArray(cursorInfo->Mask, kCursorBitWidth, kCursorHeight, static_cast<size_t>(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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<ClInclude Include="audio\AudioFormat.h" />
|
||||
<ClInclude Include="audio\AudioMixer.h" />
|
||||
<ClInclude Include="audio\SDLAudioSource.h" />
|
||||
<ClInclude Include="CursorData.h" />
|
||||
<ClInclude Include="CursorRepository.h" />
|
||||
<ClInclude Include="drawing\BitmapReader.h" />
|
||||
<ClInclude Include="drawing\engines\DrawingEngineFactory.hpp" />
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user