ZDE improvements - global zbitmap_t structure added, added native support for buttons...
[ZeXOS.git] / apps / zde / cursor.c
blob91191acb92f88297006107706e68b81727c28ff8
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 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 <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
50 int draw_cursor ()
52 int ret = xcursor_update ();
54 int cur_x;
55 int cur_y;
57 xcursor_getpos (&cur_x, &cur_y);
59 zde_cursor->x = cur_x;
60 zde_cursor->y = cur_y;
62 switch (ret) {
63 case 0:
64 zde_cursor->state = 0;
65 break;
66 case XCURSOR_STATE_RBUTTON:
67 zde_cursor->state = XCURSOR_STATE_RBUTTON;
68 break;
69 case XCURSOR_STATE_LBUTTON:
70 zde_cursor->state = XCURSOR_STATE_LBUTTON;
71 break;
72 case XCURSOR_STATE_BBUTTON:
73 zde_cursor->state = XCURSOR_STATE_BBUTTON;
74 break;
77 unsigned i = 0;
78 unsigned j = 0;
79 unsigned k = 0;
80 for (i = 0; i < 15*15; i ++) {
81 if (k >= 15) {
82 j ++;
83 k = 0;
86 if (cursor_bitmap[i] != 0xff)
87 xpixel (zde_cursor->x+k, zde_cursor->y+j, cursor_bitmap[i]*256);
89 k ++;
92 if (zde_cursor->state != XCURSOR_STATE_LBUTTON)
93 zde_cursor->flags &= ~CURSOR_FLAG_LBCLICK;
94 if (zde_cursor->state != XCURSOR_STATE_RBUTTON)
95 zde_cursor->flags &= ~CURSOR_FLAG_RBCLICK;
97 return 0;
100 int init_cursor ()
102 zde_cursor = (zde_cursor_t *) malloc (sizeof (zde_cursor_t));
104 if (!zde_cursor)
105 return -1;
107 zde_cursor->x = 0;
108 zde_cursor->y = 0;
109 zde_cursor->state = 0;
110 zde_cursor->flags = 0;
112 xcursor_settype (XCURSOR_MOUSE_AUTO);
114 int ret = xcursor_init ();
116 if (!ret)
117 return -1;
119 return 0;