Remove SDL1 code (WIP)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7663 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: e599695a71079773a26ecfd96912b52928158286 Former-commit-id: 6d5a966f5998dc037a8d31fe154438732cf7d503
This commit is contained in:
parent
9325947c57
commit
9586a48241
8 changed files with 9 additions and 162 deletions
|
@ -68,24 +68,6 @@ private: // Private data members.
|
|||
GfEventLoop::Private::Private()
|
||||
: cbKeyboardDown(0), cbKeyboardUp(0), cbRecompute(0), cbTimer(0), bQuit(false), nLockedModifiers(KMOD_NONE)
|
||||
{
|
||||
static bool bInitialized = false;
|
||||
if (!bInitialized)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
// Enable "key press" event unicode translation.
|
||||
SDL_EnableUNICODE(/*enable=*/1);
|
||||
//SDL_WM_GrabInput(SDL_GRAB_ON); // Caps-Lock bug : Not better if On.
|
||||
|
||||
// Caps-Lock bug
|
||||
// Get initial state for locked modifiers (mainly Caps and Num-Lock).
|
||||
// Note: SDL fails at taking further hits of Caps and Num-Lock keys into account,
|
||||
// so we have to do it ourselves (see operator ()).
|
||||
nLockedModifiers = SDL_GetModState();
|
||||
|
||||
// Done once and for all.
|
||||
#endif
|
||||
bInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Translation function from SDL key to unicode if possible (or SDL key sym otherwise)
|
||||
|
@ -101,34 +83,6 @@ GfEventLoop::Private::Private()
|
|||
// below, we do not want to treat the two <Enter> keys as distinct.
|
||||
int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
// Generate the key Id from its code and modifier.
|
||||
const Uint32 keyId = ((Uint32)code & 0x1FF) | (((Uint32)modifier) << 9);
|
||||
|
||||
// Search it in our unicode map.
|
||||
const std::map<Uint32, Uint16>::const_iterator itUnicode = _mapUnicodes.find(keyId);
|
||||
|
||||
// If not found, update the map for next times.
|
||||
int keyUnicode;
|
||||
if (itUnicode == _mapUnicodes.end())
|
||||
{
|
||||
// Truncate unicodes above GF_MAX_KEYCODE (no need for more).
|
||||
keyUnicode = unicode ? (unicode & GF_MAX_KEYCODE) : code;
|
||||
_mapUnicodes[keyId] = (unsigned short)keyUnicode;
|
||||
GfLogDebug("translateKeySym(c=%X, m=%X, u=%X) : '%c', id=%X, ucode=%X (nk=%d), ms=%X\n",
|
||||
code, modifier, unicode, // Truncate high bits for MSVC 2010 bugs.
|
||||
(keyUnicode > 0 && keyUnicode < 128 && isprint(keyUnicode & 0x7F)
|
||||
? (char)(keyUnicode & 0x7F) : ' '),
|
||||
keyId, keyUnicode, _mapUnicodes.size(), SDL_GetModState());
|
||||
}
|
||||
|
||||
// If found, get the unicode from the map.
|
||||
else
|
||||
keyUnicode = (*itUnicode).second;
|
||||
|
||||
// Done.
|
||||
return keyUnicode;
|
||||
#else
|
||||
int keyUnicode = code; //default to returning code
|
||||
|
||||
// Make the Numpad <Enter> key behave like the regular <Enter> key
|
||||
|
@ -167,7 +121,7 @@ int GfEventLoop::Private::translateKeySym(int code, int modifier, int unicode)
|
|||
}
|
||||
|
||||
return keyUnicode;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Uint32 GfEventLoop::Private::callTimerCB(Uint32 interval, void *pEvLoopPriv)
|
||||
|
@ -204,11 +158,8 @@ void GfEventLoop::injectKeyboardEvent(int code, int modifier, int state,
|
|||
GfLogDebug("injectKeyboardEvent(c=%X) : lockedMod=%X (SDL says %X)\n",
|
||||
code, _pPrivate->nLockedModifiers, SDL_GetModState());
|
||||
return;
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
case SDLK_NUMLOCK:
|
||||
#else
|
||||
|
||||
case SDLK_NUMLOCKCLEAR:
|
||||
#endif
|
||||
_pPrivate->nLockedModifiers ^= KMOD_NUM;
|
||||
GfLogDebug("injectKeyboardEvent(c=%X) : lockedMod=%X (SDL says %X)\n",
|
||||
code, _pPrivate->nLockedModifiers, SDL_GetModState());
|
||||
|
@ -221,15 +172,9 @@ void GfEventLoop::injectKeyboardEvent(int code, int modifier, int state,
|
|||
if (modifier & KMOD_RSHIFT) modifier |= KMOD_LSHIFT;
|
||||
if (modifier & KMOD_RCTRL) modifier |= KMOD_LCTRL;
|
||||
if (modifier & KMOD_RALT) modifier |= KMOD_LALT;
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
if (modifier & KMOD_RMETA) modifier |= KMOD_LMETA;
|
||||
|
||||
modifier &= (KMOD_LSHIFT | KMOD_LCTRL | KMOD_LALT | KMOD_LMETA);
|
||||
#else
|
||||
if (modifier & KMOD_RGUI) modifier |= KMOD_LGUI;
|
||||
|
||||
modifier &= (KMOD_LSHIFT | KMOD_LCTRL | KMOD_LALT | KMOD_LGUI);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Toggle the Shift modifier if the Caps-Lock key is on. // Caps-Lock bug
|
||||
|
@ -271,21 +216,11 @@ void GfEventLoop::operator()()
|
|||
switch(event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
event.key.keysym.unicode);
|
||||
#else
|
||||
0);
|
||||
#endif
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0, 0);
|
||||
break;
|
||||
|
||||
case SDL_KEYUP:
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
event.key.keysym.unicode);
|
||||
#else
|
||||
0);
|
||||
#endif
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1, 0);
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
|
|
|
@ -545,12 +545,10 @@ void GfInit(bool bWithLogging)
|
|||
GfLogInfo("Compiled against SDL version %d.%d.%d \n",
|
||||
compiled.major, compiled.minor, compiled.patch);
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_version linked;
|
||||
SDL_GetVersion(&linked);
|
||||
GfLogInfo("Linking against SDL version %d.%d.%d.\n",
|
||||
linked.major, linked.minor, linked.patch);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -131,10 +131,8 @@ class TGFCLIENT_API GfglFeatures
|
|||
// Update supported OpenGL features according to the given frame buffer specs.
|
||||
bool detectBestSupport(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBump, bool& bStereo, int& nAniFilt);
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
bool detectBestSupportSDL2(int& nWidth, int& nHeight, int& nDepth,
|
||||
bool& bAlpha, bool& bFullScreen, bool& bBump, bool& bStereo, int& nAniFilt);
|
||||
#endif
|
||||
|
||||
bool loadSupport(int &nWidth, int &nHeight, int &nDepth,
|
||||
bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt, void* hparmConfig = 0);
|
||||
|
|
|
@ -47,9 +47,7 @@ PFNGLACTIVETEXTUREARBPROC glActiveTextureARB ;
|
|||
#endif
|
||||
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_Window* GfuiWindow = NULL;
|
||||
#endif
|
||||
|
||||
tGfuiScreen *GfuiScreen; /* current screen */
|
||||
static int GfuiMouseVisible = 1;
|
||||
|
@ -455,13 +453,8 @@ gfuiKeyboardDown(int key, int modifier, int /* x */, int /* y */)
|
|||
// as the unicode generator already took care of it.
|
||||
if (curKey->key == key
|
||||
&& (curKey->modifier == modifier
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
|| (curKey->modifier == (modifier & (~GFUIM_SHIFT))
|
||||
&& key >= ' ' && key <= 'z')
|
||||
#else
|
||||
|| (curKey->modifier == (modifier & (~GFUIM_SHIFT))
|
||||
&& isprint(key))
|
||||
#endif
|
||||
))
|
||||
{
|
||||
if (curKey->onPress)
|
||||
|
@ -536,11 +529,7 @@ void GfuiMouseSetPos(int x, int y)
|
|||
{
|
||||
if (GfuiScreen)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_WarpMouseInWindow(GfuiWindow, x,y);
|
||||
#else
|
||||
SDL_WarpMouse(x,y);
|
||||
#endif
|
||||
GfuiMouse.X = (x - (ScrW - ViewW)/2) * (int)GfuiScreen->width / ViewW;
|
||||
GfuiMouse.Y = (ViewH - y + (ScrH - ViewH)/2) * (int)GfuiScreen->height / ViewH;
|
||||
}
|
||||
|
@ -556,11 +545,7 @@ gfuiMouseButton(int button, int state, int x, int y)
|
|||
GfuiMouse.X = (x - (ScrW - ViewW)/2) * (int)GfuiScreen->width / ViewW;
|
||||
GfuiMouse.Y = (ViewH - y + (ScrH - ViewH)/2) * (int)GfuiScreen->height / ViewH;
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
if (button == SDL_MOUSEWHEEL) {
|
||||
#else
|
||||
if (button == SDL_BUTTON_WHEELUP || button == SDL_BUTTON_WHEELDOWN) {
|
||||
#endif
|
||||
// Up/down happens very quickly, leaving no time for the system to see them
|
||||
// this just toggle every down event
|
||||
if (state == SDL_PRESSED) {
|
||||
|
@ -653,18 +638,6 @@ GfuiScreenActivate(void *screen)
|
|||
GfuiApp().eventLoop().setMousePassiveMotionCB(gfuiMousePassiveMotion);
|
||||
GfuiApp().eventLoop().setRecomputeCB(0);
|
||||
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
if (GfuiScreen->keyAutoRepeat)
|
||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
else
|
||||
SDL_EnableKeyRepeat(0, 0);
|
||||
//#else
|
||||
#if SDL_JOYSTICK
|
||||
GfuiApp().eventLoop().setJoystickAxisCB(GfctrlJoySetAxis);
|
||||
GfuiApp().eventLoop().setJoystickButtonCB(GfctrlJoySetButton);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (GfuiScreen->onlyCallback == 0)
|
||||
{
|
||||
if (GfuiScreen->hasFocus == NULL)
|
||||
|
@ -1245,17 +1218,10 @@ GfuiInitWindowPositionAndSize(int x, int y, int w, int h)
|
|||
// No need to resize, already done when setting the video mode.
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
if (SDL_GetWindowWMInfo(GfuiWindow, &wmInfo)) {
|
||||
#else
|
||||
if (SDL_GetWMInfo(&wmInfo)) {
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SetWindowPos(wmInfo.info.win.window, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
|
||||
#else
|
||||
SetWindowPos(wmInfo.window, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
|
||||
#endif
|
||||
#else
|
||||
// TODO.
|
||||
GfLogWarning("GfuiInitWindowPositionAndSize not yet implemented under non-Windows OSes\n");
|
||||
|
@ -1274,9 +1240,5 @@ GfuiInitWindowPositionAndSize(int x, int y, int w, int h)
|
|||
void
|
||||
GfuiSwapBuffers(void)
|
||||
{
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
SDL_GL_SwapWindow(GfuiWindow);
|
||||
#else
|
||||
SDL_GL_SwapBuffers();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -136,11 +136,10 @@ void GfuiEventLoop::injectJoystickButtonEvent(int joy, int button, int value)
|
|||
void GfuiEventLoop::operator()()
|
||||
{
|
||||
SDL_Event event; // Event structure
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
static int unicode = 0;
|
||||
static SDL_Keymod modifier = KMOD_NONE;
|
||||
static SDL_Keycode keysym = SDLK_UNKNOWN;
|
||||
#endif
|
||||
static SDL_Keymod modifier = KMOD_NONE;
|
||||
static SDL_Keycode keysym = SDLK_UNKNOWN;
|
||||
|
||||
|
||||
// Check for events.
|
||||
while (!quitRequested())
|
||||
|
@ -152,9 +151,6 @@ void GfuiEventLoop::operator()()
|
|||
switch(event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,event.key.keysym.unicode);
|
||||
#else
|
||||
if((event.key.keysym.sym & SDLK_SCANCODE_MASK) == SDLK_SCANCODE_MASK)
|
||||
{
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 0,0);
|
||||
|
@ -174,25 +170,18 @@ void GfuiEventLoop::operator()()
|
|||
//GfLogDebug("SDL_KEYDOWN: %c\r\n",(char)event.key.keysym.sym);
|
||||
keysym = event.key.keysym.sym;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
case SDL_TEXTINPUT:
|
||||
unicode = (int)(event.text.text[0]);
|
||||
modifier = SDL_GetModState();
|
||||
injectKeyboardEvent(keysym, modifier, 0, unicode);
|
||||
//GfLogDebug("SDL_TEXTINPUT: %c %X\r\n",(char)unicode,modifier);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_KEYUP:
|
||||
#if SDL_MAJOR_VERSION < 2
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,event.key.keysym.unicode);
|
||||
#else
|
||||
injectKeyboardEvent(event.key.keysym.sym, event.key.keysym.mod, 1,0);
|
||||
//GfLogDebug("SDL_KEYUP: %c\r\n",(char)event.key.keysym.sym);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
|
@ -210,7 +199,6 @@ void GfuiEventLoop::operator()()
|
|||
postQuit();
|
||||
break;
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#if SDL_JOYSTICK
|
||||
case SDL_JOYAXISMOTION:
|
||||
injectJoystickAxisEvent(event.jaxis.which, event.jaxis.axis, (float) event.jaxis.value / 32768);
|
||||
|
@ -225,9 +213,6 @@ void GfuiEventLoop::operator()()
|
|||
break;
|
||||
#endif
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
#else
|
||||
case SDL_VIDEOEXPOSE:
|
||||
#endif
|
||||
forceRedisplay();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -44,22 +44,12 @@
|
|||
#endif
|
||||
|
||||
#include <SDL.h>
|
||||
#if 0
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#include <SDL_keyboard.h>
|
||||
#else
|
||||
#include <SDL_keysym.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <tgf.hpp>
|
||||
|
||||
#include "guiscreen.h"
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
extern SDL_Window* GfuiWindow;
|
||||
#endif
|
||||
|
||||
|
||||
// DLL exported symbols declarator for Windows.
|
||||
#ifdef WIN32
|
||||
|
@ -91,9 +81,7 @@ typedef struct ScreenSize
|
|||
int height; // Height in pixels.
|
||||
} tScreenSize;
|
||||
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
TGFCLIENT_API SDL_Window* GfScrGetMainWindow();//{return GfuiWindow;};
|
||||
#endif
|
||||
TGFCLIENT_API bool GfScrInit(int nWinWidth = -1, int nWinHeight = -1, int nFullScreen = -1);
|
||||
TGFCLIENT_API void GfScrShutdown(void);
|
||||
TGFCLIENT_API void GfScrGetSize(int *scrW, int *scrH, int *viewW, int *viewH);
|
||||
|
@ -188,11 +176,7 @@ TGFCLIENT_API tScreenSize* GfScrGetDefaultSizes(int* pnSizes);
|
|||
#define GFUIM_CTRL KMOD_LCTRL
|
||||
#define GFUIM_SHIFT KMOD_LSHIFT
|
||||
#define GFUIM_ALT KMOD_LALT
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
#define GFUIM_META KMOD_LGUI
|
||||
#else
|
||||
#define GFUIM_META KMOD_LMETA
|
||||
#endif
|
||||
|
||||
// Some keyboard key / special key codes, to avoid SDLK constants everywhere.
|
||||
#define GFUIK_BACKSPACE SDLK_BACKSPACE
|
||||
|
@ -238,13 +222,6 @@ TGFCLIENT_API tScreenSize* GfScrGetDefaultSizes(int* pnSizes);
|
|||
// Maximun value of a key code (Has to be the least greater 2^N - 1 >= SDLK_LAST)
|
||||
#define GFUIK_MAX GF_MAX_KEYCODE
|
||||
|
||||
#if SDL_MAJOR_VERSION < 2 // SDLK_LAST no longer defined as of SDL2
|
||||
#if (GFUIK_MAX < SDLK_LAST)
|
||||
# error SDLK_MAX has grown too much, please increase GF_MAX_KEYCODE to the least greater power of 2 minus 1.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/** Scroll bar call-back information */
|
||||
typedef struct ScrollBarInfo
|
||||
{
|
||||
|
@ -702,7 +679,7 @@ TGFCLIENT_API tCtrlJoyInfo* GfctrlJoyCreate(void);
|
|||
TGFCLIENT_API void GfctrlJoyRelease(tCtrlJoyInfo* joyInfo);
|
||||
TGFCLIENT_API int GfctrlJoyGetCurrentStates(tCtrlJoyInfo* joyInfo);
|
||||
#if SDL_JOYSTICK
|
||||
#if ((SDL_MAJOR_VERSION >= 2) && (SDL_FORCEFEEDBACK))
|
||||
#if SDL_FORCEFEEDBACK
|
||||
TGFCLIENT_API void gfctrlJoyConstantForce(int index, int level, int dir);
|
||||
TGFCLIENT_API void gfctrlJoyRumble(int index, float level);
|
||||
#endif
|
||||
|
|
|
@ -481,11 +481,7 @@ ReSituationUpdater::ReSituationUpdater()
|
|||
ReSituation::self().setThreadSafe(true);
|
||||
|
||||
// Create and start the updater thread.
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
_pUpdateThread = SDL_CreateThread(ReSituationUpdater::threadLoop,"Update_thread",this);
|
||||
#else
|
||||
_pUpdateThread = SDL_CreateThread(ReSituationUpdater::threadLoop, this);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -584,11 +584,7 @@ ReSituationUpdater::ReSituationUpdater()
|
|||
ReSituation::self().setThreadSafe(true);
|
||||
|
||||
// Create and start the updater thread.
|
||||
#if SDL_MAJOR_VERSION >= 2
|
||||
_pUpdateThread = SDL_CreateThread(ReSituationUpdater::threadLoop,"Update_thread",this);
|
||||
#else
|
||||
_pUpdateThread = SDL_CreateThread(ReSituationUpdater::threadLoop, this);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue