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