-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
50 lines (42 loc) · 1.18 KB
/
Copy pathbutton.cpp
File metadata and controls
50 lines (42 loc) · 1.18 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
#include "button.h"
void const Button::draw()
{
if (highlighted) { draw_highlighted(); }
graphics::Brush br;
br.outline_opacity = 0.f;
br.fill_color[0] = .2f;
br.fill_color[1] = .2f;
br.fill_color[2] = .2f;
br.fill_secondary_color[0] = .3f;
br.fill_secondary_color[1] = .3f;
br.fill_secondary_color[2] = .3f;
br.gradient = true;
br.gradient_dir_u = 1.f;
br.gradient_dir_v = 1.f;
graphics::drawRect(pos_x, pos_y, width, height, br);
br.gradient = false;
br.fill_color[0] = 1.0f;
br.fill_color[1] = 1.0f;
br.fill_color[2] = 0.0f;
graphics::setFont(std::string(ASSET_PATH) + "ARCADE.TTF");
graphics::drawText((pos_x - width/2) + offset, ( pos_y + height/2) , text_size, text, br);
}
void Button::draw_highlighted()
{
graphics::Brush br;
br.fill_color[0] = 1.0f;
br.fill_color[1] = 1.0f;
br.fill_color[2] = 0.0f;
br.fill_opacity = 0.8f;
br.outline_opacity = 0.0f;
graphics::drawRect(pos_x, pos_y, width + highlight_border, height + highlight_border, br);
}
bool Button::contains(float x, float y)
{
bool a = x > pos_x - width / 2;
bool b = x < pos_x + width / 2;
bool c = y > pos_y - height / 2;
bool d = y < pos_y + height / 2;
return (a && b && c && d);
}
Button::~Button(){}