Changeset ed1a948 in mainline for uspace/lib/ui/src/wdecor.c
- Timestamp:
- 2023-09-20T13:10:28Z (15 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d1bcd7
- Parents:
- 153dd3b
- git-author:
- Jiri Svoboda <jiri@…> (2023-09-19 17:10:04)
- git-committer:
- Jiri Svoboda <jiri@…> (2023-09-20 13:10:28)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/wdecor.c
r153dd3b red1a948 104 104 /** Window caption horizontal margin in text mode */ 105 105 wdecor_cap_hmargin_text = 1, 106 /** System menu handle width */ 107 wdecor_sysmenu_hdl_w = 20, 108 /** System menu handle height */ 109 wdecor_sysmenu_hdl_h = 20, 110 /** System menu handle width in text mode */ 111 wdecor_sysmenu_hdl_w_text = 3, 112 /** System menu handle height in text mode */ 113 wdecor_sysmenu_hdl_h_text = 1, 106 114 /** Close button cross leg length */ 107 115 wdecor_close_cross_n = 5, … … 296 304 } 297 305 306 /** Paint system menu handle in graphics mode. 307 * 308 * @param wdecor Window decoration 309 * @param rect System menu handle rectangle 310 * @return EOK on success or an error code 311 */ 312 errno_t ui_wdecor_sysmenu_hdl_paint_gfx(ui_wdecor_t *wdecor, gfx_rect_t *rect) 313 { 314 errno_t rc; 315 gfx_rect_t mrect; 316 gfx_rect_t inside; 317 gfx_coord2_t center; 318 319 rc = gfx_set_color(wdecor->res->gc, wdecor->sysmenu_hdl_active ? 320 wdecor->res->btn_shadow_color : wdecor->res->btn_face_color); 321 if (rc != EOK) 322 return rc; 323 324 rc = gfx_fill_rect(wdecor->res->gc, rect); 325 if (rc != EOK) 326 return rc; 327 328 center.x = (rect->p0.x + rect->p1.x) / 2; 329 center.y = (rect->p0.y + rect->p1.y) / 2; 330 mrect.p0.x = center.x - 7; 331 mrect.p0.y = center.y - 1; 332 mrect.p1.x = center.x + 7; 333 mrect.p1.y = center.y + 1 + 1; 334 335 /* XXX Not really a bevel, just a frame */ 336 rc = ui_paint_bevel(wdecor->res->gc, &mrect, 337 wdecor->res->btn_text_color, wdecor->res->btn_text_color, 1, 338 &inside); 339 if (rc != EOK) 340 return rc; 341 342 rc = gfx_set_color(wdecor->res->gc, wdecor->res->btn_highlight_color); 343 if (rc != EOK) 344 return rc; 345 346 rc = gfx_fill_rect(wdecor->res->gc, &inside); 347 if (rc != EOK) 348 return rc; 349 350 return EOK; 351 } 352 353 /** Paint system menu handle in text mode. 354 * 355 * @param wdecor Window decoration 356 * @param rect System menu handle rectangle 357 * @return EOK on success or an error code 358 */ 359 errno_t ui_wdecor_sysmenu_hdl_paint_text(ui_wdecor_t *wdecor, gfx_rect_t *rect) 360 { 361 errno_t rc; 362 gfx_text_fmt_t fmt; 363 364 gfx_text_fmt_init(&fmt); 365 fmt.font = wdecor->res->font; 366 fmt.color = wdecor->res->tbar_act_text_color; 367 fmt.halign = gfx_halign_left; 368 fmt.valign = gfx_valign_top; 369 370 rc = gfx_puttext(&rect->p0, &fmt, "[\u2261]"); 371 if (rc != EOK) 372 return rc; 373 374 return EOK; 375 } 376 377 /** Paint system menu handle. 378 * 379 * @param wdecor Window decoration 380 * @param rect System menu handle rectangle 381 * @return EOK on success or an error code 382 */ 383 errno_t ui_wdecor_sysmenu_hdl_paint(ui_wdecor_t *wdecor, gfx_rect_t *rect) 384 { 385 errno_t rc; 386 387 if (wdecor->res->textmode) 388 rc = ui_wdecor_sysmenu_hdl_paint_text(wdecor, rect); 389 else 390 rc = ui_wdecor_sysmenu_hdl_paint_gfx(wdecor, rect); 391 392 return rc; 393 } 394 395 /** Set system menu handle active flag. 396 * 397 * @param wdecor Window decoration 398 * @param active @c true iff handle should be active 399 */ 400 void ui_wdecor_sysmenu_hdl_set_active(ui_wdecor_t *wdecor, bool active) 401 { 402 ui_wdecor_geom_t geom; 403 404 wdecor->sysmenu_hdl_active = active; 405 406 ui_wdecor_get_geom(wdecor, &geom); 407 (void) ui_wdecor_sysmenu_hdl_paint(wdecor, &geom.sysmenu_hdl_rect); 408 } 409 298 410 /** Paint window decoration. 299 411 * … … 395 507 return rc; 396 508 509 if ((wdecor->style & ui_wds_sysmenu_hdl) != 0) { 510 rc = ui_wdecor_sysmenu_hdl_paint(wdecor, 511 &geom.sysmenu_hdl_rect); 512 if (rc != EOK) 513 return rc; 514 } 515 397 516 if (wdecor->btn_min != NULL) { 398 517 rc = ui_pbutton_paint(wdecor->btn_min); … … 520 639 gfx_coord_t btn_y; 521 640 gfx_coord_t cap_hmargin; 641 gfx_coord_t cap_x; 642 gfx_coord_t hdl_x_off; 643 gfx_coord_t hdl_y_off; 644 gfx_coord_t hdl_w; 645 gfx_coord_t hdl_h; 522 646 523 647 /* Does window have a frame? */ … … 568 692 } 569 693 694 /* Does window have a sysmenu handle? */ 695 if ((wdecor->style & ui_wds_sysmenu_hdl) != 0) { 696 if (wdecor->res->textmode) { 697 hdl_x_off = 2; 698 hdl_y_off = 0; 699 hdl_w = wdecor_sysmenu_hdl_w_text; 700 hdl_h = wdecor_sysmenu_hdl_h_text; 701 } else { 702 hdl_x_off = 1; 703 hdl_y_off = 1; 704 hdl_w = wdecor_sysmenu_hdl_w; 705 hdl_h = wdecor_sysmenu_hdl_h; 706 } 707 708 geom->sysmenu_hdl_rect.p0.x = geom->title_bar_rect.p0.x + 709 hdl_x_off; 710 geom->sysmenu_hdl_rect.p0.y = geom->title_bar_rect.p0.y + 711 hdl_y_off; 712 geom->sysmenu_hdl_rect.p1.x = geom->sysmenu_hdl_rect.p0.x + 713 hdl_w; 714 geom->sysmenu_hdl_rect.p1.y = geom->sysmenu_hdl_rect.p0.y + 715 hdl_h; 716 cap_x = hdl_w; 717 } else { 718 geom->sysmenu_hdl_rect.p0.x = 0; 719 geom->sysmenu_hdl_rect.p0.y = 0; 720 geom->sysmenu_hdl_rect.p1.x = 0; 721 geom->sysmenu_hdl_rect.p1.y = 0; 722 cap_x = 0; 723 } 724 570 725 /* Does window have a close button? */ 571 726 if ((wdecor->style & ui_wds_close_btn) != 0) { … … 640 795 } 641 796 642 if (wdecor->res->textmode == false) 643 cap_hmargin = wdecor_cap_hmargin; 644 else 645 cap_hmargin = wdecor_cap_hmargin_text; 646 647 geom->caption_rect.p0.x = geom->title_bar_rect.p0.x + 648 cap_hmargin; 649 geom->caption_rect.p0.y = geom->title_bar_rect.p0.y; 650 geom->caption_rect.p1.x = btn_x - cap_hmargin; 651 geom->caption_rect.p1.y = geom->title_bar_rect.p1.y; 797 if ((wdecor->style & ui_wds_titlebar) != 0) { 798 if (wdecor->res->textmode == false) 799 cap_hmargin = wdecor_cap_hmargin; 800 else 801 cap_hmargin = wdecor_cap_hmargin_text; 802 803 geom->caption_rect.p0.x = geom->title_bar_rect.p0.x + 804 cap_hmargin + cap_x; 805 geom->caption_rect.p0.y = geom->title_bar_rect.p0.y; 806 geom->caption_rect.p1.x = btn_x - cap_hmargin; 807 geom->caption_rect.p1.y = geom->title_bar_rect.p1.y; 808 } else { 809 geom->caption_rect.p0.x = 0; 810 geom->caption_rect.p0.y = 0; 811 geom->caption_rect.p1.x = 0; 812 geom->caption_rect.p1.y = 0; 813 } 652 814 } 653 815 … … 828 990 if (event->type == KEY_PRESS && (event->mods & (KM_CTRL | KM_ALT | 829 991 KM_SHIFT)) == 0) { 830 if (event->key == KC_F9) 992 if (event->key == KC_F9) { 993 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 831 994 ui_wdecor_sysmenu(wdecor, event->kbd_id); 995 } 832 996 } 833 997 … … 881 1045 882 1046 ui_wdecor_get_geom(wdecor, &geom); 1047 1048 if ((wdecor->style & ui_wds_sysmenu_hdl) != 0) { 1049 if (event->type == POS_PRESS && 1050 gfx_pix_inside_rect(&pos, &geom.sysmenu_hdl_rect)) { 1051 ui_wdecor_sysmenu_hdl_set_active(wdecor, true); 1052 ui_wdecor_sysmenu(wdecor, event->pos_id); 1053 return ui_claimed; 1054 } 1055 } 883 1056 884 1057 if (wdecor->btn_min != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.