-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradio.c
More file actions
180 lines (152 loc) · 3.3 KB
/
Copy pathradio.c
File metadata and controls
180 lines (152 loc) · 3.3 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "radio.h"
void radio_init(
UIRadio *radio,
const char *text,
bool selected)
{
radio->text = text;
radio->selected = selected;
}
void radio_layout(
UIRadio *radio,
UIContext *ui,
float x,
float y)
{
radio->rect =
ui_rect(
ui,
x,
y,
220,
36
);
}
bool radio_event(
UIRadio *radio,
SDL_Event *event)
{
if (
event->type ==
SDL_MOUSEBUTTONDOWN &&
event->button.button ==
SDL_BUTTON_LEFT
) {
if (
ui_point_in_rect(
event->button.x,
event->button.y,
radio->rect
)
) {
radio->selected = !radio->selected;
return true;
}
}
return false;
}
void radio_draw(
UIRadio *radio,
UIContext *ui,
SDL_Renderer *renderer,
TTF_Font *font)
{
int outerRadius =
(int)roundf(
10.0f * ui->scale);
int cx =
radio->rect.x + outerRadius + 2;
int cy =
radio->rect.y + radio->rect.h / 2;
/*
Shadow.
*/
ui_fill_circle(
renderer,
cx, cy + 2,
outerRadius + 1,
(UIColor){15, 20, 40, 20});
/*
Outer glass circle.
*/
ui_fill_circle(
renderer,
cx, cy,
outerRadius,
(UIColor){240, 245, 252, 195});
/*
Bright ring.
*/
ui_fill_circle(
renderer,
cx, cy,
outerRadius - 1,
(UIColor){255, 255, 255, 110});
/*
Top highlight arc (simulated).
*/
if (outerRadius > 4) {
int hlR = outerRadius - 2;
int hlY = cy - (int)(hlR * 0.25f);
SDL_SetRenderDrawBlendMode(
renderer,
SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(
renderer,
255, 255, 255, 40);
for (int y = -hlR; y <= 0; ++y) {
float fy = (float)y;
float val =
(float)(hlR * hlR) - fy * fy;
if (val <= 0.0f) continue;
int hw =
(int)floorf(sqrtf(val));
SDL_RenderDrawLine(
renderer,
cx - hw, hlY + y,
cx + hw, hlY + y);
}
}
/*
Selected indicator.
*/
if (radio->selected) {
int innerRadius =
(int)roundf(
5.0f * ui->scale);
/* Glow */
ui_fill_circle(
renderer,
cx, cy,
innerRadius + 3,
(UIColor){
55, 110, 240, 40});
/* Core */
ui_fill_circle(
renderer,
cx, cy,
innerRadius,
(UIColor){
50, 100, 235, 255});
/* Bright center */
ui_fill_circle(
renderer,
cx, cy,
innerRadius > 2
? innerRadius - 2 : 1,
(UIColor){
100, 150, 255, 180});
}
ui_text(
renderer,
font,
radio->text,
radio->rect.x +
(int)roundf(28.0f * ui->scale),
radio->rect.y +
(int)roundf(5.0f * ui->scale),
ui_theme(ui->dark,
(UIColor){25, 35, 55, 255},
(UIColor){195, 205, 225, 255}
));
}