Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
105 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   Massimiliano Giorgi <massy@gandalf.sssup.it>
11
 *   Luca Abeni          <luca@gandalf.sssup.it>
12
 *   (see the web pages for full authors list)
13
 *
14
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
15
 *
16
 * http://www.sssup.it
17
 * http://retis.sssup.it
18
 * http://shark.sssup.it
19
 */
20
 
21
/**
22
 ------------
23
 CVS :        $Id: mcurgrx.c,v 1.1 2003-03-24 10:54:17 pj Exp $
24
 
25
 File:        $File$
26
 Revision:    $Revision: 1.1 $
27
 Last update: $Date: 2003-03-24 10:54:17 $
28
 ------------
29
 
30
 Author:        Massimiliano Giorgi
31
 Date:  24/Giu/99
32
 
33
**/
34
 
35
/*
36
 * Copyright (C) 2000 Paolo Gai
37
 *
38
 * This program is free software; you can redistribute it and/or modify
39
 * it under the terms of the GNU General Public License as published by
40
 * the Free Software Foundation; either version 2 of the License, or
41
 * (at your option) any later version.
42
 *
43
 * This program is distributed in the hope that it will be useful,
44
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46
 * GNU General Public License for more details.
47
 *
48
 * You should have received a copy of the GNU General Public License
49
 * along with this program; if not, write to the Free Software
50
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
51
 *
52
 */
53
 
54
/*---------------*
55
 * GRX Management*
56
 *---------------*/
57
 
58
#include <kernel/kern.h>
59
//#include <sys/sys.h>
60
//#include <mem.h>
61
#include <drivers/mouse.h>
62
#include <drivers/glib.h>
63
#include "_mouse.h"
64
 
65
static BYTE left_ptr_bits[] = {
66
   0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00,
67
   0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
68
   0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};
69
 
70
 
71
static BYTE left_ptrmsk_bits[] = {
72
   0x0c, 0x00, 0x1c, 0x00, 0x3c, 0x00, 0x7c, 0x00, 0xfc, 0x00, 0xfc, 0x01,
73
   0xfc, 0x03, 0xfc, 0x07, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x01, 0xdc, 0x03,
74
   0xcc, 0x03, 0x80, 0x07, 0x80, 0x07, 0x00, 0x03};
75
 
76
/* if called with NULL -> retrieve next bit of a bits-stream
77
 * else                -> initialize the bit stream
78
 */
79
static int get_bit(BYTE *p)
80
{
81
  static BYTE *ptr;
82
  static BYTE val;
83
  static int  c;
84
 
85
  if (p!=NULL) {
86
    ptr=p;
87
    val=0;
88
    c=8;
89
    return 0;
90
  }
91
 
92
  if (c==8) {
93
    c=0;
94
    val=*ptr;
95
    ptr++;
96
  } else
97
    val>>=1;
98
 
99
  c++;
100
  return val&1;
101
}
102
 
103
/* dimensions (16x16) */
104
#define SHAPE_DX MOUSESHAPEDX
105
#define SHAPE_DY MOUSESHAPEDY
106
 
107
/* shape hot spot (3,1) */
108
#define HOTSPOT_X MOUSEHOTSPOTX
109
#define HOTSPOT_Y MOUSEHOTSPOTY
110
 
111
/* cursor shape */
112
static BYTE shape[SHAPE_DX*SHAPE_DY*4];
113
/* cursor mask */
114
static BYTE mask[SHAPE_DX*SHAPE_DY*4];
115
 
116
/* old memory buffer */
117
static BYTE saved_shape[SHAPE_DX*SHAPE_DY*4];
118
/* new memory buffer */
119
static BYTE new_shape[SHAPE_DX*SHAPE_DY*4];
120
 
121
static BYTE *saved_shapeptr=(void*)DEFAULT;
122
static BYTE *saved_maskptr=(void*)DEFAULT;
123
 
124
static int bpp; // bytes per pixel
125
 
126
/* show grx cursor */
127
static void show_grx_cursor(int x, int y)
128
{
129
  int i;
130
  x-=HOTSPOT_X-1;
131
  y-=HOTSPOT_Y-1;
132
  grx_getimage(x,y,x+SHAPE_DX-1,y+SHAPE_DY-1,saved_shape);
133
  for(i=0;i<SHAPE_DX*SHAPE_DY*bpp/4;i++)
134
    ((DWORD*)new_shape)[i]=(((DWORD*)saved_shape)[i]&((DWORD*)mask)[i])|((DWORD*)shape)[i];
135
  grx_putimage(x,y,x+SHAPE_DX-1,y+SHAPE_DY-1,new_shape);
136
}
137
 
138
/* restore grx cursor */
139
static void restore_grx_cursor(int x, int y)
140
{
141
  x-=HOTSPOT_X-1;
142
  y-=HOTSPOT_Y-1;
143
  grx_putimage(x,y,x+SHAPE_DX-1,y+SHAPE_DY-1,saved_shape);
144
}
145
 
146
int mouse_grxcursor(int cmd)
147
{
148
  mouse_grxshape(saved_shapeptr,saved_maskptr);
149
  return _mouse_cursor_init(cmd|GRXCURSOR,show_grx_cursor,restore_grx_cursor);
150
}
151
 
152
/* compute the shape and mask array */
153
int mouse_grxshape(BYTE *shapeptr, BYTE *maskptr)
154
{
155
  int          result;
156
  grx_vga_modeinfo info;
157
  int          nb;
158
  BYTE         b;
159
  int          pc;
160
  int          i,j;
161
  int          saved_x,saved_y;
162
  int          cond;
163
 
164
  result=gd_getmodeinfo(&info);
165
  if (result==-1) return -1;
166
  bpp=nb=info.bytesperpixel;
167
 
168
  cond=(
169
        ((autocursormode&STATUSMASK)==ENABLE)&&
170
        ((autocursormode&GRXCURSOR)==GRXCURSOR)
171
       );
172
 
173
  if (cond) {
174
    _mouse_getsavedposition(&saved_x,&saved_y);
175
    restore_grx_cursor(saved_x,saved_y);
176
  }
177
 
178
  if (shapeptr==(void*)DEFAULT) {
179
    //int h;
180
 
181
    shapeptr=left_ptr_bits;
182
    pc=0;
183
    get_bit(left_ptr_bits);
184
    for (i=0;i<SHAPE_DX*SHAPE_DY;i++) {
185
      b=get_bit(NULL)?255:0;
186
      for (j=0;j<nb;j++) shape[pc++]=b;
187
      //grx_plot(h+180,i+80,b);
188
    }
189
  } else {
190
    memcpy(shape,shapeptr,SHAPE_DX*SHAPE_DY*nb);
191
    saved_shapeptr=shapeptr;
192
  }
193
 
194
  /*
195
  some test!
196
 
197
  pc=0;
198
  for (i=0;i<16;i++)
199
    for (j=0;j<16;j++) {
200
      char s[16];
201
      sprintf(s,"%c",shape[pc++]==0?'-':'*');
202
      grx_text(s,200+j*8,200+i*8,255,0);
203
    }
204
  grx_putimage(200,80,200+15,80+16,shape);
205
 
206
  grx_getimage(180,80,180+16,80+16,shape);
207
 
208
  pc=0;
209
  for (i=0;i<16;i++)
210
    for (j=0;j<17;j++) {
211
      char s[16];
212
      sprintf(s,"%c",shape[pc++]==0?'-':'*');
213
      grx_text(s,400+j*8,400+i*8,255,0);
214
    }
215
  */
216
 
217
  if (maskptr==(void*)DEFAULT) {
218
    maskptr=left_ptrmsk_bits;
219
    pc=0;
220
    get_bit(left_ptrmsk_bits);
221
    for (i=0;i<SHAPE_DX*SHAPE_DY;i++) {
222
      b=get_bit(NULL)?0:255;
223
      for (j=0;j<nb;j++) mask[pc++]=b;
224
    }
225
  }else {
226
    memcpy(mask,maskptr,SHAPE_DX*SHAPE_DY*nb);
227
    saved_maskptr=maskptr;
228
  }
229
 
230
  if (cond)
231
     show_grx_cursor(saved_x,saved_y);
232
 
233
  return 0;
234
}