3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <libx/base.h>
27 #include <libx/object.h>
28 #include <libx/image.h>
29 #include <libx/cursor.h>
30 #include <libx/text.h>
38 static zbitmap_t bitmap_button
;
40 zde_btn_t zde_btn_list
;
42 extern zde_cursor_t
*zde_cursor
;
43 extern unsigned short image_button
[];
46 zde_btn_t
*create_button (char *name
, int type
, void *(*entry
) (void *), void *arg
)
48 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
56 button
->bitmap
= image_button
;
60 button
->name
= strdup (name
);
61 button
->entry
= entry
;
66 button
->next
= &zde_btn_list
;
67 button
->prev
= zde_btn_list
.prev
;
69 button
->x
= 14 + (button
->prev
->x
* 40);
72 button
->prev
->next
= button
;
73 button
->next
->prev
= button
;
80 zde_btn_t
*create_button_window (char *name
, int type
, void *(*entry
) (void *), void *arg
, zde_win_t
*window
)
85 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
90 button
->x
= 0 + (window
->objectid
* 40);
95 unsigned short name_len
= strlen (name
);
98 unsigned arg_len
= strlen ((char *) arg
);
100 button
->arg
= malloc (arg_len
+ 1);
105 char *s
= button
->arg
;
107 memcpy (s
, arg
, arg_len
);
108 //memcpy (s+arg_len, "/", 1);
109 //memcpy (s+arg_len+1, name, name_len);
112 button
->bitmap
= (unsigned short *) image_button
;
116 button
->name_len
= name_len
;
117 button
->name
= strdup (name
);
118 button
->entry
= entry
;
119 button
->object
= (void *) window
;
122 button
->next
= &zde_btn_list
;
123 button
->prev
= zde_btn_list
.prev
;
124 button
->prev
->next
= button
;
125 button
->next
->prev
= button
;
130 unsigned destroy_button_window (zde_win_t
*window
)
138 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
139 if (button
->object
== (void *) window
) {
140 button
->next
->prev
= button
->prev
;
141 button
->prev
->next
= button
->next
;
157 static void draw_bitmapspec (zbitmap_t
*bitmap
)
170 unsigned short w
= bitmap
->data
[299+34];
172 for (i
= bitmap
->posx
+(bitmap
->posy
*13); i
< 13*25; i
++) {
183 if (bitmap
->data
[pix
] != w
)
184 if (k
< bitmap
->sizex
&& j
< bitmap
->sizey
)
185 xpixel ((unsigned) bitmap
->x
+k
, (unsigned) bitmap
->y
+j
, image_button
[pix
]);
191 int draw_button_window (zde_win_t
*window
)
194 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
195 if (button
->object
!= (void *) window
)
198 /* we click on left button */
199 if (zde_cursor
->state
== XCURSOR_STATE_LBUTTON
)
200 if (!(zde_cursor
->flags
& CURSOR_FLAG_LBCLICK
))
201 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
)) {
202 if (window
->x
+4+button
->x
<= zde_cursor
->x
&& window
->x
+button
->x
+12+((short) button
->name_len
*6) >= zde_cursor
->x
&&
203 window
->y
+button
->y
+22 <= zde_cursor
->y
&& window
->y
+button
->y
+43 >= zde_cursor
->y
) {
204 zde_cursor
->state
= 0;
205 zde_cursor
->flags
|= CURSOR_FLAG_LBCLICK
;
208 pthread_create (&thread
, NULL
, button
->entry
, button
->arg
);
213 if (button
->bitmap
) {
214 unsigned len
= button
->name_len
;
216 bitmap_button
.data
= button
->bitmap
;
217 bitmap_button
.x
= window
->x
+4+button
->x
;
218 bitmap_button
.y
= window
->y
+21+button
->y
;
219 bitmap_button
.posx
= 0;
220 bitmap_button
.posy
= 0;
221 bitmap_button
.sizex
= 4;
222 bitmap_button
.sizey
= 23;
224 draw_bitmapspec (&bitmap_button
);
227 for (l
= 0; l
< len
; l
++) {
228 bitmap_button
.x
= window
->x
+8+button
->x
+(l
*6);
229 bitmap_button
.y
= window
->y
+21+button
->y
;
230 bitmap_button
.posx
= 4;
231 bitmap_button
.posy
= 0;
232 bitmap_button
.sizex
= 6;
233 bitmap_button
.sizey
= 23;
235 draw_bitmapspec (&bitmap_button
);
238 bitmap_button
.x
= window
->x
+8+button
->x
+(len
*6);
239 bitmap_button
.y
= window
->y
+21+button
->y
;
240 bitmap_button
.posx
= 9;
241 bitmap_button
.posy
= 0;
242 bitmap_button
.sizex
= 4;
243 bitmap_button
.sizey
= 23;
245 draw_bitmapspec (&bitmap_button
);
247 xrectfill (button
->x
+window
->x
, button
->y
+window
->y
, button
->x
+32+window
->x
, button
->y
+32+window
->y
, ~0);
250 xtext_puts (button
->x
+8+window
->x
, button
->y
+28+window
->y
, 0, button
->name
);
258 zde_btn_list
.next
= &zde_btn_list
;
259 zde_btn_list
.prev
= &zde_btn_list
;
262 /* bitmap_button = (unsigned short *) malloc (1100);
267 memset (bitmap_button, 0, 1082);
270 int fd = open ("button", O_RDONLY);
273 puts ("error -> file 'button' not found\n");
277 if (!read (fd, (unsigned char *) bitmap_button, 1082)) {
278 puts ("error -> something was wrong !\n");
283 /* create test button */
284 //create_button ("Filesystem", 0, handler_button_filesystem, "");
288 //pthread_create (&thread, NULL, handler_button_filesystem, "");