HelenOS sources
This source file includes following definitions.
- ui_resource_create_gfx
- ui_resource_create_text
- ui_resource_create
- ui_resource_destroy
- ui_resource_set_expose_cb
- ui_resource_expose
- ui_resource_get_font
- ui_resource_is_textmode
- ui_resource_get_wnd_face_color
- ui_resource_get_wnd_text_color
#include <errno.h>
#include <gfx/color.h>
#include <gfx/context.h>
#include <gfx/font.h>
#include <gfx/render.h>
#include <gfx/typeface.h>
#include <stdlib.h>
#include <str.h>
#include <ui/resource.h>
#include "../private/resource.h"
static const char *ui_typeface_path = "/data/font/helena.tpf";
static errno_t ui_resource_create_gfx(gfx_context_t *gc,
ui_resource_t **rresource)
{
ui_resource_t *resource;
gfx_typeface_t *tface = NULL;
gfx_font_t *font = NULL;
gfx_font_info_t *finfo;
gfx_color_t *btn_frame_color = NULL;
gfx_color_t *btn_face_color = NULL;
gfx_color_t *btn_face_lit_color = NULL;
gfx_color_t *btn_text_color = NULL;
gfx_color_t *btn_highlight_color = NULL;
gfx_color_t *btn_shadow_color = NULL;
gfx_color_t *wnd_face_color = NULL;
gfx_color_t *wnd_text_color = NULL;
gfx_color_t *wnd_dis_text_color = NULL;
gfx_color_t *wnd_text_hgl_color = NULL;
gfx_color_t *wnd_sel_text_color = NULL;
gfx_color_t *wnd_sel_text_hgl_color = NULL;
gfx_color_t *wnd_sel_text_bg_color = NULL;
gfx_color_t *wnd_frame_hi_color = NULL;
gfx_color_t *wnd_frame_sh_color = NULL;
gfx_color_t *wnd_highlight_color = NULL;
gfx_color_t *wnd_shadow_color = NULL;
gfx_color_t *tbar_act_bg_color = NULL;
gfx_color_t *tbar_inact_bg_color = NULL;
gfx_color_t *tbar_act_text_color = NULL;
gfx_color_t *tbar_inact_text_color = NULL;
gfx_color_t *entry_fg_color = NULL;
gfx_color_t *entry_bg_color = NULL;
gfx_color_t *entry_act_bg_color = NULL;
gfx_color_t *entry_sel_text_fg_color = NULL;
gfx_color_t *entry_sel_text_bg_color = NULL;
gfx_color_t *sbar_trough_color = NULL;
gfx_color_t *sbar_act_trough_color = NULL;
errno_t rc;
resource = calloc(1, sizeof(ui_resource_t));
if (resource == NULL)
return ENOMEM;
rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
if (rc != EOK)
goto error;
finfo = gfx_typeface_first_font(tface);
if (finfo == NULL) {
rc = EIO;
goto error;
}
rc = gfx_font_open(finfo, &font);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &btn_face_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xe8e8, 0xe8e8, 0xe8e8, &btn_face_lit_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
&btn_highlight_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &btn_shadow_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &wnd_face_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x9696, 0x9696, 0x9696, &wnd_dis_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_hgl_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &wnd_sel_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
&wnd_sel_text_hgl_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4,
&wnd_sel_text_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x4444, 0x4444, 0x4444, &wnd_frame_sh_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
&wnd_highlight_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_shadow_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4, &tbar_act_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
&tbar_act_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xdddd, 0xdddd, 0xdddd,
&tbar_inact_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
&tbar_inact_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0, &entry_fg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &entry_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
&entry_sel_text_fg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0, 0, 0xffff, &entry_sel_text_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0xe4e4, 0xe4e4, 0xe4e4,
&sbar_trough_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
&sbar_act_trough_color);
if (rc != EOK)
goto error;
resource->gc = gc;
resource->tface = tface;
resource->font = font;
resource->textmode = false;
resource->btn_frame_color = btn_frame_color;
resource->btn_face_color = btn_face_color;
resource->btn_face_lit_color = btn_face_lit_color;
resource->btn_text_color = btn_text_color;
resource->btn_highlight_color = btn_highlight_color;
resource->btn_shadow_color = btn_shadow_color;
resource->wnd_face_color = wnd_face_color;
resource->wnd_text_color = wnd_text_color;
resource->wnd_dis_text_color = wnd_dis_text_color;
resource->wnd_text_hgl_color = wnd_text_hgl_color;
resource->wnd_sel_text_color = wnd_sel_text_color;
resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
resource->wnd_frame_hi_color = wnd_frame_hi_color;
resource->wnd_frame_sh_color = wnd_frame_sh_color;
resource->wnd_highlight_color = wnd_highlight_color;
resource->wnd_shadow_color = wnd_shadow_color;
resource->tbar_act_bg_color = tbar_act_bg_color;
resource->tbar_act_text_color = tbar_act_text_color;
resource->tbar_inact_bg_color = tbar_inact_bg_color;
resource->tbar_inact_text_color = tbar_inact_text_color;
resource->entry_fg_color = entry_fg_color;
resource->entry_bg_color = entry_bg_color;
resource->entry_act_bg_color = entry_act_bg_color;
resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
resource->sbar_trough_color = sbar_trough_color;
resource->sbar_act_trough_color = sbar_act_trough_color;
*rresource = resource;
return EOK;
error:
if (btn_frame_color != NULL)
gfx_color_delete(btn_frame_color);
if (btn_face_color != NULL)
gfx_color_delete(btn_face_color);
if (btn_face_lit_color != NULL)
gfx_color_delete(btn_face_lit_color);
if (btn_text_color != NULL)
gfx_color_delete(btn_text_color);
if (btn_highlight_color != NULL)
gfx_color_delete(btn_highlight_color);
if (btn_shadow_color != NULL)
gfx_color_delete(btn_shadow_color);
if (wnd_face_color != NULL)
gfx_color_delete(wnd_face_color);
if (wnd_text_color != NULL)
gfx_color_delete(wnd_text_color);
if (wnd_dis_text_color != NULL)
gfx_color_delete(wnd_dis_text_color);
if (wnd_text_hgl_color != NULL)
gfx_color_delete(wnd_text_hgl_color);
if (wnd_sel_text_color != NULL)
gfx_color_delete(wnd_sel_text_color);
if (wnd_sel_text_hgl_color != NULL)
gfx_color_delete(wnd_sel_text_hgl_color);
if (wnd_sel_text_bg_color != NULL)
gfx_color_delete(wnd_sel_text_bg_color);
if (wnd_frame_hi_color != NULL)
gfx_color_delete(wnd_frame_hi_color);
if (wnd_frame_sh_color != NULL)
gfx_color_delete(wnd_frame_sh_color);
if (wnd_highlight_color != NULL)
gfx_color_delete(wnd_highlight_color);
if (wnd_shadow_color != NULL)
gfx_color_delete(wnd_shadow_color);
if (tbar_act_bg_color != NULL)
gfx_color_delete(tbar_act_bg_color);
if (tbar_act_text_color != NULL)
gfx_color_delete(tbar_act_text_color);
if (tbar_inact_bg_color != NULL)
gfx_color_delete(tbar_inact_bg_color);
if (tbar_inact_text_color != NULL)
gfx_color_delete(tbar_inact_text_color);
if (entry_fg_color != NULL)
gfx_color_delete(entry_fg_color);
if (entry_bg_color != NULL)
gfx_color_delete(entry_bg_color);
if (entry_sel_text_fg_color != NULL)
gfx_color_delete(entry_sel_text_fg_color);
if (entry_sel_text_bg_color != NULL)
gfx_color_delete(entry_sel_text_bg_color);
if (entry_act_bg_color != NULL)
gfx_color_delete(entry_act_bg_color);
if (sbar_trough_color != NULL)
gfx_color_delete(sbar_trough_color);
if (sbar_act_trough_color != NULL)
gfx_color_delete(sbar_act_trough_color);
if (tface != NULL)
gfx_typeface_destroy(tface);
free(resource);
return rc;
}
static errno_t ui_resource_create_text(gfx_context_t *gc,
ui_resource_t **rresource)
{
ui_resource_t *resource;
gfx_typeface_t *tface = NULL;
gfx_font_t *font = NULL;
gfx_color_t *btn_frame_color = NULL;
gfx_color_t *btn_face_color = NULL;
gfx_color_t *btn_face_lit_color = NULL;
gfx_color_t *btn_text_color = NULL;
gfx_color_t *btn_highlight_color = NULL;
gfx_color_t *btn_shadow_color = NULL;
gfx_color_t *wnd_face_color = NULL;
gfx_color_t *wnd_text_color = NULL;
gfx_color_t *wnd_dis_text_color = NULL;
gfx_color_t *wnd_text_hgl_color = NULL;
gfx_color_t *wnd_sel_text_color = NULL;
gfx_color_t *wnd_sel_text_hgl_color = NULL;
gfx_color_t *wnd_sel_text_bg_color = NULL;
gfx_color_t *wnd_frame_hi_color = NULL;
gfx_color_t *wnd_frame_sh_color = NULL;
gfx_color_t *wnd_highlight_color = NULL;
gfx_color_t *wnd_shadow_color = NULL;
gfx_color_t *tbar_act_bg_color = NULL;
gfx_color_t *tbar_inact_bg_color = NULL;
gfx_color_t *tbar_act_text_color = NULL;
gfx_color_t *tbar_inact_text_color = NULL;
gfx_color_t *entry_fg_color = NULL;
gfx_color_t *entry_bg_color = NULL;
gfx_color_t *entry_sel_text_fg_color = NULL;
gfx_color_t *entry_sel_text_bg_color = NULL;
gfx_color_t *entry_act_bg_color = NULL;
gfx_color_t *sbar_trough_color = NULL;
gfx_color_t *sbar_act_trough_color = NULL;
errno_t rc;
resource = calloc(1, sizeof(ui_resource_t));
if (resource == NULL)
return ENOMEM;
rc = gfx_typeface_create(gc, &tface);
if (rc != EOK)
goto error;
rc = gfx_font_create_textmode(tface, &font);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &btn_frame_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x20, &btn_face_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x30, &btn_face_lit_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x20, &btn_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x20, &btn_highlight_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x01, &btn_shadow_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &wnd_face_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &wnd_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x78, &wnd_dis_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x74, &wnd_text_hgl_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x04, &wnd_sel_text_hgl_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &wnd_highlight_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x01, &wnd_shadow_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &tbar_act_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x70, &tbar_act_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &entry_fg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &entry_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x1e, &entry_sel_text_fg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x1e, &entry_sel_text_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x37, &entry_act_bg_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &sbar_trough_color);
if (rc != EOK)
goto error;
rc = gfx_color_new_ega(0x07, &sbar_act_trough_color);
if (rc != EOK)
goto error;
resource->gc = gc;
resource->tface = tface;
resource->font = font;
resource->textmode = true;
resource->btn_frame_color = btn_frame_color;
resource->btn_face_color = btn_face_color;
resource->btn_face_lit_color = btn_face_lit_color;
resource->btn_text_color = btn_text_color;
resource->btn_highlight_color = btn_highlight_color;
resource->btn_shadow_color = btn_shadow_color;
resource->wnd_face_color = wnd_face_color;
resource->wnd_text_color = wnd_text_color;
resource->wnd_dis_text_color = wnd_dis_text_color;
resource->wnd_text_hgl_color = wnd_text_hgl_color;
resource->wnd_sel_text_color = wnd_sel_text_color;
resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
resource->wnd_frame_hi_color = wnd_frame_hi_color;
resource->wnd_frame_sh_color = wnd_frame_sh_color;
resource->wnd_highlight_color = wnd_highlight_color;
resource->wnd_shadow_color = wnd_shadow_color;
resource->tbar_act_bg_color = tbar_act_bg_color;
resource->tbar_act_text_color = tbar_act_text_color;
resource->tbar_inact_bg_color = tbar_inact_bg_color;
resource->tbar_inact_text_color = tbar_inact_text_color;
resource->entry_fg_color = entry_fg_color;
resource->entry_bg_color = entry_bg_color;
resource->entry_act_bg_color = entry_act_bg_color;
resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
resource->sbar_trough_color = sbar_trough_color;
resource->sbar_act_trough_color = sbar_act_trough_color;
*rresource = resource;
return EOK;
error:
if (btn_frame_color != NULL)
gfx_color_delete(btn_frame_color);
if (btn_face_color != NULL)
gfx_color_delete(btn_face_color);
if (btn_face_lit_color != NULL)
gfx_color_delete(btn_face_lit_color);
if (btn_text_color != NULL)
gfx_color_delete(btn_text_color);
if (btn_highlight_color != NULL)
gfx_color_delete(btn_highlight_color);
if (btn_shadow_color != NULL)
gfx_color_delete(btn_shadow_color);
if (wnd_face_color != NULL)
gfx_color_delete(wnd_face_color);
if (wnd_text_color != NULL)
gfx_color_delete(wnd_text_color);
if (wnd_dis_text_color != NULL)
gfx_color_delete(wnd_dis_text_color);
if (wnd_text_hgl_color != NULL)
gfx_color_delete(wnd_text_hgl_color);
if (wnd_sel_text_color != NULL)
gfx_color_delete(wnd_sel_text_color);
if (wnd_sel_text_hgl_color != NULL)
gfx_color_delete(wnd_sel_text_hgl_color);
if (wnd_sel_text_bg_color != NULL)
gfx_color_delete(wnd_sel_text_bg_color);
if (wnd_frame_hi_color != NULL)
gfx_color_delete(wnd_frame_hi_color);
if (wnd_frame_sh_color != NULL)
gfx_color_delete(wnd_frame_sh_color);
if (wnd_highlight_color != NULL)
gfx_color_delete(wnd_highlight_color);
if (wnd_shadow_color != NULL)
gfx_color_delete(wnd_shadow_color);
if (tbar_act_bg_color != NULL)
gfx_color_delete(tbar_act_bg_color);
if (tbar_act_text_color != NULL)
gfx_color_delete(tbar_act_text_color);
if (tbar_inact_bg_color != NULL)
gfx_color_delete(tbar_inact_bg_color);
if (tbar_inact_text_color != NULL)
gfx_color_delete(tbar_inact_text_color);
if (entry_fg_color != NULL)
gfx_color_delete(entry_fg_color);
if (entry_bg_color != NULL)
gfx_color_delete(entry_bg_color);
if (entry_act_bg_color != NULL)
gfx_color_delete(entry_act_bg_color);
if (entry_sel_text_fg_color != NULL)
gfx_color_delete(entry_sel_text_fg_color);
if (entry_sel_text_bg_color != NULL)
gfx_color_delete(entry_sel_text_bg_color);
if (sbar_trough_color != NULL)
gfx_color_delete(sbar_trough_color);
if (sbar_act_trough_color != NULL)
gfx_color_delete(sbar_act_trough_color);
if (tface != NULL)
gfx_typeface_destroy(tface);
free(resource);
return rc;
}
errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
ui_resource_t **rresource)
{
if (textmode)
return ui_resource_create_text(gc, rresource);
else
return ui_resource_create_gfx(gc, rresource);
}
void ui_resource_destroy(ui_resource_t *resource)
{
if (resource == NULL)
return;
gfx_color_delete(resource->btn_frame_color);
gfx_color_delete(resource->btn_face_color);
gfx_color_delete(resource->btn_face_lit_color);
gfx_color_delete(resource->btn_text_color);
gfx_color_delete(resource->btn_highlight_color);
gfx_color_delete(resource->btn_shadow_color);
gfx_color_delete(resource->wnd_face_color);
gfx_color_delete(resource->wnd_text_color);
gfx_color_delete(resource->wnd_dis_text_color);
gfx_color_delete(resource->wnd_sel_text_color);
gfx_color_delete(resource->wnd_sel_text_bg_color);
gfx_color_delete(resource->wnd_frame_hi_color);
gfx_color_delete(resource->wnd_frame_sh_color);
gfx_color_delete(resource->wnd_highlight_color);
gfx_color_delete(resource->wnd_shadow_color);
gfx_color_delete(resource->tbar_act_bg_color);
gfx_color_delete(resource->tbar_act_text_color);
gfx_color_delete(resource->tbar_inact_bg_color);
gfx_color_delete(resource->tbar_inact_text_color);
gfx_color_delete(resource->entry_fg_color);
gfx_color_delete(resource->entry_bg_color);
gfx_color_delete(resource->entry_act_bg_color);
gfx_color_delete(resource->entry_sel_text_fg_color);
gfx_color_delete(resource->entry_sel_text_bg_color);
gfx_color_delete(resource->sbar_trough_color);
gfx_color_delete(resource->sbar_act_trough_color);
gfx_font_close(resource->font);
gfx_typeface_destroy(resource->tface);
free(resource);
}
void ui_resource_set_expose_cb(ui_resource_t *resource,
ui_expose_cb_t cb, void *arg)
{
resource->expose_cb = cb;
resource->expose_arg = arg;
}
void ui_resource_expose(ui_resource_t *resource)
{
if (resource->expose_cb != NULL)
resource->expose_cb(resource->expose_arg);
}
gfx_font_t *ui_resource_get_font(ui_resource_t *resource)
{
return resource->font;
}
bool ui_resource_is_textmode(ui_resource_t *resource)
{
return resource->textmode;
}
gfx_color_t *ui_resource_get_wnd_face_color(ui_resource_t *resource)
{
return resource->wnd_face_color;
}
gfx_color_t *ui_resource_get_wnd_text_color(ui_resource_t *resource)
{
return resource->wnd_text_color;
}
HelenOS homepage, sources at GitHub