Changes in uspace/app/barber/barber.c [bdf06ad:a130983] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/barber/barber.c
rbdf06ad ra130983 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2020 Jiri Svoboda 3 3 * Copyright (c) 2014 Martin Decky 4 4 * All rights reserved. … … 50 50 #include <ui/image.h> 51 51 #include "images.h" 52 #include "images_tiny.h"53 52 54 53 #define NAME "barber" … … 61 60 #define MIN_LOAD (LOAD_UNIT / 4) 62 61 #define MAX_LOAD (LOAD_UNIT / 3) 62 63 #define FRAME_WIDTH 59 64 #define FRAME_HEIGHT 192 63 65 64 66 #define LED_PERIOD 1000000 … … 95 97 static unsigned int frame = 0; 96 98 static unsigned int fps = MIN_FPS; 97 static gfx_coord_t frame_width;98 static gfx_coord_t frame_height;99 99 100 100 static void led_timer_callback(void *); … … 102 102 103 103 static void wnd_close(ui_window_t *, void *); 104 static void wnd_kbd_event(ui_window_t *, void *, kbd_event_t *);105 104 106 105 static ui_window_cb_t window_cb = { 107 .close = wnd_close, 108 .kbd = wnd_kbd_event 106 .close = wnd_close 109 107 }; 110 108 … … 112 110 * 113 111 * @param window Window 114 * @param arg Argument ( barber)112 * @param arg Argument (launcher) 115 113 */ 116 114 static void wnd_close(ui_window_t *window, void *arg) … … 121 119 } 122 120 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) 121 static bool decode_frames(gfx_context_t *gc) 169 122 { 170 123 gfx_rect_t rect; … … 172 125 173 126 for (unsigned int i = 0; i < FRAMES; i++) { 174 rc = decode_tga_gz(gc, im g[i].addr, img[i].size,127 rc = decode_tga_gz(gc, images[i].addr, images[i].size, 175 128 &frame_bmp[i], &rect); 176 129 if (rc != EOK) { … … 179 132 } 180 133 181 (void) rect;134 (void) rect; 182 135 } 183 136 … … 285 238 rect.p0.x = 0; 286 239 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; 289 242 290 243 ui_image_set_bmp(frame_img, frame_bmp[frame], &rect); … … 346 299 int main(int argc, char *argv[]) 347 300 { 348 const char *display_spec = UI_ ANY_DEFAULT;301 const char *display_spec = UI_DISPLAY_DEFAULT; 349 302 barber_t barber; 350 303 ui_t *ui; … … 357 310 gfx_context_t *gc; 358 311 gfx_coord2_t off; 359 image_t *img;360 312 int i; 361 313 … … 403 355 } 404 356 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 413 357 rect.p0.x = 0; 414 358 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; 417 361 418 362 ui_wnd_params_init(¶ms); … … 423 367 * to rect 424 368 */ 425 ui_wdecor_rect_from_app( ui,params.style, &rect, &wrect);369 ui_wdecor_rect_from_app(params.style, &rect, &wrect); 426 370 off = wrect.p0; 427 371 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); … … 440 384 ui_window_set_cb(window, &window_cb, (void *) &barber); 441 385 442 img = ui_is_textmode(ui) ? image_tinys : images; 443 444 if (!decode_frames(gc, img)) 386 if (!decode_frames(gc)) 445 387 return 1; 446 388
Note:
See TracChangeset
for help on using the changeset viewer.