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>
37 unsigned short *bitmap_button
;
39 //zde_btn_t zde_btn_list;
41 extern zde_cursor_t
*zde_cursor
;
43 zde_btn_t
*create_button (char *name
, int type
, void *(*entry
) (void *), void *arg
)
45 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
53 button
->bitmap
= bitmap_folder
;
57 button
->name
= strdup (name
);
58 button
->entry
= entry
;
63 button
->next
= &zde_btn_list
;
64 button
->prev
= zde_btn_list
.prev
;
66 button
->x
= 14 + (button
->prev
->x
* 40);
69 button
->prev
->next
= button
;
70 button
->next
->prev
= button
;
76 zde_btn_t
*create_button_window (char *name
, int type
, void *(*entry
) (void *), void *arg
, zde_win_t
*window
)
81 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
86 button
->x
= window
->x
+ 14 + (window
->objectid
* 40);
87 button
->y
= window
->y
+ 28;
92 unsigned arg_len
= strlen ((char *) arg
);
93 unsigned name_len
= strlen (name
);
95 button
->arg
= malloc (arg_len
+ name_len
+ 2);
100 char *s
= button
->arg
;
102 memcpy (s
, arg
, arg_len
);
103 memcpy (s
+arg_len
, "/", 1);
104 memcpy (s
+arg_len
+1, name
, name_len
);
105 s
[arg_len
+name_len
+1] = '\0';
107 button
->bitmap
= bitmap_folder
;
111 button
->name
= strdup (name
);
112 button
->entry
= entry
;
113 button
->object
= (void *) window
;
116 button
->next
= &zde_btn_list
;
117 button
->prev
= zde_btn_list
.prev
;
118 button
->prev
->next
= button
;
119 button
->next
->prev
= button
;
124 unsigned destroy_button_window (zde_win_t
*window
)
132 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
133 if (button
->object
== (void *) window
) {
134 button
->next
->prev
= button
->prev
;
135 button
->prev
->next
= button
->next
;
151 static void draw_bitmap (unsigned short x
, unsigned short y
)
158 for (i
= 0; i
< 32*31; i
++) {
169 if (bitmap_folder
[pix
] != (unsigned short) 0)
170 if (k
<= 32 && j
<= 32)
171 xpixel ((unsigned) x
+k
, (unsigned) y
+j
, (unsigned) bitmap_folder
[pix
]);
178 int draw_button_window (zde_win_t
*window
)
181 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
182 if (button
->object
!= (void *) window
)
185 /* we click on left button */
186 if (zde_cursor
->state
== XCURSOR_STATE_LBUTTON
) {
187 if (zde_cursor
->x
>= button
->x
&& zde_cursor
->x
<= button
->x
+32)
188 if (zde_cursor
->y
>= button
->y
&& zde_cursor
->y
<= button
->y
+32) {
189 zde_cursor
->state
= 0;
193 pthread_create (&thread
, NULL
, button
->entry
, button
->arg
);
199 draw_bitmap (button
->x
, button
->y
);
201 xrectfill (button
->x
, button
->y
, button
->x
+32, button
->y
+32, ~0);
204 xtext_puts (button
->x
-7, button
->y
+35, 0, button
->name
);
212 // zde_btn_list.next = &zde_btn_list;
213 // zde_btn_list.prev = &zde_btn_list;
216 /* bitmap_button = (unsigned short *) malloc (1100);
221 memset (bitmap_button, 0, 1082);
224 int fd = open ("button", O_RDONLY);
227 puts ("error -> file 'button' not found\n");
231 if (!read (fd, (unsigned char *) bitmap_button, 1082)) {
232 puts ("error -> something was wrong !\n");
237 /* create test button */
238 //create_button ("Filesystem", 0, handler_button_filesystem, "");
242 //pthread_create (&thread, NULL, handler_button_filesystem, "");