Changeset fa01c05 in mainline for uspace/app/uidemo/uidemo.c


Ignore:
Timestamp:
2020-11-03T18:46:35Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b71c0fc
Parents:
4ac11ff
Message:

UI window should fill the application are background

Except for applications that want to do their own drawing without the
use of UI control hierarchy. We solve this by doing it in a default
paint callback that the application can override with its own
paint routine.

File:
1 edited

Legend:

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

    r4ac11ff rfa01c05  
    3333 */
    3434
    35 #include <gfx/color.h>
    3635#include <gfx/coord.h>
    37 #include <gfx/render.h>
    3836#include <io/pos_event.h>
    3937#include <stdio.h>
     
    5048
    5149static void wnd_close(ui_window_t *, void *);
     50static errno_t wnd_paint(ui_window_t *, void *);
    5251static void wnd_pos(ui_window_t *, void *, pos_event_t *pos);
    5352
    5453static ui_window_cb_t window_cb = {
    5554        .close = wnd_close,
     55        .paint = wnd_paint,
    5656        .pos = wnd_pos
    5757};
     
    7373
    7474        ui_quit(demo->ui);
     75}
     76
     77/** Window paint request.
     78 *
     79 * @param window Window
     80 * @param arg Argument (demo)
     81 * @return EOK on success or an error code
     82 */
     83static errno_t wnd_paint(ui_window_t *window, void *arg)
     84{
     85        ui_demo_t *demo = (ui_demo_t *) arg;
     86        errno_t rc;
     87
     88        /* Let window paint its background */
     89        rc = ui_window_def_paint(window);
     90        if (rc != EOK)
     91                return rc;
     92
     93        return ui_fixed_paint(demo->fixed);
    7594}
    7695
     
    122141        ui_demo_t demo;
    123142        gfx_rect_t rect;
    124         gfx_rect_t app_rect;
    125         gfx_color_t *color;
    126143        ui_resource_t *ui_res;
    127         gfx_context_t *gc;
    128144        errno_t rc;
    129145
     
    156172
    157173        ui_res = ui_window_get_res(window);
    158         gc = ui_window_get_gc(window);
    159         ui_window_get_app_rect(window, &app_rect);
    160174
    161175        rc = ui_fixed_create(&demo.fixed);
     
    226240        }
    227241
    228         rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &color);
    229         if (rc != EOK) {
    230                 printf("Error allocating color.\n");
    231                 return rc;
    232         }
    233 
    234         rc = gfx_set_color(gc, color);
    235         if (rc != EOK) {
    236                 printf("Error setting color.\n");
    237                 return rc;
    238         }
    239 
    240         rc = gfx_fill_rect(gc, &app_rect);
    241         if (rc != EOK) {
    242                 printf("Error filling background.\n");
    243                 return rc;
    244         }
    245 
    246         rc = ui_fixed_paint(demo.fixed);
    247         if (rc != EOK) {
    248                 printf("Error painting UI controls.\n");
     242        rc = ui_window_paint(window);
     243        if (rc != EOK) {
     244                printf("Error painting window.\n");
    249245                return rc;
    250246        }
Note: See TracChangeset for help on using the changeset viewer.