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


Ignore:
Timestamp:
2020-10-19T20:17:11Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba09d06
Parents:
de9992c
Message:

Window decoration

File:
1 edited

Legend:

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

    rde9992c r1769693  
    4242#include <ui/pbutton.h>
    4343#include <ui/resource.h>
     44#include <ui/wdecor.h>
    4445#include "uidemo.h"
    4546
    4647static void wnd_close_event(void *);
     48static void wnd_focus_event(void *);
    4749static void wnd_kbd_event(void *, kbd_event_t *);
    4850static void wnd_pos_event(void *, pos_event_t *);
     51static void wnd_unfocus_event(void *);
    4952
    5053static display_wnd_cb_t wnd_cb = {
    5154        .close_event = wnd_close_event,
     55        .focus_event = wnd_focus_event,
    5256        .kbd_event = wnd_kbd_event,
    53         .pos_event = wnd_pos_event
     57        .pos_event = wnd_pos_event,
     58        .unfocus_event = wnd_unfocus_event
    5459};
    5560
     
    6065};
    6166
     67static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *);
     68
     69static ui_wdecor_cb_t wdecor_cb = {
     70        .move = wd_move
     71};
     72
    6273static bool quit = false;
    6374
     
    7384        printf("Close event\n");
    7485        quit = true;
     86}
     87
     88/** Handle window focus event. */
     89static void wnd_focus_event(void *arg)
     90{
     91        ui_demo_t *demo = (ui_demo_t *) arg;
     92
     93        if (demo->wdecor != NULL) {
     94                ui_wdecor_set_active(demo->wdecor, true);
     95                ui_wdecor_paint(demo->wdecor);
     96        }
    7597}
    7698
     
    88110        ui_demo_t *demo = (ui_demo_t *) arg;
    89111
     112        /* Make sure we don't process events until fully initialized */
     113        if (demo->wdecor == NULL || demo->pb1 == NULL || demo->pb2 == NULL)
     114                return;
     115
     116        ui_wdecor_pos_event(demo->wdecor, event);
    90117        ui_pbutton_pos_event(demo->pb1, event);
    91118        ui_pbutton_pos_event(demo->pb2, event);
     119}
     120
     121/** Handle window unfocus event. */
     122static void wnd_unfocus_event(void *arg)
     123{
     124        ui_demo_t *demo = (ui_demo_t *) arg;
     125
     126        if (demo->wdecor != NULL) {
     127                ui_wdecor_set_active(demo->wdecor, false);
     128                ui_wdecor_paint(demo->wdecor);
     129        }
    92130}
    93131
     
    106144                printf("Clicked 'Cancel' button\n");
    107145        }
     146}
     147
     148/** Window decoration requested window move.
     149 *
     150 * @param wdecor Window decoration
     151 * @param arg Argument (demo)
     152 * @param pos Position where the title bar was pressed
     153 */
     154static void wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
     155{
     156        ui_demo_t *demo = (ui_demo_t *) arg;
     157
     158        (void) display_window_move_req(demo->dwindow, pos);
    108159}
    109160
     
    135186        params.rect.p1.y = 100;
    136187
     188        memset((void *) &demo, 0, sizeof(demo));
     189
    137190        rc = display_window_create(display, &params, &wnd_cb, (void *) &demo,
    138191            &window);
     
    142195        }
    143196
     197        demo.dwindow = window;
     198
    144199        rc = display_window_get_gc(window, &gc);
    145200        if (rc != EOK) {
     
    155210                return rc;
    156211        }
     212
     213        printf("Create window decoration\n");
     214        rc = ui_wdecor_create(ui_res, "UI Demo", &demo.wdecor);
     215        if (rc != EOK) {
     216                printf("Error creating window decoration.\n");
     217                return rc;
     218        }
     219
     220        ui_wdecor_set_rect(demo.wdecor, &params.rect);
     221        ui_wdecor_set_cb(demo.wdecor, &wdecor_cb, (void *) &demo);
    157222
    158223        rc = ui_pbutton_create(ui_res, "Confirm", &demo.pb1);
     
    207272        color = NULL;
    208273
     274        rc = ui_wdecor_paint(demo.wdecor);
     275        if (rc != EOK) {
     276                printf("Error painting window decoration.\n");
     277                return rc;
     278        }
     279
    209280        rc = ui_pbutton_paint(demo.pb1);
    210281        if (rc != EOK) {
     
    223294        }
    224295
     296        ui_wdecor_destroy(demo.wdecor);
    225297        ui_pbutton_destroy(demo.pb1);
    226298        ui_pbutton_destroy(demo.pb2);
Note: See TracChangeset for help on using the changeset viewer.