This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClickText.cpp
86 lines (69 loc) · 1.76 KB
/
ClickText.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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "ClickText.h"
ClickText::ClickText(void)
{
}
ClickText::ClickText(sf::IntRect position, std::string textString, int Size, sf::RenderWindow *renderWindow, sf::Font *renderFont)
{
Text = textString;
Position = position;
window = renderWindow;
font = renderFont;
text.setFont(*font);
text.setString(textString);
text.setPosition(position.left, position.top);
text.setCharacterSize(Size);
text.setColor(sf::Color::White);
Selected = false;
}
ClickText::ClickText(sf::IntRect position, std::string textString, sf::RenderWindow *renderWindow, sf::Font *renderFont)
{
Text = textString;
Position = position;
window = renderWindow;
font = renderFont;
text.setFont(*font);
text.setString(textString);
text.setPosition(position.left, position.top);
text.setCharacterSize(position.height);
text.setColor(sf::Color::White);
Selected = false;
}
ClickText::~ClickText(void)
{
}
void ClickText::SetColor(sf::Color normalColor, sf::Color highlightColor)
{
NormalColor = normalColor;
HighlightColor = highlightColor;
text.setColor(normalColor);
}
bool ClickText::Clicked()
{
if (Selected)
{
text.setColor(HighlightColor);
return false;
}
sf::Vector2i mousePos = sf::Mouse::getPosition(*window);
sf::IntRect mouseRect(mousePos.x, mousePos.y, 1, 1);
sf::IntRect textRect(Position.left, Position.top, Position.width, Position.height);
if (textRect.intersects(mouseRect))
{
text.setColor(HighlightColor);
return (sf::Mouse::isButtonPressed(sf::Mouse::Left));
}
else
{
text.setColor(NormalColor);
return false;
}
}
void ClickText::Draw()
{
window->draw(text);
}
void ClickText::SetString(std::string textString)
{
Text = textString;
text.setString(textString);
}