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_WINMM)
AC_DEFINE(SDL_JOYSTICK_DINPUT) SOURCES="$SOURCES $srcdir/src/joystick/win32/*.c"
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_dxjoystick.c"
else
AC_DEFINE(SDL_JOYSTICK_WINMM)
SOURCES="$SOURCES $srcdir/src/joystick/win32/SDL_mmjoystick.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,98 +436,102 @@ extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp); ...@@ -436,98 +436,102 @@ 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 */
static int DX5_loaded = 0;
static HINSTANCE DDrawDLL = NULL;
static HINSTANCE DInputDLL = NULL;
void DX5_Unload(void)
{
if ( --DX5_loaded == 0 ) {
if ( DDrawDLL != NULL ) {
FreeLibrary(DDrawDLL);
DDrawCreate = NULL;
DDrawDLL = NULL;
}
if ( DInputDLL != NULL ) {
FreeLibrary(DInputDLL);
DInputCreate = NULL;
DInputDLL = NULL;
}
}
}
int DX5_Load(void)
{
int status = 0;
if ( ++DX5_loaded == 1 ) {
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;
}
/* DX5 driver bootstrap functions */ /* DX5 driver bootstrap functions */
static int DX5_Available(void) static int DX5_Available(void)
{ {
int ddraw_ok = 0; HINSTANCE DInputDLL;
HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *); HINSTANCE DDrawDLL;
LPDIRECTDRAW DDraw; int dinput_ok;
int ddraw_ok;
/* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */ /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
if ( DX5_Load() < 0 ) { dinput_ok = 0;
return -1; DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
} if ( DInputDLL != NULL ) {
dinput_ok = 1;
/* Try to create a valid DirectDraw object */ FreeLibrary(DInputDLL);
DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate")); }
if ( (DDrawCreate != NULL) ddraw_ok = 0;
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
if ( DDrawDLL != NULL ) {
HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
LPDIRECTDRAW DDraw;
/* Try to create a valid DirectDraw object */
DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
if ( (DDrawCreate != NULL)
&& !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) { && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw, if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
NULL, DDSCL_NORMAL)) ) { NULL, DDSCL_NORMAL)) ) {
DDSURFACEDESC desc; DDSURFACEDESC desc;
LPDIRECTDRAWSURFACE DDrawSurf; LPDIRECTDRAWSURFACE DDrawSurf;
LPDIRECTDRAWSURFACE3 DDrawSurf3; LPDIRECTDRAWSURFACE3 DDrawSurf3;
/* Try to create a DirectDrawSurface3 object */ /* Try to create a DirectDrawSurface3 object */
SDL_memset(&desc, 0, sizeof(desc)); SDL_memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc); desc.dwSize = sizeof(desc);
desc.dwFlags = DDSD_CAPS; desc.dwFlags = DDSD_CAPS;
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY; desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc, if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
&DDrawSurf, NULL)) ) { &DDrawSurf, NULL)) ) {
if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf, if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
&IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) { &IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
/* Yay! */ /* Yay! */
ddraw_ok = 1; ddraw_ok = 1;
/* Clean up.. */ /* Clean up.. */
IDirectDrawSurface3_Release(DDrawSurf3); IDirectDrawSurface3_Release(DDrawSurf3);
}
IDirectDrawSurface_Release(DDrawSurf);
} }
IDirectDrawSurface_Release(DDrawSurf);
} }
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,38 +110,36 @@ void WatchJoystick(SDL_Joystick *joystick) ...@@ -110,38 +110,36 @@ 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[draw], 0x0000);
SDL_FillRect(screen, &axis_area[i][draw], 0x0000);
/* Draw the X/Y axis */
/* Draw the X/Y axis */ draw = !draw;
draw = !draw; x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
x = (((int)SDL_JoystickGetAxis(joystick, i*2+0))+32768); x *= SCREEN_WIDTH;
x *= SCREEN_WIDTH; x /= 65535;
x /= 65535; if ( x < 0 ) {
if ( x < 0 ) { x = 0;
x = 0; } else
} else 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 *= SCREEN_HEIGHT;
y /= 65535;
if ( y < 0 ) {
y = 0;
} else
if ( y > (SCREEN_HEIGHT-16) ) {
y = SCREEN_HEIGHT-16;
}
axis_area[i][draw].x = (Sint16)x;
axis_area[i][draw].y = (Sint16)y;
axis_area[i][draw].w = 16;
axis_area[i][draw].h = 16;
SDL_FillRect(screen, &axis_area[i][draw], 0xFFFF);
SDL_UpdateRects(screen, 2, axis_area[i]);
} }
y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
y *= SCREEN_HEIGHT;
y /= 65535;
if ( y < 0 ) {
y = 0;
} else
if ( y > (SCREEN_HEIGHT-16) ) {
y = SCREEN_HEIGHT-16;
}
axis_area[draw].x = (Sint16)x;
axis_area[draw].y = (Sint16)y;
axis_area[draw].w = 16;
axis_area[draw].h = 16;
SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
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