2017-03-25 15:57:02 +01:00
|
|
|
/*****************************************************************************
|
2020-07-21 15:04:34 +02:00
|
|
|
* Copyright (c) 2014-2020 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>
|
|
|
|
|
|
|
|
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:
|
2018-06-22 23:22:29 +02:00
|
|
|
SDL_Cursor* _cursors[CURSOR_COUNT] = { nullptr };
|
|
|
|
|
2018-02-16 00:43:16 +01:00
|
|
|
public:
|
2018-06-22 23:22:29 +02:00
|
|
|
CursorSetHolder(const std::function<SDL_Cursor*(CURSOR_ID)>& getCursor)
|
2017-12-09 17:08:38 +01:00
|
|
|
{
|
2018-02-16 00:43:16 +01:00
|
|
|
for (size_t i = 0; i < CURSOR_COUNT; i++)
|
2017-12-09 17:08:38 +01:00
|
|
|
{
|
2018-02-16 00:43:16 +01:00
|
|
|
_cursors[i] = getCursor(static_cast<CURSOR_ID>(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()
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < CURSOR_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
|
|
|
|
2018-06-22 23:22:29 +02:00
|
|
|
SDL_Cursor* getScaledCursor(CURSOR_ID cursorId)
|
2018-02-16 00:43:16 +01:00
|
|
|
{
|
|
|
|
return _cursors[cursorId];
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
|
2018-06-22 23:22:29 +02:00
|
|
|
CURSOR_ID _currentCursor = CURSOR_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();
|
|
|
|
CURSOR_ID GetCurrentCursor();
|
|
|
|
void SetCurrentCursor(CURSOR_ID 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);
|
2018-06-22 23:22:29 +02:00
|
|
|
static const CursorData* GetCursorData(CURSOR_ID cursorId);
|
2018-02-16 00:43:16 +01:00
|
|
|
};
|
2018-06-22 23:22:29 +02:00
|
|
|
} // namespace OpenRCT2::Ui
|