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.
16 #define WIN32_LEAN_AND_MEAN
31 #define ME_CURSOR_MOVED (1<<0)
32 #define ME_LB_P (1<<1)
33 #define ME_LB_R (1<<2)
34 #define ME_RB_P (1<<3)
35 #define ME_RB_R (1<<4)
36 #define ME_MB_P (1<<5)
37 #define ME_MB_R (1<<6)
38 #define ME_OB_P (1<<7)
39 #define ME_OB_R (1<<8)
41 #define ME_Y_C (1<<10)
42 #define ME_Z_C (1<<11)
43 #define ME_P_C (1<<12)
44 #define ME_B_C (1<<13)
45 #define ME_H_C (1<<14)
46 #define ME_O_C (1<<15)
48 #define MOUSE_MAX_BUTTONS 11
50 typedef struct event_info {
58 ushort device_dependant;
61 typedef struct mouse_info {
65 ubyte pressed[MOUSE_MAX_BUTTONS];
66 fix time_went_down[MOUSE_MAX_BUTTONS];
67 fix time_held_down[MOUSE_MAX_BUTTONS];
68 uint num_downs[MOUSE_MAX_BUTTONS];
69 uint num_ups[MOUSE_MAX_BUTTONS];
74 typedef struct cyberman_info {
81 ubyte pitch_descriptor;
82 ubyte roll_descriptor;
87 static mouse_info Mouse;
89 static int Mouse_installed = 0;
90 static HWND _hMouseWnd = 0;
91 static Mouse_center = 0;
93 extern int timer_initialized;
96 void mouse_set_window(HWND wnd)
101 int Save_x=320,Save_y=240;
103 #define MOUSE_CENTER_X 160
104 #define MOUSE_CENTER_Y 100
106 int mouse_set_mode(int i)
110 if (i) Mouse_center = 1;
111 else Mouse_center = 0;
115 mouse_get_pos( &Save_x, &Save_y); //save current pos
116 mouse_get_delta(&x,&y); //flush old movement
119 mouse_set_pos( Save_x, Save_y); //restore pos
126 //--------------------------------------------------------
127 // returns 0 if no mouse
128 // else number of buttons
130 int mouse_init(int enable_cyberman)
137 atexit( mouse_close );
149 if (Mouse_installed) {
156 void mouse_set_limits( int x1, int y1, int x2, int y2 )
161 void mouse_get_pos( int *x, int *y)
165 GetCursorPos(&point);
167 //ScreenToClient(_hMouseWnd, &point);
172 void mouse_get_delta( int *dx, int *dy )
176 GetCursorPos(&point);
177 *dx = (point.x-MOUSE_CENTER_X)/2;
178 *dy = (point.y-MOUSE_CENTER_Y)/2;
180 //mprintf((0,"C=%d (%d,%d) (%d,%d) ",Mouse_center,point.x,point.y,*dx,*dy));
183 //SetCursorPos (320,240);
184 SetCursorPos (MOUSE_CENTER_X,MOUSE_CENTER_Y);
193 for (i=0; i<MOUSE_MAX_BUTTONS; i++ ) {
194 if (Mouse.pressed[i])
201 void mouse_set_pos( int x, int y)
207 ClientToScreen(_hMouseWnd, &point);
208 SetCursorPos(point.x, point.y);
217 //Clear the mouse data
218 CurTime =timer_get_fixed_secondsX();
219 for (i=0; i<MOUSE_MAX_BUTTONS; i++ ) {
220 Mouse.pressed[i] = 0;
221 Mouse.time_went_down[i] = CurTime;
222 Mouse.time_held_down[i] = 0;
223 Mouse.num_downs[i]=0;
229 // Returns how many times this button has went down since last call.
230 int mouse_button_down_count(int button)
235 count = Mouse.num_downs[button];
236 Mouse.num_downs[button]=0;
241 // Returns 1 if this button is currently down
242 int mouse_button_state(int button)
247 state = Mouse.pressed[button];
254 // Returns how long this button has been down since last call.
255 fix mouse_button_down_time(int button)
260 if ( !Mouse.pressed[button] ) {
261 time_down = Mouse.time_held_down[button];
262 Mouse.time_held_down[button] = 0;
264 time = timer_get_fixed_secondsX();
265 time_down = time - Mouse.time_went_down[button];
266 Mouse.time_went_down[button] = time;
272 void mouse_get_cyberman_pos( int *x, int *y )
279 // Mouse Callback from windows
281 void mouse_win_callback(UINT msg, UINT wParam, UINT lParam)
283 if (!timer_initialized) return;
285 Mouse.ctime = timer_get_fixed_secondsX();
290 mprintf ((0,"Left down!\n"));
292 if (!Mouse.pressed[MB_LEFT]) {
293 Mouse.pressed[MB_LEFT] = 1;
294 Mouse.time_went_down[MB_LEFT] = Mouse.ctime;
296 Mouse.num_downs[MB_LEFT]++;
300 if (Mouse.pressed[MB_LEFT]) {
301 Mouse.pressed[MB_LEFT] = 0;
302 Mouse.time_held_down[MB_LEFT] += Mouse.ctime-Mouse.time_went_down[MB_LEFT];
304 Mouse.num_ups[MB_LEFT]++;
309 mprintf ((0,"Right down!\n"));
310 if (!Mouse.pressed[MB_RIGHT]) {
311 Mouse.pressed[MB_RIGHT] = 1;
312 Mouse.time_went_down[MB_RIGHT] = Mouse.ctime;
314 Mouse.num_downs[MB_RIGHT]++;
318 if (Mouse.pressed[MB_RIGHT]) {
319 Mouse.pressed[MB_RIGHT] = 0;
320 Mouse.time_held_down[MB_RIGHT] += Mouse.ctime-Mouse.time_went_down[MB_RIGHT];
322 Mouse.num_ups[MB_RIGHT]++;
326 if (!Mouse.pressed[MB_MIDDLE]) {
327 Mouse.pressed[MB_MIDDLE] = 1;
328 Mouse.time_went_down[MB_MIDDLE] = Mouse.ctime;
330 Mouse.num_downs[MB_MIDDLE]++;
334 if (Mouse.pressed[MB_MIDDLE]) {
335 Mouse.pressed[MB_MIDDLE] = 0;
336 Mouse.time_held_down[MB_MIDDLE] += Mouse.ctime-Mouse.time_went_down[MB_MIDDLE];
338 Mouse.num_ups[MB_MIDDLE]++;