Changeset 7e38970d in mainline for uspace/app/barber/barber.c
- Timestamp:
- 2020-12-07T00:08:37Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 25f26600
- Parents:
- 7a873f0 (diff), 8596474 (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
r7a873f0 r7e38970d 1 1 /* 2 * Copyright (c) 2020 Jiri Svoboda 2 3 * Copyright (c) 2014 Martin Decky 3 4 * All rights reserved. … … 33 34 */ 34 35 36 #include <device/led_dev.h> 37 #include <errno.h> 38 #include <fibril_synch.h> 39 #include <gfximage/tga_gz.h> 40 #include <io/pixel.h> 41 #include <loc.h> 42 #include <stats.h> 35 43 #include <stdbool.h> 36 #include <errno.h>37 44 #include <stdio.h> 38 45 #include <stdlib.h> 39 #include <task.h>40 #include <loc.h>41 #include <stats.h>42 46 #include <str.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> 47 #include <ui/ui.h> 48 #include <ui/wdecor.h> 49 #include <ui/window.h> 50 #include <ui/image.h> 50 51 #include "images.h" 51 52 … … 72 73 } led_dev_t; 73 74 74 static char *winreg = NULL; 75 typedef struct { 76 ui_t *ui; 77 } barber_t; 75 78 76 79 static fibril_timer_t *led_timer = NULL; … … 89 92 90 93 static fibril_timer_t *frame_timer = NULL; 91 static canvas_t *frame_canvas;92 static surface_t *frames[FRAMES];94 static ui_image_t *frame_img; 95 static gfx_bitmap_t *frame_bmp[FRAMES]; 93 96 94 97 static unsigned int frame = 0; … … 98 101 static void frame_timer_callback(void *); 99 102 100 static bool decode_frames(void) 101 { 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 102 126 for (unsigned int i = 0; i < FRAMES; i++) { 103 frames[i] = decode_tga_gz(images[i].addr, images[i].size, 0); 104 if (frames[i] == NULL) { 127 rc = decode_tga_gz(gc, images[i].addr, images[i].size, 128 &frame_bmp[i], &rect); 129 if (rc != EOK) { 105 130 printf("Unable to decode frame %u.\n", i); 106 131 return false; 107 132 } 133 134 (void) rect; 108 135 } 109 136 110 137 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 } 111 148 } 112 149 … … 192 229 { 193 230 struct timespec prev; 231 gfx_rect_t rect; 194 232 getuptime(&prev); 195 233 … … 198 236 frame = 0; 199 237 200 update_canvas(frame_canvas, frames[frame]); 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); 201 245 202 246 struct timespec cur; … … 255 299 int main(int argc, char *argv[]) 256 300 { 257 const char *display_svc = DISPLAY_DEFAULT; 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; 258 312 int i; 259 313 … … 268 322 } 269 323 270 display_s vc = argv[i++];324 display_spec = argv[i++]; 271 325 } else { 272 326 printf("Invalid option '%s'.\n", argv[i]); … … 295 349 } 296 350 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); 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 } 320 405 321 406 plan_led_timer(); 322 407 plan_frame_timer(0); 323 408 324 task_retval(0); 325 async_manager(); 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(); 326 418 327 419 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.