Changeset ff6e91b in mainline
- Timestamp:
- 2021-08-30T20:41:27Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 81ec7e1
- Parents:
- 9b2e20c
- Location:
- uspace/lib/ui
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/types/ui/paint.h
r9b2e20c rff6e91b 49 49 } ui_fcircle_part_t; 50 50 51 /** Box characters for a particular box style. 52 * 53 * The first coordinate selects top, center, bottom, 54 * the second coordinate selects left, center, right. 55 * The top/bottom, left/right characters correpsond to corners, 56 * the characters with one center coordinate correspond to edges: 57 * 58 * 0 1 2 59 * 0 '+' '-' '+' 60 * 1 ' |' ' ' '|' 61 * 2 '+' '-' '+' 62 * 63 */ 64 typedef struct { 65 const char *c[3][3]; 66 } ui_box_chars_t; 67 68 /** Box style */ 69 typedef enum { 70 /** Single box */ 71 ui_box_single, 72 /** Double box */ 73 ui_box_double 74 } ui_box_style_t; 75 51 76 #endif 52 77 -
uspace/lib/ui/include/ui/paint.h
r9b2e20c rff6e91b 55 55 extern errno_t ui_paint_filled_circle(gfx_context_t *, gfx_coord2_t *, 56 56 gfx_coord_t, ui_fcircle_part_t); 57 extern errno_t ui_paint_text_box(ui_resource_t *, gfx_rect_t *, 58 ui_box_style_t, gfx_color_t *); 57 59 58 60 #endif -
uspace/lib/ui/private/menu.h
r9b2e20c rff6e91b 82 82 extern void ui_menu_get_geom(ui_menu_t *, gfx_coord2_t *, ui_menu_geom_t *); 83 83 extern ui_resource_t *ui_menu_get_res(ui_menu_t *); 84 extern errno_t ui_menu_paint_bg_gfx(ui_menu_t *, gfx_coord2_t *); 85 extern errno_t ui_menu_paint_bg_text(ui_menu_t *, gfx_coord2_t *); 84 86 85 87 #endif -
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; -
uspace/lib/ui/test/menu.c
r9b2e20c rff6e91b 209 209 } 210 210 211 /** Paint background in graphics mode */ 212 PCUT_TEST(paint_bg_gfx) 213 { 214 ui_t *ui = NULL; 215 ui_window_t *window = NULL; 216 ui_wnd_params_t params; 217 ui_menu_bar_t *mbar = NULL; 218 ui_menu_t *menu = NULL; 219 gfx_rect_t prect; 220 gfx_coord2_t pos; 221 errno_t rc; 222 223 rc = ui_create_disp(NULL, &ui); 224 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 225 226 ui_wnd_params_init(¶ms); 227 params.caption = "Hello"; 228 229 rc = ui_window_create(ui, ¶ms, &window); 230 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 231 PCUT_ASSERT_NOT_NULL(window); 232 233 rc = ui_menu_bar_create(ui, window, &mbar); 234 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 235 PCUT_ASSERT_NOT_NULL(mbar); 236 237 rc = ui_menu_create(mbar, "Test", &menu); 238 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 239 PCUT_ASSERT_NOT_NULL(menu); 240 241 prect.p0.x = 0; 242 prect.p0.y = 0; 243 prect.p1.x = 0; 244 prect.p1.y = 0; 245 246 /* Menu needs to be open to be able to paint it */ 247 rc = ui_menu_open(menu, &prect); 248 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 249 250 pos.x = 0; 251 pos.y = 0; 252 rc = ui_menu_paint_bg_gfx(menu, &pos); 253 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 254 255 ui_menu_bar_destroy(mbar); 256 ui_window_destroy(window); 257 ui_destroy(ui); 258 } 259 260 /** Paint background in text mode */ 261 PCUT_TEST(paint_bg_text) 262 { 263 ui_t *ui = NULL; 264 ui_window_t *window = NULL; 265 ui_wnd_params_t params; 266 ui_menu_bar_t *mbar = NULL; 267 ui_menu_t *menu = NULL; 268 gfx_rect_t prect; 269 gfx_coord2_t pos; 270 errno_t rc; 271 272 rc = ui_create_disp(NULL, &ui); 273 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 274 275 ui_wnd_params_init(¶ms); 276 params.caption = "Hello"; 277 278 rc = ui_window_create(ui, ¶ms, &window); 279 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 280 PCUT_ASSERT_NOT_NULL(window); 281 282 rc = ui_menu_bar_create(ui, window, &mbar); 283 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 284 PCUT_ASSERT_NOT_NULL(mbar); 285 286 rc = ui_menu_create(mbar, "Test", &menu); 287 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 288 PCUT_ASSERT_NOT_NULL(menu); 289 290 prect.p0.x = 0; 291 prect.p0.y = 0; 292 prect.p1.x = 0; 293 prect.p1.y = 0; 294 295 /* Menu needs to be open to be able to paint it */ 296 rc = ui_menu_open(menu, &prect); 297 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 298 299 pos.x = 0; 300 pos.y = 0; 301 rc = ui_menu_paint_bg_text(menu, &pos); 302 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 304 ui_menu_bar_destroy(mbar); 305 ui_window_destroy(window); 306 ui_destroy(ui); 307 } 308 211 309 /** Paint menu */ 212 310 PCUT_TEST(paint) -
uspace/lib/ui/test/paint.c
r9b2e20c rff6e91b 241 241 } 242 242 243 /** Paint text box */ 244 PCUT_TEST(text_box) 245 { 246 errno_t rc; 247 gfx_context_t *gc = NULL; 248 ui_resource_t *resource = NULL; 249 gfx_color_t *color = NULL; 250 test_gc_t tgc; 251 gfx_rect_t rect; 252 253 memset(&tgc, 0, sizeof(tgc)); 254 rc = gfx_context_new(&ops, &tgc, &gc); 255 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 256 257 rc = ui_resource_create(gc, false, &resource); 258 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 259 PCUT_ASSERT_NOT_NULL(resource); 260 261 rc = gfx_color_new_rgb_i16(1, 2, 3, &color); 262 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 263 264 rect.p0.x = 10; 265 rect.p0.y = 20; 266 rect.p1.x = 30; 267 rect.p1.y = 40; 268 269 /* Paint text box */ 270 rc = ui_paint_text_box(resource, &rect, ui_box_single, color); 271 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 272 273 gfx_color_delete(color); 274 ui_resource_destroy(resource); 275 rc = gfx_context_delete(gc); 276 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 277 } 278 243 279 static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect) 244 280 {
Note:
See TracChangeset
for help on using the changeset viewer.