-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOption.cpp
More file actions
70 lines (55 loc) · 1.31 KB
/
Option.cpp
File metadata and controls
70 lines (55 loc) · 1.31 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Option.h"
#include "FontData.h"
#include "Config.h"
#include <SFML/Graphics/RenderTarget.hpp>
Option::Option(
const std::string &string,
const sf::Vector2f &position,
unsigned int fontSize)
:
Shakable(0.25f, 0.0f),
Collidable(position, sf::Vector2f()),
sf::Drawable(),
text_(string, FontData::getInstance().getFont(), fontSize),
isHovered_(false)
{
text_.setFillColor(sf::Color(236, 236, 236));
text_.setScale(
sf::Vector2f(
Config::Font::scale,
Config::Font::scale));
const sf::FloatRect textLocalBounds = text_.getLocalBounds();
text_.setOrigin(
textLocalBounds.left,
textLocalBounds.top);
const sf::FloatRect textGlobalBounds = text_.getGlobalBounds();
size_.x = textGlobalBounds.width;
size_.y = textGlobalBounds.height;
position_.y -= size_.y * 0.5f;
text_.setPosition(position_);
}
void Option::update(float deltaTime)
{
Shakable::update(deltaTime);
text_.setPosition(position_ + offset_);
}
void Option::updateOnMouseMove(const sf::Vector2f &worldMousePosition)
{
isHovered_ = this->contains(worldMousePosition);
}
void Option::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(text_, states);
}
void Option::startShaking()
{
trauma_ = 1.0f;
}
void Option::stopShaking()
{
trauma_ = 0.0f;
}
bool Option::isHovered() const
{
return isHovered_;
}