|
|
1.1 root 1: #ifndef lint
2: static char *rcsid_cursor_c = "$Header: cursor.c,v 10.3 86/12/17 18:05:41 swick Exp $";
3: #endif lint
4: /* Copyright 1985 Massachusetts Institute of Technology */
5:
6: /* cursor.c - various stuff with the mouse & cursor
7: *
8: * StoreCursor Creates a cursor
9: * FreeCursor Frees the storage taken by a cursor
10: * LoadCursor Loads a bitmap to use as cursor
11: * InitMouse Initialize the mouse
12: * SetCursorPosition Forces cursor to a particular position
13: * SetMouseCharacteristics Controls speed of cursor relative to mouse
14: *
15: * Changes and additions by:
16: *
17: * Scott Bates
18: * Brown University
19: * IRIS, Box 1946
20: * Providence, RI 02912
21: *
22: *
23: * Copyright (c) 1986 Brown University
24: *
25: * Permission to use, copy, modify and distribute this software and its
26: * documentation for any purpose and without fee is hereby granted, provided
27: * that the above copyright notice appear in all copies, and that both
28: * that copyright notice and this permission notice appear in supporting
29: * documentation, and that the name of Brown University not be used in
30: * advertising or publicity pertaining to distribution of the software
31: * without specific, written prior permission. Brown University makes no
32: * representations about the suitability of this software for any purpose.
33: * It is provided "as-is" without express or implied warranty.
34: */
35:
36: #include "private.h"
37: #include "bitblt.h"
38:
39: #ifdef APA16
40: #include "apa16.h"
41: #endif APA16
42:
43: #ifdef AED
44: #include "aed.h"
45: #endif AED
46:
47: #ifdef APA8
48: #include "apa8.h"
49: #endif APA8
50:
51: #ifdef APA8C
52: #include "apa8c.h"
53: #endif APA8C
54:
55: #ifdef PQD
56: #include "pqd.h"
57: #endif PQD
58:
59: #define imin(a,b) ((a) < (b) ? (a) : (b))
60:
61: /*
62: * Create a cursor
63: */
64:
65: /*ARGSUSED*/
66: CURSOR *StoreCursor (func, image, fore, back, mask, xoff, yoff)
67: register BITMAP *image;
68: BITMAP *mask;
69: int func, fore, back, xoff, yoff;
70: {
71: register CURSOR *cursor;
72: register u_short *cimage = (u_short *)image->data;
73: register u_short *cmask = (u_short *)mask->data;
74: register CursPriv *curdata;
75: register i, width_mask;
76: static u_short bmask[] = { 0x0000, 0x8000, 0xC000, 0xE000,
77: 0xF000, 0xF800, 0xFC00, 0xFE00,
78: 0xFF00, 0xFF80, 0xFFC0, 0xFFE0,
79: 0xFFF0, 0xFFF8, 0xFFFC, 0xFFFE, 0xFFFF };
80:
81: static u_short defmask[] = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
82: 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
83: 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
84: 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF };
85:
86: #ifdef TRACE_X
87: fprintf(stderr, "In StoreCursor\n");
88: fflush(stderr);
89: #endif TRACE_X
90:
91: /*
92: * If no mask supplied use default
93: */
94:
95: if (mask == NULL)
96: cmask = defmask;
97:
98: /*
99: * Allocate space for cursor structure
100: */
101:
102: cursor = (CURSOR *) Xalloc (sizeof (CURSOR));
103:
104: /*
105: * Fill in cursor structure
106: */
107:
108: cursor->width = imin(image->width, CURSOR_WIDTH);
109: cursor->height = imin(image->height, CURSOR_HEIGHT);
110: cursor->xmin = 0;
111: cursor->ymin = 0;
112: cursor->xmax = pbm.width - 1;
113: cursor->ymax = pbm.height - 1;
114: cursor->xoff = xoff;
115: cursor->yoff = yoff;
116: cursor->refcnt = 1;
117:
118: /*
119: * Allocate space for CursPriv structure which holds
120: * cursor image and mask
121: */
122:
123: curdata = (CursPriv *) Xalloc (sizeof (CursPriv));
124: cursor->data = (caddr_t) curdata;
125:
126: /*
127: * Get width mask
128: *
129: * Note: cursor image and mask are in IBM bit order
130: * not VAX. Therefore, width masks are in IBM
131: * bit order.
132: */
133:
134: width_mask = bmask[cursor->width];
135:
136: if (fore == 0) {
137: /*
138: * Invert and store cursor in CursPriv structure
139: */
140:
141: for ( i = 0; i < cursor->height; i++) {
142: curdata->mask[i] = (*cmask++) & width_mask;
143: curdata->data[i] = ((*cimage++) & width_mask)
144: ^ curdata->mask[i];
145: }
146: } else {
147: /*
148: * Store cursor in CursPriv structure
149: */
150:
151: for ( i = 0; i < cursor->height; i++) {
152: curdata->data[i] = (*cimage++) & width_mask;
153: curdata->mask[i] = (*cmask++) & width_mask;
154: }
155: }
156:
157: /*
158: * Pad cursor image and mask to maximum cursor size
159: */
160:
161: for (i = cursor->height; i < CURSOR_HEIGHT; i++) {
162: curdata->data[i] = 0;
163: curdata->mask[i] = 0;
164: }
165:
166: /*
167: * Set cursor hotspot
168: */
169:
170: curdata->hotspot.x = curdata->hotspot.y = 0;
171:
172: /*
173: * Return pointer to cursor structure
174: */
175:
176: return (cursor);
177: }
178:
179: /*
180: * Free resources held by cursor
181: */
182:
183: FreeCursor (cursor)
184: register CURSOR *cursor;
185: {
186: #ifdef TRACE_X
187: fprintf(stderr, "In FreeCursor\n");
188: fflush(stderr);
189: #endif TRACE_X
190:
191: free ((caddr_t) CDATA(cursor));
192: free ((caddr_t) cursor);
193: }
194:
195: /*
196: * Set hotspot and load new cursor
197: */
198:
199: LoadCursor (cursor)
200: register CURSOR *cursor;
201: {
202: #ifdef TRACE_X
203: fprintf(stderr, "In LoadCursor\n");
204: fflush(stderr);
205: #endif TRACE_X
206:
207: /*
208: * Set new hotspot
209: */
210:
211: XAddr->hotspot.x = cursor->xoff;
212: XAddr->hotspot.y = cursor->yoff;
213:
214: /*
215: * Load new cursor
216: */
217:
218: return(ioctl (xdev, QIOCLDCUR, (caddr_t) cursor->data));
219: }
220:
221: /*
222: * Initialize mouse
223: */
224:
225: InitMouse ()
226: {
227: char *MouseType = getenv("MOUSETYPE");
228: char *MouseName = getenv("MOUSENAME");
229: struct sgttyb MouseSG;
230: int ldisc, ioarg;
231: extern int mdev;
232:
233: #ifdef TRACE_X
234: fprintf(stderr, "In InitMouse\n");
235: fflush(stderr);
236: #endif TRACE_X
237:
238: /*
239: * Switch to mouse line discipline
240: */
241:
242: ldisc = TABLDISC;
243: ioctl(mdev, TIOCSETD, (caddr_t) &ldisc);
244:
245: /*
246: * Check for Mouse Systems Mouse
247: */
248:
249: if (MouseType && (strcmp (MouseType, "MSCMOUSE") == 0)) {
250: MouseSG.sg_ispeed = 9;
251: MouseSG.sg_ospeed = 9;
252: MouseSG.sg_erase = -1;
253: MouseSG.sg_kill = -1;
254: MouseSG.sg_flags = RAW | ANYP;
255: ioctl(mdev, TIOCSETP, (caddr_t) &MouseSG);
256:
257: /*
258: * Set to MSCmouse emulation
259: */
260:
261: ldisc = PCMS_DISC;
262: if (ioctl (mdev, TBIOSETD, (caddr_t) &ldisc) < 0)
263: DeviceError("Error in setting PCMS_DISC Line Discipline");
264:
265: } else { /* Assume the Planar Mouse */
266:
267: /*
268: * Use 3 button emulation
269: */
270:
271: ldisc = PLANMS_DISC3;
272: if (ioctl (mdev, TBIOSETD, (caddr_t) &ldisc) < 0)
273: DeviceError("Error in setting PLANMS_DISC3 Line Discipline");
274:
275: /*
276: * Set defualt mouse sample rate
277: */
278:
279: ioarg = MS_RATE_40;
280: if (ioctl (mdev, MSIC_SAMP, (caddr_t) &ioarg) < 0)
281: DeviceError ("Error in setting mouse sample rate");
282:
283: /*
284: * Set defualt mouse resolution
285: */
286:
287: ioarg = MS_RES_200;
288: if (ioctl (mdev, MSIC_RESL, (caddr_t) &ioarg) < 0)
289: DeviceError ("Error in setting mouse resolution");
290: }
291:
292: }
293:
294: /*
295: * Set new cursor position
296: */
297:
298: SetCursorPosition(pos)
299: register XCursor *pos;
300: {
301: #ifdef TRACE_X
302: fprintf(stderr, "In SetCursorPosition\n");
303: fflush(stderr);
304: #endif TRACE_X
305:
306: return(ioctl(xdev, QIOCSMSTATE, (caddr_t) pos));
307: }
308:
309: /*
310: * Set mouse threshold and acceleration (mouse speed control)
311: */
312:
313: SetMouseCharacteristics (threshold, accelaration)
314: int threshold, accelaration;
315: {
316: #ifdef TRACE_X
317: fprintf(stderr, "In SetMouseCharacteristics\n");
318: fflush(stderr);
319: #endif TRACE_X
320:
321: XAddr->mscale = accelaration;
322: XAddr->mthreshold = threshold;
323: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.