Changeset c37c24c in mainline for uspace/app/barber/barber.c
- Timestamp:
- 2024-04-07T09:52:47Z (8 months ago)
- Children:
- e55d2c1
- Parents:
- 6c1e7c0 (diff), 34aad53d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/barber/barber.c
r6c1e7c0 rc37c24c 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2024 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" 52 53 53 54 #define NAME "barber" … … 60 61 #define MIN_LOAD (LOAD_UNIT / 4) 61 62 #define MAX_LOAD (LOAD_UNIT / 3) 62 63 #define FRAME_WIDTH 5964 #define FRAME_HEIGHT 19265 63 66 64 #define LED_PERIOD 1000000 … … 97 95 static unsigned int frame = 0; 98 96 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 *); 104 105 105 106 static ui_window_cb_t window_cb = { 106 .close = wnd_close 107 .close = wnd_close, 108 .kbd = wnd_kbd_event 107 109 }; 108 110 … … 110 112 * 111 113 * @param window Window 112 * @param arg Argument ( launcher)114 * @param arg Argument (barber) 113 115 */ 114 116 static void wnd_close(ui_window_t *window, void *arg) … … 119 121 } 120 122 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 */ 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) 122 169 { 123 170 gfx_rect_t rect; … … 125 172 126 173 for (unsigned int i = 0; i < FRAMES; i++) { 127 rc = decode_tga_gz(gc, im ages[i].addr, images[i].size,174 rc = decode_tga_gz(gc, img[i].addr, img[i].size, 128 175 &frame_bmp[i], &rect); 129 176 if (rc != EOK) { … … 132 179 } 133 180 134 (void) 181 (void)rect; 135 182 } 136 183 … … 238 285 rect.p0.x = 0; 239 286 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; 242 289 243 290 ui_image_set_bmp(frame_img, frame_bmp[frame], &rect); … … 299 346 int main(int argc, char *argv[]) 300 347 { 301 const char *display_spec = UI_ DISPLAY_DEFAULT;348 const char *display_spec = UI_ANY_DEFAULT; 302 349 barber_t barber; 303 350 ui_t *ui; … … 310 357 gfx_context_t *gc; 311 358 gfx_coord2_t off; 359 image_t *img; 312 360 int i; 313 361 … … 355 403 } 356 404 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 357 413 rect.p0.x = 0; 358 414 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; 361 417 362 418 ui_wnd_params_init(¶ms); … … 367 423 * to rect 368 424 */ 369 ui_wdecor_rect_from_app( params.style, &rect, &wrect);425 ui_wdecor_rect_from_app(ui, params.style, &rect, &wrect); 370 426 off = wrect.p0; 371 427 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); … … 384 440 ui_window_set_cb(window, &window_cb, (void *) &barber); 385 441 386 if (!decode_frames(gc)) 442 img = ui_is_textmode(ui) ? image_tinys : images; 443 444 if (!decode_frames(gc, img)) 387 445 return 1; 388 446
Note:
See TracChangeset
for help on using the changeset viewer.