3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <libx/base.h>
26 #include <libx/object.h>
27 #include <libx/image.h>
28 #include <libx/cursor.h>
29 #include <libx/text.h>
34 static char zstr
[128];
37 static appcl_t
*zappcl
;
38 static unsigned short zsizex
;
39 static unsigned short zsizey
;
40 static unsigned zstate
;
41 static zbitmap_t bitmap_button
;
42 static unsigned zitem_sel
;
43 static unsigned zitem_curr
;
45 extern unsigned short image_button
[];
47 appcl_t
*zgui_window ()
52 void zgui_puts (unsigned short x
, unsigned short y
, char *str
, unsigned color
)
61 for (i
= 0; str
[i
]; i
++) {
72 if (zappcl
->sizex
< k
+15) {
78 if (j
< zappcl
->sizey
)
79 xtext_putch (zappcl
->x
+4+x
+k
, zappcl
->y
+21+y
+j
, color
, str
[i
]);
84 //xtext_puts (zappcl->x+4+x, zappcl->y+21+y, color, str);
88 int zgui_cursor (unsigned short *x
, unsigned short *y
)
90 if (!zappcl
|| !x
|| !y
)
93 if (zappcl
->mousex
-4 > zappcl
->sizex
)
95 else if (zappcl
->mousex
-4 < 0)
98 *x
= zappcl
->mousex
-4;
100 if (zappcl
->mousey
-21 > zappcl
->sizey
)
101 *y
= zappcl
->sizey
-1;
102 else if (zappcl
->mousey
-21 < 0)
105 *y
= zappcl
->mousey
-21;
107 return (zappcl
->state
& APPCL_STATE_LBUTTON
) ? 1 : 0;
110 void zgui_input (unsigned short x
, unsigned short y
, char *str
, unsigned len
, unsigned color
)
117 if (x
+4 <= zappcl
->mousex
&& x
+8+((short) len
*6) >= zappcl
->mousex
&&
118 y
+19 <= zappcl
->mousey
&& y
+28 >= zappcl
->mousey
) {
119 if (zappcl
->state
& APPCL_STATE_LBUTTON
) {
120 zappcl
->state
&= ~APPCL_STATE_LBUTTON
;
121 zitem_sel
= zitem_curr
;
125 if (zitem_curr
== zitem_sel
)
127 switch (zappcl
->kbd
) {
131 for (i
= len
-1; i
>= 0; i
--) {
142 for (i
= 0; i
< len
; i
++) {
144 str
[i
] = zappcl
->kbd
;
154 xtext_puts (zappcl
->x
+4+x
, zappcl
->y
+21+y
, color
, str
);
157 void zgui_bitmap (zbitmap_t
*bitmap
)
170 for (i
= bitmap
->posx
+(bitmap
->posy
*bitmap
->resx
); i
< bitmap
->resx
*bitmap
->resy
; i
++) {
171 if (k
>= bitmap
->resx
) {
176 if (k
< bitmap
->sizex
&& j
< bitmap
->sizey
)
177 xpixel ((unsigned) zappcl
->x
+4+bitmap
->x
+k
, (unsigned) zappcl
->y
+21+bitmap
->y
+j
, (unsigned short) bitmap
->data
[i
]);
183 static void draw_bitmapspec (zbitmap_t
*bitmap
)
196 unsigned short w
= bitmap
->data
[299+34];
198 for (i
= bitmap
->posx
+(bitmap
->posy
*13); i
< 13*25; i
++) {
209 if (bitmap
->data
[pix
] != w
)
210 if (k
< bitmap
->sizex
&& j
< bitmap
->sizey
)
211 xpixel ((unsigned) bitmap
->x
+k
, (unsigned) bitmap
->y
+j
, image_button
[pix
]);
217 int zgui_button (unsigned short x
, unsigned short y
, char *str
)
224 if (zitem_curr
!= zitem_sel
)
227 unsigned len
= strlen (str
);
229 /*xrectfill (zappcl->x+4+x, zappcl->y+21+y, zappcl->x+8+x+(len*6), zappcl->y+31+y, ~0);*/
231 bitmap_button
.x
= zappcl
->x
+4+x
;
232 bitmap_button
.y
= zappcl
->y
+21+y
;
233 bitmap_button
.posx
= 0;
234 bitmap_button
.posy
= 0;
235 bitmap_button
.sizex
= 4;
236 bitmap_button
.sizey
= 23;
238 draw_bitmapspec (&bitmap_button
);
241 for (l
= 0; l
< len
; l
++) {
242 bitmap_button
.x
= zappcl
->x
+8+x
+(l
*6);
243 bitmap_button
.y
= zappcl
->y
+21+y
;
244 bitmap_button
.posx
= 4;
245 bitmap_button
.posy
= 0;
246 bitmap_button
.sizex
= 6;
247 bitmap_button
.sizey
= 23;
249 draw_bitmapspec (&bitmap_button
);
252 bitmap_button
.x
= zappcl
->x
+8+x
+(len
*6);
253 bitmap_button
.y
= zappcl
->y
+21+y
;
254 bitmap_button
.posx
= 9;
255 bitmap_button
.posy
= 0;
256 bitmap_button
.sizex
= 4;
257 bitmap_button
.sizey
= 23;
259 draw_bitmapspec (&bitmap_button
);
263 if (x
+4 <= zappcl
->mousex
&& x
+12+((short) len
*6) >= zappcl
->mousex
&&
264 y
+22 <= zappcl
->mousey
&& y
+43 >= zappcl
->mousey
) {
265 if (zappcl
->state
& APPCL_STATE_LBUTTON
) {
266 zappcl
->state
&= ~APPCL_STATE_LBUTTON
;
272 xtext_puts (zappcl
->x
+8+x
, zappcl
->y
+28+y
, 0, str
);
279 int zgui_resize (unsigned short x
, unsigned short y
)
287 zstate
|= APPCL_STATE_RESIZE
;
292 unsigned zgui_event ()
296 if (zappcl
->state
& APPCL_STATE_REDRAW
) {
297 zappcl
->state
&= ~APPCL_STATE_REDRAW
;
298 zappcl
->state
|= APPCL_STATE_RECVOK
;
300 ipc_send (zappcl_fd
, zstr
, sizeof (appcl_t
));
303 int ret
= ipc_recv (zappcl_fd
, zstr
, 128);
306 if (zstate
& APPCL_STATE_RESIZE
) {
307 zappcl
->sizex
= zsizex
;
308 zappcl
->sizey
= zsizey
;
309 zappcl
->state
|= APPCL_STATE_RESIZE
;
312 return zappcl
->state
;
326 bitmap_button
.data
= image_button
;
329 zappcl_fd
= ipc_open ("/zdeserver", 0);
332 int ret
= ipc_recv (zappcl_fd
, zstr
, 127);
337 if (strcmp (zstr
, "ZDE"))
345 zappcl
= (appcl_t
*) zstr
;
347 memset (zstr
, 0, sizeof (appcl_t
));
354 ipc_close (zappcl_fd
);