mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Implemented hardware cursor support
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#include "../CMT.h"
|
||||
|
||||
CursorHandler::CursorHandler()
|
||||
: cursorSW(new CursorSoftware())
|
||||
: cursorSW(new CursorHardware())
|
||||
, frameTime(0.f)
|
||||
, showing(false)
|
||||
, pos(0,0)
|
||||
@@ -52,6 +52,9 @@ void CursorHandler::changeGraphic(Cursor::Type type, size_t index)
|
||||
{
|
||||
assert(dndObject == nullptr);
|
||||
|
||||
if (type == this->type && index == this->frame)
|
||||
return;
|
||||
|
||||
this->type = type;
|
||||
this->frame = index;
|
||||
|
||||
@@ -346,3 +349,39 @@ CursorSoftware::~CursorSoftware()
|
||||
SDL_FreeSurface(cursorSurface);
|
||||
|
||||
}
|
||||
|
||||
CursorHardware::CursorHardware():
|
||||
cursor(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
CursorHardware::~CursorHardware()
|
||||
{
|
||||
if(cursor)
|
||||
SDL_FreeCursor(cursor);
|
||||
}
|
||||
|
||||
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
|
||||
{
|
||||
auto cursorSurface = CSDL_Ext::newSurface(image->dimensions().x, image->dimensions().y);
|
||||
|
||||
image->draw(cursorSurface);
|
||||
|
||||
cursor = SDL_CreateColorCursor(cursorSurface, pivotOffset.x, pivotOffset.y);
|
||||
|
||||
if (!cursor)
|
||||
logGlobal->error("Failed to set cursor! SDL says %s", SDL_GetError());
|
||||
|
||||
SDL_FreeSurface(cursorSurface);
|
||||
SDL_SetCursor(cursor);
|
||||
}
|
||||
|
||||
void CursorHardware::setCursorPosition( const Point & newPos )
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
|
||||
void CursorHardware::render()
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ class CAnimation;
|
||||
class IImage;
|
||||
struct SDL_Surface;
|
||||
struct SDL_Texture;
|
||||
struct SDL_Cursor;
|
||||
|
||||
#include "Geometries.h"
|
||||
|
||||
@@ -113,7 +114,18 @@ namespace Cursor
|
||||
|
||||
class CursorHardware
|
||||
{
|
||||
//TODO
|
||||
std::shared_ptr<IImage> cursorImage;
|
||||
|
||||
SDL_Cursor * cursor;
|
||||
|
||||
public:
|
||||
CursorHardware();
|
||||
~CursorHardware();
|
||||
|
||||
void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset);
|
||||
void setCursorPosition( const Point & newPos );
|
||||
|
||||
void render();
|
||||
};
|
||||
|
||||
class CursorSoftware
|
||||
@@ -137,7 +149,6 @@ public:
|
||||
void setCursorPosition( const Point & newPos );
|
||||
|
||||
void render();
|
||||
void setVisible(bool on);
|
||||
};
|
||||
|
||||
/// handles mouse cursor
|
||||
@@ -167,7 +178,7 @@ class CursorHandler final
|
||||
|
||||
std::shared_ptr<IImage> getCurrentImage();
|
||||
|
||||
std::unique_ptr<CursorSoftware> cursorSW;
|
||||
std::unique_ptr<CursorHardware> cursorSW;
|
||||
public:
|
||||
CursorHandler();
|
||||
~CursorHandler();
|
||||
|
Reference in New Issue
Block a user