1 #if ! defined(PROG_DISABLE_GUI)
2 
3 #include "declarations.h"
4 #include "gui.h"
5 
6 
7 
8 /**
9  * @brief Draw single pixel.
10  *
11  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
12  * place when drawing request pipeline is flushed somewhere in near future.
13  *
14  * @param[in] h Window handle to draw, returned by gui_window_open()
15  * @param[in] p Pixel coordinates in pixels and pixel color
16  *
17  */
18 
19 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_pixel(unsigned int h,struct point_2 * p)20 void gui_draw_pixel(unsigned int h, struct point_2 *p) {
21 	struct w_cmd c;
22 
23 	c.c = WINDOW_COMMAND_DRAW_PIXEL;
24 	c.e = IS_NO;
25 	c.h = h;
26 	c.p = (void *) p;
27 	c.t = sizeof(struct point_2);
28 
29 	(void) window_cmd_push(&c);
30 }
31 #endif
32 
33 /**
34  * @brief Draw single pixel with alpha channel.
35  *
36  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
37  * place when drawing request pipeline is flushed somewhere in near future.
38  *
39  * @param[in] h Window handle to draw, returned by gui_window_open()
40  * @param[in] p Pixel coordinates in pixels, pixel color and alpha value
41  *
42  */
43 
44 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_pixel_alpha(unsigned int h,struct point_2 * p)45 void gui_draw_pixel_alpha(unsigned int h, struct point_2 *p) {
46 	struct w_cmd c;
47 
48 	c.c = WINDOW_COMMAND_DRAW_PIXEL_ALPHA;
49 	c.e = IS_NO;
50 	c.h = h;
51 	c.p = (void *) p;
52 	c.t = sizeof(struct point_2);
53 
54 	(void) window_cmd_push(&c);
55 }
56 #endif
57 
58 /**
59  * @brief Draw array of pixels.
60  *
61  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
62  * place when drawing request pipeline is flushed somewhere in near future.
63  *
64  * @param[in] h Window handle to draw, returned by gui_window_open()
65  * @param[in] p Pixel count, each pixel coordinates in pixels and pixel color
66  *
67  */
68 
69 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_pixels(unsigned int h,struct points_2 * p)70 void gui_draw_pixels(unsigned int h, struct points_2 *p) {
71 	struct w_cmd c;
72 
73 	c.c = WINDOW_COMMAND_DRAW_PIXELS;
74 	c.e = IS_NO;
75 	c.h = h;
76 	c.p = (void *) p;
77 	c.t = sizeof(struct points_2);
78 
79 	(void) window_cmd_push(&c);
80 }
81 #endif
82 
83 /**
84  * @brief Draw array of pixels with alpha channel.
85  *
86  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
87  * place when drawing request pipeline is flushed somewhere in near future.
88  *
89  * @param[in] h Window handle to draw, returned by gui_window_open()
90  * @param[in] p Pixel count, each pixel coordinates in pixels, pixel color and alpha value
91  *
92  */
93 
94 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_pixels_alpha(unsigned int h,struct points_2 * p)95 void gui_draw_pixels_alpha(unsigned int h, struct points_2 *p) {
96 	struct w_cmd c;
97 
98 	c.c = WINDOW_COMMAND_DRAW_PIXELS_ALPHA;
99 	c.e = IS_NO;
100 	c.h = h;
101 	c.p = (void *) p;
102 	c.t = sizeof(struct points_2);
103 
104 	(void) window_cmd_push(&c);
105 }
106 #endif
107 
108 /**
109  * @brief Draw single subpixel.
110  *
111  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
112  * place when drawing request pipeline is flushed somewhere in near future.
113  *
114  * @param[in] h Window handle to draw, returned by gui_window_open()
115  * @param[in] p Subpixel coordinates in subpixels and subpixel color
116  *
117  */
118 
119 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_subpixel(unsigned int h,struct subpoint_2 * p)120 void gui_draw_subpixel(unsigned int h, struct subpoint_2 *p) {
121 	struct w_cmd c;
122 
123 	c.c = WINDOW_COMMAND_DRAW_SUBPIXEL;
124 	c.e = IS_NO;
125 	c.h = h;
126 	c.p = (void *) p;
127 	c.t = sizeof(struct subpoint_2);
128 
129 	(void) window_cmd_push(&c);
130 }
131 #endif
132 
133 /**
134  * @brief Draw single subpixel with alpha channel.
135  *
136  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
137  * place when drawing request pipeline is flushed somewhere in near future.
138  *
139  * @param[in] h Window handle to draw, returned by gui_window_open()
140  * @param[in] p Subpixel coordinates in subpixels, subpixel color and alpha value
141  *
142  */
143 
144 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_subpixel_alpha(unsigned int h,struct subpoint_2 * p)145 void gui_draw_subpixel_alpha(unsigned int h, struct subpoint_2 *p) {
146 	struct w_cmd c;
147 
148 	c.c = WINDOW_COMMAND_DRAW_SUBPIXEL_ALPHA;
149 	c.e = IS_NO;
150 	c.h = h;
151 	c.p = (void *) p;
152 	c.t = sizeof(struct subpoint_2);
153 
154 	(void) window_cmd_push(&c);
155 }
156 #endif
157 
158 /**
159  * @brief Draw array of subpixels.
160  *
161  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
162  * place when drawing request pipeline is flushed somewhere in near future.
163  *
164  * @param[in] h Window handle to draw, returned by gui_window_open()
165  * @param[in] p Subpixel count, each subpixel coordinates in subpixels and subpixel color
166  *
167  */
168 
169 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_subpixels(unsigned int h,struct subpoints_2 * p)170 void gui_draw_subpixels(unsigned int h, struct subpoints_2 *p) {
171 	struct w_cmd c;
172 
173 	c.c = WINDOW_COMMAND_DRAW_SUBPIXELS;
174 	c.e = IS_NO;
175 	c.h = h;
176 	c.p = (void *) p;
177 	c.t = sizeof(struct subpoints_2);
178 
179 	(void) window_cmd_push(&c);
180 }
181 #endif
182 
183 /**
184  * @brief Draw array of subpixels with alpha channel.
185  *
186  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
187  * place when drawing request pipeline is flushed somewhere in near future.
188  *
189  * @param[in] h Window handle to draw, returned by gui_window_open()
190  * @param[in] p Subpixel count, each subpixel coordinates in subpixels, subpixel color and alpha value
191  *
192  */
193 
194 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_subpixels_alpha(unsigned int h,struct subpoints_2 * p)195 void gui_draw_subpixels_alpha(unsigned int h, struct subpoints_2 *p) {
196 	struct w_cmd c;
197 
198 	c.c = WINDOW_COMMAND_DRAW_SUBPIXELS_ALPHA;
199 	c.e = IS_NO;
200 	c.h = h;
201 	c.p = (void *) p;
202 	c.t = sizeof(struct subpoints_2);
203 
204 	(void) window_cmd_push(&c);
205 }
206 #endif
207 
208 /**
209  * @brief Draw single line.
210  *
211  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
212  * place when drawing request pipeline is flushed somewhere in near future.
213  *
214  * @param[in] h Window handle to draw, returned by gui_window_open()
215  * @param[in] p Line coordinates in pixels and line color
216  *
217  */
218 
219 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_line(unsigned int h,struct point_4 * p)220 void gui_draw_line(unsigned int h, struct point_4 *p) {
221 	struct w_cmd c;
222 
223 	c.c = WINDOW_COMMAND_DRAW_LINE;
224 	c.e = IS_NO;
225 	c.h = h;
226 	c.p = (void *) p;
227 	c.t = sizeof(struct point_4);
228 
229 	(void) window_cmd_push(&c);
230 }
231 #endif
232 
233 /**
234  * @brief Draw single line with anti-aliasing.
235  *
236  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
237  * place when drawing request pipeline is flushed somewhere in near future.
238  *
239  * @param[in] h Window handle to draw, returned by gui_window_open()
240  * @param[in] p Line coordinates in pixels and line color
241  *
242  */
243 
244 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_line_aa(unsigned int h,struct point_4 * p)245 void gui_draw_line_aa(unsigned int h, struct point_4 *p) {
246 	struct w_cmd c;
247 
248 	c.c = WINDOW_COMMAND_DRAW_LINE_AA;
249 	c.e = IS_NO;
250 	c.h = h;
251 	c.p = (void *) p;
252 	c.t = sizeof(struct point_4);
253 
254 	(void) window_cmd_push(&c);
255 }
256 #endif
257 
258 /**
259  * @brief Draw single line with alpha channel.
260  *
261  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
262  * place when drawing request pipeline is flushed somewhere in near future.
263  *
264  * @param[in] h Window handle to draw, returned by gui_window_open()
265  * @param[in] p Line coordinates in pixels and line color
266  *
267  */
268 
269 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_line_alpha(unsigned int h,struct point_4 * p)270 void gui_draw_line_alpha(unsigned int h, struct point_4 *p) {
271 	struct w_cmd c;
272 
273 	c.c = WINDOW_COMMAND_DRAW_LINE_ALPHA;
274 	c.e = IS_NO;
275 	c.h = h;
276 	c.p = (void *) p;
277 	c.t = sizeof(struct point_4);
278 
279 	(void) window_cmd_push(&c);
280 }
281 #endif
282 
283 /**
284  * @brief Draw array of lines.
285  *
286  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
287  * place when drawing request pipeline is flushed somewhere in near future.
288  *
289  * @param[in] h Window handle to draw, returned by gui_window_open()
290  * @param[in] p Line count, each line coordinates in pixels and line color
291  *
292  */
293 
294 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_lines(unsigned int h,struct points_4 * p)295 void gui_draw_lines(unsigned int h, struct points_4 *p) {
296 	struct w_cmd c;
297 
298 	c.c = WINDOW_COMMAND_DRAW_LINES;
299 	c.e = IS_NO;
300 	c.h = h;
301 	c.p = (void *) p;
302 	c.t = sizeof(struct points_4);
303 
304 	(void) window_cmd_push(&c);
305 }
306 #endif
307 
308 /**
309  * @brief Draw array of lines with anti-aliasing.
310  *
311  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
312  * place when drawing request pipeline is flushed somewhere in near future.
313  *
314  * @param[in] h Window handle to draw, returned by gui_window_open()
315  * @param[in] p Line count, each line coordinates in pixels and line color
316  *
317  */
318 
gui_draw_lines_aa(unsigned int h,struct points_4 * p)319 void gui_draw_lines_aa(unsigned int h, struct points_4 *p) {
320 	struct w_cmd c;
321 
322 	c.c = WINDOW_COMMAND_DRAW_LINES_AA;
323 	c.e = IS_NO;
324 	c.h = h;
325 	c.p = (void *) p;
326 	c.t = sizeof(struct points_4);
327 
328 	(void) window_cmd_push(&c);
329 }
330 
331 /**
332  * @brief Draw array of lines with alpha channel.
333  *
334  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
335  * place when drawing request pipeline is flushed somewhere in near future.
336  *
337  * @param[in] h Window handle to draw, returned by gui_window_open()
338  * @param[in] p Line count, each line coordinates in pixels and line color
339  *
340  */
341 
342 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_lines_alpha(unsigned int h,struct points_4 * p)343 void gui_draw_lines_alpha(unsigned int h, struct points_4 *p) {
344 	struct w_cmd c;
345 
346 	c.c = WINDOW_COMMAND_DRAW_LINES_ALPHA;
347 	c.e = IS_NO;
348 	c.h = h;
349 	c.p = (void *) p;
350 	c.t = sizeof(struct points_4);
351 
352 	(void) window_cmd_push(&c);
353 }
354 #endif
355 
356 /**
357  * @brief Draw single circle.
358  *
359  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
360  * place when drawing request pipeline is flushed somewhere in near future.
361  *
362  * @param[in] h Window handle to draw, returned by gui_window_open()
363  * @param[in] p Circle coordinates in pixels and circle color
364  *
365  */
366 
367 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circle(unsigned int h,struct circle_2 * p)368 void gui_draw_circle(unsigned int h, struct circle_2 *p) {
369 	struct w_cmd c;
370 
371 	c.c = WINDOW_COMMAND_DRAW_CIRCLE;
372 	c.e = IS_NO;
373 	c.h = h;
374 	c.p = (void *) p;
375 	c.t = sizeof(struct circle_2);
376 
377 	(void) window_cmd_push(&c);
378 }
379 #endif
380 
381 /**
382  * @brief Draw single circle with anti-aliasing.
383  *
384  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
385  * place when drawing request pipeline is flushed somewhere in near future.
386  *
387  * @param[in] h Window handle to draw, returned by gui_window_open()
388  * @param[in] p Circle coordinates in pixels and circle color
389  *
390  */
391 
392 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circle_aa(unsigned int h,struct circle_2 * p)393 void gui_draw_circle_aa(unsigned int h, struct circle_2 *p) {
394 	struct w_cmd c;
395 
396 	c.c = WINDOW_COMMAND_DRAW_CIRCLE_AA;
397 	c.e = IS_NO;
398 	c.h = h;
399 	c.p = (void *) p;
400 	c.t = sizeof(struct circle_2);
401 
402 	(void) window_cmd_push(&c);
403 }
404 #endif
405 
406 /**
407  * @brief Draw single circle with alpha channel.
408  *
409  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
410  * place when drawing request pipeline is flushed somewhere in near future.
411  *
412  * @param[in] h Window handle to draw, returned by gui_window_open()
413  * @param[in] p Circle coordinates in pixels and circle color
414  *
415  */
416 
417 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circle_alpha(unsigned int h,struct circle_2 * p)418 void gui_draw_circle_alpha(unsigned int h, struct circle_2 *p) {
419 	struct w_cmd c;
420 
421 	c.c = WINDOW_COMMAND_DRAW_CIRCLE_ALPHA;
422 	c.e = IS_NO;
423 	c.h = h;
424 	c.p = (void *) p;
425 	c.t = sizeof(struct circle_2);
426 
427 	(void) window_cmd_push(&c);
428 }
429 #endif
430 
431 /**
432  * @brief Draw array of circles.
433  *
434  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
435  * place when drawing request pipeline is flushed somewhere in near future.
436  *
437  * @param[in] h Window handle to draw, returned by gui_window_open()
438  * @param[in] p Circle count, each circle coordinates in pixels and circle color
439  *
440  */
441 
442 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circles(unsigned int h,struct circles_2 * p)443 void gui_draw_circles(unsigned int h, struct circles_2 *p) {
444 	struct w_cmd c;
445 
446 	c.c = WINDOW_COMMAND_DRAW_CIRCLES;
447 	c.e = IS_NO;
448 	c.h = h;
449 	c.p = (void *) p;
450 	c.t = sizeof(struct circles_2);
451 
452 	(void) window_cmd_push(&c);
453 }
454 #endif
455 
456 /**
457  * @brief Draw array of circles with anti-aliasing.
458  *
459  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
460  * place when drawing request pipeline is flushed somewhere in near future.
461  *
462  * @param[in] h Window handle to draw, returned by gui_window_open()
463  * @param[in] p Circle count, each circle coordinates in pixels and circle color
464  *
465  */
466 
467 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circles_aa(unsigned int h,struct circles_2 * p)468 void gui_draw_circles_aa(unsigned int h, struct circles_2 *p) {
469 	struct w_cmd c;
470 
471 	c.c = WINDOW_COMMAND_DRAW_CIRCLES_AA;
472 	c.e = IS_NO;
473 	c.h = h;
474 	c.p = (void *) p;
475 	c.t = sizeof(struct circles_2);
476 
477 	(void) window_cmd_push(&c);
478 }
479 #endif
480 
481 /**
482  * @brief Draw array of circles with alpha channel.
483  *
484  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
485  * place when drawing request pipeline is flushed somewhere in near future.
486  *
487  * @param[in] h Window handle to draw, returned by gui_window_open()
488  * @param[in] p Circle count, each circle coordinates in pixels and circle color
489  *
490  */
491 
492 #if ! defined(PROG_DISABLE_DRAW)
gui_draw_circles_alpha(unsigned int h,struct circles_2 * p)493 void gui_draw_circles_alpha(unsigned int h, struct circles_2 *p) {
494 	struct w_cmd c;
495 
496 	c.c = WINDOW_COMMAND_DRAW_CIRCLES_ALPHA;
497 	c.e = IS_NO;
498 	c.h = h;
499 	c.p = (void *) p;
500 	c.t = sizeof(struct circles_2);
501 
502 	(void) window_cmd_push(&c);
503 }
504 #endif
505 
506 /**
507  * @brief Draw text.
508  *
509  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
510  * place when drawing request pipeline is flushed somewhere in near future.
511  *
512  * @param[in] h Window handle to draw, returned by gui_window_open()
513  * @param[in] p Text coordinates in pixels and font handle returned by fonts_open()
514  *
515  */
516 
gui_draw_text(unsigned int h,struct text_2 * p)517 void gui_draw_text(unsigned int h, struct text_2 *p) {
518 	struct w_cmd c;
519 
520 	c.c = WINDOW_COMMAND_DRAW_TEXT;
521 	c.e = IS_NO;
522 	c.h = h;
523 	c.p = (void *) p;
524 	c.t = sizeof(struct text_2);
525 
526 	(void) window_cmd_push(&c);
527 }
528 
529 /**
530  * @brief Draw array of texts.
531  *
532  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
533  * place when drawing request pipeline is flushed somewhere in near future.
534  *
535  * @param[in] h Window handle to draw, returned by gui_window_open()
536  * @param[in] p Text count, each text coordinates in pixels and font handle returned by fonts_open()
537  *
538  */
539 
gui_draw_texts(unsigned int h,struct texts_2 * p)540 void gui_draw_texts(unsigned int h, struct texts_2 *p) {
541 	struct w_cmd c;
542 
543 	c.c = WINDOW_COMMAND_DRAW_TEXTS;
544 	c.e = IS_NO;
545 	c.h = h;
546 	c.p = (void *) p;
547 	c.t = sizeof(struct texts_2);
548 
549 	(void) window_cmd_push(&c);
550 }
551 
552 /**
553  * @brief Set (fill) content of region.
554  *
555  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
556  * place when drawing request pipeline is flushed somewhere in near future.
557  *
558  * @param[in] h Window handle to set, returned by gui_window_open()
559  * @param[in] p Fill region coordinates in pixels and region color
560  *
561  */
562 
gui_draw_set(unsigned int h,struct point_4 * p)563 void gui_draw_set(unsigned int h, struct point_4 *p) {
564 	struct w_cmd c;
565 
566 	c.c = WINDOW_COMMAND_DRAW_SET;
567 	c.e = IS_NO;
568 	c.h = h;
569 	c.p = (void *) p;
570 	c.t = sizeof(struct point_4);
571 
572 	(void) window_cmd_push(&c);
573 }
574 
575 /**
576  * @brief Set (fill) content of region with alpha channel.
577  *
578  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
579  * place when drawing request pipeline is flushed somewhere in near future.
580  *
581  * @param[in] h Window handle to set, returned by gui_window_open()
582  * @param[in] p Fill region coordinates in pixels, region color and alpha value
583  *
584  */
585 
gui_draw_set_alpha(unsigned int h,struct point_4 * p)586 void gui_draw_set_alpha(unsigned int h, struct point_4 *p) {
587 	struct w_cmd c;
588 
589 	c.c = WINDOW_COMMAND_DRAW_SET_ALPHA;
590 	c.e = IS_NO;
591 	c.h = h;
592 	c.p = (void *) p;
593 	c.t = sizeof(struct point_4);
594 
595 	(void) window_cmd_push(&c);
596 }
597 
598 /**
599  * @brief Draw rectangular border.
600  *
601  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
602  * place when drawing request pipeline is flushed somewhere in near future.
603  *
604  * @param[in] h Window handle to draw, returned by gui_window_open()
605  * @param[in] p Border coordinates in pixels, border color and border thickness in pixels
606  *
607  */
608 
gui_draw_border(unsigned int h,struct border_4 * p)609 void gui_draw_border(unsigned int h, struct border_4 *p) {
610 	struct w_cmd c;
611 
612 	c.c = WINDOW_COMMAND_DRAW_BORDER;
613 	c.e = IS_NO;
614 	c.h = h;
615 	c.p = (void *) p;
616 	c.t = sizeof(struct border_4);
617 
618 	(void) window_cmd_push(&c);
619 }
620 
621 /**
622  * @brief Draw rectangular border with alpha channel.
623  *
624  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
625  * place when drawing request pipeline is flushed somewhere in near future.
626  *
627  * @param[in] h Window handle to draw, returned by gui_window_open()
628  * @param[in] p Border coordinates in pixels, border color, alpha value and border thickness in pixels
629  *
630  */
631 
gui_draw_border_alpha(unsigned int h,struct border_4 * p)632 void gui_draw_border_alpha(unsigned int h, struct border_4 *p) {
633 	struct w_cmd c;
634 
635 	c.c = WINDOW_COMMAND_DRAW_BORDER_ALPHA;
636 	c.e = IS_NO;
637 	c.h = h;
638 	c.p = (void *) p;
639 	c.t = sizeof(struct border_4);
640 
641 	(void) window_cmd_push(&c);
642 }
643 
644 /**
645  * @brief Copy region.
646  *
647  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
648  * place when drawing request pipeline is flushed somewhere in near future.
649  *
650  * @param[in] h Window handle where to copy, returned by gui_window_open()
651  * @param[in] p Region source buffer, coordinates and region size in pixels
652  *
653  */
654 
gui_draw_copy(unsigned int h,struct region_copy_8 * p)655 void gui_draw_copy(unsigned int h, struct region_copy_8 *p) {
656 	struct w_cmd c;
657 
658 	c.c = WINDOW_COMMAND_DRAW_COPY;
659 	c.e = IS_NO;
660 	c.h = h;
661 	c.p = (void *) p;
662 	c.t = sizeof(struct region_copy_8);
663 
664 	(void) window_cmd_push(&c);
665 }
666 
667 /**
668  * @brief Copy region with alpha channel.
669  *
670  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
671  * place when drawing request pipeline is flushed somewhere in near future.
672  *
673  * @param[in] h Window handle where to copy, returned by gui_window_open()
674  * @param[in] p Region source buffer, coordinates and region size in pixels and region alpha value
675  *
676  */
677 
gui_draw_copy_alpha(unsigned int h,struct region_copy_8 * p)678 void gui_draw_copy_alpha(unsigned int h, struct region_copy_8 *p) {
679 	struct w_cmd c;
680 
681 	c.c = WINDOW_COMMAND_DRAW_COPY_ALPHA;
682 	c.e = IS_NO;
683 	c.h = h;
684 	c.p = (void *) p;
685 	c.t = sizeof(struct region_copy_8);
686 
687 	(void) window_cmd_push(&c);
688 }
689 
690 /**
691  * @brief Wipe (set to zero) active window area.
692  *
693  * Unlike draw_*() functions, this function returns immediately and drawing operation actually takes
694  * place when drawing request pipeline is flushed somewhere in near future.
695  *
696  * @param[in] h Window handle to wipe, returned by gui_window_open()
697  *
698  */
699 
gui_draw_wipe(unsigned int h)700 void gui_draw_wipe(unsigned int h) {
701 	struct w_cmd c;
702 
703 	c.c = WINDOW_COMMAND_DRAW_WIPE;
704 	c.e = IS_NO;
705 	c.h = h;
706 	c.p = NULL;
707 	c.t = 0;
708 
709 	(void) window_cmd_push(&c);
710 }
711 
712 /**
713  * @brief Open new window.
714  *
715  * cb_open_notify() is called when window is opened. New window handle is passed as a parameter to this
716  * callback function, and callback should store it for later use. If opening the window fails, callback
717  * function gets zero as a parameter, values other than zero indicates succesfully opened window.
718  * gui_window_close() should be called when window is no longer needed. Call gui_window_map() to map the
719  * window on screen.
720  *
721  * This function returns immediately and window opening actually takes place when drawing request
722  * pipeline is flushed somewhere in near future.
723  *
724  * @param[in] w Window info structure
725  *
726  */
727 
gui_window_open(struct w_ctx * w)728 void gui_window_open(struct w_ctx *w) {
729 	struct w_cmd c;
730 	struct w_ctx *p;
731 
732 	APP_MALLOC_RET_VOID(p, sizeof(struct w_ctx));
733 
734 	/* Set window title and title charset */
735 	if(w->s == NULL) p->s = NULL;
736 	else {
737 		if((p->s = gui_window_open_op(w->s)) == NULL) {
738 			(void) free(p);
739 
740 			return;
741 		}
742 	}
743 
744 	if(w->c == NULL) p->c = NULL;
745 	else {
746 		if((p->c = gui_window_open_op(w->c)) == NULL) {
747 			(void) free(p->s);
748 			(void) free(p);
749 
750 			return;
751 		}
752 	}
753 
754 	/* Set window variables */
755 	p->r = w->r;
756 	p->p = w->p;
757 	p->e = w->e;
758 	p->m = w->m;
759 
760 	p->x = w->x;
761 	p->y = w->y;
762 
763 	p->w = w->w;
764 	p->h = w->h;
765 
766 	/* Set window callback functions and their parameters */
767 	p->cb_main_loop = w->cb_main_loop;
768 
769 	p->cb_expose = w->cb_expose;
770 
771 	p->cb_key_press = w->cb_key_press;
772 	p->cb_key_release = w->cb_key_release;
773 	p->cb_button_press = w->cb_button_press;
774 	p->cb_button_release = w->cb_button_release;
775 
776 	p->cb_client_message = w->cb_client_message;
777 
778 	p->cb_configure_notify = w->cb_configure_notify;
779 	p->cb_destroy_notify = w->cb_destroy_notify;
780 	p->cb_motion_notify = w->cb_motion_notify;
781 	p->cb_map_notify = w->cb_map_notify;
782 	p->cb_unmap_notify = w->cb_unmap_notify;
783 
784 	p->cb_open_notify = w->cb_open_notify;
785 
786 	/* window_close() frees allocated stuff */
787 	p->par_main_loop.s = gui_window_open_op(w->par_main_loop.s);
788 	p->par_main_loop.n = w->par_main_loop.n;
789 
790 	p->par_expose.s = gui_window_open_op(w->par_expose.s);
791 	p->par_expose.n = w->par_expose.n;
792 
793 	p->par_key_press.s = gui_window_open_op(w->par_key_press.s);
794 	p->par_key_press.n = w->par_key_press.n;
795 	p->par_key_release.s = gui_window_open_op(w->par_key_release.s);
796 	p->par_key_release.n = w->par_key_release.n;
797 	p->par_button_press.s = gui_window_open_op(w->par_button_press.s);
798 	p->par_button_press.n = w->par_button_press.n;
799 	p->par_button_release.s = gui_window_open_op(w->par_button_release.s);
800 	p->par_button_release.n = w->par_button_release.n;
801 
802 	p->par_client_message.s = gui_window_open_op(w->par_client_message.s);
803 	p->par_client_message.n = w->par_client_message.n;
804 
805 	p->par_configure_notify.s = gui_window_open_op(w->par_configure_notify.s);
806 	p->par_configure_notify.n = w->par_configure_notify.n;
807 	p->par_destroy_notify.s = gui_window_open_op(w->par_destroy_notify.s);
808 	p->par_destroy_notify.n = w->par_destroy_notify.n;
809 	p->par_motion_notify.s = gui_window_open_op(w->par_motion_notify.s);
810 	p->par_motion_notify.n = w->par_motion_notify.n;
811 	p->par_map_notify.s = gui_window_open_op(w->par_map_notify.s);
812 	p->par_map_notify.n = w->par_map_notify.n;
813 	p->par_unmap_notify.s = gui_window_open_op(w->par_unmap_notify.s);
814 	p->par_unmap_notify.n = w->par_unmap_notify.n;
815 
816 	p->par_open_notify.s = gui_window_open_op(w->par_open_notify.s);
817 	p->par_open_notify.n = w->par_open_notify.n;
818 
819 	c.c = WINDOW_COMMAND_WINDOW_OPEN;
820 	c.e = IS_NO;
821 	c.h = 0;
822 	c.p = (void *) p;
823 	c.t = sizeof(struct w_ctx);
824 
825 	if(window_cmd_push(&c) != 0) {
826 		if(p->s != NULL) (void) free(p->s);
827 		if(p->c != NULL) (void) free(p->c);
828 
829 		if(p->par_main_loop.s != NULL) (void) free(p->par_main_loop.s);
830 
831 		if(p->par_expose.s != NULL) (void) free(p->par_expose.s);
832 
833 		if(p->par_key_press.s != NULL) (void) free(p->par_key_press.s);
834 		if(p->par_key_release.s != NULL) (void) free(p->par_key_release.s);
835 		if(p->par_button_press.s != NULL) (void) free(p->par_button_press.s);
836 		if(p->par_button_release.s != NULL) (void) free(p->par_button_release.s);
837 
838 		if(p->par_client_message.s != NULL) (void) free(p->par_client_message.s);
839 
840 		if(p->par_configure_notify.s != NULL) (void) free(p->par_configure_notify.s);
841 		if(p->par_destroy_notify.s != NULL) (void) free(p->par_destroy_notify.s);
842 		if(p->par_motion_notify.s != NULL) (void) free(p->par_motion_notify.s);
843 		if(p->par_map_notify.s != NULL) (void) free(p->par_map_notify.s);
844 		if(p->par_unmap_notify.s != NULL) (void) free(p->par_unmap_notify.s);
845 
846 		if(p->par_open_notify.s != NULL) (void) free(p->par_open_notify.s);
847 	}
848 
849 	(void) free(p);
850 }
851 
gui_window_open_op(char * s)852 static char *gui_window_open_op(char *s) {
853 	char *p;
854 
855 	size_t t;
856 
857 	if(s == NULL) return(NULL);
858 
859 	t = str_len(s, STRING_ASCII);
860 
861 	APP_MALLOC_RET_VALUE(p, t + sizeof(char), NULL);
862 
863 	(void) memcpy((void *) p, (const void *) s, t);
864 
865 	p[t] = 0;
866 
867 	return(p);
868 }
869 
870 /**
871  * @brief Set window icon.
872  *
873  * Set icon image for window to be displayed on desktop when window is iconified.
874  *
875  * This function returns immediately and icon creation actually takes place when drawing request
876  * pipeline is flushed somewhere in near future.
877  *
878  * @param[in] h Window handle to set icon, returned by gui_window_open()
879  * @param[in] s Icon file name
880  *
881  */
882 
gui_window_icon(unsigned int h,char * s)883 void gui_window_icon(unsigned int h, char *s) {
884 	struct w_cmd c;
885 
886 	/* Add one extra char to string length for terminating null byte */
887 	c.c = WINDOW_COMMAND_WINDOW_ICON;
888 	c.e = IS_NO;
889 	c.h = h;
890 	c.p = (void *) s;
891 	c.t = str_len(s, STRING_ASCII) + sizeof(char);
892 
893 	(void) window_cmd_push(&c);
894 }
895 
896 /**
897  * @brief Close window.
898  *
899  * Close previously opended window and free all its internal resources. After command completes,
900  * window is gone for good and handle should not be used anymore.
901  *
902  * This function returns immediately and window closing actually takes place when drawing request
903  * pipeline is flushed somewhere in near future.
904  *
905  * @param[in] h Window handle to close, returned by gui_window_open()
906  *
907  */
908 
gui_window_close(unsigned int h)909 void gui_window_close(unsigned int h) {
910 	struct w_cmd c;
911 
912 	c.c = WINDOW_COMMAND_WINDOW_CLOSE;
913 	c.e = IS_NO;
914 	c.h = h;
915 	c.p = NULL;
916 	c.t = 0;
917 
918 	(void) window_cmd_push(&c);
919 }
920 
921 /**
922  * @brief Map (show) window.
923  *
924  * Display opened window.
925  *
926  * This function returns immediately and window mapping actually takes place when drawing request
927  * pipeline is flushed somewhere in near future.
928  *
929  * @param[in] h Window handle to map, returned by gui_window_open()
930  *
931  */
932 
gui_window_map(unsigned int h)933 void gui_window_map(unsigned int h) {
934 	struct w_cmd c;
935 
936 	c.c = WINDOW_COMMAND_WINDOW_MAP;
937 	c.e = IS_NO;
938 	c.h = h;
939 	c.p = NULL;
940 	c.t = 0;
941 
942 	(void) window_cmd_push(&c);
943 }
944 
945 /**
946  * @brief Unmap (hide) window.
947  *
948  * Hide already mapped window.
949  *
950  * This function returns immediately and window unmapping actually takes place when drawing request
951  * pipeline is flushed somewhere in near future.
952  *
953  * @param[in] h Window handle to unmap, returned by gui_window_open()
954  *
955  */
956 
gui_window_unmap(unsigned int h)957 void gui_window_unmap(unsigned int h) {
958 	struct w_cmd c;
959 
960 	c.c = WINDOW_COMMAND_WINDOW_UNMAP;
961 	c.e = IS_NO;
962 	c.h = h;
963 	c.p = NULL;
964 	c.t = 0;
965 
966 	(void) window_cmd_push(&c);
967 }
968 
969 /**
970  * @brief Set window attributes.
971  *
972  * Set window internal attributes.
973  *
974  * This function returns immediately and setting attributes actually takes place when drawing request
975  * pipeline is flushed somewhere in near future.
976  *
977  * @param[in] h Window handle to set, returned by gui_window_open()
978  * @param[in] w Window attribute structure
979  *
980  */
981 
gui_window_set_attrs(unsigned int h,struct w_att * w)982 void gui_window_set_attrs(unsigned int h, struct w_att *w) {
983 	struct w_cmd c;
984 
985 	c.c = WINDOW_COMMAND_WINDOW_SET_ATTRS;
986 	c.e = IS_NO;
987 	c.h = h;
988 	c.p = (void *) w;
989 	c.t = sizeof(struct w_att);
990 
991 	(void) window_cmd_push(&c);
992 }
993 
994 /**
995  * @brief Refresh window.
996  *
997  * Refresh (redraw) previously opened window.
998  *
999  * This function returns immediately and window closing actually takes place when drawing request
1000  * pipeline is flushed somewhere in near future.
1001  *
1002  * @param[in] h Window handle to refresh, returned by gui_window_open()
1003  * @param[in] w Window area to be refreshed
1004  *
1005  */
1006 
gui_window_refresh(unsigned int h,struct clip_2 * w)1007 void gui_window_refresh(unsigned int h, struct clip_2 *w) {
1008 	struct w_cmd c;
1009 
1010 	c.c = WINDOW_COMMAND_WINDOW_REFRESH;
1011 	c.e = IS_NO;
1012 	c.h = h;
1013 	c.p = (void *) w;
1014 	c.t = sizeof(struct clip_2);
1015 
1016 	(void) window_cmd_push(&c);
1017 }
1018 #endif
1019