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