Okay. Maybe I am really doing something wrong.
Here is a little example. It's stupid and messy, but compiles and runs.
#include <SFML/Graphics.hpp>
int main ()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Selecting with mouse - test", sf::Style::Close | sf::Style::Resize);
sf::Text text;
text.SetPosition(50, 50);
text.SetColor(sf::Color::White);
text.SetString("Selected color:");
sf::Text text2 = text;
text2.SetPosition(600, 50);
text2.SetString("Avaliable colors:");
sf::Text text3 = text;
text3.SetPosition(50, 350);
text3.SetString("Test area");
sf::FloatRect rect1(650, 100, 50, 50);
sf::Shape shape1 = sf::Shape::Rectangle(rect1, sf::Color::Red);
sf::FloatRect rect2(650, 150, 50, 50);
sf::Shape shape2 = sf::Shape::Rectangle(rect2, sf::Color::Green);
sf::FloatRect sel(50, 100, 50, 50);
sf::Shape selected = sf::Shape::Rectangle(sel, sf::Color::White);
sf::Color selectedColor = sf::Color::White;
sf::FloatRect test1(50, 400, 50, 50);
sf::FloatRect test2(50, 450, 50, 50);
sf::Shape s1 = sf::Shape::Rectangle(test1, selectedColor);
sf::Shape s2 = sf::Shape::Rectangle(test2, selectedColor);
while (App.IsOpened())
{
sf::Event event;
while (App.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
App.Close();
if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Keyboard::Escape)
App.Close();
}
if (sf::Mouse::IsButtonPressed(sf::Mouse::Left))
{
if (rect1.Contains((sf::Vector2f)sf::Mouse::GetPosition(App)))
{
selectedColor = sf::Color::Red;
}
else if (rect2.Contains((sf::Vector2f)sf::Mouse::GetPosition(App)))
{
selectedColor = sf::Color::Green;
}
if (test1.Contains((sf::Vector2f)sf::Mouse::GetPosition(App)))
{
s1.SetColor(selectedColor);
}
if (test2.Contains((sf::Vector2f)sf::Mouse::GetPosition(App)))
{
s2.SetColor(selectedColor);
}
}
selected.SetColor(selectedColor);
App.Clear(sf::Color::Black);
App.Draw(text);
App.Draw(text2);
App.Draw(text3);
App.Draw(selected);
App.Draw(shape1);
App.Draw(shape2);
App.Draw(s1);
App.Draw(s2);
App.Display();
}
return 0;
}
If I resize the window, everything is scaled accordingly, and I can't select any of the colors anymore. Is this how it should be ? Or is it a bug ?