Browse Source

Remove not supported method, allow relative mode for iOS

Andrii Danylchenko 2 years ago
parent
commit
9a765e5f67
2 changed files with 14 additions and 5 deletions
  1. 2 0
      client/CMT.cpp
  2. 12 5
      client/gui/CGuiHandler.cpp

+ 2 - 0
client/CMT.cpp

@@ -437,11 +437,13 @@ int main(int argc, char * argv[])
 	SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, "1");
 #endif
 
+#ifdef SDL_HINT_MOUSE_TOUCH_EVENTS
 	if(GH.isPointerRelativeMode)
 	{
 		SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
 		SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
 	}
+#endif
 
 #ifndef VCMI_NO_THREADED_LOAD
 	//we can properly play intro only in the main thread, so we have to move loading to the separate thread

+ 12 - 5
client/gui/CGuiHandler.cpp

@@ -268,12 +268,17 @@ void CGuiHandler::fakeMouseButtonEventRelativeMode(bool down, bool right)
 	sme.x = CCS->curh->xpos;
 	sme.y = CCS->curh->ypos;
 
-	int windowX, windowY;
+	float xScale, yScale;
+	int w, h, rLogicalWidth, rLogicalHeight;
 
-	SDL_RenderLogicalToWindow(mainRenderer, sme.x, sme.y, &windowX, &windowY);
+	SDL_GetWindowSize(mainWindow, &w, &h);
+	SDL_RenderGetLogicalSize(mainRenderer, &rLogicalWidth, &rLogicalHeight);
+	SDL_RenderGetScale(mainRenderer, &xScale, &yScale);
 
 	SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
-	SDL_WarpMouse(windowX, windowY);
+	SDL_WarpMouse(
+		(int)(sme.x * xScale) + (w - rLogicalWidth * xScale) / 2,
+		(int)(sme.y * yScale + (h - rLogicalHeight * yScale) / 2));
 	SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
 
 	event.button = sme;
@@ -430,7 +435,6 @@ void CGuiHandler::handleCurrentEvent()
 			}
 		}
 	}
-#ifndef VCMI_IOS
 	else if(current->type == SDL_FINGERMOTION)
 	{
 		if(isPointerRelativeMode)
@@ -453,12 +457,14 @@ void CGuiHandler::handleCurrentEvent()
 				fakeMouseButtonEventRelativeMode(true, isRightClick);
 			}
 		}
+#ifndef VCMI_IOS
 		else if(fingerCount == 2)
 		{
 			convertTouchToMouse(current);
 			handleMouseMotion();
 			handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true);
 		}
+#endif //VCMI_IOS
 	}
 	else if(current->type == SDL_FINGERUP)
 	{
@@ -473,6 +479,7 @@ void CGuiHandler::handleCurrentEvent()
 				fakeMouseButtonEventRelativeMode(false, isRightClick);
 			}
 		}
+#ifndef VCMI_IOS
 		else if(multifinger)
 		{
 			convertTouchToMouse(current);
@@ -480,8 +487,8 @@ void CGuiHandler::handleCurrentEvent()
 			handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
 			multifinger = fingerCount != 0;
 		}
-	}
 #endif //VCMI_IOS
+	}
 
 	current = nullptr;
 } //event end