[f80690a] | 1 | /*
|
---|
[c88d7f99] | 2 | * Copyright (c) 2022 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 |
|
---|
[bd16113] | 89 | static void scrollbar_up(ui_scrollbar_t *, void *);
|
---|
| 90 | static void scrollbar_down(ui_scrollbar_t *, void *);
|
---|
[1026cc4] | 91 | static void scrollbar_page_up(ui_scrollbar_t *, void *);
|
---|
| 92 | static void scrollbar_page_down(ui_scrollbar_t *, void *);
|
---|
[bd16113] | 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,
|
---|
[1026cc4] | 98 | .page_up = scrollbar_page_up,
|
---|
| 99 | .page_down = scrollbar_page_down,
|
---|
[bd16113] | 100 | .moved = scrollbar_moved
|
---|
| 101 | };
|
---|
| 102 |
|
---|
[5e109e1] | 103 | static void uidemo_file_load(ui_menu_entry_t *, void *);
|
---|
[252d03c] | 104 | static void uidemo_file_message(ui_menu_entry_t *, void *);
|
---|
[214aefb] | 105 | static void uidemo_file_exit(ui_menu_entry_t *, void *);
|
---|
[80d4aea] | 106 | static void uidemo_edit_modify(ui_menu_entry_t *, void *);
|
---|
[214aefb] | 107 |
|
---|
[5e109e1] | 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 |
|
---|
[80d4aea] | 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 |
|
---|
[252d03c] | 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 |
|
---|
[5de71df] | 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 |
|
---|
[d284ce9] | 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)
|
---|
[47728678] | 149 | {
|
---|
[20d2c6c] | 150 | ui_demo_t *demo = (ui_demo_t *) arg;
|
---|
| 151 |
|
---|
[d284ce9] | 152 | ui_quit(demo->ui);
|
---|
[47728678] | 153 | }
|
---|
| 154 |
|
---|
[8ef48ece] | 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;
|
---|
[ba09d06] | 163 | errno_t rc;
|
---|
[8ef48ece] | 164 |
|
---|
| 165 | if (pbutton == demo->pb1) {
|
---|
[d8ddf7a] | 166 | rc = ui_entry_set_text(demo->entry, "OK pressed");
|
---|
[ba09d06] | 167 | if (rc != EOK)
|
---|
[d8ddf7a] | 168 | printf("Error changing entry text.\n");
|
---|
[8ef48ece] | 169 | } else {
|
---|
[d8ddf7a] | 170 | rc = ui_entry_set_text(demo->entry, "Cancel pressed");
|
---|
[ba09d06] | 171 | if (rc != EOK)
|
---|
[d8ddf7a] | 172 | printf("Error changing entry text.\n");
|
---|
[8ef48ece] | 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[d70dc1c4] | 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 |
|
---|
[5de71df] | 185 | ui_entry_set_read_only(demo->entry, enable);
|
---|
[d70dc1c4] | 186 | }
|
---|
| 187 |
|
---|
[7020d1f] | 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;
|
---|
[5de71df] | 197 | gfx_halign_t halign = *(gfx_halign_t *) barg;
|
---|
[7020d1f] | 198 |
|
---|
[5de71df] | 199 | ui_entry_set_halign(demo->entry, halign);
|
---|
[7020d1f] | 200 | (void) ui_entry_paint(demo->entry);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
[ef734b7] | 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 |
|
---|
[bd16113] | 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);
|
---|
[1026cc4] | 244 | scrollbar_moved(scrollbar, arg, pos);
|
---|
[bd16113] | 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);
|
---|
[1026cc4] | 260 | scrollbar_moved(scrollbar, arg, pos);
|
---|
| 261 | }
|
---|
[bd16113] | 262 |
|
---|
[1026cc4] | 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;
|
---|
[bd16113] | 271 |
|
---|
[1026cc4] | 272 | pos = ui_scrollbar_get_pos(scrollbar);
|
---|
| 273 | ui_scrollbar_set_pos(scrollbar, pos -
|
---|
| 274 | ui_scrollbar_through_length(scrollbar) / 4);
|
---|
[bd16113] | 275 |
|
---|
[1026cc4] | 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);
|
---|
[bd16113] | 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 |
|
---|
[5e109e1] | 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 |
|
---|
[80d4aea] | 352 | /** File / Load menu entry selected.
|
---|
[5e109e1] | 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 |
|
---|
[80d4aea] | 376 | /** File / Message menu entry selected.
|
---|
[252d03c] | 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 |
|
---|
[80d4aea] | 401 | /** File / Exit menu entry selected.
|
---|
[214aefb] | 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 |
|
---|
[80d4aea] | 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 |
|
---|
[5e109e1] | 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 |
|
---|
[80d4aea] | 494 | /** File dialog close request.
|
---|
[5e109e1] | 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 |
|
---|
[80d4aea] | 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 |
|
---|
[252d03c] | 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 |
|
---|
[47728678] | 576 | /** Run UI demo on display server. */
|
---|
[d284ce9] | 577 | static errno_t ui_demo(const char *display_spec)
|
---|
[47728678] | 578 | {
|
---|
[d284ce9] | 579 | ui_t *ui = NULL;
|
---|
| 580 | ui_wnd_params_t params;
|
---|
| 581 | ui_window_t *window = NULL;
|
---|
[f6df5a3] | 582 | ui_demo_t demo;
|
---|
[47728678] | 583 | gfx_rect_t rect;
|
---|
[d8ddf7a] | 584 | gfx_context_t *gc;
|
---|
[3583ffb] | 585 | ui_resource_t *ui_res;
|
---|
[d8ddf7a] | 586 | gfx_bitmap_params_t bparams;
|
---|
| 587 | gfx_bitmap_t *bitmap;
|
---|
| 588 | gfx_coord2_t off;
|
---|
[252d03c] | 589 | ui_menu_entry_t *mmsg;
|
---|
[5e109e1] | 590 | ui_menu_entry_t *mload;
|
---|
[214aefb] | 591 | ui_menu_entry_t *mfoo;
|
---|
| 592 | ui_menu_entry_t *mbar;
|
---|
| 593 | ui_menu_entry_t *mfoobar;
|
---|
[80d4aea] | 594 | ui_menu_entry_t *msep;
|
---|
[214aefb] | 595 | ui_menu_entry_t *mexit;
|
---|
[80d4aea] | 596 | ui_menu_entry_t *mmodify;
|
---|
[214aefb] | 597 | ui_menu_entry_t *mabout;
|
---|
[47728678] | 598 | errno_t rc;
|
---|
| 599 |
|
---|
[d284ce9] | 600 | rc = ui_create(display_spec, &ui);
|
---|
[47728678] | 601 | if (rc != EOK) {
|
---|
[d284ce9] | 602 | printf("Error creating UI on display %s.\n", display_spec);
|
---|
[47728678] | 603 | return rc;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
[252d03c] | 606 | memset((void *) &demo, 0, sizeof(demo));
|
---|
| 607 | demo.ui = ui;
|
---|
| 608 |
|
---|
[d284ce9] | 609 | ui_wnd_params_init(¶ms);
|
---|
| 610 | params.caption = "UI Demo";
|
---|
[2d879f7] | 611 | params.style |= ui_wds_resizable;
|
---|
[47728678] | 612 |
|
---|
[252d03c] | 613 | /* FIXME: Auto layout */
|
---|
| 614 | if (ui_is_textmode(ui)) {
|
---|
| 615 | params.rect.p0.x = 0;
|
---|
| 616 | params.rect.p0.y = 0;
|
---|
[ab3bfc1] | 617 | params.rect.p1.x = 44;
|
---|
[bd16113] | 618 | params.rect.p1.y = 23;
|
---|
[252d03c] | 619 | } else {
|
---|
| 620 | params.rect.p0.x = 0;
|
---|
| 621 | params.rect.p0.y = 0;
|
---|
| 622 | params.rect.p1.x = 220;
|
---|
[bd16113] | 623 | params.rect.p1.y = 370;
|
---|
[252d03c] | 624 | }
|
---|
[1769693] | 625 |
|
---|
[d284ce9] | 626 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
[47728678] | 627 | if (rc != EOK) {
|
---|
| 628 | printf("Error creating window.\n");
|
---|
| 629 | return rc;
|
---|
| 630 | }
|
---|
| 631 |
|
---|
[d284ce9] | 632 | ui_window_set_cb(window, &window_cb, (void *) &demo);
|
---|
| 633 | demo.window = window;
|
---|
[47728678] | 634 |
|
---|
[3583ffb] | 635 | ui_res = ui_window_get_res(window);
|
---|
[d8ddf7a] | 636 | gc = ui_window_get_gc(window);
|
---|
[3583ffb] | 637 |
|
---|
[8009dc27] | 638 | rc = ui_fixed_create(&demo.fixed);
|
---|
| 639 | if (rc != EOK) {
|
---|
| 640 | printf("Error creating fixed layout.\n");
|
---|
| 641 | return rc;
|
---|
| 642 | }
|
---|
| 643 |
|
---|
[c68c18b9] | 644 | rc = ui_menu_bar_create(ui, window, &demo.mbar);
|
---|
[214aefb] | 645 | if (rc != EOK) {
|
---|
| 646 | printf("Error creating menu bar.\n");
|
---|
| 647 | return rc;
|
---|
| 648 | }
|
---|
| 649 |
|
---|
[ca2680d] | 650 | rc = ui_menu_create(demo.mbar, "~F~ile", &demo.mfile);
|
---|
[214aefb] | 651 | if (rc != EOK) {
|
---|
| 652 | printf("Error creating menu.\n");
|
---|
| 653 | return rc;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[c88d7f99] | 656 | rc = ui_menu_entry_create(demo.mfile, "~M~essage", "", &mmsg);
|
---|
[252d03c] | 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 |
|
---|
[c88d7f99] | 664 | rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload);
|
---|
[5e109e1] | 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 |
|
---|
[c88d7f99] | 672 | rc = ui_menu_entry_create(demo.mfile, "~F~oo", "Ctrl-Alt-Del", &mfoo);
|
---|
[214aefb] | 673 | if (rc != EOK) {
|
---|
| 674 | printf("Error creating menu.\n");
|
---|
| 675 | return rc;
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[c88d7f99] | 678 | rc = ui_menu_entry_create(demo.mfile, "~B~ar", "", &mbar);
|
---|
[214aefb] | 679 | if (rc != EOK) {
|
---|
| 680 | printf("Error creating menu.\n");
|
---|
| 681 | return rc;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
[c88d7f99] | 684 | rc = ui_menu_entry_create(demo.mfile, "F~o~obar", "", &mfoobar);
|
---|
[214aefb] | 685 | if (rc != EOK) {
|
---|
| 686 | printf("Error creating menu.\n");
|
---|
| 687 | return rc;
|
---|
| 688 | }
|
---|
| 689 |
|
---|
[80d4aea] | 690 | rc = ui_menu_entry_sep_create(demo.mfile, &msep);
|
---|
[6186f9f] | 691 | if (rc != EOK) {
|
---|
| 692 | printf("Error creating menu.\n");
|
---|
| 693 | return rc;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[c88d7f99] | 696 | rc = ui_menu_entry_create(demo.mfile, "E~x~it", "Alt-F4", &mexit);
|
---|
[214aefb] | 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 |
|
---|
[ca2680d] | 704 | rc = ui_menu_create(demo.mbar, "~E~dit", &demo.medit);
|
---|
[214aefb] | 705 | if (rc != EOK) {
|
---|
| 706 | printf("Error creating menu.\n");
|
---|
| 707 | return rc;
|
---|
| 708 | }
|
---|
| 709 |
|
---|
[c88d7f99] | 710 | rc = ui_menu_entry_create(demo.medit, "~M~odify", "", &mmodify);
|
---|
[80d4aea] | 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 |
|
---|
[ca2680d] | 718 | rc = ui_menu_create(demo.mbar, "~P~references", &demo.mpreferences);
|
---|
[214aefb] | 719 | if (rc != EOK) {
|
---|
| 720 | printf("Error creating menu.\n");
|
---|
| 721 | return rc;
|
---|
| 722 | }
|
---|
| 723 |
|
---|
[ca2680d] | 724 | rc = ui_menu_create(demo.mbar, "~H~elp", &demo.mhelp);
|
---|
[214aefb] | 725 | if (rc != EOK) {
|
---|
| 726 | printf("Error creating menu.\n");
|
---|
| 727 | return rc;
|
---|
| 728 | }
|
---|
| 729 |
|
---|
[c88d7f99] | 730 | rc = ui_menu_entry_create(demo.mhelp, "~A~bout", "Ctrl-H, F1", &mabout);
|
---|
[214aefb] | 731 | if (rc != EOK) {
|
---|
| 732 | printf("Error creating menu.\n");
|
---|
| 733 | return rc;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[252d03c] | 736 | /* FIXME: Auto layout */
|
---|
| 737 | if (ui_is_textmode(ui)) {
|
---|
| 738 | rect.p0.x = 1;
|
---|
[45004f3] | 739 | rect.p0.y = 1;
|
---|
[ab3bfc1] | 740 | rect.p1.x = 43;
|
---|
[45004f3] | 741 | rect.p1.y = 2;
|
---|
[252d03c] | 742 | } else {
|
---|
| 743 | rect.p0.x = 4;
|
---|
| 744 | rect.p0.y = 30;
|
---|
| 745 | rect.p1.x = 216;
|
---|
| 746 | rect.p1.y = 52;
|
---|
| 747 | }
|
---|
[214aefb] | 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 |
|
---|
[db3895d] | 756 | rc = ui_entry_create(window, "", &demo.entry);
|
---|
[214aefb] | 757 | if (rc != EOK) {
|
---|
| 758 | printf("Error creating entry.\n");
|
---|
| 759 | return rc;
|
---|
| 760 | }
|
---|
| 761 |
|
---|
[a977e37] | 762 | /* FIXME: Auto layout */
|
---|
| 763 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 764 | rect.p0.x = 2;
|
---|
| 765 | rect.p0.y = 3;
|
---|
| 766 | rect.p1.x = 42;
|
---|
| 767 | rect.p1.y = 4;
|
---|
[a977e37] | 768 | } else {
|
---|
| 769 | rect.p0.x = 15;
|
---|
| 770 | rect.p0.y = 53;
|
---|
| 771 | rect.p1.x = 205;
|
---|
| 772 | rect.p1.y = 78;
|
---|
| 773 | }
|
---|
| 774 |
|
---|
[214aefb] | 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 |
|
---|
[d8ddf7a] | 784 | rc = ui_label_create(ui_res, "Text label", &demo.label);
|
---|
[ba09d06] | 785 | if (rc != EOK) {
|
---|
| 786 | printf("Error creating label.\n");
|
---|
| 787 | return rc;
|
---|
| 788 | }
|
---|
| 789 |
|
---|
[a977e37] | 790 | /* FIXME: Auto layout */
|
---|
| 791 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 792 | rect.p0.x = 2;
|
---|
| 793 | rect.p0.y = 5;
|
---|
| 794 | rect.p1.x = 42;
|
---|
| 795 | rect.p1.y = 6;
|
---|
[a977e37] | 796 | } else {
|
---|
| 797 | rect.p0.x = 60;
|
---|
| 798 | rect.p0.y = 88;
|
---|
| 799 | rect.p1.x = 160;
|
---|
| 800 | rect.p1.y = 101;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
[ba09d06] | 803 | ui_label_set_rect(demo.label, &rect);
|
---|
[58a67050] | 804 | ui_label_set_halign(demo.label, gfx_halign_center);
|
---|
[ba09d06] | 805 |
|
---|
[8009dc27] | 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 |
|
---|
[d8ddf7a] | 812 | rc = ui_pbutton_create(ui_res, "OK", &demo.pb1);
|
---|
[47728678] | 813 | if (rc != EOK) {
|
---|
| 814 | printf("Error creating button.\n");
|
---|
[f6df5a3] | 815 | return rc;
|
---|
[47728678] | 816 | }
|
---|
| 817 |
|
---|
[8ef48ece] | 818 | ui_pbutton_set_cb(demo.pb1, &pbutton_cb, (void *) &demo);
|
---|
| 819 |
|
---|
[a977e37] | 820 | /* FIXME: Auto layout */
|
---|
| 821 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 822 | rect.p0.x = 2;
|
---|
| 823 | rect.p0.y = 7;
|
---|
| 824 | rect.p1.x = 12;
|
---|
| 825 | rect.p1.y = 8;
|
---|
[a977e37] | 826 | } else {
|
---|
| 827 | rect.p0.x = 15;
|
---|
| 828 | rect.p0.y = 111;
|
---|
| 829 | rect.p1.x = 105;
|
---|
| 830 | rect.p1.y = 139;
|
---|
| 831 | }
|
---|
| 832 |
|
---|
[f6df5a3] | 833 | ui_pbutton_set_rect(demo.pb1, &rect);
|
---|
[47728678] | 834 |
|
---|
[c9a7adc] | 835 | ui_pbutton_set_default(demo.pb1, true);
|
---|
| 836 |
|
---|
[8009dc27] | 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 |
|
---|
[3583ffb] | 843 | rc = ui_pbutton_create(ui_res, "Cancel", &demo.pb2);
|
---|
[47728678] | 844 | if (rc != EOK) {
|
---|
| 845 | printf("Error creating button.\n");
|
---|
[f6df5a3] | 846 | return rc;
|
---|
[47728678] | 847 | }
|
---|
| 848 |
|
---|
[8ef48ece] | 849 | ui_pbutton_set_cb(demo.pb2, &pbutton_cb, (void *) &demo);
|
---|
| 850 |
|
---|
[a977e37] | 851 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 852 | rect.p0.x = 32;
|
---|
| 853 | rect.p0.y = 7;
|
---|
| 854 | rect.p1.x = 42;
|
---|
| 855 | rect.p1.y = 8;
|
---|
[a977e37] | 856 | } else {
|
---|
| 857 | rect.p0.x = 115;
|
---|
| 858 | rect.p0.y = 111;
|
---|
| 859 | rect.p1.x = 205;
|
---|
| 860 | rect.p1.y = 139;
|
---|
| 861 | }
|
---|
| 862 |
|
---|
[f6df5a3] | 863 | ui_pbutton_set_rect(demo.pb2, &rect);
|
---|
[47728678] | 864 |
|
---|
[8009dc27] | 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 |
|
---|
[d8ddf7a] | 871 | gfx_bitmap_params_init(&bparams);
|
---|
[de0c55a] | 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 | }
|
---|
[d8ddf7a] | 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 |
|
---|
[de0c55a] | 898 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 899 | off.x = 2;
|
---|
| 900 | off.y = 9;
|
---|
[de0c55a] | 901 | } else {
|
---|
| 902 | off.x = 15;
|
---|
| 903 | off.y = 155;
|
---|
| 904 | }
|
---|
| 905 |
|
---|
[d8ddf7a] | 906 | gfx_rect_translate(&off, &bparams.rect, &rect);
|
---|
| 907 |
|
---|
| 908 | /* Adjust for frame width (2 x 1 pixel) */
|
---|
[de0c55a] | 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 |
|
---|
[d8ddf7a] | 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 |
|
---|
[5de71df] | 923 | rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox);
|
---|
[d70dc1c4] | 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 |
|
---|
[307d4d2] | 931 | /* FIXME: Auto layout */
|
---|
| 932 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 933 | rect.p0.x = 2;
|
---|
| 934 | rect.p0.y = 12;
|
---|
| 935 | rect.p1.x = 12;
|
---|
| 936 | rect.p1.y = 13;
|
---|
[307d4d2] | 937 | } else {
|
---|
| 938 | rect.p0.x = 15;
|
---|
| 939 | rect.p0.y = 190;
|
---|
| 940 | rect.p1.x = 140;
|
---|
| 941 | rect.p1.y = 210;
|
---|
| 942 | }
|
---|
[de0c55a] | 943 |
|
---|
[d70dc1c4] | 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 |
|
---|
[7020d1f] | 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 |
|
---|
[5de71df] | 958 | rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0],
|
---|
| 959 | &demo.rbleft);
|
---|
[7020d1f] | 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 |
|
---|
[297b1b3] | 968 | /* FIXME: Auto layout */
|
---|
| 969 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 970 | rect.p0.x = 2;
|
---|
| 971 | rect.p0.y = 14;
|
---|
| 972 | rect.p1.x = 12;
|
---|
| 973 | rect.p1.y = 15;
|
---|
[297b1b3] | 974 | } else {
|
---|
| 975 | rect.p0.x = 15;
|
---|
| 976 | rect.p0.y = 220;
|
---|
| 977 | rect.p1.x = 140;
|
---|
| 978 | rect.p1.y = 240;
|
---|
| 979 | }
|
---|
[5de71df] | 980 | ui_rbutton_set_rect(demo.rbleft, &rect);
|
---|
[7020d1f] | 981 |
|
---|
[5de71df] | 982 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbleft));
|
---|
[7020d1f] | 983 | if (rc != EOK) {
|
---|
| 984 | printf("Error adding control to layout.\n");
|
---|
| 985 | return rc;
|
---|
| 986 | }
|
---|
| 987 |
|
---|
[5de71df] | 988 | rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1],
|
---|
| 989 | &demo.rbcenter);
|
---|
[7020d1f] | 990 | if (rc != EOK) {
|
---|
| 991 | printf("Error creating radio button.\n");
|
---|
| 992 | return rc;
|
---|
| 993 | }
|
---|
| 994 |
|
---|
[297b1b3] | 995 | /* FIXME: Auto layout */
|
---|
| 996 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 997 | rect.p0.x = 2;
|
---|
| 998 | rect.p0.y = 15;
|
---|
| 999 | rect.p1.x = 12;
|
---|
| 1000 | rect.p1.y = 16;
|
---|
[297b1b3] | 1001 | } else {
|
---|
| 1002 | rect.p0.x = 15;
|
---|
| 1003 | rect.p0.y = 250;
|
---|
| 1004 | rect.p1.x = 140;
|
---|
| 1005 | rect.p1.y = 270;
|
---|
| 1006 | }
|
---|
[5de71df] | 1007 | ui_rbutton_set_rect(demo.rbcenter, &rect);
|
---|
| 1008 | ui_rbutton_select(demo.rbcenter);
|
---|
[7020d1f] | 1009 |
|
---|
[5de71df] | 1010 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbcenter));
|
---|
[7020d1f] | 1011 | if (rc != EOK) {
|
---|
| 1012 | printf("Error adding control to layout.\n");
|
---|
| 1013 | return rc;
|
---|
| 1014 | }
|
---|
| 1015 |
|
---|
[5de71df] | 1016 | rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2],
|
---|
| 1017 | &demo.rbright);
|
---|
[7020d1f] | 1018 | if (rc != EOK) {
|
---|
| 1019 | printf("Error creating radio button.\n");
|
---|
| 1020 | return rc;
|
---|
| 1021 | }
|
---|
| 1022 |
|
---|
[297b1b3] | 1023 | /* FIXME: Auto layout */
|
---|
| 1024 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 1025 | rect.p0.x = 2;
|
---|
| 1026 | rect.p0.y = 16;
|
---|
| 1027 | rect.p1.x = 12;
|
---|
| 1028 | rect.p1.y = 17;
|
---|
[297b1b3] | 1029 | } else {
|
---|
| 1030 | rect.p0.x = 15;
|
---|
| 1031 | rect.p0.y = 280;
|
---|
| 1032 | rect.p1.x = 140;
|
---|
| 1033 | rect.p1.y = 300;
|
---|
| 1034 | }
|
---|
[5de71df] | 1035 | ui_rbutton_set_rect(demo.rbright, &rect);
|
---|
[7020d1f] | 1036 |
|
---|
[5de71df] | 1037 | rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rbright));
|
---|
[7020d1f] | 1038 | if (rc != EOK) {
|
---|
| 1039 | printf("Error adding control to layout.\n");
|
---|
| 1040 | return rc;
|
---|
| 1041 | }
|
---|
| 1042 |
|
---|
[0eca788] | 1043 | rc = ui_slider_create(ui_res, &demo.slider);
|
---|
[ef734b7] | 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 |
|
---|
[943f032] | 1051 | /* FIXME: Auto layout */
|
---|
| 1052 | if (ui_is_textmode(ui)) {
|
---|
[ab3bfc1] | 1053 | rect.p0.x = 2;
|
---|
| 1054 | rect.p0.y = 18;
|
---|
| 1055 | rect.p1.x = 12;
|
---|
| 1056 | rect.p1.y = 19;
|
---|
[943f032] | 1057 | } else {
|
---|
| 1058 | rect.p0.x = 15;
|
---|
| 1059 | rect.p0.y = 310;
|
---|
| 1060 | rect.p1.x = 130;
|
---|
| 1061 | rect.p1.y = 330;
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
[ef734b7] | 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 |
|
---|
[8965860c] | 1072 | rc = ui_scrollbar_create(ui, window, &demo.scrollbar);
|
---|
[bd16113] | 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 |
|
---|
[b71c0fc] | 1104 | ui_window_add(window, ui_fixed_ctl(demo.fixed));
|
---|
| 1105 |
|
---|
[fa01c05] | 1106 | rc = ui_window_paint(window);
|
---|
[ba09d06] | 1107 | if (rc != EOK) {
|
---|
[fa01c05] | 1108 | printf("Error painting window.\n");
|
---|
[f6df5a3] | 1109 | return rc;
|
---|
[47728678] | 1110 | }
|
---|
| 1111 |
|
---|
[d284ce9] | 1112 | ui_run(ui);
|
---|
[47728678] | 1113 |
|
---|
[d284ce9] | 1114 | ui_window_destroy(window);
|
---|
| 1115 | ui_destroy(ui);
|
---|
[47728678] | 1116 |
|
---|
| 1117 | return EOK;
|
---|
| 1118 | }
|
---|
| 1119 |
|
---|
[d8ddf7a] | 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,
|
---|
[de0c55a] | 1148 | PIXEL(0, k, k, 255 - k));
|
---|
[d8ddf7a] | 1149 | }
|
---|
| 1150 | }
|
---|
| 1151 |
|
---|
| 1152 | return EOK;
|
---|
| 1153 | }
|
---|
| 1154 |
|
---|
[d284ce9] | 1155 | static void print_syntax(void)
|
---|
| 1156 | {
|
---|
| 1157 | printf("Syntax: uidemo [-d <display-spec>]\n");
|
---|
| 1158 | }
|
---|
| 1159 |
|
---|
[f80690a] | 1160 | int main(int argc, char *argv[])
|
---|
| 1161 | {
|
---|
[552b69f] | 1162 | const char *display_spec = UI_ANY_DEFAULT;
|
---|
[f80690a] | 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 |
|
---|
[d284ce9] | 1176 | display_spec = argv[i++];
|
---|
[f80690a] | 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 |
|
---|
[d284ce9] | 1189 | rc = ui_demo(display_spec);
|
---|
[47728678] | 1190 | if (rc != EOK)
|
---|
[f80690a] | 1191 | return 1;
|
---|
| 1192 |
|
---|
| 1193 | return 0;
|
---|
| 1194 | }
|
---|
| 1195 |
|
---|
| 1196 | /** @}
|
---|
| 1197 | */
|
---|