Changeset bc52b5b in mainline
- Timestamp:
- 2021-08-15T10:02:32Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 99589a9
- Parents:
- de0c55a
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
rde0c55a rbc52b5b 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 73 73 static gfx_coord_t vpad; 74 74 75 /** Determine if we are running in text mode. 76 * 77 * @param w Screen width 78 * @param h Screen height 79 * @return @c true iff we are running in text mode 80 */ 81 static bool demo_is_text(gfx_coord_t w, gfx_coord_t h) 82 { 83 // XXX Need a proper way to determine text mode 84 return w <= 80; 85 } 86 75 87 /** Clear screen. 76 88 * … … 215 227 216 228 if (font != NULL) { 217 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 218 if (rc != EOK) 219 goto error; 229 if (demo_is_text(w, h)) { 230 rc = gfx_color_new_ega(0x1e, &color); 231 if (rc != EOK) 232 goto error; 233 } else { 234 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color); 235 if (rc != EOK) 236 goto error; 237 } 220 238 221 239 gfx_text_fmt_init(&fmt); … … 740 758 741 759 for (i = 0; i < 8; i++) { 742 rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0, 743 (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color); 744 if (rc != EOK) 745 goto error; 760 if (demo_is_text(w, h)) { 761 rc = gfx_color_new_ega(i, &color); 762 if (rc != EOK) 763 goto error; 764 } else { 765 rc = gfx_color_new_rgb_i16((i & 4) ? 0xffff : 0, 766 (i & 2) ? 0xffff : 0, (i & 1) ? 0xffff : 0, &color); 767 if (rc != EOK) 768 goto error; 769 } 746 770 747 771 fmt.color = color; -
uspace/lib/congfx/src/console.c
rde0c55a rbc52b5b 75 75 }; 76 76 77 /** Convert pixel value to charfield. 78 * 79 * On the bottom of this function lies a big big hack. In the absence 80 * of support for different color formats (FIX ME!), here's a single 81 * format that can represent both 3x8bit RGB and 24-bit characters 82 * with 8-bit EGA attributes (i.e. we can specify the foreground and 83 * background colors individually). 84 * 85 * A R G B 86 * 0 red grn blu 24-bit color 87 * attr c2 c1 c0 attribute + 24-bit character 88 */ 89 static void console_gc_pix_to_charfield(pixel_t clr, charfield_t *ch) 90 { 91 uint8_t attr; 92 93 if ((clr >> 24) == 0) { 94 /* RGB (no text) */ 95 ch->ch = 0; 96 ch->flags = CHAR_FLAG_DIRTY; 97 ch->attrs.type = CHAR_ATTR_RGB; 98 ch->attrs.val.rgb.fgcolor = clr ^ 0xffffff; 99 ch->attrs.val.rgb.bgcolor = clr; 100 } else { 101 /* EGA attributes (with text) */ 102 attr = clr >> 24; 103 ch->ch = clr & 0xffffff; 104 ch->flags = CHAR_FLAG_DIRTY; 105 ch->attrs.type = CHAR_ATTR_INDEX; 106 ch->attrs.val.index.fgcolor = attr & 0x7; 107 ch->attrs.val.index.bgcolor = (attr >> 4) & 0x7; 108 ch->attrs.val.index.attr = 109 ((attr & 0x8) ? CATTR_BRIGHT : 0) + 110 ((attr & 0x80) ? CATTR_BLINK : 0); 111 } 112 } 113 77 114 /** Set clipping rectangle on console GC. 78 115 * … … 107 144 console_gc_t *cgc = (console_gc_t *) arg; 108 145 109 cgc->clr = PIXEL( 0, color->r >> 8, color->g >> 8, color->b >> 8);146 cgc->clr = PIXEL(color->attr, color->r >> 8, color->g >> 8, color->b >> 8); 110 147 return EOK; 111 148 } … … 131 168 cols = cgc->rect.p1.x - cgc->rect.p0.x; 132 169 133 ch.ch = cgc->clr >> 24; 134 ch.flags = CHAR_FLAG_DIRTY; 135 ch.attrs.type = CHAR_ATTR_RGB; 136 ch.attrs.val.rgb.fgcolor = cgc->clr ^ 0xffffff; 137 ch.attrs.val.rgb.bgcolor = cgc->clr; 170 console_gc_pix_to_charfield(cgc->clr, &ch); 138 171 139 172 for (y = crect.p0.y; y < crect.p1.y; y++) { … … 374 407 y - offs.y - cbm->rect.p0.y); 375 408 376 ch.ch = clr >> 24; 377 ch.flags = CHAR_FLAG_DIRTY; 378 ch.attrs.type = CHAR_ATTR_RGB; 379 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 380 ch.attrs.val.rgb.bgcolor = clr; 381 409 console_gc_pix_to_charfield(clr, &ch); 382 410 cbm->cgc->buf[y * cols + x] = ch; 383 411 } … … 392 420 y - offs.y - cbm->rect.p0.y); 393 421 394 ch.ch = clr >> 24; 395 ch.flags = CHAR_FLAG_DIRTY; 396 ch.attrs.type = CHAR_ATTR_RGB; 397 ch.attrs.val.rgb.fgcolor = clr ^ 0xffffff; 398 ch.attrs.val.rgb.bgcolor = clr; 422 console_gc_pix_to_charfield(clr, &ch); 399 423 400 424 if (clr != cbm->key_color) … … 404 428 } else { 405 429 /* Color key & colorize */ 406 ch.ch = 0; 407 ch.flags = CHAR_FLAG_DIRTY; 408 ch.attrs.type = CHAR_ATTR_RGB; 409 ch.attrs.val.rgb.fgcolor = cbm->cgc->clr; 410 ch.attrs.val.rgb.bgcolor = cbm->cgc->clr; 430 console_gc_pix_to_charfield(cbm->cgc->clr, &ch); 411 431 412 432 for (y = crect.p0.y; y < crect.p1.y; y++) { -
uspace/lib/gfx/include/gfx/color.h
rde0c55a rbc52b5b 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 extern errno_t gfx_color_new_rgb_i16(uint16_t, uint16_t, 44 44 uint16_t, gfx_color_t **); 45 extern errno_t gfx_color_new_ega(uint8_t, gfx_color_t **); 45 46 extern void gfx_color_delete(gfx_color_t *); 46 47 extern void gfx_color_get_rgb_i16(gfx_color_t *, uint16_t *, uint16_t *, 47 48 uint16_t *); 49 extern void gfx_color_get_ega(gfx_color_t *, uint8_t *); 48 50 49 51 #endif -
uspace/lib/gfx/private/color.h
rde0c55a rbc52b5b 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 48 48 uint16_t g; 49 49 uint16_t b; 50 uint8_t attr; 50 51 }; 51 52 -
uspace/lib/gfx/src/color.c
rde0c55a rbc52b5b 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 69 69 } 70 70 71 /** Create new EGA color. 72 * 73 * @param attr EGA attributes 74 * @param rcolor Place to store pointer to new color 75 * 76 * @return EOK on success or an error code, ENOMEM if out of resources, 77 * EIO if the graphic device connection was lost 78 */ 79 errno_t gfx_color_new_ega(uint8_t attr, gfx_color_t **rcolor) 80 { 81 gfx_color_t *color; 82 83 color = calloc(1, sizeof(gfx_color_t)); 84 if (color == NULL) 85 return ENOMEM; 86 87 color->attr = attr; 88 89 *rcolor = color; 90 return EOK; 91 } 92 71 93 /** Delete color. 72 94 * … … 93 115 } 94 116 117 /** Convert color to EGA attributes. 118 * 119 * @param color Color 120 * @param attr Place to store EGA attributes 121 */ 122 void gfx_color_get_ega(gfx_color_t *color, uint8_t *attr) 123 { 124 *attr = color->attr; 125 } 126 95 127 /** @} 96 128 */ -
uspace/lib/gfxfont/src/text.c
rde0c55a rbc52b5b 110 110 gfx_bitmap_t *bitmap; 111 111 gfx_bitmap_alloc_t alloc; 112 uint 16_t r, g, b;112 uint8_t attr; 113 113 pixelmap_t pmap; 114 114 gfx_coord_t x; 115 115 pixel_t pixel; 116 char32_t c; 117 size_t off; 116 118 errno_t rc; 117 119 … … 121 123 */ 122 124 123 gfx_color_get_rgb_i16(color, &r, &g, &b); 124 125 /* 126 * We are setting the *background* color, the foreground color 127 * will be set to its complement. 128 */ 129 r = 0xff ^ (r >> 8); 130 g = 0xff ^ (g >> 8); 131 b = 0xff ^ (b >> 8); 125 gfx_color_get_ega(color, &attr); 132 126 133 127 gfx_bitmap_params_init(¶ms); … … 156 150 pmap.data = alloc.pixels; 157 151 152 off = 0; 158 153 for (x = 0; x < params.rect.p1.x; x++) { 159 pixel = PIXEL(str[x], r, g, b); 154 c = str_decode(str, &off, STR_NO_LIMIT); 155 pixel = PIXEL(attr, 156 (c >> 16) & 0xff, 157 (c >> 8) & 0xff, 158 c & 0xff); 160 159 pixelmap_put_pixel(&pmap, x, 0, pixel); 161 160 } -
uspace/lib/memgfx/src/memgc.c
rde0c55a rbc52b5b 108 108 mem_gc_t *mgc = (mem_gc_t *) arg; 109 109 uint16_t r, g, b; 110 uint8_t attr; 110 111 111 112 gfx_color_get_rgb_i16(color, &r, &g, &b); 112 mgc->color = PIXEL(0, r >> 8, g >> 8, b >> 8); 113 gfx_color_get_ega(color, &attr); 114 mgc->color = PIXEL(attr, r >> 8, g >> 8, b >> 8); 113 115 return EOK; 114 116 } -
uspace/lib/ui/src/pbutton.c
rde0c55a rbc52b5b 366 366 rect.p1.y = pbutton->rect.p0.y + 1; 367 367 368 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_ highlight_color);368 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color); 369 369 if (rc != EOK) 370 370 goto error; -
uspace/lib/ui/src/resource.c
rde0c55a rbc52b5b 47 47 static const char *ui_typeface_path = "/data/font/helena.tpf"; 48 48 49 /** Create new UI resource .49 /** Create new UI resource in graphics mode. 50 50 * 51 51 * @param gc Graphic context 52 * @param textmode @c true if running in text mode53 52 * @param rresource Place to store pointer to new UI resource 54 53 * @return EOK on success, ENOMEM if out of memory 55 54 */ 56 errno_t ui_resource_create(gfx_context_t *gc, bool textmode,55 static errno_t ui_resource_create_gfx(gfx_context_t *gc, 57 56 ui_resource_t **rresource) 58 57 { … … 87 86 return ENOMEM; 88 87 89 if (textmode) { 90 /* Create dummy font for text mode */ 91 rc = gfx_typeface_create(gc, &tface); 92 if (rc != EOK) 93 goto error; 94 95 rc = gfx_font_create_textmode(tface, &font); 96 if (rc != EOK) 97 goto error; 98 } else { 99 rc = gfx_typeface_open(gc, ui_typeface_path, &tface); 100 if (rc != EOK) 101 goto error; 102 103 finfo = gfx_typeface_first_font(tface); 104 if (finfo == NULL) { 105 rc = EIO; 106 goto error; 107 } 108 109 rc = gfx_font_open(finfo, &font); 110 if (rc != EOK) 111 goto error; 88 rc = gfx_typeface_open(gc, ui_typeface_path, &tface); 89 if (rc != EOK) 90 goto error; 91 92 finfo = gfx_typeface_first_font(tface); 93 if (finfo == NULL) { 94 rc = EIO; 95 goto error; 112 96 } 97 98 rc = gfx_font_open(finfo, &font); 99 if (rc != EOK) 100 goto error; 113 101 114 102 rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color); … … 201 189 resource->tface = tface; 202 190 resource->font = font; 203 resource->textmode = textmode;191 resource->textmode = false; 204 192 205 193 resource->btn_frame_color = btn_frame_color; … … 280 268 } 281 269 270 /** Create new UI resource in text mode. 271 * 272 * @param gc Graphic context 273 * @param rresource Place to store pointer to new UI resource 274 * @return EOK on success, ENOMEM if out of memory 275 */ 276 static errno_t ui_resource_create_text(gfx_context_t *gc, 277 ui_resource_t **rresource) 278 { 279 ui_resource_t *resource; 280 gfx_typeface_t *tface = NULL; 281 gfx_font_t *font = NULL; 282 gfx_color_t *btn_frame_color = NULL; 283 gfx_color_t *btn_face_color = NULL; 284 gfx_color_t *btn_text_color = NULL; 285 gfx_color_t *btn_highlight_color = NULL; 286 gfx_color_t *btn_shadow_color = NULL; 287 gfx_color_t *wnd_face_color = NULL; 288 gfx_color_t *wnd_text_color = NULL; 289 gfx_color_t *wnd_sel_text_color = NULL; 290 gfx_color_t *wnd_sel_text_bg_color = NULL; 291 gfx_color_t *wnd_frame_hi_color = NULL; 292 gfx_color_t *wnd_frame_sh_color = NULL; 293 gfx_color_t *wnd_highlight_color = NULL; 294 gfx_color_t *wnd_shadow_color = NULL; 295 gfx_color_t *tbar_act_bg_color = NULL; 296 gfx_color_t *tbar_inact_bg_color = NULL; 297 gfx_color_t *tbar_act_text_color = NULL; 298 gfx_color_t *tbar_inact_text_color = NULL; 299 gfx_color_t *entry_fg_color = NULL; 300 gfx_color_t *entry_bg_color = NULL; 301 gfx_color_t *entry_act_bg_color = NULL; 302 errno_t rc; 303 304 resource = calloc(1, sizeof(ui_resource_t)); 305 if (resource == NULL) 306 return ENOMEM; 307 308 /* Create dummy font for text mode */ 309 rc = gfx_typeface_create(gc, &tface); 310 if (rc != EOK) 311 goto error; 312 313 rc = gfx_font_create_textmode(tface, &font); 314 if (rc != EOK) 315 goto error; 316 317 rc = gfx_color_new_ega(0x07, &btn_frame_color); 318 if (rc != EOK) 319 goto error; 320 321 rc = gfx_color_new_ega(0x20, &btn_face_color); 322 if (rc != EOK) 323 goto error; 324 325 rc = gfx_color_new_ega(0x20, &btn_text_color); 326 if (rc != EOK) 327 goto error; 328 329 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, 330 &btn_highlight_color); 331 if (rc != EOK) 332 goto error; 333 334 rc = gfx_color_new_ega(0x01, &btn_shadow_color); 335 if (rc != EOK) 336 goto error; 337 338 rc = gfx_color_new_ega(0x70, &wnd_face_color); 339 if (rc != EOK) 340 goto error; 341 342 rc = gfx_color_new_ega(0x70, &wnd_text_color); 343 if (rc != EOK) 344 goto error; 345 346 rc = gfx_color_new_ega(0x07, &wnd_sel_text_color); 347 if (rc != EOK) 348 goto error; 349 350 rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color); 351 if (rc != EOK) 352 goto error; 353 354 rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color); 355 if (rc != EOK) 356 goto error; 357 358 rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color); 359 if (rc != EOK) 360 goto error; 361 362 rc = gfx_color_new_ega(0x70, &wnd_highlight_color); 363 if (rc != EOK) 364 goto error; 365 366 rc = gfx_color_new_ega(0x01, &wnd_shadow_color); 367 if (rc != EOK) 368 goto error; 369 370 rc = gfx_color_new_ega(0x1f, &tbar_act_bg_color); 371 if (rc != EOK) 372 goto error; 373 374 rc = gfx_color_new_ega(0x1e, &tbar_act_text_color); 375 if (rc != EOK) 376 goto error; 377 378 rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color); 379 if (rc != EOK) 380 goto error; 381 382 rc = gfx_color_new_ega(0x07, &tbar_inact_text_color); 383 if (rc != EOK) 384 goto error; 385 386 rc = gfx_color_new_ega(0x1b, &entry_fg_color); 387 if (rc != EOK) 388 goto error; 389 390 rc = gfx_color_new_ega(0x1b, &entry_bg_color); 391 if (rc != EOK) 392 goto error; 393 394 rc = gfx_color_new_ega(0x37, &entry_act_bg_color); 395 if (rc != EOK) 396 goto error; 397 398 resource->gc = gc; 399 resource->tface = tface; 400 resource->font = font; 401 resource->textmode = true; 402 403 resource->btn_frame_color = btn_frame_color; 404 resource->btn_face_color = btn_face_color; 405 resource->btn_text_color = btn_text_color; 406 resource->btn_highlight_color = btn_highlight_color; 407 resource->btn_shadow_color = btn_shadow_color; 408 409 resource->wnd_face_color = wnd_face_color; 410 resource->wnd_text_color = wnd_text_color; 411 resource->wnd_sel_text_color = wnd_sel_text_color; 412 resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color; 413 resource->wnd_frame_hi_color = wnd_frame_hi_color; 414 resource->wnd_frame_sh_color = wnd_frame_sh_color; 415 resource->wnd_highlight_color = wnd_highlight_color; 416 resource->wnd_shadow_color = wnd_shadow_color; 417 418 resource->tbar_act_bg_color = tbar_act_bg_color; 419 resource->tbar_act_text_color = tbar_act_text_color; 420 resource->tbar_inact_bg_color = tbar_inact_bg_color; 421 resource->tbar_inact_text_color = tbar_inact_text_color; 422 423 resource->entry_fg_color = entry_fg_color; 424 resource->entry_bg_color = entry_bg_color; 425 resource->entry_act_bg_color = entry_act_bg_color; 426 427 *rresource = resource; 428 return EOK; 429 error: 430 if (btn_frame_color != NULL) 431 gfx_color_delete(btn_frame_color); 432 if (btn_face_color != NULL) 433 gfx_color_delete(btn_face_color); 434 if (btn_text_color != NULL) 435 gfx_color_delete(btn_text_color); 436 if (btn_highlight_color != NULL) 437 gfx_color_delete(btn_highlight_color); 438 if (btn_shadow_color != NULL) 439 gfx_color_delete(btn_shadow_color); 440 441 if (wnd_face_color != NULL) 442 gfx_color_delete(wnd_face_color); 443 if (wnd_text_color != NULL) 444 gfx_color_delete(wnd_text_color); 445 if (wnd_sel_text_color != NULL) 446 gfx_color_delete(wnd_sel_text_color); 447 if (wnd_sel_text_bg_color != NULL) 448 gfx_color_delete(wnd_sel_text_bg_color); 449 if (wnd_frame_hi_color != NULL) 450 gfx_color_delete(wnd_frame_hi_color); 451 if (wnd_frame_sh_color != NULL) 452 gfx_color_delete(wnd_frame_sh_color); 453 if (wnd_highlight_color != NULL) 454 gfx_color_delete(wnd_highlight_color); 455 if (wnd_shadow_color != NULL) 456 gfx_color_delete(wnd_shadow_color); 457 458 if (tbar_act_bg_color != NULL) 459 gfx_color_delete(tbar_act_bg_color); 460 if (tbar_act_text_color != NULL) 461 gfx_color_delete(tbar_act_text_color); 462 if (tbar_inact_bg_color != NULL) 463 gfx_color_delete(tbar_inact_bg_color); 464 if (tbar_inact_text_color != NULL) 465 gfx_color_delete(tbar_inact_text_color); 466 467 if (entry_fg_color != NULL) 468 gfx_color_delete(entry_fg_color); 469 if (entry_bg_color != NULL) 470 gfx_color_delete(entry_bg_color); 471 if (entry_act_bg_color != NULL) 472 gfx_color_delete(entry_act_bg_color); 473 474 if (tface != NULL) 475 gfx_typeface_destroy(tface); 476 free(resource); 477 return rc; 478 } 479 480 /** Create new UI resource. 481 * 482 * @param gc Graphic context 483 * @param textmode @c true if running in text mode 484 * @param rresource Place to store pointer to new UI resource 485 * @return EOK on success, ENOMEM if out of memory 486 */ 487 errno_t ui_resource_create(gfx_context_t *gc, bool textmode, 488 ui_resource_t **rresource) 489 { 490 if (textmode) 491 return ui_resource_create_text(gc, rresource); 492 else 493 return ui_resource_create_gfx(gc, rresource); 494 } 495 282 496 /** Destroy UI resource. 283 497 *
Note:
See TracChangeset
for help on using the changeset viewer.