BeatTheStreet/src/button.cpp
//Boolean function that returns true when the mouse is released over th button
Boolean function that returns true when the mouse is released over th button
Boolean function that returns true when the mouse is released over th button
bool button::isclicked(sf::Event &event)
{
	sf::FloatRect frButtonBounds = sButtonSprite.getGlobalBounds();
	sf::Vector2f v2fClickLocation(event.mouseButton.x, event.mouseButton.y);
	sf::Color darker(100, 100, 100, 255);
	sf::Color normal(255, 255, 255, 255);
	if (event.type == sf::Event::MouseButtonPressed)
	{
		if (event.mouseButton.button == sf::Mouse::Left)
		{
			if (frButtonBounds.contains(v2fClickLocation))
			{
				sButtonSprite.setColor(darker);
			}
		}
	}
	if (event.type == sf::Event::MouseButtonReleased)
	{
		if (event.mouseButton.button == sf::Mouse::Left)
		{
			sButtonSprite.setColor(normal);
			if (frButtonBounds.contains(v2fClickLocation)) 
			{
				return true;
			}
			else return false;
		}
		else return false;
	}
	return false;
}
bool button :: isclicked ( sf :: Event & event ) { sf :: FloatRect frButtonBounds = sButtonSprite . getGlobalBounds ( ) ; sf :: Vector2f v2fClickLocation ( event . mouseButton . x , event . mouseButton . y ) ; sf :: Color darker ( 100 , 100 , 100 , 255 ) ; sf :: Color normal ( 255 , 255 , 255 , 255 ) ; if ( event . type == sf :: Event :: MouseButtonPressed ) { if ( event . mouseButton . button == sf :: Mouse :: Left ) { if ( frButtonBounds . contains ( v2fClickLocation ) ) { sButtonSprite . setColor ( darker ) ; } } } if ( event . type == sf :: Event :: MouseButtonReleased ) { if ( event . mouseButton . button == sf :: Mouse :: Left ) { sButtonSprite . setColor ( normal ) ; if ( frButtonBounds . contains ( v2fClickLocation ) ) { return true ; } else return false ; } else return false ; } return false ; }
Boolean function that returns true when the mouse is released over th button
Boolean function that returns true when the mouse is released over th button
//floatrect of button global bounds initialized, used when determining if it has been clicked. //vector that holds x and y position of the click location //Darker and normal colors are used to darken the sprite when the button is depressed. //If a mouse button is pressed //If the mouse button is left //If the click location is within the bounds of the button //set the button color to darker //If the mouse button is released  //If the mouse button is left //Set the color back to normal //If the click location is within the bounds of the button //Return true