Changes in uspace/lib/ui/src/resource.c [be869b0:214aefb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/resource.c
rbe869b0 r214aefb 47 47 static const char *ui_typeface_path = "/data/font/helena.tpf"; 48 48 49 /** Create new UI resource in graphics mode.49 /** Create new UI resource. 50 50 * 51 51 * @param gc Graphic context 52 * @param textmode @c true if running in text mode 52 53 * @param rresource Place to store pointer to new UI resource 53 54 * @return EOK on success, ENOMEM if out of memory 54 55 */ 55 static errno_t ui_resource_create_gfx(gfx_context_t *gc,56 errno_t ui_resource_create(gfx_context_t *gc, bool textmode, 56 57 ui_resource_t **rresource) 57 58 { … … 80 81 gfx_color_t *entry_bg_color = NULL; 81 82 gfx_color_t *entry_act_bg_color = NULL; 82 gfx_color_t *entry_sel_text_fg_color = NULL;83 gfx_color_t *entry_sel_text_bg_color = NULL;84 83 errno_t rc; 85 84 … … 88 87 return ENOMEM; 89 88 90 rc = gfx_typeface_open(gc, ui_typeface_path, &tface); 91 if (rc != EOK) 92 goto error; 93 94 finfo = gfx_typeface_first_font(tface); 95 if (finfo == NULL) { 96 rc = EIO; 97 goto error; 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; 98 112 } 99 100 rc = gfx_font_open(finfo, &font);101 if (rc != EOK)102 goto error;103 113 104 114 rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color); … … 185 195 186 196 rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color); 187 if (rc != EOK)188 goto error;189 190 rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,191 &entry_sel_text_fg_color);192 if (rc != EOK)193 goto error;194 195 rc = gfx_color_new_rgb_i16(0, 0, 0xffff, &entry_sel_text_bg_color);196 197 if (rc != EOK) 197 198 goto error; … … 200 201 resource->tface = tface; 201 202 resource->font = font; 202 resource->textmode = false;203 resource->textmode = textmode; 203 204 204 205 resource->btn_frame_color = btn_frame_color; … … 225 226 resource->entry_bg_color = entry_bg_color; 226 227 resource->entry_act_bg_color = entry_act_bg_color; 227 resource->entry_sel_text_fg_color = entry_sel_text_fg_color;228 resource->entry_sel_text_bg_color = entry_sel_text_bg_color;229 228 230 229 *rresource = resource; … … 272 271 if (entry_bg_color != NULL) 273 272 gfx_color_delete(entry_bg_color); 274 if (entry_sel_text_fg_color != NULL)275 gfx_color_delete(entry_sel_text_fg_color);276 if (entry_sel_text_bg_color != NULL)277 gfx_color_delete(entry_sel_text_bg_color);278 273 if (entry_act_bg_color != NULL) 279 274 gfx_color_delete(entry_act_bg_color); … … 283 278 free(resource); 284 279 return rc; 285 }286 287 /** Create new UI resource in text mode.288 *289 * @param gc Graphic context290 * @param rresource Place to store pointer to new UI resource291 * @return EOK on success, ENOMEM if out of memory292 */293 static errno_t ui_resource_create_text(gfx_context_t *gc,294 ui_resource_t **rresource)295 {296 ui_resource_t *resource;297 gfx_typeface_t *tface = NULL;298 gfx_font_t *font = NULL;299 gfx_color_t *btn_frame_color = NULL;300 gfx_color_t *btn_face_color = NULL;301 gfx_color_t *btn_text_color = NULL;302 gfx_color_t *btn_highlight_color = NULL;303 gfx_color_t *btn_shadow_color = NULL;304 gfx_color_t *wnd_face_color = NULL;305 gfx_color_t *wnd_text_color = NULL;306 gfx_color_t *wnd_sel_text_color = NULL;307 gfx_color_t *wnd_sel_text_bg_color = NULL;308 gfx_color_t *wnd_frame_hi_color = NULL;309 gfx_color_t *wnd_frame_sh_color = NULL;310 gfx_color_t *wnd_highlight_color = NULL;311 gfx_color_t *wnd_shadow_color = NULL;312 gfx_color_t *tbar_act_bg_color = NULL;313 gfx_color_t *tbar_inact_bg_color = NULL;314 gfx_color_t *tbar_act_text_color = NULL;315 gfx_color_t *tbar_inact_text_color = NULL;316 gfx_color_t *entry_fg_color = NULL;317 gfx_color_t *entry_bg_color = NULL;318 gfx_color_t *entry_sel_text_fg_color = NULL;319 gfx_color_t *entry_sel_text_bg_color = NULL;320 gfx_color_t *entry_act_bg_color = NULL;321 errno_t rc;322 323 resource = calloc(1, sizeof(ui_resource_t));324 if (resource == NULL)325 return ENOMEM;326 327 /* Create dummy font for text mode */328 rc = gfx_typeface_create(gc, &tface);329 if (rc != EOK)330 goto error;331 332 rc = gfx_font_create_textmode(tface, &font);333 if (rc != EOK)334 goto error;335 336 rc = gfx_color_new_ega(0x07, &btn_frame_color);337 if (rc != EOK)338 goto error;339 340 rc = gfx_color_new_ega(0x20, &btn_face_color);341 if (rc != EOK)342 goto error;343 344 rc = gfx_color_new_ega(0x20, &btn_text_color);345 if (rc != EOK)346 goto error;347 348 rc = gfx_color_new_ega(0x20, &btn_highlight_color);349 if (rc != EOK)350 goto error;351 352 rc = gfx_color_new_ega(0x01, &btn_shadow_color);353 if (rc != EOK)354 goto error;355 356 rc = gfx_color_new_ega(0x70, &wnd_face_color);357 if (rc != EOK)358 goto error;359 360 rc = gfx_color_new_ega(0x70, &wnd_text_color);361 if (rc != EOK)362 goto error;363 364 rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);365 if (rc != EOK)366 goto error;367 368 rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);369 if (rc != EOK)370 goto error;371 372 rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);373 if (rc != EOK)374 goto error;375 376 rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);377 if (rc != EOK)378 goto error;379 380 rc = gfx_color_new_ega(0x70, &wnd_highlight_color);381 if (rc != EOK)382 goto error;383 384 rc = gfx_color_new_ega(0x01, &wnd_shadow_color);385 if (rc != EOK)386 goto error;387 388 rc = gfx_color_new_ega(0x70, &tbar_act_bg_color);389 if (rc != EOK)390 goto error;391 392 rc = gfx_color_new_ega(0x70, &tbar_act_text_color);393 if (rc != EOK)394 goto error;395 396 rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);397 if (rc != EOK)398 goto error;399 400 rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);401 if (rc != EOK)402 goto error;403 404 rc = gfx_color_new_ega(0x1b, &entry_fg_color);405 if (rc != EOK)406 goto error;407 408 rc = gfx_color_new_ega(0x1b, &entry_bg_color);409 if (rc != EOK)410 goto error;411 412 rc = gfx_color_new_ega(0x20, &entry_sel_text_fg_color);413 if (rc != EOK)414 goto error;415 416 rc = gfx_color_new_ega(0x20, &entry_sel_text_bg_color);417 if (rc != EOK)418 goto error;419 420 rc = gfx_color_new_ega(0x37, &entry_act_bg_color);421 if (rc != EOK)422 goto error;423 424 resource->gc = gc;425 resource->tface = tface;426 resource->font = font;427 resource->textmode = true;428 429 resource->btn_frame_color = btn_frame_color;430 resource->btn_face_color = btn_face_color;431 resource->btn_text_color = btn_text_color;432 resource->btn_highlight_color = btn_highlight_color;433 resource->btn_shadow_color = btn_shadow_color;434 435 resource->wnd_face_color = wnd_face_color;436 resource->wnd_text_color = wnd_text_color;437 resource->wnd_sel_text_color = wnd_sel_text_color;438 resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;439 resource->wnd_frame_hi_color = wnd_frame_hi_color;440 resource->wnd_frame_sh_color = wnd_frame_sh_color;441 resource->wnd_highlight_color = wnd_highlight_color;442 resource->wnd_shadow_color = wnd_shadow_color;443 444 resource->tbar_act_bg_color = tbar_act_bg_color;445 resource->tbar_act_text_color = tbar_act_text_color;446 resource->tbar_inact_bg_color = tbar_inact_bg_color;447 resource->tbar_inact_text_color = tbar_inact_text_color;448 449 resource->entry_fg_color = entry_fg_color;450 resource->entry_bg_color = entry_bg_color;451 resource->entry_act_bg_color = entry_act_bg_color;452 resource->entry_sel_text_fg_color = entry_sel_text_fg_color;453 resource->entry_sel_text_bg_color = entry_sel_text_bg_color;454 455 *rresource = resource;456 return EOK;457 error:458 if (btn_frame_color != NULL)459 gfx_color_delete(btn_frame_color);460 if (btn_face_color != NULL)461 gfx_color_delete(btn_face_color);462 if (btn_text_color != NULL)463 gfx_color_delete(btn_text_color);464 if (btn_highlight_color != NULL)465 gfx_color_delete(btn_highlight_color);466 if (btn_shadow_color != NULL)467 gfx_color_delete(btn_shadow_color);468 469 if (wnd_face_color != NULL)470 gfx_color_delete(wnd_face_color);471 if (wnd_text_color != NULL)472 gfx_color_delete(wnd_text_color);473 if (wnd_sel_text_color != NULL)474 gfx_color_delete(wnd_sel_text_color);475 if (wnd_sel_text_bg_color != NULL)476 gfx_color_delete(wnd_sel_text_bg_color);477 if (wnd_frame_hi_color != NULL)478 gfx_color_delete(wnd_frame_hi_color);479 if (wnd_frame_sh_color != NULL)480 gfx_color_delete(wnd_frame_sh_color);481 if (wnd_highlight_color != NULL)482 gfx_color_delete(wnd_highlight_color);483 if (wnd_shadow_color != NULL)484 gfx_color_delete(wnd_shadow_color);485 486 if (tbar_act_bg_color != NULL)487 gfx_color_delete(tbar_act_bg_color);488 if (tbar_act_text_color != NULL)489 gfx_color_delete(tbar_act_text_color);490 if (tbar_inact_bg_color != NULL)491 gfx_color_delete(tbar_inact_bg_color);492 if (tbar_inact_text_color != NULL)493 gfx_color_delete(tbar_inact_text_color);494 495 if (entry_fg_color != NULL)496 gfx_color_delete(entry_fg_color);497 if (entry_bg_color != NULL)498 gfx_color_delete(entry_bg_color);499 if (entry_act_bg_color != NULL)500 gfx_color_delete(entry_act_bg_color);501 if (entry_sel_text_fg_color != NULL)502 gfx_color_delete(entry_sel_text_fg_color);503 if (entry_sel_text_bg_color != NULL)504 gfx_color_delete(entry_sel_text_bg_color);505 506 if (tface != NULL)507 gfx_typeface_destroy(tface);508 free(resource);509 return rc;510 }511 512 /** Create new UI resource.513 *514 * @param gc Graphic context515 * @param textmode @c true if running in text mode516 * @param rresource Place to store pointer to new UI resource517 * @return EOK on success, ENOMEM if out of memory518 */519 errno_t ui_resource_create(gfx_context_t *gc, bool textmode,520 ui_resource_t **rresource)521 {522 if (textmode)523 return ui_resource_create_text(gc, rresource);524 else525 return ui_resource_create_gfx(gc, rresource);526 280 } 527 281 … … 558 312 gfx_color_delete(resource->entry_bg_color); 559 313 gfx_color_delete(resource->entry_act_bg_color); 560 gfx_color_delete(resource->entry_sel_text_fg_color);561 gfx_color_delete(resource->entry_sel_text_bg_color);562 314 563 315 gfx_font_close(resource->font); … … 594 346 } 595 347 596 /** Get the UI font.597 *598 * @param resource UI resource599 * @return UI font600 */601 gfx_font_t *ui_resource_get_font(ui_resource_t *resource)602 {603 return resource->font;604 }605 606 348 /** @} 607 349 */
Note:
See TracChangeset
for help on using the changeset viewer.