Commit f2d67baf authored by Sam Lantinga's avatar Sam Lantinga

Moved DirectInput joystick code to 1.3 branch

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401821
parent fe915b7a
No preview for this file type
...@@ -2270,13 +2270,8 @@ case "$host" in ...@@ -2270,13 +2270,8 @@ case "$host" in
fi fi
# Set up files for the joystick library # Set up files for the joystick library
if test x$enable_joystick = xyes; then if test x$enable_joystick = xyes; then
if test x$have_directx = xyes; then
AC_DEFINE(SDL_JOYSTICK_DINPUT)
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_dxjoystick.c"
else
AC_DEFINE(SDL_JOYSTICK_WINMM) AC_DEFINE(SDL_JOYSTICK_WINMM)
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_mmjoystick.c" SOURCES="$SOURCES $srcdir/src/joystick/win32/*.c"
fi
have_joystick=yes have_joystick=yes
fi fi
# Set up files for the cdrom library # Set up files for the cdrom library
......
...@@ -198,7 +198,6 @@ ...@@ -198,7 +198,6 @@
#undef SDL_JOYSTICK_AMIGA #undef SDL_JOYSTICK_AMIGA
#undef SDL_JOYSTICK_BEOS #undef SDL_JOYSTICK_BEOS
#undef SDL_JOYSTICK_DC #undef SDL_JOYSTICK_DC
#undef SDL_JOYSTICK_DINPUT
#undef SDL_JOYSTICK_DUMMY #undef SDL_JOYSTICK_DUMMY
#undef SDL_JOYSTICK_IOKIT #undef SDL_JOYSTICK_IOKIT
#undef SDL_JOYSTICK_LINUX #undef SDL_JOYSTICK_LINUX
......
...@@ -131,7 +131,7 @@ typedef unsigned int uintptr_t; ...@@ -131,7 +131,7 @@ typedef unsigned int uintptr_t;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
#define SDL_JOYSTICK_DISABLED 1 #define SDL_JOYSTICK_DISABLED 1
#else #else
#define SDL_JOYSTICK_DINPUT 1 #define SDL_JOYSTICK_WINMM 1
#endif #endif
/* Enable various shared object loading systems */ /* Enable various shared object loading systems */
......
This diff is collapsed.
...@@ -436,64 +436,28 @@ extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp); ...@@ -436,64 +436,28 @@ extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp); extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
extern void DIB_QuitGamma(_THIS); extern void DIB_QuitGamma(_THIS);
/* Functions for loading the DirectX functions dynamically */ /* DX5 driver bootstrap functions */
static int DX5_loaded = 0;
static HINSTANCE DDrawDLL = NULL;
static HINSTANCE DInputDLL = NULL;
void DX5_Unload(void) static int DX5_Available(void)
{ {
if ( --DX5_loaded == 0 ) { HINSTANCE DInputDLL;
if ( DDrawDLL != NULL ) { HINSTANCE DDrawDLL;
FreeLibrary(DDrawDLL); int dinput_ok;
DDrawCreate = NULL; int ddraw_ok;
DDrawDLL = NULL;
} /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
dinput_ok = 0;
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
if ( DInputDLL != NULL ) { if ( DInputDLL != NULL ) {
dinput_ok = 1;
FreeLibrary(DInputDLL); FreeLibrary(DInputDLL);
DInputCreate = NULL;
DInputDLL = NULL;
}
} }
} ddraw_ok = 0;
int DX5_Load(void)
{
int status = 0;
if ( ++DX5_loaded == 1 ) {
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL")); DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
if ( DDrawDLL != NULL ) { if ( DDrawDLL != NULL ) {
DDrawCreate = (void *)GetProcAddress(DDrawDLL,
TEXT("DirectDrawCreate"));
}
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
if ( DInputDLL != NULL ) {
DInputCreate = (void *)GetProcAddress(DInputDLL,
TEXT("DirectInputCreateA"));
}
if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
status = 0;
} else {
DX5_Unload();
status = -1;
}
}
return status;
}
/* DX5 driver bootstrap functions */
static int DX5_Available(void)
{
int ddraw_ok = 0;
HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *); HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
LPDIRECTDRAW DDraw; LPDIRECTDRAW DDraw;
/* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
if ( DX5_Load() < 0 ) {
return -1;
}
/* Try to create a valid DirectDraw object */ /* Try to create a valid DirectDraw object */
DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate")); DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
if ( (DDrawCreate != NULL) if ( (DDrawCreate != NULL)
...@@ -524,10 +488,50 @@ static int DX5_Available(void) ...@@ -524,10 +488,50 @@ static int DX5_Available(void)
} }
IDirectDraw_Release(DDraw); IDirectDraw_Release(DDraw);
} }
FreeLibrary(DDrawDLL);
}
return(dinput_ok && ddraw_ok);
}
DX5_Unload(); /* Functions for loading the DirectX functions dynamically */
static HINSTANCE DDrawDLL = NULL;
static HINSTANCE DInputDLL = NULL;
return ddraw_ok; static void DX5_Unload(void)
{
if ( DDrawDLL != NULL ) {
FreeLibrary(DDrawDLL);
DDrawCreate = NULL;
DDrawDLL = NULL;
}
if ( DInputDLL != NULL ) {
FreeLibrary(DInputDLL);
DInputCreate = NULL;
DInputDLL = NULL;
}
}
static int DX5_Load(void)
{
int status;
DX5_Unload();
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
if ( DDrawDLL != NULL ) {
DDrawCreate = (void *)GetProcAddress(DDrawDLL,
TEXT("DirectDrawCreate"));
}
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
if ( DInputDLL != NULL ) {
DInputCreate = (void *)GetProcAddress(DInputDLL,
TEXT("DirectInputCreateA"));
}
if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
status = 0;
} else {
DX5_Unload();
status = -1;
}
return status;
} }
static void DX5_DeleteDevice(SDL_VideoDevice *this) static void DX5_DeleteDevice(SDL_VideoDevice *this)
...@@ -537,7 +541,6 @@ static void DX5_DeleteDevice(SDL_VideoDevice *this) ...@@ -537,7 +541,6 @@ static void DX5_DeleteDevice(SDL_VideoDevice *this)
IDirectDraw2_Release(ddraw2); IDirectDraw2_Release(ddraw2);
} }
DX5_Unload(); DX5_Unload();
if ( this ) { if ( this ) {
if ( this->hidden ) { if ( this->hidden ) {
SDL_free(this->hidden); SDL_free(this->hidden);
......
...@@ -17,7 +17,7 @@ void WatchJoystick(SDL_Joystick *joystick) ...@@ -17,7 +17,7 @@ void WatchJoystick(SDL_Joystick *joystick)
int i, done; int i, done;
SDL_Event event; SDL_Event event;
int x, y, draw; int x, y, draw;
SDL_Rect axis_area[6][2]; SDL_Rect axis_area[2];
/* Set a video mode to display joystick axis position */ /* Set a video mode to display joystick axis position */
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0); screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
...@@ -110,13 +110,12 @@ void WatchJoystick(SDL_Joystick *joystick) ...@@ -110,13 +110,12 @@ void WatchJoystick(SDL_Joystick *joystick)
SDL_UpdateRects(screen, 1, &area); SDL_UpdateRects(screen, 1, &area);
} }
for ( i=0; i<SDL_JoystickNumAxes(joystick)/2 && i < SDL_arraysize(axis_area); ++i ) {
/* Erase previous axes */ /* Erase previous axes */
SDL_FillRect(screen, &axis_area[i][draw], 0x0000); SDL_FillRect(screen, &axis_area[draw], 0x0000);
/* Draw the X/Y axis */ /* Draw the X/Y axis */
draw = !draw; draw = !draw;
x = (((int)SDL_JoystickGetAxis(joystick, i*2+0))+32768); x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
x *= SCREEN_WIDTH; x *= SCREEN_WIDTH;
x /= 65535; x /= 65535;
if ( x < 0 ) { if ( x < 0 ) {
...@@ -125,7 +124,7 @@ void WatchJoystick(SDL_Joystick *joystick) ...@@ -125,7 +124,7 @@ void WatchJoystick(SDL_Joystick *joystick)
if ( x > (SCREEN_WIDTH-16) ) { if ( x > (SCREEN_WIDTH-16) ) {
x = SCREEN_WIDTH-16; x = SCREEN_WIDTH-16;
} }
y = (((int)SDL_JoystickGetAxis(joystick, i*2+1))+32768); y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
y *= SCREEN_HEIGHT; y *= SCREEN_HEIGHT;
y /= 65535; y /= 65535;
if ( y < 0 ) { if ( y < 0 ) {
...@@ -134,14 +133,13 @@ void WatchJoystick(SDL_Joystick *joystick) ...@@ -134,14 +133,13 @@ void WatchJoystick(SDL_Joystick *joystick)
if ( y > (SCREEN_HEIGHT-16) ) { if ( y > (SCREEN_HEIGHT-16) ) {
y = SCREEN_HEIGHT-16; y = SCREEN_HEIGHT-16;
} }
axis_area[i][draw].x = (Sint16)x; axis_area[draw].x = (Sint16)x;
axis_area[i][draw].y = (Sint16)y; axis_area[draw].y = (Sint16)y;
axis_area[i][draw].w = 16; axis_area[draw].w = 16;
axis_area[i][draw].h = 16; axis_area[draw].h = 16;
SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF); SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
SDL_UpdateRects(screen, 2, axis_area[i]); SDL_UpdateRects(screen, 2, axis_area);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment