|
|
1.1 root 1: /*
2: * X window system version 10.3
3: * Copyright (c) 1985, 1986 Massachusets Institute of Technology
4: *
5: * Sun implementation dependent library
6: * Copyright (c) 1983, 1984, 1985, 1986 Sun Microsystems, Inc.
7: *
8: * $Author: swick $
9: * $Source: /u1/X/libsun/RCS/cursor.c,v $
10: * $Revision: 10.5 $
11: * $Date: 86/12/17 20:32:30 $
12: *
13: */
14:
15: #ifndef lint
16: static char rcs_id[] = "$Header: cursor.c,v 10.5 86/12/17 20:32:30 swick Exp $";
17: #endif !lint
18:
19: #ifdef sun
20:
21: /* cursor.c various stuff with the mouse & cursor
22: *
23: * StoreCursor Creates a cursor
24: * FreeCursor Frees the storage taken by a cursor
25: * LoadCursor Loads a bitmap to use as cursor
26: * InitMouse Initialize the mouse
27: * SetCursorPosition Forces cursor to a particular position
28: * SetMouseCharacteristics Controls speed of cursor relative to mouse
29: *
30: */
31:
32: /*
33: * ToDo:
34: * Use macros for CheckCursor()
35: */
36:
37: #include "Xsun.h"
38:
39: extern struct pixrect *PixRect;
40: extern char *Xalloc();
41: extern DEVICE *CurrentDevice;
42: extern int vsdev;
43: CURSOR *CurrentCursor;
44: int CursorDisplayed;
45: static struct pixrect *CursorPixrect;
46:
47: CURSOR *StoreCursor (func, image, fore, back, mask, xoff, yoff)
48: BITMAP *image;
49: BITMAP *mask;
50: int func, fore, back, xoff, yoff;
51: {
52: register CURSOR *cursor;
53: register CursPriv *data;
54:
55: if (!image)
56: return (NULL);
57: cursor = (CURSOR *) Xalloc(sizeof(CURSOR));
58: cursor->width = image->width;
59: cursor->height = image->height;
60: /* Only the tip need be on-screen */
61: cursor->xmin = 0;
62: cursor->ymin = 0;
63: cursor->xoff = xoff;
64: cursor->yoff = yoff;
65: cursor->xmax = PixRect->pr_size.x;
66: cursor->ymax = PixRect->pr_size.y;
67: cursor->refcnt = 1;
68: data = (CursPriv *) Xalloc(sizeof(CursPriv));
69: cursor->data = (caddr_t) data;
70: data->top = mem_point(image->width, image->height, 1, image->data);
71: if (fore && back || !fore && !back)
72: if (fore)
73: data->c_func = PIX_SRC | PIX_NOT(PIX_SRC);
74: else
75: data->c_func = PIX_SRC & PIX_NOT(PIX_SRC);
76: else if (fore && WhitePixel)
77: data->c_func = SUN_FROM_X_OP(func);
78: else
79: data->c_func = SUN_FROM_X_OP_INVERT(func);
80: data->top_bit = image;
81: image->refcnt++;
82: if (mask) {
83: data->bot = mem_point(mask->width, mask->height, 1,
84: mask->data);
85: data->bot_bit = mask;
86: mask->refcnt++;
87: } else {
88: data->bot = NULL;
89: data->bot_bit = NULL;
90: }
91: data->sv = mem_create(cursor->width, cursor->height,
92: PixRect->pr_depth);
93: data->fore = fore;
94: data->back = back;
95: return (cursor);
96: }
97:
98: FreeCursor (cursor)
99: register CURSOR *cursor;
100: {
101: CursPriv *cp = CDATA(cursor);
102: pr_destroy(cp->top);
103: if (cp->top_bit && --(cp->top_bit)->refcnt <= 0)
104: FreeBitmap(cp->top_bit);
105: if (cp->bot) {
106: pr_destroy(cp->bot);
107: if (cp->bot_bit && --(cp->bot_bit)->refcnt <= 0)
108: FreeBitmap(cp->bot_bit);
109: }
110: pr_destroy(cp->sv);
111: free((caddr_t) CDATA(cursor));
112: free((caddr_t) cursor);
113: }
114:
115: struct pr_prpos topbatch, botbatch;
116:
117: LoadCursor (cursor)
118: register CURSOR *cursor;
119: {
120: if (CursorDisplayed)
121: DisplayCursor(NULL);
122: if ((CurrentCursor = cursor) != NULL) {
123: topbatch.pr = CDATA(cursor)->top;
124: topbatch.pos.x = 0;
125: topbatch.pos.y = 0;
126: botbatch.pr = CDATA(cursor)->bot;
127: botbatch.pos.x = 0;
128: botbatch.pos.y = 0;
129: DisplayCursor(cursor);
130: }
131: }
132:
133: InitMouse ()
134: {
135: }
136:
137: SetCursorPosition(pos)
138: register vsCursor *pos;
139: {
140: if (pos->x != (CurrentDevice->mouse->x) || pos->y != (CurrentDevice->mouse->y)) {
141: if (CursorDisplayed)
142: DisplayCursor(NULL);
143: *(CurrentDevice->mouse) = *pos;
144: DisplayCursor(CurrentCursor);
145: win_setmouseposition(vsdev, pos->x, pos->y);
146: }
147: }
148:
149: SetMouseCharacteristics (threshold, accelaration)
150: int threshold, accelaration;
151: {
152: extern sunthreshold;
153: extern sunaccel;
154:
155: sunthreshold = threshold;
156: sunaccel = accelaration;
157: }
158:
159: DisplayCursor(cs)
160: CURSOR *cs;
161: {
162: extern struct pixrect *PixRect;
163: vsCursor *ms = CurrentDevice->mouse;
164:
165: if (cs == NULL) {
166: if (CurrentCursor) {
167: /* take it out */
168: extern int private_czmask;
169: int old_zmask = private_czmask;
170: int allmask = -1;
171:
172: SetZmask(PixRect, &allmask);
173: pr_rop(PixRect, ms->x, ms->y, CurrentCursor->width,
174: CurrentCursor->height, PIX_SRC,
175: CDATA(CurrentCursor)->sv, 0, 0);
176: SetZmask(PixRect, &old_zmask);
177: CursorDisplayed = 0;
178: }
179: } else {
180: CursPriv *cp = CDATA(cs);
181:
182: /* put it in */
183: pr_rop(cp->sv, 0, 0, cs->width, cs->height, PIX_SRC,
184: PixRect, ms->x, ms->y);
185: if (PixRect->pr_depth == 1) {
186: if (cp->bot != (struct pixrect *) NULL &&
187: cp->top != (struct pixrect *) NULL) {
188: pr_stencil(PixRect, ms->x, ms->y,
189: cs->width, cs->height,
190: cp->c_func,
191: cp->bot, 0, 0,
192: cp->top, 0, 0);
193: }
194: } else {
195: extern int private_bgcolor;
196: extern int private_fgcolor;
197: extern int private_czmask;
198: int old_zmask = private_czmask;
199:
200: private_bgcolor = -1;
201: private_czmask = -1;
202: if (botbatch.pr) {
203: private_fgcolor = cp->back;
204: pr_batchrop(PixRect, ms->x, ms->y,
205: PIX_SRC | PIX_DST,
206: &botbatch, 1);
207: }
208: private_fgcolor = cp->fore;
209: if (topbatch.pr)
210: pr_batchrop(PixRect, ms->x, ms->y,
211: PIX_NOT(PIX_SRC) & PIX_DST,
212: &topbatch, 1);
213: private_czmask = old_zmask;
214: }
215: CursorDisplayed = 1;
216: }
217: }
218:
219: int
220: CheckCursor(x, y, w, h)
221: {
222: register vsCursor *ms = CurrentDevice->mouse;
223: register CURSOR *cs = CurrentCursor;
224:
225: if (CursorDisplayed
226: && OverLap(x, y, w, h, ms->x, ms->y, cs->width, cs->height)) {
227: DisplayCursor(NULL);
228: }
229: }
230:
231: RestoreCursor()
232: {
233: if (!CursorDisplayed)
234: DisplayCursor(CurrentCursor);
235: }
236: #endif sun
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.