-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu.hc
414 lines (332 loc) · 9.49 KB
/
menu.hc
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/*======================================================================*/
/*= CHANGES AND UPDATES =*/
/*======================================================================*/
/*= date person file subject =*/
/*=--------------------------------------------------------------------=*/
/*= =*/
/*= 180193 hua menu.hc only operate if button1press =*/
/*= =*/
/*= 050293 hua menu.hc added enable =*/
/*= =*/
/*======================================================================*/
#include "menu.h"
/*----------------------------------------------------------------------*/
/* CLASS menu (static initializations) */
/*----------------------------------------------------------------------*/
bool menu::manager_init = false;
bool menu::group_enabled [max_menu_groups];
/*----------------------------------------------------------------------*/
/* CLASS menu (funktions) */
/*----------------------------------------------------------------------*/
menu::menu ()
{
}
menu::menu (const char w_name [],
int w_x,
int w_y,
const char w_cmds [],
int w_mode,
int menu_group)
{init_manager;
init_status;
load_colors;
calc_dim;
tick ();
. init_manager
if (! manager_init)
init_group_manager.
. init_group_manager
{manager_init = true;
for (int i = 0; i < max_menu_groups; i++)
group_enabled [i] = false;
group_enabled [std_menu_group] = true;
}.
. load_colors
{c_border_light = win_default_c ("menu_border_light");
c_background = win_default_c ("menu_background");
c_border_dark = win_default_c ("menu_border_dark");
c_foreground = win_default_c ("menu_foreground");
}.
. init_status
{group = menu_group;
x = w_x;
y = w_y;
is_open = false;
mode = w_mode;
is_press = false;
last_mouse_button = nobutton;
pressed_button = no_menu_request;
strcpy (name, w_name);
}.
. calc_dim
if (is_text_menu)
calc_text_dim
else calc_icon_dim.
. is_text_menu
(w_cmds [0] != '$' && w_cmds [0] != '/').
. calc_icon_dim
{int icon_dx;
int icon_dy;
calc_button_dir;
scan_buttons;
get_icon_size;
icon_mode = true;
button_dx = icon_dx + 2 * border_dx;
button_dy = icon_dy + 2 * border_dy;
dy = button_dy * num_buttons;
dx = button_dx;
}.
. calc_button_dir
{if (w_cmds [0] == '$')
strcpy (button_dir, "");
else sprintf (button_dir, "%s/", win_default_s ("button_dir"));
}.
. get_icon_size
{char name [128];
sprintf (name, "%s%s", button_dir, cmds [0]);
bitmap_size (name, icon_dx, icon_dy);
}.
. calc_text_dim
{scan_buttons;
dy = button_dy * num_buttons;
dx = button_dx;
icon_mode = false;
}.
. scan_buttons
{int p = 0;
char cmd [128];
XFontStruct *font_info;
Display *display;
open_font_info;
button_dx = 0;
num_buttons = 0;
while (get_cmd (w_cmds, p, cmd))
handle_button;
close_font_info;
}.
. open_font_info
{char name [128];
strcpy (name, getenv ("DISPLAY"));
display = XOpenDisplay (name);
font_info = XLoadQueryFont (display, men_font);
}.
. close_font_info
{XFreeFont (display, font_info);
XCloseDisplay (display);
}.
. handle_button
{calc_tdx_tdy;
strcpy (cmds [num_buttons], cmd);
is_pressed [num_buttons] = false;
button_dy = act_tdy + 2 * border_dy * 2;
button_dx = i_max (button_dx, act_tdx + 2 * border_dx + 10);
num_buttons++;
}.
. calc_tdx_tdy
{act_tdx = XTextWidth (font_info, cmd, strlen (cmd));
act_tdy = font_info->max_bounds.width;
}.
. act_tdx tdx [num_buttons].
. act_tdy tdy [num_buttons].
}
menu::~menu ()
{if (is_open)
delete (w);
}
void menu::open ()
{open_window;
write_cmds;
is_open = true;
w->tick ();
. open_window
{w = new win (name, "", x, y, dx, dy);
w->set_font (men_font);
}.
. write_cmds
{for (int i = 0; i < num_buttons; i++)
write (i, cmds [i], is_pressed [i]);
}.
}
void menu::close ()
{delete (w);
is_open = false;
}
int menu::mouse_button ()
{return last_mouse_button;
}
void menu::enable (int group, bool mode)
{group_enabled [group] = mode;
}
void menu::tick ()
{if (is_visable && ! is_open)
open ();
else if (! is_visable && is_open)
close ();
. is_visable
group_enabled [group].
}
void menu::write (int no, char string [], bool pressed)
{draw_border;
if (icon_mode)
write_icon
else write_text;
. draw_border
{if (pressed)
pressed_border
else none_pressed_border;
}.
. pressed_border
{clear;
for (int i = 0; i < border_dx; i++)
draw_pressed_line;
}.
. draw_pressed_line
{w->set_color (c_border_dark);
if (i < border_dx-1)
w->set_color (black);
w->line (x_button+i, y_button+i, xe_button - i, y_button + i);
w->line (x_button+i, y_button+i, x_button + i, ye_button - i);
w->set_color (c_border_light);
if (i < border_dx-1)
w->set_color (black);
w->line (x_button+i, ye_button-i, xe_button- i, ye_button - i);
w->line (xe_button-i, y_button+i, xe_button- i, ye_button - i);
}.
. draw_released_line
{w->set_color (c_border_light);
w->line (x_button+i, y_button+i, xe_button - i, y_button + i);
w->line (x_button+i, y_button+i, x_button + i, ye_button - i);
w->set_color (c_border_dark);
w->line (x_button+i, ye_button-i, xe_button- i, ye_button - i);
w->line (xe_button-i, y_button+i, xe_button- i, ye_button - i);
}.
. none_pressed_border
{clear;
for (int i = 0; i < border_dx; i++)
draw_released_line;
}.
. clear
{w->set_color (c_background);
w->fill (x_button, y_button, button_dx, button_dy);
}.
. write_icon
{char m_name [128];
sprintf (m_name, "%s%s", button_dir, string);
w->set_background (c_background);
w->set_color (c_foreground);
w->show_map (border_dx, yy + border_dy, m_name);
w->tick ();
}.
. write_text
{w->function (GXcopy);
w->set_background (c_background);
w->set_color (c_foreground);
w->write (xtext, ytext, string);
w->tick ();
}.
. xtext border_dx + (((button_dx - 2 * border_dx) - act_tdx) / 2).
. ytext yy +
border_dy +
act_tdy +
2 +
(((button_dy - 2 * border_dy) - act_tdy) / 2).
. act_tdx tdx [no].
. act_tdy tdy [no].
. x_button 0.
. y_button yy.
. xe_button x_button + button_dx.
. ye_button y_button + button_dy.
. yy no * button_dy.
}
int menu::eval (bool is_repeat)
{tick ();
if (is_open)
exec_eval
else return no_menu_request;
. exec_eval
{int x;
int y;
int button;
get_button;
return_result;
}.
. get_button
{int d;
w->tick ();
w->mouse (d, d, x, y, button);
if (button == button1press || button == button3press)
handle_new_press
else if (button == button1release || button == button3release)
handle_release
else if (! is_repeat && button != button1press && button != button3press)
handle_release;
}.
. handle_new_press
{last_mouse_button = button;
if (pressed_button != menu_point)
release ();
press (menu_point);
is_press = true;
pressed_button = menu_point;
}.
. handle_release
{release ();
is_press = false;
pressed_button = no_menu_request;
}.
. return_result
{return pressed_button;
}.
. menu_point
(y / button_dy).
}
void menu::press (int no)
{write (no, cmds [no], true);
is_pressed [no] = true;
}
void menu::release ()
{if (pressed_button != no_menu_request)
release (pressed_button);
pressed_button = no_menu_request;
}
void menu::release (int no)
{write (no, cmds [no], false);
is_pressed [no] = false;
}
bool menu::get_cmd (const char cmds [], int &p, char cmd [])
{if (eof)
return false;
else read_cmd;
return true;
. read_cmd
{int c = 0;
bool skip_mode = false;
skip_icon_symbol;
while (cmd_char != ':' && ! eof)
{handle_skip_mode;
store_char;
p++;
};
cmd [c] = 0;
p++;
}.
. handle_skip_mode
{if (cmd_char == ';')
switch_skip_mode;
}.
. store_char
{if (! skip_mode)
cmd [c++] = cmd_char;
}.
. switch_skip_mode
{skip_mode = ! skip_mode;
p++;
}.
. skip_icon_symbol
if (cmd_char == '$' || cmd_char == '&')
p++.
. eof
(p >= strlen (cmds)).
. cmd_char
cmds [p].
}