1 | /*
|
---|
2 | * Copyright (c) 2021 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_sel_text_color = NULL;
|
---|
70 | gfx_color_t *wnd_sel_text_bg_color = NULL;
|
---|
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;
|
---|
79 | gfx_color_t *entry_fg_color = NULL;
|
---|
80 | gfx_color_t *entry_bg_color = NULL;
|
---|
81 | gfx_color_t *entry_act_bg_color = NULL;
|
---|
82 | errno_t rc;
|
---|
83 |
|
---|
84 | resource = calloc(1, sizeof(ui_resource_t));
|
---|
85 | if (resource == NULL)
|
---|
86 | return ENOMEM;
|
---|
87 |
|
---|
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;
|
---|
96 | }
|
---|
97 |
|
---|
98 | rc = gfx_font_open(finfo, &font);
|
---|
99 | if (rc != EOK)
|
---|
100 | goto error;
|
---|
101 |
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
140 | rc = gfx_color_new_rgb_i16(0x8888, 0x8888, 0x8888, &wnd_frame_hi_color);
|
---|
141 | if (rc != EOK)
|
---|
142 | goto error;
|
---|
143 |
|
---|
144 | rc = gfx_color_new_rgb_i16(0x4444, 0x4444, 0x4444, &wnd_frame_sh_color);
|
---|
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 |
|
---|
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 |
|
---|
184 | rc = gfx_color_new_rgb_i16(0xc8c8, 0xc8c8, 0xc8c8, &entry_act_bg_color);
|
---|
185 | if (rc != EOK)
|
---|
186 | goto error;
|
---|
187 |
|
---|
188 | resource->gc = gc;
|
---|
189 | resource->tface = tface;
|
---|
190 | resource->font = font;
|
---|
191 | resource->textmode = false;
|
---|
192 |
|
---|
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;
|
---|
198 |
|
---|
199 | resource->wnd_face_color = wnd_face_color;
|
---|
200 | resource->wnd_text_color = wnd_text_color;
|
---|
201 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
---|
202 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
---|
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 |
|
---|
213 | resource->entry_fg_color = entry_fg_color;
|
---|
214 | resource->entry_bg_color = entry_bg_color;
|
---|
215 | resource->entry_act_bg_color = entry_act_bg_color;
|
---|
216 |
|
---|
217 | *rresource = resource;
|
---|
218 | return EOK;
|
---|
219 | error:
|
---|
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);
|
---|
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);
|
---|
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);
|
---|
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 |
|
---|
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);
|
---|
261 | if (entry_act_bg_color != NULL)
|
---|
262 | gfx_color_delete(entry_act_bg_color);
|
---|
263 |
|
---|
264 | if (tface != NULL)
|
---|
265 | gfx_typeface_destroy(tface);
|
---|
266 | free(resource);
|
---|
267 | return rc;
|
---|
268 | }
|
---|
269 |
|
---|
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_ega(0x20, &btn_highlight_color);
|
---|
330 | if (rc != EOK)
|
---|
331 | goto error;
|
---|
332 |
|
---|
333 | rc = gfx_color_new_ega(0x01, &btn_shadow_color);
|
---|
334 | if (rc != EOK)
|
---|
335 | goto error;
|
---|
336 |
|
---|
337 | rc = gfx_color_new_ega(0x70, &wnd_face_color);
|
---|
338 | if (rc != EOK)
|
---|
339 | goto error;
|
---|
340 |
|
---|
341 | rc = gfx_color_new_ega(0x70, &wnd_text_color);
|
---|
342 | if (rc != EOK)
|
---|
343 | goto error;
|
---|
344 |
|
---|
345 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_color);
|
---|
346 | if (rc != EOK)
|
---|
347 | goto error;
|
---|
348 |
|
---|
349 | rc = gfx_color_new_ega(0x07, &wnd_sel_text_bg_color);
|
---|
350 | if (rc != EOK)
|
---|
351 | goto error;
|
---|
352 |
|
---|
353 | rc = gfx_color_new_ega(0x70, &wnd_frame_hi_color);
|
---|
354 | if (rc != EOK)
|
---|
355 | goto error;
|
---|
356 |
|
---|
357 | rc = gfx_color_new_ega(0x01, &wnd_frame_sh_color);
|
---|
358 | if (rc != EOK)
|
---|
359 | goto error;
|
---|
360 |
|
---|
361 | rc = gfx_color_new_ega(0x70, &wnd_highlight_color);
|
---|
362 | if (rc != EOK)
|
---|
363 | goto error;
|
---|
364 |
|
---|
365 | rc = gfx_color_new_ega(0x01, &wnd_shadow_color);
|
---|
366 | if (rc != EOK)
|
---|
367 | goto error;
|
---|
368 |
|
---|
369 | rc = gfx_color_new_ega(0x70, &tbar_act_bg_color);
|
---|
370 | if (rc != EOK)
|
---|
371 | goto error;
|
---|
372 |
|
---|
373 | rc = gfx_color_new_ega(0x70, &tbar_act_text_color);
|
---|
374 | if (rc != EOK)
|
---|
375 | goto error;
|
---|
376 |
|
---|
377 | rc = gfx_color_new_ega(0x07, &tbar_inact_bg_color);
|
---|
378 | if (rc != EOK)
|
---|
379 | goto error;
|
---|
380 |
|
---|
381 | rc = gfx_color_new_ega(0x07, &tbar_inact_text_color);
|
---|
382 | if (rc != EOK)
|
---|
383 | goto error;
|
---|
384 |
|
---|
385 | rc = gfx_color_new_ega(0x1b, &entry_fg_color);
|
---|
386 | if (rc != EOK)
|
---|
387 | goto error;
|
---|
388 |
|
---|
389 | rc = gfx_color_new_ega(0x1b, &entry_bg_color);
|
---|
390 | if (rc != EOK)
|
---|
391 | goto error;
|
---|
392 |
|
---|
393 | rc = gfx_color_new_ega(0x37, &entry_act_bg_color);
|
---|
394 | if (rc != EOK)
|
---|
395 | goto error;
|
---|
396 |
|
---|
397 | resource->gc = gc;
|
---|
398 | resource->tface = tface;
|
---|
399 | resource->font = font;
|
---|
400 | resource->textmode = true;
|
---|
401 |
|
---|
402 | resource->btn_frame_color = btn_frame_color;
|
---|
403 | resource->btn_face_color = btn_face_color;
|
---|
404 | resource->btn_text_color = btn_text_color;
|
---|
405 | resource->btn_highlight_color = btn_highlight_color;
|
---|
406 | resource->btn_shadow_color = btn_shadow_color;
|
---|
407 |
|
---|
408 | resource->wnd_face_color = wnd_face_color;
|
---|
409 | resource->wnd_text_color = wnd_text_color;
|
---|
410 | resource->wnd_sel_text_color = wnd_sel_text_color;
|
---|
411 | resource->wnd_sel_text_bg_color = wnd_sel_text_bg_color;
|
---|
412 | resource->wnd_frame_hi_color = wnd_frame_hi_color;
|
---|
413 | resource->wnd_frame_sh_color = wnd_frame_sh_color;
|
---|
414 | resource->wnd_highlight_color = wnd_highlight_color;
|
---|
415 | resource->wnd_shadow_color = wnd_shadow_color;
|
---|
416 |
|
---|
417 | resource->tbar_act_bg_color = tbar_act_bg_color;
|
---|
418 | resource->tbar_act_text_color = tbar_act_text_color;
|
---|
419 | resource->tbar_inact_bg_color = tbar_inact_bg_color;
|
---|
420 | resource->tbar_inact_text_color = tbar_inact_text_color;
|
---|
421 |
|
---|
422 | resource->entry_fg_color = entry_fg_color;
|
---|
423 | resource->entry_bg_color = entry_bg_color;
|
---|
424 | resource->entry_act_bg_color = entry_act_bg_color;
|
---|
425 |
|
---|
426 | *rresource = resource;
|
---|
427 | return EOK;
|
---|
428 | error:
|
---|
429 | if (btn_frame_color != NULL)
|
---|
430 | gfx_color_delete(btn_frame_color);
|
---|
431 | if (btn_face_color != NULL)
|
---|
432 | gfx_color_delete(btn_face_color);
|
---|
433 | if (btn_text_color != NULL)
|
---|
434 | gfx_color_delete(btn_text_color);
|
---|
435 | if (btn_highlight_color != NULL)
|
---|
436 | gfx_color_delete(btn_highlight_color);
|
---|
437 | if (btn_shadow_color != NULL)
|
---|
438 | gfx_color_delete(btn_shadow_color);
|
---|
439 |
|
---|
440 | if (wnd_face_color != NULL)
|
---|
441 | gfx_color_delete(wnd_face_color);
|
---|
442 | if (wnd_text_color != NULL)
|
---|
443 | gfx_color_delete(wnd_text_color);
|
---|
444 | if (wnd_sel_text_color != NULL)
|
---|
445 | gfx_color_delete(wnd_sel_text_color);
|
---|
446 | if (wnd_sel_text_bg_color != NULL)
|
---|
447 | gfx_color_delete(wnd_sel_text_bg_color);
|
---|
448 | if (wnd_frame_hi_color != NULL)
|
---|
449 | gfx_color_delete(wnd_frame_hi_color);
|
---|
450 | if (wnd_frame_sh_color != NULL)
|
---|
451 | gfx_color_delete(wnd_frame_sh_color);
|
---|
452 | if (wnd_highlight_color != NULL)
|
---|
453 | gfx_color_delete(wnd_highlight_color);
|
---|
454 | if (wnd_shadow_color != NULL)
|
---|
455 | gfx_color_delete(wnd_shadow_color);
|
---|
456 |
|
---|
457 | if (tbar_act_bg_color != NULL)
|
---|
458 | gfx_color_delete(tbar_act_bg_color);
|
---|
459 | if (tbar_act_text_color != NULL)
|
---|
460 | gfx_color_delete(tbar_act_text_color);
|
---|
461 | if (tbar_inact_bg_color != NULL)
|
---|
462 | gfx_color_delete(tbar_inact_bg_color);
|
---|
463 | if (tbar_inact_text_color != NULL)
|
---|
464 | gfx_color_delete(tbar_inact_text_color);
|
---|
465 |
|
---|
466 | if (entry_fg_color != NULL)
|
---|
467 | gfx_color_delete(entry_fg_color);
|
---|
468 | if (entry_bg_color != NULL)
|
---|
469 | gfx_color_delete(entry_bg_color);
|
---|
470 | if (entry_act_bg_color != NULL)
|
---|
471 | gfx_color_delete(entry_act_bg_color);
|
---|
472 |
|
---|
473 | if (tface != NULL)
|
---|
474 | gfx_typeface_destroy(tface);
|
---|
475 | free(resource);
|
---|
476 | return rc;
|
---|
477 | }
|
---|
478 |
|
---|
479 | /** Create new UI resource.
|
---|
480 | *
|
---|
481 | * @param gc Graphic context
|
---|
482 | * @param textmode @c true if running in text mode
|
---|
483 | * @param rresource Place to store pointer to new UI resource
|
---|
484 | * @return EOK on success, ENOMEM if out of memory
|
---|
485 | */
|
---|
486 | errno_t ui_resource_create(gfx_context_t *gc, bool textmode,
|
---|
487 | ui_resource_t **rresource)
|
---|
488 | {
|
---|
489 | if (textmode)
|
---|
490 | return ui_resource_create_text(gc, rresource);
|
---|
491 | else
|
---|
492 | return ui_resource_create_gfx(gc, rresource);
|
---|
493 | }
|
---|
494 |
|
---|
495 | /** Destroy UI resource.
|
---|
496 | *
|
---|
497 | * @param resource UI resource or @c NULL
|
---|
498 | */
|
---|
499 | void ui_resource_destroy(ui_resource_t *resource)
|
---|
500 | {
|
---|
501 | if (resource == NULL)
|
---|
502 | return;
|
---|
503 |
|
---|
504 | gfx_color_delete(resource->btn_frame_color);
|
---|
505 | gfx_color_delete(resource->btn_face_color);
|
---|
506 | gfx_color_delete(resource->btn_text_color);
|
---|
507 | gfx_color_delete(resource->btn_highlight_color);
|
---|
508 | gfx_color_delete(resource->btn_shadow_color);
|
---|
509 |
|
---|
510 | gfx_color_delete(resource->wnd_face_color);
|
---|
511 | gfx_color_delete(resource->wnd_text_color);
|
---|
512 | gfx_color_delete(resource->wnd_sel_text_color);
|
---|
513 | gfx_color_delete(resource->wnd_sel_text_bg_color);
|
---|
514 | gfx_color_delete(resource->wnd_frame_hi_color);
|
---|
515 | gfx_color_delete(resource->wnd_frame_sh_color);
|
---|
516 | gfx_color_delete(resource->wnd_highlight_color);
|
---|
517 | gfx_color_delete(resource->wnd_shadow_color);
|
---|
518 |
|
---|
519 | gfx_color_delete(resource->tbar_act_bg_color);
|
---|
520 | gfx_color_delete(resource->tbar_act_text_color);
|
---|
521 | gfx_color_delete(resource->tbar_inact_bg_color);
|
---|
522 | gfx_color_delete(resource->tbar_inact_text_color);
|
---|
523 |
|
---|
524 | gfx_color_delete(resource->entry_fg_color);
|
---|
525 | gfx_color_delete(resource->entry_bg_color);
|
---|
526 | gfx_color_delete(resource->entry_act_bg_color);
|
---|
527 |
|
---|
528 | gfx_font_close(resource->font);
|
---|
529 | gfx_typeface_destroy(resource->tface);
|
---|
530 | free(resource);
|
---|
531 | }
|
---|
532 |
|
---|
533 | /** Set UI resource expose callback.
|
---|
534 | *
|
---|
535 | * @param resource Resource
|
---|
536 | * @param cb Callback
|
---|
537 | * @param arg Callback argument
|
---|
538 | */
|
---|
539 | void ui_resource_set_expose_cb(ui_resource_t *resource,
|
---|
540 | ui_expose_cb_t cb, void *arg)
|
---|
541 | {
|
---|
542 | resource->expose_cb = cb;
|
---|
543 | resource->expose_arg = arg;
|
---|
544 | }
|
---|
545 |
|
---|
546 | /** Force UI repaint after an area has been exposed.
|
---|
547 | *
|
---|
548 | * This is called when a popup disappears, which could have exposed some
|
---|
549 | * other UI elements. It causes complete repaint of the UI.
|
---|
550 | *
|
---|
551 | * NOTE Ideally we could specify the exposed rectangle and then limit
|
---|
552 | * the repaint to just that. That would, however, require means of
|
---|
553 | * actually clipping the repaint operation.
|
---|
554 | */
|
---|
555 | void ui_resource_expose(ui_resource_t *resource)
|
---|
556 | {
|
---|
557 | if (resource->expose_cb != NULL)
|
---|
558 | resource->expose_cb(resource->expose_arg);
|
---|
559 | }
|
---|
560 |
|
---|
561 | /** @}
|
---|
562 | */
|
---|