From 8d4a505f7237e8ba9fc683de97946d5a571fcbc2 Mon Sep 17 00:00:00 2001 From: matusz Date: Wed, 17 Jun 2009 18:04:10 +0000 Subject: [PATCH] gtk-port: unhide cheat menu items limit cheat size option to 1-4 --- desmume/src/gtk/cheatsGTK.cpp | 80 +++++++++++++++++++++++++++++++---- desmume/src/gtk/main.cpp | 8 ---- desmume/src/gtk/main.h | 9 +++- 3 files changed, 78 insertions(+), 19 deletions(-) diff --git a/desmume/src/gtk/cheatsGTK.cpp b/desmume/src/gtk/cheatsGTK.cpp index a2b67cc59..378c6cd35 100644 --- a/desmume/src/gtk/cheatsGTK.cpp +++ b/desmume/src/gtk/cheatsGTK.cpp @@ -39,8 +39,17 @@ enum { NUM_COL }; +enum +{ + COLUMN_SIZE_TEXT, + NUM_SIZE_COLUMNS +}; + +GtkTreeModel * size_model; + enum { TYPE_TOGGLE, + TYPE_COMBO, TYPE_STRING }; @@ -50,7 +59,7 @@ static struct { gint column; } columnTable[]={ { "Enabled", TYPE_TOGGLE, COLUMN_ENABLED}, - { "Size", TYPE_STRING, COLUMN_SIZE}, + { "Size", TYPE_COMBO, COLUMN_SIZE}, { "Offset", TYPE_STRING, COLUMN_HI}, { "Value", TYPE_STRING, COLUMN_LO}, { "Description", TYPE_STRING, COLUMN_DESC} @@ -177,7 +186,39 @@ static void cheat_list_add_cheat(GtkWidget * widget, gpointer data) #undef NEW_DESC } -static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore *store) +static GtkTreeModel * +create_numbers_model (void) +{ +#define N_NUMBERS 4 + gint i = 0; + GtkListStore *model; + GtkTreeIter iter; + + /* create list store */ + model = gtk_list_store_new (NUM_SIZE_COLUMNS, G_TYPE_STRING, G_TYPE_INT); + + /* add numbers */ + for (i = 1; i < N_NUMBERS+1; i++) + { + char str[2]; + + str[0] = '0' + i; + str[1] = '\0'; + + gtk_list_store_append (model, &iter); + + gtk_list_store_set (model, &iter, + COLUMN_SIZE_TEXT, str, + -1); + } + + return GTK_TREE_MODEL (model); + +#undef N_NUMBERS +} + +static void cheat_list_add_columns(GtkTreeView * tree, + GtkListStore * store) { GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree)); @@ -186,20 +227,40 @@ static void cheat_list_add_columns(GtkTreeView * tree, GtkListStore *store) GtkCellRenderer *renderer; GtkTreeViewColumn *column; const gchar *attrib; - if (columnTable[ii].type == TYPE_TOGGLE) { + switch (columnTable[ii].type) { + case TYPE_TOGGLE: renderer = gtk_cell_renderer_toggle_new(); g_signal_connect(renderer, "toggled", G_CALLBACK(enabled_toggled), model); attrib = "active"; - } else { + break; + case TYPE_STRING: renderer = gtk_cell_renderer_text_new(); - g_object_set (renderer, "editable", TRUE, NULL); - g_signal_connect (renderer, "edited", G_CALLBACK (cheat_list_modify_cheat), store); + g_object_set(renderer, "editable", TRUE, NULL); + g_signal_connect(renderer, "edited", + G_CALLBACK(cheat_list_modify_cheat), store); attrib = "text"; + break; + case TYPE_COMBO: + renderer = gtk_cell_renderer_combo_new(); + g_object_set(renderer, + "model", size_model, + "text-column", COLUMN_SIZE_TEXT, + "editable", TRUE, + "has-entry", FALSE, + NULL); + g_signal_connect(renderer, "edited", + G_CALLBACK(cheat_list_modify_cheat), store); + attrib = "text"; + break; } - column = gtk_tree_view_column_new_with_attributes(columnTable[ii].caption, - renderer, attrib, columnTable[ii].column, NULL); - g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (columnTable[ii].column)); + column = + gtk_tree_view_column_new_with_attributes(columnTable[ii]. + caption, renderer, + attrib, columnTable[ii].column, + NULL); + g_object_set_data(G_OBJECT(renderer), "column", + GINT_TO_POINTER(columnTable[ii].column)); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); } @@ -254,6 +315,7 @@ static GtkWidget *cheat_list_create_ui() g_signal_connect (button, "clicked", G_CALLBACK (cheat_list_remove_cheat), tree); gtk_container_add(GTK_CONTAINER(hbbox),button); + size_model = create_numbers_model(); cheat_list_add_columns(GTK_TREE_VIEW(tree), store); /* Setup the selection handler */ diff --git a/desmume/src/gtk/main.cpp b/desmume/src/gtk/main.cpp index 070ccc46c..15c55161f 100644 --- a/desmume/src/gtk/main.cpp +++ b/desmume/src/gtk/main.cpp @@ -192,12 +192,10 @@ static const char *ui_description = " " " " " " -#ifdef DESMUME_GTK_CHEAT_BROKEN " " " " " " " " -#endif " " " " " " @@ -264,11 +262,9 @@ static const GtkActionEntry action_entries[] = { { "reset", "gtk-refresh", "Re_set", NULL, NULL, Reset }, { "FrameskipMenu", NULL, "_Frameskip" }, { "LayersMenu", NULL, "_Layers" }, -#ifdef DESMUME_GTK_CHEAT_BROKEN { "CheatMenu", NULL, "_Cheat" }, { "cheatsearch", NULL, "_Search", NULL, NULL, CheatSearch }, { "cheatlist", NULL, "_List", NULL, NULL, CheatList }, -#endif { "ConfigMenu", NULL, "_Config" }, { "ConfigSaveMenu", NULL, "_Saves" }, @@ -582,10 +578,8 @@ static int Open(const char *filename, const char *cflash_disk_image) { int res; res = NDS_LoadROM( filename, cflash_disk_image ); -#ifdef DESMUME_GTK_CHEAT_BROKEN if(res > 0) gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), TRUE); -#endif return res; } @@ -1840,10 +1834,8 @@ common_gtk_main( struct configured_features *my_config) gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE); -#ifdef DESMUME_GTK_CHEAT_BROKEN gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatlist"), FALSE); gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "cheatsearch"), FALSE); -#endif gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); diff --git a/desmume/src/gtk/main.h b/desmume/src/gtk/main.h index afc690eae..a12669fcf 100644 --- a/desmume/src/gtk/main.h +++ b/desmume/src/gtk/main.h @@ -1,2 +1,7 @@ -extern void Pause(); -extern void Launch(); +#ifndef __DESMUME_GTK_MAIN_H__ +#define __DESMUME_GTK_MAIN_H__ + +void Pause(); +void Launch(); + +#endif