sdl: prelimenary SDL2.0 support

sdl: fixed bug where fceux would take exclusive grab of input in windowed mode when resuming from pause
This commit is contained in:
punkrockguy318 2013-03-10 23:54:01 +00:00
parent 748f621eff
commit ec8cbcfc00
7 changed files with 78 additions and 23 deletions

View File

@ -26,7 +26,8 @@ opts.AddVariables(
BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', 1), BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', 1),
BoolVariable('GTK', 'Enable GTK2 GUI (SDL only)', 1), BoolVariable('GTK', 'Enable GTK2 GUI (SDL only)', 1),
BoolVariable('GTK3', 'Enable GTK3 GUI (SDL only)', 0), BoolVariable('GTK3', 'Enable GTK3 GUI (SDL only)', 0),
BoolVariable('CLANG', 'Compile with llvm-clang instead of gcc', 0) BoolVariable('CLANG', 'Compile with llvm-clang instead of gcc', 0),
BoolVariable('SDL2', 'Compile using SDL2 instead of SDL 1.2 (experimental/non-functional)', 0)
) )
AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix') AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix')
@ -90,9 +91,17 @@ else:
env.Append(CPPDEFINES=["_SYSTEM_MINIZIP"]) env.Append(CPPDEFINES=["_SYSTEM_MINIZIP"])
else: else:
assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib" assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib"
if not conf.CheckLib('SDL'): if env['SDL2']:
print 'Did not find libSDL or SDL.lib, exiting!' if not conf.CheckLib('SDL2'):
Exit(1) print 'Did not find libSDL2 or SDL2.lib, exiting!'
Exit(1)
env.Append(CPPDEFINES=["_SDL2"])
env.ParseConfig('pkg-config sdl2 --cflags --libs')
else:
if not conf.CheckLib('SDL'):
print 'Did not find libSDL or SDL.lib, exiting!'
Exit(1)
env.ParseConfig('sdl-config --cflags --libs')
if env['GTK']: if env['GTK']:
if not conf.CheckLib('gtk-x11-2.0'): if not conf.CheckLib('gtk-x11-2.0'):
print 'Could not find libgtk-2.0, exiting!' print 'Could not find libgtk-2.0, exiting!'
@ -148,8 +157,6 @@ else:
if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c', autoadd=1): if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c', autoadd=1):
conf.env.Append(CCFLAGS = "-DOPENGL") conf.env.Append(CCFLAGS = "-DOPENGL")
conf.env.Append(CPPDEFINES = ['PSS_STYLE=1']) conf.env.Append(CPPDEFINES = ['PSS_STYLE=1'])
# parse SDL cflags/libs
env.ParseConfig('sdl-config --cflags --libs')
env = conf.Finish() env = conf.Finish()

View File

@ -10,8 +10,6 @@
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <SDL/SDL.h>
#include "../../types.h" #include "../../types.h"
#include "../../fceu.h" #include "../../fceu.h"
#include "../../driver.h" #include "../../driver.h"
@ -2114,7 +2112,7 @@ gint convertKeypress(GtkWidget *grab, GdkEventKey *event, gpointer user_data)
// Only let the emulator handle the key event if this window has the input focus. // Only let the emulator handle the key event if this window has the input focus.
if(keystate == 0 || gtk_window_is_active(GTK_WINDOW(MainWindow))) if(keystate == 0 || gtk_window_is_active(GTK_WINDOW(MainWindow)))
{ {
#if SDL_VERSION_ATLEAST(1, 3, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey(sdlkey)] = keystate; SDL_GetKeyboardState(NULL)[SDL_GetScancodeFromKey(sdlkey)] = keystate;
#else #else
SDL_GetKeyState(NULL)[sdlkey] = keystate; SDL_GetKeyState(NULL)[sdlkey] = keystate;

View File

@ -148,8 +148,8 @@ _keyonly (int a)
// check for valid key // check for valid key
if (a > SDLK_LAST + 1 || a < 0) if (a > SDLK_LAST + 1 || a < 0)
return 0; return 0;
#if SDL_VERSION_ATLEAST(1, 3, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (g_keyState[SDL_GetScancodeFromKey ((SDLKey) a)]) if (g_keyState[SDL_GetScancodeFromKey (a)])
#else #else
if (g_keyState[a]) if (g_keyState[a])
#endif #endif
@ -198,7 +198,16 @@ TogglePause ()
int no_cursor; int no_cursor;
g_config->getOption("SDL.NoFullscreenCursor", &no_cursor); g_config->getOption("SDL.NoFullscreenCursor", &no_cursor);
int fullscreen;
g_config->getOption ("SDL.Fullscreen", &fullscreen);
// Don't touch grab when in windowed mode
if(fullscreen == 0)
return;
#if SDL_VERSION_ATLEAST(2, 0, 0)
// TODO - SDL2
#else
if (FCEUI_EmulationPaused () == 0) if (FCEUI_EmulationPaused () == 0)
{ {
SDL_WM_GrabInput (SDL_GRAB_ON); SDL_WM_GrabInput (SDL_GRAB_ON);
@ -209,7 +218,7 @@ TogglePause ()
SDL_WM_GrabInput (SDL_GRAB_OFF); SDL_WM_GrabInput (SDL_GRAB_OFF);
SDL_ShowCursor (1); SDL_ShowCursor (1);
} }
#endif
return; return;
} }
@ -420,7 +429,11 @@ void FCEUD_LoadStateFrom ()
unsigned int *GetKeyboard(void) unsigned int *GetKeyboard(void)
{ {
int size = 256; int size = 256;
#if SDL_VERSION_ATLEAST(2, 0, 0)
Uint8* keystate = SDL_GetKeyboardState(&size);
#else
Uint8* keystate = SDL_GetKeyState(&size); Uint8* keystate = SDL_GetKeyState(&size);
#endif
return (unsigned int*)(keystate); return (unsigned int*)(keystate);
} }
@ -442,20 +455,29 @@ static void KeyboardCommands ()
// check if the family keyboard is enabled // check if the family keyboard is enabled
if (CurInputType[2] == SIFC_FKB) if (CurInputType[2] == SIFC_FKB)
{ {
#if SDL_VERSION_ATLEAST(1, 3, 0)
// TODO - SDL2
if (0)
#else
if (keyonly (SCROLLLOCK)) if (keyonly (SCROLLLOCK))
#endif
{ {
g_fkbEnabled ^= 1; g_fkbEnabled ^= 1;
FCEUI_DispMessage ("Family Keyboard %sabled.", 0, FCEUI_DispMessage ("Family Keyboard %sabled.", 0,
g_fkbEnabled ? "en" : "dis"); g_fkbEnabled ? "en" : "dis");
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
// TODO - SDL2
#else
SDL_WM_GrabInput (g_fkbEnabled ? SDL_GRAB_ON : SDL_GRAB_OFF); SDL_WM_GrabInput (g_fkbEnabled ? SDL_GRAB_ON : SDL_GRAB_OFF);
#endif
if (g_fkbEnabled) if (g_fkbEnabled)
{ {
return; return;
} }
} }
#if SDL_VERSION_ATLEAST(1, 3, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (g_keyState[SDL_GetScancodeFromKey (SDLK_LSHIFT)] if (g_keyState[SDL_GetScancodeFromKey (SDLK_LSHIFT)]
|| g_keyState[SDL_GetScancodeFromKey (SDLK_RSHIFT)]) || g_keyState[SDL_GetScancodeFromKey (SDLK_RSHIFT)])
#else #else
@ -464,7 +486,7 @@ static void KeyboardCommands ()
is_shift = 1; is_shift = 1;
else else
is_shift = 0; is_shift = 0;
#if SDL_VERSION_ATLEAST(1, 3, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (g_keyState[SDL_GetScancodeFromKey (SDLK_LALT)] if (g_keyState[SDL_GetScancodeFromKey (SDLK_LALT)]
|| g_keyState[SDL_GetScancodeFromKey (SDLK_RALT)]) || g_keyState[SDL_GetScancodeFromKey (SDLK_RALT)])
#else #else
@ -472,7 +494,7 @@ static void KeyboardCommands ()
#endif #endif
{ {
is_alt = 1; is_alt = 1;
#if !SDL_VERSION_ATLEAST(1, 3, 0) #if !SDL_VERSION_ATLEAST(2, 0, 0)
// workaround for GDK->SDL in GTK problems where ALT release is never getting sent // workaround for GDK->SDL in GTK problems where ALT release is never getting sent
// i know this is sort of an ugly hack to fix this, but the bug is rather annoying // i know this is sort of an ugly hack to fix this, but the bug is rather annoying
// prg318 10/23/11 // prg318 10/23/11
@ -1013,7 +1035,11 @@ ButtonConfigBegin ()
sprintf (SDL_windowhack, "SDL_WINDOWID=%u", sprintf (SDL_windowhack, "SDL_WINDOWID=%u",
(unsigned int) (unsigned int)
GDK_WINDOW_XID (gtk_widget_get_window (evbox))); GDK_WINDOW_XID (gtk_widget_get_window (evbox)));
#if SDL_VERSION_ATLEAST(2, 0, 0)
// TODO - SDL2
#else
SDL_putenv (SDL_windowhack); SDL_putenv (SDL_windowhack);
#endif
} }
#endif #endif
if (SDL_InitSubSystem (SDL_INIT_VIDEO) == -1) if (SDL_InitSubSystem (SDL_INIT_VIDEO) == -1)
@ -1023,8 +1049,12 @@ ButtonConfigBegin ()
} }
// set the screen and notify the user of button configuration // set the screen and notify the user of button configuration
#if SDL_VERSION_ATLEAST(2, 0, 0)
// TODO - SDL2
#else
screen = SDL_SetVideoMode (420, 200, 8, 0); screen = SDL_SetVideoMode (420, 200, 8, 0);
SDL_WM_SetCaption ("Button Config", 0); SDL_WM_SetCaption ("Button Config", 0);
#endif
} }
} }
@ -1071,8 +1101,8 @@ DTestButton (ButtConfig * bc)
{ {
if (bc->ButtType[x] == BUTTC_KEYBOARD) if (bc->ButtType[x] == BUTTC_KEYBOARD)
{ {
#if SDL_VERSION_ATLEAST(1,3,0) #if SDL_VERSION_ATLEAST(2, 0, 0)
if (g_keyState[SDL_GetScancodeFromKey ((SDLKey) bc->ButtonNum[x])]) if (g_keyState[SDL_GetScancodeFromKey (bc->ButtonNum[x])])
{ {
#else #else
if (g_keyState[bc->ButtonNum[x]]) if (g_keyState[bc->ButtonNum[x]])
@ -1101,10 +1131,15 @@ DTestButton (ButtConfig * bc)
#define GPZ() {MKZ(), MKZ(), MKZ(), MKZ()} #define GPZ() {MKZ(), MKZ(), MKZ(), MKZ()}
ButtConfig GamePadConfig[4][10] = { ButtConfig GamePadConfig[4][10] = {
#if SDL_VERSION_ATLEAST(2, 0, 0)
/* Gamepad 1 */
{MK (KP_3), MK (KP_2), MK (SLASH), MK (ENTER),
MK (W), MK (Z), MK (A), MK (S), MKZ (), MKZ ()},
#else
/* Gamepad 1 */ /* Gamepad 1 */
{MK (KP3), MK (KP2), MK (SLASH), MK (ENTER), {MK (KP3), MK (KP2), MK (SLASH), MK (ENTER),
MK (W), MK (Z), MK (A), MK (S), MKZ (), MKZ ()} MK (W), MK (Z), MK (A), MK (S), MKZ (), MKZ ()},
, #endif
/* Gamepad 2 */ /* Gamepad 2 */
GPZ (), GPZ (),
@ -1589,7 +1624,11 @@ ButtonName (const ButtConfig * bc, int which)
switch (bc->ButtType[which]) switch (bc->ButtType[which])
{ {
case BUTTC_KEYBOARD: case BUTTC_KEYBOARD:
#if SDL_VERSION_ATLEAST(2,0,0)
return SDL_GetKeyName (bc->ButtonNum[which]);
#else
return SDL_GetKeyName ((SDLKey) bc->ButtonNum[which]); return SDL_GetKeyName ((SDLKey) bc->ButtonNum[which]);
#endif
case BUTTC_JOYSTICK: case BUTTC_JOYSTICK:
int joyNum, inputNum; int joyNum, inputNum;
const char *inputType, *inputDirection; const char *inputType, *inputDirection;
@ -1651,7 +1690,11 @@ DWaitButton (const uint8 * text, ButtConfig * bc, int wb)
{ {
std::string title = "Press a key for "; std::string title = "Press a key for ";
title += (const char *) text; title += (const char *) text;
#if SDL_VERSION_ATLEAST(2,0,0)
// TODO - SDL2
#else
SDL_WM_SetCaption (title.c_str (), 0); SDL_WM_SetCaption (title.c_str (), 0);
#endif
puts ((const char *) text); puts ((const char *) text);
} }

View File

@ -1,4 +1,3 @@
#include <SDL.h>
#define SDLK_A SDLK_a #define SDLK_A SDLK_a
#define SDLK_B SDLK_b #define SDLK_B SDLK_b
#define SDLK_C SDLK_c #define SDLK_C SDLK_c
@ -43,7 +42,7 @@
#define SDLK_SCROLLLOCK SDLK_SCROLLOCK /* I guess the SDL people don't like lots of Ls... */ #define SDLK_SCROLLLOCK SDLK_SCROLLOCK /* I guess the SDL people don't like lots of Ls... */
#define SDLK_GRAVE SDLK_BACKQUOTE #define SDLK_GRAVE SDLK_BACKQUOTE
#define MKK(k) SDLK_##k #define MKK(k) SDLK_##k
#if SDL_VERSION_ATLEAST(1, 3, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
#define SDLK_LAST SDL_NUM_SCANCODES #define SDLK_LAST SDL_NUM_SCANCODES
#endif #endif
#define MKK_COUNT (SDLK_LAST+1) #define MKK_COUNT (SDLK_LAST+1)

View File

@ -20,8 +20,6 @@
#ifndef __FCEU_SDL_MAIN_H #ifndef __FCEU_SDL_MAIN_H
#define __FCEU_SDL_MAIN_H #define __FCEU_SDL_MAIN_H
#include <SDL.h>
#include "../../driver.h" #include "../../driver.h"
#include "../common/config.h" #include "../common/config.h"
#include "../common/args.h" #include "../common/args.h"

View File

@ -1,5 +1,11 @@
#ifndef __FCEU_SDL_VIDEO_H #ifndef __FCEU_SDL_VIDEO_H
#define __FCEU_SDL_VIDEO_H #define __FCEU_SDL_VIDEO_H
#ifdef _SDL2
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
#endif
uint32 PtoV(uint16 x, uint16 y); uint32 PtoV(uint16 x, uint16 y);
bool FCEUD_ShouldDrawInputAids(); bool FCEUD_ShouldDrawInputAids();
bool FCEUI_AviDisableMovieMessages(); bool FCEUI_AviDisableMovieMessages();

View File

@ -1,7 +1,11 @@
#ifndef __FCEU_SDL_H #ifndef __FCEU_SDL_H
#define __FCEU_SDL_H #define __FCEU_SDL_H
#if _SDL2
#include <SDL2/SDL.h>
#else
#include <SDL.h> #include <SDL.h>
#endif
#include "main.h" #include "main.h"
#include "dface.h" #include "dface.h"
#include "input.h" #include "input.h"