Changeset c3d4b39b in mainline
- Timestamp:
- 2024-03-11T10:28:12Z (10 months ago)
- Branches:
- master
- Children:
- 45208e22
- Parents:
- 3f81cdc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/viewer/viewer.c
r3f81cdc rc3d4b39b 55 55 char **imgs; 56 56 57 bool fullscreen; 57 58 ui_window_t *window; 58 59 gfx_bitmap_t *bitmap; … … 66 67 gfx_rect_t *); 67 68 static bool viewer_img_setup(viewer_t *, gfx_bitmap_t *, gfx_rect_t *); 69 static void viewer_window_destroy(viewer_t *); 68 70 69 71 static void wnd_close(ui_window_t *, void *); … … 219 221 } 220 222 221 int main(int argc, char *argv[])222 { 223 const char *display_spec = UI_ANY_DEFAULT;223 static errno_t viewer_window_create(viewer_t *viewer) 224 { 225 ui_wnd_params_t params; 224 226 gfx_bitmap_t *lbitmap; 225 227 gfx_rect_t lrect; 226 bool fullscreen = false;227 gfx_rect_t rect;228 228 gfx_rect_t wrect; 229 229 gfx_coord2_t off; 230 ui_t *ui = NULL; 231 ui_wnd_params_t params; 232 viewer_t *viewer; 230 gfx_rect_t rect; 233 231 errno_t rc; 234 int i;235 unsigned u;236 237 viewer = calloc(1, sizeof(viewer_t));238 if (viewer == NULL) {239 printf("Out of memory.\n");240 goto error;241 }242 243 i = 1;244 while (i < argc && argv[i][0] == '-') {245 if (str_cmp(argv[i], "-d") == 0) {246 ++i;247 if (i >= argc) {248 printf("Argument missing.\n");249 print_syntax();250 goto error;251 }252 253 display_spec = argv[i++];254 } else if (str_cmp(argv[i], "-f") == 0) {255 ++i;256 fullscreen = true;257 } else {258 printf("Invalid option '%s'.\n", argv[i]);259 print_syntax();260 goto error;261 }262 }263 264 if (i >= argc) {265 printf("No image files specified.\n");266 print_syntax();267 goto error;268 }269 270 viewer->imgs_count = argc - i;271 viewer->imgs = calloc(viewer->imgs_count, sizeof(char *));272 if (viewer->imgs == NULL) {273 printf("Out of memory.\n");274 goto error;275 }276 277 for (int j = 0; j < argc - i; j++) {278 viewer->imgs[j] = str_dup(argv[i + j]);279 if (viewer->imgs[j] == NULL) {280 printf("Out of memory.\n");281 goto error;282 }283 }284 285 rc = ui_create(display_spec, &ui);286 if (rc != EOK) {287 printf("Error creating UI on display %s.\n", display_spec);288 goto error;289 }290 291 if (ui_is_fullscreen(ui))292 fullscreen = true;293 294 viewer->ui = ui;295 232 296 233 /* … … 305 242 params.rect.p1.y = 1; 306 243 307 if ( fullscreen) {244 if (viewer->fullscreen) { 308 245 params.style &= ~ui_wds_decorated; 309 246 params.placement = ui_wnd_place_full_screen; 310 247 } 311 248 312 rc = ui_window_create( ui, ¶ms, &viewer->window);249 rc = ui_window_create(viewer->ui, ¶ms, &viewer->window); 313 250 if (rc != EOK) { 314 251 printf("Error creating window.\n"); … … 331 268 * to rect 332 269 */ 333 ui_wdecor_rect_from_app( ui, params.style, &lrect, &wrect);270 ui_wdecor_rect_from_app(viewer->ui, params.style, &lrect, &wrect); 334 271 off = wrect.p0; 335 272 gfx_rect_rtranslate(&off, &wrect, &rect); 336 273 337 if (! fullscreen) {274 if (!viewer->fullscreen) { 338 275 rc = ui_window_resize(viewer->window, &rect); 339 276 if (rc != EOK) { … … 354 291 goto error; 355 292 } 293 294 return EOK; 295 error: 296 viewer_window_destroy(viewer); 297 return rc; 298 } 299 300 static void viewer_window_destroy(viewer_t *viewer) 301 { 302 if (viewer->window != NULL) 303 ui_window_destroy(viewer->window); 304 viewer->window = NULL; 305 } 306 307 int main(int argc, char *argv[]) 308 { 309 const char *display_spec = UI_ANY_DEFAULT; 310 ui_t *ui = NULL; 311 viewer_t *viewer; 312 errno_t rc; 313 int i; 314 unsigned u; 315 316 viewer = calloc(1, sizeof(viewer_t)); 317 if (viewer == NULL) { 318 printf("Out of memory.\n"); 319 goto error; 320 } 321 322 i = 1; 323 while (i < argc && argv[i][0] == '-') { 324 if (str_cmp(argv[i], "-d") == 0) { 325 ++i; 326 if (i >= argc) { 327 printf("Argument missing.\n"); 328 print_syntax(); 329 goto error; 330 } 331 332 display_spec = argv[i++]; 333 } else if (str_cmp(argv[i], "-f") == 0) { 334 ++i; 335 viewer->fullscreen = true; 336 } else { 337 printf("Invalid option '%s'.\n", argv[i]); 338 print_syntax(); 339 goto error; 340 } 341 } 342 343 if (i >= argc) { 344 printf("No image files specified.\n"); 345 print_syntax(); 346 goto error; 347 } 348 349 viewer->imgs_count = argc - i; 350 viewer->imgs = calloc(viewer->imgs_count, sizeof(char *)); 351 if (viewer->imgs == NULL) { 352 printf("Out of memory.\n"); 353 goto error; 354 } 355 356 for (int j = 0; j < argc - i; j++) { 357 viewer->imgs[j] = str_dup(argv[i + j]); 358 if (viewer->imgs[j] == NULL) { 359 printf("Out of memory.\n"); 360 goto error; 361 } 362 } 363 364 rc = ui_create(display_spec, &ui); 365 if (rc != EOK) { 366 printf("Error creating UI on display %s.\n", display_spec); 367 goto error; 368 } 369 370 if (ui_is_fullscreen(ui)) 371 viewer->fullscreen = true; 372 373 viewer->ui = ui; 374 375 rc = viewer_window_create(viewer); 376 if (rc != EOK) 377 goto error; 356 378 357 379 ui_run(ui); … … 370 392 free(viewer->imgs); 371 393 } 372 if (viewer != NULL && viewer->window != NULL)373 ui_window_destroy(viewer->window);394 if (viewer != NULL) 395 viewer_window_destroy(viewer); 374 396 if (ui != NULL) 375 397 ui_destroy(ui);
Note:
See TracChangeset
for help on using the changeset viewer.