2017-03-25 15:57:02 +01:00
|
|
|
/*****************************************************************************
|
2024-01-01 12:52:28 +01:00
|
|
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
2018-06-15 14:07:34 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2017-03-25 15:57:02 +01:00
|
|
|
|
2018-05-31 00:22:19 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-02 21:23:58 +01:00
|
|
|
#include <SDL.h>
|
2018-06-22 23:22:29 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
2017-03-25 15:57:02 +01:00
|
|
|
#include <openrct2/interface/Cursors.h>
|
2020-10-11 18:01:14 +02:00
|
|
|
#include <openrct2/util/Util.h>
|
2017-03-25 15:57:02 +01:00
|
|
|
|
|
|
|
struct SDL_Cursor;
|
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
namespace OpenRCT2::Ui
|
2017-03-25 15:57:02 +01:00
|
|
|
{
|
2018-02-16 00:43:16 +01:00
|
|
|
class CursorRepository
|
2017-03-25 15:57:02 +01:00
|
|
|
{
|
2018-02-16 00:43:16 +01:00
|
|
|
private:
|
|
|
|
class CursorSetHolder
|
2017-03-25 15:57:02 +01:00
|
|
|
{
|
|
|
|
private:
|
2020-10-11 18:01:14 +02:00
|
|
|
SDL_Cursor* _cursors[EnumValue(CursorID::Count)] = { nullptr };
|
2018-06-22 23:22:29 +02:00
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
public:
|
2020-10-11 18:01:14 +02:00
|
|
|
CursorSetHolder(const std::function<SDL_Cursor*(CursorID)>& getCursor)
|
2017-12-09 17:08:38 +01:00
|
|
|
{
|
2020-10-11 18:01:14 +02:00
|
|
|
for (size_t i = 0; i < EnumValue(CursorID::Count); i++)
|
2017-12-09 17:08:38 +01:00
|
|
|
{
|
2020-10-11 18:01:14 +02:00
|
|
|
_cursors[i] = getCursor(static_cast<CursorID>(i));
|
2017-12-09 17:08:38 +01:00
|
|
|
}
|
2018-02-16 00:43:16 +01:00
|
|
|
}
|
2017-12-09 17:08:38 +01:00
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
~CursorSetHolder()
|
|
|
|
{
|
2020-10-11 18:01:14 +02:00
|
|
|
for (size_t i = 0; i < EnumValue(CursorID::Count); i++)
|
2017-12-09 17:08:38 +01:00
|
|
|
{
|
2018-02-16 00:43:16 +01:00
|
|
|
SDL_FreeCursor(_cursors[i]);
|
2017-12-09 17:08:38 +01:00
|
|
|
}
|
2018-02-16 00:43:16 +01:00
|
|
|
}
|
2017-12-09 17:08:38 +01:00
|
|
|
|
2021-11-23 14:18:07 +01:00
|
|
|
SDL_Cursor* GetScaledCursor(CursorID cursorId)
|
2018-02-16 00:43:16 +01:00
|
|
|
{
|
2020-10-11 18:01:14 +02:00
|
|
|
return _cursors[EnumValue(cursorId)];
|
2018-02-16 00:43:16 +01:00
|
|
|
}
|
|
|
|
};
|
2017-12-09 17:08:38 +01:00
|
|
|
|
2018-06-22 23:22:29 +02:00
|
|
|
constexpr static int32_t BASE_CURSOR_WIDTH = 32;
|
2018-06-20 17:28:51 +02:00
|
|
|
constexpr static int32_t BASE_CURSOR_HEIGHT = 32;
|
2017-12-09 17:08:38 +01:00
|
|
|
|
2020-10-11 18:01:14 +02:00
|
|
|
CursorID _currentCursor = CursorID::Undefined;
|
2018-06-20 17:28:51 +02:00
|
|
|
uint8_t _currentCursorScale = 1;
|
2017-03-25 15:57:02 +01:00
|
|
|
|
2018-06-20 17:28:51 +02:00
|
|
|
std::map<uint8_t, CursorSetHolder> _scaledCursors;
|
2017-03-25 15:57:02 +01:00
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
public:
|
|
|
|
~CursorRepository();
|
|
|
|
void LoadCursors();
|
2020-10-11 18:01:14 +02:00
|
|
|
CursorID GetCurrentCursor();
|
|
|
|
void SetCurrentCursor(CursorID cursorId);
|
2018-06-20 17:28:51 +02:00
|
|
|
void SetCursorScale(uint8_t cursorScale);
|
2017-03-25 15:57:02 +01:00
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
private:
|
2018-06-22 23:22:29 +02:00
|
|
|
SDL_Cursor* Create(const CursorData* cursorInfo, uint8_t scale);
|
2018-06-20 17:28:51 +02:00
|
|
|
void GenerateScaledCursorSetHolder(uint8_t scale);
|
2020-10-11 18:01:14 +02:00
|
|
|
static const CursorData* GetCursorData(CursorID cursorId);
|
2018-02-16 00:43:16 +01:00
|
|
|
};
|
2018-06-22 23:22:29 +02:00
|
|
|
} // namespace OpenRCT2::Ui
|