What I want is for the global bounds to be the same size and shape as the circle. Currently the globalBounds is basically a rectangle. Current code literally just simulates the code of getGlobalBounds function.
#include <iostream>
#include <SFML/Graphics.hpp>
bool calculate(sf::Vector2f pos, sf::Vector2f mouse, int r)
{
std::cout<<pos.x - mouse.x<<" "<<pos.y - mouse.y <<std::endl;
if(pos.x - mouse.x >= 0 && pos.x - mouse.x <= r)
{
if(pos.y - mouse.y >= 0 && pos.y - mouse.y <= r)
{
return true;
}
else if(pos.y - mouse.y <= 0 && pos.y - mouse.y >= -r)
{
return true;
}
else
{
return false;
}
}
else if(pos.x - mouse.x <= 0 && pos.x - mouse.x >= -r)
{
if(pos.y - mouse.y <= 0 && pos.y - mouse.y >= -r)
{
return true;
}
else if(pos.y - mouse.y >= 0 && pos.y - mouse.y <= r)
{
return true;
}
else
{
return false;
}
}
else
{
return 0;
}
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");
sf::Event event;
sf::Vector2f mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));
sf::CircleShape circle;
circle.setRadius(150);
circle.setPosition(sf::Vector2f(400, 300));
circle.setFillColor(sf::Color::Blue);
circle.setOrigin(circle.getRadius(), circle.getRadius());
while(window.isOpen())
{
mouseCoords = window.mapPixelToCoords(sf::Vector2i(sf::Mouse::getPosition(window)));
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
window.close();
}
if(event.type == sf::Event::MouseMoved)
{
if(calculate(circle.getPosition(), mouseCoords, circle.getRadius()) == true)
{
circle.setFillColor(sf::Color::Red);
}
else
{
circle.setFillColor(sf::Color::Blue);
}
}
}
window.clear(sf::Color::White);
window.draw(circle);
window.display();
}
}