glut: Fix build.
[mesa.git] / src / glut / glx / glut_joy.c
1
2 /* Copyright (c) Mark J. Kilgard, 1997, 1998. */
3
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
7
8 #ifdef _WIN32
9 #ifdef __MINGW32__
10 #include <GL/gl.h>
11 #endif
12 #include <windows.h>
13 #ifndef __CYGWIN32__
14 #include <mmsystem.h> /* Win32 Multimedia API header. */
15 #endif
16 #endif
17
18 #include "glutint.h"
19
20 /* CENTRY */
21 void GLUTAPIENTRY
22 glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval)
23 {
24 #ifdef _WIN32
25 if (joystickFunc && (pollInterval > 0)) {
26 if (__glutCurrentWindow->entryState == WM_SETFOCUS) {
27 MMRESULT result;
28
29 /* Capture joystick focus if current window has
30 focus now. */
31 result = joySetCapture(__glutCurrentWindow->win,
32 JOYSTICKID1, 0, TRUE);
33 if (result == JOYERR_NOERROR) {
34 (void) joySetThreshold(JOYSTICKID1, pollInterval);
35 }
36 }
37 __glutCurrentWindow->joyPollInterval = pollInterval;
38 } else {
39 /* Release joystick focus if current window has
40 focus now. */
41 if (__glutCurrentWindow->joystick
42 && (__glutCurrentWindow->joyPollInterval > 0)
43 && (__glutCurrentWindow->entryState == WM_SETFOCUS)) {
44 (void) joyReleaseCapture(JOYSTICKID1);
45 }
46 __glutCurrentWindow->joyPollInterval = 0;
47 }
48 __glutCurrentWindow->joystick = joystickFunc;
49 #else
50 /* XXX No support currently for X11 joysticks. */
51 #endif
52 }
53
54 void GLUTAPIENTRY
55 glutForceJoystickFunc(void)
56 {
57 #ifdef _WIN32
58 if (__glutCurrentWindow->joystick) {
59 JOYINFOEX jix;
60 MMRESULT res;
61 int x, y, z;
62
63 /* Poll the joystick. */
64 jix.dwSize = sizeof(jix);
65 jix.dwFlags = JOY_RETURNALL;
66 res = joyGetPosEx(JOYSTICKID1,&jix);
67 if (res == JOYERR_NOERROR) {
68
69 /* Convert to int for scaling. */
70 x = jix.dwXpos;
71 y = jix.dwYpos;
72 z = jix.dwZpos;
73
74 #define SCALE(v) ((int) ((v - 32767)/32.768))
75
76 __glutCurrentWindow->joystick(jix.dwButtons,
77 SCALE(x), SCALE(y), SCALE(z));
78 }
79 }
80 #else
81 /* XXX No support currently for X11 joysticks. */
82 #endif
83 }
84
85 /* ENDCENTRY */