Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/MiniMap.cpp
Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | void CMiniMap::HandleMessage(SGUIMessage& Message) | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
bool CMiniMap::MouseOver() | bool CMiniMap::MouseOver() | ||||
{ | { | ||||
// Get the mouse position. | // Get the mouse position. | ||||
CPos mousePos = GetMousePos(); | const CPos& mousePos = m_pGUI->GetMousePos(); | ||||
// Get the position of the center of the minimap. | // Get the position of the center of the minimap. | ||||
CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0); | CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0); | ||||
// Take the magnitude of the difference of the mouse position and minimap center. | // Take the magnitude of the difference of the mouse position and minimap center. | ||||
double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2)); | double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2)); | ||||
// If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap. | // If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap. | ||||
if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0) | if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0) | ||||
return true; | return true; | ||||
else | else | ||||
return false; | return false; | ||||
} | } | ||||
void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) | void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) | ||||
{ | { | ||||
// Determine X and Z according to proportion of mouse position and minimap | // Determine X and Z according to proportion of mouse position and minimap | ||||
CPos mousePos = GetMousePos(); | const CPos& mousePos = m_pGUI->GetMousePos(); | ||||
float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth(); | float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth(); | ||||
float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight(); | float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight(); | ||||
float angle = GetAngle(); | float angle = GetAngle(); | ||||
// Scale world coordinates for shrunken square map | // Scale world coordinates for shrunken square map | ||||
x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); | x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); | ||||
▲ Show 20 Lines • Show All 493 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator