ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/msmouse.c
Revision: 2.2
Committed: Fri Oct 9 15:24:02 1992 UTC (31 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +19 -16 lines
Log Message:
Changes for 32-bit PC port

File Contents

# Content
1 /* Copyright (c) 1992 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 #include <i86.h>
8 #include <graph.h>
9 #include "driver.h"
10
11 #define M_RIGHTBUTT 0x8
12 #define M_LEFTBUTT 0x2
13 #define M_MOTION 0x1
14
15 static int xdispsize, ydispsize;
16 static int crad;
17 #define right_button (mouse_event & M_RIGHTBUTT)
18 #define left_button (mouse_event & M_LEFTBUTT)
19 static int mouse_event = 0;
20 static int mouse_xpos = -1;
21 static int mouse_ypos = -1;
22
23
24 #pragma off (check_stack)
25 static void _loadds far mouse_handler (int max, int mcx, int mdx)
26 {
27 #pragma aux mouse_handler parm [EAX] [ECX] [EDX]
28 mouse_event = max;
29 mouse_xpos = mcx;
30 mouse_ypos = mdx * (long)ydispsize / 200; /* kludge */
31 }
32 #pragma on (check_stack)
33
34
35 static void
36 move_cursor(newx, newy) /* move cursor to new position */
37 int newx, newy;
38 {
39 extern char *bmalloc();
40 static char *imp = NULL;
41 static int curx = -1, cury = -1;
42 #define xcmin (curx-crad<0 ? 0 : curx-crad)
43 #define ycmin (cury-crad<0 ? 0 : cury-crad)
44 #define xcmax (curx+crad>=xdispsize ? xdispsize-1 : curx+crad)
45 #define ycmax (cury+crad>=ydispsize ? ydispsize-1 : cury+crad)
46
47 if (imp == NULL &&
48 (imp = bmalloc(_imagesize(0,0,2*crad+1,2*crad+1))) == NULL) {
49 eputs("out of memory in move_cursor");
50 quit(1);
51 }
52 if (curx >= 0 & cury >= 0) /* clear old cursor */
53 _putimage(xcmin, ycmin, imp, _GPSET);
54 /* record new position */
55 curx = newx; cury = newy;
56 if (curx < 0 | cury < 0)
57 return; /* no cursor */
58 /* save under new cursor */
59 _getimage(xcmin, ycmin, xcmax, ycmax, imp);
60 /* draw new cursor */
61 _setcolor(1);
62 _rectangle(_GFILLINTERIOR, xcmin, cury-1, xcmax, cury+1);
63 _rectangle(_GFILLINTERIOR, curx-1, ycmin, curx+1, ycmax);
64 _setcolor(0);
65 _moveto(xcmin+1, cury);
66 _lineto(xcmax-1, cury);
67 _moveto(curx, ycmin+1);
68 _lineto(curx, ycmax-1);
69 #undef xcmin
70 #undef ycmin
71 #undef xcmax
72 #undef ycmax
73 }
74
75
76 static int
77 ms_getcur(xp, yp) /* get mouse cursor position */
78 int *xp, *yp;
79 {
80 /* show cursor */
81
82 move_cursor(mouse_xpos, mouse_ypos);
83
84 /* update cursor until button pressed */
85
86 do {
87 mouse_event = 0;
88 while( !mouse_event )
89 if (kbhit())
90 switch (getch()) {
91 case MB1:
92 mouse_event = M_LEFTBUTT;
93 break;
94 case MB2:
95 case MB3:
96 mouse_event = M_RIGHTBUTT;
97 break;
98 default:
99 mouse_event = M_RIGHTBUTT | M_LEFTBUTT;
100 break;
101 }
102 if (mouse_event & M_MOTION)
103 move_cursor(mouse_xpos, mouse_ypos);
104 } while (!(mouse_event & (M_RIGHTBUTT|M_LEFTBUTT)));
105
106 /* clear cursor */
107
108 move_cursor(-1, -1);
109
110 /* compute final position */
111
112 if (mouse_xpos < 0 | mouse_ypos < 0)
113 return(ABORT);
114
115 *xp = mouse_xpos;
116 *yp = ydispsize-1 - mouse_ypos;
117
118 switch (mouse_event) {
119 case M_LEFTBUTT:
120 case M_LEFTBUTT|M_MOTION:
121 return(MB1);
122 case M_RIGHTBUTT:
123 case M_RIGHTBUTT|M_MOTION:
124 return(MB2);
125 }
126 return(ABORT);
127 }
128
129
130 void
131 ms_gcinit( dp )
132 struct driver *dp;
133 {
134 struct SREGS sregs;
135 union REGS inregs, outregs;
136 int far *ptr;
137 int (far *function_ptr)();
138
139 segread(&sregs);
140
141 /* check for mouse driver */
142
143 inregs.w.ax = 0;
144 int386 (0x33, &inregs, &outregs);
145 if( outregs.w.ax != -1 ) {
146 dp->getcur = NULL;
147 return;
148 }
149
150 /* get relevant parameters */
151
152 xdispsize = dp->xsiz;
153 ydispsize = dp->ysiz;
154 crad = dp->ysiz/40;
155
156 /* install watcher */
157
158 inregs.w.ax = 0xC;
159 inregs.w.cx = M_RIGHTBUTT | M_LEFTBUTT | M_MOTION;
160 function_ptr = mouse_handler;
161 inregs.x.edx = FP_OFF( function_ptr );
162 sregs.es = FP_SEG( function_ptr );
163 int386x( 0x33, &inregs, &outregs, &sregs );
164
165 dp->getcur = ms_getcur;
166 }