Explorar el Código

Fix cursor scaling

Ivan Savenko hace 1 año
padre
commit
095f5b5e60
Se han modificado 2 ficheros con 13 adiciones y 6 borrados
  1. 2 2
      client/renderSDL/CursorHardware.cpp
  2. 11 4
      client/renderSDL/CursorSoftware.cpp

+ 2 - 2
client/renderSDL/CursorHardware.cpp

@@ -12,7 +12,7 @@
 #include "CursorHardware.h"
 
 #include "../gui/CGuiHandler.h"
-#include "../renderSDL/ScreenHandler.h"
+#include "../render/IScreenHandler.h"
 #include "../render/Colors.h"
 #include "../render/IImage.h"
 #include "SDL_Extensions.h"
@@ -45,7 +45,7 @@ void CursorHardware::setVisible(bool on)
 
 void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivotOffset)
 {
-	auto cursorSurface = CSDL_Ext::newSurface(image->dimensions());
+	auto cursorSurface = CSDL_Ext::newSurface(image->dimensions() * GH.screenHandler().getScalingFactor());
 
 	CSDL_Ext::fillSurface(cursorSurface, CSDL_Ext::toSDL(Colors::TRANSPARENCY));
 

+ 11 - 4
client/renderSDL/CursorSoftware.cpp

@@ -11,6 +11,8 @@
 #include "StdInc.h"
 #include "CursorSoftware.h"
 
+#include "../gui/CGuiHandler.h"
+#include "../render/IScreenHandler.h"
 #include "../render/Colors.h"
 #include "../render/IImage.h"
 #include "../CMT.h"
@@ -30,8 +32,8 @@ void CursorSoftware::render()
 	SDL_Rect destRect;
 	destRect.x = renderPos.x;
 	destRect.y = renderPos.y;
-	destRect.w = 40;
-	destRect.h = 40;
+	destRect.w = cursorSurface->w;
+	destRect.h = cursorSurface->h;
 
 	SDL_RenderCopy(mainRenderer, cursorTexture, nullptr, &destRect);
 }
@@ -53,8 +55,13 @@ void CursorSoftware::createTexture(const Point & dimensions)
 
 void CursorSoftware::updateTexture()
 {
-	if (!cursorSurface ||  Point(cursorSurface->w, cursorSurface->h) != cursorImage->dimensions())
-		createTexture(cursorImage->dimensions());
+	if (!cursorSurface)
+		createTexture(cursorImage->dimensions() * GH.screenHandler().getScalingFactor());
+
+	Point currentSize = Point(cursorSurface->w, cursorSurface->h);
+
+	if (currentSize != cursorImage->dimensions() * GH.screenHandler().getScalingFactor())
+		createTexture(cursorImage->dimensions() * GH.screenHandler().getScalingFactor());
 
 	CSDL_Ext::fillSurface(cursorSurface, CSDL_Ext::toSDL(Colors::TRANSPARENCY));