-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckbox.cpp
More file actions
90 lines (70 loc) · 1.64 KB
/
Copy pathcheckbox.cpp
File metadata and controls
90 lines (70 loc) · 1.64 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "checkbox.h"
#include "application.h"
#include "text_renderer.h"
CheckBox::CheckBox(Widget *parent, CheckPositioner positioner, CheckOnClick onclick) : Widget(parent) {
POSITIONER = positioner;
ONCLICK = onclick;
hovered = false;
bgcolor = App::theme.darker_background_color;
id = icu::UnicodeString::fromUTF8("CheckBox");
}
void CheckBox::position(int x, int y, int width, int height) {
t_w = width;
t_h = height;
t_x = x;
t_y = y;
POSITIONER(this, t_x, t_y, t_w, t_h);
}
bool CheckBox::on_mouse_button_event(int button, int action, int mods) {
if (!is_visible) {
return false;
}
if (!hovered) {
return false;
}
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
is_checked = !is_checked;
if (ONCLICK) {
ONCLICK(this);
}
return true;
}
return false;
}
bool CheckBox::on_mouse_move_event() {
if (!is_visible) {
return false;
}
int mx = App::mouseX;
int my = App::mouseY;
if (t_x <= mx && t_x+t_w >= mx && t_y <= my && t_y+t_h >= my) {
hovered = true;
}else{
hovered = false;
}
Widget::on_mouse_move_event();
return false;
}
void CheckBox::render() {
if (!is_visible) {
return;
}
int p = 4;
int radius = App::text_padding;
if (rounded) {
App::DrawRoundedRect(t_x, t_y, t_w, t_h, radius, bgcolor);
}else{
App::DrawRect(t_x, t_y, t_w, t_h, bgcolor);
}
if (is_checked) {
App::DrawRoundedRect(t_x+p, t_y+p, t_w-2*p, t_h-2*p, radius, App::theme.main_text_color);
}
Widget::render();
if (border) {
if (rounded) {
App::DrawRoundBorder(t_x, t_y, t_w, t_h, App::theme.border, 5, radius);
}else{
App::DrawBorder(t_x, t_y, t_w, t_h, App::theme.border);
}
}
}