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