Ignore:
File:
1 edited

Legend:

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

    rbdf06ad ra130983  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2020 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"
    5352
    5453#define NAME  "barber"
     
    6160#define MIN_LOAD  (LOAD_UNIT / 4)
    6261#define MAX_LOAD  (LOAD_UNIT / 3)
     62
     63#define FRAME_WIDTH   59
     64#define FRAME_HEIGHT  192
    6365
    6466#define LED_PERIOD  1000000
     
    9597static unsigned int frame = 0;
    9698static unsigned int fps = MIN_FPS;
    97 static gfx_coord_t frame_width;
    98 static gfx_coord_t frame_height;
    9999
    100100static void led_timer_callback(void *);
     
    102102
    103103static void wnd_close(ui_window_t *, void *);
    104 static void wnd_kbd_event(ui_window_t *, void *, kbd_event_t *);
    105104
    106105static ui_window_cb_t window_cb = {
    107         .close = wnd_close,
    108         .kbd = wnd_kbd_event
     106        .close = wnd_close
    109107};
    110108
     
    112110 *
    113111 * @param window Window
    114  * @param arg Argument (barber)
     112 * @param arg Argument (launcher)
    115113 */
    116114static void wnd_close(ui_window_t *window, void *arg)
     
    121119}
    122120
    123 /** Barber unmodified key press.
    124  *
    125  * @param barber Barber
    126  * @param event Keyboard event
    127  */
    128 static 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  */
    139 static 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  */
    151 static 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 
    168 static bool decode_frames(gfx_context_t *gc, image_t *img)
     121static bool decode_frames(gfx_context_t *gc)
    169122{
    170123        gfx_rect_t rect;
     
    172125
    173126        for (unsigned int i = 0; i < FRAMES; i++) {
    174                 rc = decode_tga_gz(gc, img[i].addr, img[i].size,
     127                rc = decode_tga_gz(gc, images[i].addr, images[i].size,
    175128                    &frame_bmp[i], &rect);
    176129                if (rc != EOK) {
     
    179132                }
    180133
    181                 (void)rect;
     134                (void) rect;
    182135        }
    183136
     
    285238        rect.p0.x = 0;
    286239        rect.p0.y = 0;
    287         rect.p1.x = frame_width;
    288         rect.p1.y = frame_height;
     240        rect.p1.x = FRAME_WIDTH;
     241        rect.p1.y = FRAME_HEIGHT;
    289242
    290243        ui_image_set_bmp(frame_img, frame_bmp[frame], &rect);
     
    346299int main(int argc, char *argv[])
    347300{
    348         const char *display_spec = UI_ANY_DEFAULT;
     301        const char *display_spec = UI_DISPLAY_DEFAULT;
    349302        barber_t barber;
    350303        ui_t *ui;
     
    357310        gfx_context_t *gc;
    358311        gfx_coord2_t off;
    359         image_t *img;
    360312        int i;
    361313
     
    403355        }
    404356
    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 
    413357        rect.p0.x = 0;
    414358        rect.p0.y = 0;
    415         rect.p1.x = frame_width;
    416         rect.p1.y = frame_height;
     359        rect.p1.x = FRAME_WIDTH;
     360        rect.p1.y = FRAME_HEIGHT;
    417361
    418362        ui_wnd_params_init(&params);
     
    423367         * to rect
    424368         */
    425         ui_wdecor_rect_from_app(ui, params.style, &rect, &wrect);
     369        ui_wdecor_rect_from_app(params.style, &rect, &wrect);
    426370        off = wrect.p0;
    427371        gfx_rect_rtranslate(&off, &wrect, &params.rect);
     
    440384        ui_window_set_cb(window, &window_cb, (void *) &barber);
    441385
    442         img = ui_is_textmode(ui) ? image_tinys : images;
    443 
    444         if (!decode_frames(gc, img))
     386        if (!decode_frames(gc))
    445387                return 1;
    446388
Note: See TracChangeset for help on using the changeset viewer.