From 82c55b16e4526a4270c744e653034d7f5c383ec4 Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Fri, 19 Feb 2010 00:40:16 +0000 Subject: [PATCH] GTK: added GUI for --inputcfg; only works with gamepad 1 currently --- src/drivers/sdl/gui.cpp | 67 ++++++++++++++++++++++++++++++--------- src/drivers/sdl/input.cpp | 10 +++--- src/drivers/sdl/input.h | 13 +++++--- 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 00549101..d880e700 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -10,6 +10,7 @@ #include "sdl.h" #include "gui.h" #include "dface.h" +#include "input.h" #ifdef _S9XLUA_H #include "../../fceulua.h" @@ -17,28 +18,62 @@ extern Config *g_config; -// test rendering -//SDL_Surface* screen = NULL; -//SDL_Surface* hello = NULL; - GtkWidget* MainWindow = NULL; - -// we're not using this loop right now since integrated sdl is broken -gint mainLoop(gpointer data) +int configGamepadButton(GtkButton* button, gpointer p) { - // test render - /* - SDL_UpdateRect(screen, 0, 0, xres, yres); + int x = GPOINTER_TO_INT(p); + int padNo = 0; + char buf[256]; + std::string prefix; + + ButtonConfigBegin(); + + snprintf(buf, 256, "SDL.Input.GamePad.%d", padNo); + prefix = buf; + ConfigButton("Press key twice to bind...", &GamePadConfig[padNo][x]); + + g_config->setOption(prefix + GamePadNames[x], GamePadConfig[padNo][x].ButtonNum[0]); + + if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_KEYBOARD) + { + g_config->setOption(prefix + "DeviceType", "Keyboard"); + } else if(GamePadConfig[padNo][x].ButtType[0] == BUTTC_JOYSTICK) { + g_config->setOption(prefix + "DeviceType", "Joystick"); + } else { + g_config->setOption(prefix + "DeviceType", "Unknown"); + } + g_config->setOption(prefix + "DeviceNum", GamePadConfig[padNo][0].DeviceNum[0]); + + ButtonConfigEnd(); + + return 0; +} + +// TODO: Implement something for gamepads 1 - 4 +// shouldnt be hard but im lazy right now +void openGamepadConfig() +{ + GtkWidget* win; + GtkWidget* vbox; + GtkWidget* buttons[10]; + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win), "Gamepad 1 Config"); + gtk_widget_set_size_request(win, 250, 600); + vbox = gtk_vbox_new(TRUE, 2); + for(int i=0; i<10; i++) + { + buttons[i] = gtk_button_new_with_label(GamePadNames[i]); + gtk_box_pack_start(GTK_BOX(vbox), buttons[i], TRUE, TRUE, 5); + gtk_signal_connect(GTK_OBJECT(buttons[i]), "clicked", G_CALLBACK(configGamepadButton), GINT_TO_POINTER(i)); + } - SDL_BlitSurface (hello, NULL, screen, NULL); + gtk_container_add(GTK_CONTAINER(win), vbox); - SDL_Flip( screen ); - */ - DoFun(0); + gtk_widget_show_all(win); - return TRUE; + return; } void quit () @@ -263,6 +298,7 @@ static GtkItemFactoryEntry menu_items[] = { { "/Emulator/_Pause", NULL, emuPause, 0, ""}, { "/Emulator/R_esume", NULL, emuResume, 0, ""}, { "/Options/_Preferences", "P" , openPrefs, 0, "", GTK_STOCK_PREFERENCES }, + { "/Options/_Gamepad Config", NULL , openGamepadConfig, 0, "", GTK_STOCK_PREFERENCES }, { "/Options/tear", NULL, NULL, 0, "" }, { "/Options/_Fullscreen", NULL, enableFullscreen, 0, "" }, // { "/Options/sep", NULL, NULL, 0, "" }, @@ -395,3 +431,4 @@ int InitGTKSubsystem(int argc, char** argv) return 0; } + diff --git a/src/drivers/sdl/input.cpp b/src/drivers/sdl/input.cpp index 69a00264..23558401 100644 --- a/src/drivers/sdl/input.cpp +++ b/src/drivers/sdl/input.cpp @@ -745,7 +745,7 @@ static int bcpv,bcpj; * subsystems into a well-known state. Button configuration really * needs to be cleaned up after the new config system is in place. */ -static int +int ButtonConfigBegin() { SDL_Surface *screen; @@ -781,7 +781,7 @@ ButtonConfigBegin() * subsystems to their previous state. Button configuration really * needs to be cleaned up after the new config system is in place. */ -static void +void ButtonConfigEnd() { extern FCEUGI *GameInfo; @@ -829,7 +829,7 @@ DTestButton(ButtConfig *bc) #define MKZ() {{0},{0},{0},0} #define GPZ() {MKZ(), MKZ(), MKZ(), MKZ()} -static ButtConfig GamePadConfig[4][10]={ +ButtConfig GamePadConfig[4][10]={ /* Gamepad 1 */ { MK(KP3), MK(KP2), MK(TAB), MK(ENTER), MK(W), MK(Z), MK(A), MK(S), MKZ(), MKZ() }, @@ -1321,7 +1321,7 @@ DWaitButton(const uint8 *text, * used as input for the specified button, thus allowing up to four * possible settings for each input button. */ -static void +void ConfigButton(char *text, ButtConfig *bc) { @@ -1713,7 +1713,6 @@ UpdateInput(Config *config) fkbmap[j].NumC = 1; } } - // Definitions from main.h: // GamePad defaults const char *GamePadNames[GAMEPAD_NUM_BUTTONS] = @@ -1807,3 +1806,4 @@ const int DefaultFamilyKeyBoard[FAMILYKEYBOARD_NUM_BUTTONS] = SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_RALT, SDLK_RSHIFT, SDLK_LALT, SDLK_SPACE, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_UP, SDLK_LEFT, SDLK_RIGHT, SDLK_DOWN }; + diff --git a/src/drivers/sdl/input.h b/src/drivers/sdl/input.h index 4ad76f6c..ce592500 100644 --- a/src/drivers/sdl/input.h +++ b/src/drivers/sdl/input.h @@ -16,6 +16,9 @@ extern CFGSTRUCT InputConfig[]; extern ARGPSTRUCT InputArgs[]; void ParseGIInput(FCEUGI *GI); void setHotKeys(); +int ButtonConfigBegin(); +void ButtonConfigEnd(); +void ConfigButton(char *text, ButtConfig *bc); #define BUTTC_KEYBOARD 0x00 #define BUTTC_JOYSTICK 0x01 @@ -28,12 +31,10 @@ void setHotKeys(); void InitInputInterface(void); void InputUserActiveFix(void); -#ifdef EXTGUI extern ButtConfig GamePadConfig[4][10]; -extern ButtConfig powerpadsc[2][12]; -extern ButtConfig QuizKingButtons[6]; -extern ButtConfig FTrainerButtons[12]; -#endif +//extern ButtConfig powerpadsc[2][12]; +//extern ButtConfig QuizKingButtons[6]; +//extern ButtConfig FTrainerButtons[12]; void IncreaseEmulationSpeed(void); void DecreaseEmulationSpeed(void); @@ -45,4 +46,6 @@ void FCEUD_UpdateInput(void); void UpdateInput(Config *config); void InputCfg(const std::string &); + + #endif