Hotkey selected state cleanup. Sync gui menu selected state when state changes occur via hotkeys. Removed deprecated gtk widgets from sdl/input.cpp.

This commit is contained in:
Matthew Budd 2020-05-16 09:09:36 -04:00
parent 3573a596e9
commit c3e4db0faa
3 changed files with 49 additions and 23 deletions

View File

@ -59,15 +59,15 @@ GtkWidget *evbox = NULL;
GtkWidget *padNoCombo = NULL; GtkWidget *padNoCombo = NULL;
GtkWidget *configNoCombo = NULL; GtkWidget *configNoCombo = NULL;
GtkWidget *buttonMappings[10]; GtkWidget *buttonMappings[10];
GtkWidget *Menubar; static GtkWidget *Menubar = NULL;
GtkRadioAction *stateSlot = NULL; static GtkRadioMenuItem *stateSlot[10] = { NULL };
bool gtkIsStarted = false; bool gtkIsStarted = false;
bool menuTogglingEnabled = false; bool menuTogglingEnabled = false;
unsigned int gtk_draw_area_width = NES_WIDTH; unsigned int gtk_draw_area_width = NES_WIDTH;
unsigned int gtk_draw_area_height = NES_HEIGHT; unsigned int gtk_draw_area_height = NES_HEIGHT;
static unsigned int gtk_win_width = NES_WIDTH; static unsigned int gtk_win_width = 0;
static unsigned int gtk_win_height = NES_HEIGHT; static unsigned int gtk_win_height = 0;
static GtkTreeStore *hotkey_store = NULL; static GtkTreeStore *hotkey_store = NULL;
// check to see if a particular GTK version is available // check to see if a particular GTK version is available
@ -2168,11 +2168,18 @@ void quickSave (void)
FCEUI_SaveState (NULL); FCEUI_SaveState (NULL);
} }
//void changeState(GtkAction *action, GtkRadioAction *current, gpointer data) void setStateMenuItem( int i )
void changeState (GtkRadioMenuItem * radiomenuitem, gpointer user_data)
{ {
//printf("Changing State: %li\n", (long)user_data); if ( (i >= 0) && (i < 10) )
FCEUI_SelectState ((long) user_data, 0); {
gtk_menu_item_activate( GTK_MENU_ITEM(stateSlot[i]) );
}
}
static void changeState (GtkRadioMenuItem * radiomenuitem, gpointer user_data)
{
printf("GTK Changing State: %li\n", (long)user_data);
FCEUI_SelectState ((long) user_data, 1);
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
@ -2526,6 +2533,8 @@ static GtkWidget *CreateMenubar (GtkWidget * window)
item = gtk_radio_menu_item_new_with_label (radioGroup, stmp); item = gtk_radio_menu_item_new_with_label (radioGroup, stmp);
stateSlot[i] = GTK_RADIO_MENU_ITEM(item);
radioGroup = radioGroup =
gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM
(item)); (item));
@ -3015,7 +3024,7 @@ gboolean handle_resize (GtkWindow * win, GdkEvent * event, gpointer data)
// of the GTK window as possible // of the GTK window as possible
// get new window width/height // get new window width/height
int width, height, winsize_changed; int width, height, draw_width, draw_height, winsize_changed = 0;
width = event->configure.width; width = event->configure.width;
height = event->configure.height; height = event->configure.height;
//printf ("DEBUG: Configure new window size: %dx%d\n", width, height); //printf ("DEBUG: Configure new window size: %dx%d\n", width, height);
@ -3029,8 +3038,15 @@ gboolean handle_resize (GtkWindow * win, GdkEvent * event, gpointer data)
double xscale = width / (double) NES_WIDTH; double xscale = width / (double) NES_WIDTH;
double yscale = height / (double) NES_HEIGHT; double yscale = height / (double) NES_HEIGHT;
gtk_draw_area_width = gtk_widget_get_allocated_width (evbox); draw_width = gtk_widget_get_allocated_width (evbox);
gtk_draw_area_height = gtk_widget_get_allocated_height (evbox); draw_height = gtk_widget_get_allocated_height (evbox);
if ( (draw_width != gtk_draw_area_width) || (draw_height != gtk_draw_area_height) )
{
winsize_changed = 1;
}
gtk_draw_area_width = draw_width;
gtk_draw_area_height = draw_height;
if ( gtk_draw_area_width < NES_WIDTH ) gtk_draw_area_width = NES_WIDTH; if ( gtk_draw_area_width < NES_WIDTH ) gtk_draw_area_width = NES_WIDTH;
if ( gtk_draw_area_height < NES_HEIGHT ) gtk_draw_area_height = NES_HEIGHT; if ( gtk_draw_area_height < NES_HEIGHT ) gtk_draw_area_height = NES_HEIGHT;

View File

@ -27,7 +27,6 @@
#endif #endif
extern GtkWidget* MainWindow; extern GtkWidget* MainWindow;
extern GtkWidget* evbox; extern GtkWidget* evbox;
extern GtkRadioAction* stateSlot;
extern int GtkMouseData[3]; extern int GtkMouseData[3];
extern bool gtkIsStarted; extern bool gtkIsStarted;
@ -55,6 +54,8 @@ void setGl(GtkWidget* w, gpointer p);
void setDoubleBuffering(GtkWidget* w, gpointer p); void setDoubleBuffering(GtkWidget* w, gpointer p);
#endif #endif
void setStateMenuItem( int i );
void openVideoConfig(); void openVideoConfig();
void openSoundConfig(); void openSoundConfig();
void quit (); void quit ();

View File

@ -31,6 +31,7 @@
#include "../../movie.h" #include "../../movie.h"
#include "../../fceu.h" #include "../../fceu.h"
#include "../../driver.h" #include "../../driver.h"
#include "../../state.h"
#include "../../utils/xstring.h" #include "../../utils/xstring.h"
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
#include "../../fceulua.h" #include "../../fceulua.h"
@ -281,16 +282,16 @@ std::string GetFilename (const char *title, bool save, const char *filter)
if (save) if (save)
fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL, fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, "_Cancel",
GTK_RESPONSE_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE_AS, "_Save",
GTK_RESPONSE_ACCEPT, NULL); GTK_RESPONSE_ACCEPT, NULL);
else else
fileChooser = gtk_file_chooser_dialog_new ("Open", NULL, fileChooser = gtk_file_chooser_dialog_new ("Open", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, "_Cancel",
GTK_RESPONSE_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, "_Open",
GTK_RESPONSE_ACCEPT, NULL); GTK_RESPONSE_ACCEPT, NULL);
// TODO: make file filters case insensitive // TODO: make file filters case insensitive
@ -739,22 +740,30 @@ static void KeyboardCommands ()
#endif #endif
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{
if (_keyonly (Hotkeys[HK_SELECT_STATE_0 + i])) if (_keyonly (Hotkeys[HK_SELECT_STATE_0 + i]))
{ {
#ifdef _GTK #ifdef _GTK
gtk_radio_action_set_current_value (stateSlot, i); setStateMenuItem(i);
#endif #endif
FCEUI_SelectState (i, 1); FCEUI_SelectState (i, 1);
} }
}
if (_keyonly (Hotkeys[HK_SELECT_STATE_NEXT])) if (_keyonly (Hotkeys[HK_SELECT_STATE_NEXT]))
{ {
FCEUI_SelectStateNext (1); FCEUI_SelectStateNext (1);
#ifdef _GTK
setStateMenuItem( CurrentState );
#endif
} }
if (_keyonly (Hotkeys[HK_SELECT_STATE_PREV])) if (_keyonly (Hotkeys[HK_SELECT_STATE_PREV]))
{ {
FCEUI_SelectStateNext (-1); FCEUI_SelectStateNext (-1);
#ifdef _GTK
setStateMenuItem( CurrentState );
#endif
} }
if (_keyonly (Hotkeys[HK_BIND_STATE])) if (_keyonly (Hotkeys[HK_BIND_STATE]))
@ -1685,13 +1694,13 @@ const char * ButtonName (const ButtConfig * bc, int which)
inputValue = bc->ButtonNum[which] & 0xF; inputValue = bc->ButtonNum[which] & 0xF;
if (inputValue & SDL_HAT_UP) if (inputValue & SDL_HAT_UP)
strncat (direction, "Up ", sizeof (direction)); strncat (direction, "Up ", sizeof (direction)-1);
if (inputValue & SDL_HAT_DOWN) if (inputValue & SDL_HAT_DOWN)
strncat (direction, "Down ", sizeof (direction)); strncat (direction, "Down ", sizeof (direction)-1);
if (inputValue & SDL_HAT_LEFT) if (inputValue & SDL_HAT_LEFT)
strncat (direction, "Left ", sizeof (direction)); strncat (direction, "Left ", sizeof (direction)-1);
if (inputValue & SDL_HAT_RIGHT) if (inputValue & SDL_HAT_RIGHT)
strncat (direction, "Right ", sizeof (direction)); strncat (direction, "Right ", sizeof (direction)-1);
if (direction[0]) if (direction[0])
inputDirection = direction; inputDirection = direction;
@ -2127,7 +2136,7 @@ UpdateInput (Config * config)
for (unsigned int i = 0; i < GAMEPAD_NUM_DEVICES; i++) for (unsigned int i = 0; i < GAMEPAD_NUM_DEVICES; i++)
{ {
char buf[64]; char buf[64];
snprintf (buf, 20, "SDL.Input.GamePad.%d.", i); snprintf (buf, 32, "SDL.Input.GamePad.%d.", i);
prefix = buf; prefix = buf;
config->getOption (prefix + "DeviceType", &device); config->getOption (prefix + "DeviceType", &device);
@ -2160,7 +2169,7 @@ UpdateInput (Config * config)
for (unsigned int i = 0; i < POWERPAD_NUM_DEVICES; i++) for (unsigned int i = 0; i < POWERPAD_NUM_DEVICES; i++)
{ {
char buf[64]; char buf[64];
snprintf (buf, 20, "SDL.Input.PowerPad.%d.", i); snprintf (buf, 32, "SDL.Input.PowerPad.%d.", i);
prefix = buf; prefix = buf;
config->getOption (prefix + "DeviceType", &device); config->getOption (prefix + "DeviceType", &device);