While building a traditional boardgame (like Life, Risk, etc.) I cannot get the zooming out of the board image to work properly. I want the ability to show a particular quadrant of the board, say the upper left for example, and display as much of that quadrant given the current window size. This works as designed when the view’s & window’s aspect ratio are equal at 1:1. At first I used the window size to calculate the setCenter() values after a call to zoom() function on the view object. Expectedly black areas appeared within the window. I soon realized my error in using window size and then switched to using the actual gameboard sprite image dimensions to calculate setPosition() values. It worked somewhat. The more I zoomed out the view the larger the black areas became. I have to believe I am missing something obvious to do the calculations correctly to get the results I desire.
void GrapeGameGuiWindow::DisplayGameboardQuardrant(int nQuadrantValue)
{
if (m_pGameboardView != nullptr)
{
unsigned int DisplayW = getSize().x;
unsigned int DisplayH = getSize().y;
// m_ImageW = 4000
// m_ImageH = 3000
switch (nQuadrantValue)
{
case GUI_QUADRANT_CENTERED:
m_pGameboardView->setCenter(sf::Vector2f((m_ImageW / 2), (m_ImageH / 2)));
break;
case GUI_QUADRANT_TOP_LEFT:
// tl: 0,0 br: .5,.5 <-- Values to calculate which portion of the image’s rectangle to base setCenter()
// m_pGameboardView->setCenter(sf::Vector2f((float)(DisplayW / 2), (float)(DisplayH / 2)));
m_pGameboardView->setCenter(sf::Vector2f((m_ImageW * 0.25f), (m_ImageH * 0.25f)));
break;
case GUI_QUADRANT_TOP_RIGHT:
// tl: .5,0 br: 1,.5 <-- Values to calculate which portion of the image's rectangle to base setCenter()
m_pGameboardView->setCenter(sf::Vector2f(((m_ImageW - DisplayW) + (float)(DisplayW / 2)), (float)(DisplayH / 2)));
break;
case GUI_QUADRANT_BOTTOM_LEFT:
// tl: 0,.5 br: .5,1 <-- Values to calculate which portion of the image's rectangle to base setCenter()
m_pGameboardView->setCenter(sf::Vector2f((float)(DisplayW / 2), ((m_ImageH - DisplayH) + (DisplayH / 2))));
break;
case GUI_QUADRANT_BOTTOM_RIGHT:
// tl: .5,.5 br: 1,1 <-- Values to calculate which portion of the image's rectangle to base setCenter()
m_pGameboardView->setCenter(sf::Vector2f(((m_ImageW - DisplayW) + (DisplayW / 2)), ((m_ImageH - DisplayH) + (DisplayH / 2))));
break;
}
}
}