Changes in uspace/app/barber/barber.c [266ec54:fd11144] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/barber/barber.c
r266ec54 rfd11144 1 1 /* 2 * Copyright (c) 2020 Jiri Svoboda3 2 * Copyright (c) 2014 Martin Decky 4 3 * All rights reserved. … … 34 33 */ 35 34 36 #include < device/led_dev.h>35 #include <stdbool.h> 37 36 #include <errno.h> 38 #include < fibril_synch.h>39 #include < gfximage/tga_gz.h>40 #include < io/pixel.h>37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <task.h> 41 40 #include <loc.h> 42 41 #include <stats.h> 43 #include <stdbool.h>44 #include <stdio.h>45 #include <stdlib.h>46 42 #include <str.h> 47 #include <ui/ui.h> 48 #include <ui/wdecor.h> 49 #include <ui/window.h> 50 #include <ui/image.h> 43 #include <fibril_synch.h> 44 #include <io/pixel.h> 45 #include <device/led_dev.h> 46 #include <window.h> 47 #include <canvas.h> 48 #include <draw/surface.h> 49 #include <draw/codec.h> 51 50 #include "images.h" 52 51 … … 73 72 } led_dev_t; 74 73 75 typedef struct { 76 ui_t *ui; 77 } barber_t; 74 static char *winreg = NULL; 78 75 79 76 static fibril_timer_t *led_timer = NULL; … … 92 89 93 90 static fibril_timer_t *frame_timer = NULL; 94 static ui_image_t *frame_img;95 static gfx_bitmap_t *frame_bmp[FRAMES];91 static canvas_t *frame_canvas; 92 static surface_t *frames[FRAMES]; 96 93 97 94 static unsigned int frame = 0; … … 101 98 static void frame_timer_callback(void *); 102 99 103 static void wnd_close(ui_window_t *, void *); 104 105 static ui_window_cb_t window_cb = { 106 .close = wnd_close 107 }; 108 109 /** Window close button was clicked. 110 * 111 * @param window Window 112 * @param arg Argument (launcher) 113 */ 114 static void wnd_close(ui_window_t *window, void *arg) 115 { 116 barber_t *barber = (barber_t *) arg; 117 118 ui_quit(barber->ui); 119 } 120 121 static bool decode_frames(gfx_context_t *gc) 122 { 123 gfx_rect_t rect; 124 errno_t rc; 125 100 static bool decode_frames(void) 101 { 126 102 for (unsigned int i = 0; i < FRAMES; i++) { 127 rc = decode_tga_gz(gc, images[i].addr, images[i].size, 128 &frame_bmp[i], &rect); 129 if (rc != EOK) { 103 frames[i] = decode_tga_gz(images[i].addr, images[i].size, 0); 104 if (frames[i] == NULL) { 130 105 printf("Unable to decode frame %u.\n", i); 131 106 return false; 132 107 } 133 134 (void) rect;135 108 } 136 109 137 110 return true; 138 }139 140 static void destroy_frames(void)141 {142 unsigned i;143 144 for (i = 0; i < FRAMES; i++) {145 gfx_bitmap_destroy(frame_bmp[i]);146 frame_bmp[i] = NULL;147 }148 111 } 149 112 … … 229 192 { 230 193 struct timespec prev; 231 gfx_rect_t rect;232 194 getuptime(&prev); 233 195 … … 236 198 frame = 0; 237 199 238 rect.p0.x = 0; 239 rect.p0.y = 0; 240 rect.p1.x = FRAME_WIDTH; 241 rect.p1.y = FRAME_HEIGHT; 242 243 ui_image_set_bmp(frame_img, frame_bmp[frame], &rect); 244 (void) ui_image_paint(frame_img); 200 update_canvas(frame_canvas, frames[frame]); 245 201 246 202 struct timespec cur; … … 299 255 int main(int argc, char *argv[]) 300 256 { 301 const char *display_spec = UI_DISPLAY_DEFAULT; 302 barber_t barber; 303 ui_t *ui; 304 ui_wnd_params_t params; 305 ui_window_t *window; 306 ui_resource_t *ui_res; 307 gfx_rect_t rect; 308 gfx_rect_t wrect; 309 gfx_rect_t app_rect; 310 gfx_context_t *gc; 311 gfx_coord2_t off; 257 const char *display_svc = DISPLAY_DEFAULT; 312 258 int i; 313 259 … … 322 268 } 323 269 324 display_s pec = argv[i++];270 display_svc = argv[i++]; 325 271 } else { 326 272 printf("Invalid option '%s'.\n", argv[i]); … … 349 295 } 350 296 351 rc = ui_create(display_spec, &ui); 352 if (rc != EOK) { 353 printf("Error creating UI on display %s.\n", display_spec); 354 return 1; 355 } 356 357 rect.p0.x = 0; 358 rect.p0.y = 0; 359 rect.p1.x = FRAME_WIDTH; 360 rect.p1.y = FRAME_HEIGHT; 361 362 ui_wnd_params_init(¶ms); 363 params.caption = ""; 364 params.placement = ui_wnd_place_bottom_right; 365 /* 366 * Compute window rectangle such that application area corresponds 367 * to rect 368 */ 369 ui_wdecor_rect_from_app(params.style, &rect, &wrect); 370 off = wrect.p0; 371 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); 372 373 barber.ui = ui; 374 375 rc = ui_window_create(ui, ¶ms, &window); 376 if (rc != EOK) { 377 printf("Error creating window.\n"); 378 return 1; 379 } 380 381 ui_res = ui_window_get_res(window); 382 gc = ui_window_get_gc(window); 383 ui_window_get_app_rect(window, &app_rect); 384 ui_window_set_cb(window, &window_cb, (void *) &barber); 385 386 if (!decode_frames(gc)) 387 return 1; 388 389 rc = ui_image_create(ui_res, frame_bmp[frame], &rect, 390 &frame_img); 391 if (rc != EOK) { 392 printf("Error creating UI.\n"); 393 return 1; 394 } 395 396 ui_image_set_rect(frame_img, &app_rect); 397 398 ui_window_add(window, ui_image_ctl(frame_img)); 399 400 rc = ui_window_paint(window); 401 if (rc != EOK) { 402 printf("Error painting window.\n"); 403 return 1; 404 } 297 if (!decode_frames()) 298 return 1; 299 300 winreg = argv[1]; 301 window_t *main_window = window_open(display_svc, NULL, 302 WINDOW_MAIN | WINDOW_DECORATED, "barber"); 303 if (!main_window) { 304 printf("Cannot open main window.\n"); 305 return 1; 306 } 307 308 frame_canvas = create_canvas(window_root(main_window), NULL, 309 FRAME_WIDTH, FRAME_HEIGHT, frames[frame]); 310 311 if (!frame_canvas) { 312 window_close(main_window); 313 printf("Cannot create widgets.\n"); 314 return 1; 315 } 316 317 window_resize(main_window, 0, 0, FRAME_WIDTH + 8, FRAME_HEIGHT + 28, 318 WINDOW_PLACEMENT_RIGHT | WINDOW_PLACEMENT_BOTTOM); 319 window_exec(main_window); 405 320 406 321 plan_led_timer(); 407 322 plan_frame_timer(0); 408 323 409 ui_run(ui); 410 411 /* Unlink bitmap from image so it is not destroyed along with it */ 412 ui_image_set_bmp(frame_img, NULL, &rect); 413 414 ui_window_destroy(window); 415 ui_destroy(ui); 416 417 destroy_frames(); 324 task_retval(0); 325 async_manager(); 418 326 419 327 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.