Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / wm / cursor.c
blob3132328f956e3cd5ad83de167116028a21c8708e
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
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/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <libx/base.h>
25 #include <libx/object.h>
26 #include <libx/image.h>
27 #include <libx/cursor.h>
28 #include "cursor.h"
29 #include "config.h"
31 wmcursor *cursor;
33 const unsigned char cursor_bitmap [] = {
34 0x3f,0x3f,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
35 0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
36 0xff,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
37 0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
38 0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,
39 0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,
40 0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,
41 0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
42 0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f,0xff,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,
43 0xff,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,0xff,0xff,
44 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,0xff,
45 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,
46 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,
47 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,
48 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f
51 unsigned cursor_setpos (unsigned x, unsigned y)
53 if (!cursor)
54 return 0;
56 cursor->x = x;
57 cursor->y = y;
59 return 1;
62 unsigned cursor_getpos (unsigned x, unsigned y)
64 if (!cursor)
65 return 0;
67 x = cursor->x;
68 y = cursor->y;
70 return 1;
73 unsigned cursor_setstate (unsigned state)
75 if (!cursor)
76 return 0;
78 cursor->state |= state;
80 return 1;
83 unsigned char cursor_getstate ()
85 if (!cursor)
86 return 0;
88 return cursor->state;
91 unsigned cursor_draw ()
93 if (!cursor)
94 return 0;
96 if (!cursor->active)
97 return 2;
99 int ret = xcursor_update ();
101 xcursor_getpos (&cursor->x, &cursor->y);
103 switch (ret) {
104 case 0:
105 cursor->state = 0;
106 break;
107 case XCURSOR_STATE_RBUTTON:
108 cursor->state = XCURSOR_STATE_RBUTTON;
109 break;
110 case XCURSOR_STATE_LBUTTON:
111 cursor->state = XCURSOR_STATE_LBUTTON;
112 break;
113 case XCURSOR_STATE_BBUTTON:
114 cursor->state = XCURSOR_STATE_BBUTTON;
115 break;
119 //xpixel (cursor->x, cursor->y, 55);
120 //ximage_draw (cursor_img, cursor->x, cursor->y, 0);
121 unsigned i = 0;
122 unsigned j = 0;
123 unsigned k = 0;
124 for (i = 0; i < 15*15; i ++) {
125 if (k >= 15) {
126 j ++;
127 k = 0;
130 if (cursor_bitmap[i] != 0xff)
131 xpixel (cursor->x+k, cursor->y+j, cursor_bitmap[i]*256);
133 k ++;
135 //ximage_draw_spec (cursor_img, cursor->x, cursor->y, 24, 24, 0, 0, 0);
137 return 1;
140 unsigned init_cursor ()
142 /*cursor_img = ximage_open ("rocket");
144 if (!cursor_img)
145 return 0;*/
147 cursor = (wmcursor *) malloc (sizeof (wmcursor));
149 if (!cursor)
150 return 0;
152 cursor->x = 0;
153 cursor->y = 0;
154 cursor->active = 1;
155 cursor->state = 0;
156 cursor->action = 0;
158 switch (cfg->mouse) {
159 case 0:
160 xcursor_settype (XCURSOR_MOUSE_KB);
161 break;
162 case 1:
163 xcursor_settype (XCURSOR_MOUSE_SERIAL);
164 break;
165 case 2:
166 xcursor_settype (XCURSOR_MOUSE_PS2);
167 break;
168 case 3:
169 xcursor_settype (XCURSOR_MOUSE_USB);
170 break;
173 int ret = xcursor_init ();
175 if (!ret)
176 return 0;
178 return 1;