Hi Hapax,
Sorry I don't think I explained myself very well last time. Hopefully a screenshot will show up better. For some reason when I use the IMG code to display this PNG, it doesn't show the full width of it, so I am just putting the tinypic link instead.
So mapview is the main window that I can scroll around.
The minimapview is static is in the bottom left corner. See the yellow highlight box?
http://tinypic.com/r/25uo5eq/9I need a way to be able to ensure the size of this rectangle is the same as what is shown in the mapview.
I need a way to be able to ensure the position of this rectangle is the same as what is shown in the mapview.
Finally, the position of the rectangle should move when I scroll in the mapview. (I scroll with a mapview.move call).
I got the rectangle position as per the above screenshot using the below, but it isn't quite right. It doesn't cover all of Italy when it is displayed in the mapview. Also I am not sure when I move the mapview, how to get the border to move in tandem in the minimapview. If I just use the same value in minimap.move it goes flying off-screen.
sf::Vector2f borderSize(miniMapView.getSize().x * miniMapView.getViewport().width, miniMapView.getSize().y * miniMapView.getViewport().height);
sf::Vector2f borderPos(miniMapView.getCenter().x - borderSize.x, miniMapView.getCenter().y - borderSize.y);
Here is now I am defining the map and mini-views
void drawEngine::calcMapView()
{
int xSize = gameWindow.getSize().x;
int ySize = gameWindow.getSize().y * 0.800;
float xFloat = (float)xSize/gameWindow.getSize().x;
float yFloat = (float)ySize/gameWindow.getSize().y;
mapView.reset(sf::FloatRect(0.f, 0.f, xSize, ySize));
mapView.setViewport(sf::FloatRect(0.f, 0.f, xFloat, yFloat));
}
void drawEngine::calcMiniMapView()
{
int xSize = gameWindow.getSize().x * 0.25;
int ySize = gameWindow.getSize().y * 0.23;
float xFloat = (float)xSize/gameWindow.getSize().x;
float yFloat = (float)ySize/gameWindow.getSize().y;
miniMapView.reset(sf::FloatRect(0.f, 0.f, xSize, ySize));
miniMapView.setViewport(sf::FloatRect(0.f, 0.77, xFloat, yFloat));
}
Then to draw the minimap, I change the scale of the images of the regions to fit into the minimapview.
I then define a rectangle, try to work out position and size. Then I draw that
void drawEngine::drawMiniMap()
{
gameWindow.setView(miniMapView);
sf::Vector2f origPos;
for (int i = 0; i < regionListPtr->size(); i++)
{
regionListPtr->at(i).getRegionSprite()->setPosition(regionListPtr->at(i).getImagePosition());
regionListPtr->at(i).getRegionSprite()->setScale(0.35f, 0.33f);
gameWindow.draw(*regionListPtr->at(i).getRegionSprite());
sf::Vector2f borderSize(miniMapView.getSize().x * miniMapView.getViewport().width, miniMapView.getSize().y * miniMapView.getViewport().height);
sf::Vector2f borderPos(miniMapView.getCenter().x - borderSize.x, miniMapView.getCenter().y - borderSize.y);
sf::RectangleShape border = createArmyUnitBorder(borderPos, borderSize, 4);
gameWindow.draw(border);
}
sf::RectangleShape drawEngine::createArmyUnitBorder(sf::Vector2f borderPos, sf::Vector2f borderSize, int borderThickness)
{
sf::RectangleShape returnBorder;
returnBorder.setOutlineThickness(borderThickness);
returnBorder.setOutlineColor(sf::Color::Yellow);
returnBorder.setFillColor(sf::Color::Transparent);
returnBorder.setSize(borderSize);
returnBorder.setPosition(borderPos);
return returnBorder;
}
So I assumed I would have to work out what is being displayed in the mapview and somehow convert it to the minimapview. However I don't fully understand whether this is correct and I don't quite follow what you are saying. I am setting the view to minimap when I draw the rectangle but the position and size are not correct?