GTK: Add icons to key bindings to clear entry.

This commit is contained in:
Brandon Wright 2019-02-28 21:02:19 -06:00
parent d751e9916c
commit 712c979771
2 changed files with 66 additions and 1 deletions

View File

@ -249,6 +249,15 @@ event_game_data_clear (GtkEntry *entry,
gtk_entry_set_text (entry, SAME_AS_GAME);
}
static void event_binding_icon_clear(GtkEntry *entry,
GtkEntryIconPosition icon_pos,
GdkEvent *event,
gpointer user_data)
{
auto window = (Snes9xPreferences *)user_data;
window->clear_binding(gtk_buildable_get_name(GTK_BUILDABLE(entry)));
}
static void
event_game_data_browse (GtkButton *widget, gpointer data)
{
@ -534,6 +543,27 @@ Snes9xPreferences::Snes9xPreferences (Snes9xConfig *config) :
get_widget ("relative_video_rate"),
NULL,
(GConnectFlags) 0);
for (int i = 0; ; i++)
{
const BindingLink &link = b_links[i];
if (!link.button_name)
break;
GtkWidget *entry = get_widget(link.button_name);
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(entry),
GTK_ENTRY_ICON_SECONDARY,
"edit-clear");
gtk_entry_set_icon_activatable(GTK_ENTRY(entry),
GTK_ENTRY_ICON_SECONDARY,
true);
g_signal_connect_data((gpointer)entry,
"icon-release",
G_CALLBACK(event_binding_icon_clear),
(gpointer)this,
NULL,
(GConnectFlags)0);
}
}
Snes9xPreferences::~Snes9xPreferences ()
@ -1227,11 +1257,45 @@ Snes9xPreferences::get_focused_binding ()
return -1;
}
void Snes9xPreferences::clear_binding(const char *name)
{
Binding unset;
int i;
for (i = 0; i < NUM_JOYPAD_LINKS; i++)
{
if (!strcmp(name, b_links[i].button_name))
{
int current_joypad = get_combo("control_combo");
pad[current_joypad].data[i] = unset;
break;
}
}
if (i == NUM_JOYPAD_LINKS)
{
for (i = NUM_JOYPAD_LINKS; b_links[i].button_name; i++)
{
if (!strcmp(name, b_links[i].button_name))
{
shortcut[i - NUM_JOYPAD_LINKS] = unset;
break;
}
}
}
if (b_links[i].button_name)
{
char buf[256];
unset.to_string(buf);
set_entry_text(b_links[i].button_name, buf);
}
}
void
Snes9xPreferences::bindings_to_dialog (int joypad)
{
char name[256];
Binding *bindings = (Binding *) &pad[joypad];
Binding *bindings = (Binding *) &pad[joypad].data;
set_combo ("control_combo", joypad);

View File

@ -28,6 +28,7 @@ class Snes9xPreferences : public GtkBuilderWindow
int combo_value (int hw_accel);
void focus_next ();
void swap_with ();
void clear_binding (const char *name);
void reset_current_joypad ();
void load_ntsc_settings ();
void store_ntsc_settings ();