-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added button class, unicode texts and comment after end of game
- Loading branch information
Showing
6 changed files
with
180 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef BUTTON_H | ||
#define BUTTON_H | ||
#include <SFML/Graphics.hpp> | ||
#include "ResourceManager.h" | ||
|
||
class Button : public sf::Drawable{ | ||
sf::RectangleShape shape; | ||
sf::Text text; | ||
void fixTextAlignment(){ | ||
text.setOrigin(text.getLocalBounds().width/2.0f,text.getLocalBounds().height/2.0f); | ||
sf::Vector2f position = shape.getPosition(); | ||
text.setPosition(sf::Vector2f(position.x + shape.getLocalBounds().width/2.0f,position.y + shape.getLocalBounds().height/2.0f)); | ||
} | ||
public: | ||
Button(sf::IntRect rect) { | ||
setRect(rect); | ||
text.setFont(FontManager::instance().get("arial")); | ||
text.setCharacterSize(32); | ||
text.setColor(sf::Color(190,190,190)); | ||
} | ||
|
||
void setPosition(sf::Vector2f position){ | ||
shape.setPosition(position); | ||
fixTextAlignment(); | ||
} | ||
sf::Vector2f getPosition() const{ | ||
return shape.getPosition(); | ||
} | ||
|
||
void setSize(sf::Vector2f size){ | ||
shape.setSize((sf::Vector2f)size); | ||
} | ||
sf::Vector2f getSize() const{ | ||
return shape.getSize(); | ||
} | ||
|
||
void setRect(sf::IntRect rect){ | ||
setPosition(sf::Vector2f(rect.left,rect.top)); | ||
setSize(sf::Vector2f(rect.width,rect.height)); | ||
} | ||
|
||
void setBackgroundColor(sf::Color color){ | ||
shape.setFillColor(color); | ||
} | ||
void setText(sf::String str){ | ||
text.setString(str); | ||
fixTextAlignment(); | ||
|
||
} | ||
virtual void draw(sf::RenderTarget& target,sf::RenderStates states) const override{ | ||
target.draw(shape,states); | ||
target.draw(text,states); | ||
} | ||
|
||
bool isPointInside(sf::Vector2i point){ | ||
return (point.x >= shape.getPosition().x && point.y >= shape.getPosition().y && | ||
point.x <= shape.getPosition().x + shape.getSize().x && point.y <= shape.getPosition().y + shape.getSize().y); | ||
} | ||
|
||
}; | ||
|
||
#endif // BUTTON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters