| 1 | /*
|
|---|
| 2 | * Copyright (c) 2021 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/resource.h>
|
|---|
| 52 | #include <ui/ui.h>
|
|---|
| 53 | #include <ui/window.h>
|
|---|
| 54 | #include "uidemo.h"
|
|---|
| 55 |
|
|---|
| 56 | static errno_t bitmap_moire(gfx_bitmap_t *, gfx_coord_t, gfx_coord_t);
|
|---|
| 57 |
|
|---|
| 58 | static void wnd_close(ui_window_t *, void *);
|
|---|
| 59 |
|
|---|
| 60 | static ui_window_cb_t window_cb = {
|
|---|
| 61 | .close = wnd_close
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | static void pb_clicked(ui_pbutton_t *, void *);
|
|---|
| 65 |
|
|---|
| 66 | static ui_pbutton_cb_t pbutton_cb = {
|
|---|
| 67 | .clicked = pb_clicked
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | static void checkbox_switched(ui_checkbox_t *, void *, bool);
|
|---|
| 71 |
|
|---|
| 72 | static ui_checkbox_cb_t checkbox_cb = {
|
|---|
| 73 | .switched = checkbox_switched
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 | static void rb_selected(ui_rbutton_group_t *, void *, void *);
|
|---|
| 77 |
|
|---|
| 78 | static ui_rbutton_group_cb_t rbutton_group_cb = {
|
|---|
| 79 | .selected = rb_selected
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 82 | static void slider_moved(ui_slider_t *, void *, gfx_coord_t);
|
|---|
| 83 |
|
|---|
| 84 | static ui_slider_cb_t slider_cb = {
|
|---|
| 85 | .moved = slider_moved
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | static void uidemo_file_load(ui_menu_entry_t *, void *);
|
|---|
| 89 | static void uidemo_file_message(ui_menu_entry_t *, void *);
|
|---|
| 90 | static void uidemo_file_exit(ui_menu_entry_t *, void *);
|
|---|
| 91 |
|
|---|
| 92 | static void file_dialog_bok(ui_file_dialog_t *, void *, const char *);
|
|---|
| 93 | static void file_dialog_bcancel(ui_file_dialog_t *, void *);
|
|---|
| 94 | static void file_dialog_close(ui_file_dialog_t *, void *);
|
|---|
| 95 |
|
|---|
| 96 | static ui_file_dialog_cb_t file_dialog_cb = {
|
|---|
| 97 | .bok = file_dialog_bok,
|
|---|
| 98 | .bcancel = file_dialog_bcancel,
|
|---|
| 99 | .close = file_dialog_close
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned);
|
|---|
| 103 | static void msg_dialog_close(ui_msg_dialog_t *, void *);
|
|---|
| 104 |
|
|---|
| 105 | static ui_msg_dialog_cb_t msg_dialog_cb = {
|
|---|
| 106 | .button = msg_dialog_button,
|
|---|
| 107 | .close = msg_dialog_close
|
|---|
| 108 | };
|
|---|
| 109 |
|
|---|
| 110 | /** Horizontal alignment selected by each radio button */
|
|---|
| 111 | static const gfx_halign_t uidemo_halign[3] = {
|
|---|
| 112 | gfx_halign_left,
|
|---|
| 113 | gfx_halign_center,
|
|---|
| 114 | gfx_halign_right
|
|---|
| 115 | };
|
|---|
| 116 |
|
|---|
| 117 | /** Window close button was clicked.
|
|---|
| 118 | *
|
|---|
| 119 | * @param window Window
|
|---|
| 120 | * @param arg Argument (demo)
|
|---|
| 121 | */
|
|---|
| 122 | static void wnd_close(ui_window_t *window, void *arg)
|
|---|
| 123 | {
|
|---|
| 124 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 125 |
|
|---|
| 126 | ui_quit(demo->ui);
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /** Push button was clicked.
|
|---|
| 130 | *
|
|---|
| 131 | * @param pbutton Push button
|
|---|
| 132 | * @param arg Argument (demo)
|
|---|
| 133 | */
|
|---|
| 134 | static void pb_clicked(ui_pbutton_t *pbutton, void *arg)
|
|---|
| 135 | {
|
|---|
| 136 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 137 | errno_t rc;
|
|---|
| 138 |
|
|---|
| 139 | if (pbutton == demo->pb1) {
|
|---|
| 140 | rc = ui_entry_set_text(demo->entry, "OK pressed");
|
|---|
| 141 | if (rc != EOK)
|
|---|
| 142 | printf("Error changing entry text.\n");
|
|---|
| 143 | } else {
|
|---|
| 144 | rc = ui_entry_set_text(demo->entry, "Cancel pressed");
|
|---|
| 145 | if (rc != EOK)
|
|---|
| 146 | printf("Error changing entry text.\n");
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /** Check box was switched.
|
|---|
| 151 | *
|
|---|
| 152 | * @param checkbox Check box
|
|---|
| 153 | * @param arg Argument (demo)
|
|---|
| 154 | */
|
|---|
| 155 | static void checkbox_switched(ui_checkbox_t *checkbox, void *arg, bool enable)
|
|---|
| 156 | {
|
|---|
| 157 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 158 |
|
|---|
| 159 | ui_entry_set_read_only(demo->entry, enable);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | /** Radio button was selected.
|
|---|
| 163 | *
|
|---|
| 164 | * @param rbgroup Radio button group
|
|---|
| 165 | * @param garg Group argument (demo)
|
|---|
| 166 | * @param barg Button argument
|
|---|
| 167 | */
|
|---|
| 168 | static void rb_selected(ui_rbutton_group_t *rbgroup, void *garg, void *barg)
|
|---|
| 169 | {
|
|---|
| 170 | ui_demo_t *demo = (ui_demo_t *) garg;
|
|---|
| 171 | gfx_halign_t halign = *(gfx_halign_t *) barg;
|
|---|
| 172 |
|
|---|
| 173 | ui_entry_set_halign(demo->entry, halign);
|
|---|
| 174 | (void) ui_entry_paint(demo->entry);
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | /** Slider was moved.
|
|---|
| 178 | *
|
|---|
| 179 | * @param slider Slider
|
|---|
| 180 | * @param arg Argument (demo)
|
|---|
| 181 | * @param pos Position
|
|---|
| 182 | */
|
|---|
| 183 | static void slider_moved(ui_slider_t *slider, void *arg, gfx_coord_t pos)
|
|---|
| 184 | {
|
|---|
| 185 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 186 | char *str;
|
|---|
| 187 | errno_t rc;
|
|---|
| 188 | int rv;
|
|---|
| 189 |
|
|---|
| 190 | rv = asprintf(&str, "Slider at %d of %d", (int) pos,
|
|---|
| 191 | ui_slider_length(slider));
|
|---|
| 192 | if (rv < 0) {
|
|---|
| 193 | printf("Out of memory.\n");
|
|---|
| 194 | return;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | rc = ui_entry_set_text(demo->entry, str);
|
|---|
| 198 | if (rc != EOK)
|
|---|
| 199 | printf("Error changing entry text.\n");
|
|---|
| 200 | (void) ui_entry_paint(demo->entry);
|
|---|
| 201 |
|
|---|
| 202 | free(str);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | /** Display a message window.
|
|---|
| 206 | *
|
|---|
| 207 | * @param demo UI demo
|
|---|
| 208 | * @param caption Window caption
|
|---|
| 209 | * @param text Message text
|
|---|
| 210 | */
|
|---|
| 211 | static void uidemo_show_message(ui_demo_t *demo, const char *caption,
|
|---|
| 212 | const char *text)
|
|---|
| 213 | {
|
|---|
| 214 | ui_msg_dialog_params_t mdparams;
|
|---|
| 215 | ui_msg_dialog_t *dialog;
|
|---|
| 216 | errno_t rc;
|
|---|
| 217 |
|
|---|
| 218 | ui_msg_dialog_params_init(&mdparams);
|
|---|
| 219 | mdparams.caption = caption;
|
|---|
| 220 | mdparams.text = text;
|
|---|
| 221 |
|
|---|
| 222 | rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
|
|---|
| 223 | if (rc != EOK) {
|
|---|
| 224 | printf("Error creating message dialog.\n");
|
|---|
| 225 | return;
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo);
|
|---|
| 229 | }
|
|---|
| 230 |
|
|---|
| 231 | /** File/load menu entry selected.
|
|---|
| 232 | *
|
|---|
| 233 | * @param mentry Menu entry
|
|---|
| 234 | * @param arg Argument (demo)
|
|---|
| 235 | */
|
|---|
| 236 | static void uidemo_file_load(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 237 | {
|
|---|
| 238 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 239 | ui_file_dialog_params_t fdparams;
|
|---|
| 240 | ui_file_dialog_t *dialog;
|
|---|
| 241 | errno_t rc;
|
|---|
| 242 |
|
|---|
| 243 | ui_file_dialog_params_init(&fdparams);
|
|---|
| 244 | fdparams.caption = "Load File";
|
|---|
| 245 |
|
|---|
| 246 | rc = ui_file_dialog_create(demo->ui, &fdparams, &dialog);
|
|---|
| 247 | if (rc != EOK) {
|
|---|
| 248 | printf("Error creating message dialog.\n");
|
|---|
| 249 | return;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | ui_file_dialog_set_cb(dialog, &file_dialog_cb, demo);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | /** File/message menu entry selected.
|
|---|
| 256 | *
|
|---|
| 257 | * @param mentry Menu entry
|
|---|
| 258 | * @param arg Argument (demo)
|
|---|
| 259 | */
|
|---|
| 260 | static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 261 | {
|
|---|
| 262 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 263 | ui_msg_dialog_params_t mdparams;
|
|---|
| 264 | ui_msg_dialog_t *dialog;
|
|---|
| 265 | errno_t rc;
|
|---|
| 266 |
|
|---|
| 267 | ui_msg_dialog_params_init(&mdparams);
|
|---|
| 268 | mdparams.caption = "Message For You";
|
|---|
| 269 | mdparams.text = "Hello, world!";
|
|---|
| 270 |
|
|---|
| 271 | rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog);
|
|---|
| 272 | if (rc != EOK) {
|
|---|
| 273 | printf("Error creating message dialog.\n");
|
|---|
| 274 | return;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo);
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | /** File/exit menu entry selected.
|
|---|
| 281 | *
|
|---|
| 282 | * @param mentry Menu entry
|
|---|
| 283 | * @param arg Argument (demo)
|
|---|
| 284 | */
|
|---|
| 285 | static void uidemo_file_exit(ui_menu_entry_t *mentry, void *arg)
|
|---|
| 286 | {
|
|---|
| 287 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 288 |
|
|---|
| 289 | ui_quit(demo->ui);
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | /** File dialog OK button press.
|
|---|
| 293 | *
|
|---|
| 294 | * @param dialog File dialog
|
|---|
| 295 | * @param arg Argument (ui_demo_t *)
|
|---|
| 296 | * @param fname File name
|
|---|
| 297 | */
|
|---|
| 298 | static void file_dialog_bok(ui_file_dialog_t *dialog, void *arg,
|
|---|
| 299 | const char *fname)
|
|---|
| 300 | {
|
|---|
| 301 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 302 | char buf[128];
|
|---|
| 303 | char *p;
|
|---|
| 304 | FILE *f;
|
|---|
| 305 |
|
|---|
| 306 | ui_file_dialog_destroy(dialog);
|
|---|
| 307 |
|
|---|
| 308 | f = fopen(fname, "rt");
|
|---|
| 309 | if (f == NULL) {
|
|---|
| 310 | uidemo_show_message(demo, "Error", "Error opening file.");
|
|---|
| 311 | return;
|
|---|
| 312 | }
|
|---|
| 313 |
|
|---|
| 314 | p = fgets(buf, sizeof(buf), f);
|
|---|
| 315 | if (p == NULL) {
|
|---|
| 316 | uidemo_show_message(demo, "Error", "Error reading file.");
|
|---|
| 317 | fclose(f);
|
|---|
| 318 | return;
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | /* Cut string off at the first non-printable character */
|
|---|
| 322 | p = buf;
|
|---|
| 323 | while (*p != '\0') {
|
|---|
| 324 | if (*p < ' ') {
|
|---|
| 325 | *p = '\0';
|
|---|
| 326 | break;
|
|---|
| 327 | }
|
|---|
| 328 | ++p;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | ui_entry_set_text(demo->entry, buf);
|
|---|
| 332 | fclose(f);
|
|---|
| 333 | }
|
|---|
| 334 |
|
|---|
| 335 | /** File dialog cancel button press.
|
|---|
| 336 | *
|
|---|
| 337 | * @param dialog File dialog
|
|---|
| 338 | * @param arg Argument (ui_demo_t *)
|
|---|
| 339 | */
|
|---|
| 340 | static void file_dialog_bcancel(ui_file_dialog_t *dialog, void *arg)
|
|---|
| 341 | {
|
|---|
| 342 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 343 |
|
|---|
| 344 | (void) demo;
|
|---|
| 345 | ui_file_dialog_destroy(dialog);
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | /** Message dialog close request.
|
|---|
| 349 | *
|
|---|
| 350 | * @param dialog File dialog
|
|---|
| 351 | * @param arg Argument (ui_demo_t *)
|
|---|
| 352 | */
|
|---|
| 353 | static void file_dialog_close(ui_file_dialog_t *dialog, void *arg)
|
|---|
| 354 | {
|
|---|
| 355 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 356 |
|
|---|
| 357 | (void) demo;
|
|---|
| 358 | ui_file_dialog_destroy(dialog);
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | /** Message dialog button press.
|
|---|
| 362 | *
|
|---|
| 363 | * @param dialog Message dialog
|
|---|
| 364 | * @param arg Argument (ui_demo_t *)
|
|---|
| 365 | * @param bnum Button number
|
|---|
| 366 | */
|
|---|
| 367 | static void msg_dialog_button(ui_msg_dialog_t *dialog, void *arg,
|
|---|
| 368 | unsigned bnum)
|
|---|
| 369 | {
|
|---|
| 370 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 371 |
|
|---|
| 372 | (void) demo;
|
|---|
| 373 | ui_msg_dialog_destroy(dialog);
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | /** Message dialog close request.
|
|---|
| 377 | *
|
|---|
| 378 | * @param dialog Message dialog
|
|---|
| 379 | * @param arg Argument (ui_demo_t *)
|
|---|
| 380 | */
|
|---|
| 381 | static void msg_dialog_close(ui_msg_dialog_t *dialog, void *arg)
|
|---|
| 382 | {
|
|---|
| 383 | ui_demo_t *demo = (ui_demo_t *) arg;
|
|---|
| 384 |
|
|---|
| 385 | (void) demo;
|
|---|
| 386 | ui_msg_dialog_destroy(dialog);
|
|---|
| 387 | }
|
|---|
| 388 |
|
|---|
| 389 | /** Run UI demo on display server. */
|
|---|
| 390 | static errno_t ui_demo(const char *display_spec)
|
|---|
| 391 | {
|
|---|
| 392 | ui_t *ui = NULL;
|
|---|
| 393 | ui_wnd_params_t params;
|
|---|
| 394 | ui_window_t *window = NULL;
|
|---|
| 395 | ui_demo_t demo;
|
|---|
| 396 | gfx_rect_t rect;
|
|---|
| 397 | gfx_context_t *gc;
|
|---|
| 398 | ui_resource_t *ui_res;
|
|---|
| 399 | gfx_bitmap_params_t bparams;
|
|---|
| 400 | gfx_bitmap_t *bitmap;
|
|---|
| 401 | gfx_coord2_t off;
|
|---|
| 402 | ui_menu_entry_t *mmsg;
|
|---|
| 403 | ui_menu_entry_t *mload;
|
|---|
| 404 | ui_menu_entry_t *mfoo;
|
|---|
| 405 | ui_menu_entry_t *mbar;
|
|---|
| 406 | ui_menu_entry_t *mfoobar;
|
|---|
| 407 | ui_menu_entry_t *mexit;
|
|---|
| 408 | ui_menu_entry_t *mabout;
|
|---|
| 409 | errno_t rc;
|
|---|
| 410 |
|
|---|
| 411 | rc = ui_create(display_spec, &ui);
|
|---|
| 412 | if (rc != EOK) {
|
|---|
| 413 | printf("Error creating UI on display %s.\n", display_spec);
|
|---|
| 414 | return rc;
|
|---|
| 415 | }
|
|---|
| 416 |
|
|---|
| 417 | memset((void *) &demo, 0, sizeof(demo));
|
|---|
| 418 | demo.ui = ui;
|
|---|
| 419 |
|
|---|
| 420 | ui_wnd_params_init(¶ms);
|
|---|
| 421 | params.caption = "UI Demo";
|
|---|
| 422 | params.style |= ui_wds_resizable;
|
|---|
| 423 |
|
|---|
| 424 | /* FIXME: Auto layout */
|
|---|
| 425 | if (ui_is_textmode(ui)) {
|
|---|
| 426 | params.rect.p0.x = 0;
|
|---|
| 427 | params.rect.p0.y = 0;
|
|---|
| 428 | params.rect.p1.x = 80;
|
|---|
| 429 | params.rect.p1.y = 25;
|
|---|
| 430 | } else {
|
|---|
| 431 | params.rect.p0.x = 0;
|
|---|
| 432 | params.rect.p0.y = 0;
|
|---|
| 433 | params.rect.p1.x = 220;
|
|---|
| 434 | params.rect.p1.y = 350;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 438 | if (rc != EOK) {
|
|---|
| 439 | printf("Error creating window.\n");
|
|---|
| 440 | return rc;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 | ui_window_set_cb(window, &window_cb, (void *) &demo);
|
|---|
| 444 | demo.window = window;
|
|---|
| 445 |
|
|---|
| 446 | ui_res = ui_window_get_res(window);
|
|---|
| 447 | gc = ui_window_get_gc(window);
|
|---|
| 448 |
|
|---|
| 449 | rc = ui_fixed_create(&demo.fixed);
|
|---|
| 450 | if (rc != EOK) {
|
|---|
| 451 | printf("Error creating fixed layout.\n");
|
|---|
| 452 | return rc;
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | rc = ui_menu_bar_create(ui, window, &demo.mbar);
|
|---|
| 456 | if (rc != EOK) {
|
|---|
| 457 | printf("Error creating menu bar.\n");
|
|---|
| 458 | return rc;
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | rc = ui_menu_create(demo.mbar, "File", &demo.mfile);
|
|---|
| 462 | if (rc != EOK) {
|
|---|
| 463 | printf("Error creating menu.\n");
|
|---|
| 464 | return rc;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | rc = ui_menu_entry_create(demo.mfile, "Message", "", &mmsg);
|
|---|
| 468 | if (rc != EOK) {
|
|---|
| 469 | printf("Error creating menu.\n");
|
|---|
| 470 | return rc;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo);
|
|---|
| 474 |
|
|---|
| 475 | rc = ui_menu_entry_create(demo.mfile, "Load", "", &mload);
|
|---|
| 476 | if (rc != EOK) {
|
|---|
| 477 | printf("Error creating menu.\n");
|
|---|
| 478 | return rc;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | ui_menu_entry_set_cb(mload, uidemo_file_load, (void *) &demo);
|
|---|
| 482 |
|
|---|
| 483 | rc = ui_menu_entry_create(demo.mfile, "Foo", "Ctrl-Alt-Del", &mfoo);
|
|---|
| 484 | if (rc != EOK) {
|
|---|
| 485 | printf("Error creating menu.\n");
|
|---|
| 486 | return rc;
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | rc = ui_menu_entry_create(demo.mfile, "Bar", "", &mbar);
|
|---|
| 490 | if (rc != EOK) {
|
|---|
| 491 | printf("Error creating menu.\n");
|
|---|
| 492 | return rc;
|
|---|
| 493 | }
|
|---|
| 494 |
|
|---|
| 495 | rc = ui_menu_entry_create(demo.mfile, "Foobar", "", &mfoobar);
|
|---|
| 496 | if (rc != EOK) {
|
|---|
| 497 | printf("Error creating menu.\n");
|
|---|
| 498 | return rc;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | rc = ui_menu_entry_sep_create(demo.mfile, &mexit);
|
|---|
| 502 | if (rc != EOK) {
|
|---|
| 503 | printf("Error creating menu.\n");
|
|---|
| 504 | return rc;
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | rc = ui_menu_entry_create(demo.mfile, "Exit", "Alt-F4", &mexit);
|
|---|
| 508 | if (rc != EOK) {
|
|---|
| 509 | printf("Error creating menu.\n");
|
|---|
| 510 | return rc;
|
|---|
| 511 | }
|
|---|
| 512 |
|
|---|
| 513 | ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo);
|
|---|
| 514 |
|
|---|
| 515 | rc = ui_menu_create(demo.mbar, "Edit", &demo.medit);
|
|---|
| 516 | if (rc != EOK) {
|
|---|
| 517 | printf("Error creating menu.\n");
|
|---|
| 518 | return rc;
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | rc = ui_menu_create(demo.mbar, "Preferences", &demo.mpreferences);
|
|---|
| 522 | if (rc != EOK) {
|
|---|
| 523 | printf("Error creating menu.\n");
|
|---|
| 524 | return rc;
|
|---|
| 525 | }
|
|---|
| 526 |
|
|---|
| 527 | rc = ui_menu_create(demo.mbar, "Help", &demo.mhelp);
|
|---|
| 528 | if (rc != EOK) {
|
|---|
| 529 | printf("Error creating menu.\n");
|
|---|
| 530 | return rc;
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|
| 533 | rc = ui_menu_entry_create(demo.mhelp, "About", "Ctrl-H, F1", &mabout);
|
|---|
| 534 | if (rc != EOK) {
|
|---|
| 535 | printf("Error creating menu.\n");
|
|---|
| 536 | return rc;
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | /* FIXME: Auto layout */
|
|---|
| 540 | if (ui_is_textmode(ui)) {
|
|---|
| 541 | rect.p0.x = 1;
|
|---|
| 542 | rect.p0.y = 2;
|
|---|
| 543 | rect.p1.x = 79;
|
|---|
| 544 | rect.p1.y = 3;
|
|---|
| 545 | } else {
|
|---|
| 546 | rect.p0.x = 4;
|
|---|
| 547 | rect.p0.y = 30;
|
|---|
| 548 | rect.p1.x = 216;
|
|---|
| 549 | rect.p1.y = 52;
|
|---|
| 550 | }
|
|---|
| 551 | ui_menu_bar_set_rect(demo.mbar, &rect);
|
|---|
| 552 |
|
|---|
| 553 | rc = ui_fixed_add(demo.fixed, ui_menu_bar_ctl(demo.mbar));
|
|---|
| 554 | if (rc != EOK) {
|
|---|
| 555 | printf("Error adding control to layout.\n");
|
|---|
| 556 | return rc;
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | rc = ui_entry_create(window, "", &demo.entry);
|
|---|
| 560 | if (rc != EOK) {
|
|---|
| 561 | printf("Error creating entry.\n");
|
|---|
| 562 | return rc;
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | /* FIXME: Auto layout */
|
|---|
| 566 | if (ui_is_textmode(ui)) {
|
|---|
| 567 | rect.p0.x = 20;
|
|---|
| 568 | rect.p0.y = 4;
|
|---|
| 569 | rect.p1.x = 60;
|
|---|
| 570 | rect.p1.y = 5;
|
|---|
| 571 | } else {
|
|---|
| 572 | rect.p0.x = 15;
|
|---|
| 573 | rect.p0.y = 53;
|
|---|
| 574 | rect.p1.x = 205;
|
|---|
| 575 | rect.p1.y = 78;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | ui_entry_set_rect(demo.entry, &rect);
|
|---|
| 579 | ui_entry_set_halign(demo.entry, gfx_halign_center);
|
|---|
| 580 |
|
|---|
| 581 | rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry));
|
|---|
| 582 | if (rc != EOK) {
|
|---|
| 583 | printf("Error adding control to layout.\n");
|
|---|
| 584 | return rc;
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | rc = ui_label_create(ui_res, "Text label", &demo.label);
|
|---|
| 588 | if (rc != EOK) {
|
|---|
| 589 | printf("Error creating label.\n");
|
|---|
| 590 | return rc;
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | /* FIXME: Auto layout */
|
|---|
| 594 | if (ui_is_textmode(ui)) {
|
|---|
| 595 | rect.p0.x = 20;
|
|---|
| 596 | rect.p0.y = 6;
|
|---|
| 597 | rect.p1.x = 60;
|
|---|
| 598 | rect.p1.y = 7;
|
|---|
| 599 | } else {
|
|---|
| 600 | rect.p0.x = 60;
|
|---|
| 601 | rect.p0.y = 88;
|
|---|
| 602 | rect.p1.x = 160;
|
|---|
| 603 | rect.p1.y = 101;
|
|---|
| 604 | }
|
|---|
| 605 |
|
|---|
| 606 | ui_label_set_rect(demo.label, &rect);
|
|---|
| 607 | ui_label_set_halign(demo.label, gfx_halign_center);
|
|---|
| 608 |
|
|---|
| 609 | rc = ui_fixed_add(demo.fixed, ui_label_ctl(demo.label));
|
|---|
| 610 | if (rc != EOK) {
|
|---|
| 611 | printf("Error adding control to layout.\n");
|
|---|
| 612 | return rc;
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | rc = ui_pbutton_create(ui_res, "OK", &demo.pb1);
|
|---|
| 616 | if (rc != EOK) {
|
|---|
| 617 | printf("Error creating button.\n");
|
|---|
| 618 | return rc;
|
|---|
| 619 | }
|
|---|
| 620 |
|
|---|
| 621 | ui_pbutton_set_cb(demo.pb1, &pbutton_cb, (void *) &demo);
|
|---|
| 622 |
|
|---|
| 623 | /* FIXME: Auto layout */
|
|---|
| 624 | if (ui_is_textmode(ui)) {
|
|---|
| 625 | rect.p0.x = 20;
|
|---|
| 626 | rect.p0.y = 8;
|
|---|
| 627 | rect.p1.x = 30;
|
|---|
| 628 | rect.p1.y = 9;
|
|---|
| 629 | } else {
|
|---|
| 630 | rect.p0.x = 15;
|
|---|
| 631 | rect.p0.y = 111;
|
|---|
| 632 | rect.p1.x = 105;
|
|---|
| 633 | rect.p1.y = 139;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| 636 | ui_pbutton_set_rect(demo.pb1, &rect);
|
|---|
| 637 |
|
|---|
| 638 | ui_pbutton_set_default(demo.pb1, true);
|
|---|
| 639 |
|
|---|
| 640 | rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb1));
|
|---|
| 641 | if (rc != EOK) {
|
|---|
| 642 | printf("Error adding control to layout.\n");
|
|---|
| 643 | return rc;
|
|---|
| 644 | }
|
|---|
| 645 |
|
|---|
| 646 | rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2);
|
|---|
| 647 | if (rc != EOK) {
|
|---|
| 648 | printf("Error creating button.\n");
|
|---|
| 649 | return rc;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | ui_pbutton_set_cb(demo.pb2, &pbutton_cb, (void *) &demo);
|
|---|
| 653 |
|
|---|
| 654 | if (ui_is_textmode(ui)) {
|
|---|
| 655 | rect.p0.x = 50;
|
|---|
| 656 | rect.p0.y = 8;
|
|---|
| 657 | rect.p1.x = 60;
|
|---|
| 658 | rect.p1.y = 9;
|
|---|
| 659 | } else {
|
|---|
| 660 | rect.p0.x = 115;
|
|---|
| 661 | rect.p0.y = 111;
|
|---|
| 662 | rect.p1.x = 205;
|
|---|
| 663 | rect.p1.y = 139;
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | ui_pbutton_set_rect(demo.pb2, &rect);
|
|---|
| 667 |
|
|---|
| 668 | rc = ui_fixed_add(demo.fixed, ui_pbutton_ctl(demo.pb2));
|
|---|
| 669 | if (rc != EOK) {
|
|---|
| 670 | printf("Error adding control to layout.\n");
|
|---|
| 671 | return rc;
|
|---|
| 672 | }
|
|---|
| 673 |
|
|---|
| 674 | gfx_bitmap_params_init(&bparams);
|
|---|
| 675 | bparams.rect.p0.x = 0;
|
|---|
| 676 | bparams.rect.p0.y = 0;
|
|---|
| 677 | bparams.rect.p1.x = 188;
|
|---|
| 678 | bparams.rect.p1.y = 24;
|
|---|
| 679 |
|
|---|
| 680 | rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap);
|
|---|
| 681 | if (rc != EOK)
|
|---|
| 682 | return rc;
|
|---|
| 683 |
|
|---|
| 684 | rc = bitmap_moire(bitmap, bparams.rect.p1.x, bparams.rect.p1.y);
|
|---|
| 685 | if (rc != EOK)
|
|---|
| 686 | return rc;
|
|---|
| 687 |
|
|---|
| 688 | rc = ui_image_create(ui_res, bitmap, ¶ms.rect, &demo.image);
|
|---|
| 689 | if (rc != EOK) {
|
|---|
| 690 | printf("Error creating label.\n");
|
|---|
| 691 | return rc;
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | off.x = 15;
|
|---|
| 695 | off.y = 155;
|
|---|
| 696 | gfx_rect_translate(&off, &bparams.rect, &rect);
|
|---|
| 697 |
|
|---|
| 698 | /* Adjust for frame width (2 x 1 pixel) */
|
|---|
| 699 | rect.p1.x += 2;
|
|---|
| 700 | rect.p1.y += 2;
|
|---|
| 701 | ui_image_set_rect(demo.image, &rect);
|
|---|
| 702 | ui_image_set_flags(demo.image, ui_imgf_frame);
|
|---|
| 703 |
|
|---|
| 704 | rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image));
|
|---|
| 705 | if (rc != EOK) {
|
|---|
| 706 | printf("Error adding control to layout.\n");
|
|---|
| 707 | return rc;
|
|---|
| 708 | }
|
|---|
| 709 |
|
|---|
| 710 | rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox);
|
|---|
| 711 | if (rc != EOK) {
|
|---|
| 712 | printf("Error creating check box.\n");
|
|---|
| 713 | return rc;
|
|---|
| 714 | }
|
|---|
| 715 |
|
|---|
| 716 | ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo);
|
|---|
| 717 |
|
|---|
| 718 | /* FIXME: Auto layout */
|
|---|
| 719 | if (ui_is_textmode(ui)) {
|
|---|
| 720 | rect.p0.x = 20;
|
|---|
| 721 | rect.p0.y = 12;
|
|---|
| 722 | rect.p1.x = 40;
|
|---|
| 723 | rect.p1.y = 13;
|
|---|
| 724 | } else {
|
|---|
| 725 | rect.p0.x = 15;
|
|---|
| 726 | rect.p0.y = 190;
|
|---|
| 727 | rect.p1.x = 140;
|
|---|
| 728 | rect.p1.y = 210;
|
|---|
| 729 | }
|
|---|
| 730 | ui_checkbox_set_rect(demo.checkbox, &rect);
|
|---|
| 731 |
|
|---|
| 732 | rc = ui_fixed_add(demo.fixed, ui_checkbox_ctl(demo.checkbox));
|
|---|
| 733 | if (rc != EOK) {
|
|---|
| 734 | printf("Error adding control to layout.\n");
|
|---|
| 735 | return rc;
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | rc = ui_rbutton_group_create(ui_res, &demo.rbgroup);
|
|---|
| 739 | if (rc != EOK) {
|
|---|
| 740 | printf("Error creating radio button group.\n");
|
|---|
| 741 | return rc;
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0],
|
|---|
| 745 | &demo.rbleft);
|
|---|
| 746 | if (rc != EOK) {
|
|---|
| 747 | printf("Error creating radio button.\n");
|
|---|
| 748 | return rc;
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | ui_rbutton_group_set_cb(demo.rbgroup, &rbutton_group_cb,
|
|---|
| 752 | (void *) &demo);
|
|---|
| 753 |
|
|---|
| 754 | /* FIXME: Auto layout */
|
|---|
| 755 | if (ui_is_textmode(ui)) {
|
|---|
| 756 | rect.p0.x = 20;
|
|---|
| 757 | rect.p0.y = 14;
|
|---|
| 758 | rect.p1.x = 40;
|
|---|
| 759 | rect.p1.y = 15;
|
|---|
| 760 | } else {
|
|---|
| 761 | rect.p0.x = 15;
|
|---|
| 762 | rect.p0.y = 220;
|
|---|
| 763 | rect.p1.x = 140;
|
|---|
| 764 | rect.p1.y = 240;
|
|---|
| 765 | }
|
|---|
| 766 | ui_rbutton_set_rect(demo.rbleft, &rect);
|
|---|
| 767 |
|
|---|
| 768 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbleft));
|
|---|
| 769 | if (rc != EOK) {
|
|---|
| 770 | printf("Error adding control to layout.\n");
|
|---|
| 771 | return rc;
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1],
|
|---|
| 775 | &demo.rbcenter);
|
|---|
| 776 | if (rc != EOK) {
|
|---|
| 777 | printf("Error creating radio button.\n");
|
|---|
| 778 | return rc;
|
|---|
| 779 | }
|
|---|
| 780 |
|
|---|
| 781 | /* FIXME: Auto layout */
|
|---|
| 782 | if (ui_is_textmode(ui)) {
|
|---|
| 783 | rect.p0.x = 20;
|
|---|
| 784 | rect.p0.y = 15;
|
|---|
| 785 | rect.p1.x = 40;
|
|---|
| 786 | rect.p1.y = 16;
|
|---|
| 787 | } else {
|
|---|
| 788 | rect.p0.x = 15;
|
|---|
| 789 | rect.p0.y = 250;
|
|---|
| 790 | rect.p1.x = 140;
|
|---|
| 791 | rect.p1.y = 270;
|
|---|
| 792 | }
|
|---|
| 793 | ui_rbutton_set_rect(demo.rbcenter, &rect);
|
|---|
| 794 | ui_rbutton_select(demo.rbcenter);
|
|---|
| 795 |
|
|---|
| 796 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbcenter));
|
|---|
| 797 | if (rc != EOK) {
|
|---|
| 798 | printf("Error adding control to layout.\n");
|
|---|
| 799 | return rc;
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2],
|
|---|
| 803 | &demo.rbright);
|
|---|
| 804 | if (rc != EOK) {
|
|---|
| 805 | printf("Error creating radio button.\n");
|
|---|
| 806 | return rc;
|
|---|
| 807 | }
|
|---|
| 808 |
|
|---|
| 809 | /* FIXME: Auto layout */
|
|---|
| 810 | if (ui_is_textmode(ui)) {
|
|---|
| 811 | rect.p0.x = 20;
|
|---|
| 812 | rect.p0.y = 16;
|
|---|
| 813 | rect.p1.x = 40;
|
|---|
| 814 | rect.p1.y = 17;
|
|---|
| 815 | } else {
|
|---|
| 816 | rect.p0.x = 15;
|
|---|
| 817 | rect.p0.y = 280;
|
|---|
| 818 | rect.p1.x = 140;
|
|---|
| 819 | rect.p1.y = 300;
|
|---|
| 820 | }
|
|---|
| 821 | ui_rbutton_set_rect(demo.rbright, &rect);
|
|---|
| 822 |
|
|---|
| 823 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbright));
|
|---|
| 824 | if (rc != EOK) {
|
|---|
| 825 | printf("Error adding control to layout.\n");
|
|---|
| 826 | return rc;
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | rc = ui_slider_create(ui_res, "Slide!", &demo.slider);
|
|---|
| 830 | if (rc != EOK) {
|
|---|
| 831 | printf("Error creating button.\n");
|
|---|
| 832 | return rc;
|
|---|
| 833 | }
|
|---|
| 834 |
|
|---|
| 835 | ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo);
|
|---|
| 836 |
|
|---|
| 837 | rect.p0.x = 15;
|
|---|
| 838 | rect.p0.y = 310;
|
|---|
| 839 | rect.p1.x = 130;
|
|---|
| 840 | rect.p1.y = 330;
|
|---|
| 841 | ui_slider_set_rect(demo.slider, &rect);
|
|---|
| 842 |
|
|---|
| 843 | rc = ui_fixed_add(demo.fixed, ui_slider_ctl(demo.slider));
|
|---|
| 844 | if (rc != EOK) {
|
|---|
| 845 | printf("Error adding control to layout.\n");
|
|---|
| 846 | return rc;
|
|---|
| 847 | }
|
|---|
| 848 |
|
|---|
| 849 | ui_window_add(window, ui_fixed_ctl(demo.fixed));
|
|---|
| 850 |
|
|---|
| 851 | rc = ui_window_paint(window);
|
|---|
| 852 | if (rc != EOK) {
|
|---|
| 853 | printf("Error painting window.\n");
|
|---|
| 854 | return rc;
|
|---|
| 855 | }
|
|---|
| 856 |
|
|---|
| 857 | ui_run(ui);
|
|---|
| 858 |
|
|---|
| 859 | ui_window_destroy(window);
|
|---|
| 860 | ui_destroy(ui);
|
|---|
| 861 |
|
|---|
| 862 | return EOK;
|
|---|
| 863 | }
|
|---|
| 864 |
|
|---|
| 865 | /** Fill bitmap with moire pattern.
|
|---|
| 866 | *
|
|---|
| 867 | * @param bitmap Bitmap
|
|---|
| 868 | * @param w Bitmap width
|
|---|
| 869 | * @param h Bitmap height
|
|---|
| 870 | * @return EOK on success or an error code
|
|---|
| 871 | */
|
|---|
| 872 | static errno_t bitmap_moire(gfx_bitmap_t *bitmap, gfx_coord_t w, gfx_coord_t h)
|
|---|
| 873 | {
|
|---|
| 874 | int i, j;
|
|---|
| 875 | int k;
|
|---|
| 876 | pixelmap_t pixelmap;
|
|---|
| 877 | gfx_bitmap_alloc_t alloc;
|
|---|
| 878 | errno_t rc;
|
|---|
| 879 |
|
|---|
| 880 | rc = gfx_bitmap_get_alloc(bitmap, &alloc);
|
|---|
| 881 | if (rc != EOK)
|
|---|
| 882 | return rc;
|
|---|
| 883 |
|
|---|
| 884 | /* In absence of anything else, use pixelmap */
|
|---|
| 885 | pixelmap.width = w;
|
|---|
| 886 | pixelmap.height = h;
|
|---|
| 887 | pixelmap.data = alloc.pixels;
|
|---|
| 888 |
|
|---|
| 889 | for (i = 0; i < w; i++) {
|
|---|
| 890 | for (j = 0; j < h; j++) {
|
|---|
| 891 | k = i * i + j * j;
|
|---|
| 892 | pixelmap_put_pixel(&pixelmap, i, j,
|
|---|
| 893 | PIXEL(255, k, k, 255 - k));
|
|---|
| 894 | }
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 | return EOK;
|
|---|
| 898 | }
|
|---|
| 899 |
|
|---|
| 900 | static void print_syntax(void)
|
|---|
| 901 | {
|
|---|
| 902 | printf("Syntax: uidemo [-d <display-spec>]\n");
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | int main(int argc, char *argv[])
|
|---|
| 906 | {
|
|---|
| 907 | const char *display_spec = UI_DISPLAY_DEFAULT;
|
|---|
| 908 | errno_t rc;
|
|---|
| 909 | int i;
|
|---|
| 910 |
|
|---|
| 911 | i = 1;
|
|---|
| 912 | while (i < argc && argv[i][0] == '-') {
|
|---|
| 913 | if (str_cmp(argv[i], "-d") == 0) {
|
|---|
| 914 | ++i;
|
|---|
| 915 | if (i >= argc) {
|
|---|
| 916 | printf("Argument missing.\n");
|
|---|
| 917 | print_syntax();
|
|---|
| 918 | return 1;
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 | display_spec = argv[i++];
|
|---|
| 922 | } else {
|
|---|
| 923 | printf("Invalid option '%s'.\n", argv[i]);
|
|---|
| 924 | print_syntax();
|
|---|
| 925 | return 1;
|
|---|
| 926 | }
|
|---|
| 927 | }
|
|---|
| 928 |
|
|---|
| 929 | if (i < argc) {
|
|---|
| 930 | print_syntax();
|
|---|
| 931 | return 1;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | rc = ui_demo(display_spec);
|
|---|
| 935 | if (rc != EOK)
|
|---|
| 936 | return 1;
|
|---|
| 937 |
|
|---|
| 938 | return 0;
|
|---|
| 939 | }
|
|---|
| 940 |
|
|---|
| 941 | /** @}
|
|---|
| 942 | */
|
|---|