-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel.c
More file actions
128 lines (118 loc) · 3.08 KB
/
Copy pathpanel.c
File metadata and controls
128 lines (118 loc) · 3.08 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
#include "common.h"
static const char *g_ctrl_keys[8] = {
"Space", "R", "1 / 2 / 4", "Click view",
"Pan. button", "Speed", "Size", "Scroll"
};
static const char *g_ctrl_descs[8] = {
"Pause / Resume", "Shuffle & restart", "Split views", "Focus view",
"Toggle panel", "Steps per frame", "Array length", "Scroll algo list"
};
static void draw_algo_btn(t_app_state *state, int a, int y)
{
if (UiButton(
(Rectangle){8, y, PANEL_WIDTH - 24, 32},
g_algorithms[a].name,
state->views[state->focused_view].algo_idx == a))
{
state->views[state->focused_view].algo_idx = a;
reset_view(state, &state->views[state->focused_view]);
}
}
void draw_algo_list(t_app_state *state, int arraysize_y)
{
int lc_h;
int lv_h;
int ms;
int y;
int a;
lc_h = 24 + g_algo_count * 38;
lv_h = arraysize_y - TOOLBAR_HEIGHT;
ms = lc_h - lv_h;
if (ms < 0)
ms = 0;
if (state->panel_scroll > ms)
state->panel_scroll = ms;
if (state->panel_scroll < 0)
state->panel_scroll = 0;
BeginScissorMode(0, TOOLBAR_HEIGHT, PANEL_WIDTH, lv_h);
y = TOOLBAR_HEIGHT + 14 - state->panel_scroll;
DrawTxt("ALGORITHMS", 14, y, 11, COL_MUTED);
y += 24;
a = 0;
while (a < g_algo_count)
{
draw_algo_btn(state, a, y);
y += 38;
a++;
}
EndScissorMode();
}
void draw_scrollbar(t_app_state *state, int vis_h, int cont_h, int ay)
{
int sb_x;
int sb_track_y;
int sb_track_h;
int thumb_h;
int thumb_y;
if (cont_h - vis_h <= 0)
return ;
sb_x = PANEL_WIDTH - 8;
sb_track_y = TOOLBAR_HEIGHT + 6;
sb_track_h = ay - TOOLBAR_HEIGHT - 12;
DrawRectangleRounded(
(Rectangle){(float)sb_x, (float)sb_track_y, 4.0f, (float)sb_track_h},
1.0f, 4, COL_FAINT);
thumb_h = (int)((float)vis_h / (float)cont_h * sb_track_h);
if (thumb_h < 24)
thumb_h = 24;
thumb_y = sb_track_y + (int)((float)state->panel_scroll
/ (float)(cont_h - vis_h) * (sb_track_h - thumb_h));
DrawRectangleRounded(
(Rectangle){(float)sb_x, (float)thumb_y, 4.0f, (float)thumb_h},
1.0f, 4, COL_MUTED);
}
void draw_controls(int controls_y)
{
int cy;
int h;
int kw;
DrawLineEx(
(Vector2){0, controls_y},
(Vector2){PANEL_WIDTH, controls_y},
1.5f, COL_BORDER);
cy = controls_y + 14;
DrawTxt("CONTROLS", 14, cy, 11, COL_MUTED);
cy += 22;
h = 0;
while (h < 8)
{
kw = MeasureTxt(g_ctrl_keys[h], 14);
DrawTxt(g_ctrl_keys[h], 14, cy, 14, COL_PRIMARY);
DrawTxt(g_ctrl_descs[h], 14 + kw + 8, cy, 14, COL_MUTED);
cy += 21;
h++;
}
}
void draw_panel(t_app_state *state)
{
int arraysize_y;
int lc_h;
int prev_size;
if (!state->show_panel)
return ;
DrawRectangle(0, TOOLBAR_HEIGHT, PANEL_WIDTH,
SCREEN_HEIGHT - TOOLBAR_HEIGHT, COL_SURFACE);
DrawLineEx(
(Vector2){PANEL_WIDTH, TOOLBAR_HEIGHT},
(Vector2){PANEL_WIDTH, SCREEN_HEIGHT},
1.5f, COL_BORDER);
arraysize_y = SCREEN_HEIGHT - PANEL_FIXED_H;
lc_h = 24 + g_algo_count * 38;
draw_algo_list(state, arraysize_y);
draw_scrollbar(state, arraysize_y - TOOLBAR_HEIGHT, lc_h, arraysize_y);
prev_size = state->global_size;
draw_panel_info(state, arraysize_y, arraysize_y + PANEL_ARRAYSIZE_H);
if (state->global_size != prev_size)
reset_all(state);
draw_controls(SCREEN_HEIGHT - PANEL_CONTROLS_H);
}