-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontextmenu.cpp
More file actions
114 lines (89 loc) · 2.7 KB
/
Copy pathcontextmenu.cpp
File metadata and controls
114 lines (89 loc) · 2.7 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
#include "contextmenu.h"
#include "application.h"
ContextMenu::ContextMenu(Widget* parent) : Widget(parent) {
id = icu::UnicodeString::fromUTF8("contextmenu");
}
void ContextMenu::render() {
if (!is_visible || !is_visible_2 || !is_visible_3) {
return;
}
App::DrawRoundedRect(t_x, t_y, t_w, t_h, App::text_padding+sqrt(App::text_padding), App::theme.extras_background_color, true);
Widget::render();
int yc = t_y+App::text_padding+App::border_width;
for (int bi = 0; bi < buttons.size(); bi++) {
Button* b = buttons[bi];
if (b) {
App::runWithSKIZ(b->t_x, b->t_y, b->t_w, b->t_h, [&](){
b->render();
});
yc = b->t_h+b->t_y+App::text_padding;
}else{
App::DrawRect(t_x+App::text_padding+App::border_width, yc, maxwidth, App::border_width*2, App::theme.main_text_color);
yc += App::text_padding+App::border_width*2;
}
}
}
void ContextMenu::position(int x, int y, int width, int height) {
if (!is_visible || !is_visible_2 || !is_visible_3) {
return;
}
t_x = x_loc;
t_y = y_loc;
maxwidth = 0;
Widget::position(t_x, t_y, t_w, t_h);
int bx = t_x+App::text_padding+App::border_width;
int by = t_y+App::text_padding+App::border_width;
for (int bi = 0; bi < buttons.size(); bi++) {
Button* b = buttons[bi];
if (!b) {
by += App::border_width*2+App::text_padding;
continue;
}
b->t_x = bx;
b->t_y = by;
b->t_w = maxwidth;
by += b->t_h+App::text_padding;
// hate to do this a second time but we need to because button isn't sized until it is. So.
if (App::mouseX >= b->t_x && App::mouseX <= b->t_x+b->t_w && App::mouseY >= b->t_y && App::mouseY <= b->t_y+b->t_h) {
App::expectedCursorType = 3;
}
}
t_w = maxwidth+App::text_padding*2+App::border_width*2;
t_h = (App::border_width+by)-t_y;
if (App::expectedCursorType == -1 && cursor_in_this) {
App::expectedCursorType = 0;
}
}
void ContextMenu::addToMenu(icu::UnicodeString name, Button::OnClick onclick) {
Button* b = new Button(this, name, [&](Widget *btn, int x, int y, int av_width, int av_height, int w, int h) {
maxwidth = std::max(maxwidth, w);
}, onclick);
b->border = true;
b->rounded = true;
b->alignLeft = true;
b->isContext = true;
b->background_color = App::theme.main_text_color;
buttons.push_back(b);
}
void ContextMenu::addSeparaterToMenu() {
buttons.push_back(nullptr);
}
void ContextMenu::clearMenu() {
for (Button* b : buttons) {
if (!b) {
continue;
}
App::deleteWidget(b);
}
buttons.clear();
}
bool ContextMenu::on_mouse_button_event(int button, int action, int mods) {
if (!is_visible || !is_visible_2 || !is_visible_3) {
return false;
}
if (!cursor_in_this) {
return false;
}
Widget::on_mouse_button_event(button, action, mods);
return true;
}