3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
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>
36 unsigned short *bitmap_folder
;
38 zde_btn_t zde_btn_list
;
40 extern zde_cursor_t
*zde_cursor
;
42 zde_btn_t
*create_button (char *name
, int type
, void *(*entry
) (void *), void *arg
)
44 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
52 button
->bitmap
= bitmap_folder
;
56 button
->name
= strdup (name
);
57 button
->entry
= entry
;
62 button
->next
= &zde_btn_list
;
63 button
->prev
= zde_btn_list
.prev
;
65 button
->x
= 14 + (button
->prev
->x
* 40);
68 button
->prev
->next
= button
;
69 button
->next
->prev
= button
;
75 zde_btn_t
*create_button_window (char *name
, int type
, void *(*entry
) (void *), void *arg
, zde_win_t
*window
)
80 zde_btn_t
*button
= (zde_btn_t
*) malloc (sizeof (zde_btn_t
));
85 button
->x
= window
->x
+ 14 + (window
->objectid
* 40);
86 button
->y
= window
->y
+ 28;
91 unsigned arg_len
= strlen ((char *) arg
);
92 unsigned name_len
= strlen (name
);
94 button
->arg
= malloc (arg_len
+ name_len
+ 2);
99 char *s
= button
->arg
;
101 memcpy (s
, arg
, arg_len
);
102 memcpy (s
+arg_len
, "/", 1);
103 memcpy (s
+arg_len
+1, name
, name_len
);
104 s
[arg_len
+name_len
+1] = '\0';
106 button
->bitmap
= bitmap_folder
;
110 button
->name
= strdup (name
);
111 button
->entry
= entry
;
112 button
->object
= (void *) window
;
115 button
->next
= &zde_btn_list
;
116 button
->prev
= zde_btn_list
.prev
;
117 button
->prev
->next
= button
;
118 button
->next
->prev
= button
;
123 unsigned destroy_button_window (zde_win_t
*window
)
131 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
132 if (button
->object
== (void *) window
) {
133 button
->next
->prev
= button
->prev
;
134 button
->prev
->next
= button
->next
;
150 static void draw_bitmap (unsigned short x
, unsigned short y
)
157 for (i
= 0; i
< 32*31; i
++) {
168 if (bitmap_folder
[pix
] != (unsigned short) 0)
169 if (k
<= 32 && j
<= 32)
170 xpixel ((unsigned) x
+k
, (unsigned) y
+j
, (unsigned) bitmap_folder
[pix
]);
177 int draw_button_window (zde_win_t
*window
)
180 for (button
= zde_btn_list
.next
; button
!= &zde_btn_list
; button
= button
->next
) {
181 if (button
->object
!= (void *) window
)
184 /* we click on left button */
185 if (zde_cursor
->state
== XCURSOR_STATE_LBUTTON
) {
186 if (zde_cursor
->x
>= button
->x
&& zde_cursor
->x
<= button
->x
+32)
187 if (zde_cursor
->y
>= button
->y
&& zde_cursor
->y
<= button
->y
+32) {
188 zde_cursor
->state
= 0;
192 pthread_create (&thread
, NULL
, button
->entry
, button
->arg
);
198 draw_bitmap (button
->x
, button
->y
);
200 xrectfill (button
->x
, button
->y
, button
->x
+32, button
->y
+32, ~0);
203 xtext_puts (button
->x
-7, button
->y
+35, 0, button
->name
);
211 zde_btn_list
.next
= &zde_btn_list
;
212 zde_btn_list
.prev
= &zde_btn_list
;
215 bitmap_folder
= (unsigned short *) malloc (2120);
220 memset (bitmap_folder
, 0, 2048+70);
223 int fd
= open ("folder", O_RDONLY
);
226 puts ("error -> file 'folder' not found\n");
230 if (!read (fd
, (unsigned char *) bitmap_folder
, 2048+70)) {
231 puts ("error -> something was wrong !\n");
236 /* create test button */
237 //create_button ("Filesystem", 0, handler_button_filesystem, "");
241 //pthread_create (&thread, NULL, handler_button_filesystem, "");