2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 #pragma off (unreferenced)
16 static char rcsid[] = "$Id: mouse.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
17 #pragma on (unreferenced)
20 #define WIN32_LEAN_AND_MEAN
35 #define ME_CURSOR_MOVED (1<<0)
36 #define ME_LB_P (1<<1)
37 #define ME_LB_R (1<<2)
38 #define ME_RB_P (1<<3)
39 #define ME_RB_R (1<<4)
40 #define ME_MB_P (1<<5)
41 #define ME_MB_R (1<<6)
42 #define ME_OB_P (1<<7)
43 #define ME_OB_R (1<<8)
45 #define ME_Y_C (1<<10)
46 #define ME_Z_C (1<<11)
47 #define ME_P_C (1<<12)
48 #define ME_B_C (1<<13)
49 #define ME_H_C (1<<14)
50 #define ME_O_C (1<<15)
52 #define MOUSE_MAX_BUTTONS 11
54 typedef struct event_info {
62 ushort device_dependant;
65 typedef struct mouse_info {
69 ubyte pressed[MOUSE_MAX_BUTTONS];
70 fix time_went_down[MOUSE_MAX_BUTTONS];
71 fix time_held_down[MOUSE_MAX_BUTTONS];
72 uint num_downs[MOUSE_MAX_BUTTONS];
73 uint num_ups[MOUSE_MAX_BUTTONS];
78 typedef struct cyberman_info {
85 ubyte pitch_descriptor;
86 ubyte roll_descriptor;
91 static mouse_info Mouse;
93 static int Mouse_installed = 0;
94 static HWND _hMouseWnd = 0;
95 static Mouse_center = 0;
97 extern int timer_initialized;
100 void mouse_set_window(HWND wnd)
105 int Save_x=320,Save_y=240;
107 #define MOUSE_CENTER_X 160
108 #define MOUSE_CENTER_Y 100
110 int mouse_set_mode(int i)
114 if (i) Mouse_center = 1;
115 else Mouse_center = 0;
119 mouse_get_pos( &Save_x, &Save_y); //save current pos
120 mouse_get_delta(&x,&y); //flush old movement
123 mouse_set_pos( Save_x, Save_y); //restore pos
130 //--------------------------------------------------------
131 // returns 0 if no mouse
132 // else number of buttons
134 int mouse_init(int enable_cyberman)
141 atexit( mouse_close );
153 if (Mouse_installed) {
160 void mouse_set_limits( int x1, int y1, int x2, int y2 )
165 void mouse_get_pos( int *x, int *y)
169 GetCursorPos(&point);
171 //ScreenToClient(_hMouseWnd, &point);
176 void mouse_get_delta( int *dx, int *dy )
180 GetCursorPos(&point);
181 *dx = (point.x-MOUSE_CENTER_X)/2;
182 *dy = (point.y-MOUSE_CENTER_Y)/2;
184 //mprintf((0,"C=%d (%d,%d) (%d,%d) ",Mouse_center,point.x,point.y,*dx,*dy));
187 //SetCursorPos (320,240);
188 SetCursorPos (MOUSE_CENTER_X,MOUSE_CENTER_Y);
197 for (i=0; i<MOUSE_MAX_BUTTONS; i++ ) {
198 if (Mouse.pressed[i])
205 void mouse_set_pos( int x, int y)
211 ClientToScreen(_hMouseWnd, &point);
212 SetCursorPos(point.x, point.y);
221 //Clear the mouse data
222 CurTime =timer_get_fixed_secondsX();
223 for (i=0; i<MOUSE_MAX_BUTTONS; i++ ) {
224 Mouse.pressed[i] = 0;
225 Mouse.time_went_down[i] = CurTime;
226 Mouse.time_held_down[i] = 0;
227 Mouse.num_downs[i]=0;
233 // Returns how many times this button has went down since last call.
234 int mouse_button_down_count(int button)
239 count = Mouse.num_downs[button];
240 Mouse.num_downs[button]=0;
245 // Returns 1 if this button is currently down
246 int mouse_button_state(int button)
251 state = Mouse.pressed[button];
258 // Returns how long this button has been down since last call.
259 fix mouse_button_down_time(int button)
264 if ( !Mouse.pressed[button] ) {
265 time_down = Mouse.time_held_down[button];
266 Mouse.time_held_down[button] = 0;
268 time = timer_get_fixed_secondsX();
269 time_down = time - Mouse.time_went_down[button];
270 Mouse.time_went_down[button] = time;
276 void mouse_get_cyberman_pos( int *x, int *y )
283 // Mouse Callback from windows
285 void mouse_win_callback(UINT msg, UINT wParam, UINT lParam)
287 if (!timer_initialized) return;
289 Mouse.ctime = timer_get_fixed_secondsX();
294 mprintf ((0,"Left down!\n"));
296 if (!Mouse.pressed[MB_LEFT]) {
297 Mouse.pressed[MB_LEFT] = 1;
298 Mouse.time_went_down[MB_LEFT] = Mouse.ctime;
300 Mouse.num_downs[MB_LEFT]++;
304 if (Mouse.pressed[MB_LEFT]) {
305 Mouse.pressed[MB_LEFT] = 0;
306 Mouse.time_held_down[MB_LEFT] += Mouse.ctime-Mouse.time_went_down[MB_LEFT];
308 Mouse.num_ups[MB_LEFT]++;
313 mprintf ((0,"Right down!\n"));
314 if (!Mouse.pressed[MB_RIGHT]) {
315 Mouse.pressed[MB_RIGHT] = 1;
316 Mouse.time_went_down[MB_RIGHT] = Mouse.ctime;
318 Mouse.num_downs[MB_RIGHT]++;
322 if (Mouse.pressed[MB_RIGHT]) {
323 Mouse.pressed[MB_RIGHT] = 0;
324 Mouse.time_held_down[MB_RIGHT] += Mouse.ctime-Mouse.time_went_down[MB_RIGHT];
326 Mouse.num_ups[MB_RIGHT]++;
330 if (!Mouse.pressed[MB_MIDDLE]) {
331 Mouse.pressed[MB_MIDDLE] = 1;
332 Mouse.time_went_down[MB_MIDDLE] = Mouse.ctime;
334 Mouse.num_downs[MB_MIDDLE]++;
338 if (Mouse.pressed[MB_MIDDLE]) {
339 Mouse.pressed[MB_MIDDLE] = 0;
340 Mouse.time_held_down[MB_MIDDLE] += Mouse.ctime-Mouse.time_went_down[MB_MIDDLE];
342 Mouse.num_ups[MB_MIDDLE]++;