mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Hardware cursor can now be hidden
This commit is contained in:
		| @@ -4,39 +4,39 @@ | ||||
|  * Authors: listed in file AUTHORS in main folder | ||||
|  * | ||||
|  * License: GNU General Public License v2.0 or later | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "StdInc.h" | ||||
| #include "CursorHandler.h" | ||||
|  | ||||
|  * Full text of license available in license.txt file, in main folder | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #include "StdInc.h" | ||||
| #include "CursorHandler.h" | ||||
|  | ||||
| #include <SDL.h> | ||||
|  | ||||
| #include "SDL_Extensions.h" | ||||
| #include "CGuiHandler.h" | ||||
| #include "CAnimation.h" | ||||
| #include "../../lib/CConfigHandler.h" | ||||
|  | ||||
| std::unique_ptr<ICursor> CursorHandler::createCursor() | ||||
| { | ||||
| 	if (settings["video"]["cursor"].String() == "auto") | ||||
| 	{ | ||||
| #if defined(VCMI_ANDROID) || defined(VCMI_IOS) | ||||
| 		return std::make_unique<CursorSoftware>(); | ||||
| #else | ||||
| 		return std::make_unique<CursorHardware>(); | ||||
| #endif | ||||
| 	} | ||||
|  | ||||
| 	if (settings["video"]["cursor"].String() == "hardware") | ||||
| 		return std::make_unique<CursorHardware>(); | ||||
|  | ||||
| 	assert(settings["video"]["cursor"].String() == "software"); | ||||
| 	return std::make_unique<CursorSoftware>(); | ||||
| } | ||||
|  | ||||
| CursorHandler::CursorHandler() | ||||
| #include "CAnimation.h" | ||||
| #include "../../lib/CConfigHandler.h" | ||||
|  | ||||
| std::unique_ptr<ICursor> CursorHandler::createCursor() | ||||
| { | ||||
| 	if (settings["video"]["cursor"].String() == "auto") | ||||
| 	{ | ||||
| #if defined(VCMI_ANDROID) || defined(VCMI_IOS) | ||||
| 		return std::make_unique<CursorSoftware>(); | ||||
| #else | ||||
| 		return std::make_unique<CursorHardware>(); | ||||
| #endif | ||||
| 	} | ||||
|  | ||||
| 	if (settings["video"]["cursor"].String() == "hardware") | ||||
| 		return std::make_unique<CursorHardware>(); | ||||
|  | ||||
| 	assert(settings["video"]["cursor"].String() == "software"); | ||||
| 	return std::make_unique<CursorSoftware>(); | ||||
| } | ||||
|  | ||||
| CursorHandler::CursorHandler() | ||||
| 	: cursor(createCursor()) | ||||
| 	, frameTime(0.f) | ||||
| 	, showing(false) | ||||
| @@ -288,6 +288,24 @@ void CursorHandler::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() | ||||
| { | ||||
| 	//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; | ||||
| } | ||||
|  | ||||
| void CursorSoftware::setVisible(bool on) | ||||
| { | ||||
| 	visible = on; | ||||
| } | ||||
|  | ||||
| CursorSoftware::CursorSoftware(): | ||||
| 	cursorTexture(nullptr), | ||||
| 	cursorSurface(nullptr), | ||||
| 	needUpdate(false), | ||||
| 	visible(false), | ||||
| 	pivot(0,0) | ||||
| { | ||||
| 	SDL_ShowCursor(SDL_DISABLE); | ||||
| @@ -364,12 +388,12 @@ CursorSoftware::~CursorSoftware() | ||||
|  | ||||
| 	if (cursorSurface) | ||||
| 		SDL_FreeSurface(cursorSurface); | ||||
|  | ||||
| } | ||||
|  | ||||
| CursorHardware::CursorHardware(): | ||||
| 	cursor(nullptr) | ||||
| { | ||||
| 	SDL_ShowCursor(SDL_DISABLE); | ||||
| } | ||||
|  | ||||
| CursorHardware::~CursorHardware() | ||||
| @@ -378,6 +402,14 @@ CursorHardware::~CursorHardware() | ||||
| 		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) | ||||
| { | ||||
| 	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 setCursorPosition( const Point & newPos ) = 0; | ||||
| 	virtual void render() = 0; | ||||
| 	virtual void setVisible( bool on) = 0; | ||||
| }; | ||||
|  | ||||
| class CursorHardware : public ICursor | ||||
| @@ -135,6 +136,7 @@ public: | ||||
| 	void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override; | ||||
| 	void setCursorPosition( const Point & newPos ) override; | ||||
| 	void render() override; | ||||
| 	void setVisible( bool on) override; | ||||
| }; | ||||
|  | ||||
| class CursorSoftware : public ICursor | ||||
| @@ -147,6 +149,7 @@ class CursorSoftware : public ICursor | ||||
| 	Point pos; | ||||
| 	Point pivot; | ||||
| 	bool needUpdate; | ||||
| 	bool visible; | ||||
|  | ||||
| 	void createTexture(const Point & dimensions); | ||||
| 	void updateTexture(); | ||||
| @@ -157,6 +160,7 @@ public: | ||||
| 	void setImage(std::shared_ptr<IImage> image, const Point & pivotOffset) override; | ||||
| 	void setCursorPosition( const Point & newPos ) override; | ||||
| 	void render() override; | ||||
| 	void setVisible( bool on) override; | ||||
| }; | ||||
|  | ||||
| /// handles mouse cursor | ||||
| @@ -222,8 +226,8 @@ public: | ||||
|  | ||||
| 	void render(); | ||||
|  | ||||
| 	void hide() { showing=false; }; | ||||
| 	void show() { showing=true; }; | ||||
| 	void hide(); | ||||
| 	void show(); | ||||
|  | ||||
| 	/// change cursor's positions to (x, y) | ||||
| 	void cursorMove(const int & x, const int & y); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user