Changeset 86fff971 in mainline
- Timestamp:
- 2022-04-04T18:49:30Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fd05ea6
- Parents:
- d68239a1
- Location:
- uspace/lib/ui
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/paint.h
rd68239a1 r86fff971 63 63 extern errno_t ui_paint_right_triangle(gfx_context_t *, gfx_coord2_t *, 64 64 gfx_coord_t); 65 extern errno_t ui_paint_cross(gfx_context_t *, gfx_coord2_t *, gfx_coord_t, 66 gfx_coord_t, gfx_coord_t); 65 67 extern errno_t ui_paint_text_box(ui_resource_t *, gfx_rect_t *, 66 68 ui_box_style_t, gfx_color_t *); -
uspace/lib/ui/src/checkbox.c
rd68239a1 r86fff971 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 52 52 checkbox_box_h = 16, 53 53 checkbox_label_margin = 8, 54 checkbox_cross_n = 5, 55 checkbox_cross_w = 2, 56 checkbox_cross_h = 2 54 57 }; 55 58 … … 188 191 189 192 if (checkbox->checked) { 190 box_center.x = (box_inside.p0.x + box_inside.p1.x) / 2;191 box_center.y = (box_inside.p0.y + box_inside.p1.y) / 2;192 193 gfx_text_fmt_init(&fmt);194 fmt.font = checkbox->res->font; 195 fmt.color = checkbox->res->entry_fg_color;196 fmt.halign = gfx_halign_center;197 fmt.valign = gfx_valign_center; 198 199 rc = gfx_puttext(&box_center, &fmt, "X");193 rc = gfx_set_color(checkbox->res->gc, 194 checkbox->res->entry_fg_color); 195 if (rc != EOK) 196 goto error; 197 198 box_center.x = (box_inside.p0.x + box_inside.p1.x) / 2 - 1; 199 box_center.y = (box_inside.p0.y + box_inside.p1.y) / 2 - 1; 200 201 rc = ui_paint_cross(checkbox->res->gc, &box_center, 202 checkbox_cross_n, checkbox_cross_w, checkbox_cross_h); 200 203 if (rc != EOK) 201 204 goto error; -
uspace/lib/ui/src/paint.c
rd68239a1 r86fff971 365 365 * @param pos Center position 366 366 * @param n Length of triangle side 367 * @return EOK on success or an error code 367 368 */ 368 369 errno_t ui_paint_up_triangle(gfx_context_t *gc, gfx_coord2_t *pos, … … 391 392 * @param pos Center position 392 393 * @param n Length of triangle side 394 * @return EOK on success or an error code 393 395 */ 394 396 errno_t ui_paint_down_triangle(gfx_context_t *gc, gfx_coord2_t *pos, … … 417 419 * @param pos Center position 418 420 * @param n Length of triangle side 421 * @return EOK on success or an error code 419 422 */ 420 423 errno_t ui_paint_left_triangle(gfx_context_t *gc, gfx_coord2_t *pos, … … 443 446 * @param pos Center position 444 447 * @param n Length of triangle side 448 * @return EOK on success or an error code 445 449 */ 446 450 errno_t ui_paint_right_triangle(gfx_context_t *gc, gfx_coord2_t *pos, … … 456 460 rect.p1.x = pos->x + n / 2 - i + 1; 457 461 rect.p1.y = pos->y + i + 1; 462 rc = gfx_fill_rect(gc, &rect); 463 if (rc != EOK) 464 return rc; 465 } 466 467 return EOK; 468 } 469 470 /** Paint diagonal cross (X). 471 * 472 * @param gc Graphic context 473 * @param pos Center position 474 * @param n Length of each leg 475 * @param w Pen width 476 * @param h Pen height 477 * @return EOK on success or an error code 478 */ 479 errno_t ui_paint_cross(gfx_context_t *gc, gfx_coord2_t *pos, 480 gfx_coord_t n, gfx_coord_t w, gfx_coord_t h) 481 { 482 gfx_coord_t i; 483 gfx_rect_t rect; 484 errno_t rc; 485 486 rect.p0.x = pos->x; 487 rect.p0.y = pos->y; 488 rect.p1.x = pos->x + w; 489 rect.p1.y = pos->y + h; 490 rc = gfx_fill_rect(gc, &rect); 491 if (rc != EOK) 492 return rc; 493 494 for (i = 1; i < n; i++) { 495 rect.p0.x = pos->x - i; 496 rect.p0.y = pos->y - i; 497 rect.p1.x = pos->x - i + w; 498 rect.p1.y = pos->y - i + h; 499 rc = gfx_fill_rect(gc, &rect); 500 if (rc != EOK) 501 return rc; 502 503 rect.p0.x = pos->x - i; 504 rect.p0.y = pos->y + i; 505 rect.p1.x = pos->x - i + w; 506 rect.p1.y = pos->y + i + h; 507 rc = gfx_fill_rect(gc, &rect); 508 if (rc != EOK) 509 return rc; 510 511 rect.p0.x = pos->x + i; 512 rect.p0.y = pos->y - i; 513 rect.p1.x = pos->x + i + w; 514 rect.p1.y = pos->y - i + h; 515 rc = gfx_fill_rect(gc, &rect); 516 if (rc != EOK) 517 return rc; 518 519 rect.p0.x = pos->x + i; 520 rect.p0.y = pos->y + i; 521 rect.p1.x = pos->x + i + w; 522 rect.p1.y = pos->y + i + h; 458 523 rc = gfx_fill_rect(gc, &rect); 459 524 if (rc != EOK) -
uspace/lib/ui/src/wdecor.c
rd68239a1 r86fff971 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 50 50 51 51 static void ui_wdecor_btn_clicked(ui_pbutton_t *, void *); 52 static errno_t ui_wdecor_btn_close_paint(ui_pbutton_t *, void *, 53 gfx_coord2_t *); 52 54 53 55 static ui_pbutton_cb_t ui_wdecor_btn_close_cb = { 54 56 .clicked = ui_wdecor_btn_clicked 57 }; 58 59 static ui_pbutton_decor_ops_t ui_wdecor_btn_close_decor_ops = { 60 .paint = ui_wdecor_btn_close_paint 55 61 }; 56 62 … … 62 68 wdecor_tbar_h = 22, 63 69 wdecor_frame_w = 4, 64 wdecor_frame_w_text = 1 70 wdecor_frame_w_text = 1, 71 wdecor_close_cross_n = 5, 72 wdecor_close_cross_w = 2, 73 wdecor_close_cross_h = 1 65 74 }; 66 75 … … 98 107 ui_pbutton_set_cb(wdecor->btn_close, &ui_wdecor_btn_close_cb, 99 108 (void *)wdecor); 109 110 ui_pbutton_set_decor_ops(wdecor->btn_close, 111 &ui_wdecor_btn_close_decor_ops, (void *)wdecor); 100 112 101 113 wdecor->res = resource; … … 647 659 } 648 660 661 /** Paint close button decoration. 662 * 663 * @param pbutton Push button 664 * @param arg Argument (ui_wdecor_t *) 665 * @param pos Center position 666 */ 667 static errno_t ui_wdecor_btn_close_paint(ui_pbutton_t *pbutton, 668 void *arg, gfx_coord2_t *pos) 669 { 670 ui_wdecor_t *wdecor = (ui_wdecor_t *)arg; 671 gfx_coord2_t p; 672 errno_t rc; 673 674 rc = gfx_set_color(wdecor->res->gc, wdecor->res->btn_text_color); 675 if (rc != EOK) 676 return rc; 677 678 p.x = pos->x - 1; 679 p.y = pos->y - 1; 680 return ui_paint_cross(wdecor->res->gc, &p, wdecor_close_cross_n, 681 wdecor_close_cross_w, wdecor_close_cross_h); 682 } 683 649 684 /** @} 650 685 */ -
uspace/lib/ui/test/paint.c
rd68239a1 r86fff971 332 332 } 333 333 334 /** Paint diagonal cross (X) */ 335 PCUT_TEST(cross) 336 { 337 errno_t rc; 338 gfx_context_t *gc = NULL; 339 test_gc_t tgc; 340 gfx_coord2_t center; 341 342 memset(&tgc, 0, sizeof(tgc)); 343 rc = gfx_context_new(&ops, &tgc, &gc); 344 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 345 346 center.x = 0; 347 center.y = 0; 348 349 rc = ui_paint_cross(gc, ¢er, 5, 1, 2); 350 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 351 352 rc = gfx_context_delete(gc); 353 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 354 } 355 334 356 /** Paint text box */ 335 357 PCUT_TEST(text_box)
Note:
See TracChangeset
for help on using the changeset viewer.