Parcourir la source

Fixed hard-coded screen dimensions in UI Screen

Sanjay Madhav il y a 8 ans
Parent
commit
c7901a5fc8
2 fichiers modifiés avec 6 ajouts et 6 suppressions
  1. 3 3
      Chapter11/UIScreen.cpp
  2. 3 3
      Chapter12/UIScreen.cpp

+ 3 - 3
Chapter11/UIScreen.cpp

@@ -81,10 +81,10 @@ void UIScreen::ProcessInput(const uint8_t* keys)
 		// Get position of mouse
 		int x, y;
 		SDL_GetMouseState(&x, &y);
-		// Convert to (0,0) center coordinates (assume 1024x768)
+		// Convert to (0,0) center coordinates
 		Vector2 mousePos(static_cast<float>(x), static_cast<float>(y));
-		mousePos.x -= 512.0f;
-		mousePos.y = 384.0f - mousePos.y;
+		mousePos.x -= mGame->GetRenderer()->GetScreenWidth() * 0.5f;
+		mousePos.y = mGame->GetRenderer()->GetScreenHeight() * 0.5f - mousePos.y;
 		
 		// Highlight any buttons
 		for (auto b : mButtons)

+ 3 - 3
Chapter12/UIScreen.cpp

@@ -81,10 +81,10 @@ void UIScreen::ProcessInput(const uint8_t* keys)
 		// Get position of mouse
 		int x, y;
 		SDL_GetMouseState(&x, &y);
-		// Convert to (0,0) center coordinates (assume 1024x768)
+		// Convert to (0,0) center coordinates
 		Vector2 mousePos(static_cast<float>(x), static_cast<float>(y));
-		mousePos.x -= 512.0f;
-		mousePos.y = 384.0f - mousePos.y;
+		mousePos.x -= mGame->GetRenderer()->GetScreenWidth() * 0.5f;
+		mousePos.y = mGame->GetRenderer()->GetScreenHeight() * 0.5f - mousePos.y;
 		
 		// Highlight any buttons
 		for (auto b : mButtons)