ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/msmouse.c
Revision: 2.1
Committed: Thu Oct 8 16:20:48 1992 UTC (31 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

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