mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-29 00:41:38 +02:00
Hardware cursor can now be hidden
This commit is contained in:
@ -288,6 +288,24 @@ void CursorHandler::render()
|
|||||||
cursor->render();
|
cursor->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CursorHandler::hide()
|
||||||
|
{
|
||||||
|
if (!showing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
showing = false;
|
||||||
|
cursor->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CursorHandler::show()
|
||||||
|
{
|
||||||
|
if (showing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
showing = true;
|
||||||
|
cursor->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
void CursorSoftware::render()
|
void CursorSoftware::render()
|
||||||
{
|
{
|
||||||
//texture must be updated in the main (renderer) thread, but changes to cursor type may come from other threads
|
//texture must be updated in the main (renderer) thread, but changes to cursor type may come from other threads
|
||||||
@ -348,10 +366,16 @@ void CursorSoftware::setCursorPosition( const Point & newPos )
|
|||||||
pos = newPos;
|
pos = newPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CursorSoftware::setVisible(bool on)
|
||||||
|
{
|
||||||
|
visible = on;
|
||||||
|
}
|
||||||
|
|
||||||
CursorSoftware::CursorSoftware():
|
CursorSoftware::CursorSoftware():
|
||||||
cursorTexture(nullptr),
|
cursorTexture(nullptr),
|
||||||
cursorSurface(nullptr),
|
cursorSurface(nullptr),
|
||||||
needUpdate(false),
|
needUpdate(false),
|
||||||
|
visible(false),
|
||||||
pivot(0,0)
|
pivot(0,0)
|
||||||
{
|
{
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
@ -364,12 +388,12 @@ CursorSoftware::~CursorSoftware()
|
|||||||
|
|
||||||
if (cursorSurface)
|
if (cursorSurface)
|
||||||
SDL_FreeSurface(cursorSurface);
|
SDL_FreeSurface(cursorSurface);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorHardware::CursorHardware():
|
CursorHardware::CursorHardware():
|
||||||
cursor(nullptr)
|
cursor(nullptr)
|
||||||
{
|
{
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorHardware::~CursorHardware()
|
CursorHardware::~CursorHardware()
|
||||||
@ -378,6 +402,14 @@ CursorHardware::~CursorHardware()
|
|||||||
SDL_FreeCursor(cursor);
|
SDL_FreeCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CursorHardware::setVisible(bool on)
|
||||||
|
{
|
||||||
|
if (on)
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
else
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
|
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
|
||||||
{
|
{
|
||||||
auto cursorSurface = CSDL_Ext::newSurface(image->dimensions().x, image->dimensions().y);
|
auto cursorSurface = CSDL_Ext::newSurface(image->dimensions().x, image->dimensions().y);
|
||||||
|
@ -120,6 +120,7 @@ public:
|
|||||||
virtual void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) = 0;
|
virtual void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) = 0;
|
||||||
virtual void setCursorPosition( const Point & newPos ) = 0;
|
virtual void setCursorPosition( const Point & newPos ) = 0;
|
||||||
virtual void render() = 0;
|
virtual void render() = 0;
|
||||||
|
virtual void setVisible( bool on) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CursorHardware : public ICursor
|
class CursorHardware : public ICursor
|
||||||
@ -135,6 +136,7 @@ public:
|
|||||||
void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override;
|
void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override;
|
||||||
void setCursorPosition( const Point & newPos ) override;
|
void setCursorPosition( const Point & newPos ) override;
|
||||||
void render() override;
|
void render() override;
|
||||||
|
void setVisible( bool on) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CursorSoftware : public ICursor
|
class CursorSoftware : public ICursor
|
||||||
@ -147,6 +149,7 @@ class CursorSoftware : public ICursor
|
|||||||
Point pos;
|
Point pos;
|
||||||
Point pivot;
|
Point pivot;
|
||||||
bool needUpdate;
|
bool needUpdate;
|
||||||
|
bool visible;
|
||||||
|
|
||||||
void createTexture(const Point & dimensions);
|
void createTexture(const Point & dimensions);
|
||||||
void updateTexture();
|
void updateTexture();
|
||||||
@ -157,6 +160,7 @@ public:
|
|||||||
void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override;
|
void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override;
|
||||||
void setCursorPosition( const Point & newPos ) override;
|
void setCursorPosition( const Point & newPos ) override;
|
||||||
void render() override;
|
void render() override;
|
||||||
|
void setVisible( bool on) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// handles mouse cursor
|
/// handles mouse cursor
|
||||||
@ -222,8 +226,8 @@ public:
|
|||||||
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void hide() { showing=false; };
|
void hide();
|
||||||
void show() { showing=true; };
|
void show();
|
||||||
|
|
||||||
/// change cursor's positions to (x, y)
|
/// change cursor's positions to (x, y)
|
||||||
void cursorMove(const int & x, const int & y);
|
void cursorMove(const int & x, const int & y);
|
||||||
|
Reference in New Issue
Block a user