Changeset ff6e91b in mainline for uspace/lib/ui/src
- Timestamp:
- 2021-08-30T20:41:27Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 81ec7e1
- Parents:
- 9b2e20c
- Location:
- uspace/lib/ui/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/menu.c
r9b2e20c rff6e91b 58 58 menu_frame_h = 4, 59 59 menu_frame_w_text = 2, 60 menu_frame_h_text = 1 60 menu_frame_h_text = 1, 61 menu_frame_h_margin_text = 1 61 62 }; 62 63 … … 276 277 * @return EOK on success or an error code 277 278 */ 279 errno_t ui_menu_paint_bg_gfx(ui_menu_t *menu, gfx_coord2_t *spos) 280 { 281 ui_resource_t *res; 282 ui_menu_geom_t geom; 283 gfx_rect_t bg_rect; 284 errno_t rc; 285 286 res = ui_menu_get_res(menu); 287 ui_menu_get_geom(menu, spos, &geom); 288 289 /* Paint menu frame */ 290 291 rc = gfx_set_color(res->gc, res->wnd_face_color); 292 if (rc != EOK) 293 goto error; 294 295 rc = ui_paint_outset_frame(res, &geom.outer_rect, &bg_rect); 296 if (rc != EOK) 297 goto error; 298 299 /* Paint menu background */ 300 301 rc = gfx_set_color(res->gc, res->wnd_face_color); 302 if (rc != EOK) 303 goto error; 304 305 rc = gfx_fill_rect(res->gc, &bg_rect); 306 if (rc != EOK) 307 goto error; 308 309 return EOK; 310 error: 311 return rc; 312 } 313 314 /** Paint menu. 315 * 316 * @param menu Menu 317 * @param spos Starting position (top-left corner) 318 * @return EOK on success or an error code 319 */ 320 errno_t ui_menu_paint_bg_text(ui_menu_t *menu, gfx_coord2_t *spos) 321 { 322 ui_resource_t *res; 323 ui_menu_geom_t geom; 324 gfx_rect_t rect; 325 errno_t rc; 326 327 res = ui_menu_get_res(menu); 328 ui_menu_get_geom(menu, spos, &geom); 329 330 /* Paint menu background */ 331 332 rc = gfx_set_color(res->gc, res->wnd_face_color); 333 if (rc != EOK) 334 goto error; 335 336 rc = gfx_fill_rect(res->gc, &geom.outer_rect); 337 if (rc != EOK) 338 goto error; 339 340 /* Paint menu box */ 341 342 rect = geom.outer_rect; 343 rect.p0.x += menu_frame_h_margin_text; 344 rect.p1.x -= menu_frame_h_margin_text; 345 346 rc = ui_paint_text_box(res, &rect, ui_box_single, res->wnd_face_color); 347 if (rc != EOK) 348 goto error; 349 350 return EOK; 351 error: 352 return rc; 353 } 354 355 /** Paint menu. 356 * 357 * @param menu Menu 358 * @param spos Starting position (top-left corner) 359 * @return EOK on success or an error code 360 */ 278 361 errno_t ui_menu_paint(ui_menu_t *menu, gfx_coord2_t *spos) 279 362 { … … 282 365 ui_menu_entry_t *mentry; 283 366 ui_menu_geom_t geom; 284 gfx_rect_t bg_rect;285 367 errno_t rc; 286 368 … … 288 370 ui_menu_get_geom(menu, spos, &geom); 289 371 290 /* Paint menu frame */ 291 292 rc = gfx_set_color(res->gc, res->wnd_face_color); 293 if (rc != EOK) 294 goto error; 295 296 rc = ui_paint_outset_frame(res, &geom.outer_rect, &bg_rect); 297 if (rc != EOK) 298 goto error; 299 300 /* Paint menu background */ 301 302 rc = gfx_set_color(res->gc, res->wnd_face_color); 303 if (rc != EOK) 304 goto error; 305 306 rc = gfx_fill_rect(res->gc, &bg_rect); 372 /* Paint menu frame and background */ 373 if (res->textmode) 374 rc = ui_menu_paint_bg_text(menu, spos); 375 else 376 rc = ui_menu_paint_bg_gfx(menu, spos); 307 377 if (rc != EOK) 308 378 goto error; -
uspace/lib/ui/src/paint.c
r9b2e20c rff6e91b 38 38 #include <gfx/context.h> 39 39 #include <gfx/render.h> 40 #include <gfx/text.h> 40 41 #include <ui/paint.h> 42 #include <stdlib.h> 43 #include <str.h> 41 44 #include "../private/resource.h" 45 46 /** Single box characters */ 47 static ui_box_chars_t single_box_chars = { 48 { 49 { "\u250c", "\u2500", "\u2510" }, 50 { "\u2502", " ", "\u2502" }, 51 { "\u2514", "\u2500", "\u2518" } 52 } 53 }; 54 55 /** Double box characters */ 56 static ui_box_chars_t double_box_chars = { 57 { 58 { "\u2554", "\u2550", "\u2557" }, 59 { "\u2551", " ", "\u2551" }, 60 { "\u255a", "\u2550", "\u255d" } 61 } 62 }; 42 63 43 64 /** Paint bevel. … … 324 345 } 325 346 347 /** Paint a text box. 348 * 349 * @param resource UI resource 350 * @param rect Rectangle inside which to paint the box 351 * @param style Box style 352 * @param color Color 353 * @return EOK on success or an error code 354 */ 355 errno_t ui_paint_text_box(ui_resource_t *resource, gfx_rect_t *rect, 356 ui_box_style_t style, gfx_color_t *color) 357 { 358 errno_t rc; 359 gfx_text_fmt_t fmt; 360 gfx_rect_t srect; 361 gfx_coord2_t pos; 362 gfx_coord2_t dim; 363 size_t bufsz; 364 size_t off; 365 int i; 366 gfx_coord_t y; 367 char *str = NULL; 368 ui_box_chars_t *boxc = NULL; 369 370 gfx_rect_points_sort(rect, &srect); 371 gfx_rect_dims(&srect, &dim); 372 373 /* Is rectangle large enough to hold box? */ 374 if (dim.x < 2 || dim.y < 2) 375 return EOK; 376 377 switch (style) { 378 case ui_box_single: 379 boxc = &single_box_chars; 380 break; 381 case ui_box_double: 382 boxc = &double_box_chars; 383 break; 384 } 385 386 if (boxc == NULL) 387 return EINVAL; 388 389 gfx_text_fmt_init(&fmt); 390 fmt.color = color; 391 392 bufsz = str_size(boxc->c[0][0]) + 393 str_size(boxc->c[0][1]) * (dim.x - 2) + 394 str_size(boxc->c[0][2]) + 1; 395 396 str = malloc(bufsz); 397 if (str == NULL) 398 return ENOMEM; 399 400 /* Top edge and corners */ 401 402 str_cpy(str, bufsz, boxc->c[0][0]); 403 off = str_size(boxc->c[0][0]); 404 405 for (i = 1; i < dim.x - 1; i++) { 406 str_cpy(str + off, bufsz - off, boxc->c[0][1]); 407 off += str_size(boxc->c[0][1]); 408 } 409 410 str_cpy(str + off, bufsz - off, boxc->c[0][2]); 411 off += str_size(boxc->c[0][2]); 412 str[off] = '\0'; 413 414 pos = rect->p0; 415 rc = gfx_puttext(resource->font, &pos, &fmt, str); 416 if (rc != EOK) 417 goto error; 418 419 /* Vertical edges */ 420 for (y = rect->p0.y + 1; y < rect->p1.y - 1; y++) { 421 pos.y = y; 422 423 pos.x = rect->p0.x; 424 rc = gfx_puttext(resource->font, &pos, &fmt, 425 boxc->c[1][0]); 426 if (rc != EOK) 427 goto error; 428 429 pos.x = rect->p1.x - 1; 430 rc = gfx_puttext(resource->font, &pos, &fmt, 431 boxc->c[1][2]); 432 if (rc != EOK) 433 goto error; 434 } 435 436 /* Bottom edge and corners */ 437 438 str_cpy(str, bufsz, boxc->c[2][0]); 439 off = str_size(boxc->c[2][0]); 440 441 for (i = 1; i < dim.x - 1; i++) { 442 str_cpy(str + off, bufsz - off, boxc->c[2][1]); 443 off += str_size(boxc->c[2][1]); 444 } 445 446 str_cpy(str + off, bufsz - off, boxc->c[2][2]); 447 off += str_size(boxc->c[2][2]); 448 str[off] = '\0'; 449 450 pos.x = rect->p0.x; 451 pos.y = rect->p1.y - 1; 452 rc = gfx_puttext(resource->font, &pos, &fmt, str); 453 if (rc != EOK) 454 goto error; 455 456 free(str); 457 return EOK; 458 error: 459 if (str != NULL) 460 free(str); 461 return rc; 462 } 463 326 464 /** @} 327 465 */ -
uspace/lib/ui/src/rbutton.c
r9b2e20c rff6e91b 322 322 323 323 rc = gfx_puttext(rbutton->group->res->font, &pos, &fmt, 324 rbutton->group->selected == rbutton ? "( *)" : "( )");324 rbutton->group->selected == rbutton ? "(\u2022)" : "( )"); 325 325 if (rc != EOK) 326 326 goto error; -
uspace/lib/ui/src/slider.c
r9b2e20c rff6e91b 332 332 gfx_coord_t w, i; 333 333 char *buf; 334 const char *gchar; 335 size_t gcharsz; 334 336 errno_t rc; 335 337 … … 344 346 345 347 w = slider->rect.p1.x - slider->rect.p0.x; 346 buf = malloc(w + 1); 348 gchar = "\u2550"; 349 gcharsz = str_size(gchar); 350 351 buf = malloc(w * gcharsz + 1); 347 352 if (buf == NULL) 348 353 return ENOMEM; 349 354 350 355 for (i = 0; i < w; i++) 351 buf[i] = '=';352 buf[w ] = '\0';356 str_cpy(buf + i * gcharsz, (w - i) * gcharsz + 1, gchar); 357 buf[w * gcharsz] = '\0'; 353 358 354 359 rc = gfx_puttext(slider->res->font, &pos, &fmt, buf); -
uspace/lib/ui/src/wdecor.c
r9b2e20c rff6e91b 180 180 181 181 if (wdecor->res->textmode != false) { 182 rc = ui_paint_bevel(wdecor->res->gc, &rect, 183 wdecor->res->wnd_frame_hi_color, 184 wdecor->res->wnd_frame_sh_color, 1, &rect); 182 rc = ui_paint_text_box(wdecor->res, &rect, 183 ui_box_double, wdecor->res->wnd_face_color); 185 184 if (rc != EOK) 186 185 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.