Changeset 8fa65af0 in mainline for uspace/app/gfxdemo/gfxdemo.c
- Timestamp:
- 2020-10-06T08:59:57Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74f59b7
- Parents:
- 25f2983b
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-05 18:59:36)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-06 08:59:57)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r25f2983b r8fa65af0 42 42 #include <gfx/color.h> 43 43 #include <gfx/render.h> 44 #include <gfx/font.h> 45 #include <gfx/text.h> 46 #include <gfx/typeface.h> 44 47 #include <io/console.h> 45 48 #include <io/pixelmap.h> … … 366 369 return rc; 367 370 } 371 368 372 /** Run bitmap color key demo on a graphic context. 369 373 * … … 424 428 } 425 429 426 /** Run demo loopon a graphic context.430 /** Run text demo on a graphic context. 427 431 * 428 432 * @param gc Graphic context … … 430 434 * @param h Height 431 435 */ 436 static errno_t demo_text(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 437 { 438 gfx_color_t *color = NULL; 439 gfx_rect_t rect; 440 gfx_typeface_t *tface = NULL; 441 gfx_font_info_t *finfo; 442 gfx_font_t *font = NULL; 443 gfx_coord2_t pos; 444 gfx_text_fmt_t fmt; 445 int i; 446 errno_t rc; 447 448 rc = gfx_typeface_open(gc, "/data/font/helena.tpf", &tface); 449 if (rc != EOK) { 450 printf("Error opening typeface\n"); 451 goto error; 452 } 453 454 finfo = gfx_typeface_first_font(tface); 455 if (finfo == NULL) { 456 printf("Typeface contains no font.\n"); 457 rc = ENOENT; 458 goto error; 459 } 460 461 rc = gfx_font_open(finfo, &font); 462 if (rc != EOK) { 463 printf("Error opening font.\n"); 464 goto error; 465 } 466 467 rc = clear_scr(gc, w, h); 468 if (rc != EOK) 469 goto error; 470 471 /* Vertical bars */ 472 473 for (i = 0; i < 20; i++) { 474 rc = gfx_color_new_rgb_i16(0, 0x8000 * i / 20, 475 0x8000 * i / 20, &color); 476 if (rc != EOK) 477 goto error; 478 479 rc = gfx_set_color(gc, color); 480 if (rc != EOK) 481 goto error; 482 483 rect.p0.x = w * i / 20; 484 rect.p0.y = 0; 485 rect.p1.x = w * (i + 1) / 20; 486 rect.p1.y = h; 487 488 rc = gfx_fill_rect(gc, &rect); 489 if (rc != EOK) 490 goto error; 491 492 gfx_color_delete(color); 493 } 494 495 rc = gfx_color_new_rgb_i16(0, 0, 0x8000, &color); 496 if (rc != EOK) 497 goto error; 498 499 rc = gfx_set_color(gc, color); 500 if (rc != EOK) 501 goto error; 502 503 rect.p0.x = w / 20; 504 rect.p0.y = 3 * h / 15; 505 rect.p1.x = w - w / 20; 506 rect.p1.y = 5 * h / 15; 507 508 rc = gfx_fill_rect(gc, &rect); 509 if (rc != EOK) 510 goto error; 511 512 gfx_color_delete(color); 513 514 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 515 if (rc != EOK) 516 goto error; 517 518 rc = gfx_set_color(gc, color); 519 if (rc != EOK) 520 goto error; 521 522 gfx_text_fmt_init(&fmt); 523 524 pos.x = rect.p0.x; 525 pos.y = rect.p0.y; 526 rc = gfx_puttext(font, &pos, &fmt, "Top left"); 527 if (rc != EOK) { 528 printf("Error rendering text.\n"); 529 goto error; 530 } 531 532 pos.x = (rect.p0.x + rect.p1.x) / 2; 533 pos.y = rect.p0.y; 534 fmt.halign = gfx_halign_center; 535 rc = gfx_puttext(font, &pos, &fmt, "Top center"); 536 if (rc != EOK) 537 goto error; 538 539 pos.x = rect.p1.x; 540 pos.y = rect.p0.y; 541 fmt.halign = gfx_halign_right; 542 rc = gfx_puttext(font, &pos, &fmt, "Top right"); 543 if (rc != EOK) 544 goto error; 545 546 fmt.valign = gfx_valign_center; 547 548 pos.x = rect.p0.x; 549 pos.y = (rect.p0.y + rect.p1.y) / 2; 550 fmt.halign = gfx_halign_left; 551 rc = gfx_puttext(font, &pos, &fmt, "Center left"); 552 if (rc != EOK) 553 goto error; 554 555 pos.x = (rect.p0.x + rect.p1.x) / 2; 556 pos.y = (rect.p0.y + rect.p1.y) / 2; 557 fmt.halign = gfx_halign_center; 558 rc = gfx_puttext(font, &pos, &fmt, "Center"); 559 if (rc != EOK) 560 goto error; 561 562 pos.x = rect.p1.x; 563 pos.y = (rect.p0.y + rect.p1.y) / 2; 564 fmt.halign = gfx_halign_right; 565 rc = gfx_puttext(font, &pos, &fmt, "Center right"); 566 if (rc != EOK) 567 goto error; 568 569 fmt.valign = gfx_valign_bottom; 570 571 pos.x = rect.p0.x; 572 pos.y = rect.p1.y; 573 fmt.halign = gfx_halign_left; 574 rc = gfx_puttext(font, &pos, &fmt, "Bottom left"); 575 if (rc != EOK) 576 goto error; 577 578 pos.x = (rect.p0.x + rect.p1.x) / 2; 579 pos.y = rect.p1.y; 580 fmt.halign = gfx_halign_center; 581 rc = gfx_puttext(font, &pos, &fmt, "Bottom center"); 582 if (rc != EOK) 583 goto error; 584 585 pos.x = rect.p1.x; 586 pos.y = rect.p1.y; 587 fmt.halign = gfx_halign_right; 588 rc = gfx_puttext(font, &pos, &fmt, "Bottom right"); 589 if (rc != EOK) 590 goto error; 591 592 gfx_text_fmt_init(&fmt); 593 594 for (i = 0; i < 8; i++) { 595 pos.x = w / 20; 596 pos.y = (7 + i) * h / 15; 597 rc = gfx_puttext(font, &pos, &fmt, "The quick brown fox jumps over the lazy dog."); 598 if (rc != EOK) 599 goto error; 600 } 601 602 for (i = 0; i < 10; i++) { 603 fibril_usleep(500 * 1000); 604 if (quit) 605 break; 606 } 607 608 gfx_color_delete(color); 609 610 gfx_font_close(font); 611 gfx_typeface_destroy(tface); 612 return EOK; 613 error: 614 if (font != NULL) 615 gfx_font_close(font); 616 if (tface != NULL) 617 gfx_typeface_destroy(tface); 618 return rc; 619 } 620 621 /** Run demo loop on a graphic context. 622 * 623 * @param gc Graphic context 624 * @param w Width 625 * @param h Height 626 */ 432 627 static errno_t demo_loop(gfx_context_t *gc, gfx_coord_t w, gfx_coord_t h) 433 628 { … … 448 643 449 644 rc = demo_bitmap_kc(gc, w, h); 645 if (rc != EOK) 646 return rc; 647 648 rc = demo_text(gc, w, h); 450 649 if (rc != EOK) 451 650 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.