Ignore:
File:
1 edited

Legend:

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

    r442210e rbdf06ad  
    11/*
    2  * Copyright (c) 2020 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * Copyright (c) 2014 Martin Decky
    44 * All rights reserved.
     
    5050#include <ui/image.h>
    5151#include "images.h"
     52#include "images_tiny.h"
    5253
    5354#define NAME  "barber"
     
    6061#define MIN_LOAD  (LOAD_UNIT / 4)
    6162#define MAX_LOAD  (LOAD_UNIT / 3)
    62 
    63 #define FRAME_WIDTH   59
    64 #define FRAME_HEIGHT  192
    6563
    6664#define LED_PERIOD  1000000
     
    9795static unsigned int frame = 0;
    9896static unsigned int fps = MIN_FPS;
     97static gfx_coord_t frame_width;
     98static gfx_coord_t frame_height;
    9999
    100100static void led_timer_callback(void *);
     
    102102
    103103static void wnd_close(ui_window_t *, void *);
     104static void wnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
    104105
    105106static ui_window_cb_t window_cb = {
    106         .close = wnd_close
     107        .close = wnd_close,
     108        .kbd = wnd_kbd_event
    107109};
    108110
     
    110112 *
    111113 * @param window Window
    112  * @param arg Argument (launcher)
     114 * @param arg Argument (barber)
    113115 */
    114116static void wnd_close(ui_window_t *window, void *arg)
     
    119121}
    120122
    121 static bool decode_frames(gfx_context_t *gc)
     123/** Barber unmodified key press.
     124 *
     125 * @param barber Barber
     126 * @param event Keyboard event
     127 */
     128static void barber_kbd_event_unmod(barber_t *barber, kbd_event_t *event)
     129{
     130        if (event->key == KC_ESCAPE)
     131                ui_quit(barber->ui);
     132}
     133
     134/** Barber ctrl-key key press.
     135 *
     136 * @param barber Barber
     137 * @param event Keyboard event
     138 */
     139static void barber_kbd_event_ctrl(barber_t *barber, kbd_event_t *event)
     140{
     141        if (event->key == KC_Q)
     142                ui_quit(barber->ui);
     143}
     144
     145/** Barber window keyboard event.
     146 *
     147 * @param window UI window
     148 * @param arg Argument (barber_t *)
     149 * @param event Keyboard event
     150 */
     151static void wnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event)
     152{
     153        barber_t *barber = (barber_t *)arg;
     154
     155        if (event->type != KEY_PRESS)
     156                return;
     157
     158        if ((event->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
     159                barber_kbd_event_unmod(barber, event);
     160
     161        if ((event->mods & KM_CTRL) != 0 &&
     162            (event->mods & (KM_ALT | KM_SHIFT)) == 0)
     163                barber_kbd_event_ctrl(barber, event);
     164
     165        ui_window_def_kbd(window, event);
     166}
     167
     168static bool decode_frames(gfx_context_t *gc, image_t *img)
    122169{
    123170        gfx_rect_t rect;
     
    125172
    126173        for (unsigned int i = 0; i < FRAMES; i++) {
    127                 rc = decode_tga_gz(gc, images[i].addr, images[i].size,
     174                rc = decode_tga_gz(gc, img[i].addr, img[i].size,
    128175                    &frame_bmp[i], &rect);
    129176                if (rc != EOK) {
     
    132179                }
    133180
    134                 (void) rect;
     181                (void)rect;
    135182        }
    136183
     
    238285        rect.p0.x = 0;
    239286        rect.p0.y = 0;
    240         rect.p1.x = FRAME_WIDTH;
    241         rect.p1.y = FRAME_HEIGHT;
     287        rect.p1.x = frame_width;
     288        rect.p1.y = frame_height;
    242289
    243290        ui_image_set_bmp(frame_img, frame_bmp[frame], &rect);
     
    299346int main(int argc, char *argv[])
    300347{
    301         const char *display_spec = UI_DISPLAY_DEFAULT;
     348        const char *display_spec = UI_ANY_DEFAULT;
    302349        barber_t barber;
    303350        ui_t *ui;
     
    310357        gfx_context_t *gc;
    311358        gfx_coord2_t off;
     359        image_t *img;
    312360        int i;
    313361
     
    355403        }
    356404
     405        if (ui_is_textmode(ui)) {
     406                frame_width = 10;
     407                frame_height = 16;
     408        } else {
     409                frame_width = 59;
     410                frame_height = 192;
     411        }
     412
    357413        rect.p0.x = 0;
    358414        rect.p0.y = 0;
    359         rect.p1.x = FRAME_WIDTH;
    360         rect.p1.y = FRAME_HEIGHT;
     415        rect.p1.x = frame_width;
     416        rect.p1.y = frame_height;
    361417
    362418        ui_wnd_params_init(&params);
    363         params.caption = "";
     419        params.caption = "Barber Pole";
    364420        params.placement = ui_wnd_place_bottom_right;
    365421        /*
     
    367423         * to rect
    368424         */
    369         ui_wdecor_rect_from_app(params.style, &rect, &wrect);
     425        ui_wdecor_rect_from_app(ui, params.style, &rect, &wrect);
    370426        off = wrect.p0;
    371427        gfx_rect_rtranslate(&off, &wrect, &params.rect);
     
    384440        ui_window_set_cb(window, &window_cb, (void *) &barber);
    385441
    386         if (!decode_frames(gc))
     442        img = ui_is_textmode(ui) ? image_tinys : images;
     443
     444        if (!decode_frames(gc, img))
    387445                return 1;
    388446
Note: See TracChangeset for help on using the changeset viewer.