SFML community forums

Help => Graphics => Topic started by: Kevin47 on September 22, 2010, 04:29:23 pm

Title: Button
Post by: Kevin47 on September 22, 2010, 04:29:23 pm
Hello!
I'm trying to make graphical button (I read tutorials and I tested samples).

Here is my image:
(http://img245.imageshack.us/img245/8444/buttonhw.png)

Code example:

Quote
If you click left mouse button and mouse cursor X pos is 100-218 and Y pos is 100-161
{
do something
}



Can someone help? Thanks! :)
Title: Button
Post by: Lupinius on September 22, 2010, 05:56:00 pm
What exactly is the problem?
Title: Button
Post by: Kevin47 on September 22, 2010, 06:45:13 pm
Quote from: "Lupinius"
What exactly is the problem?


I don't know how to make this.
Title: Button
Post by: Finn on September 22, 2010, 06:57:23 pm
Code: [Select]

bool MouseOver(sf::Sprite &Sprite)//returns true if the mouse is over given sf::Sprite
{
float XPos = Sprite.GetPosition().x;//the x position
float YPos = Sprite.GetPosition().y;//the y position
float XSize = Sprite.GetSize().x;//the width
float YSize = Sprite.GetSize().y;//the height

if(MouseX >= XPos && MouseX <= XPos+XSize && MouseY >= YPos && MouseY <= YPos+YSize)
return true;

else
return false;
}