OpenRCT2/src/openrct2-ui/CursorRepository.h

73 lines
2.1 KiB
C
Raw Normal View History

/*****************************************************************************
2020-07-21 15:04:34 +02:00
* Copyright (c) 2014-2020 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.
*****************************************************************************/
2018-05-31 00:22:19 +02:00
#pragma once
#include <SDL.h>
2018-06-22 23:22:29 +02:00
#include <functional>
#include <map>
#include <openrct2/interface/Cursors.h>
struct SDL_Cursor;
2018-02-16 00:43:16 +01:00
namespace OpenRCT2::Ui
{
2018-02-16 00:43:16 +01:00
class CursorRepository
{
2018-02-16 00:43:16 +01:00
private:
class CursorSetHolder
{
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;
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;
uint8_t _currentCursorScale = 1;
std::map<uint8_t, CursorSetHolder> _scaledCursors;
2018-02-16 00:43:16 +01:00
public:
~CursorRepository();
void LoadCursors();
CURSOR_ID GetCurrentCursor();
void SetCurrentCursor(CURSOR_ID cursorId);
void SetCursorScale(uint8_t cursorScale);
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);
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