GRAPHICS: Added an arrow cursor to CursorMan

It is meant to be used as a sane cursor when the game is relying on
system cursor, like some Windows titles.

If you want to improve the cursor graphics, you are welcome.
This commit is contained in:
Eugene Sandulenko 2024-08-09 14:16:40 +02:00
parent 2f20fc4fd4
commit 5a3a131b09
No known key found for this signature in database
GPG Key ID: 014D387312D34F08
2 changed files with 49 additions and 0 deletions

View File

@ -31,6 +31,32 @@ DECLARE_SINGLETON(Graphics::CursorManager);
namespace Graphics {
static const int CURSOR_W = 12;
static const int CURSOR_H = 20;
static const byte ARROW_CURSOR[CURSOR_W * CURSOR_H] = {
1,1,0,0,0,0,0,0,0,0,0,0,
1,2,1,0,0,0,0,0,0,0,0,0,
1,2,2,1,0,0,0,0,0,0,0,0,
1,2,2,2,1,0,0,0,0,0,0,0,
1,2,2,2,2,1,0,0,0,0,0,0,
1,2,2,2,2,2,1,0,0,0,0,0,
1,2,2,2,2,2,2,1,0,0,0,0,
1,2,2,2,2,2,2,2,1,0,0,0,
1,2,2,2,2,2,2,2,2,1,0,0,
1,2,2,2,2,2,2,2,2,2,1,0,
1,2,2,2,2,2,2,1,1,1,1,1,
1,2,2,2,1,2,2,1,0,0,0,0,
1,2,2,1,1,2,2,1,0,0,0,0,
1,2,1,0,0,1,2,2,1,0,0,0,
1,1,0,0,0,1,2,2,1,0,0,0,
1,0,0,0,0,0,1,2,2,1,0,0,
0,0,0,0,0,0,1,2,2,1,0,0,
0,0,0,0,0,0,0,1,2,2,1,0,
0,0,0,0,0,0,0,1,2,2,1,0,
0,0,0,0,0,0,0,0,1,1,0,0,
};
static const byte CURSOR_PALETTE[] = { 0x80, 0x80, 0x80, 0, 0, 0, 0xff, 0xff, 0xff };
CursorManager::~CursorManager() {
for (Common::Stack<Cursor *>::size_type i = 0; i < _cursorStack.size(); ++i)
delete _cursorStack[i];
@ -275,6 +301,18 @@ void CursorManager::lock(bool locked) {
_locked = locked;
}
void CursorManager::setDefaultArrowCursor(bool push) {
Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
if (push) {
pushCursorPalette(CURSOR_PALETTE, 0, ARRAYSIZE(CURSOR_PALETTE) / 3);
pushCursor(ARROW_CURSOR, CURSOR_W, CURSOR_H, 0, 0, 0, true, &format);
} else {
replaceCursorPalette(CURSOR_PALETTE, 0, ARRAYSIZE(CURSOR_PALETTE) / 3);
replaceCursor(ARROW_CURSOR, CURSOR_W, CURSOR_H, 0, 0, 0, true, &format);
}
}
CursorManager::Cursor::Cursor(const Surface &surf, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const byte *mask) {
const uint32 keycolor_mask = (((uint32) -1) >> (sizeof(uint32) * 8 - surf.format.bytesPerPixel * 8));
_keycolor = keycolor & keycolor_mask;

View File

@ -242,6 +242,17 @@ public:
* and returns false.
*/
void lock(bool locked);
/**
* Sets default arrow cursor
*
* This is supposed to be used as a sane fallback for system cursor for
* games that rely on the system cursor
*
* @param push Specified if cursor should be pushed on replaced (defailt)
*/
void setDefaultArrowCursor(bool push = false);
private:
/**
* Generic class for implementing the singleton design pattern.