Ignore:
File:
1 edited

Legend:

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

    rd0dfbba r0a411bbf  
    11/*
    2  * Copyright (c) 2026 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <display.h>
    3737#include <fibril.h>
    38 #include <fibril_synch.h>
    3938#include <gfx/bitmap.h>
    4039#include <gfx/color.h>
     
    6261};
    6362
    64 static void uiwnd_resize_event(ui_window_t *, void *);
    6563static void uiwnd_close_event(ui_window_t *, void *);
    6664static void uiwnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
    6765
    6866static ui_window_cb_t ui_window_cb = {
    69         .resize = uiwnd_resize_event,
    7067        .close = uiwnd_close_event,
    7168        .kbd = uiwnd_kbd_event
     
    8178static gfx_coord_t vpad;
    8279static console_ctrl_t *con = NULL;
    83 static bool textmode;
    84 static console_gc_t *cgc = NULL;
    85 static unsigned scr_width, scr_height;
    8680static ui_t *ui;
    8781
    8882/** Determine if we are running in text mode.
    8983 *
     84 * @param w Screen width
     85 * @param h Screen height
    9086 * @return @c true iff we are running in text mode
    9187 */
    92 static bool demo_is_text(void)
    93 {
    94         return textmode;
     88static bool demo_is_text(gfx_coord_t w, gfx_coord_t h)
     89{
     90        // XXX Need a proper way to determine text mode
     91        return w <= 80;
    9592}
    9693
     
    104101        usec_t usec;
    105102        cons_event_t cevent;
    106         sysarg_t cols, rows;
    107103
    108104        if (ui != NULL)
     
    119115                                                demo_kbd_event(&cevent.ev.key);
    120116                                                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);
    131117                                        }
    132118                                }
     
    195181
    196182        /* XXX Crude way of detecting text mode */
    197         if (demo_is_text()) {
     183        if (w < 256) {
    198184                /* Create dummy font for text mode */
    199185                rc = gfx_typeface_create(gc, &tface);
     
    284270
    285271        if (font != NULL) {
    286                 if (demo_is_text()) {
     272                if (demo_is_text(w, h)) {
    287273                        rc = gfx_color_new_ega(0x1e, &color);
    288274                        if (rc != EOK)
     
    733719        gfx_color_delete(color);
    734720
    735         if (demo_is_text()) {
     721        if (demo_is_text(w, h)) {
    736722                rc = gfx_color_new_ega(0x1f, &color);
    737723                if (rc != EOK)
     
    821807
    822808        for (i = 0; i < 8; i++) {
    823                 if (demo_is_text()) {
     809                if (demo_is_text(w, h)) {
    824810                        rc = gfx_color_new_ega(i != 0 ? i : 0x10, &color);
    825811                        if (rc != EOK)
     
    898884                gfx_color_delete(color);
    899885
    900                 if (demo_is_text()) {
     886                if (demo_is_text(w, h)) {
    901887                        rc = gfx_color_new_ega(0x1f, &color);
    902888                        if (rc != EOK)
     
    10401026 *
    10411027 * @param gc Graphic context
    1042  */
    1043 static errno_t demo_loop(gfx_context_t *gc)
    1044 {
    1045         errno_t rc;
    1046 
    1047         (void) demo_font_init(gc, scr_width, scr_height);
     1028 * @param w Width
     1029 * @param h Height
     1030 */
     1031static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h)
     1032{
     1033        errno_t rc;
     1034
     1035        (void) demo_font_init(gc, w, h);
    10481036
    10491037        while (!quit) {
    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);
     1038                rc = demo_rects(gc, w, h);
     1039                if (rc != EOK)
     1040                        goto error;
     1041
     1042                rc = demo_bitmap(gc, w, h);
     1043                if (rc != EOK)
     1044                        goto error;
     1045
     1046                rc = demo_bitmap2(gc, w, h);
     1047                if (rc != EOK)
     1048                        goto error;
     1049
     1050                rc = demo_bitmap_kc(gc, w, h);
     1051                if (rc != EOK)
     1052                        goto error;
     1053
     1054                rc = demo_text(gc, w, h);
     1055                if (rc != EOK)
     1056                        goto error;
     1057
     1058                rc = demo_text_abbr(gc, w, h);
     1059                if (rc != EOK)
     1060                        goto error;
     1061
     1062                rc = demo_clip(gc, w, h);
    10751063                if (rc != EOK)
    10761064                        goto error;
     
    10871075static errno_t demo_console(void)
    10881076{
     1077        console_gc_t *cgc = NULL;
    10891078        gfx_context_t *gc;
    10901079        sysarg_t cols, rows;
     
    11051094        gc = console_gc_get_ctx(cgc);
    11061095
    1107         /* Currently console is always text. */
    1108         textmode = true;
    1109 
    1110         scr_width = cols;
    1111         scr_height = rows;
    1112 
    1113         rc = demo_loop(gc);
     1096        rc = demo_loop(gc, cols, rows);
    11141097        if (rc != EOK)
    11151098                return rc;
     
    11281111
    11291112        ui_lock(args->ui);
    1130         scr_width = args->dims.x;
    1131         scr_height = args->dims.y;
    1132         rc = demo_loop(args->gc);
     1113        rc = demo_loop(args->gc, args->dims.x, args->dims.y);
    11331114        ui_unlock(args->ui);
    11341115        ui_quit(args->ui);
     
    11721153
    11731154        /* Do not decorate the window in fullscreen mode */
    1174         if (ui_is_fullscreen(ui)) {
     1155        if (ui_is_fullscreen(ui))
    11751156                params.style &= ~ui_wds_decorated;
    1176                 params.placement = ui_wnd_place_full_screen;
    1177         }
    11781157
    11791158        /*
     
    12131192                task_retval(0);
    12141193
    1215         textmode = ui_is_textmode(ui);
    1216 
    12171194        args.gc = gc;
    12181195        args.dims = dims;
     
    12761253        task_retval(0);
    12771254
    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);
     1255        rc = demo_loop(gc, 400, 300);
    12841256        if (rc != EOK)
    12851257                return rc;
     
    13331305        (void)arg;
    13341306        demo_kbd_event(event);
    1335 }
    1336 
    1337 static 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;
    13461307}
    13471308
     
    13881349        }
    13891350
    1390         if (i >= argc || str_cmp(argv[i], "ui") == 0) {
    1391                 rc = demo_ui(ui_display_spec);
     1351        if (i >= argc || str_cmp(argv[i], "display") == 0) {
     1352                rc = demo_display(display_svc);
    13921353                if (rc != EOK)
    13931354                        return 1;
     
    13961357                if (rc != EOK)
    13971358                        return 1;
    1398         } else if (str_cmp(argv[i], "display") == 0) {
    1399                 rc = demo_display(display_svc);
     1359        } else if (str_cmp(argv[i], "ui") == 0) {
     1360                rc = demo_ui(ui_display_spec);
    14001361                if (rc != EOK)
    14011362                        return 1;
Note: See TracChangeset for help on using the changeset viewer.