check event button against GLUT_MAX_MENUS (bug 1484284)
[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 #include <windows.h>
10 #ifndef __CYGWIN32__
11 #include <mmsystem.h> /* Win32 Multimedia API header. */
12 #endif
13 #endif
14
15 #include "glutint.h"
16
17 /* CENTRY */
18 void GLUTAPIENTRY
19 glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval)
20 {
21 #ifdef _WIN32
22 if (joystickFunc && (pollInterval > 0)) {
23 if (__glutCurrentWindow->entryState == WM_SETFOCUS) {
24 MMRESULT result;
25
26 /* Capture joystick focus if current window has
27 focus now. */
28 result = joySetCapture(__glutCurrentWindow->win,
29 JOYSTICKID1, 0, TRUE);
30 if (result == JOYERR_NOERROR) {
31 (void) joySetThreshold(JOYSTICKID1, pollInterval);
32 }
33 }
34 __glutCurrentWindow->joyPollInterval = pollInterval;
35 } else {
36 /* Release joystick focus if current window has
37 focus now. */
38 if (__glutCurrentWindow->joystick
39 && (__glutCurrentWindow->joyPollInterval > 0)
40 && (__glutCurrentWindow->entryState == WM_SETFOCUS)) {
41 (void) joyReleaseCapture(JOYSTICKID1);
42 }
43 __glutCurrentWindow->joyPollInterval = 0;
44 }
45 __glutCurrentWindow->joystick = joystickFunc;
46 #else
47 /* XXX No support currently for X11 joysticks. */
48 #endif
49 }
50
51 void GLUTAPIENTRY
52 glutForceJoystickFunc(void)
53 {
54 #ifdef _WIN32
55 if (__glutCurrentWindow->joystick) {
56 JOYINFOEX jix;
57 MMRESULT res;
58 int x, y, z;
59
60 /* Poll the joystick. */
61 jix.dwSize = sizeof(jix);
62 jix.dwFlags = JOY_RETURNALL;
63 res = joyGetPosEx(JOYSTICKID1,&jix);
64 if (res == JOYERR_NOERROR) {
65
66 /* Convert to int for scaling. */
67 x = jix.dwXpos;
68 y = jix.dwYpos;
69 z = jix.dwZpos;
70
71 #define SCALE(v) ((int) ((v - 32767)/32.768))
72
73 __glutCurrentWindow->joystick(jix.dwButtons,
74 SCALE(x), SCALE(y), SCALE(z));
75 }
76 }
77 #else
78 /* XXX No support currently for X11 joysticks. */
79 #endif
80 }
81
82 /* ENDCENTRY */