-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractButton.cpp
45 lines (36 loc) · 1.1 KB
/
AbstractButton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "AbstractButton.h"
AbstractButton::AbstractButton(std::string texte, sf::Vector2f pos, sf::RenderWindow *parent) : marge_(20, 20), parent_(parent), colorDefaut_(sf::Color(250, 150, 100))
{
font_.loadFromFile("Font/LiberationSans-Regular.ttf");
texte_.setString(texte);
texte_.setFont(font_);
texte_.setColor(sf::Color::Red);
zone_.setPosition(pos);
zone_.setOutlineThickness(5);
zone_.setOutlineColor(colorDefaut_);
autosize();
}
void AbstractButton::setParent(sf::RenderWindow* parent)
{
parent_ = parent;
}
void AbstractButton::setPosition(sf::Vector2f pos)
{
zone_.setPosition(pos);
}
void AbstractButton::autosize()
{
sf::FloatRect rect = texte_.getLocalBounds();
texte_.setPosition(sf::Vector2f(zone_.getPosition().x + marge_.x -rect.left, zone_.getPosition().y + marge_.y -rect.top));
zone_.setSize(sf::Vector2f(rect.width + 2*marge_.x, rect.height + 2*marge_.y));
zone_.setFillColor(sf::Color::Blue);
}
sf::Vector2f AbstractButton::getSize() const
{
return zone_.getSize();
}
void AbstractButton::afficher() const
{
parent_->draw(zone_);
parent_->draw(texte_);
}