remove old sdl stuff
This commit is contained in:
@@ -1,285 +0,0 @@
|
||||
/*
|
||||
* This input handler checks for SDL device input messages and sends them off to
|
||||
* InputFilter. If we add mouse support, it should go here, too.
|
||||
*
|
||||
* Note that the SDL video event systems are interlinked--you can't use events
|
||||
* until video is initialized. So, if we aren't using SDL for video, we can't
|
||||
* use SDL events at all, and so we lose input support, too. In that case, you'll
|
||||
* need to write other input handlers for those cases and load them instead of this.
|
||||
* (Part of this is probably because, in Windows, you need a window to get input.)
|
||||
*/
|
||||
#include "global.h"
|
||||
#include "InputHandler_SDL.h"
|
||||
#include "SDL_utils.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageDisplay.h"
|
||||
|
||||
|
||||
static DeviceButton SDLSymToDeviceButton( SDLKey key )
|
||||
{
|
||||
#define KEY_INV DeviceButton_Invalid
|
||||
const DeviceButton ASCIIKeySyms[] =
|
||||
{
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_INV, /* 0-3 */
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_INV, /* 4-7 */
|
||||
KEY_BACK, KEY_TAB, KEY_INV, KEY_INV, /* 8-11 */
|
||||
KEY_INV, KEY_ENTER, KEY_INV, KEY_INV, /* 12-15 */
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_PAUSE, /* 16-19 */
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_INV, /* 20-23 */
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_ESC, /* 24-27 */
|
||||
KEY_INV, KEY_INV, KEY_INV, KEY_INV, /* 28-31 */
|
||||
KEY_SPACE, KEY_EXCL, KEY_QUOTE, KEY_HASH, /* 32-35 */
|
||||
KEY_DOLLAR, KEY_PERCENT,KEY_AMPER, KEY_SQUOTE, /* 36-39 */
|
||||
KEY_LPAREN, KEY_RPAREN, KEY_ASTERISK,KEY_PLUS, /* 40-43 */
|
||||
KEY_COMMA, KEY_HYPHEN, KEY_PERIOD, KEY_SLASH, /* 44-47 */
|
||||
KEY_C0, KEY_C1, KEY_C2, KEY_C3, /* 48-51 */
|
||||
KEY_C4, KEY_C5, KEY_C6, KEY_C7, /* 52-55 */
|
||||
KEY_C8, KEY_C9, KEY_COLON, KEY_SEMICOLON, /* 56-59 */
|
||||
KEY_LANGLE, KEY_EQUAL, KEY_RANGLE, KEY_QUESTION, /* 60-63 */
|
||||
KEY_AT, KEY_CA, KEY_CB, KEY_CC, KEY_CD, KEY_CE, KEY_CF, KEY_CG, KEY_CH, /* 64-72 */
|
||||
KEY_CI, KEY_CJ, KEY_CK, KEY_CL, KEY_CM, KEY_CN, KEY_CO, KEY_CP, KEY_CQ, /* 73-81 */
|
||||
KEY_CR, KEY_CS, KEY_CT, KEY_CU, KEY_CV, KEY_CW, KEY_CX, KEY_CY, KEY_CZ, /* 82-90 */
|
||||
KEY_LBRACKET, KEY_BACKSLASH, KEY_RBRACKET, KEY_CARAT, /* 91-94 */
|
||||
KEY_UNDERSCORE, KEY_ACCENT, KEY_Ca, KEY_Cb, /* 95-98 */
|
||||
KEY_Cc, KEY_Cd, KEY_Ce, KEY_Cf, KEY_Cg, KEY_Ch, KEY_Ci, KEY_Cj, KEY_Ck, /* 99-107 */
|
||||
KEY_Cl, KEY_Cm, KEY_Cn, KEY_Co, KEY_Cp, KEY_Cq, KEY_Cr, KEY_Cs, KEY_Ct, /* 108-116 */
|
||||
KEY_Cu, KEY_Cv, KEY_Cw, KEY_Cx, KEY_Cy, KEY_Cz, /* 117-122 */
|
||||
KEY_LBRACE, KEY_PIPE, KEY_RBRACE, KEY_INV, KEY_DEL /* 123-127 */
|
||||
};
|
||||
|
||||
/* 0...127: */
|
||||
if( key < int(ARRAYSIZE(ASCIIKeySyms)) )
|
||||
return ASCIIKeySyms[key];
|
||||
|
||||
/* SDLK_WORLD_0 ... SDLK_WORLD_95 to KEY_OTHER_0 ... KEY_OTHER_0 + 95 */
|
||||
if( key >= SDLK_WORLD_0 && key <= SDLK_WORLD_95 )
|
||||
return enum_add2( KEY_OTHER_0, key - SDLK_WORLD_0 );
|
||||
|
||||
/* SDLK_KP0 ... SDLK_KP9 to KEY_KP_C0 ... KEY_KP_C9 */
|
||||
if( key >= SDLK_KP0 && key <= SDLK_KP9 )
|
||||
return enum_add2( KEY_KP_C0, key - SDLK_KP0 );
|
||||
|
||||
switch( key )
|
||||
{
|
||||
case SDLK_KP_PERIOD: return KEY_KP_PERIOD;
|
||||
case SDLK_KP_DIVIDE: return KEY_KP_SLASH;
|
||||
case SDLK_KP_MULTIPLY: return KEY_KP_ASTERISK;
|
||||
case SDLK_KP_MINUS: return KEY_KP_HYPHEN;
|
||||
case SDLK_KP_PLUS: return KEY_KP_PLUS;
|
||||
case SDLK_KP_EQUALS: return KEY_KP_EQUAL;
|
||||
case SDLK_KP_ENTER: return KEY_KP_ENTER;
|
||||
case SDLK_UP: return KEY_UP;
|
||||
case SDLK_DOWN: return KEY_DOWN;
|
||||
case SDLK_RIGHT: return KEY_RIGHT;
|
||||
case SDLK_LEFT: return KEY_LEFT;
|
||||
case SDLK_INSERT: return KEY_INSERT;
|
||||
case SDLK_HOME: return KEY_HOME;
|
||||
case SDLK_END: return KEY_END;
|
||||
case SDLK_PAGEUP: return KEY_PGUP;
|
||||
case SDLK_PAGEDOWN: return KEY_PGDN;
|
||||
case SDLK_F1: return KEY_F1;
|
||||
case SDLK_F2: return KEY_F2;
|
||||
case SDLK_F3: return KEY_F3;
|
||||
case SDLK_F4: return KEY_F4;
|
||||
case SDLK_F5: return KEY_F5;
|
||||
case SDLK_F6: return KEY_F6;
|
||||
case SDLK_F7: return KEY_F7;
|
||||
case SDLK_F8: return KEY_F8;
|
||||
case SDLK_F9: return KEY_F9;
|
||||
case SDLK_F10: return KEY_F10;
|
||||
case SDLK_F11: return KEY_F11;
|
||||
case SDLK_F12: return KEY_F12;
|
||||
case SDLK_F13: return KEY_F13;
|
||||
case SDLK_F14: return KEY_F14;
|
||||
case SDLK_F15: return KEY_F15;
|
||||
|
||||
case SDLK_NUMLOCK: return KEY_NUMLOCK;
|
||||
case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
|
||||
case SDLK_SCROLLOCK: return KEY_SCRLLOCK;
|
||||
case SDLK_SYSREQ: return KEY_PRTSC;
|
||||
case SDLK_PRINT: return KEY_PRTSC;
|
||||
case SDLK_RSHIFT: return KEY_RSHIFT;
|
||||
case SDLK_LSHIFT: return KEY_LSHIFT;
|
||||
case SDLK_RCTRL: return KEY_RCTRL;
|
||||
case SDLK_LCTRL: return KEY_LCTRL;
|
||||
case SDLK_RALT: return KEY_RALT;
|
||||
case SDLK_LALT: return KEY_LALT;
|
||||
case SDLK_RMETA: return KEY_RMETA;
|
||||
case SDLK_LMETA: return KEY_LMETA;
|
||||
case SDLK_LSUPER: return KEY_LSUPER;
|
||||
case SDLK_RSUPER: return KEY_RSUPER;
|
||||
case SDLK_MENU: return KEY_MENU;
|
||||
}
|
||||
|
||||
/* Map anything else to key+KEY_OTHER_0+95. */
|
||||
if( key+KEY_OTHER_0+95 < KEY_LAST_OTHER )
|
||||
return enum_add2( KEY_OTHER_0, key+95 );
|
||||
|
||||
return KEY_INVALID;
|
||||
}
|
||||
|
||||
static const Sint8 Handled_SDL_Events[] = {
|
||||
SDL_KEYDOWN, SDL_KEYUP, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP,
|
||||
SDL_JOYAXISMOTION, SDL_JOYHATMOTION, -1
|
||||
};
|
||||
static int SDL_EventMask;
|
||||
|
||||
InputHandler_SDL::InputHandler_SDL()
|
||||
{
|
||||
SDL_InitSubSystem( SDL_INIT_JOYSTICK );
|
||||
|
||||
#ifdef _XBOX
|
||||
//strange hardware timing issue with 3rd party controllers
|
||||
Sleep(750);
|
||||
#endif
|
||||
|
||||
SDL_EnableKeyRepeat( 0, 0 );
|
||||
|
||||
/* We can do this to get Unicode values in the key struct, which (with
|
||||
* a little more work) will make us work better on international keyboards.
|
||||
* Not all archs support this well. */
|
||||
// SDL_EnableUNICODE( 1 );
|
||||
|
||||
//
|
||||
// Init joysticks
|
||||
//
|
||||
int iNumJoySticks = min( SDL_NumJoysticks(), NUM_JOYSTICKS );
|
||||
LOG->Info( "Found %d joysticks", iNumJoySticks );
|
||||
int i;
|
||||
for( i=0; i<iNumJoySticks; i++ )
|
||||
{
|
||||
SDL_Joystick *pJoystick = SDL_JoystickOpen( i );
|
||||
|
||||
if(pJoystick == NULL) {
|
||||
LOG->Info(" %d: '%s' Error opening: %s",
|
||||
i, SDL_JoystickName(i), SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG->Info( " %d: '%s' axes: %d, hats: %d, buttons: %d",
|
||||
i,
|
||||
SDL_JoystickName(i),
|
||||
SDL_JoystickNumAxes(pJoystick),
|
||||
SDL_JoystickNumHats(pJoystick),
|
||||
SDL_JoystickNumButtons(pJoystick) );
|
||||
|
||||
/* For some weird reason, we won't get any joystick events at all
|
||||
* if we don't keep the joystick open. (Why? The joystick event
|
||||
* API is completely separate from the SDL_Joystick polling API ...) */
|
||||
Joysticks.push_back(pJoystick);
|
||||
}
|
||||
|
||||
for(i = 0; Handled_SDL_Events[i] != -1; ++i)
|
||||
{
|
||||
mySDL_EventState(Handled_SDL_Events[i], SDL_ENABLE);
|
||||
SDL_EventMask |= SDL_EVENTMASK(Handled_SDL_Events[i]);
|
||||
}
|
||||
}
|
||||
|
||||
InputHandler_SDL::~InputHandler_SDL()
|
||||
{
|
||||
unsigned i;
|
||||
for(i = 0; i < Joysticks.size(); ++i)
|
||||
SDL_JoystickClose(Joysticks[i]);
|
||||
|
||||
SDL_QuitSubSystem( SDL_INIT_JOYSTICK );
|
||||
|
||||
for(i = 0; Handled_SDL_Events[i] != -1; ++i)
|
||||
mySDL_EventState(Handled_SDL_Events[i], SDL_IGNORE);
|
||||
}
|
||||
|
||||
void InputHandler_SDL::Update()
|
||||
{
|
||||
SDL_Event event;
|
||||
while(SDL_GetEvent(event, SDL_EventMask))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
LOG->Trace("key: sym %i, key %i, state %i",
|
||||
event.key.keysym.sym, DeviceButton(event.key.keysym.sym), event.key.state );
|
||||
DeviceInput di( DEVICE_KEYBOARD, DeviceButton(event.key.keysym.sym) );
|
||||
ButtonPressed(di, event.key.state == SDL_PRESSED);
|
||||
}
|
||||
continue;
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jbutton.which);
|
||||
DeviceButton Button = enum_add2(JOY_BUTTON_1, key - event.jbutton.button);
|
||||
if(Button > JOY_BUTTON_32)
|
||||
{
|
||||
LOG->Warn("Ignored joystick event (button too high)");
|
||||
continue;
|
||||
}
|
||||
DeviceInput di(i, Button);
|
||||
ButtonPressed(di, event.jbutton.state == SDL_PRESSED);
|
||||
continue;
|
||||
}
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jaxis.which);
|
||||
DeviceButton neg = enum_add2(JOY_LEFT, 2*event.jaxis.axis);
|
||||
DeviceButton pos = enum_add2(JOY_RIGHT, 2*event.jaxis.axis);
|
||||
float l = SCALE( event.jaxis.value, 0.0f, 32768.0f, 0.0f, 1.0f );
|
||||
ButtonPressed(DeviceInput(i, neg,max(-l,0),RageZeroTimer), event.jaxis.value < -16000);
|
||||
ButtonPressed(DeviceInput(i, pos,max(+l,0),RageZeroTimer), event.jaxis.value > +16000);
|
||||
continue;
|
||||
}
|
||||
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
InputDevice i = InputDevice(DEVICE_JOY1 + event.jhat.which);
|
||||
ButtonPressed(DeviceInput(i, JOY_HAT_UP), !!(event.jhat.value & SDL_HAT_UP));
|
||||
ButtonPressed(DeviceInput(i, JOY_HAT_DOWN), !!(event.jhat.value & SDL_HAT_DOWN));
|
||||
ButtonPressed(DeviceInput(i, JOY_HAT_LEFT), !!(event.jhat.value & SDL_HAT_LEFT));
|
||||
ButtonPressed(DeviceInput(i, JOY_HAT_RIGHT), !!(event.jhat.value & SDL_HAT_RIGHT));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputHandler::UpdateTimer();
|
||||
}
|
||||
|
||||
|
||||
void InputHandler_SDL::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut )
|
||||
{
|
||||
vDevicesOut.push_back( InputDeviceInfo(DEVICE_KEYBOARD,"Keyboard") );
|
||||
|
||||
for( int i=0; i<SDL_NumJoysticks(); i++ )
|
||||
{
|
||||
if( SDL_JoystickOpened(i) )
|
||||
vDevicesOut.push_back( InputDeviceInfo(InputDevice(DEVICE_JOY1+i), SDL_JoystickName(i)) );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef INPUT_HANDLER_SDL_KEYBOARD_H
|
||||
#define INPUT_HANDLER_SDL_KEYBOARD_H
|
||||
|
||||
#include "InputHandler.h"
|
||||
|
||||
struct _SDL_Joystick;
|
||||
typedef struct _SDL_Joystick SDL_Joystick;
|
||||
|
||||
class InputHandler_SDL: public InputHandler
|
||||
{
|
||||
vector<SDL_Joystick *> Joysticks;
|
||||
|
||||
public:
|
||||
void Update();
|
||||
InputHandler_SDL();
|
||||
~InputHandler_SDL();
|
||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevicesOut );
|
||||
};
|
||||
#define USE_INPUT_HANDLER_SDL
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -14,13 +14,10 @@
|
||||
|
||||
#include "InputHandler_MonkeyKeyboard.h"
|
||||
|
||||
// NOTE: If X11 is available, we don't use LLW_SDL, which IH_SDL depends on.
|
||||
#if defined(HAVE_X11)
|
||||
#include "InputHandler_X11.h"
|
||||
#elif defined(MACOSX)
|
||||
#include "InputHandler_Carbon.h"
|
||||
#elif defined(HAVE_SDL)
|
||||
#include "InputHandler_SDL.h"
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS)
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
#include "global.h"
|
||||
#include "LowLevelWindow_SDL.h"
|
||||
#include "SDL_utils.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageDisplay.h" // for REFRESH_DEFAULT
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
#include "DisplayResolutions.h"
|
||||
|
||||
LowLevelWindow_SDL::LowLevelWindow_SDL()
|
||||
{
|
||||
/* By default, ignore all SDL events. We'll enable them as we need them.
|
||||
* We must not enable any events we don't actually want, since we won't
|
||||
* query for them and they'll fill up the event queue.
|
||||
*
|
||||
* This needs to be done after we initialize video, since it's really part
|
||||
* of the SDL video system--it'll be reinitialized on us if we do this first. */
|
||||
SDL_EventState(0xFF /*SDL_ALLEVENTS*/, SDL_IGNORE);
|
||||
|
||||
SDL_EventState( SDL_VIDEORESIZE, SDL_ENABLE );
|
||||
SDL_EventState( SDL_ACTIVEEVENT, SDL_ENABLE );
|
||||
SDL_EventState( SDL_QUIT, SDL_ENABLE );
|
||||
}
|
||||
|
||||
LowLevelWindow_SDL::~LowLevelWindow_SDL()
|
||||
{
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
mySDL_EventState( SDL_VIDEORESIZE, SDL_IGNORE );
|
||||
mySDL_EventState( SDL_ACTIVEEVENT, SDL_IGNORE );
|
||||
mySDL_EventState( SDL_QUIT, SDL_IGNORE );
|
||||
}
|
||||
|
||||
void *LowLevelWindow_SDL::GetProcAddress(RString s)
|
||||
{
|
||||
return SDL_GL_GetProcAddress(s);
|
||||
}
|
||||
|
||||
RString LowLevelWindow_SDL::TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut )
|
||||
{
|
||||
bool wasWindowed = CurrentParams.windowed;
|
||||
|
||||
CurrentParams = p;
|
||||
|
||||
/* We need to preserve the event mask and all events, since they're lost by
|
||||
* SDL_QuitSubSystem(SDL_INIT_VIDEO). */
|
||||
vector<SDL_Event> events;
|
||||
mySDL_GetAllEvents(events);
|
||||
Uint8 EventEnabled[SDL_NUMEVENTS];
|
||||
|
||||
/* Queue up key-up events for all keys that are currently down (eg. alt-enter).
|
||||
* This is normally done by SDL, but since we're shutting down the video system
|
||||
* we're also shutting down the event system. */
|
||||
{
|
||||
const Uint8 *KeyState = SDL_GetKeyState(NULL);
|
||||
for ( SDLKey key=SDLK_FIRST; key<SDLK_LAST; key = (SDLKey)(key+1) )
|
||||
{
|
||||
if ( KeyState[key] != SDL_PRESSED )
|
||||
continue;
|
||||
SDL_Event e;
|
||||
memset(&e, 0, sizeof(e));
|
||||
e.key.type = SDL_KEYUP;
|
||||
e.key.keysym.sym = key;
|
||||
events.push_back(e);
|
||||
}
|
||||
}
|
||||
|
||||
for( int i = 0; i < SDL_NUMEVENTS; ++i )
|
||||
EventEnabled[i] = mySDL_EventState( (Uint8) i, SDL_QUERY );
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO);
|
||||
|
||||
if( SDL_InitSubSystem(SDL_INIT_VIDEO) == -1 )
|
||||
{
|
||||
const RString err = mySDL_GetError();
|
||||
|
||||
/* Check for a confusing SDL error message. */
|
||||
if( !err.CompareNoCase( "X11 driver not configured with OpenGL" ) )
|
||||
RageException::Throw( "Your installation of SDL was not compiled with OpenGL enabled." );
|
||||
RageException::Throw( "SDL_INIT_VIDEO failed: %s", err.c_str() );
|
||||
}
|
||||
|
||||
/* Put them back. */
|
||||
for( int i = 0; i < SDL_NUMEVENTS; ++i)
|
||||
mySDL_EventState((Uint8) i, EventEnabled[i]);
|
||||
mySDL_PushEvents(events);
|
||||
|
||||
/* Set SDL window title, icon and cursor -before- creating the window */
|
||||
SDL_WM_SetCaption( p.sWindowTitle, "");
|
||||
mySDL_WM_SetIcon( p.sIconFile );
|
||||
SDL_ShowCursor( p.windowed ? SDL_ENABLE : SDL_DISABLE );
|
||||
|
||||
int flags = SDL_RESIZABLE | SDL_OPENGL;
|
||||
if( !p.windowed )
|
||||
flags |= SDL_FULLSCREEN;
|
||||
|
||||
ASSERT( p.bpp == 16 || p.bpp == 32 );
|
||||
switch( p.bpp )
|
||||
{
|
||||
case 16:
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
||||
break;
|
||||
case 32:
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
}
|
||||
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);
|
||||
|
||||
#if defined(LINUX)
|
||||
/* nVidia cards:
|
||||
*
|
||||
* This only works the first time we set up a window; after that, the
|
||||
* drivers appear to cache the value, so you have to actually restart
|
||||
* the program to change it again. */
|
||||
static char buf[128];
|
||||
strcpy( buf, "__GL_SYNC_TO_VBLANK=" );
|
||||
strcat( buf, p.vsync?"1":"0" );
|
||||
putenv( buf );
|
||||
#endif
|
||||
|
||||
SDL_Surface *screen = SDL_SetVideoMode( p.width, p.height, p.bpp, flags );
|
||||
if( !screen )
|
||||
{
|
||||
LOG->Trace( "SDL_SetVideoMode failed: %s", mySDL_GetError().c_str() );
|
||||
SDL_ShowCursor( wasWindowed ? SDL_ENABLE : SDL_DISABLE );
|
||||
return mySDL_GetError(); // failed to set mode
|
||||
}
|
||||
|
||||
bNewDeviceOut = true; // always a new context because we're resetting SDL_Video
|
||||
|
||||
static bool bLogged = false;
|
||||
if( !bLogged )
|
||||
{
|
||||
bLogged = true;
|
||||
const SDL_version *ver = SDL_Linked_Version();
|
||||
LOG->Info( "SDL version: %i.%i.%i", ver->major, ver->minor, ver->patch );
|
||||
}
|
||||
|
||||
{
|
||||
/* Find out what we really got. */
|
||||
int r,g,b,a, colorbits, depth, stencil;
|
||||
|
||||
SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r);
|
||||
SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g);
|
||||
SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b);
|
||||
SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a);
|
||||
SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &colorbits);
|
||||
SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
|
||||
SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil);
|
||||
LOG->Info("Got %i bpp (%i%i%i%i), %i depth, %i stencil",
|
||||
colorbits, r, g, b, a, depth, stencil);
|
||||
}
|
||||
|
||||
return ""; // we set the video mode successfully
|
||||
}
|
||||
|
||||
void LowLevelWindow_SDL::SwapBuffers()
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
void LowLevelWindow_SDL::Update()
|
||||
{
|
||||
/* This needs to be called before anything that handles SDL events. */
|
||||
SDL_PumpEvents();
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_GetEvent(event, SDL_VIDEORESIZEMASK|SDL_ACTIVEEVENTMASK|SDL_QUITMASK))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_VIDEORESIZE:
|
||||
CurrentParams.width = event.resize.w;
|
||||
CurrentParams.height = event.resize.h;
|
||||
|
||||
/* Let DISPLAY know that our resolution has changed. */
|
||||
DISPLAY->ResolutionChanged();
|
||||
break;
|
||||
case SDL_ACTIVEEVENT:
|
||||
/* We don't care about mouse focus. */
|
||||
if(event.active.state == SDL_APPMOUSEFOCUS)
|
||||
break;
|
||||
|
||||
if( event.active.gain && // app regaining focus
|
||||
!DISPLAY->GetActualVideoModeParams().windowed ) // full screen
|
||||
{
|
||||
// need to reacquire an OGL context
|
||||
/* This hasn't been done in a long time, since HandleSDLEvents was
|
||||
* handling this event before we got it. I tried reenablng it, and
|
||||
* it resulted in input not being regained and textures being erased,
|
||||
* so I left it disabled; but this might be needed on some cards (with
|
||||
* the above fixed) ... */
|
||||
// DISPLAY->SetVideoMode( DISPLAY->GetActualVideoModeParams() );
|
||||
}
|
||||
|
||||
{
|
||||
uint8_t i = SDL_GetAppState();
|
||||
LOG->Trace( "SDL_GetAppState: %i", i );
|
||||
HOOKS->SetHasFocus( i&SDL_APPINPUTFOCUS && i&SDL_APPACTIVE );
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
LOG->Trace("SDL_QUIT: shutting down");
|
||||
ArchHooks::SetUserQuit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LowLevelWindow_SDL::GetDisplayResolutions( DisplayResolutions &out ) const
|
||||
{
|
||||
SDL_Rect **modes = SDL_ListModes(NULL, SDL_RESIZABLE | SDL_OPENGL | SDL_FULLSCREEN );
|
||||
ASSERT_M( modes, "No modes available" );
|
||||
|
||||
for(int i=0; modes[i]; ++i )
|
||||
{
|
||||
DisplayResolution res = { modes[i]->w, modes[i]->h };
|
||||
out.insert( res );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2003-2004 Chris Danford, Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef LOW_LEVEL_WINDOW_SDL_H
|
||||
#define LOW_LEVEL_WINDOW_SDL_H
|
||||
|
||||
#include "LowLevelWindow.h"
|
||||
#include "RageDisplay.h"
|
||||
|
||||
class LowLevelWindow_SDL: public LowLevelWindow
|
||||
{
|
||||
public:
|
||||
LowLevelWindow_SDL();
|
||||
~LowLevelWindow_SDL();
|
||||
void *GetProcAddress(RString s);
|
||||
RString TryVideoMode( const VideoModeParams &p, bool &bNewDeviceOut );
|
||||
virtual void GetDisplayResolutions( DisplayResolutions &out ) const;
|
||||
|
||||
void SwapBuffers();
|
||||
void Update();
|
||||
|
||||
const VideoModeParams &GetActualVideoModeParams() const { return CurrentParams; }
|
||||
|
||||
private:
|
||||
VideoModeParams CurrentParams;
|
||||
};
|
||||
|
||||
#ifdef ARCH_LOW_LEVEL_WINDOW
|
||||
#error "More than one LowLevelWindow selected!"
|
||||
#endif
|
||||
#define ARCH_LOW_LEVEL_WINDOW LowLevelWindow_SDL
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* (c) 2003-2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -8,8 +8,6 @@
|
||||
#include "LowLevelWindow_X11.h"
|
||||
#elif defined(MACOSX)
|
||||
#include "LowLevelWindow_Cocoa.h"
|
||||
#elif defined(HAVE_SDL)
|
||||
#include "LowLevelWindow_SDL.h"
|
||||
#else
|
||||
#error "No suitable LowLevelWindow available."
|
||||
#endif
|
||||
|
||||
@@ -37,9 +37,6 @@ void MakeInputHandlers( const RString &drivers, vector<InputHandler *> &Add )
|
||||
#ifdef USE_INPUT_HANDLER_LINUX_TTY
|
||||
if( !s->CompareNoCase("tty") ) ret = new InputHandler_Linux_tty;
|
||||
#endif
|
||||
#ifdef USE_INPUT_HANDLER_SDL
|
||||
if( !s->CompareNoCase("SDL") ) ret = new InputHandler_SDL;
|
||||
#endif
|
||||
#ifdef USE_INPUT_HANDLER_WIN32_PARA
|
||||
if( !s->CompareNoCase("Para") ) ret = new InputHandler_Win32_Para;
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "Xbox"
|
||||
#elif defined(HAVE_DIRECTX)
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump,Para"
|
||||
#elif defined(HAVE_X11) // Prefer X11 over SDL
|
||||
#elif defined(HAVE_X11)
|
||||
#define DEFAULT_INPUT_DRIVER_LIST "X11,Joystick"
|
||||
#elif defined(MACOSX)
|
||||
# define DEFAULT_INPUT_DRIVER_LIST "Carbon"
|
||||
|
||||
Reference in New Issue
Block a user