|
|
1.1 root 1: /*
2: * $Source: /u1/X/libis/RCS/cursor.c,v $
3: * $Header: cursor.c,v 1.1 86/11/17 14:33:26 swick Rel $
4: */
5:
6: #ifndef lint
7: static char *rcsid_cursor_c = "$Header: cursor.c,v 1.1 86/11/17 14:33:26 swick Rel $";
8: #endif lint
9:
10: #include "is-copyright.h"
11:
12: /* cursor.c - various stuff with the mouse & cursor
13: *
14: * StoreCursor Creates a cursor
15: * FreeCursor Frees the storage taken by a cursor
16: * LoadCursor Loads a bitmap to use as cursor
17: * InitMouse Initialize the mouse
18: * SetCursorPosition Forces cursor to a particular position
19: * UpdateCursorPosition Moves cursor to a particular position
20: * SetMouseCharacteristics Controls speed of cursor relative to mouse
21: *
22: * Copyright (c) 1986, Integrated Solutions, Inc.
23: *
24: */
25:
26: #include "Xis.h"
27:
28: static CURSOR *CurrentCursor;
29: static int CursorDisplayed;
30:
31: extern BITMAP *StoreBitmap();
32: extern PIXMAP *MakePixmap();
33: extern DEVICE *CurrentDevice;
34:
35: /*
36: * StoreCursor
37: */
38: CURSOR *StoreCursor(func, image, fore, back, mask, xoff, yoff)
39: int func;
40: register BITMAP *image;
41: register int fore, back;
42: BITMAP *mask;
43: int xoff, yoff;
44: {
45: register CURSOR *cursor;
46: register CursPriv *data;
47: BITMAP *bitmap;
48:
49: #ifdef DEBUG
50: if (debug & D_Cursor)
51: printf("StoreCursor(func=%d, image=0x%x, fore=%d, back=%d, mask=0x%x,\n xoff=%d, yoff=%d)\n",
52: func, image, fore, back, mask, xoff, yoff);
53: #endif DEBUG
54:
55: if (!image) {
56: return (NULL);
57: }
58:
59: cursor = (CURSOR *) Xalloc(sizeof(CURSOR));
60:
61: cursor->width = image->width;
62: cursor->height = image->height;
63: cursor->xoff = xoff;
64: cursor->yoff = yoff;
65:
66: /* Only the tip need be on-screen */
67: cursor->xmin = 0;
68: cursor->ymin = 0;
69: cursor->xmax = CurrentDevice->width;
70: cursor->ymax = CurrentDevice->height;
71:
72: cursor->refcnt = 1;
73:
74: data = (CursPriv *) Xalloc(sizeof(CursPriv));
75:
76: cursor->data = (caddr_t) data;
77:
78: data->image = MakePixmap(image, fore, back);
79: data->image->tile = CannotBeTiled;
80: data->mask = mask;
81: if (mask) {
82: mask->refcnt++;
83: }
84: data->func = func;
85: data->fore = fore;
86: data->back = back;
87:
88: bitmap = StoreBitmap(image->width, image->height, (char *)NULL);
89: data->save = MakePixmap(bitmap, fore, back);
90: data->save->tile = CannotBeTiled;
91: return (cursor);
92: }
93:
94: /*
95: * FreeCursor
96: */
97: FreeCursor(cursor)
98: CURSOR *cursor;
99: {
100: register CursPriv *cp = CDATA(cursor);
101:
102: #ifdef DEBUG
103: if (debug & D_Cursor)
104: printf("FreeCursor(cursor=0x%x)\n", cursor);
105: #endif DEBUG
106:
107: FreePixmap(cp->image);
108: if (cp->mask) {
109: FreeBitmap(cp->mask);
110: }
111: FreePixmap(cp->save);
112: free((caddr_t) cp);
113: free((caddr_t) cursor);
114: }
115:
116: /*
117: * LoadCursor
118: */
119: LoadCursor(cursor)
120: register CURSOR *cursor;
121: {
122:
123: #ifdef DEBUG
124: if (debug & D_Cursor)
125: printf("LoadCursor(cursor=0x%x)\n", cursor);
126: #endif DEBUG
127:
128: if (CurrentCursor != cursor) {
129: if (CursorDisplayed) {
130: DisplayCursor((CURSOR *)NULL);
131: }
132: if ((CurrentCursor = cursor) != NULL) {
133: DisplayCursor(cursor);
134: }
135: }
136: }
137:
138: /*
139: * InitMouse
140: */
141: static short sbounds[4];
142: InitMouse()
143: {
144: #ifdef DEBUG
145: if (debug & D_Misc)
146: printf("InitMouse()\n");
147: #endif DEBUG
148: sbounds[0] = 0;
149: sbounds[1] = ScreenPixmap.width;
150: sbounds[2] = 0;
151: sbounds[3] = ScreenPixmap.height;
152: }
153:
154:
155: /*
156: * SetCursorPosition
157: */
158: SetCursorPosition(pos)
159: register vsCursor *pos;
160: {
161: extern int indev, invalid_mouse;
162:
163: #ifdef DEBUG
164: if (debug & D_Cursor)
165: printf("SetCursorPosition(pos->x=%d, pos->y=%d)\n", pos->x, pos->y);
166: #endif DEBUG
167:
168: if (pos->x != (CurrentDevice->mouse->x) ||
169: pos->y != (CurrentDevice->mouse->y)) {
170: /* keep mouse in sync with cursor */
171: short mbounds[4];
172: mbounds[0] = mbounds[1] = pos->x;
173: mbounds[2] = mbounds[3] = pos->y;
174: ioctl(indev, TIOUMBND, mbounds); /* warps mouse cursor */
175: ioctl(indev, TIOUMBND, sbounds); /* sets bounds back */
176: invalid_mouse = 1;
177: UpdateCursorPosition(pos);
178: }
179: }
180:
181: vsCursor last_mouse; /* last known mouse position */
182:
183: /*
184: * UpdateCursorPosition
185: */
186: UpdateCursorPosition(pos)
187: register vsCursor *pos;
188: {
189:
190: #ifdef DEBUG
191: if (debug & D_Cursor)
192: printf("UpdateCursorPosition(pos->x=%d, pos->y=%d)\n", pos->x, pos->y);
193: #endif DEBUG
194:
195: /* assumes mouse is in sync with cursor */
196: if (pos->x != (CurrentDevice->mouse->x) ||
197: pos->y != (CurrentDevice->mouse->y)) {
198: if (CursorDisplayed) {
199: DisplayCursor((CURSOR *)NULL);
200: }
201: *(CurrentDevice->mouse) = *pos;
202: last_mouse = *pos; /* update last mouse position */
203: DisplayCursor(CurrentCursor);
204: }
205: }
206:
207: SetMouseCharacteristics(threshold, acceleration)
208: int threshold, acceleration;
209: {
210: extern int mouse_threshold, mouse_acceleration;
211: #ifdef DEBUG
212: if (debug & D_Misc)
213: printf("SetMouseCharacteristics(threshold=%d, acceleration=%d)\n",
214: threshold, acceleration);
215: #endif DEBUG
216: mouse_threshold = threshold;
217: mouse_acceleration = acceleration;
218: }
219:
220: /*
221: * DisplayCursor
222: */
223: static DisplayCursor(cursor)
224: CURSOR *cursor;
225: {
226: register vsCursor *ms = CurrentDevice->mouse;
227: register CursPriv *cp = CDATA(cursor);
228: register int x = ms->x;
229: register int y = ms->y;
230: CLIP i;
231: CLIP bc, bs;
232:
233: #ifdef DEBUG
234: if (debug & D_Cursor)
235: printf("DisplayCursor(cursor=0x%x)\n", cursor);
236: #endif DEBUG
237:
238: bs.left = 0;
239: bs.width = ScreenPixmap.width;
240: bs.top = 0;
241: bs.height = ScreenPixmap.height;
242:
243: if (cursor == NULL) {
244: if (CurrentCursor) {
245: /* pick up cursor (put background back) */
246: cp = CDATA(CurrentCursor);
247: bc.left = x;
248: bc.width = CurrentCursor->width;
249: bc.top = y;
250: bc.height = CurrentCursor->height;
251: i = Intersection(bc, bs);
252:
253: GIP_RasterOp(GIPcopy,
254: cp->save, i.left-x, i.top-y,
255: &ScreenPixmap, i.left, i.top,
256: (BITMAP *)NULL, 0, 0,
257: i.width, i.height,
258: ~0);
259:
260: CursorDisplayed = 0;
261: }
262: } else {
263: bc.left = x;
264: bc.width = cursor->width;
265: bc.top = y;
266: bc.height = cursor->height;
267: i = Intersection(bc, bs);
268:
269: /* save background */
270: GIP_RasterOp(GIPcopy,
271: &ScreenPixmap, i.left, i.top,
272: cp->save, i.left-x, i.top-y,
273: (BITMAP *)NULL, 0, 0,
274: i.width, i.height,
275: ~0);
276:
277: /* put cursor down */
278: GIP_RasterOp((unsigned char)(cp->func),
279: cp->image, i.left-x, i.top-y,
280: &ScreenPixmap, i.left, i.top,
281: cp->mask, i.left-x, i.top-y,
282: i.width, i.height,
283: ~0);
284:
285: CursorDisplayed = 1;
286: }
287: }
288:
289: /*
290: * CheckCursor
291: */
292: CheckCursor(r1)
293: CLIP r1;
294: {
295: register vsCursor *ms = CurrentDevice->mouse;
296: register CURSOR *cursor = CurrentCursor;
297:
298: CLIP r2;
299:
300: #ifdef DEBUG
301: if (debug & D_Cursor) {
302: printf("CheckCursor()\n");
303: printf_clip(" bounds", r1);
304: }
305: #endif DEBUG
306:
307: if (cursor == NULL) {
308: return;
309: }
310:
311: r2.left = ms->x;
312: r2.top = ms->y;
313: r2.width = cursor->width;
314: r2.height = cursor->height;
315:
316: #ifdef DEBUG
317: if (debug & D_Cursor)
318: printf_clip(" cursor", r2);
319: #endif DEBUG
320:
321: if (CursorDisplayed && Overlap(r1, r2)) {
322: DisplayCursor((CURSOR *)NULL);
323: }
324: }
325:
326: /*
327: * RestoreCursor
328: */
329: RestoreCursor()
330: {
331:
332: #ifdef DEBUG
333: if (debug & D_Cursor)
334: printf("RestoreCursor()\n");
335: #endif DEBUG
336:
337: if (!CursorDisplayed) {
338: DisplayCursor(CurrentCursor);
339: }
340: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.