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-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * Functions to access Mouse and Cyberman...
19 #define WIN32_LEAN_AND_MEAN
34 // These are to kludge up a bit my slightly broken GCC directx port.
36 #define E_FAIL (HRESULT)0x80004005L
39 #define SUCCEEDED(a) ((HRESULT)(a) >= 0)
45 #ifndef SEVERITY_SUCCESS
46 #define SEVERITY_SUCCESS 0
47 #define SEVERITY_ERROR 1
49 #ifndef FACILITY_WIN32
50 #define FACILITY_WIN32 7
53 #define FIELD_OFFSET(type, field) ((LONG)&(((type *)0)->field))
56 #define ME_CURSOR_MOVED (1<<0)
57 #define ME_LB_P (1<<1)
58 #define ME_LB_R (1<<2)
59 #define ME_RB_P (1<<3)
60 #define ME_RB_R (1<<4)
61 #define ME_MB_P (1<<5)
62 #define ME_MB_R (1<<6)
63 #define ME_OB_P (1<<7)
64 #define ME_OB_R (1<<8)
66 #define ME_Y_C (1<<10)
67 #define ME_Z_C (1<<11)
68 #define ME_P_C (1<<12)
69 #define ME_B_C (1<<13)
70 #define ME_H_C (1<<14)
71 #define ME_O_C (1<<15)
73 typedef struct event_info {
81 ushort device_dependant;
84 typedef struct mouse_info {
88 ubyte pressed[MOUSE_MAX_BUTTONS];
89 fix time_went_down[MOUSE_MAX_BUTTONS];
90 fix time_held_down[MOUSE_MAX_BUTTONS];
91 uint num_downs[MOUSE_MAX_BUTTONS];
92 uint num_ups[MOUSE_MAX_BUTTONS];
93 // ubyte went_down; /* Not in PC version, not needed with 'num_downs' etc */
98 typedef struct cyberman_info {
105 ubyte pitch_descriptor;
106 ubyte roll_descriptor;
107 ubyte yaw_descriptor;
111 static mouse_info Mouse;
113 static int Mouse_installed = 0;
115 int WMMouse_Handler_Ready = 0;
116 int mouse_wparam, mouse_lparam, mouse_msg;
120 //extern ggi_visual_t visual;
121 //extern ggi_directbuffer_t dbuf; // GGI direct acces to screen memory
122 //extern ggi_pixellinearbuffer *plb;
125 static double mouse_x, mouse_y;
126 static double mouse_saved_x, mouse_saved_y; //used when hiding/unhiding to reset the real (displayed) postion
127 double mouse_accel=1.0;
129 void DrawMouse(void);
130 void EraseMouse(void);
131 void MoveMouse(/*int button,*/ int x, int y);
133 #define WIN_WIDTH 640
134 #define WIN_HEIGHT 480
135 #define SCR_WIDTH 640
136 #define SCR_HEIGHT 480
138 LPDIRECTINPUT g_lpdi = NULL;
139 LPDIRECTINPUTDEVICE g_lpdidMouse = NULL;
143 HRESULT ReadMouse (DIDEVICEOBJECTDATA *pdidod)
148 if (g_lpdidMouse == NULL)
151 hr = IDirectInputDevice_GetDeviceData (
158 if (hr == DIERR_INPUTLOST)
160 hr = IDirectInputDevice_Acquire (g_lpdidMouse);
163 hr = IDirectInputDevice_GetDeviceData (
172 if (SUCCEEDED (hr) && cElements != 1)
179 void UpdateMouseState (DIDEVICEOBJECTDATA *pdidod)
181 // fix timeNow = timer_get_fixed_seconds ();
183 ULONG iEvt = pdidod->dwOfs;
191 BOOL bPressed = pdidod->dwData & 0x80;
192 ULONG iButton = (iEvt - DIMOFS_BUTTON0) + MB_LEFT;
195 if (!Mouse.pressed [iButton])
197 Mouse.pressed [iButton] = 1;
198 Mouse.time_went_down [iButton] = Mouse.ctime;
199 Mouse.num_downs [iButton]++;
200 // Mouse.went_down = 1;
202 Mouse.num_downs [iButton] ++;
206 if (Mouse.pressed [iButton])
208 Mouse.pressed [iButton] = 0;
209 Mouse.time_held_down [iButton] += Mouse.ctime - Mouse.time_went_down [iButton];
210 Mouse.num_ups [iButton]++;
211 // Mouse.went_down = 0;
217 mouse_x += (double) ((LONG) pdidod->dwData);
221 mouse_y += (double) ((LONG) pdidod->dwData);
224 break;//hm, handle this?
226 mprintf((0,"unknown mouse event %i\n",iEvt));
227 // exit (iEvt);//not happy.
234 DIDEVICEOBJECTDATA didod;
236 Mouse.ctime = timer_get_fixed_seconds();
238 while (SUCCEEDED (ReadMouse (&didod)))
240 UpdateMouseState (&didod);
249 if (!Mouse_installed)
254 CurTime = timer_get_fixed_seconds();
255 for (i = 0; i < MOUSE_MAX_BUTTONS; i++) {
256 Mouse.pressed[i] = 0;
257 Mouse.time_went_down[i] = CurTime;
258 Mouse.time_held_down[i] = 0;
259 Mouse.num_downs[i] = 0;
260 Mouse.num_ups[i] = 0;
262 // Mouse.went_down = 0; /* mac only */
266 DWORD cElements = INFINITE;
268 IDirectInputDevice_GetDeviceData (
270 sizeof (DIDEVICEOBJECTDATA),
278 void mouse_close(void)
280 // if (Mouse_installed) // DPH: Unnecessary...
281 WMMouse_Handler_Ready=Mouse_installed = 0;
283 if (g_lpdidMouse != NULL)
285 IDirectInputDevice_Unacquire (g_lpdidMouse);
286 IDirectInputDevice_Release (g_lpdidMouse);
291 IDirectInput_Release (g_lpdi);
298 int mouse_init(int unused)
300 if (FindArg("-nomouse"))
303 return Mouse.num_buttons;
308 if (SUCCEEDED (hr = DirectInputCreate (GetModuleHandle (NULL), DIRECTINPUT_VERSION, &g_lpdi, NULL)))
310 if (SUCCEEDED (hr = IDirectInput_CreateDevice (g_lpdi,(void *) &GUID_SysMouse, &g_lpdidMouse, NULL)))
313 dipdw.diph.dwSize = sizeof (DIPROPDWORD);
314 dipdw.diph.dwHeaderSize = sizeof (DIPROPHEADER);
315 dipdw.diph.dwObj = 0;
316 dipdw.diph.dwHow = DIPH_DEVICE;
319 if (SUCCEEDED (hr = IDirectInputDevice_SetDataFormat (g_lpdidMouse, &c_dfDIMouse)) &&
320 //changed on 9/4/99 by Victor Rachels NONEX -> Exclusive
321 SUCCEEDED (hr = IDirectInputDevice_SetCooperativeLevel (g_lpdidMouse, g_hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND)) &&
322 //end this section edit -VR
323 SUCCEEDED (hr = IDirectInputDevice_SetProperty (g_lpdidMouse, DIPROP_BUFFERSIZE, &dipdw.diph)) &&
324 SUCCEEDED (hr = IDirectInputDevice_Acquire (g_lpdidMouse)))
329 IDirectInputDevice_Release (g_lpdidMouse);
336 Mouse.num_buttons = 3;
338 WMMouse_Handler_Ready=Mouse_installed = 1;
341 // mouse_set_center();
343 return Mouse.num_buttons;
347 void mouse_center() {
348 mouse_x=mouse_saved_x=WIN_WIDTH/2;
349 mouse_y=mouse_saved_y=WIN_HEIGHT/2;
352 void mouse_get_pos( int *x, int *y)
354 mouse_handler(); //temp
360 void mouse_get_delta( int *dx, int *dy )
362 if (!Mouse_installed) {
366 mouse_handler(); //temp
368 *dx = (int) mouse_x - WIN_WIDTH/2;
369 *dy = (int) mouse_y - WIN_HEIGHT/2;
371 //Now reset the mouse position to the center of the screen
372 mouse_x = (double) WIN_WIDTH/2;
373 mouse_y = (double) WIN_HEIGHT/2;
376 void mouse_get_delta_no_reset( int *dx, int *dy )
378 if (!Mouse_installed) {
382 mouse_handler(); //temp
384 *dx = (int) mouse_x - WIN_WIDTH/2;
385 *dy = (int) mouse_y - WIN_HEIGHT/2;
394 if (!Mouse_installed)
397 mouse_handler(); //temp
399 for (i = 0; i < MOUSE_MAX_BUTTONS; i++) {
400 if (Mouse.pressed[i])
407 /* This should be replaced with mouse_button_down_count(int button) */
408 int mouse_went_down(int button)
412 if (!Mouse_installed)
415 mouse_handler(); //temp
417 if ((button < 0) || (button >= MOUSE_MAX_BUTTONS))
421 count = Mouse.num_downs[button];
422 Mouse.num_downs[button] = 0;
428 // Returns how many times this button has went down since last call.
429 int mouse_button_down_count(int button)
433 if (!Mouse_installed)
436 mouse_handler(); //temp
438 if ((button < 0) || (button >= MOUSE_MAX_BUTTONS))
442 count = Mouse.num_downs[button];
443 Mouse.num_downs[button] = 0;
448 // Returns 1 if this button is currently down
449 int mouse_button_state(int button)
453 if (!Mouse_installed)
456 mouse_handler(); //temp
458 if ((button < 0) || (button >= MOUSE_MAX_BUTTONS))
462 state = Mouse.pressed[button];
467 // Returns how long this button has been down since last call.
468 fix mouse_button_down_time(int button)
472 if (!Mouse_installed)
475 mouse_handler(); //temp
477 if ((button < 0) || (button >= MOUSE_MAX_BUTTONS))
481 if (!Mouse.pressed[button]) {
482 time_down = Mouse.time_held_down[button];
483 Mouse.time_held_down[button] = 0;
485 time = timer_get_fixed_seconds();
486 time_down = time - Mouse.time_held_down[button];
487 Mouse.time_held_down[button] = 0;
494 void mouse_get_cyberman_pos( int *x, int *y )
500 //WHS: I made this :)
512 /* New mouse pointer stuff for GGI/DGA */
513 //#include "cursor.h" /* cursor and mask */
515 typedef struct Sprite {
522 //Sprite mouse_sprite = { cursor_width, cursor_height, cursor_bits, cursor_mask_bits};
524 //byte *behind_mouse;
525 //byte behind_mouse[cursor_width*cursor_height];
533 void EraseMouse(void)
537 //Should add a mode, relative, absolute
540 //void MoveMouse(int mode, int x, int y) {
542 void MoveMouse(int x, int y)