1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-28 17:24:47 +01:00

Merge pull request #22466 from AaronVanGeffen/refactor-cursors

Replace hardcoded cursor bytes with ASCII art bitmaps
This commit is contained in:
Aaron van Geffen
2024-08-04 23:32:50 +02:00
committed by GitHub
13 changed files with 1019 additions and 662 deletions

View File

@@ -1,6 +1,7 @@
0.4.14 (in development)
------------------------------------------------------------------------
- Change: [#21659] Increase the Hybrid Roller Coasters maximum lift speed to 17 km/h (11 mph).
- Change: [#22466] The Clear Scenery tool now uses a bulldozer cursor instead of a generic crosshair.
0.4.13 (2024-08-04)
------------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View 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

View File

@@ -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);

View File

@@ -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

View File

@@ -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" />

View File

@@ -409,7 +409,7 @@ namespace OpenRCT2::Ui::Windows
{
ShowGridlines();
auto* toolWindow = ContextOpenWindow(WindowClass::ClearScenery);
ToolSet(*toolWindow, WIDX_BACKGROUND, Tool::Crosshair);
ToolSet(*toolWindow, WIDX_BACKGROUND, Tool::Bulldozer);
InputSetFlag(INPUT_FLAG_6, true);
}
}

View File

@@ -41,6 +41,7 @@ enum class CursorID : uint8_t
EntranceDown,
HandOpen,
HandClosed,
Bulldozer,
Count,
Undefined = 0xFF
@@ -50,19 +51,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

View File

@@ -470,6 +470,7 @@ enum class Tool
WalkDown = 22,
PaintDown = 23,
EntranceDown = 24,
Bulldozer = 27,
};
using modal_callback = void (*)(int32_t result);

View File

@@ -10,11 +10,14 @@
#pragma once
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "../localisation/StringIdType.h"
#include "../world/Location.hpp"
#include "ObjectTypes.h"
#include <string_view>
enum class CursorID : uint8_t;
struct LargeSceneryText;
struct LargeSceneryTile

View File

@@ -10,10 +10,11 @@
#pragma once
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "../localisation/StringIdType.h"
#include "ObjectTypes.h"
enum class CursorID : uint8_t;
enum class PathAdditionDrawType : uint8_t
{
Light,

View File

@@ -10,10 +10,11 @@
#pragma once
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "../localisation/StringIdType.h"
#include "ObjectTypes.h"
enum class CursorID : uint8_t;
enum SMALL_SCENERY_FLAGS : uint32_t
{
SMALL_SCENERY_FLAG_FULL_TILE = (1 << 0), // 0x1

View File

@@ -10,10 +10,11 @@
#pragma once
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "../localisation/StringIdType.h"
#include "ObjectTypes.h"
enum class CursorID : uint8_t;
enum WALL_SCENERY_FLAGS
{
WALL_SCENERY_HAS_PRIMARY_COLOUR = (1 << 0), // 0x1