Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/gfxdemo/gfxdemo.c

    rda15002 rd0dfbba  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2026 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <display.h>
    3737#include <fibril.h>
     38#include <fibril_synch.h>
    3839#include <gfx/bitmap.h>
    3940#include <gfx/color.h>
     
    5152#include <ui/window.h>
    5253#include <ui/wdecor.h>
     54#include "gfxdemo.h"
    5355
    5456static void wnd_close_event(void *);
     
    6062};
    6163
     64static void uiwnd_resize_event(ui_window_t *, void *);
    6265static void uiwnd_close_event(ui_window_t *, void *);
    6366static void uiwnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
    6467
    6568static ui_window_cb_t ui_window_cb = {
     69        .resize = uiwnd_resize_event,
    6670        .close = uiwnd_close_event,
    6771        .kbd = uiwnd_kbd_event
    6872};
    6973
     74static void demo_kbd_event(kbd_event_t *);
     75
    7076static bool quit = false;
     77static FIBRIL_MUTEX_INITIALIZE(quit_lock);
     78static FIBRIL_CONDVAR_INITIALIZE(quit_cv);
    7179static gfx_typeface_t *tface;
    7280static gfx_font_t *font;
    7381static gfx_coord_t vpad;
     82static console_ctrl_t *con = NULL;
     83static bool textmode;
     84static console_gc_t *cgc = NULL;
     85static unsigned scr_width, scr_height;
     86static ui_t *ui;
     87
     88/** Determine if we are running in text mode.
     89 *
     90 * @return @c true iff we are running in text mode
     91 */
     92static bool demo_is_text(void)
     93{
     94        return textmode;
     95}
     96
     97/** Sleep until timeout or quit request.
     98 *
     99 * @param msec Number of microseconds to sleep for
     100 */
     101static void demo_msleep(unsigned msec)
     102{
     103        errno_t rc;
     104        usec_t usec;
     105        cons_event_t cevent;
     106        sysarg_t cols, rows;
     107
     108        if (ui != NULL)
     109                ui_unlock(ui);
     110        fibril_mutex_lock(&quit_lock);
     111        if (!quit) {
     112                if (con != NULL) {
     113                        usec = (usec_t)msec * 1000;
     114                        while (usec > 0 && !quit) {
     115                                rc = console_get_event_timeout(con, &cevent, &usec);
     116                                if (rc == EOK) {
     117                                        if (cevent.type == CEV_KEY) {
     118                                                fibril_mutex_unlock(&quit_lock);
     119                                                demo_kbd_event(&cevent.ev.key);
     120                                                fibril_mutex_lock(&quit_lock);
     121                                        } else if (cevent.type == CEV_RESIZE) {
     122                                                rc = console_get_size(con,
     123                                                    &cols, &rows);
     124                                                if (rc == EOK) {
     125                                                        scr_width = cols;
     126                                                        scr_height = rows;
     127                                                }
     128                                                rc = console_gc_resize(cgc);
     129                                                if (rc != EOK)
     130                                                        exit(1);
     131                                        }
     132                                }
     133                        }
     134                } else {
     135                        (void) fibril_condvar_wait_timeout(&quit_cv, &quit_lock,
     136                            (usec_t)msec * 1000);
     137                }
     138        }
     139        fibril_mutex_unlock(&quit_lock);
     140        if (ui != NULL)
     141                ui_lock(ui);
     142}
    74143
    75144/** Clear screen.
     
    126195
    127196        /* XXX Crude way of detecting text mode */
    128         if (w < 256) {
     197        if (demo_is_text()) {
    129198                /* Create dummy font for text mode */
    130199                rc = gfx_typeface_create(gc, &tface);
     
    215284
    216285        if (font != NULL) {
    217                 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    218                 if (rc != EOK)
    219                         goto error;
     286                if (demo_is_text()) {
     287                        rc = gfx_color_new_ega(0x1e, &color);
     288                        if (rc != EOK)
     289                                goto error;
     290                } else {
     291                        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     292                        if (rc != EOK)
     293                                goto error;
     294                }
    220295
    221296                gfx_text_fmt_init(&fmt);
     297                fmt.font = font;
    222298                fmt.color = color;
    223299                fmt.halign = gfx_halign_center;
     
    225301
    226302                pos.x = w / 2;
    227                 pos.y = h - 1;
    228                 rc = gfx_puttext(font, &pos, &fmt, text);
     303                pos.y = h;
     304                rc = gfx_puttext(&pos, &fmt, text);
    229305                if (rc != EOK) {
    230306                        printf("Error rendering text.\n");
     
    297373                gfx_color_delete(color);
    298374
    299                 fibril_usleep(500 * 1000);
    300 
     375                demo_msleep(500);
    301376                if (quit)
    302377                        break;
     
    332407                for (j = 0; j < h; j++) {
    333408                        pixelmap_put_pixel(&pixelmap, i, j,
    334                             PIXEL(0, (i % 30) < 3 ? 255 : 0,
     409                            PIXEL(255, (i % 30) < 3 ? 255 : 0,
    335410                            (j % 30) < 3 ? 255 : 0, i / 2));
    336411                }
     
    368443                        k = i * i + j * j;
    369444                        pixelmap_put_pixel(&pixelmap, i, j,
    370                             PIXEL(0, k, k, k));
     445                            PIXEL(255, k, k, k));
    371446                }
    372447        }
     
    403478                        k = i * i + j * j;
    404479                        pixelmap_put_pixel(&pixelmap, i, j,
    405                             k < w * w / 2 ? PIXEL(0, 0, 255, 0) :
    406                             PIXEL(0, 255, 0, 255));
     480                            k < w * w / 2 ? PIXEL(255, 0, 255, 0) :
     481                            PIXEL(255, 255, 0, 255));
    407482                }
    408483        }
     
    459534                        if (rc != EOK)
    460535                                goto error;
    461                         fibril_usleep(250 * 1000);
    462 
     536
     537                        demo_msleep(250);
    463538                        if (quit)
    464539                                goto out;
     
    520595                }
    521596
    522                 fibril_usleep(500 * 1000);
    523 
     597                demo_msleep(500);
    524598                if (quit)
    525599                        break;
     
    561635        params.rect.p1.y = 40;
    562636        params.flags = bmpf_color_key;
    563         params.key_color = PIXEL(0, 255, 0, 255);
     637        params.key_color = PIXEL(255, 255, 0, 255);
    564638
    565639        rc = gfx_bitmap_create(gc, &params, NULL, &bitmap);
     
    581655                }
    582656
    583                 fibril_usleep(500 * 1000);
    584 
     657                demo_msleep(500);
    585658                if (quit)
    586659                        break;
     
    660733        gfx_color_delete(color);
    661734
    662         rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
    663         if (rc != EOK)
    664                 goto error;
     735        if (demo_is_text()) {
     736                rc = gfx_color_new_ega(0x1f, &color);
     737                if (rc != EOK)
     738                        goto error;
     739        } else {
     740                rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
     741                if (rc != EOK)
     742                        goto error;
     743        }
    665744
    666745        gfx_text_fmt_init(&fmt);
     746        fmt.font = font;
    667747        fmt.color = color;
    668748
    669749        pos.x = rect.p0.x;
    670750        pos.y = rect.p0.y;
    671         rc = gfx_puttext(font, &pos, &fmt, "Top left");
     751        rc = gfx_puttext(&pos, &fmt, "Top left");
    672752        if (rc != EOK) {
    673753                printf("Error rendering text.\n");
     
    678758        pos.y = rect.p0.y;
    679759        fmt.halign = gfx_halign_center;
    680         rc = gfx_puttext(font, &pos, &fmt, "Top center");
    681         if (rc != EOK)
    682                 goto error;
    683 
    684         pos.x = rect.p1.x - 1;
     760        rc = gfx_puttext(&pos, &fmt, "Top center");
     761        if (rc != EOK)
     762                goto error;
     763
     764        pos.x = rect.p1.x;
    685765        pos.y = rect.p0.y;
    686766        fmt.halign = gfx_halign_right;
    687         rc = gfx_puttext(font, &pos, &fmt, "Top right");
     767        rc = gfx_puttext(&pos, &fmt, "Top right");
    688768        if (rc != EOK)
    689769                goto error;
     
    694774        pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
    695775        fmt.halign = gfx_halign_left;
    696         rc = gfx_puttext(font, &pos, &fmt, "Center left");
     776        rc = gfx_puttext(&pos, &fmt, "Center left");
    697777        if (rc != EOK)
    698778                goto error;
     
    701781        pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
    702782        fmt.halign = gfx_halign_center;
    703         rc = gfx_puttext(font, &pos, &fmt, "Center");
    704         if (rc != EOK)
    705                 goto error;
    706 
    707         pos.x = rect.p1.x - 1;
     783        rc = gfx_puttext(&pos, &fmt, "Center");
     784        if (rc != EOK)
     785                goto error;
     786
     787        pos.x = rect.p1.x;
    708788        pos.y = (rect.p0.y + rect.p1.y - 1) / 2;
    709789        fmt.halign = gfx_halign_right;
    710         rc = gfx_puttext(font, &pos, &fmt, "Center right");
     790        rc = gfx_puttext(&pos, &fmt, "Center right");
    711791        if (rc != EOK)
    712792                goto error;
     
    717797        pos.y = rect.p1.y - 1;
    718798        fmt.halign = gfx_halign_left;
    719         rc = gfx_puttext(font, &pos, &fmt, "Bottom left");
     799        rc = gfx_puttext(&pos, &fmt, "Bottom left");
    720800        if (rc != EOK)
    721801                goto error;
    722802
    723803        pos.x = (rect.p0.x + rect.p1.x - 1) / 2;
    724         pos.y = rect.p1.y - 1;
     804        pos.y = rect.p1.y;
    725805        fmt.halign = gfx_halign_center;
    726         rc = gfx_puttext(font, &pos, &fmt, "Bottom center");
    727         if (rc != EOK)
    728                 goto error;
    729 
    730         pos.x = rect.p1.x - 1;
    731         pos.y = rect.p1.y - 1;
     806        rc = gfx_puttext(&pos, &fmt, "Bottom center");
     807        if (rc != EOK)
     808                goto error;
     809
     810        pos.x = rect.p1.x;
     811        pos.y = rect.p1.y;
    732812        fmt.halign = gfx_halign_right;
    733         rc = gfx_puttext(font, &pos, &fmt, "Bottom right");
     813        rc = gfx_puttext(&pos, &fmt, "Bottom right");
    734814        if (rc != EOK)
    735815                goto error;
     
    738818
    739819        gfx_text_fmt_init(&fmt);
     820        fmt.font = font;
    740821
    741822        for (i = 0; i < 8; i++) {
    742                 rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0,
    743                     (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color);
    744                 if (rc != EOK)
    745                         goto error;
     823                if (demo_is_text()) {
     824                        rc = gfx_color_new_ega(i != 0 ? i : 0x10, &color);
     825                        if (rc != EOK)
     826                                goto error;
     827                } else {
     828                        rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0,
     829                            (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color);
     830                        if (rc != EOK)
     831                                goto error;
     832                }
    746833
    747834                fmt.color = color;
     835                fmt.underline = !fmt.underline;
    748836
    749837                pos.x = w / 20;
    750838                pos.y = (6 + i) * h / 15;
    751                 rc = gfx_puttext(font, &pos, &fmt, "The quick brown fox jumps over the lazy dog.");
     839                rc = gfx_puttext(&pos, &fmt, "The quick brown fox jumps over the lazy dog.");
    752840                if (rc != EOK)
    753841                        goto error;
     
    757845
    758846        for (i = 0; i < 10; i++) {
    759                 fibril_usleep(500 * 1000);
     847                demo_msleep(500);
     848                if (quit)
     849                        break;
     850        }
     851
     852        return EOK;
     853error:
     854        return rc;
     855}
     856
     857/** Run text abbreviation demo on a graphic context.
     858 *
     859 * @param gc Graphic context
     860 * @param w Width
     861 * @param h Height
     862 */
     863static errno_t demo_text_abbr(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
     864{
     865        gfx_color_t *color = NULL;
     866        gfx_rect_t rect;
     867        gfx_coord2_t pos;
     868        gfx_text_fmt_t fmt;
     869        int i;
     870        errno_t rc;
     871
     872        if (quit)
     873                return EOK;
     874
     875        rc = demo_begin(gc, w, h, "Text abbreviation");
     876        if (rc != EOK)
     877                goto error;
     878
     879        for (i = 0; i < 11; i++) {
     880
     881                rc = gfx_color_new_rgb_i16(0, 0, 0x8000, &color);
     882                if (rc != EOK)
     883                        goto error;
     884
     885                rc = gfx_set_color(gc, color);
     886                if (rc != EOK)
     887                        goto error;
     888
     889                rect.p0.x = w / 20;
     890                rect.p0.y = (2 + 2 * i) * h / 25;
     891                rect.p1.x = w - w / 20 - w * i / 12;
     892                rect.p1.y = (3 + 2 * i) * h / 25;
     893
     894                rc = gfx_fill_rect(gc, &rect);
     895                if (rc != EOK)
     896                        goto error;
     897
     898                gfx_color_delete(color);
     899
     900                if (demo_is_text()) {
     901                        rc = gfx_color_new_ega(0x1f, &color);
     902                        if (rc != EOK)
     903                                goto error;
     904                } else {
     905                        rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
     906                            &color);
     907                        if (rc != EOK)
     908                                goto error;
     909                }
     910
     911                gfx_text_fmt_init(&fmt);
     912                fmt.font = font;
     913                fmt.color = color;
     914                fmt.abbreviate = true;
     915                fmt.width = rect.p1.x - rect.p0.x;
     916
     917                pos.x = rect.p0.x;
     918                pos.y = rect.p0.y;
     919                rc = gfx_puttext(&pos, &fmt,
     920                    "The quick brow fox jumps over the lazy dog!");
     921                if (rc != EOK) {
     922                        printf("Error rendering text.\n");
     923                        goto error;
     924                }
     925        }
     926
     927        for (i = 0; i < 10; i++) {
     928                demo_msleep(500);
    760929                if (quit)
    761930                        break;
     
    8541023                }
    8551024
    856                 fibril_usleep(500 * 1000);
    857 
     1025                demo_msleep(500);
    8581026                if (quit)
    8591027                        break;
     
    8721040 *
    8731041 * @param gc Graphic context
    874  * @param w Width
    875  * @param h Height
    876  */
    877 static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
    878 {
    879         errno_t rc;
    880 
    881         (void) demo_font_init(gc, w, h);
     1042 */
     1043static errno_t demo_loop(gfx_context_t *gc)
     1044{
     1045        errno_t rc;
     1046
     1047        (void) demo_font_init(gc, scr_width, scr_height);
    8821048
    8831049        while (!quit) {
    884                 rc = demo_rects(gc, w, h);
    885                 if (rc != EOK)
    886                         goto error;
    887 
    888                 rc = demo_bitmap(gc, w, h);
    889                 if (rc != EOK)
    890                         goto error;
    891 
    892                 rc = demo_bitmap2(gc, w, h);
    893                 if (rc != EOK)
    894                         goto error;
    895 
    896                 rc = demo_bitmap_kc(gc, w, h);
    897                 if (rc != EOK)
    898                         goto error;
    899 
    900                 rc = demo_text(gc, w, h);
    901                 if (rc != EOK)
    902                         goto error;
    903 
    904                 rc = demo_clip(gc, w, h);
     1050                rc = demo_rects(gc, scr_width, scr_height);
     1051                if (rc != EOK)
     1052                        goto error;
     1053
     1054                rc = demo_bitmap(gc, scr_width, scr_height);
     1055                if (rc != EOK)
     1056                        goto error;
     1057
     1058                rc = demo_bitmap2(gc, scr_width, scr_height);
     1059                if (rc != EOK)
     1060                        goto error;
     1061
     1062                rc = demo_bitmap_kc(gc, scr_width, scr_height);
     1063                if (rc != EOK)
     1064                        goto error;
     1065
     1066                rc = demo_text(gc, scr_width, scr_height);
     1067                if (rc != EOK)
     1068                        goto error;
     1069
     1070                rc = demo_text_abbr(gc, scr_width, scr_height);
     1071                if (rc != EOK)
     1072                        goto error;
     1073
     1074                rc = demo_clip(gc, scr_width, scr_height);
    9051075                if (rc != EOK)
    9061076                        goto error;
     
    9171087static errno_t demo_console(void)
    9181088{
    919         console_ctrl_t *con = NULL;
    920         console_gc_t *cgc = NULL;
    9211089        gfx_context_t *gc;
    922         errno_t rc;
    923 
    924         printf("Init console..\n");
     1090        sysarg_t cols, rows;
     1091        errno_t rc;
     1092
    9251093        con = console_init(stdin, stdout);
    9261094        if (con == NULL)
    9271095                return EIO;
    9281096
    929         printf("Create console GC\n");
     1097        rc = console_get_size(con, &cols, &rows);
     1098        if (rc != EOK)
     1099                return rc;
     1100
    9301101        rc = console_gc_create(con, stdout, &cgc);
    9311102        if (rc != EOK)
     
    9341105        gc = console_gc_get_ctx(cgc);
    9351106
    936         rc = demo_loop(gc, 80, 25);
     1107        /* Currently console is always text. */
     1108        textmode = true;
     1109
     1110        scr_width = cols;
     1111        scr_height = rows;
     1112
     1113        rc = demo_loop(gc);
    9371114        if (rc != EOK)
    9381115                return rc;
     
    9431120
    9441121        return EOK;
     1122}
     1123
     1124static errno_t demo_ui_fibril(void *arg)
     1125{
     1126        demo_ui_args_t *args = (demo_ui_args_t *)arg;
     1127        errno_t rc;
     1128
     1129        ui_lock(args->ui);
     1130        scr_width = args->dims.x;
     1131        scr_height = args->dims.y;
     1132        rc = demo_loop(args->gc);
     1133        ui_unlock(args->ui);
     1134        ui_quit(args->ui);
     1135        return rc;
    9451136}
    9461137
     
    9481139static errno_t demo_ui(const char *display_spec)
    9491140{
    950         ui_t *ui = NULL;
    9511141        ui_wnd_params_t params;
    9521142        ui_window_t *window = NULL;
     
    9551145        gfx_rect_t wrect;
    9561146        gfx_coord2_t off;
    957         errno_t rc;
    958 
    959         printf("Init UI..\n");
     1147        gfx_rect_t ui_rect;
     1148        gfx_coord2_t dims;
     1149        demo_ui_args_t args;
     1150        fid_t fid;
     1151        errno_t rc;
    9601152
    9611153        rc = ui_create(display_spec, &ui);
    9621154        if (rc != EOK) {
    9631155                printf("Error initializing UI (%s)\n", display_spec);
     1156                goto error;
     1157        }
     1158
     1159        rc = ui_get_rect(ui, &ui_rect);
     1160        if (rc != EOK) {
     1161                printf("Error getting display size.\n");
    9641162                goto error;
    9651163        }
     
    9731171        params.caption = "GFX Demo";
    9741172
     1173        /* Do not decorate the window in fullscreen mode */
     1174        if (ui_is_fullscreen(ui)) {
     1175                params.style &= ~ui_wds_decorated;
     1176                params.placement = ui_wnd_place_full_screen;
     1177        }
     1178
    9751179        /*
    9761180         * Compute window rectangle such that application area corresponds
    9771181         * to rect
    9781182         */
    979         ui_wdecor_rect_from_app(params.style, &rect, &wrect);
     1183        ui_wdecor_rect_from_app(ui, params.style, &rect, &wrect);
    9801184        off = wrect.p0;
    9811185        gfx_rect_rtranslate(&off, &wrect, &params.rect);
     1186
     1187        gfx_rect_dims(&ui_rect, &dims);
     1188
     1189        /* Make sure window is not larger than the entire screen */
     1190        if (params.rect.p1.x > dims.x)
     1191                params.rect.p1.x = dims.x;
     1192        if (params.rect.p1.y > dims.y)
     1193                params.rect.p1.y = dims.y;
    9821194
    9831195        rc = ui_window_create(ui, &params, &window);
     
    9951207        }
    9961208
    997         task_retval(0);
    998 
    999         rc = demo_loop(gc, rect.p1.x, rect.p1.y);
    1000         if (rc != EOK)
    1001                 goto error;
    1002 
     1209        ui_window_get_app_rect(window, &rect);
     1210        gfx_rect_dims(&rect, &dims);
     1211
     1212        if (!ui_is_fullscreen(ui))
     1213                task_retval(0);
     1214
     1215        textmode = ui_is_textmode(ui);
     1216
     1217        args.gc = gc;
     1218        args.dims = dims;
     1219        args.ui = ui;
     1220
     1221        fid = fibril_create(demo_ui_fibril, (void *)&args);
     1222        if (fid == 0) {
     1223                rc = ENOMEM;
     1224                goto error;
     1225        }
     1226
     1227        fibril_add_ready(fid);
     1228
     1229        ui_run(ui);
    10031230        ui_window_destroy(window);
    10041231        ui_destroy(ui);
     
    10221249        errno_t rc;
    10231250
    1024         printf("Init display..\n");
    1025 
    10261251        rc = display_open(display_svc, &display);
    10271252        if (rc != EOK) {
     
    10351260        params.rect.p1.x = 400;
    10361261        params.rect.p1.y = 300;
     1262        params.caption = "GFX Demo";
    10371263
    10381264        rc = display_window_create(display, &params, &wnd_cb, NULL, &window);
     
    10501276        task_retval(0);
    10511277
    1052         rc = demo_loop(gc, 400, 300);
     1278        /* FIXME Assuming display service is not text mode. */
     1279        textmode = false;
     1280
     1281        scr_width = 400;
     1282        scr_height = 300;
     1283        rc = demo_loop(gc);
    10531284        if (rc != EOK)
    10541285                return rc;
     
    10641295}
    10651296
     1297static void demo_quit(void)
     1298{
     1299        fibril_mutex_lock(&quit_lock);
     1300        quit = true;
     1301        fibril_mutex_unlock(&quit_lock);
     1302        fibril_condvar_broadcast(&quit_cv);
     1303}
     1304
    10661305static void wnd_close_event(void *arg)
    10671306{
    1068         printf("Close event\n");
    1069         quit = true;
     1307        demo_quit();
     1308}
     1309
     1310static void demo_kbd_event(kbd_event_t *event)
     1311{
     1312        if (event->type == KEY_PRESS) {
     1313                /* Ctrl-Q */
     1314                if ((event->mods & KM_CTRL) != 0 &&
     1315                    (event->mods & KM_ALT) == 0 &&
     1316                    (event->mods & KM_SHIFT) == 0 &&
     1317                    event->key == KC_Q) {
     1318                        demo_quit();
     1319                }
     1320
     1321                /* Escape */
     1322                if ((event->mods & KM_CTRL) == 0 &&
     1323                    (event->mods & KM_ALT) == 0 &&
     1324                    (event->mods & KM_SHIFT) == 0 &&
     1325                    event->key == KC_ESCAPE) {
     1326                        demo_quit();
     1327                }
     1328        }
    10701329}
    10711330
    10721331static void wnd_kbd_event(void *arg, kbd_event_t *event)
    10731332{
    1074         printf("Keyboard event type=%d key=%d\n", event->type, event->key);
    1075         if (event->type == KEY_PRESS)
    1076                 quit = true;
     1333        (void)arg;
     1334        demo_kbd_event(event);
     1335}
     1336
     1337static void uiwnd_resize_event(ui_window_t *window, void *arg)
     1338{
     1339        gfx_rect_t rect;
     1340        gfx_coord2_t dims;
     1341
     1342        ui_window_get_app_rect(window, &rect);
     1343        gfx_rect_dims(&rect, &dims);
     1344        scr_width = dims.x;
     1345        scr_height = dims.y;
    10771346}
    10781347
    10791348static void uiwnd_close_event(ui_window_t *window, void *arg)
    10801349{
    1081         printf("Close event\n");
    1082         quit = true;
     1350        demo_quit();
    10831351}
    10841352
    10851353static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event)
    10861354{
    1087         printf("Keyboard event type=%d key=%d\n", event->type, event->key);
    1088         if (event->type == KEY_PRESS)
    1089                 quit = true;
     1355        (void)window;
     1356        (void)arg;
     1357        demo_kbd_event(event);
    10901358}
    10911359
     
    10991367        errno_t rc;
    11001368        const char *display_svc = DISPLAY_DEFAULT;
     1369        const char *ui_display_spec = UI_ANY_DEFAULT;
    11011370        int i;
    11021371
     
    11111380                        }
    11121381
    1113                         display_svc = argv[i++];
     1382                        display_svc = ui_display_spec = argv[i++];
    11141383                } else {
    11151384                        printf("Invalid option '%s'.\n", argv[i]);
     
    11191388        }
    11201389
    1121         if (i >= argc || str_cmp(argv[i], "display") == 0) {
    1122                 rc = demo_display(display_svc);
     1390        if (i >= argc || str_cmp(argv[i], "ui") == 0) {
     1391                rc = demo_ui(ui_display_spec);
    11231392                if (rc != EOK)
    11241393                        return 1;
     
    11271396                if (rc != EOK)
    11281397                        return 1;
    1129         } else if (str_cmp(argv[i], "ui") == 0) {
    1130                 rc = demo_ui(display_svc);
     1398        } else if (str_cmp(argv[i], "display") == 0) {
     1399                rc = demo_display(display_svc);
    11311400                if (rc != EOK)
    11321401                        return 1;
Note: See TracChangeset for help on using the changeset viewer.