[47728678] | 1 | /*
|
---|
[3c54869] | 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
[47728678] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libui
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file UI resources
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <gfx/color.h>
|
---|
| 38 | #include <gfx/context.h>
|
---|
| 39 | #include <gfx/font.h>
|
---|
| 40 | #include <gfx/render.h>
|
---|
| 41 | #include <gfx/typeface.h>
|
---|
| 42 | #include <stdlib.h>
|
---|
| 43 | #include <str.h>
|
---|
| 44 | #include <ui/resource.h>
|
---|
| 45 | #include "../private/resource.h"
|
---|
| 46 |
|
---|
| 47 | static const char *ui_typeface_path = "/data/font/helena.tpf";
|
---|
| 48 |
|
---|
[bc52b5b] | 49 | /** Create new UI resource in graphics mode.
|
---|
[47728678] | 50 | *
|
---|
| 51 | * @param gc Graphic context
|
---|
[ba09d06] | 52 | * @param rresource Place to store pointer to new UI resource
|
---|
[47728678] | 53 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 54 | */
|
---|
[bc52b5b] | 55 | static errno_t ui_resource_create_gfx(gfx_context_t *gc,
|
---|
[9c7dc8e] | 56 | ui_resource_t **rresource)
|
---|
[47728678] | 57 | {
|
---|
| 58 | ui_resource_t *resource;
|
---|
| 59 | gfx_typeface_t *tface = NULL;
|
---|
| 60 | gfx_font_t *font = NULL;
|
---|
| 61 | gfx_font_info_t *finfo;
|
---|
[de9992c] | 62 | gfx_color_t *btn_frame_color = NULL;
|
---|
| 63 | gfx_color_t *btn_face_color = NULL;
|
---|
[3c54869] | 64 | gfx_color_t *btn_face_lit_color = NULL;
|
---|
[de9992c] | 65 | gfx_color_t *btn_text_color = NULL;
|
---|
| 66 | gfx_color_t *btn_highlight_color = NULL;
|
---|
| 67 | gfx_color_t *btn_shadow_color = NULL;
|
---|
[1769693] | 68 | gfx_color_t *wnd_face_color = NULL;
|
---|
| 69 | gfx_color_t *wnd_text_color = NULL;
|
---|
[ca2680d] | 70 | gfx_color_t *wnd_text_hgl_color = NULL;
|
---|
[214aefb] | 71 | gfx_color_t *wnd_sel_text_color = NULL;
|
---|
[ca2680d] | 72 | gfx_color_t *wnd_sel_text_hgl_color = NULL;
|
---|
[214aefb] | 73 | gfx_color_t *wnd_sel_text_bg_color = NULL;
|
---|
[1769693] | 74 | gfx_color_t *wnd_frame_hi_color = NULL;
|
---|
| 75 | gfx_color_t *wnd_frame_sh_color = NULL;
|
---|
| 76 | gfx_color_t *wnd_highlight_color = NULL;
|
---|
| 77 | gfx_color_t *wnd_shadow_color = NULL;
|
---|
| 78 | gfx_color_t *tbar_act_bg_color = NULL;
|
---|
| 79 | gfx_color_t *tbar_inact_bg_color = NULL;
|
---|
| 80 | gfx_color_t *tbar_act_text_color = NULL;
|
---|
| 81 | gfx_color_t *tbar_inact_text_color = NULL;
|
---|
[03145ee] | 82 | gfx_color_t *entry_fg_color = NULL;
|
---|
| 83 | gfx_color_t *entry_bg_color = NULL;
|
---|
[d70dc1c4] | 84 | gfx_color_t *entry_act_bg_color = NULL;
|
---|
[6df564c] | 85 | gfx_color_t *entry_sel_text_fg_color = NULL;
|
---|
| 86 | gfx_color_t *entry_sel_text_bg_color = NULL;
|
---|
[bd16113] | 87 | gfx_color_t *sbar_through_color = NULL;
|
---|
[1026cc4] | 88 | gfx_color_t *sbar_act_through_color = NULL;
|
---|
[47728678] | 89 | errno_t rc;
|
---|
| 90 |
|
---|
| 91 | resource = calloc(1, sizeof(ui_resource_t));
|
---|
| 92 | if (resource == NULL)
|
---|
| 93 | return ENOMEM;
|
---|
| 94 |
|
---|
[bc52b5b] | 95 | rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
|
---|
| 96 | if (rc != EOK)
|
---|
| 97 | goto error;
|
---|
| 98 |
|
---|
| 99 | finfo = gfx_typeface_first_font(tface);
|
---|
| 100 | if (finfo == NULL) {
|
---|
| 101 | rc = EIO;
|
---|
| 102 | goto error;
|
---|
[47728678] | 103 | }
|
---|
| 104 |
|
---|
[bc52b5b] | 105 | rc = gfx_font_open(finfo, &font);
|
---|
| 106 | if (rc != EOK)
|
---|
| 107 | goto error;
|
---|
| 108 |
|
---|
[de9992c] | 109 | rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
|
---|
| 110 | if (rc != EOK)
|
---|
| 111 | goto error;
|
---|
| 112 |
|
---|
| 113 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &btn_face_color);
|
---|
| 114 | if (rc != EOK)
|
---|
| 115 | goto error;
|
---|
| 116 |
|
---|
[3c54869] | 117 | rc = gfx_color_new_rgb_i16(0xe8e8, 0xe8e8, 0xe8e8, &btn_face_lit_color);
|
---|
| 118 | if (rc != EOK)
|
---|
| 119 | goto error;
|
---|
| 120 |
|
---|
[de9992c] | 121 | rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_text_color);
|
---|
| 122 | if (rc != EOK)
|
---|
| 123 | goto error;
|
---|
| 124 |
|
---|
| 125 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
---|
| 126 | &btn_highlight_color);
|
---|
| 127 | if (rc != EOK)
|
---|
| 128 | goto error;
|
---|
| 129 |
|
---|
| 130 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &btn_shadow_color);
|
---|
| 131 | if (rc != EOK)
|
---|
| 132 | goto error;
|
---|
| 133 |
|
---|
[1769693] | 134 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &wnd_face_color);
|
---|
| 135 | if (rc != EOK)
|
---|
| 136 | goto error;
|
---|
| 137 |
|
---|
| 138 | rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_color);
|
---|
| 139 | if (rc != EOK)
|
---|
| 140 | goto error;
|
---|
| 141 |
|
---|
[ca2680d] | 142 | rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_hgl_color);
|
---|
| 143 | if (rc != EOK)
|
---|
| 144 | goto error;
|
---|
| 145 |
|
---|
[214aefb] | 146 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &wnd_sel_text_color);
|
---|
| 147 | if (rc != EOK)
|
---|
| 148 | goto error;
|
---|
| 149 |
|
---|
[ca2680d] | 150 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
---|
| 151 | &wnd_sel_text_hgl_color);
|
---|
| 152 | if (rc != EOK)
|
---|
| 153 | goto error;
|
---|
| 154 |
|
---|
[214aefb] | 155 | rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4,
|
---|
| 156 | &wnd_sel_text_bg_color);
|
---|
| 157 | if (rc != EOK)
|
---|
| 158 | goto error;
|
---|
| 159 |
|
---|
[1769693] | 160 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color);
|
---|
| 161 | if (rc != EOK)
|
---|
| 162 | goto error;
|
---|
| 163 |
|
---|
[7020d1f] | 164 | rc = gfx_color_new_rgb_i16(0x4444, 0x4444, 0x4444, &wnd_frame_sh_color);
|
---|
[1769693] | 165 | if (rc != EOK)
|
---|
| 166 | goto error;
|
---|
| 167 |
|
---|
| 168 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
---|
| 169 | &wnd_highlight_color);
|
---|
| 170 | if (rc != EOK)
|
---|
| 171 | goto error;
|
---|
| 172 |
|
---|
| 173 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_shadow_color);
|
---|
| 174 | if (rc != EOK)
|
---|
| 175 | goto error;
|
---|
| 176 |
|
---|
| 177 | rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4, &tbar_act_bg_color);
|
---|
| 178 | if (rc != EOK)
|
---|
| 179 | goto error;
|
---|
| 180 |
|
---|
| 181 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
---|
| 182 | &tbar_act_text_color);
|
---|
| 183 | if (rc != EOK)
|
---|
| 184 | goto error;
|
---|
| 185 |
|
---|
| 186 | rc = gfx_color_new_rgb_i16(0xdddd, 0xdddd, 0xdddd,
|
---|
| 187 | &tbar_inact_bg_color);
|
---|
| 188 | if (rc != EOK)
|
---|
| 189 | goto error;
|
---|
| 190 |
|
---|
| 191 | rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
|
---|
| 192 | &tbar_inact_text_color);
|
---|
| 193 | if (rc != EOK)
|
---|
| 194 | goto error;
|
---|
| 195 |
|
---|
[03145ee] | 196 | rc = gfx_color_new_rgb_i16(0, 0, 0, &entry_fg_color);
|
---|
| 197 | if (rc != EOK)
|
---|
| 198 | goto error;
|
---|
| 199 |
|
---|
| 200 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &entry_bg_color);
|
---|
| 201 | if (rc != EOK)
|
---|
| 202 | goto error;
|
---|
| 203 |
|
---|
[d70dc1c4] | 204 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color);
|
---|
| 205 | if (rc != EOK)
|
---|
| 206 | goto error;
|
---|
| 207 |
|
---|
[6df564c] | 208 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
---|
| 209 | &entry_sel_text_fg_color);
|
---|
| 210 | if (rc != EOK)
|
---|
| 211 | goto error;
|
---|
| 212 |
|
---|
| 213 | rc = gfx_color_new_rgb_i16(0, 0, 0xffff, &entry_sel_text_bg_color);
|
---|
| 214 | if (rc != EOK)
|
---|
| 215 | goto error;
|
---|
| 216 |
|
---|
[bd16113] | 217 | rc = gfx_color_new_rgb_i16(0xe4e4, 0xe4e4, 0xe4e4,
|
---|
| 218 | &sbar_through_color);
|
---|
| 219 | if (rc != EOK)
|
---|
| 220 | goto error;
|
---|
| 221 |
|
---|
[1026cc4] | 222 | rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
|
---|
| 223 | &sbar_act_through_color);
|
---|
| 224 | if (rc != EOK)
|
---|
| 225 | goto error;
|
---|
| 226 |
|
---|
[47728678] | 227 | resource->gc = gc;
|
---|
| 228 | resource->tface = tface;
|
---|
| 229 | resource->font = font;
|
---|
[bc52b5b] | 230 | resource->textmode = false;
|
---|
[1769693] | 231 |
|
---|
[de9992c] | 232 | resource->btn_frame_color = btn_frame_color;
|
---|
| 233 | resource->btn_face_color = btn_face_color;
|
---|
[3c54869] | 234 | resource->btn_face_lit_color = btn_face_lit_color;
|
---|
[de9992c] | 235 | resource->btn_text_color = btn_text_color;
|
---|
| 236 | resource->btn_highlight_color = btn_highlight_color;
|
---|
| 237 | resource->btn_shadow_color = btn_shadow_color;
|
---|
[1769693] | 238 |
|
---|
| 239 | resource->wnd_face_color = wnd_face_color;
|
---|
| 240 | resource->wnd_text_color = wnd_text_color;
|
---|
[ca2680d] | 241 | resource->wnd_text_hgl_color = wnd_text_hgl_color;
|
---|
[214aefb] | 242 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
---|
[ca2680d] | 243 | resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
|
---|
[214aefb] | 244 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
---|
[1769693] | 245 | resource->wnd_frame_hi_color = wnd_frame_hi_color;
|
---|
| 246 | resource->wnd_frame_sh_color = wnd_frame_sh_color;
|
---|
| 247 | resource->wnd_highlight_color = wnd_highlight_color;
|
---|
| 248 | resource->wnd_shadow_color = wnd_shadow_color;
|
---|
| 249 |
|
---|
| 250 | resource->tbar_act_bg_color = tbar_act_bg_color;
|
---|
| 251 | resource->tbar_act_text_color = tbar_act_text_color;
|
---|
| 252 | resource->tbar_inact_bg_color = tbar_inact_bg_color;
|
---|
| 253 | resource->tbar_inact_text_color = tbar_inact_text_color;
|
---|
| 254 |
|
---|
[03145ee] | 255 | resource->entry_fg_color = entry_fg_color;
|
---|
| 256 | resource->entry_bg_color = entry_bg_color;
|
---|
[d70dc1c4] | 257 | resource->entry_act_bg_color = entry_act_bg_color;
|
---|
[6df564c] | 258 | resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
|
---|
| 259 | resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
|
---|
[03145ee] | 260 |
|
---|
[bd16113] | 261 | resource->sbar_through_color = sbar_through_color;
|
---|
[1026cc4] | 262 | resource->sbar_act_through_color = sbar_act_through_color;
|
---|
[bd16113] | 263 |
|
---|
[47728678] | 264 | *rresource = resource;
|
---|
| 265 | return EOK;
|
---|
| 266 | error:
|
---|
[de9992c] | 267 | if (btn_frame_color != NULL)
|
---|
| 268 | gfx_color_delete(btn_frame_color);
|
---|
| 269 | if (btn_face_color != NULL)
|
---|
| 270 | gfx_color_delete(btn_face_color);
|
---|
[3c54869] | 271 | if (btn_face_lit_color != NULL)
|
---|
| 272 | gfx_color_delete(btn_face_lit_color);
|
---|
[de9992c] | 273 | if (btn_text_color != NULL)
|
---|
| 274 | gfx_color_delete(btn_text_color);
|
---|
| 275 | if (btn_highlight_color != NULL)
|
---|
| 276 | gfx_color_delete(btn_highlight_color);
|
---|
| 277 | if (btn_shadow_color != NULL)
|
---|
| 278 | gfx_color_delete(btn_shadow_color);
|
---|
[1769693] | 279 |
|
---|
| 280 | if (wnd_face_color != NULL)
|
---|
| 281 | gfx_color_delete(wnd_face_color);
|
---|
| 282 | if (wnd_text_color != NULL)
|
---|
| 283 | gfx_color_delete(wnd_text_color);
|
---|
[ca2680d] | 284 | if (wnd_text_hgl_color != NULL)
|
---|
| 285 | gfx_color_delete(wnd_text_hgl_color);
|
---|
[214aefb] | 286 | if (wnd_sel_text_color != NULL)
|
---|
| 287 | gfx_color_delete(wnd_sel_text_color);
|
---|
[ca2680d] | 288 | if (wnd_sel_text_hgl_color != NULL)
|
---|
| 289 | gfx_color_delete(wnd_sel_text_hgl_color);
|
---|
[214aefb] | 290 | if (wnd_sel_text_bg_color != NULL)
|
---|
| 291 | gfx_color_delete(wnd_sel_text_bg_color);
|
---|
[1769693] | 292 | if (wnd_frame_hi_color != NULL)
|
---|
| 293 | gfx_color_delete(wnd_frame_hi_color);
|
---|
| 294 | if (wnd_frame_sh_color != NULL)
|
---|
| 295 | gfx_color_delete(wnd_frame_sh_color);
|
---|
| 296 | if (wnd_highlight_color != NULL)
|
---|
| 297 | gfx_color_delete(wnd_highlight_color);
|
---|
| 298 | if (wnd_shadow_color != NULL)
|
---|
| 299 | gfx_color_delete(wnd_shadow_color);
|
---|
| 300 |
|
---|
| 301 | if (tbar_act_bg_color != NULL)
|
---|
| 302 | gfx_color_delete(tbar_act_bg_color);
|
---|
| 303 | if (tbar_act_text_color != NULL)
|
---|
| 304 | gfx_color_delete(tbar_act_text_color);
|
---|
| 305 | if (tbar_inact_bg_color != NULL)
|
---|
| 306 | gfx_color_delete(tbar_inact_bg_color);
|
---|
| 307 | if (tbar_inact_text_color != NULL)
|
---|
| 308 | gfx_color_delete(tbar_inact_text_color);
|
---|
| 309 |
|
---|
[03145ee] | 310 | if (entry_fg_color != NULL)
|
---|
| 311 | gfx_color_delete(entry_fg_color);
|
---|
| 312 | if (entry_bg_color != NULL)
|
---|
| 313 | gfx_color_delete(entry_bg_color);
|
---|
[6df564c] | 314 | if (entry_sel_text_fg_color != NULL)
|
---|
| 315 | gfx_color_delete(entry_sel_text_fg_color);
|
---|
| 316 | if (entry_sel_text_bg_color != NULL)
|
---|
| 317 | gfx_color_delete(entry_sel_text_bg_color);
|
---|
[d70dc1c4] | 318 | if (entry_act_bg_color != NULL)
|
---|
| 319 | gfx_color_delete(entry_act_bg_color);
|
---|
[03145ee] | 320 |
|
---|
[bd16113] | 321 | if (sbar_through_color != NULL)
|
---|
| 322 | gfx_color_delete(sbar_through_color);
|
---|
[1026cc4] | 323 | if (sbar_act_through_color != NULL)
|
---|
| 324 | gfx_color_delete(sbar_act_through_color);
|
---|
[bd16113] | 325 |
|
---|
[47728678] | 326 | if (tface != NULL)
|
---|
| 327 | gfx_typeface_destroy(tface);
|
---|
| 328 | free(resource);
|
---|
| 329 | return rc;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
[bc52b5b] | 332 | /** Create new UI resource in text mode.
|
---|
| 333 | *
|
---|
| 334 | * @param gc Graphic context
|
---|
| 335 | * @param rresource Place to store pointer to new UI resource
|
---|
| 336 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 337 | */
|
---|
| 338 | static errno_t ui_resource_create_text(gfx_context_t *gc,
|
---|
| 339 | ui_resource_t **rresource)
|
---|
| 340 | {
|
---|
| 341 | ui_resource_t *resource;
|
---|
| 342 | gfx_typeface_t *tface = NULL;
|
---|
| 343 | gfx_font_t *font = NULL;
|
---|
| 344 | gfx_color_t *btn_frame_color = NULL;
|
---|
| 345 | gfx_color_t *btn_face_color = NULL;
|
---|
[3c54869] | 346 | gfx_color_t *btn_face_lit_color = NULL;
|
---|
[bc52b5b] | 347 | gfx_color_t *btn_text_color = NULL;
|
---|
| 348 | gfx_color_t *btn_highlight_color = NULL;
|
---|
| 349 | gfx_color_t *btn_shadow_color = NULL;
|
---|
| 350 | gfx_color_t *wnd_face_color = NULL;
|
---|
| 351 | gfx_color_t *wnd_text_color = NULL;
|
---|
[ca2680d] | 352 | gfx_color_t *wnd_text_hgl_color = NULL;
|
---|
[bc52b5b] | 353 | gfx_color_t *wnd_sel_text_color = NULL;
|
---|
[ca2680d] | 354 | gfx_color_t *wnd_sel_text_hgl_color = NULL;
|
---|
[bc52b5b] | 355 | gfx_color_t *wnd_sel_text_bg_color = NULL;
|
---|
| 356 | gfx_color_t *wnd_frame_hi_color = NULL;
|
---|
| 357 | gfx_color_t *wnd_frame_sh_color = NULL;
|
---|
| 358 | gfx_color_t *wnd_highlight_color = NULL;
|
---|
| 359 | gfx_color_t *wnd_shadow_color = NULL;
|
---|
| 360 | gfx_color_t *tbar_act_bg_color = NULL;
|
---|
| 361 | gfx_color_t *tbar_inact_bg_color = NULL;
|
---|
| 362 | gfx_color_t *tbar_act_text_color = NULL;
|
---|
| 363 | gfx_color_t *tbar_inact_text_color = NULL;
|
---|
| 364 | gfx_color_t *entry_fg_color = NULL;
|
---|
| 365 | gfx_color_t *entry_bg_color = NULL;
|
---|
[6df564c] | 366 | gfx_color_t *entry_sel_text_fg_color = NULL;
|
---|
| 367 | gfx_color_t *entry_sel_text_bg_color = NULL;
|
---|
[bc52b5b] | 368 | gfx_color_t *entry_act_bg_color = NULL;
|
---|
[bd16113] | 369 | gfx_color_t *sbar_through_color = NULL;
|
---|
[1026cc4] | 370 | gfx_color_t *sbar_act_through_color = NULL;
|
---|
[bc52b5b] | 371 | errno_t rc;
|
---|
| 372 |
|
---|
| 373 | resource = calloc(1, sizeof(ui_resource_t));
|
---|
| 374 | if (resource == NULL)
|
---|
| 375 | return ENOMEM;
|
---|
| 376 |
|
---|
| 377 | /* Create dummy font for text mode */
|
---|
| 378 | rc = gfx_typeface_create(gc, &tface);
|
---|
| 379 | if (rc != EOK)
|
---|
| 380 | goto error;
|
---|
| 381 |
|
---|
| 382 | rc = gfx_font_create_textmode(tface, &font);
|
---|
| 383 | if (rc != EOK)
|
---|
| 384 | goto error;
|
---|
| 385 |
|
---|
| 386 | rc = gfx_color_new_ega(0x07, &btn_frame_color);
|
---|
| 387 | if (rc != EOK)
|
---|
| 388 | goto error;
|
---|
| 389 |
|
---|
| 390 | rc = gfx_color_new_ega(0x20, &btn_face_color);
|
---|
| 391 | if (rc != EOK)
|
---|
| 392 | goto error;
|
---|
| 393 |
|
---|
[3c54869] | 394 | rc = gfx_color_new_ega(0x30, &btn_face_lit_color);
|
---|
| 395 | if (rc != EOK)
|
---|
| 396 | goto error;
|
---|
| 397 |
|
---|
[bc52b5b] | 398 | rc = gfx_color_new_ega(0x20, &btn_text_color);
|
---|
| 399 | if (rc != EOK)
|
---|
| 400 | goto error;
|
---|
| 401 |
|
---|
[1ebcb791] | 402 | rc = gfx_color_new_ega(0x20, &btn_highlight_color);
|
---|
[bc52b5b] | 403 | if (rc != EOK)
|
---|
| 404 | goto error;
|
---|
| 405 |
|
---|
| 406 | rc = gfx_color_new_ega(0x01, &btn_shadow_color);
|
---|
| 407 | if (rc != EOK)
|
---|
| 408 | goto error;
|
---|
| 409 |
|
---|
| 410 | rc = gfx_color_new_ega(0x70, &wnd_face_color);
|
---|
| 411 | if (rc != EOK)
|
---|
| 412 | goto error;
|
---|
| 413 |
|
---|
| 414 | rc = gfx_color_new_ega(0x70, &wnd_text_color);
|
---|
| 415 | if (rc != EOK)
|
---|
| 416 | goto error;
|
---|
| 417 |
|
---|
[ca2680d] | 418 | rc = gfx_color_new_ega(0x74, &wnd_text_hgl_color);
|
---|
| 419 | if (rc != EOK)
|
---|
| 420 | goto error;
|
---|
| 421 |
|
---|
[bc52b5b] | 422 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);
|
---|
| 423 | if (rc != EOK)
|
---|
| 424 | goto error;
|
---|
| 425 |
|
---|
[ca2680d] | 426 | rc = gfx_color_new_ega(0x04, &wnd_sel_text_hgl_color);
|
---|
| 427 | if (rc != EOK)
|
---|
| 428 | goto error;
|
---|
| 429 |
|
---|
[bc52b5b] | 430 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);
|
---|
| 431 | if (rc != EOK)
|
---|
| 432 | goto error;
|
---|
| 433 |
|
---|
| 434 | rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);
|
---|
| 435 | if (rc != EOK)
|
---|
| 436 | goto error;
|
---|
| 437 |
|
---|
| 438 | rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);
|
---|
| 439 | if (rc != EOK)
|
---|
| 440 | goto error;
|
---|
| 441 |
|
---|
| 442 | rc = gfx_color_new_ega(0x70, &wnd_highlight_color);
|
---|
| 443 | if (rc != EOK)
|
---|
| 444 | goto error;
|
---|
| 445 |
|
---|
| 446 | rc = gfx_color_new_ega(0x01, &wnd_shadow_color);
|
---|
| 447 | if (rc != EOK)
|
---|
| 448 | goto error;
|
---|
| 449 |
|
---|
[45004f3] | 450 | rc = gfx_color_new_ega(0x70, &tbar_act_bg_color);
|
---|
[bc52b5b] | 451 | if (rc != EOK)
|
---|
| 452 | goto error;
|
---|
| 453 |
|
---|
[45004f3] | 454 | rc = gfx_color_new_ega(0x70, &tbar_act_text_color);
|
---|
[bc52b5b] | 455 | if (rc != EOK)
|
---|
| 456 | goto error;
|
---|
| 457 |
|
---|
| 458 | rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);
|
---|
| 459 | if (rc != EOK)
|
---|
| 460 | goto error;
|
---|
| 461 |
|
---|
| 462 | rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);
|
---|
| 463 | if (rc != EOK)
|
---|
| 464 | goto error;
|
---|
| 465 |
|
---|
[52214a2] | 466 | rc = gfx_color_new_ega(0x07, &entry_fg_color);
|
---|
[bc52b5b] | 467 | if (rc != EOK)
|
---|
| 468 | goto error;
|
---|
| 469 |
|
---|
[52214a2] | 470 | rc = gfx_color_new_ega(0x07, &entry_bg_color);
|
---|
[bc52b5b] | 471 | if (rc != EOK)
|
---|
| 472 | goto error;
|
---|
| 473 |
|
---|
[52214a2] | 474 | rc = gfx_color_new_ega(0x1e, &entry_sel_text_fg_color);
|
---|
[6df564c] | 475 | if (rc != EOK)
|
---|
| 476 | goto error;
|
---|
| 477 |
|
---|
[52214a2] | 478 | rc = gfx_color_new_ega(0x1e, &entry_sel_text_bg_color);
|
---|
[6df564c] | 479 | if (rc != EOK)
|
---|
| 480 | goto error;
|
---|
| 481 |
|
---|
[bc52b5b] | 482 | rc = gfx_color_new_ega(0x37, &entry_act_bg_color);
|
---|
| 483 | if (rc != EOK)
|
---|
| 484 | goto error;
|
---|
| 485 |
|
---|
[bd16113] | 486 | rc = gfx_color_new_ega(0x07, &sbar_through_color);
|
---|
| 487 | if (rc != EOK)
|
---|
| 488 | goto error;
|
---|
| 489 |
|
---|
[1026cc4] | 490 | rc = gfx_color_new_ega(0x07, &sbar_act_through_color);
|
---|
| 491 | if (rc != EOK)
|
---|
| 492 | goto error;
|
---|
| 493 |
|
---|
[bc52b5b] | 494 | resource->gc = gc;
|
---|
| 495 | resource->tface = tface;
|
---|
| 496 | resource->font = font;
|
---|
| 497 | resource->textmode = true;
|
---|
| 498 |
|
---|
| 499 | resource->btn_frame_color = btn_frame_color;
|
---|
| 500 | resource->btn_face_color = btn_face_color;
|
---|
[3c54869] | 501 | resource->btn_face_lit_color = btn_face_lit_color;
|
---|
[bc52b5b] | 502 | resource->btn_text_color = btn_text_color;
|
---|
| 503 | resource->btn_highlight_color = btn_highlight_color;
|
---|
| 504 | resource->btn_shadow_color = btn_shadow_color;
|
---|
| 505 |
|
---|
| 506 | resource->wnd_face_color = wnd_face_color;
|
---|
| 507 | resource->wnd_text_color = wnd_text_color;
|
---|
[ca2680d] | 508 | resource->wnd_text_hgl_color = wnd_text_hgl_color;
|
---|
[bc52b5b] | 509 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
---|
[ca2680d] | 510 | resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
|
---|
[bc52b5b] | 511 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
---|
| 512 | resource->wnd_frame_hi_color = wnd_frame_hi_color;
|
---|
| 513 | resource->wnd_frame_sh_color = wnd_frame_sh_color;
|
---|
| 514 | resource->wnd_highlight_color = wnd_highlight_color;
|
---|
| 515 | resource->wnd_shadow_color = wnd_shadow_color;
|
---|
| 516 |
|
---|
| 517 | resource->tbar_act_bg_color = tbar_act_bg_color;
|
---|
| 518 | resource->tbar_act_text_color = tbar_act_text_color;
|
---|
| 519 | resource->tbar_inact_bg_color = tbar_inact_bg_color;
|
---|
| 520 | resource->tbar_inact_text_color = tbar_inact_text_color;
|
---|
| 521 |
|
---|
| 522 | resource->entry_fg_color = entry_fg_color;
|
---|
| 523 | resource->entry_bg_color = entry_bg_color;
|
---|
| 524 | resource->entry_act_bg_color = entry_act_bg_color;
|
---|
[6df564c] | 525 | resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
|
---|
| 526 | resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
|
---|
[bc52b5b] | 527 |
|
---|
[bd16113] | 528 | resource->sbar_through_color = sbar_through_color;
|
---|
[1026cc4] | 529 | resource->sbar_act_through_color = sbar_act_through_color;
|
---|
[bd16113] | 530 |
|
---|
[bc52b5b] | 531 | *rresource = resource;
|
---|
| 532 | return EOK;
|
---|
| 533 | error:
|
---|
| 534 | if (btn_frame_color != NULL)
|
---|
| 535 | gfx_color_delete(btn_frame_color);
|
---|
| 536 | if (btn_face_color != NULL)
|
---|
| 537 | gfx_color_delete(btn_face_color);
|
---|
[3c54869] | 538 | if (btn_face_lit_color != NULL)
|
---|
| 539 | gfx_color_delete(btn_face_lit_color);
|
---|
[bc52b5b] | 540 | if (btn_text_color != NULL)
|
---|
| 541 | gfx_color_delete(btn_text_color);
|
---|
| 542 | if (btn_highlight_color != NULL)
|
---|
| 543 | gfx_color_delete(btn_highlight_color);
|
---|
| 544 | if (btn_shadow_color != NULL)
|
---|
| 545 | gfx_color_delete(btn_shadow_color);
|
---|
| 546 |
|
---|
| 547 | if (wnd_face_color != NULL)
|
---|
| 548 | gfx_color_delete(wnd_face_color);
|
---|
| 549 | if (wnd_text_color != NULL)
|
---|
| 550 | gfx_color_delete(wnd_text_color);
|
---|
[ca2680d] | 551 | if (wnd_text_hgl_color != NULL)
|
---|
| 552 | gfx_color_delete(wnd_text_hgl_color);
|
---|
[bc52b5b] | 553 | if (wnd_sel_text_color != NULL)
|
---|
| 554 | gfx_color_delete(wnd_sel_text_color);
|
---|
[ca2680d] | 555 | if (wnd_sel_text_hgl_color != NULL)
|
---|
| 556 | gfx_color_delete(wnd_sel_text_hgl_color);
|
---|
[bc52b5b] | 557 | if (wnd_sel_text_bg_color != NULL)
|
---|
| 558 | gfx_color_delete(wnd_sel_text_bg_color);
|
---|
| 559 | if (wnd_frame_hi_color != NULL)
|
---|
| 560 | gfx_color_delete(wnd_frame_hi_color);
|
---|
| 561 | if (wnd_frame_sh_color != NULL)
|
---|
| 562 | gfx_color_delete(wnd_frame_sh_color);
|
---|
| 563 | if (wnd_highlight_color != NULL)
|
---|
| 564 | gfx_color_delete(wnd_highlight_color);
|
---|
| 565 | if (wnd_shadow_color != NULL)
|
---|
| 566 | gfx_color_delete(wnd_shadow_color);
|
---|
| 567 |
|
---|
| 568 | if (tbar_act_bg_color != NULL)
|
---|
| 569 | gfx_color_delete(tbar_act_bg_color);
|
---|
| 570 | if (tbar_act_text_color != NULL)
|
---|
| 571 | gfx_color_delete(tbar_act_text_color);
|
---|
| 572 | if (tbar_inact_bg_color != NULL)
|
---|
| 573 | gfx_color_delete(tbar_inact_bg_color);
|
---|
| 574 | if (tbar_inact_text_color != NULL)
|
---|
| 575 | gfx_color_delete(tbar_inact_text_color);
|
---|
| 576 |
|
---|
| 577 | if (entry_fg_color != NULL)
|
---|
| 578 | gfx_color_delete(entry_fg_color);
|
---|
| 579 | if (entry_bg_color != NULL)
|
---|
| 580 | gfx_color_delete(entry_bg_color);
|
---|
| 581 | if (entry_act_bg_color != NULL)
|
---|
| 582 | gfx_color_delete(entry_act_bg_color);
|
---|
[6df564c] | 583 | if (entry_sel_text_fg_color != NULL)
|
---|
| 584 | gfx_color_delete(entry_sel_text_fg_color);
|
---|
| 585 | if (entry_sel_text_bg_color != NULL)
|
---|
| 586 | gfx_color_delete(entry_sel_text_bg_color);
|
---|
[bd16113] | 587 | if (sbar_through_color != NULL)
|
---|
| 588 | gfx_color_delete(sbar_through_color);
|
---|
[1026cc4] | 589 | if (sbar_act_through_color != NULL)
|
---|
| 590 | gfx_color_delete(sbar_act_through_color);
|
---|
[bc52b5b] | 591 |
|
---|
| 592 | if (tface != NULL)
|
---|
| 593 | gfx_typeface_destroy(tface);
|
---|
| 594 | free(resource);
|
---|
| 595 | return rc;
|
---|
| 596 | }
|
---|
| 597 |
|
---|
| 598 | /** Create new UI resource.
|
---|
| 599 | *
|
---|
| 600 | * @param gc Graphic context
|
---|
| 601 | * @param textmode @c true if running in text mode
|
---|
| 602 | * @param rresource Place to store pointer to new UI resource
|
---|
| 603 | * @return EOK on success, ENOMEM if out of memory
|
---|
| 604 | */
|
---|
| 605 | errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
|
---|
| 606 | ui_resource_t **rresource)
|
---|
| 607 | {
|
---|
| 608 | if (textmode)
|
---|
| 609 | return ui_resource_create_text(gc, rresource);
|
---|
| 610 | else
|
---|
| 611 | return ui_resource_create_gfx(gc, rresource);
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[47728678] | 614 | /** Destroy UI resource.
|
---|
| 615 | *
|
---|
[4ed00d3] | 616 | * @param resource UI resource or @c NULL
|
---|
[47728678] | 617 | */
|
---|
| 618 | void ui_resource_destroy(ui_resource_t *resource)
|
---|
| 619 | {
|
---|
| 620 | if (resource == NULL)
|
---|
| 621 | return;
|
---|
| 622 |
|
---|
[de9992c] | 623 | gfx_color_delete(resource->btn_frame_color);
|
---|
| 624 | gfx_color_delete(resource->btn_face_color);
|
---|
[3c54869] | 625 | gfx_color_delete(resource->btn_face_lit_color);
|
---|
[de9992c] | 626 | gfx_color_delete(resource->btn_text_color);
|
---|
| 627 | gfx_color_delete(resource->btn_highlight_color);
|
---|
| 628 | gfx_color_delete(resource->btn_shadow_color);
|
---|
| 629 |
|
---|
[1769693] | 630 | gfx_color_delete(resource->wnd_face_color);
|
---|
| 631 | gfx_color_delete(resource->wnd_text_color);
|
---|
[214aefb] | 632 | gfx_color_delete(resource->wnd_sel_text_color);
|
---|
| 633 | gfx_color_delete(resource->wnd_sel_text_bg_color);
|
---|
[1769693] | 634 | gfx_color_delete(resource->wnd_frame_hi_color);
|
---|
| 635 | gfx_color_delete(resource->wnd_frame_sh_color);
|
---|
| 636 | gfx_color_delete(resource->wnd_highlight_color);
|
---|
| 637 | gfx_color_delete(resource->wnd_shadow_color);
|
---|
| 638 |
|
---|
| 639 | gfx_color_delete(resource->tbar_act_bg_color);
|
---|
| 640 | gfx_color_delete(resource->tbar_act_text_color);
|
---|
| 641 | gfx_color_delete(resource->tbar_inact_bg_color);
|
---|
| 642 | gfx_color_delete(resource->tbar_inact_text_color);
|
---|
| 643 |
|
---|
[03145ee] | 644 | gfx_color_delete(resource->entry_fg_color);
|
---|
| 645 | gfx_color_delete(resource->entry_bg_color);
|
---|
[d70dc1c4] | 646 | gfx_color_delete(resource->entry_act_bg_color);
|
---|
[6df564c] | 647 | gfx_color_delete(resource->entry_sel_text_fg_color);
|
---|
| 648 | gfx_color_delete(resource->entry_sel_text_bg_color);
|
---|
[03145ee] | 649 |
|
---|
[bd16113] | 650 | gfx_color_delete(resource->sbar_through_color);
|
---|
[1026cc4] | 651 | gfx_color_delete(resource->sbar_act_through_color);
|
---|
[bd16113] | 652 |
|
---|
[47728678] | 653 | gfx_font_close(resource->font);
|
---|
| 654 | gfx_typeface_destroy(resource->tface);
|
---|
| 655 | free(resource);
|
---|
| 656 | }
|
---|
| 657 |
|
---|
[214aefb] | 658 | /** Set UI resource expose callback.
|
---|
| 659 | *
|
---|
| 660 | * @param resource Resource
|
---|
| 661 | * @param cb Callback
|
---|
| 662 | * @param arg Callback argument
|
---|
| 663 | */
|
---|
| 664 | void ui_resource_set_expose_cb(ui_resource_t *resource,
|
---|
| 665 | ui_expose_cb_t cb, void *arg)
|
---|
| 666 | {
|
---|
| 667 | resource->expose_cb = cb;
|
---|
| 668 | resource->expose_arg = arg;
|
---|
| 669 | }
|
---|
| 670 |
|
---|
| 671 | /** Force UI repaint after an area has been exposed.
|
---|
| 672 | *
|
---|
| 673 | * This is called when a popup disappears, which could have exposed some
|
---|
| 674 | * other UI elements. It causes complete repaint of the UI.
|
---|
| 675 | *
|
---|
| 676 | * NOTE Ideally we could specify the exposed rectangle and then limit
|
---|
| 677 | * the repaint to just that. That would, however, require means of
|
---|
| 678 | * actually clipping the repaint operation.
|
---|
| 679 | */
|
---|
| 680 | void ui_resource_expose(ui_resource_t *resource)
|
---|
| 681 | {
|
---|
| 682 | if (resource->expose_cb != NULL)
|
---|
| 683 | resource->expose_cb(resource->expose_arg);
|
---|
| 684 | }
|
---|
| 685 |
|
---|
[be869b0] | 686 | /** Get the UI font.
|
---|
| 687 | *
|
---|
| 688 | * @param resource UI resource
|
---|
| 689 | * @return UI font
|
---|
| 690 | */
|
---|
| 691 | gfx_font_t *ui_resource_get_font(ui_resource_t *resource)
|
---|
| 692 | {
|
---|
| 693 | return resource->font;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
[e0e612b] | 696 | /** Determine if resource is textmode.
|
---|
| 697 | *
|
---|
| 698 | * @param resource UI resource
|
---|
| 699 | * @return @c true iff resource is textmode
|
---|
| 700 | */
|
---|
| 701 | bool ui_resource_is_textmode(ui_resource_t *resource)
|
---|
| 702 | {
|
---|
| 703 | return resource->textmode;
|
---|
| 704 | }
|
---|
| 705 |
|
---|
[50a16d9] | 706 | /** Get the UI window face color.
|
---|
| 707 | *
|
---|
| 708 | * @param resource UI resource
|
---|
| 709 | * @return UI window face color
|
---|
| 710 | */
|
---|
| 711 | gfx_color_t *ui_resource_get_wnd_face_color(ui_resource_t *resource)
|
---|
| 712 | {
|
---|
| 713 | return resource->wnd_face_color;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | /** Get the UI window text color.
|
---|
| 717 | *
|
---|
| 718 | * @param resource UI resource
|
---|
| 719 | * @return UI window text color
|
---|
| 720 | */
|
---|
| 721 | gfx_color_t *ui_resource_get_wnd_text_color(ui_resource_t *resource)
|
---|
| 722 | {
|
---|
| 723 | return resource->wnd_text_color;
|
---|
| 724 | }
|
---|
| 725 |
|
---|
[47728678] | 726 | /** @}
|
---|
| 727 | */
|
---|