From a4dcdcf0ffae4c6cf52354fbd63c95d7d7815fd9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 19 Aug 1999 13:57:42 +0000 Subject: initial check-in (post crash) --- src/glut/glx/glut_joy.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/glut/glx/glut_joy.c (limited to 'src/glut/glx/glut_joy.c') diff --git a/src/glut/glx/glut_joy.c b/src/glut/glx/glut_joy.c new file mode 100644 index 0000000000..a7db032f53 --- /dev/null +++ b/src/glut/glx/glut_joy.c @@ -0,0 +1,80 @@ + +/* Copyright (c) Mark J. Kilgard, 1997, 1998. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +#ifdef _WIN32 +#include +#include /* Win32 Multimedia API header. */ +#endif + +#include "glutint.h" + +/* CENTRY */ +void APIENTRY +glutJoystickFunc(GLUTjoystickCB joystickFunc, int pollInterval) +{ +#ifdef _WIN32 + if (joystickFunc && (pollInterval > 0)) { + if (__glutCurrentWindow->entryState == WM_SETFOCUS) { + MMRESULT result; + + /* Capture joystick focus if current window has + focus now. */ + result = joySetCapture(__glutCurrentWindow->win, + JOYSTICKID1, 0, TRUE); + if (result == JOYERR_NOERROR) { + (void) joySetThreshold(JOYSTICKID1, pollInterval); + } + } + __glutCurrentWindow->joyPollInterval = pollInterval; + } else { + /* Release joystick focus if current window has + focus now. */ + if (__glutCurrentWindow->joystick + && (__glutCurrentWindow->joyPollInterval > 0) + && (__glutCurrentWindow->entryState == WM_SETFOCUS)) { + (void) joyReleaseCapture(JOYSTICKID1); + } + __glutCurrentWindow->joyPollInterval = 0; + } + __glutCurrentWindow->joystick = joystickFunc; +#else + /* XXX No support currently for X11 joysticks. */ +#endif +} + +void APIENTRY +glutForceJoystickFunc(void) +{ +#ifdef _WIN32 + if (__glutCurrentWindow->joystick) { + JOYINFOEX jix; + MMRESULT res; + int x, y, z; + + /* Poll the joystick. */ + jix.dwSize = sizeof(jix); + jix.dwFlags = JOY_RETURNALL; + res = joyGetPosEx(JOYSTICKID1,&jix); + if (res == JOYERR_NOERROR) { + + /* Convert to int for scaling. */ + x = jix.dwXpos; + y = jix.dwYpos; + z = jix.dwZpos; + +#define SCALE(v) ((int) ((v - 32767)/32.768)) + + __glutCurrentWindow->joystick(jix.dwButtons, + SCALE(x), SCALE(y), SCALE(z)); + } + } +#else + /* XXX No support currently for X11 joysticks. */ +#endif +} + +/* ENDCENTRY */ -- cgit v1.2.3