-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
huge refactoring add Button class
- Loading branch information
David Arutiunian
committed
Jan 4, 2018
1 parent
56efbc1
commit 59a75ff
Showing
19 changed files
with
304 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "Button.h" | ||
|
||
Button::Button(ButtonOptions &buttonOptions) | ||
{ | ||
m_shape.setSize(buttonOptions.size); | ||
m_shape.setPosition(buttonOptions.position); | ||
m_shape.setOrigin(buttonOptions.size.x / 2, buttonOptions.size.y / 2); | ||
m_shape.setFillColor(buttonOptions.fillColor); | ||
m_shape.setOutlineColor(buttonOptions.outlineColor); | ||
m_shape.setOutlineThickness(buttonOptions.outlineThickness); | ||
|
||
m_p_font = std::make_shared<sf::Font>(sf::Font(buttonOptions.font)); | ||
m_text.setFont(*m_p_font); | ||
m_text.setString(buttonOptions.text); | ||
m_text.setCharacterSize(buttonOptions.textSize); | ||
m_text.setFillColor(buttonOptions.textColor); | ||
const sf::FloatRect &bounds = m_text.getLocalBounds(); | ||
const sf::Vector2f origin = {bounds.left + bounds.width / 2, bounds.top + bounds.height / 2}; | ||
m_text.setOrigin(origin); | ||
m_text.setPosition(buttonOptions.position); | ||
} | ||
|
||
void Button::draw(sf::RenderTarget &target, sf::RenderStates states) const | ||
{ | ||
target.draw(m_shape, states); | ||
target.draw(m_text, states); | ||
} | ||
|
||
const sf::RectangleShape &Button::getShape() const | ||
{ | ||
return m_shape; | ||
} | ||
|
||
Button::Button() = default; |
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,37 @@ | ||
#ifndef DOODLE_JUMP_BUTTON_H | ||
#define DOODLE_JUMP_BUTTON_H | ||
|
||
#include <SFML/Graphics.hpp> | ||
#include <memory> | ||
|
||
struct ButtonOptions | ||
{ | ||
sf::Vector2f size; | ||
sf::Vector2f position; | ||
std::string text; | ||
unsigned textSize; | ||
sf::Color fillColor; | ||
sf::Color outlineColor; | ||
unsigned outlineThickness; | ||
sf::Color textColor; | ||
sf::Font font; | ||
}; | ||
|
||
class Button : public sf::Drawable | ||
{ | ||
public: | ||
Button(); | ||
|
||
explicit Button(ButtonOptions &buttonOptions); | ||
|
||
const sf::RectangleShape &getShape() const; | ||
|
||
private: | ||
void draw(sf::RenderTarget &target, sf::RenderStates states) const override; | ||
|
||
sf::RectangleShape m_shape; | ||
sf::Text m_text; | ||
std::shared_ptr<sf::Font> m_p_font; | ||
}; | ||
|
||
#endif //DOODLE_JUMP_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
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
Oops, something went wrong.