-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.cpp
More file actions
48 lines (38 loc) · 968 Bytes
/
Copy pathButton.cpp
File metadata and controls
48 lines (38 loc) · 968 Bytes
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
45
46
47
48
#include <SFML/Graphics.hpp>
#include "Button.h"
using namespace sfSnake;
const float Button::Radius = 200.f;
Button::Button(sf::Texture &texture, float x, float y) : position_{x, y}
{
shape_.setTexture(texture);
shape_.setOrigin(texture.getSize().x / 2, texture.getSize().y / 2);
shape_.setPosition(x, y);
shape_.setScale(Button::Radius / texture.getSize().x, Button::Radius / texture.getSize().y);
}
void Button::Highlight()
{
shape_.setColor(sf::Color(255, 254, 145));
}
void Button::deHighlight()
{
shape_.setColor(sf::Color::White);
}
void Button::setPosition(sf::Vector2f &position)
{
shape_.setPosition(position);
}
sf::Vector2f Button::getPosition() const
{
return position_;
}
sf::FloatRect Button::getBound() const
{
return shape_.getGlobalBounds();
}
Button::Button() : position_{0, 0}
{
}
void Button::render(sf::RenderWindow &window)
{
window.draw(shape_);
}