1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-16 10:19:47 +02:00
vcmi/client/renderSDL/CursorHardware.cpp

78 lines
1.6 KiB
C++
Raw Normal View History

/*
2023-02-01 16:42:03 +02:00
* CursorHardware.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
2023-01-19 18:16:11 +02:00
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "CursorHardware.h"
2023-01-19 18:16:11 +02:00
#include "../gui/CGuiHandler.h"
#include "../render/Colors.h"
#include "../render/IImage.h"
#include "SDL_Extensions.h"
2023-01-19 18:16:11 +02:00
2023-01-30 00:12:43 +02:00
#include <SDL_render.h>
#include <SDL_events.h>
2023-01-30 00:12:43 +02:00
2023-01-05 22:13:24 +02:00
CursorHardware::CursorHardware():
cursor(nullptr)
{
2023-01-19 18:16:11 +02:00
SDL_ShowCursor(SDL_DISABLE);
2023-01-05 22:13:24 +02:00
}
CursorHardware::~CursorHardware()
{
if(cursor)
SDL_FreeCursor(cursor);
}
2023-01-19 18:16:11 +02:00
void CursorHardware::setVisible(bool on)
{
GH.dispatchMainThread([on]()
{
if (on)
SDL_ShowCursor(SDL_ENABLE);
else
SDL_ShowCursor(SDL_DISABLE);
});
2023-01-19 18:16:11 +02:00
}
2023-01-05 22:13:24 +02:00
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
{
auto cursorSurface = CSDL_Ext::newSurface(image->dimensions().x, image->dimensions().y);
2023-01-18 16:54:53 +02:00
CSDL_Ext::fillSurface(cursorSurface, Colors::TRANSPARENCY);
2023-01-05 23:24:49 +02:00
2023-01-05 22:13:24 +02:00
image->draw(cursorSurface);
auto oldCursor = cursor;
2023-01-05 22:13:24 +02:00
cursor = SDL_CreateColorCursor(cursorSurface, pivotOffset.x, pivotOffset.y);
if (!cursor)
logGlobal->error("Failed to set cursor! SDL says %s", SDL_GetError());
SDL_FreeSurface(cursorSurface);
GH.dispatchMainThread([this, oldCursor](){
SDL_SetCursor(cursor);
if (oldCursor)
SDL_FreeCursor(oldCursor);
});
2023-01-05 22:13:24 +02:00
}
void CursorHardware::setCursorPosition( const Point & newPos )
{
//no-op
}
void CursorHardware::render()
{
//no-op
}