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