mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Execute cursor changes in main thread on any platform
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CursorHardware.h"
|
#include "CursorHardware.h"
|
||||||
|
|
||||||
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../render/Colors.h"
|
#include "../render/Colors.h"
|
||||||
#include "../render/IImage.h"
|
#include "../render/IImage.h"
|
||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
@@ -18,10 +19,6 @@
|
|||||||
#include <SDL_render.h>
|
#include <SDL_render.h>
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
|
|
||||||
#ifdef VCMI_APPLE
|
|
||||||
#include <dispatch/dispatch.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CursorHardware::CursorHardware():
|
CursorHardware::CursorHardware():
|
||||||
cursor(nullptr)
|
cursor(nullptr)
|
||||||
{
|
{
|
||||||
@@ -36,16 +33,13 @@ CursorHardware::~CursorHardware()
|
|||||||
|
|
||||||
void CursorHardware::setVisible(bool on)
|
void CursorHardware::setVisible(bool on)
|
||||||
{
|
{
|
||||||
#ifdef VCMI_APPLE
|
GH.dispatchMainThread([on]()
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
{
|
||||||
#endif
|
|
||||||
if (on)
|
if (on)
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
else
|
else
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
#ifdef VCMI_APPLE
|
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
|
void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
|
||||||
@@ -63,16 +57,13 @@ void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivot
|
|||||||
logGlobal->error("Failed to set cursor! SDL says %s", SDL_GetError());
|
logGlobal->error("Failed to set cursor! SDL says %s", SDL_GetError());
|
||||||
|
|
||||||
SDL_FreeSurface(cursorSurface);
|
SDL_FreeSurface(cursorSurface);
|
||||||
#ifdef VCMI_APPLE
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
GH.dispatchMainThread([this, oldCursor](){
|
||||||
#endif
|
|
||||||
SDL_SetCursor(cursor);
|
SDL_SetCursor(cursor);
|
||||||
|
|
||||||
if (oldCursor)
|
if (oldCursor)
|
||||||
SDL_FreeCursor(oldCursor);
|
SDL_FreeCursor(oldCursor);
|
||||||
#ifdef VCMI_APPLE
|
|
||||||
});
|
});
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CursorHardware::setCursorPosition( const Point & newPos )
|
void CursorHardware::setCursorPosition( const Point & newPos )
|
||||||
|
Reference in New Issue
Block a user