-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.cpp
More file actions
153 lines (129 loc) · 3.75 KB
/
Copy pathbutton.cpp
File metadata and controls
153 lines (129 loc) · 3.75 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "button.h"
#include "application.h"
#include "text_renderer.h"
Button::Button(Widget *parent, icu::UnicodeString text, Positioner positioner, OnClick onclick) : Widget(parent) {
BUTTON_LABEL = text;
POSITIONER = positioner;
ONCLICK = onclick;
transparent = false;
window_button = false;
rounded = false;
background_color = App::theme.darker_background_color;
id = icu::UnicodeString::fromUTF8("Button - ") + text;
}
void Button::position(int x, int y, int width, int height) {
if (window_button) {
t_w = TextRenderer::get_text_height() * 2.5;
t_h = TextRenderer::get_text_height() + App::text_padding*2;
}else{
t_w = TextRenderer::get_text_width(BUTTON_LABEL.length()) + App::text_padding*2;
t_h = TextRenderer::get_text_height() + App::text_padding*2;
}
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) {
App::expectedCursorType = 3;
}
POSITIONER(this, x, y, width, height, t_w, t_h);
}
bool Button::on_mouse_button_event(int button, int action, int mods) {
if (!parent || !cursor_in_this || !is_visible) {
return false;
}
if (execute_on_down) {
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
ONCLICK(this);
return true;
}
}else {
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE) {
ONCLICK(this);
return true;
}
}
return false;
}
void Button::render() {
if (!is_visible) {
return;
}
int mx = App::mouseX;
int my = App::mouseY;
bool hovered = t_x <= mx && t_x+t_w >= mx && t_y <= my && t_y+t_h >= my;
Color* textColor = App::theme.main_text_color;
if (window_button) {
if (hovered) {
if (rounded) {
App::DrawRoundedRect(t_x, t_y, t_w, t_h, App::text_padding, background_color);
if (border){
App::DrawRoundBorder(t_x, t_y, t_w, t_h, App::theme.border, 5, App::text_padding);
}
}else{
App::DrawRect(t_x, t_y, t_w, t_h, background_color);
if (border){
App::DrawBorder(t_x, t_y, t_w, t_h, App::theme.border);
}
}
}
}else if (isContext){
if (hovered) {
textColor = App::theme.darker_background_color;
if (rounded) {
App::DrawRoundedRect(t_x, t_y, t_w, t_h, App::text_padding, background_color, border);
if (border) {
App::DrawRoundBorder(t_x, t_y, t_w, t_h, App::theme.border, 5, App::text_padding);
}
}else{
App::DrawRect(t_x, t_y, t_w, t_h, background_color);
if (border) {
App::DrawBorder(t_x, t_y, t_w, t_h, App::theme.border);
}
}
}
}else{
Color* fillcolor = background_color;
if (hovered) {
fillcolor = App::theme.hover_background_color;
}
if (rounded) {
App::DrawRoundedRect(t_x, t_y, t_w, t_h, App::text_padding, fillcolor, border);
if (border) {
App::DrawRoundBorder(t_x, t_y, t_w, t_h, App::theme.border, 5, App::text_padding);
}
}else{
App::DrawRect(t_x, t_y, t_w, t_h, fillcolor);
if (border) {
App::DrawBorder(t_x, t_y, t_w, t_h, App::theme.border);
}
}
}
if (text_special == 0) {
int x;
if (alignLeft) {
x = t_x+App::text_padding;
}else{
x = t_x+t_w/2-TextRenderer::get_text_width(BUTTON_LABEL.length())/2;
}
int y = t_y+t_h/2-TextRenderer::get_text_height()/2;
TextRenderer::draw_text(x, y, BUTTON_LABEL, textColor);
}else {
int wdth = TextRenderer::get_text_height()*.6;
int x;
if (alignLeft) {
x = t_x+App::text_padding;
}else{
x = t_x+t_w/2-wdth/2;
}
int y = t_y+t_h/2-wdth/2;
if (text_special == 1) {
App::DrawX(x, y, wdth, wdth, 2, textColor);
}else if (text_special == 2) {
App::DrawPlus(x, y, wdth, wdth, 2, textColor);
}else if (text_special == 3) {
App::DrawMinus(x, y, wdth, wdth, 2, textColor);
}else if (text_special == 4) {
App::DrawSquare(x, y, wdth, wdth, 2, textColor);
}
}
Widget::render();
}