|
|
@@ -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);
|