* Christmas edition *; fixed irc /os command; small cleanup in fd.c; improvements...
[ZeXOS.git] / apps / zde / cursor.c
blob549e9a303759931375d43a30842e0aefaf047684
1 /*
2 * ZeX/OS
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/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <libx/base.h>
24 #include <libx/object.h>
25 #include <libx/image.h>
26 #include <libx/cursor.h>
27 #include <libx/text.h>
29 #include "cursor.h"
31 const unsigned char cursor_bitmap [] = {
32 0x3f,0x3f,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
33 0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
34 0xff,0x3f,0x3f,0x3f,0x3f,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
35 0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
36 0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,
37 0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,
38 0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,
39 0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
40 0xff,0xff,0xff,0xff,0x3f,0x3f,0x3f,0xff,0x3f,0x00,0xff,0xff,0xff,0xff,0xff,
41 0xff,0xff,0xff,0xff,0xff,0x3f,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,0xff,0xff,
42 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,0xff,
43 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,0xff,
44 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,0xff,
45 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x00,
46 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f
49 int *cur_x;
50 int *cur_y;
52 int draw_cursor ()
54 int ret = xcursor_update ();
56 xcursor_getpos (cur_x, cur_y);
58 zde_cursor->x = *cur_x;
59 zde_cursor->y = *cur_y;
61 switch (ret) {
62 case 0:
63 zde_cursor->state = 0;
64 break;
65 case XCURSOR_STATE_RBUTTON:
66 zde_cursor->state = XCURSOR_STATE_RBUTTON;
67 break;
68 case XCURSOR_STATE_LBUTTON:
69 zde_cursor->state = XCURSOR_STATE_LBUTTON;
70 break;
71 case XCURSOR_STATE_BBUTTON:
72 zde_cursor->state = XCURSOR_STATE_BBUTTON;
73 break;
76 unsigned i = 0;
77 unsigned j = 0;
78 unsigned k = 0;
79 for (i = 0; i < 15*15; i ++) {
80 if (k >= 15) {
81 j ++;
82 k = 0;
85 if (cursor_bitmap[i] != 0xff)
86 xpixel (zde_cursor->x+k, zde_cursor->y+j, cursor_bitmap[i]*256);
88 k ++;
91 /*xpixel (zde_cursor->x, zde_cursor->y, ~0);
92 xpixel (zde_cursor->x, zde_cursor->y+1, ~0);
93 xpixel (zde_cursor->x+1, zde_cursor->y+1, ~0);
94 xpixel (zde_cursor->x+1, zde_cursor->y, ~0);*/
96 return 0;
99 int init_cursor ()
101 cur_x = (int *) malloc (sizeof (int));
103 if (!cur_x)
104 return -1;
106 cur_y = (int *) malloc (sizeof (int));
108 if (!cur_y)
109 return -1;
111 zde_cursor = (zde_cursor_t *) malloc (sizeof (zde_cursor_t));
113 if (!zde_cursor)
114 return -1;
116 zde_cursor->x = 0;
117 zde_cursor->y = 0;
118 zde_cursor->state = 0;
120 *cur_x = 0;
121 *cur_y = 0;
123 xcursor_settype (XCURSOR_MOUSE_KB);
125 int ret = xcursor_init ();
127 if (!ret)
128 return -1;
130 return 0;