1 | /*
|
---|
2 | * Copyright (c) 2022 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup uidemo
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file User interface demo
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <gfx/bitmap.h>
|
---|
36 | #include <gfx/coord.h>
|
---|
37 | #include <io/pixelmap.h>
|
---|
38 | #include <stdio.h>
|
---|
39 | #include <stdlib.h>
|
---|
40 | #include <str.h>
|
---|
41 | #include <ui/entry.h>
|
---|
42 | #include <ui/filedialog.h>
|
---|
43 | #include <ui/fixed.h>
|
---|
44 | #include <ui/image.h>
|
---|
45 | #include <ui/label.h>
|
---|
46 | #include <ui/menubar.h>
|
---|
47 | #include <ui/menuentry.h>
|
---|
48 | #include <ui/menu.h>
|
---|
49 | #include <ui/msgdialog.h>
|
---|
50 | #include <ui/pbutton.h>
|
---|
51 | #include <ui/promptdialog.h>
|
---|
52 | #include <ui/resource.h>
|
---|
53 | #include <ui/ui.h>
|
---|
54 | #include <ui/window.h>
|
---|
55 | #include "uidemo.h"
|
---|
56 |
|
---|
57 | static errno_t bitmap_moire(gfx_bitmap_t *, gfx_coord_t, gfx_coord_t);
|
---|
58 |
|
---|
59 | static void wnd_close(ui_window_t *, void *);
|
---|
60 |
|
---|
61 | static ui_window_cb_t window_cb = {
|
---|
62 | .close = wnd_close
|
---|
63 | };
|
---|
64 |
|
---|
65 | static void pb_clicked(ui_pbutton_t *, void *);
|
---|
66 |
|
---|
67 | static ui_pbutton_cb_t pbutton_cb = {
|
---|
68 | .clicked = pb_clicked
|
---|
69 | };
|
---|
70 |
|
---|
71 | static void checkbox_switched(ui_checkbox_t *, void *, bool);
|
---|
72 |
|
---|
73 | static ui_checkbox_cb_t checkbox_cb = {
|
---|
74 | .switched = checkbox_switched
|
---|
75 | };
|
---|
76 |
|
---|
77 | static void rb_selected(ui_rbutton_group_t *, void *, void *);
|
---|
78 |
|
---|
79 | static ui_rbutton_group_cb_t rbutton_group_cb = {
|
---|
80 | .selected = rb_selected
|
---|
81 | };
|
---|
82 |
|
---|
83 | static void slider_moved(ui_slider_t *, void *, gfx_coord_t);
|
---|
84 |
|
---|
85 | static ui_slider_cb_t slider_cb = {
|
---|
86 | .moved = slider_moved
|
---|
87 | };
|
---|
88 |
|
---|
89 | static void scrollbar_up(ui_scrollbar_t *, void *);
|
---|
90 | static void scrollbar_down(ui_scrollbar_t *, void *);
|
---|
91 | static void scrollbar_page_up(ui_scrollbar_t *, void *);
|
---|
92 | static void scrollbar_page_down(ui_scrollbar_t *, void *);
|
---|
93 | static void scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t);
|
---|
94 |
|
---|
95 | static ui_scrollbar_cb_t scrollbar_cb = {
|
---|
96 | .up = scrollbar_up,
|
---|
97 | .down = scrollbar_down,
|
---|
98 | .page_up = scrollbar_page_up,
|
---|
99 | .page_down = scrollbar_page_down,
|
---|
100 | .moved = scrollbar_moved
|
---|
101 | };
|
---|
102 |
|
---|
103 | static void uidemo_file_load(ui_menu_entry_t *, void *);
|
---|
104 | static void uidemo_file_message(ui_menu_entry_t *, void *);
|
---|
105 | static void uidemo_file_exit(ui_menu_entry_t *, void *);
|
---|
106 | static void uidemo_edit_modify(ui_menu_entry_t *, void *);
|
---|
107 |
|
---|
108 | static void file_dialog_bok(ui_file_dialog_t *, void *, const char *);
|
---|
109 | static void file_dialog_bcancel(ui_file_dialog_t *, void *);
|
---|
110 | static void file_dialog_close(ui_file_dialog_t *, void *);
|
---|
111 |
|
---|
112 | static ui_file_dialog_cb_t file_dialog_cb = {
|
---|
113 | .bok = file_dialog_bok,
|
---|
114 | .bcancel = file_dialog_bcancel,
|
---|
115 | .close = file_dialog_close
|
---|
116 | };
|
---|
117 |
|
---|
118 | static void prompt_dialog_bok(ui_prompt_dialog_t *, void *, const char *);
|
---|
119 | static void prompt_dialog_bcancel(ui_prompt_dialog_t *, void *);
|
---|
120 | static void prompt_dialog_close(ui_prompt_dialog_t *, void *);
|
---|
121 |
|
---|
122 | static ui_prompt_dialog_cb_t prompt_dialog_cb = {
|
---|
123 | .bok = prompt_dialog_bok,
|
---|
124 | .bcancel = prompt_dialog_bcancel,
|
---|
125 | .close = prompt_dialog_close
|
---|
126 | };
|
---|
127 |
|
---|
128 | static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned);
|
---|
129 | static void msg_dialog_close(ui_msg_dialog_t *, void *);
|
---|
130 |
|
---|
131 | static ui_msg_dialog_cb_t msg_dialog_cb = {
|
---|
132 | .button = msg_dialog_button,
|
---|
133 | .close = msg_dialog_close
|
---|
134 | };
|
---|
135 |
|
---|
136 | /** Horizontal alignment selected by each radio button */
|
---|
137 | static const gfx_halign_t uidemo_halign[3] = {
|
---|
138 | gfx_halign_left,
|
---|
139 | gfx_halign_center,
|
---|
140 | gfx_halign_right
|
---|
141 | };
|
---|
142 |
|
---|
143 | /** Window close button was clicked.
|
---|
144 | *
|
---|
145 | * @param window Window
|
---|
146 | * @param arg Argument (demo)
|
---|
147 | */
|
---|
148 | static void wnd_close(ui_window_t *window, void *arg)
|
---|
149 | {
|
---|
150 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
151 |
|
---|
152 | ui_quit(demo->ui);
|
---|
153 | }
|
---|
154 |
|
---|
155 | /** Push button was clicked.
|
---|
156 | *
|
---|
157 | * @param pbutton Push button
|
---|
158 | * @param arg Argument (demo)
|
---|
159 | */
|
---|
160 | static void pb_clicked(ui_pbutton_t *pbutton, void *arg)
|
---|
161 | {
|
---|
162 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
163 | errno_t rc;
|
---|
164 |
|
---|
165 | if (pbutton == demo->pb1) {
|
---|
166 | rc = ui_entry_set_text(demo->entry, "OK pressed");
|
---|
167 | if (rc != EOK)
|
---|
168 | printf("Error changing entry text.\n");
|
---|
169 | } else {
|
---|
170 | rc = ui_entry_set_text(demo->entry, "Cancel pressed");
|
---|
171 | if (rc != EOK)
|
---|
172 | printf("Error changing entry text.\n");
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | /** Check box was switched.
|
---|
177 | *
|
---|
178 | * @param checkbox Check box
|
---|
179 | * @param arg Argument (demo)
|
---|
180 | */
|
---|
181 | static void checkbox_switched(ui_checkbox_t *checkbox, void *arg, bool enable)
|
---|
182 | {
|
---|
183 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
184 |
|
---|
185 | ui_entry_set_read_only(demo->entry, enable);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /** Radio button was selected.
|
---|
189 | *
|
---|
190 | * @param rbgroup Radio button group
|
---|
191 | * @param garg Group argument (demo)
|
---|
192 | * @param barg Button argument
|
---|
193 | */
|
---|
194 | static void rb_selected(ui_rbutton_group_t *rbgroup, void *garg, void *barg)
|
---|
195 | {
|
---|
196 | ui_demo_t *demo = (ui_demo_t *) garg;
|
---|
197 | gfx_halign_t halign = *(gfx_halign_t *) barg;
|
---|
198 |
|
---|
199 | ui_entry_set_halign(demo->entry, halign);
|
---|
200 | (void) ui_entry_paint(demo->entry);
|
---|
201 | }
|
---|
202 |
|
---|
203 | /** Slider was moved.
|
---|
204 | *
|
---|
205 | * @param slider Slider
|
---|
206 | * @param arg Argument (demo)
|
---|
207 | * @param pos Position
|
---|
208 | */
|
---|
209 | static void slider_moved(ui_slider_t *slider, void *arg, gfx_coord_t pos)
|
---|
210 | {
|
---|
211 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
212 | char *str;
|
---|
213 | errno_t rc;
|
---|
214 | int rv;
|
---|
215 |
|
---|
216 | rv = asprintf(&str, "Slider at %d of %d", (int) pos,
|
---|
217 | ui_slider_length(slider));
|
---|
218 | if (rv < 0) {
|
---|
219 | printf("Out of memory.\n");
|
---|
220 | return;
|
---|
221 | }
|
---|
222 |
|
---|
223 | rc = ui_entry_set_text(demo->entry, str);
|
---|
224 | if (rc != EOK)
|
---|
225 | printf("Error changing entry text.\n");
|
---|
226 | (void) ui_entry_paint(demo->entry);
|
---|
227 |
|
---|
228 | free(str);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /** Scrollbar up button pressed.
|
---|
232 | *
|
---|
233 | * @param scrollbar Scrollbar
|
---|
234 | * @param arg Argument (demo)
|
---|
235 | */
|
---|
236 | static void scrollbar_up(ui_scrollbar_t *scrollbar, void *arg)
|
---|
237 | {
|
---|
238 | gfx_coord_t pos;
|
---|
239 |
|
---|
240 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
241 | ui_scrollbar_set_pos(scrollbar, pos - 1);
|
---|
242 |
|
---|
243 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
244 | scrollbar_moved(scrollbar, arg, pos);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /** Scrollbar down button pressed.
|
---|
248 | *
|
---|
249 | * @param scrollbar Scrollbar
|
---|
250 | * @param arg Argument (demo)
|
---|
251 | */
|
---|
252 | static void scrollbar_down(ui_scrollbar_t *scrollbar, void *arg)
|
---|
253 | {
|
---|
254 | gfx_coord_t pos;
|
---|
255 |
|
---|
256 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
257 | ui_scrollbar_set_pos(scrollbar, pos + 1);
|
---|
258 |
|
---|
259 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
260 | scrollbar_moved(scrollbar, arg, pos);
|
---|
261 | }
|
---|
262 |
|
---|
263 | /** Scrollbar page up event.
|
---|
264 | *
|
---|
265 | * @param scrollbar Scrollbar
|
---|
266 | * @param arg Argument (demo)
|
---|
267 | */
|
---|
268 | static void scrollbar_page_up(ui_scrollbar_t *scrollbar, void *arg)
|
---|
269 | {
|
---|
270 | gfx_coord_t pos;
|
---|
271 |
|
---|
272 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
273 | ui_scrollbar_set_pos(scrollbar, pos -
|
---|
274 | ui_scrollbar_through_length(scrollbar) / 4);
|
---|
275 |
|
---|
276 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
277 | scrollbar_moved(scrollbar, arg, pos);
|
---|
278 | }
|
---|
279 |
|
---|
280 | /** Scrollbar page down event.
|
---|
281 | *
|
---|
282 | * @param scrollbar Scrollbar
|
---|
283 | * @param arg Argument (demo)
|
---|
284 | */
|
---|
285 | static void scrollbar_page_down(ui_scrollbar_t *scrollbar, void *arg)
|
---|
286 | {
|
---|
287 | gfx_coord_t pos;
|
---|
288 |
|
---|
289 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
290 | ui_scrollbar_set_pos(scrollbar, pos +
|
---|
291 | ui_scrollbar_through_length(scrollbar) / 4);
|
---|
292 |
|
---|
293 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
294 | scrollbar_moved(scrollbar, arg, pos);
|
---|
295 | }
|
---|
296 |
|
---|
297 | /** Scrollbar was moved.
|
---|
298 | *
|
---|
299 | * @param scrollbar Scrollbar
|
---|
300 | * @param arg Argument (demo)
|
---|
301 | * @param pos Position
|
---|
302 | */
|
---|
303 | static void scrollbar_moved(ui_scrollbar_t *scrollbar, void *arg,
|
---|
304 | gfx_coord_t pos)
|
---|
305 | {
|
---|
306 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
307 | char *str;
|
---|
308 | errno_t rc;
|
---|
309 | int rv;
|
---|
310 |
|
---|
311 | rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos,
|
---|
312 | ui_scrollbar_move_length(scrollbar));
|
---|
313 | if (rv < 0) {
|
---|
314 | printf("Out of memory.\n");
|
---|
315 | return;
|
---|
316 | }
|
---|
317 |
|
---|
318 | rc = ui_entry_set_text(demo->entry, str);
|
---|
319 | if (rc != EOK)
|
---|
320 | printf("Error changing entry text.\n");
|
---|
321 | (void) ui_entry_paint(demo->entry);
|
---|
322 |
|
---|
323 | free(str);
|
---|
324 | }
|
---|
325 |
|
---|
326 | /** Display a message window.
|
---|
327 | *
|
---|
328 | * @param demo UI demo
|
---|
329 | * @param caption Window caption
|
---|
330 | * @param text Message text
|
---|
331 | */
|
---|
332 | static void uidemo_show_message(ui_demo_t *demo, const char *caption,
|
---|
333 | const char *text)
|
---|
334 | {
|
---|
335 | ui_msg_dialog_params_t mdparams;
|
---|
336 | ui_msg_dialog_t *dialog;
|
---|
337 | errno_t rc;
|
---|
338 |
|
---|
339 | ui_msg_dialog_params_init(&mdparams);
|
---|
340 | mdparams.caption = caption;
|
---|
341 | mdparams.text = text;
|
---|
342 |
|
---|
343 | rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
|
---|
344 | if (rc != EOK) {
|
---|
345 | printf("Error creating message dialog.\n");
|
---|
346 | return;
|
---|
347 | }
|
---|
348 |
|
---|
349 | ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo);
|
---|
350 | }
|
---|
351 |
|
---|
352 | /** File / Load menu entry selected.
|
---|
353 | *
|
---|
354 | * @param mentry Menu entry
|
---|
355 | * @param arg Argument (demo)
|
---|
356 | */
|
---|
357 | static void uidemo_file_load(ui_menu_entry_t *mentry, void *arg)
|
---|
358 | {
|
---|
359 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
360 | ui_file_dialog_params_t fdparams;
|
---|
361 | ui_file_dialog_t *dialog;
|
---|
362 | errno_t rc;
|
---|
363 |
|
---|
364 | ui_file_dialog_params_init(&fdparams);
|
---|
365 | fdparams.caption = "Load File";
|
---|
366 |
|
---|
367 | rc = ui_file_dialog_create(demo->ui, &fdparams, &dialog);
|
---|
368 | if (rc != EOK) {
|
---|
369 | printf("Error creating message dialog.\n");
|
---|
370 | return;
|
---|
371 | }
|
---|
372 |
|
---|
373 | ui_file_dialog_set_cb(dialog, &file_dialog_cb, demo);
|
---|
374 | }
|
---|
375 |
|
---|
376 | /** File / Message menu entry selected.
|
---|
377 | *
|
---|
378 | * @param mentry Menu entry
|
---|
379 | * @param arg Argument (demo)
|
---|
380 | */
|
---|
381 | static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg)
|
---|
382 | {
|
---|
383 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
384 | ui_msg_dialog_params_t mdparams;
|
---|
385 | ui_msg_dialog_t *dialog;
|
---|
386 | errno_t rc;
|
---|
387 |
|
---|
388 | ui_msg_dialog_params_init(&mdparams);
|
---|
389 | mdparams.caption = "Message For You";
|
---|
390 | mdparams.text = "Hello, world!";
|
---|
391 |
|
---|
392 | rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
|
---|
393 | if (rc != EOK) {
|
---|
394 | printf("Error creating message dialog.\n");
|
---|
395 | return;
|
---|
396 | }
|
---|
397 |
|
---|
398 | ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo);
|
---|
399 | }
|
---|
400 |
|
---|
401 | /** File / Exit menu entry selected.
|
---|
402 | *
|
---|
403 | * @param mentry Menu entry
|
---|
404 | * @param arg Argument (demo)
|
---|
405 | */
|
---|
406 | static void uidemo_file_exit(ui_menu_entry_t *mentry, void *arg)
|
---|
407 | {
|
---|
408 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
409 |
|
---|
410 | ui_quit(demo->ui);
|
---|
411 | }
|
---|
412 |
|
---|
413 | /** Edit / Modify menu entry selected.
|
---|
414 | *
|
---|
415 | * @param mentry Menu entry
|
---|
416 | * @param arg Argument (demo)
|
---|
417 | */
|
---|
418 | static void uidemo_edit_modify(ui_menu_entry_t *mentry, void *arg)
|
---|
419 | {
|
---|
420 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
421 | ui_prompt_dialog_params_t pdparams;
|
---|
422 | ui_prompt_dialog_t *dialog;
|
---|
423 | errno_t rc;
|
---|
424 |
|
---|
425 | ui_prompt_dialog_params_init(&pdparams);
|
---|
426 | pdparams.caption = "Modify Entry Text";
|
---|
427 | pdparams.prompt = "Enter New Text";
|
---|
428 |
|
---|
429 | rc = ui_prompt_dialog_create(demo->ui, &pdparams, &dialog);
|
---|
430 | if (rc != EOK) {
|
---|
431 | printf("Error creating message dialog.\n");
|
---|
432 | return;
|
---|
433 | }
|
---|
434 |
|
---|
435 | ui_prompt_dialog_set_cb(dialog, &prompt_dialog_cb, demo);
|
---|
436 | }
|
---|
437 |
|
---|
438 | /** File dialog OK button press.
|
---|
439 | *
|
---|
440 | * @param dialog File dialog
|
---|
441 | * @param arg Argument (ui_demo_t *)
|
---|
442 | * @param fname File name
|
---|
443 | */
|
---|
444 | static void file_dialog_bok(ui_file_dialog_t *dialog, void *arg,
|
---|
445 | const char *fname)
|
---|
446 | {
|
---|
447 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
448 | char buf[128];
|
---|
449 | char *p;
|
---|
450 | FILE *f;
|
---|
451 |
|
---|
452 | ui_file_dialog_destroy(dialog);
|
---|
453 |
|
---|
454 | f = fopen(fname, "rt");
|
---|
455 | if (f == NULL) {
|
---|
456 | uidemo_show_message(demo, "Error", "Error opening file.");
|
---|
457 | return;
|
---|
458 | }
|
---|
459 |
|
---|
460 | p = fgets(buf, sizeof(buf), f);
|
---|
461 | if (p == NULL) {
|
---|
462 | uidemo_show_message(demo, "Error", "Error reading file.");
|
---|
463 | fclose(f);
|
---|
464 | return;
|
---|
465 | }
|
---|
466 |
|
---|
467 | /* Cut string off at the first non-printable character */
|
---|
468 | p = buf;
|
---|
469 | while (*p != '\0') {
|
---|
470 | if (*p < ' ') {
|
---|
471 | *p = '\0';
|
---|
472 | break;
|
---|
473 | }
|
---|
474 | ++p;
|
---|
475 | }
|
---|
476 |
|
---|
477 | ui_entry_set_text(demo->entry, buf);
|
---|
478 | fclose(f);
|
---|
479 | }
|
---|
480 |
|
---|
481 | /** File dialog cancel button press.
|
---|
482 | *
|
---|
483 | * @param dialog File dialog
|
---|
484 | * @param arg Argument (ui_demo_t *)
|
---|
485 | */
|
---|
486 | static void file_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
|
---|
487 | {
|
---|
488 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
489 |
|
---|
490 | (void) demo;
|
---|
491 | ui_file_dialog_destroy(dialog);
|
---|
492 | }
|
---|
493 |
|
---|
494 | /** File dialog close request.
|
---|
495 | *
|
---|
496 | * @param dialog File dialog
|
---|
497 | * @param arg Argument (ui_demo_t *)
|
---|
498 | */
|
---|
499 | static void file_dialog_close(ui_file_dialog_t *dialog, void *arg)
|
---|
500 | {
|
---|
501 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
502 |
|
---|
503 | (void) demo;
|
---|
504 | ui_file_dialog_destroy(dialog);
|
---|
505 | }
|
---|
506 |
|
---|
507 | /** Prompt dialog OK button press.
|
---|
508 | *
|
---|
509 | * @param dialog Prompt dialog
|
---|
510 | * @param arg Argument (ui_demo_t *)
|
---|
511 | * @param text Submitted text
|
---|
512 | */
|
---|
513 | static void prompt_dialog_bok(ui_prompt_dialog_t *dialog, void *arg,
|
---|
514 | const char *text)
|
---|
515 | {
|
---|
516 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
517 |
|
---|
518 | ui_prompt_dialog_destroy(dialog);
|
---|
519 | ui_entry_set_text(demo->entry, text);
|
---|
520 | }
|
---|
521 |
|
---|
522 | /** Prompt dialog cancel button press.
|
---|
523 | *
|
---|
524 | * @param dialog File dialog
|
---|
525 | * @param arg Argument (ui_demo_t *)
|
---|
526 | */
|
---|
527 | static void prompt_dialog_bcancel(ui_prompt_dialog_t *dialog, void *arg)
|
---|
528 | {
|
---|
529 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
530 |
|
---|
531 | (void) demo;
|
---|
532 | ui_prompt_dialog_destroy(dialog);
|
---|
533 | }
|
---|
534 |
|
---|
535 | /** Prompt dialog close request.
|
---|
536 | *
|
---|
537 | * @param dialog File dialog
|
---|
538 | * @param arg Argument (ui_demo_t *)
|
---|
539 | */
|
---|
540 | static void prompt_dialog_close(ui_prompt_dialog_t *dialog, void *arg)
|
---|
541 | {
|
---|
542 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
543 |
|
---|
544 | (void) demo;
|
---|
545 | ui_prompt_dialog_destroy(dialog);
|
---|
546 | }
|
---|
547 |
|
---|
548 | /** Message dialog button press.
|
---|
549 | *
|
---|
550 | * @param dialog Message dialog
|
---|
551 | * @param arg Argument (ui_demo_t *)
|
---|
552 | * @param bnum Button number
|
---|
553 | */
|
---|
554 | static void msg_dialog_button(ui_msg_dialog_t *dialog, void *arg,
|
---|
555 | unsigned bnum)
|
---|
556 | {
|
---|
557 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
558 |
|
---|
559 | (void) demo;
|
---|
560 | ui_msg_dialog_destroy(dialog);
|
---|
561 | }
|
---|
562 |
|
---|
563 | /** Message dialog close request.
|
---|
564 | *
|
---|
565 | * @param dialog Message dialog
|
---|
566 | * @param arg Argument (ui_demo_t *)
|
---|
567 | */
|
---|
568 | static void msg_dialog_close(ui_msg_dialog_t *dialog, void *arg)
|
---|
569 | {
|
---|
570 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
571 |
|
---|
572 | (void) demo;
|
---|
573 | ui_msg_dialog_destroy(dialog);
|
---|
574 | }
|
---|
575 |
|
---|
576 | /** Run UI demo on display server. */
|
---|
577 | static errno_t ui_demo(const char *display_spec)
|
---|
578 | {
|
---|
579 | ui_t *ui = NULL;
|
---|
580 | ui_wnd_params_t params;
|
---|
581 | ui_window_t *window = NULL;
|
---|
582 | ui_demo_t demo;
|
---|
583 | gfx_rect_t rect;
|
---|
584 | gfx_context_t *gc;
|
---|
585 | ui_resource_t *ui_res;
|
---|
586 | gfx_bitmap_params_t bparams;
|
---|
587 | gfx_bitmap_t *bitmap;
|
---|
588 | gfx_coord2_t off;
|
---|
589 | ui_menu_entry_t *mmsg;
|
---|
590 | ui_menu_entry_t *mload;
|
---|
591 | ui_menu_entry_t *mfoo;
|
---|
592 | ui_menu_entry_t *mbar;
|
---|
593 | ui_menu_entry_t *mfoobar;
|
---|
594 | ui_menu_entry_t *msep;
|
---|
595 | ui_menu_entry_t *mexit;
|
---|
596 | ui_menu_entry_t *mmodify;
|
---|
597 | ui_menu_entry_t *mabout;
|
---|
598 | errno_t rc;
|
---|
599 |
|
---|
600 | rc = ui_create(display_spec, &ui);
|
---|
601 | if (rc != EOK) {
|
---|
602 | printf("Error creating UI on display %s.\n", display_spec);
|
---|
603 | return rc;
|
---|
604 | }
|
---|
605 |
|
---|
606 | memset((void *) &demo, 0, sizeof(demo));
|
---|
607 | demo.ui = ui;
|
---|
608 |
|
---|
609 | ui_wnd_params_init(¶ms);
|
---|
610 | params.caption = "UI Demo";
|
---|
611 | params.style |= ui_wds_resizable;
|
---|
612 |
|
---|
613 | /* FIXME: Auto layout */
|
---|
614 | if (ui_is_textmode(ui)) {
|
---|
615 | params.rect.p0.x = 0;
|
---|
616 | params.rect.p0.y = 0;
|
---|
617 | params.rect.p1.x = 44;
|
---|
618 | params.rect.p1.y = 23;
|
---|
619 | } else {
|
---|
620 | params.rect.p0.x = 0;
|
---|
621 | params.rect.p0.y = 0;
|
---|
622 | params.rect.p1.x = 220;
|
---|
623 | params.rect.p1.y = 370;
|
---|
624 | }
|
---|
625 |
|
---|
626 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
627 | if (rc != EOK) {
|
---|
628 | printf("Error creating window.\n");
|
---|
629 | return rc;
|
---|
630 | }
|
---|
631 |
|
---|
632 | ui_window_set_cb(window, &window_cb, (void *) &demo);
|
---|
633 | demo.window = window;
|
---|
634 |
|
---|
635 | ui_res = ui_window_get_res(window);
|
---|
636 | gc = ui_window_get_gc(window);
|
---|
637 |
|
---|
638 | rc = ui_fixed_create(&demo.fixed);
|
---|
639 | if (rc != EOK) {
|
---|
640 | printf("Error creating fixed layout.\n");
|
---|
641 | return rc;
|
---|
642 | }
|
---|
643 |
|
---|
644 | rc = ui_menu_bar_create(ui, window, &demo.mbar);
|
---|
645 | if (rc != EOK) {
|
---|
646 | printf("Error creating menu bar.\n");
|
---|
647 | return rc;
|
---|
648 | }
|
---|
649 |
|
---|
650 | rc = ui_menu_create(demo.mbar, "~F~ile", &demo.mfile);
|
---|
651 | if (rc != EOK) {
|
---|
652 | printf("Error creating menu.\n");
|
---|
653 | return rc;
|
---|
654 | }
|
---|
655 |
|
---|
656 | rc = ui_menu_entry_create(demo.mfile, "~M~essage", "", &mmsg);
|
---|
657 | if (rc != EOK) {
|
---|
658 | printf("Error creating menu.\n");
|
---|
659 | return rc;
|
---|
660 | }
|
---|
661 |
|
---|
662 | ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo);
|
---|
663 |
|
---|
664 | rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload);
|
---|
665 | if (rc != EOK) {
|
---|
666 | printf("Error creating menu.\n");
|
---|
667 | return rc;
|
---|
668 | }
|
---|
669 |
|
---|
670 | ui_menu_entry_set_cb(mload, uidemo_file_load, (void *) &demo);
|
---|
671 |
|
---|
672 | rc = ui_menu_entry_create(demo.mfile, "~F~oo", "Ctrl-Alt-Del", &mfoo);
|
---|
673 | if (rc != EOK) {
|
---|
674 | printf("Error creating menu.\n");
|
---|
675 | return rc;
|
---|
676 | }
|
---|
677 |
|
---|
678 | rc = ui_menu_entry_create(demo.mfile, "~B~ar", "", &mbar);
|
---|
679 | if (rc != EOK) {
|
---|
680 | printf("Error creating menu.\n");
|
---|
681 | return rc;
|
---|
682 | }
|
---|
683 |
|
---|
684 | rc = ui_menu_entry_create(demo.mfile, "F~o~obar", "", &mfoobar);
|
---|
685 | if (rc != EOK) {
|
---|
686 | printf("Error creating menu.\n");
|
---|
687 | return rc;
|
---|
688 | }
|
---|
689 |
|
---|
690 | rc = ui_menu_entry_sep_create(demo.mfile, &msep);
|
---|
691 | if (rc != EOK) {
|
---|
692 | printf("Error creating menu.\n");
|
---|
693 | return rc;
|
---|
694 | }
|
---|
695 |
|
---|
696 | rc = ui_menu_entry_create(demo.mfile, "E~x~it", "Alt-F4", &mexit);
|
---|
697 | if (rc != EOK) {
|
---|
698 | printf("Error creating menu.\n");
|
---|
699 | return rc;
|
---|
700 | }
|
---|
701 |
|
---|
702 | ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo);
|
---|
703 |
|
---|
704 | rc = ui_menu_create(demo.mbar, "~E~dit", &demo.medit);
|
---|
705 | if (rc != EOK) {
|
---|
706 | printf("Error creating menu.\n");
|
---|
707 | return rc;
|
---|
708 | }
|
---|
709 |
|
---|
710 | rc = ui_menu_entry_create(demo.medit, "~M~odify", "", &mmodify);
|
---|
711 | if (rc != EOK) {
|
---|
712 | printf("Error creating menu.\n");
|
---|
713 | return rc;
|
---|
714 | }
|
---|
715 |
|
---|
716 | ui_menu_entry_set_cb(mmodify, uidemo_edit_modify, (void *) &demo);
|
---|
717 |
|
---|
718 | rc = ui_menu_create(demo.mbar, "~P~references", &demo.mpreferences);
|
---|
719 | if (rc != EOK) {
|
---|
720 | printf("Error creating menu.\n");
|
---|
721 | return rc;
|
---|
722 | }
|
---|
723 |
|
---|
724 | rc = ui_menu_create(demo.mbar, "~H~elp", &demo.mhelp);
|
---|
725 | if (rc != EOK) {
|
---|
726 | printf("Error creating menu.\n");
|
---|
727 | return rc;
|
---|
728 | }
|
---|
729 |
|
---|
730 | rc = ui_menu_entry_create(demo.mhelp, "~A~bout", "Ctrl-H, F1", &mabout);
|
---|
731 | if (rc != EOK) {
|
---|
732 | printf("Error creating menu.\n");
|
---|
733 | return rc;
|
---|
734 | }
|
---|
735 |
|
---|
736 | /* FIXME: Auto layout */
|
---|
737 | if (ui_is_textmode(ui)) {
|
---|
738 | rect.p0.x = 1;
|
---|
739 | rect.p0.y = 1;
|
---|
740 | rect.p1.x = 43;
|
---|
741 | rect.p1.y = 2;
|
---|
742 | } else {
|
---|
743 | rect.p0.x = 4;
|
---|
744 | rect.p0.y = 30;
|
---|
745 | rect.p1.x = 216;
|
---|
746 | rect.p1.y = 52;
|
---|
747 | }
|
---|
748 | ui_menu_bar_set_rect(demo.mbar, &rect);
|
---|
749 |
|
---|
750 | rc = ui_fixed_add(demo.fixed, ui_menu_bar_ctl(demo.mbar));
|
---|
751 | if (rc != EOK) {
|
---|
752 | printf("Error adding control to layout.\n");
|
---|
753 | return rc;
|
---|
754 | }
|
---|
755 |
|
---|
756 | rc = ui_entry_create(window, "", &demo.entry);
|
---|
757 | if (rc != EOK) {
|
---|
758 | printf("Error creating entry.\n");
|
---|
759 | return rc;
|
---|
760 | }
|
---|
761 |
|
---|
762 | /* FIXME: Auto layout */
|
---|
763 | if (ui_is_textmode(ui)) {
|
---|
764 | rect.p0.x = 2;
|
---|
765 | rect.p0.y = 3;
|
---|
766 | rect.p1.x = 42;
|
---|
767 | rect.p1.y = 4;
|
---|
768 | } else {
|
---|
769 | rect.p0.x = 15;
|
---|
770 | rect.p0.y = 53;
|
---|
771 | rect.p1.x = 205;
|
---|
772 | rect.p1.y = 78;
|
---|
773 | }
|
---|
774 |
|
---|
775 | ui_entry_set_rect(demo.entry, &rect);
|
---|
776 | ui_entry_set_halign(demo.entry, gfx_halign_center);
|
---|
777 |
|
---|
778 | rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry));
|
---|
779 | if (rc != EOK) {
|
---|
780 | printf("Error adding control to layout.\n");
|
---|
781 | return rc;
|
---|
782 | }
|
---|
783 |
|
---|
784 | rc = ui_label_create(ui_res, "Text label", &demo.label);
|
---|
785 | if (rc != EOK) {
|
---|
786 | printf("Error creating label.\n");
|
---|
787 | return rc;
|
---|
788 | }
|
---|
789 |
|
---|
790 | /* FIXME: Auto layout */
|
---|
791 | if (ui_is_textmode(ui)) {
|
---|
792 | rect.p0.x = 2;
|
---|
793 | rect.p0.y = 5;
|
---|
794 | rect.p1.x = 42;
|
---|
795 | rect.p1.y = 6;
|
---|
796 | } else {
|
---|
797 | rect.p0.x = 60;
|
---|
798 | rect.p0.y = 88;
|
---|
799 | rect.p1.x = 160;
|
---|
800 | rect.p1.y = 101;
|
---|
801 | }
|
---|
802 |
|
---|
803 | ui_label_set_rect(demo.label, &rect);
|
---|
804 | ui_label_set_halign(demo.label, gfx_halign_center);
|
---|
805 |
|
---|
806 | rc = ui_fixed_add(demo.fixed, ui_label_ctl(demo.label));
|
---|
807 | if (rc != EOK) {
|
---|
808 | printf("Error adding control to layout.\n");
|
---|
809 | return rc;
|
---|
810 | }
|
---|
811 |
|
---|
812 | rc = ui_pbutton_create(ui_res, "OK", &demo.pb1);
|
---|
813 | if (rc != EOK) {
|
---|
814 | printf("Error creating button.\n");
|
---|
815 | return rc;
|
---|
816 | }
|
---|
817 |
|
---|
818 | ui_pbutton_set_cb(demo.pb1, &pbutton_cb, (void *) &demo);
|
---|
819 |
|
---|
820 | /* FIXME: Auto layout */
|
---|
821 | if (ui_is_textmode(ui)) {
|
---|
822 | rect.p0.x = 2;
|
---|
823 | rect.p0.y = 7;
|
---|
824 | rect.p1.x = 12;
|
---|
825 | rect.p1.y = 8;
|
---|
826 | } else {
|
---|
827 | rect.p0.x = 15;
|
---|
828 | rect.p0.y = 111;
|
---|
829 | rect.p1.x = 105;
|
---|
830 | rect.p1.y = 139;
|
---|
831 | }
|
---|
832 |
|
---|
833 | ui_pbutton_set_rect(demo.pb1, &rect);
|
---|
834 |
|
---|
835 | ui_pbutton_set_default(demo.pb1, true);
|
---|
836 |
|
---|
837 | rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb1));
|
---|
838 | if (rc != EOK) {
|
---|
839 | printf("Error adding control to layout.\n");
|
---|
840 | return rc;
|
---|
841 | }
|
---|
842 |
|
---|
843 | rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2);
|
---|
844 | if (rc != EOK) {
|
---|
845 | printf("Error creating button.\n");
|
---|
846 | return rc;
|
---|
847 | }
|
---|
848 |
|
---|
849 | ui_pbutton_set_cb(demo.pb2, &pbutton_cb, (void *) &demo);
|
---|
850 |
|
---|
851 | if (ui_is_textmode(ui)) {
|
---|
852 | rect.p0.x = 32;
|
---|
853 | rect.p0.y = 7;
|
---|
854 | rect.p1.x = 42;
|
---|
855 | rect.p1.y = 8;
|
---|
856 | } else {
|
---|
857 | rect.p0.x = 115;
|
---|
858 | rect.p0.y = 111;
|
---|
859 | rect.p1.x = 205;
|
---|
860 | rect.p1.y = 139;
|
---|
861 | }
|
---|
862 |
|
---|
863 | ui_pbutton_set_rect(demo.pb2, &rect);
|
---|
864 |
|
---|
865 | rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb2));
|
---|
866 | if (rc != EOK) {
|
---|
867 | printf("Error adding control to layout.\n");
|
---|
868 | return rc;
|
---|
869 | }
|
---|
870 |
|
---|
871 | gfx_bitmap_params_init(&bparams);
|
---|
872 | if (ui_is_textmode(ui)) {
|
---|
873 | bparams.rect.p0.x = 0;
|
---|
874 | bparams.rect.p0.y = 0;
|
---|
875 | bparams.rect.p1.x = 40;
|
---|
876 | bparams.rect.p1.y = 2;
|
---|
877 | } else {
|
---|
878 | bparams.rect.p0.x = 0;
|
---|
879 | bparams.rect.p0.y = 0;
|
---|
880 | bparams.rect.p1.x = 188;
|
---|
881 | bparams.rect.p1.y = 24;
|
---|
882 | }
|
---|
883 |
|
---|
884 | rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap);
|
---|
885 | if (rc != EOK)
|
---|
886 | return rc;
|
---|
887 |
|
---|
888 | rc = bitmap_moire(bitmap, bparams.rect.p1.x, bparams.rect.p1.y);
|
---|
889 | if (rc != EOK)
|
---|
890 | return rc;
|
---|
891 |
|
---|
892 | rc = ui_image_create(ui_res, bitmap, ¶ms.rect, &demo.image);
|
---|
893 | if (rc != EOK) {
|
---|
894 | printf("Error creating label.\n");
|
---|
895 | return rc;
|
---|
896 | }
|
---|
897 |
|
---|
898 | if (ui_is_textmode(ui)) {
|
---|
899 | off.x = 2;
|
---|
900 | off.y = 9;
|
---|
901 | } else {
|
---|
902 | off.x = 15;
|
---|
903 | off.y = 155;
|
---|
904 | }
|
---|
905 |
|
---|
906 | gfx_rect_translate(&off, &bparams.rect, &rect);
|
---|
907 |
|
---|
908 | /* Adjust for frame width (2 x 1 pixel) */
|
---|
909 | if (!ui_is_textmode(ui)) {
|
---|
910 | ui_image_set_flags(demo.image, ui_imgf_frame);
|
---|
911 | rect.p1.x += 2;
|
---|
912 | rect.p1.y += 2;
|
---|
913 | }
|
---|
914 |
|
---|
915 | ui_image_set_rect(demo.image, &rect);
|
---|
916 |
|
---|
917 | rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image));
|
---|
918 | if (rc != EOK) {
|
---|
919 | printf("Error adding control to layout.\n");
|
---|
920 | return rc;
|
---|
921 | }
|
---|
922 |
|
---|
923 | rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox);
|
---|
924 | if (rc != EOK) {
|
---|
925 | printf("Error creating check box.\n");
|
---|
926 | return rc;
|
---|
927 | }
|
---|
928 |
|
---|
929 | ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo);
|
---|
930 |
|
---|
931 | /* FIXME: Auto layout */
|
---|
932 | if (ui_is_textmode(ui)) {
|
---|
933 | rect.p0.x = 2;
|
---|
934 | rect.p0.y = 12;
|
---|
935 | rect.p1.x = 12;
|
---|
936 | rect.p1.y = 13;
|
---|
937 | } else {
|
---|
938 | rect.p0.x = 15;
|
---|
939 | rect.p0.y = 190;
|
---|
940 | rect.p1.x = 140;
|
---|
941 | rect.p1.y = 210;
|
---|
942 | }
|
---|
943 |
|
---|
944 | ui_checkbox_set_rect(demo.checkbox, &rect);
|
---|
945 |
|
---|
946 | rc = ui_fixed_add(demo.fixed, ui_checkbox_ctl(demo.checkbox));
|
---|
947 | if (rc != EOK) {
|
---|
948 | printf("Error adding control to layout.\n");
|
---|
949 | return rc;
|
---|
950 | }
|
---|
951 |
|
---|
952 | rc = ui_rbutton_group_create(ui_res, &demo.rbgroup);
|
---|
953 | if (rc != EOK) {
|
---|
954 | printf("Error creating radio button group.\n");
|
---|
955 | return rc;
|
---|
956 | }
|
---|
957 |
|
---|
958 | rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0],
|
---|
959 | &demo.rbleft);
|
---|
960 | if (rc != EOK) {
|
---|
961 | printf("Error creating radio button.\n");
|
---|
962 | return rc;
|
---|
963 | }
|
---|
964 |
|
---|
965 | ui_rbutton_group_set_cb(demo.rbgroup, &rbutton_group_cb,
|
---|
966 | (void *) &demo);
|
---|
967 |
|
---|
968 | /* FIXME: Auto layout */
|
---|
969 | if (ui_is_textmode(ui)) {
|
---|
970 | rect.p0.x = 2;
|
---|
971 | rect.p0.y = 14;
|
---|
972 | rect.p1.x = 12;
|
---|
973 | rect.p1.y = 15;
|
---|
974 | } else {
|
---|
975 | rect.p0.x = 15;
|
---|
976 | rect.p0.y = 220;
|
---|
977 | rect.p1.x = 140;
|
---|
978 | rect.p1.y = 240;
|
---|
979 | }
|
---|
980 | ui_rbutton_set_rect(demo.rbleft, &rect);
|
---|
981 |
|
---|
982 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbleft));
|
---|
983 | if (rc != EOK) {
|
---|
984 | printf("Error adding control to layout.\n");
|
---|
985 | return rc;
|
---|
986 | }
|
---|
987 |
|
---|
988 | rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1],
|
---|
989 | &demo.rbcenter);
|
---|
990 | if (rc != EOK) {
|
---|
991 | printf("Error creating radio button.\n");
|
---|
992 | return rc;
|
---|
993 | }
|
---|
994 |
|
---|
995 | /* FIXME: Auto layout */
|
---|
996 | if (ui_is_textmode(ui)) {
|
---|
997 | rect.p0.x = 2;
|
---|
998 | rect.p0.y = 15;
|
---|
999 | rect.p1.x = 12;
|
---|
1000 | rect.p1.y = 16;
|
---|
1001 | } else {
|
---|
1002 | rect.p0.x = 15;
|
---|
1003 | rect.p0.y = 250;
|
---|
1004 | rect.p1.x = 140;
|
---|
1005 | rect.p1.y = 270;
|
---|
1006 | }
|
---|
1007 | ui_rbutton_set_rect(demo.rbcenter, &rect);
|
---|
1008 | ui_rbutton_select(demo.rbcenter);
|
---|
1009 |
|
---|
1010 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbcenter));
|
---|
1011 | if (rc != EOK) {
|
---|
1012 | printf("Error adding control to layout.\n");
|
---|
1013 | return rc;
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2],
|
---|
1017 | &demo.rbright);
|
---|
1018 | if (rc != EOK) {
|
---|
1019 | printf("Error creating radio button.\n");
|
---|
1020 | return rc;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | /* FIXME: Auto layout */
|
---|
1024 | if (ui_is_textmode(ui)) {
|
---|
1025 | rect.p0.x = 2;
|
---|
1026 | rect.p0.y = 16;
|
---|
1027 | rect.p1.x = 12;
|
---|
1028 | rect.p1.y = 17;
|
---|
1029 | } else {
|
---|
1030 | rect.p0.x = 15;
|
---|
1031 | rect.p0.y = 280;
|
---|
1032 | rect.p1.x = 140;
|
---|
1033 | rect.p1.y = 300;
|
---|
1034 | }
|
---|
1035 | ui_rbutton_set_rect(demo.rbright, &rect);
|
---|
1036 |
|
---|
1037 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbright));
|
---|
1038 | if (rc != EOK) {
|
---|
1039 | printf("Error adding control to layout.\n");
|
---|
1040 | return rc;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | rc = ui_slider_create(ui_res, &demo.slider);
|
---|
1044 | if (rc != EOK) {
|
---|
1045 | printf("Error creating button.\n");
|
---|
1046 | return rc;
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo);
|
---|
1050 |
|
---|
1051 | /* FIXME: Auto layout */
|
---|
1052 | if (ui_is_textmode(ui)) {
|
---|
1053 | rect.p0.x = 2;
|
---|
1054 | rect.p0.y = 18;
|
---|
1055 | rect.p1.x = 12;
|
---|
1056 | rect.p1.y = 19;
|
---|
1057 | } else {
|
---|
1058 | rect.p0.x = 15;
|
---|
1059 | rect.p0.y = 310;
|
---|
1060 | rect.p1.x = 130;
|
---|
1061 | rect.p1.y = 330;
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | ui_slider_set_rect(demo.slider, &rect);
|
---|
1065 |
|
---|
1066 | rc = ui_fixed_add(demo.fixed, ui_slider_ctl(demo.slider));
|
---|
1067 | if (rc != EOK) {
|
---|
1068 | printf("Error adding control to layout.\n");
|
---|
1069 | return rc;
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | rc = ui_scrollbar_create(ui, window, &demo.scrollbar);
|
---|
1073 | if (rc != EOK) {
|
---|
1074 | printf("Error creating button.\n");
|
---|
1075 | return rc;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | ui_scrollbar_set_cb(demo.scrollbar, &scrollbar_cb, (void *) &demo);
|
---|
1079 |
|
---|
1080 | /* FIXME: Auto layout */
|
---|
1081 | if (ui_is_textmode(ui)) {
|
---|
1082 | rect.p0.x = 2;
|
---|
1083 | rect.p0.y = 20;
|
---|
1084 | rect.p1.x = 12;
|
---|
1085 | rect.p1.y = 21;
|
---|
1086 | } else {
|
---|
1087 | rect.p0.x = 15;
|
---|
1088 | rect.p0.y = 340;
|
---|
1089 | rect.p1.x = 210;
|
---|
1090 | rect.p1.y = 362;
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | ui_scrollbar_set_rect(demo.scrollbar, &rect);
|
---|
1094 |
|
---|
1095 | ui_scrollbar_set_thumb_length(demo.scrollbar,
|
---|
1096 | ui_scrollbar_through_length(demo.scrollbar) / 4);
|
---|
1097 |
|
---|
1098 | rc = ui_fixed_add(demo.fixed, ui_scrollbar_ctl(demo.scrollbar));
|
---|
1099 | if (rc != EOK) {
|
---|
1100 | printf("Error adding control to layout.\n");
|
---|
1101 | return rc;
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | ui_window_add(window, ui_fixed_ctl(demo.fixed));
|
---|
1105 |
|
---|
1106 | rc = ui_window_paint(window);
|
---|
1107 | if (rc != EOK) {
|
---|
1108 | printf("Error painting window.\n");
|
---|
1109 | return rc;
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | ui_run(ui);
|
---|
1113 |
|
---|
1114 | ui_window_destroy(window);
|
---|
1115 | ui_destroy(ui);
|
---|
1116 |
|
---|
1117 | return EOK;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | /** Fill bitmap with moire pattern.
|
---|
1121 | *
|
---|
1122 | * @param bitmap Bitmap
|
---|
1123 | * @param w Bitmap width
|
---|
1124 | * @param h Bitmap height
|
---|
1125 | * @return EOK on success or an error code
|
---|
1126 | */
|
---|
1127 | static errno_t bitmap_moire(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h)
|
---|
1128 | {
|
---|
1129 | int i, j;
|
---|
1130 | int k;
|
---|
1131 | pixelmap_t pixelmap;
|
---|
1132 | gfx_bitmap_alloc_t alloc;
|
---|
1133 | errno_t rc;
|
---|
1134 |
|
---|
1135 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
---|
1136 | if (rc != EOK)
|
---|
1137 | return rc;
|
---|
1138 |
|
---|
1139 | /* In absence of anything else, use pixelmap */
|
---|
1140 | pixelmap.width = w;
|
---|
1141 | pixelmap.height = h;
|
---|
1142 | pixelmap.data = alloc.pixels;
|
---|
1143 |
|
---|
1144 | for (i = 0; i < w; i++) {
|
---|
1145 | for (j = 0; j < h; j++) {
|
---|
1146 | k = i * i + j * j;
|
---|
1147 | pixelmap_put_pixel(&pixelmap, i, j,
|
---|
1148 | PIXEL(0, k, k, 255 - k));
|
---|
1149 | }
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 | return EOK;
|
---|
1153 | }
|
---|
1154 |
|
---|
1155 | static void print_syntax(void)
|
---|
1156 | {
|
---|
1157 | printf("Syntax: uidemo [-d <display-spec>]\n");
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | int main(int argc, char *argv[])
|
---|
1161 | {
|
---|
1162 | const char *display_spec = UI_ANY_DEFAULT;
|
---|
1163 | errno_t rc;
|
---|
1164 | int i;
|
---|
1165 |
|
---|
1166 | i = 1;
|
---|
1167 | while (i < argc && argv[i][0] == '-') {
|
---|
1168 | if (str_cmp(argv[i], "-d") == 0) {
|
---|
1169 | ++i;
|
---|
1170 | if (i >= argc) {
|
---|
1171 | printf("Argument missing.\n");
|
---|
1172 | print_syntax();
|
---|
1173 | return 1;
|
---|
1174 | }
|
---|
1175 |
|
---|
1176 | display_spec = argv[i++];
|
---|
1177 | } else {
|
---|
1178 | printf("Invalid option '%s'.\n", argv[i]);
|
---|
1179 | print_syntax();
|
---|
1180 | return 1;
|
---|
1181 | }
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | if (i < argc) {
|
---|
1185 | print_syntax();
|
---|
1186 | return 1;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | rc = ui_demo(display_spec);
|
---|
1190 | if (rc != EOK)
|
---|
1191 | return 1;
|
---|
1192 |
|
---|
1193 | return 0;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | /** @}
|
---|
1197 | */
|
---|