3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <libx/base.h>
28 #include <libx/object.h>
29 #include <libx/image.h>
30 #include <libx/cursor.h>
31 #include <libx/text.h>
40 unsigned short *bitmap_folder
;
41 unsigned short *bitmap_file
;
43 zde_icon_t zde_icon_list
;
45 extern zde_cursor_t
*zde_cursor
;
47 zde_icon_t
*create_icon (char *name
, int type
, void *(*entry
) (void *), void *arg
)
49 zde_icon_t
*icon
= (zde_icon_t
*) malloc (sizeof (zde_icon_t
));
57 icon
->bitmap
= bitmap_folder
;
61 icon
->name_len
= strlen (name
);
62 icon
->name
= strdup (name
);
65 icon
->type
= (char) type
;
68 icon
->next
= &zde_icon_list
;
69 icon
->prev
= zde_icon_list
.prev
;
72 icon
->y
= icon
->prev
->y
+ 54;
74 icon
->prev
->next
= icon
;
75 icon
->next
->prev
= icon
;
80 zde_icon_t
*create_icon_window (char *name
, int type
, void *(*entry
) (void *), void *arg
, zde_win_t
*window
)
85 zde_icon_t
*icon
= (zde_icon_t
*) malloc (sizeof (zde_icon_t
));
90 icon
->x
= window
->x
+ 14 + (window
->objectid
* 40);
91 icon
->y
= window
->y
+ 28;
99 arg_len
= strlen ((char *) arg
);
100 name_len
= strlen (name
);
102 icon
->arg
= malloc (arg_len
+ name_len
+ 2);
109 memcpy (s
, arg
, arg_len
);
110 memcpy (s
+arg_len
, "/", 1);
111 memcpy (s
+arg_len
+1, name
, name_len
);
112 s
[arg_len
+name_len
+1] = '\0';
116 icon
->bitmap
= bitmap_folder
;
119 icon
->bitmap
= bitmap_file
;
123 icon
->name_len
= strlen (name
);
124 icon
->name
= strdup (name
);
126 icon
->object
= (void *) window
;
127 icon
->type
= (char) type
;
130 icon
->next
= &zde_icon_list
;
131 icon
->prev
= zde_icon_list
.prev
;
132 icon
->prev
->next
= icon
;
133 icon
->next
->prev
= icon
;
138 unsigned destroy_icon_window (zde_win_t
*window
)
146 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
147 if (icon
->object
== (void *) window
) {
148 icon
->next
->prev
= icon
->prev
;
149 icon
->prev
->next
= icon
->next
;
165 static void draw_bitmap (unsigned short *bitmap
, unsigned short x
, unsigned short y
)
172 for (i
= 0; i
< 32*32; i
++) {
183 if (bitmap
[pix
] != (unsigned short) 0)
184 if (k
<= 32 && j
<= 32)
185 xpixel ((unsigned) x
+k
, (unsigned) y
+j
, (unsigned) bitmap
[pix
]);
191 int draw_icon_desktop ()
194 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
199 switch (zde_cursor
->state
) {
200 case XCURSOR_STATE_LBUTTON
:
202 if (!(zde_cursor
->flags
& CURSOR_FLAG_LBCLICK
))
203 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
)) {
204 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
205 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
206 zde_cursor
->state
= 0;
207 zde_cursor
->flags
|= CURSOR_FLAG_LBCLICK
;
209 /* create new thread as entry function */
211 pthread_create (&thread
, NULL
, icon
->entry
, icon
->arg
);
216 case XCURSOR_STATE_RBUTTON
:
218 if (!(zde_cursor
->flags
& CURSOR_FLAG_RBCLICK
))
219 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
)) {
220 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
221 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
222 zde_cursor
->state
= 0;
223 zde_cursor
->flags
|= CURSOR_FLAG_RBCLICK
;
225 /* create test window */
226 zde_win_t
*window
= create_window ("Properties", 1);
235 create_button_window ("Open", 0, handler_icon_filesystem
, icon
->arg
, window
);
237 create_button_window ("Read", 0, handler_icon_reader
, icon
->arg
, window
);
238 //create_button_window ("Delete", 0, handler_icon_filesystem, icon->arg, window);
248 draw_bitmap (icon
->bitmap
, icon
->x
, icon
->y
);
250 xrectfill (icon
->x
, icon
->y
, icon
->x
+32, icon
->y
+32, ~0);
253 xtext_puts (icon
->x
-(icon
->name_len
*3)+16, icon
->y
+35, ~0, icon
->name
);
259 int draw_icon_window (zde_win_t
*window
)
266 for (icon
= zde_icon_list
.next
; icon
!= &zde_icon_list
; icon
= icon
->next
) {
267 if (icon
->object
!= (void *) window
)
270 /* update icon position */
271 icon
->x
= window
->x
+ 14 + obj_x
;
272 icon
->y
= window
->y
+ 28 + obj_y
;
278 if (icon
->x
>= window
->x
+window
->sizex
-48) {
284 switch (zde_cursor
->state
) {
285 case XCURSOR_STATE_LBUTTON
:
287 if (!(zde_cursor
->flags
& CURSOR_FLAG_LBCLICK
))
288 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
)) {
289 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
290 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
291 if (isactive_window () != window
)
294 zde_cursor
->state
= 0;
295 zde_cursor
->flags
|= CURSOR_FLAG_LBCLICK
;
299 pthread_create (&thread
, NULL
, icon
->entry
, icon
->arg
);
305 case XCURSOR_STATE_RBUTTON
:
307 if (!(zde_cursor
->flags
& CURSOR_FLAG_RBCLICK
))
308 if (!(zde_cursor
->flags
& CURSOR_FLAG_MOVE
)) {
309 if (zde_cursor
->x
>= icon
->x
&& zde_cursor
->x
<= icon
->x
+32)
310 if (zde_cursor
->y
>= icon
->y
&& zde_cursor
->y
<= icon
->y
+32) {
311 zde_cursor
->state
= 0;
312 zde_cursor
->flags
|= CURSOR_FLAG_RBCLICK
;
314 /* create test window */
315 zde_win_t
*window
= create_window ("Properties", 1);
324 create_button_window ("Open", 0, handler_icon_filesystem
, icon
->arg
, window
);
326 create_button_window ("Read", 0, handler_icon_reader
, icon
->arg
, window
);
327 //create_button_window ("Delete", 0, handler_icon_filesystem, icon->arg, window);
337 draw_bitmap (icon
->bitmap
, icon
->x
, icon
->y
);
339 xrectfill (icon
->x
, icon
->y
, icon
->x
+32, icon
->y
+32, ~0);
342 xtext_puts (icon
->x
-(icon
->name_len
*3)+16, icon
->y
+35, 0, icon
->name
);
348 unsigned short *load_icon (char *filename
)
351 unsigned short *bitmap
= (unsigned short *) malloc (2120);
356 memset (bitmap
, 0, 2048+70);
359 int fd
= open (filename
, O_RDONLY
);
362 printf ("error -> file '%s' not found\n", filename
);
366 /* read icon bitmap data */
367 if (!read (fd
, (unsigned char *) bitmap
, 2048+70)) {
368 puts ("error -> something was wrong !\n");
377 zde_icon_list
.next
= &zde_icon_list
;
378 zde_icon_list
.prev
= &zde_icon_list
;
380 zde_icon_list
.prev
->x
= 0;
381 zde_icon_list
.prev
->y
= 0;
384 bitmap_folder
= load_icon ("folder");
390 bitmap_file
= load_icon ("file");
395 /* create test icon */
396 create_icon ("Filesystem", 0, handler_icon_filesystem
, "");
398 /* create test icon */
399 create_icon ("Terminal", 0, handler_icon_terminal
, "");