FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Algorithm-visualiser/button.cpp at main · ArthurJ01/Algorithm-visualiser · GitHub
ArthurJ01
/
Algorithm-visualiser
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Algorithm-visualiser
/
button.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (27 loc) · 1.2 KB
Breadcrumbs
Algorithm-visualiser
/
button.cpp
Copy path
File metadata and controls
34 lines (27 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
SFML/Graphics.hpp
>
#
include
"
button.hpp
"
extern
const
sf::Font font;
Button::Button
(
const
sf::Vector2f &size,
const
sf::Vector2f &position,
const
std::string &s)
: button(size), text(font)
{
button.
setPosition
(position);
button.
setFillColor
({
45
,
50
,
70
});
text.
setString
(s);
text.
setCharacterSize
(
24
);
text.
setFillColor
({
240
,
240
,
240
});
float
position_x = button.
getPosition
().
x
+ (button.
getSize
().
x
/
2
);
float
position_y = button.
getPosition
().
y
+ (button.
getSize
().
y
/
2
);
text.
setOrigin
({text.
getGlobalBounds
().
getCenter
()});
text.
setPosition
({position_x, position_y});
}
//
changes colour of rectangle while mouse inside button, returns wether it has been clicked or not
bool
Button::clicked
(sf::Vector2f point){
bool
inside = button.
getGlobalBounds
().
contains
(point);
button.
setFillColor
(inside ?
sf::Color
(
0
,
153
,
255
) :
sf::Color
(
45
,
50
,
70
));
text.
setFillColor
(inside ?
sf::Color
(
255
,
255
,
255
) :
sf::Color
(
240
,
240
,
240
));
return
inside &&
sf::Mouse::isButtonPressed
(sf::Mouse::Button::Left);
}
void
Button::draw
(sf::RenderTarget& target, sf::RenderStates states)
const
{
target.
draw
(button, states);
target.
draw
(text, states);
}
Back
|
FazBrowse Home
|
New Git URL