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_folder
;
38 unsigned short *bitmap_file
;
40 zde_icon_t zde_icon_list
;
42 extern zde_cursor_t
*zde_cursor
;
44 zde_icon_t
*create_icon (char *name
, int type
, void *(*entry
) (void *), void *arg
)
46 zde_icon_t
*icon
= (zde_icon_t
*) malloc (sizeof (zde_icon_t
));
54 icon
->bitmap
= bitmap_folder
;
58 icon
->name_len
= strlen (name
);
59 icon
->name
= strdup (name
);
65 icon
->next
= &zde_icon_list
;
66 icon
->prev
= zde_icon_list
.prev
;
69 icon
->y
= icon
->prev
->y
+ 54;
71 icon
->prev
->next
= icon
;
72 icon
->next
->prev
= icon
;
77 zde_icon_t
*create_icon_window (char *name
, int type
, void *(*entry
) (void *), void *arg
, zde_win_t
*window
)
82 zde_icon_t
*icon
= (zde_icon_t
*) malloc (sizeof (zde_icon_t
));
87 icon
->x
= window
->x
+ 14 + (window
->objectid
* 40);
88 icon
->y
= window
->y
+ 28;
98 arg_len
= strlen ((char *) arg
);
99 name_len
= strlen (name
);
101 icon
->arg
= malloc (arg_len
+ name_len
+ 2);
108 memcpy (s
, arg
, arg_len
);
109 memcpy (s
+arg_len
, "/", 1);
110 memcpy (s
+arg_len
+1, name
, name_len
);
111 s
[arg_len
+name_len
+1] = '\0';
113 icon
->bitmap
= bitmap_folder
;
116 arg_len
= strlen ((char *) arg
);
117 name_len
= strlen (name
);
119 icon
->arg
= malloc (arg_len
+ name_len
+ 2);
126 memcpy (s
, arg
, arg_len
);
127 memcpy (s
+arg_len
, "/", 1);
128 memcpy (s
+arg_len
+1, name
, name_len
);
129 s
[arg_len
+name_len
+1] = '\0';
131 icon
->bitmap
= bitmap_file
;
136 icon
->name_len
= strlen (name
);
137 icon
->name
= strdup (name
);
139 icon
->object
= (void *) window
;
142 icon
->next
= &zde_icon_list
;
143 icon
->prev
= zde_icon_list
.prev
;
144 icon
->prev
->next
= icon
;
145 icon
->next
->prev
= icon
;
150 unsigned destroy_icon_window (zde_win_t
*window
)
158 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
159 if (icon
->object
== (void *) window
) {
160 icon
->next
->prev
= icon
->prev
;
161 icon
->prev
->next
= icon
->next
;
177 static void draw_bitmap (unsigned short *bitmap
, unsigned short x
, unsigned short y
)
184 for (i
= 0; i
< 32*32; i
++) {
195 if (bitmap
[pix
] != (unsigned short) 0)
196 if (k
<= 32 && j
<= 32)
197 xpixel ((unsigned) x
+k
, (unsigned) y
+j
, (unsigned) bitmap
[pix
]);
203 int draw_icon_desktop ()
206 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
210 /* we click on left button */
211 if (zde_cursor
->state
== XCURSOR_STATE_LBUTTON
) {
212 if (!(zde_cursor
->flags
& CURSOR_FLAG_LBCLICK
))
213 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
))
214 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
215 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
216 zde_cursor
->state
= 0;
217 zde_cursor
->flags
|= CURSOR_FLAG_LBCLICK
;
221 pthread_create (&thread
, NULL
, icon
->entry
, icon
->arg
);
227 draw_bitmap (icon
->bitmap
, icon
->x
, icon
->y
);
229 xrectfill (icon
->x
, icon
->y
, icon
->x
+32, icon
->y
+32, ~0);
232 xtext_puts (icon
->x
-(icon
->name_len
*3)+16, icon
->y
+35, ~0, icon
->name
);
238 int draw_icon_window (zde_win_t
*window
)
245 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
246 if (icon
->object
!= (void *) window
)
249 /* update icon position */
250 icon
->x
= window
->x
+ 14 + obj_x
;
251 icon
->y
= window
->y
+ 28 + obj_y
;
257 if (icon
->x
>= window
->x
+window
->sizex
-48) {
262 /* we click on left button */
263 if (zde_cursor
->state
== XCURSOR_STATE_LBUTTON
) {
264 if (!(zde_cursor
->flags
& CURSOR_FLAG_LBCLICK
))
265 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
))
266 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
267 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
268 if (isactive_window () != window
)
271 zde_cursor
->state
= 0;
272 zde_cursor
->flags
|= CURSOR_FLAG_LBCLICK
;
276 pthread_create (&thread
, NULL
, icon
->entry
, icon
->arg
);
282 draw_bitmap (icon
->bitmap
, icon
->x
, icon
->y
);
284 xrectfill (icon
->x
, icon
->y
, icon
->x
+32, icon
->y
+32, ~0);
287 xtext_puts (icon
->x
-(icon
->name_len
*3)+16, icon
->y
+35, 0, icon
->name
);
293 unsigned short *load_icon (char *filename
)
296 unsigned short *bitmap
= (unsigned short *) malloc (2120);
301 memset (bitmap
, 0, 2048+70);
304 int fd
= open (filename
, O_RDONLY
);
307 printf ("error -> file '%s' not found\n", filename
);
311 /* read icon bitmap data */
312 if (!read (fd
, (unsigned char *) bitmap
, 2048+70)) {
313 puts ("error -> something was wrong !\n");
322 zde_icon_list
.next
= &zde_icon_list
;
323 zde_icon_list
.prev
= &zde_icon_list
;
325 zde_icon_list
.prev
->x
= 0;
326 zde_icon_list
.prev
->y
= 0;
329 bitmap_folder
= load_icon ("folder");
335 bitmap_file
= load_icon ("file");
340 /* create test icon */
341 create_icon ("Filesystem", 0, handler_icon_filesystem
, "");
343 /* create test icon */
344 create_icon ("Terminal", 0, handler_icon_terminal
, "");