| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 Jiri Svoboda
|
|---|
| 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 |
|
|---|
| 49 | /** Create new UI resource in graphics mode.
|
|---|
| 50 | *
|
|---|
| 51 | * @param gc Graphic context
|
|---|
| 52 | * @param rresource Place to store pointer to new UI resource
|
|---|
| 53 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 54 | */
|
|---|
| 55 | static errno_t ui_resource_create_gfx(gfx_context_t *gc,
|
|---|
| 56 | ui_resource_t **rresource)
|
|---|
| 57 | {
|
|---|
| 58 | ui_resource_t *resource;
|
|---|
| 59 | gfx_typeface_t *tface = NULL;
|
|---|
| 60 | gfx_font_t *font = NULL;
|
|---|
| 61 | gfx_font_info_t *finfo;
|
|---|
| 62 | gfx_color_t *btn_frame_color = NULL;
|
|---|
| 63 | gfx_color_t *btn_face_color = NULL;
|
|---|
| 64 | gfx_color_t *btn_face_lit_color = NULL;
|
|---|
| 65 | gfx_color_t *btn_text_color = NULL;
|
|---|
| 66 | gfx_color_t *btn_highlight_color = NULL;
|
|---|
| 67 | gfx_color_t *btn_shadow_color = NULL;
|
|---|
| 68 | gfx_color_t *wnd_face_color = NULL;
|
|---|
| 69 | gfx_color_t *wnd_text_color = NULL;
|
|---|
| 70 | gfx_color_t *wnd_dis_text_color = NULL;
|
|---|
| 71 | gfx_color_t *wnd_text_hgl_color = NULL;
|
|---|
| 72 | gfx_color_t *wnd_sel_text_color = NULL;
|
|---|
| 73 | gfx_color_t *wnd_sel_text_hgl_color = NULL;
|
|---|
| 74 | gfx_color_t *wnd_sel_text_bg_color = NULL;
|
|---|
| 75 | gfx_color_t *wnd_frame_hi_color = NULL;
|
|---|
| 76 | gfx_color_t *wnd_frame_sh_color = NULL;
|
|---|
| 77 | gfx_color_t *wnd_highlight_color = NULL;
|
|---|
| 78 | gfx_color_t *wnd_shadow_color = NULL;
|
|---|
| 79 | gfx_color_t *tbar_act_bg_color = NULL;
|
|---|
| 80 | gfx_color_t *tbar_inact_bg_color = NULL;
|
|---|
| 81 | gfx_color_t *tbar_act_text_color = NULL;
|
|---|
| 82 | gfx_color_t *tbar_inact_text_color = NULL;
|
|---|
| 83 | gfx_color_t *entry_fg_color = NULL;
|
|---|
| 84 | gfx_color_t *entry_bg_color = NULL;
|
|---|
| 85 | gfx_color_t *entry_act_bg_color = NULL;
|
|---|
| 86 | gfx_color_t *entry_sel_text_fg_color = NULL;
|
|---|
| 87 | gfx_color_t *entry_sel_text_bg_color = NULL;
|
|---|
| 88 | gfx_color_t *sbar_through_color = NULL;
|
|---|
| 89 | gfx_color_t *sbar_act_through_color = NULL;
|
|---|
| 90 | errno_t rc;
|
|---|
| 91 |
|
|---|
| 92 | resource = calloc(1, sizeof(ui_resource_t));
|
|---|
| 93 | if (resource == NULL)
|
|---|
| 94 | return ENOMEM;
|
|---|
| 95 |
|
|---|
| 96 | rc = gfx_typeface_open(gc, ui_typeface_path, &tface);
|
|---|
| 97 | if (rc != EOK)
|
|---|
| 98 | goto error;
|
|---|
| 99 |
|
|---|
| 100 | finfo = gfx_typeface_first_font(tface);
|
|---|
| 101 | if (finfo == NULL) {
|
|---|
| 102 | rc = EIO;
|
|---|
| 103 | goto error;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | rc = gfx_font_open(finfo, &font);
|
|---|
| 107 | if (rc != EOK)
|
|---|
| 108 | goto error;
|
|---|
| 109 |
|
|---|
| 110 | rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_frame_color);
|
|---|
| 111 | if (rc != EOK)
|
|---|
| 112 | goto error;
|
|---|
| 113 |
|
|---|
| 114 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &btn_face_color);
|
|---|
| 115 | if (rc != EOK)
|
|---|
| 116 | goto error;
|
|---|
| 117 |
|
|---|
| 118 | rc = gfx_color_new_rgb_i16(0xe8e8, 0xe8e8, 0xe8e8, &btn_face_lit_color);
|
|---|
| 119 | if (rc != EOK)
|
|---|
| 120 | goto error;
|
|---|
| 121 |
|
|---|
| 122 | rc = gfx_color_new_rgb_i16(0, 0, 0, &btn_text_color);
|
|---|
| 123 | if (rc != EOK)
|
|---|
| 124 | goto error;
|
|---|
| 125 |
|
|---|
| 126 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
|---|
| 127 | &btn_highlight_color);
|
|---|
| 128 | if (rc != EOK)
|
|---|
| 129 | goto error;
|
|---|
| 130 |
|
|---|
| 131 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &btn_shadow_color);
|
|---|
| 132 | if (rc != EOK)
|
|---|
| 133 | goto error;
|
|---|
| 134 |
|
|---|
| 135 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &wnd_face_color);
|
|---|
| 136 | if (rc != EOK)
|
|---|
| 137 | goto error;
|
|---|
| 138 |
|
|---|
| 139 | rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_color);
|
|---|
| 140 | if (rc != EOK)
|
|---|
| 141 | goto error;
|
|---|
| 142 |
|
|---|
| 143 | rc = gfx_color_new_rgb_i16(0x9696, 0x9696, 0x9696, &wnd_dis_text_color);
|
|---|
| 144 | if (rc != EOK)
|
|---|
| 145 | goto error;
|
|---|
| 146 |
|
|---|
| 147 | rc = gfx_color_new_rgb_i16(0, 0, 0, &wnd_text_hgl_color);
|
|---|
| 148 | if (rc != EOK)
|
|---|
| 149 | goto error;
|
|---|
| 150 |
|
|---|
| 151 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &wnd_sel_text_color);
|
|---|
| 152 | if (rc != EOK)
|
|---|
| 153 | goto error;
|
|---|
| 154 |
|
|---|
| 155 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
|---|
| 156 | &wnd_sel_text_hgl_color);
|
|---|
| 157 | if (rc != EOK)
|
|---|
| 158 | goto error;
|
|---|
| 159 |
|
|---|
| 160 | rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4,
|
|---|
| 161 | &wnd_sel_text_bg_color);
|
|---|
| 162 | if (rc != EOK)
|
|---|
| 163 | goto error;
|
|---|
| 164 |
|
|---|
| 165 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color);
|
|---|
| 166 | if (rc != EOK)
|
|---|
| 167 | goto error;
|
|---|
| 168 |
|
|---|
| 169 | rc = gfx_color_new_rgb_i16(0x4444, 0x4444, 0x4444, &wnd_frame_sh_color);
|
|---|
| 170 | if (rc != EOK)
|
|---|
| 171 | goto error;
|
|---|
| 172 |
|
|---|
| 173 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
|---|
| 174 | &wnd_highlight_color);
|
|---|
| 175 | if (rc != EOK)
|
|---|
| 176 | goto error;
|
|---|
| 177 |
|
|---|
| 178 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_shadow_color);
|
|---|
| 179 | if (rc != EOK)
|
|---|
| 180 | goto error;
|
|---|
| 181 |
|
|---|
| 182 | rc = gfx_color_new_rgb_i16(0x5858, 0x6a6a, 0xc4c4, &tbar_act_bg_color);
|
|---|
| 183 | if (rc != EOK)
|
|---|
| 184 | goto error;
|
|---|
| 185 |
|
|---|
| 186 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
|---|
| 187 | &tbar_act_text_color);
|
|---|
| 188 | if (rc != EOK)
|
|---|
| 189 | goto error;
|
|---|
| 190 |
|
|---|
| 191 | rc = gfx_color_new_rgb_i16(0xdddd, 0xdddd, 0xdddd,
|
|---|
| 192 | &tbar_inact_bg_color);
|
|---|
| 193 | if (rc != EOK)
|
|---|
| 194 | goto error;
|
|---|
| 195 |
|
|---|
| 196 | rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
|
|---|
| 197 | &tbar_inact_text_color);
|
|---|
| 198 | if (rc != EOK)
|
|---|
| 199 | goto error;
|
|---|
| 200 |
|
|---|
| 201 | rc = gfx_color_new_rgb_i16(0, 0, 0, &entry_fg_color);
|
|---|
| 202 | if (rc != EOK)
|
|---|
| 203 | goto error;
|
|---|
| 204 |
|
|---|
| 205 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &entry_bg_color);
|
|---|
| 206 | if (rc != EOK)
|
|---|
| 207 | goto error;
|
|---|
| 208 |
|
|---|
| 209 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color);
|
|---|
| 210 | if (rc != EOK)
|
|---|
| 211 | goto error;
|
|---|
| 212 |
|
|---|
| 213 | rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff,
|
|---|
| 214 | &entry_sel_text_fg_color);
|
|---|
| 215 | if (rc != EOK)
|
|---|
| 216 | goto error;
|
|---|
| 217 |
|
|---|
| 218 | rc = gfx_color_new_rgb_i16(0, 0, 0xffff, &entry_sel_text_bg_color);
|
|---|
| 219 | if (rc != EOK)
|
|---|
| 220 | goto error;
|
|---|
| 221 |
|
|---|
| 222 | rc = gfx_color_new_rgb_i16(0xe4e4, 0xe4e4, 0xe4e4,
|
|---|
| 223 | &sbar_through_color);
|
|---|
| 224 | if (rc != EOK)
|
|---|
| 225 | goto error;
|
|---|
| 226 |
|
|---|
| 227 | rc = gfx_color_new_rgb_i16(0x5858, 0x5858, 0x5858,
|
|---|
| 228 | &sbar_act_through_color);
|
|---|
| 229 | if (rc != EOK)
|
|---|
| 230 | goto error;
|
|---|
| 231 |
|
|---|
| 232 | resource->gc = gc;
|
|---|
| 233 | resource->tface = tface;
|
|---|
| 234 | resource->font = font;
|
|---|
| 235 | resource->textmode = false;
|
|---|
| 236 |
|
|---|
| 237 | resource->btn_frame_color = btn_frame_color;
|
|---|
| 238 | resource->btn_face_color = btn_face_color;
|
|---|
| 239 | resource->btn_face_lit_color = btn_face_lit_color;
|
|---|
| 240 | resource->btn_text_color = btn_text_color;
|
|---|
| 241 | resource->btn_highlight_color = btn_highlight_color;
|
|---|
| 242 | resource->btn_shadow_color = btn_shadow_color;
|
|---|
| 243 |
|
|---|
| 244 | resource->wnd_face_color = wnd_face_color;
|
|---|
| 245 | resource->wnd_text_color = wnd_text_color;
|
|---|
| 246 | resource->wnd_dis_text_color = wnd_dis_text_color;
|
|---|
| 247 | resource->wnd_text_hgl_color = wnd_text_hgl_color;
|
|---|
| 248 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
|---|
| 249 | resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
|
|---|
| 250 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
|---|
| 251 | resource->wnd_frame_hi_color = wnd_frame_hi_color;
|
|---|
| 252 | resource->wnd_frame_sh_color = wnd_frame_sh_color;
|
|---|
| 253 | resource->wnd_highlight_color = wnd_highlight_color;
|
|---|
| 254 | resource->wnd_shadow_color = wnd_shadow_color;
|
|---|
| 255 |
|
|---|
| 256 | resource->tbar_act_bg_color = tbar_act_bg_color;
|
|---|
| 257 | resource->tbar_act_text_color = tbar_act_text_color;
|
|---|
| 258 | resource->tbar_inact_bg_color = tbar_inact_bg_color;
|
|---|
| 259 | resource->tbar_inact_text_color = tbar_inact_text_color;
|
|---|
| 260 |
|
|---|
| 261 | resource->entry_fg_color = entry_fg_color;
|
|---|
| 262 | resource->entry_bg_color = entry_bg_color;
|
|---|
| 263 | resource->entry_act_bg_color = entry_act_bg_color;
|
|---|
| 264 | resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
|
|---|
| 265 | resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
|
|---|
| 266 |
|
|---|
| 267 | resource->sbar_through_color = sbar_through_color;
|
|---|
| 268 | resource->sbar_act_through_color = sbar_act_through_color;
|
|---|
| 269 |
|
|---|
| 270 | *rresource = resource;
|
|---|
| 271 | return EOK;
|
|---|
| 272 | error:
|
|---|
| 273 | if (btn_frame_color != NULL)
|
|---|
| 274 | gfx_color_delete(btn_frame_color);
|
|---|
| 275 | if (btn_face_color != NULL)
|
|---|
| 276 | gfx_color_delete(btn_face_color);
|
|---|
| 277 | if (btn_face_lit_color != NULL)
|
|---|
| 278 | gfx_color_delete(btn_face_lit_color);
|
|---|
| 279 | if (btn_text_color != NULL)
|
|---|
| 280 | gfx_color_delete(btn_text_color);
|
|---|
| 281 | if (btn_highlight_color != NULL)
|
|---|
| 282 | gfx_color_delete(btn_highlight_color);
|
|---|
| 283 | if (btn_shadow_color != NULL)
|
|---|
| 284 | gfx_color_delete(btn_shadow_color);
|
|---|
| 285 |
|
|---|
| 286 | if (wnd_face_color != NULL)
|
|---|
| 287 | gfx_color_delete(wnd_face_color);
|
|---|
| 288 | if (wnd_text_color != NULL)
|
|---|
| 289 | gfx_color_delete(wnd_text_color);
|
|---|
| 290 | if (wnd_dis_text_color != NULL)
|
|---|
| 291 | gfx_color_delete(wnd_dis_text_color);
|
|---|
| 292 | if (wnd_text_hgl_color != NULL)
|
|---|
| 293 | gfx_color_delete(wnd_text_hgl_color);
|
|---|
| 294 | if (wnd_sel_text_color != NULL)
|
|---|
| 295 | gfx_color_delete(wnd_sel_text_color);
|
|---|
| 296 | if (wnd_sel_text_hgl_color != NULL)
|
|---|
| 297 | gfx_color_delete(wnd_sel_text_hgl_color);
|
|---|
| 298 | if (wnd_sel_text_bg_color != NULL)
|
|---|
| 299 | gfx_color_delete(wnd_sel_text_bg_color);
|
|---|
| 300 | if (wnd_frame_hi_color != NULL)
|
|---|
| 301 | gfx_color_delete(wnd_frame_hi_color);
|
|---|
| 302 | if (wnd_frame_sh_color != NULL)
|
|---|
| 303 | gfx_color_delete(wnd_frame_sh_color);
|
|---|
| 304 | if (wnd_highlight_color != NULL)
|
|---|
| 305 | gfx_color_delete(wnd_highlight_color);
|
|---|
| 306 | if (wnd_shadow_color != NULL)
|
|---|
| 307 | gfx_color_delete(wnd_shadow_color);
|
|---|
| 308 |
|
|---|
| 309 | if (tbar_act_bg_color != NULL)
|
|---|
| 310 | gfx_color_delete(tbar_act_bg_color);
|
|---|
| 311 | if (tbar_act_text_color != NULL)
|
|---|
| 312 | gfx_color_delete(tbar_act_text_color);
|
|---|
| 313 | if (tbar_inact_bg_color != NULL)
|
|---|
| 314 | gfx_color_delete(tbar_inact_bg_color);
|
|---|
| 315 | if (tbar_inact_text_color != NULL)
|
|---|
| 316 | gfx_color_delete(tbar_inact_text_color);
|
|---|
| 317 |
|
|---|
| 318 | if (entry_fg_color != NULL)
|
|---|
| 319 | gfx_color_delete(entry_fg_color);
|
|---|
| 320 | if (entry_bg_color != NULL)
|
|---|
| 321 | gfx_color_delete(entry_bg_color);
|
|---|
| 322 | if (entry_sel_text_fg_color != NULL)
|
|---|
| 323 | gfx_color_delete(entry_sel_text_fg_color);
|
|---|
| 324 | if (entry_sel_text_bg_color != NULL)
|
|---|
| 325 | gfx_color_delete(entry_sel_text_bg_color);
|
|---|
| 326 | if (entry_act_bg_color != NULL)
|
|---|
| 327 | gfx_color_delete(entry_act_bg_color);
|
|---|
| 328 |
|
|---|
| 329 | if (sbar_through_color != NULL)
|
|---|
| 330 | gfx_color_delete(sbar_through_color);
|
|---|
| 331 | if (sbar_act_through_color != NULL)
|
|---|
| 332 | gfx_color_delete(sbar_act_through_color);
|
|---|
| 333 |
|
|---|
| 334 | if (tface != NULL)
|
|---|
| 335 | gfx_typeface_destroy(tface);
|
|---|
| 336 | free(resource);
|
|---|
| 337 | return rc;
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | /** Create new UI resource in text mode.
|
|---|
| 341 | *
|
|---|
| 342 | * @param gc Graphic context
|
|---|
| 343 | * @param rresource Place to store pointer to new UI resource
|
|---|
| 344 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 345 | */
|
|---|
| 346 | static errno_t ui_resource_create_text(gfx_context_t *gc,
|
|---|
| 347 | ui_resource_t **rresource)
|
|---|
| 348 | {
|
|---|
| 349 | ui_resource_t *resource;
|
|---|
| 350 | gfx_typeface_t *tface = NULL;
|
|---|
| 351 | gfx_font_t *font = NULL;
|
|---|
| 352 | gfx_color_t *btn_frame_color = NULL;
|
|---|
| 353 | gfx_color_t *btn_face_color = NULL;
|
|---|
| 354 | gfx_color_t *btn_face_lit_color = NULL;
|
|---|
| 355 | gfx_color_t *btn_text_color = NULL;
|
|---|
| 356 | gfx_color_t *btn_highlight_color = NULL;
|
|---|
| 357 | gfx_color_t *btn_shadow_color = NULL;
|
|---|
| 358 | gfx_color_t *wnd_face_color = NULL;
|
|---|
| 359 | gfx_color_t *wnd_text_color = NULL;
|
|---|
| 360 | gfx_color_t *wnd_dis_text_color = NULL;
|
|---|
| 361 | gfx_color_t *wnd_text_hgl_color = NULL;
|
|---|
| 362 | gfx_color_t *wnd_sel_text_color = NULL;
|
|---|
| 363 | gfx_color_t *wnd_sel_text_hgl_color = NULL;
|
|---|
| 364 | gfx_color_t *wnd_sel_text_bg_color = NULL;
|
|---|
| 365 | gfx_color_t *wnd_frame_hi_color = NULL;
|
|---|
| 366 | gfx_color_t *wnd_frame_sh_color = NULL;
|
|---|
| 367 | gfx_color_t *wnd_highlight_color = NULL;
|
|---|
| 368 | gfx_color_t *wnd_shadow_color = NULL;
|
|---|
| 369 | gfx_color_t *tbar_act_bg_color = NULL;
|
|---|
| 370 | gfx_color_t *tbar_inact_bg_color = NULL;
|
|---|
| 371 | gfx_color_t *tbar_act_text_color = NULL;
|
|---|
| 372 | gfx_color_t *tbar_inact_text_color = NULL;
|
|---|
| 373 | gfx_color_t *entry_fg_color = NULL;
|
|---|
| 374 | gfx_color_t *entry_bg_color = NULL;
|
|---|
| 375 | gfx_color_t *entry_sel_text_fg_color = NULL;
|
|---|
| 376 | gfx_color_t *entry_sel_text_bg_color = NULL;
|
|---|
| 377 | gfx_color_t *entry_act_bg_color = NULL;
|
|---|
| 378 | gfx_color_t *sbar_through_color = NULL;
|
|---|
| 379 | gfx_color_t *sbar_act_through_color = NULL;
|
|---|
| 380 | errno_t rc;
|
|---|
| 381 |
|
|---|
| 382 | resource = calloc(1, sizeof(ui_resource_t));
|
|---|
| 383 | if (resource == NULL)
|
|---|
| 384 | return ENOMEM;
|
|---|
| 385 |
|
|---|
| 386 | /* Create dummy font for text mode */
|
|---|
| 387 | rc = gfx_typeface_create(gc, &tface);
|
|---|
| 388 | if (rc != EOK)
|
|---|
| 389 | goto error;
|
|---|
| 390 |
|
|---|
| 391 | rc = gfx_font_create_textmode(tface, &font);
|
|---|
| 392 | if (rc != EOK)
|
|---|
| 393 | goto error;
|
|---|
| 394 |
|
|---|
| 395 | rc = gfx_color_new_ega(0x07, &btn_frame_color);
|
|---|
| 396 | if (rc != EOK)
|
|---|
| 397 | goto error;
|
|---|
| 398 |
|
|---|
| 399 | rc = gfx_color_new_ega(0x20, &btn_face_color);
|
|---|
| 400 | if (rc != EOK)
|
|---|
| 401 | goto error;
|
|---|
| 402 |
|
|---|
| 403 | rc = gfx_color_new_ega(0x30, &btn_face_lit_color);
|
|---|
| 404 | if (rc != EOK)
|
|---|
| 405 | goto error;
|
|---|
| 406 |
|
|---|
| 407 | rc = gfx_color_new_ega(0x20, &btn_text_color);
|
|---|
| 408 | if (rc != EOK)
|
|---|
| 409 | goto error;
|
|---|
| 410 |
|
|---|
| 411 | rc = gfx_color_new_ega(0x20, &btn_highlight_color);
|
|---|
| 412 | if (rc != EOK)
|
|---|
| 413 | goto error;
|
|---|
| 414 |
|
|---|
| 415 | rc = gfx_color_new_ega(0x01, &btn_shadow_color);
|
|---|
| 416 | if (rc != EOK)
|
|---|
| 417 | goto error;
|
|---|
| 418 |
|
|---|
| 419 | rc = gfx_color_new_ega(0x70, &wnd_face_color);
|
|---|
| 420 | if (rc != EOK)
|
|---|
| 421 | goto error;
|
|---|
| 422 |
|
|---|
| 423 | rc = gfx_color_new_ega(0x70, &wnd_text_color);
|
|---|
| 424 | if (rc != EOK)
|
|---|
| 425 | goto error;
|
|---|
| 426 |
|
|---|
| 427 | rc = gfx_color_new_ega(0x78, &wnd_dis_text_color);
|
|---|
| 428 | if (rc != EOK)
|
|---|
| 429 | goto error;
|
|---|
| 430 |
|
|---|
| 431 | rc = gfx_color_new_ega(0x74, &wnd_text_hgl_color);
|
|---|
| 432 | if (rc != EOK)
|
|---|
| 433 | goto error;
|
|---|
| 434 |
|
|---|
| 435 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);
|
|---|
| 436 | if (rc != EOK)
|
|---|
| 437 | goto error;
|
|---|
| 438 |
|
|---|
| 439 | rc = gfx_color_new_ega(0x04, &wnd_sel_text_hgl_color);
|
|---|
| 440 | if (rc != EOK)
|
|---|
| 441 | goto error;
|
|---|
| 442 |
|
|---|
| 443 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);
|
|---|
| 444 | if (rc != EOK)
|
|---|
| 445 | goto error;
|
|---|
| 446 |
|
|---|
| 447 | rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);
|
|---|
| 448 | if (rc != EOK)
|
|---|
| 449 | goto error;
|
|---|
| 450 |
|
|---|
| 451 | rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);
|
|---|
| 452 | if (rc != EOK)
|
|---|
| 453 | goto error;
|
|---|
| 454 |
|
|---|
| 455 | rc = gfx_color_new_ega(0x70, &wnd_highlight_color);
|
|---|
| 456 | if (rc != EOK)
|
|---|
| 457 | goto error;
|
|---|
| 458 |
|
|---|
| 459 | rc = gfx_color_new_ega(0x01, &wnd_shadow_color);
|
|---|
| 460 | if (rc != EOK)
|
|---|
| 461 | goto error;
|
|---|
| 462 |
|
|---|
| 463 | rc = gfx_color_new_ega(0x70, &tbar_act_bg_color);
|
|---|
| 464 | if (rc != EOK)
|
|---|
| 465 | goto error;
|
|---|
| 466 |
|
|---|
| 467 | rc = gfx_color_new_ega(0x70, &tbar_act_text_color);
|
|---|
| 468 | if (rc != EOK)
|
|---|
| 469 | goto error;
|
|---|
| 470 |
|
|---|
| 471 | rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);
|
|---|
| 472 | if (rc != EOK)
|
|---|
| 473 | goto error;
|
|---|
| 474 |
|
|---|
| 475 | rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);
|
|---|
| 476 | if (rc != EOK)
|
|---|
| 477 | goto error;
|
|---|
| 478 |
|
|---|
| 479 | rc = gfx_color_new_ega(0x07, &entry_fg_color);
|
|---|
| 480 | if (rc != EOK)
|
|---|
| 481 | goto error;
|
|---|
| 482 |
|
|---|
| 483 | rc = gfx_color_new_ega(0x07, &entry_bg_color);
|
|---|
| 484 | if (rc != EOK)
|
|---|
| 485 | goto error;
|
|---|
| 486 |
|
|---|
| 487 | rc = gfx_color_new_ega(0x1e, &entry_sel_text_fg_color);
|
|---|
| 488 | if (rc != EOK)
|
|---|
| 489 | goto error;
|
|---|
| 490 |
|
|---|
| 491 | rc = gfx_color_new_ega(0x1e, &entry_sel_text_bg_color);
|
|---|
| 492 | if (rc != EOK)
|
|---|
| 493 | goto error;
|
|---|
| 494 |
|
|---|
| 495 | rc = gfx_color_new_ega(0x37, &entry_act_bg_color);
|
|---|
| 496 | if (rc != EOK)
|
|---|
| 497 | goto error;
|
|---|
| 498 |
|
|---|
| 499 | rc = gfx_color_new_ega(0x07, &sbar_through_color);
|
|---|
| 500 | if (rc != EOK)
|
|---|
| 501 | goto error;
|
|---|
| 502 |
|
|---|
| 503 | rc = gfx_color_new_ega(0x07, &sbar_act_through_color);
|
|---|
| 504 | if (rc != EOK)
|
|---|
| 505 | goto error;
|
|---|
| 506 |
|
|---|
| 507 | resource->gc = gc;
|
|---|
| 508 | resource->tface = tface;
|
|---|
| 509 | resource->font = font;
|
|---|
| 510 | resource->textmode = true;
|
|---|
| 511 |
|
|---|
| 512 | resource->btn_frame_color = btn_frame_color;
|
|---|
| 513 | resource->btn_face_color = btn_face_color;
|
|---|
| 514 | resource->btn_face_lit_color = btn_face_lit_color;
|
|---|
| 515 | resource->btn_text_color = btn_text_color;
|
|---|
| 516 | resource->btn_highlight_color = btn_highlight_color;
|
|---|
| 517 | resource->btn_shadow_color = btn_shadow_color;
|
|---|
| 518 |
|
|---|
| 519 | resource->wnd_face_color = wnd_face_color;
|
|---|
| 520 | resource->wnd_text_color = wnd_text_color;
|
|---|
| 521 | resource->wnd_dis_text_color = wnd_dis_text_color;
|
|---|
| 522 | resource->wnd_text_hgl_color = wnd_text_hgl_color;
|
|---|
| 523 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
|---|
| 524 | resource->wnd_sel_text_hgl_color = wnd_sel_text_hgl_color;
|
|---|
| 525 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
|---|
| 526 | resource->wnd_frame_hi_color = wnd_frame_hi_color;
|
|---|
| 527 | resource->wnd_frame_sh_color = wnd_frame_sh_color;
|
|---|
| 528 | resource->wnd_highlight_color = wnd_highlight_color;
|
|---|
| 529 | resource->wnd_shadow_color = wnd_shadow_color;
|
|---|
| 530 |
|
|---|
| 531 | resource->tbar_act_bg_color = tbar_act_bg_color;
|
|---|
| 532 | resource->tbar_act_text_color = tbar_act_text_color;
|
|---|
| 533 | resource->tbar_inact_bg_color = tbar_inact_bg_color;
|
|---|
| 534 | resource->tbar_inact_text_color = tbar_inact_text_color;
|
|---|
| 535 |
|
|---|
| 536 | resource->entry_fg_color = entry_fg_color;
|
|---|
| 537 | resource->entry_bg_color = entry_bg_color;
|
|---|
| 538 | resource->entry_act_bg_color = entry_act_bg_color;
|
|---|
| 539 | resource->entry_sel_text_fg_color = entry_sel_text_fg_color;
|
|---|
| 540 | resource->entry_sel_text_bg_color = entry_sel_text_bg_color;
|
|---|
| 541 |
|
|---|
| 542 | resource->sbar_through_color = sbar_through_color;
|
|---|
| 543 | resource->sbar_act_through_color = sbar_act_through_color;
|
|---|
| 544 |
|
|---|
| 545 | *rresource = resource;
|
|---|
| 546 | return EOK;
|
|---|
| 547 | error:
|
|---|
| 548 | if (btn_frame_color != NULL)
|
|---|
| 549 | gfx_color_delete(btn_frame_color);
|
|---|
| 550 | if (btn_face_color != NULL)
|
|---|
| 551 | gfx_color_delete(btn_face_color);
|
|---|
| 552 | if (btn_face_lit_color != NULL)
|
|---|
| 553 | gfx_color_delete(btn_face_lit_color);
|
|---|
| 554 | if (btn_text_color != NULL)
|
|---|
| 555 | gfx_color_delete(btn_text_color);
|
|---|
| 556 | if (btn_highlight_color != NULL)
|
|---|
| 557 | gfx_color_delete(btn_highlight_color);
|
|---|
| 558 | if (btn_shadow_color != NULL)
|
|---|
| 559 | gfx_color_delete(btn_shadow_color);
|
|---|
| 560 |
|
|---|
| 561 | if (wnd_face_color != NULL)
|
|---|
| 562 | gfx_color_delete(wnd_face_color);
|
|---|
| 563 | if (wnd_text_color != NULL)
|
|---|
| 564 | gfx_color_delete(wnd_text_color);
|
|---|
| 565 | if (wnd_dis_text_color != NULL)
|
|---|
| 566 | gfx_color_delete(wnd_dis_text_color);
|
|---|
| 567 | if (wnd_text_hgl_color != NULL)
|
|---|
| 568 | gfx_color_delete(wnd_text_hgl_color);
|
|---|
| 569 | if (wnd_sel_text_color != NULL)
|
|---|
| 570 | gfx_color_delete(wnd_sel_text_color);
|
|---|
| 571 | if (wnd_sel_text_hgl_color != NULL)
|
|---|
| 572 | gfx_color_delete(wnd_sel_text_hgl_color);
|
|---|
| 573 | if (wnd_sel_text_bg_color != NULL)
|
|---|
| 574 | gfx_color_delete(wnd_sel_text_bg_color);
|
|---|
| 575 | if (wnd_frame_hi_color != NULL)
|
|---|
| 576 | gfx_color_delete(wnd_frame_hi_color);
|
|---|
| 577 | if (wnd_frame_sh_color != NULL)
|
|---|
| 578 | gfx_color_delete(wnd_frame_sh_color);
|
|---|
| 579 | if (wnd_highlight_color != NULL)
|
|---|
| 580 | gfx_color_delete(wnd_highlight_color);
|
|---|
| 581 | if (wnd_shadow_color != NULL)
|
|---|
| 582 | gfx_color_delete(wnd_shadow_color);
|
|---|
| 583 |
|
|---|
| 584 | if (tbar_act_bg_color != NULL)
|
|---|
| 585 | gfx_color_delete(tbar_act_bg_color);
|
|---|
| 586 | if (tbar_act_text_color != NULL)
|
|---|
| 587 | gfx_color_delete(tbar_act_text_color);
|
|---|
| 588 | if (tbar_inact_bg_color != NULL)
|
|---|
| 589 | gfx_color_delete(tbar_inact_bg_color);
|
|---|
| 590 | if (tbar_inact_text_color != NULL)
|
|---|
| 591 | gfx_color_delete(tbar_inact_text_color);
|
|---|
| 592 |
|
|---|
| 593 | if (entry_fg_color != NULL)
|
|---|
| 594 | gfx_color_delete(entry_fg_color);
|
|---|
| 595 | if (entry_bg_color != NULL)
|
|---|
| 596 | gfx_color_delete(entry_bg_color);
|
|---|
| 597 | if (entry_act_bg_color != NULL)
|
|---|
| 598 | gfx_color_delete(entry_act_bg_color);
|
|---|
| 599 | if (entry_sel_text_fg_color != NULL)
|
|---|
| 600 | gfx_color_delete(entry_sel_text_fg_color);
|
|---|
| 601 | if (entry_sel_text_bg_color != NULL)
|
|---|
| 602 | gfx_color_delete(entry_sel_text_bg_color);
|
|---|
| 603 | if (sbar_through_color != NULL)
|
|---|
| 604 | gfx_color_delete(sbar_through_color);
|
|---|
| 605 | if (sbar_act_through_color != NULL)
|
|---|
| 606 | gfx_color_delete(sbar_act_through_color);
|
|---|
| 607 |
|
|---|
| 608 | if (tface != NULL)
|
|---|
| 609 | gfx_typeface_destroy(tface);
|
|---|
| 610 | free(resource);
|
|---|
| 611 | return rc;
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | /** Create new UI resource.
|
|---|
| 615 | *
|
|---|
| 616 | * @param gc Graphic context
|
|---|
| 617 | * @param textmode @c true if running in text mode
|
|---|
| 618 | * @param rresource Place to store pointer to new UI resource
|
|---|
| 619 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 620 | */
|
|---|
| 621 | errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
|
|---|
| 622 | ui_resource_t **rresource)
|
|---|
| 623 | {
|
|---|
| 624 | if (textmode)
|
|---|
| 625 | return ui_resource_create_text(gc, rresource);
|
|---|
| 626 | else
|
|---|
| 627 | return ui_resource_create_gfx(gc, rresource);
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | /** Destroy UI resource.
|
|---|
| 631 | *
|
|---|
| 632 | * @param resource UI resource or @c NULL
|
|---|
| 633 | */
|
|---|
| 634 | void ui_resource_destroy(ui_resource_t *resource)
|
|---|
| 635 | {
|
|---|
| 636 | if (resource == NULL)
|
|---|
| 637 | return;
|
|---|
| 638 |
|
|---|
| 639 | gfx_color_delete(resource->btn_frame_color);
|
|---|
| 640 | gfx_color_delete(resource->btn_face_color);
|
|---|
| 641 | gfx_color_delete(resource->btn_face_lit_color);
|
|---|
| 642 | gfx_color_delete(resource->btn_text_color);
|
|---|
| 643 | gfx_color_delete(resource->btn_highlight_color);
|
|---|
| 644 | gfx_color_delete(resource->btn_shadow_color);
|
|---|
| 645 |
|
|---|
| 646 | gfx_color_delete(resource->wnd_face_color);
|
|---|
| 647 | gfx_color_delete(resource->wnd_text_color);
|
|---|
| 648 | gfx_color_delete(resource->wnd_dis_text_color);
|
|---|
| 649 | gfx_color_delete(resource->wnd_sel_text_color);
|
|---|
| 650 | gfx_color_delete(resource->wnd_sel_text_bg_color);
|
|---|
| 651 | gfx_color_delete(resource->wnd_frame_hi_color);
|
|---|
| 652 | gfx_color_delete(resource->wnd_frame_sh_color);
|
|---|
| 653 | gfx_color_delete(resource->wnd_highlight_color);
|
|---|
| 654 | gfx_color_delete(resource->wnd_shadow_color);
|
|---|
| 655 |
|
|---|
| 656 | gfx_color_delete(resource->tbar_act_bg_color);
|
|---|
| 657 | gfx_color_delete(resource->tbar_act_text_color);
|
|---|
| 658 | gfx_color_delete(resource->tbar_inact_bg_color);
|
|---|
| 659 | gfx_color_delete(resource->tbar_inact_text_color);
|
|---|
| 660 |
|
|---|
| 661 | gfx_color_delete(resource->entry_fg_color);
|
|---|
| 662 | gfx_color_delete(resource->entry_bg_color);
|
|---|
| 663 | gfx_color_delete(resource->entry_act_bg_color);
|
|---|
| 664 | gfx_color_delete(resource->entry_sel_text_fg_color);
|
|---|
| 665 | gfx_color_delete(resource->entry_sel_text_bg_color);
|
|---|
| 666 |
|
|---|
| 667 | gfx_color_delete(resource->sbar_through_color);
|
|---|
| 668 | gfx_color_delete(resource->sbar_act_through_color);
|
|---|
| 669 |
|
|---|
| 670 | gfx_font_close(resource->font);
|
|---|
| 671 | gfx_typeface_destroy(resource->tface);
|
|---|
| 672 | free(resource);
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| 675 | /** Set UI resource expose callback.
|
|---|
| 676 | *
|
|---|
| 677 | * @param resource Resource
|
|---|
| 678 | * @param cb Callback
|
|---|
| 679 | * @param arg Callback argument
|
|---|
| 680 | */
|
|---|
| 681 | void ui_resource_set_expose_cb(ui_resource_t *resource,
|
|---|
| 682 | ui_expose_cb_t cb, void *arg)
|
|---|
| 683 | {
|
|---|
| 684 | resource->expose_cb = cb;
|
|---|
| 685 | resource->expose_arg = arg;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | /** Force UI repaint after an area has been exposed.
|
|---|
| 689 | *
|
|---|
| 690 | * This is called when a popup disappears, which could have exposed some
|
|---|
| 691 | * other UI elements. It causes complete repaint of the UI.
|
|---|
| 692 | *
|
|---|
| 693 | * NOTE Ideally we could specify the exposed rectangle and then limit
|
|---|
| 694 | * the repaint to just that. That would, however, require means of
|
|---|
| 695 | * actually clipping the repaint operation.
|
|---|
| 696 | */
|
|---|
| 697 | void ui_resource_expose(ui_resource_t *resource)
|
|---|
| 698 | {
|
|---|
| 699 | if (resource->expose_cb != NULL)
|
|---|
| 700 | resource->expose_cb(resource->expose_arg);
|
|---|
| 701 | }
|
|---|
| 702 |
|
|---|
| 703 | /** Get the UI font.
|
|---|
| 704 | *
|
|---|
| 705 | * @param resource UI resource
|
|---|
| 706 | * @return UI font
|
|---|
| 707 | */
|
|---|
| 708 | gfx_font_t *ui_resource_get_font(ui_resource_t *resource)
|
|---|
| 709 | {
|
|---|
| 710 | return resource->font;
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | /** Determine if resource is textmode.
|
|---|
| 714 | *
|
|---|
| 715 | * @param resource UI resource
|
|---|
| 716 | * @return @c true iff resource is textmode
|
|---|
| 717 | */
|
|---|
| 718 | bool ui_resource_is_textmode(ui_resource_t *resource)
|
|---|
| 719 | {
|
|---|
| 720 | return resource->textmode;
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | /** Get the UI window face color.
|
|---|
| 724 | *
|
|---|
| 725 | * @param resource UI resource
|
|---|
| 726 | * @return UI window face color
|
|---|
| 727 | */
|
|---|
| 728 | gfx_color_t *ui_resource_get_wnd_face_color(ui_resource_t *resource)
|
|---|
| 729 | {
|
|---|
| 730 | return resource->wnd_face_color;
|
|---|
| 731 | }
|
|---|
| 732 |
|
|---|
| 733 | /** Get the UI window text color.
|
|---|
| 734 | *
|
|---|
| 735 | * @param resource UI resource
|
|---|
| 736 | * @return UI window text color
|
|---|
| 737 | */
|
|---|
| 738 | gfx_color_t *ui_resource_get_wnd_text_color(ui_resource_t *resource)
|
|---|
| 739 | {
|
|---|
| 740 | return resource->wnd_text_color;
|
|---|
| 741 | }
|
|---|
| 742 |
|
|---|
| 743 | /** @}
|
|---|
| 744 | */
|
|---|