Changeset b93ec7c0 in mainline


Ignore:
Timestamp:
2020-11-11T18:26:11Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a5825b
Parents:
66a2becf
Message:

Port GFX demo from guigfx to UI

Location:
uspace/app/gfxdemo
Files:
2 edited

Legend:

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

    r66a2becf rb93ec7c0  
    3333 */
    3434
    35 #include <canvas.h>
    3635#include <congfx/console.h>
    37 #include <draw/surface.h>
    3836#include <display.h>
    3937#include <fibril.h>
    40 #include <guigfx/canvas.h>
    4138#include <gfx/bitmap.h>
    4239#include <gfx/color.h>
     
    5148#include <str.h>
    5249#include <task.h>
    53 #include <window.h>
     50#include <ui/ui.h>
     51#include <ui/window.h>
     52#include <ui/wdecor.h>
    5453
    5554static void wnd_close_event(void *);
     
    5958        .close_event = wnd_close_event,
    6059        .kbd_event = wnd_kbd_event
     60};
     61
     62static void uiwnd_close_event(ui_window_t *, void *);
     63static void uiwnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
     64
     65static ui_window_cb_t ui_window_cb = {
     66        .close = uiwnd_close_event,
     67        .kbd = uiwnd_kbd_event
    6168};
    6269
     
    696703}
    697704
    698 /** Run demo on canvas. */
    699 static errno_t demo_canvas(const char *display_svc)
    700 {
    701         canvas_gc_t *cgc = NULL;
     705/** Run demo on UI. */
     706static errno_t demo_ui(const char *display_spec)
     707{
     708        ui_t *ui = NULL;
     709        ui_wnd_params_t params;
     710        ui_window_t *window = NULL;
    702711        gfx_context_t *gc;
    703         window_t *window = NULL;
    704         pixel_t *pixbuf = NULL;
    705         surface_t *surface = NULL;
    706         canvas_t *canvas = NULL;
    707         gfx_coord_t vw, vh;
    708         errno_t rc;
    709 
    710         printf("Init canvas..\n");
    711 
    712         window = window_open(display_svc, NULL,
    713             WINDOW_MAIN | WINDOW_DECORATED, "GFX Demo");
    714         if (window == NULL) {
     712        gfx_rect_t rect;
     713        gfx_rect_t wrect;
     714        gfx_coord2_t off;
     715        errno_t rc;
     716
     717        printf("Init UI..\n");
     718
     719        rc = ui_create(display_spec, &ui);
     720        if (rc != EOK) {
     721                printf("Error initializing UI (%s)\n", display_spec);
     722                goto error;
     723        }
     724
     725        rect.p0.x = 0;
     726        rect.p0.y = 0;
     727        rect.p1.x = 400;
     728        rect.p1.y = 300;
     729
     730        ui_wnd_params_init(&params);
     731        params.caption = "GFX Demo";
     732
     733        /*
     734         * Compute window rectangle such that application area corresponds
     735         * to rect
     736         */
     737        ui_wdecor_rect_from_app(&rect, &wrect);
     738        off = wrect.p0;
     739        gfx_rect_rtranslate(&off, &wrect, &params.rect);
     740
     741        rc = ui_window_create(ui, &params, &window);
     742        if (rc != EOK) {
    715743                printf("Error creating window.\n");
    716                 return -1;
    717         }
    718 
    719         vw = 400;
    720         vh = 300;
    721 
    722         pixbuf = calloc(vw * vh, sizeof(pixel_t));
    723         if (pixbuf == NULL) {
    724                 printf("Error allocating memory for pixel buffer.\n");
    725                 return ENOMEM;
    726         }
    727 
    728         surface = surface_create(vw, vh, pixbuf, 0);
    729         if (surface == NULL) {
    730                 printf("Error creating surface.\n");
    731                 return EIO;
    732         }
    733 
    734         canvas = create_canvas(window_root(window), NULL, vw, vh,
    735             surface);
    736         if (canvas == NULL) {
    737                 printf("Error creating canvas.\n");
    738                 return EIO;
    739         }
    740 
    741         window_resize(window, 0, 0, vw + 10, vh + 30, WINDOW_PLACEMENT_ANY);
    742         window_exec(window);
    743 
    744         printf("Create canvas GC\n");
    745         rc = canvas_gc_create(canvas, surface, &cgc);
    746         if (rc != EOK)
    747                 return rc;
    748 
    749         gc = canvas_gc_get_ctx(cgc);
     744                goto error;
     745        }
     746
     747        ui_window_set_cb(window, &ui_window_cb, NULL);
     748
     749        rc = ui_window_get_app_gc(window, &gc);
     750        if (rc != EOK) {
     751                printf("Error creating graphic context.\n");
     752                goto error;
     753        }
    750754
    751755        task_retval(0);
    752756
    753         rc = demo_loop(gc, 400, 300);
    754         if (rc != EOK)
    755                 return rc;
    756 
    757         rc = canvas_gc_delete(cgc);
    758         if (rc != EOK)
    759                 return rc;
    760 
    761         return EOK;
     757        rc = demo_loop(gc, rect.p1.x, rect.p1.y);
     758        if (rc != EOK)
     759                goto error;
     760
     761        ui_window_destroy(window);
     762        ui_destroy(ui);
     763
     764        return EOK;
     765error:
     766        if (window != NULL)
     767                ui_window_destroy(window);
     768        if (ui != NULL)
     769                ui_destroy(ui);
     770        return rc;
    762771}
    763772
     
    820829
    821830static void wnd_kbd_event(void *arg, kbd_event_t *event)
     831{
     832        printf("Keyboard event type=%d key=%d\n", event->type, event->key);
     833        if (event->type == KEY_PRESS)
     834                quit = true;
     835}
     836
     837static void uiwnd_close_event(ui_window_t *window, void *arg)
     838{
     839        printf("Close event\n");
     840        quit = true;
     841}
     842
     843static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event)
    822844{
    823845        printf("Keyboard event type=%d key=%d\n", event->type, event->key);
     
    863885                if (rc != EOK)
    864886                        return 1;
    865         } else if (str_cmp(argv[i], "canvas") == 0) {
    866                 rc = demo_canvas(display_svc);
     887        } else if (str_cmp(argv[i], "ui") == 0) {
     888                rc = demo_ui(display_svc);
    867889                if (rc != EOK)
    868890                        return 1;
  • uspace/app/gfxdemo/meson.build

    r66a2becf rb93ec7c0  
    2727#
    2828
    29 deps = [ 'gfx', 'gfxfont', 'guigfx', 'congfx', 'ipcgfx', 'display' ]
     29deps = [ 'gfx', 'gfxfont', 'ui', 'congfx', 'ipcgfx', 'display' ]
    3030src = files(
    3131        'gfxdemo.c',
Note: See TracChangeset for help on using the changeset viewer.