ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_glade.h
Revision: 1.8
Committed: 2010-04-21T22:07:34Z (13 years, 11 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +17 -5 lines
Log Message:
improved Gtk prefs editor

File Contents

# Content
1 /*
2 * Prefs_glade.h - Global preferences, Glade/Gnome/Gtk+ specific stuff
3 *
4 * Frodo Copyright (C) Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "Version.h"
22
23 #include <gnome.h>
24 #include <glade/glade.h>
25
26 #include <SDL.h>
27
28
29 // Glade XML tree
30 static GladeXML *xml = NULL;
31
32 // Result of ShowEditor()
33 static bool result = false;
34
35 // Pointer to preferences being edited
36 static Prefs *prefs = NULL;
37
38 // Prefs file name
39 static char *prefs_path = NULL;
40
41 // Prototypes
42 static void set_values();
43 static void get_values();
44 static void ghost_widgets();
45
46
47 /*
48 * Show preferences editor (synchronously)
49 * prefs_name points to the file name of the preferences (which may be changed)
50 */
51
52 bool Prefs::ShowEditor(bool startup, char *prefs_name)
53 {
54 prefs = this;
55 prefs_path = prefs_name;
56
57 // Load XML user interface file on startup
58 if (startup) {
59 xml = glade_xml_new(DATADIR "Frodo.glade", NULL, NULL);
60 if (xml) {
61 glade_xml_signal_autoconnect(xml);
62 set_values();
63 }
64 }
65
66 // No XML means no prefs editor
67 if (!xml)
68 return startup;
69
70 // Run editor
71 result = false;
72
73 gtk_widget_show(glade_xml_get_widget(xml, "prefs_win"));
74 gtk_main();
75
76 return result;
77 }
78
79
80 /*
81 * Set the values of the widgets
82 */
83
84 static void create_joystick_menu(const char *widget_name)
85 {
86 GtkWidget *w = glade_xml_get_widget(xml, widget_name);
87 gtk_option_menu_remove_menu(GTK_OPTION_MENU(w));
88
89 GtkWidget *menu = gtk_menu_new();
90
91 for (int i = -1; i < SDL_NumJoysticks(); ++i) {
92 GtkWidget *item = gtk_menu_item_new_with_label(i < 0 ? "None" : SDL_JoystickName(i));
93 gtk_widget_show(item);
94 gtk_menu_append(GTK_MENU(menu), item);
95 }
96
97 gtk_option_menu_set_menu(GTK_OPTION_MENU(w), menu);
98 }
99
100 static void set_values()
101 {
102 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")), prefs->Emul1541Proc);
103 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")), prefs->MapSlash);
104
105 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive8_path")))), prefs->DrivePath[0]);
106 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive9_path")))), prefs->DrivePath[1]);
107 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive10_path")))), prefs->DrivePath[2]);
108 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive11_path")))), prefs->DrivePath[3]);
109
110 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")), prefs->DisplayType);
111 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")), prefs->SpritesOn);
112 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")), prefs->SpriteCollisions);
113
114 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")), prefs->SIDType);
115 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")), prefs->SIDFilters);
116
117 create_joystick_menu("joystick1_port");
118 create_joystick_menu("joystick2_port");
119
120 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")), prefs->Joystick1Port);
121 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")), prefs->Joystick2Port);
122 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")), prefs->JoystickSwap);
123
124 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")), prefs->SkipFrames);
125 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")), prefs->LimitSpeed);
126 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")), prefs->FastReset);
127
128 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")), prefs->REUSize);
129
130 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")), prefs->NormalCycles);
131 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")), prefs->BadLineCycles);
132 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")), prefs->CIACycles);
133 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")), prefs->FloppyCycles);
134
135 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")), prefs->CIAIRQHack);
136
137 ghost_widgets();
138 }
139
140
141 /*
142 * Get the values of the widgets
143 */
144
145 static void get_drive_path(int num, const char *widget_name)
146 {
147 prefs->DrivePath[num][0] = 0;
148 const char *path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, widget_name)), false);
149 if (path)
150 strncpy(prefs->DrivePath[num], path, 255);
151 prefs->DrivePath[num][255] = 0;
152 }
153
154 static void get_values()
155 {
156 prefs->Emul1541Proc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")));
157 prefs->MapSlash = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")));
158
159 get_drive_path(0, "drive8_path");
160 get_drive_path(1, "drive9_path");
161 get_drive_path(2, "drive10_path");
162 get_drive_path(3, "drive11_path");
163
164 prefs->DisplayType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")));
165 prefs->SpritesOn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")));
166 prefs->SpriteCollisions = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")));
167
168 prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
169 prefs->SIDFilters = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")));
170
171 prefs->Joystick1Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")));
172 prefs->Joystick2Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")));
173 prefs->JoystickSwap = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")));
174
175 prefs->SkipFrames = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")));
176 prefs->LimitSpeed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")));
177 prefs->FastReset = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")));
178
179 prefs->REUSize = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")));
180
181 prefs->NormalCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")));
182 prefs->BadLineCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")));
183 prefs->CIACycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")));
184 prefs->FloppyCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")));
185
186 prefs->CIAIRQHack = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")));
187 }
188
189
190 /*
191 * Ghost/unghost widgets
192 */
193
194 static void ghost_widget(const char *name, bool ghosted)
195 {
196 gtk_widget_set_sensitive(glade_xml_get_widget(xml, name), !ghosted);
197 }
198
199 static void ghost_widgets()
200 {
201 ghost_widget("drive9_path", prefs->Emul1541Proc);
202 ghost_widget("drive10_path", prefs->Emul1541Proc);
203 ghost_widget("drive11_path", prefs->Emul1541Proc);
204
205 ghost_widget("sid_filters", prefs->SIDType != SIDTYPE_DIGITAL);
206 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")), prefs->SIDType == SIDTYPE_DIGITAL ? prefs->SIDFilters : (prefs->SIDType == SIDTYPE_SIDCARD ? true : false));
207
208 ghost_widget("timing_control", IsFrodoSC);
209 ghost_widget("advanced_options", IsFrodoSC);
210 }
211
212
213 /*
214 * Signal handlers
215 */
216
217 extern "C" gboolean on_prefs_win_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
218 {
219 return false;
220 }
221
222 extern "C" void on_ok_clicked(GtkButton *button, gpointer user_data)
223 {
224 result = true;
225 get_values();
226 prefs->Save(prefs_path);
227 gtk_widget_hide(glade_xml_get_widget(xml, "prefs_win"));
228 gtk_main_quit();
229 }
230
231 extern "C" void on_quit_clicked(GtkButton *button, gpointer user_data)
232 {
233 result = false;
234 gtk_main_quit();
235 }
236
237 extern "C" void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
238 {
239 GladeXML *about_xml = glade_xml_new(DATADIR "Frodo.glade", "about_win", NULL);
240 if (about_xml) {
241 GtkWidget *about_win = glade_xml_get_widget(about_xml, "about_win");
242 g_object_set(about_win, "name", VERSION_STRING, NULL);
243 gtk_widget_show(about_win);
244 }
245 }
246
247 extern "C" void on_emul1541_proc_toggled(GtkToggleButton *button, gpointer user_data)
248 {
249 prefs->Emul1541Proc = gtk_toggle_button_get_active(button);
250 ghost_widgets();
251 }
252
253 extern "C" void on_sid_type_activate(GtkMenuItem *menuitem, gpointer user_data)
254 {
255 prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
256 ghost_widgets();
257 }
258
259 extern "C" void on_sid_filters_toggled(GtkToggleButton *button, gpointer user_data)
260 {
261 prefs->SIDFilters = gtk_toggle_button_get_active(button);
262 }