ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_glade.h
Revision: 1.3
Committed: 2004-01-23T15:06:17Z (20 years, 2 months ago) by cebix
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -3 lines
Log Message:
no more drive type widgets

File Contents

# Content
1 /*
2 * Prefs_glade.h - Global preferences, Glade/Gnome/Gtk+ specific stuff
3 *
4 * Frodo (C) 1994-1997,2002-2004 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 <gnome.h>
22 #include <glade/glade.h>
23
24 #include <SDL.h>
25
26
27 // Glade XML tree
28 static GladeXML *xml = NULL;
29
30 // Result of ShowEditor()
31 static bool result = false;
32
33 // Pointer to preferences being edited
34 static Prefs *prefs = NULL;
35
36 // Prefs file name
37 static char *prefs_path = NULL;
38
39 // Prototypes
40 static void set_values();
41 static void get_values();
42 static void ghost_widgets();
43
44
45 /*
46 * Show preferences editor (synchronously)
47 * prefs_name points to the file name of the preferences (which may be changed)
48 */
49
50 bool Prefs::ShowEditor(bool startup, char *path)
51 {
52 prefs = this;
53 prefs_path = path;
54
55 // Load XML user interface file on startup
56 if (startup) {
57 xml = glade_xml_new(DATADIR "Frodo.glade", NULL, NULL);
58 if (xml) {
59 glade_xml_signal_autoconnect(xml);
60 set_values();
61 }
62 }
63
64 // No XML means no prefs editor
65 if (!xml)
66 return false;
67
68 // Run editor
69 result = false;
70 gtk_main();
71 return result;
72 }
73
74
75 /*
76 * Set the values of the widgets
77 */
78
79 static void create_joystick_menu(const char *widget_name)
80 {
81 GtkWidget *w = glade_xml_get_widget(xml, widget_name);
82 gtk_option_menu_remove_menu(GTK_OPTION_MENU(w));
83
84 GtkWidget *menu = gtk_menu_new();
85
86 for (int i = -1; i < SDL_NumJoysticks(); ++i) {
87 GtkWidget *item = gtk_menu_item_new_with_label(i < 0 ? "None" : SDL_JoystickName(i));
88 gtk_widget_show(item);
89 gtk_menu_append(GTK_MENU(menu), item);
90 }
91
92 gtk_option_menu_set_menu(GTK_OPTION_MENU(w), menu);
93 }
94
95 static void set_values()
96 {
97 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")), prefs->Emul1541Proc);
98 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")), prefs->MapSlash);
99
100 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive8_path")))), prefs->DrivePath[0]);
101 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive9_path")))), prefs->DrivePath[1]);
102 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive10_path")))), prefs->DrivePath[2]);
103 gtk_entry_set_text(GTK_ENTRY(gnome_file_entry_gtk_entry(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, "drive11_path")))), prefs->DrivePath[3]);
104
105 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")), prefs->DisplayType);
106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")), prefs->SpritesOn);
107 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")), prefs->SpriteCollisions);
108
109 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")), prefs->SIDType);
110 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")), prefs->SIDFilters);
111
112 create_joystick_menu("joystick1_port");
113 create_joystick_menu("joystick2_port");
114
115 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")), prefs->Joystick1Port);
116 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")), prefs->Joystick2Port);
117 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")), prefs->JoystickSwap);
118
119 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")), prefs->SkipFrames);
120 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")), prefs->LimitSpeed);
121 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")), prefs->FastReset);
122
123 gtk_option_menu_set_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")), prefs->REUSize);
124
125 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")), prefs->NormalCycles);
126 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")), prefs->BadLineCycles);
127 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")), prefs->CIACycles);
128 gtk_spin_button_set_value(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")), prefs->FloppyCycles);
129
130 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")), prefs->CIAIRQHack);
131
132 ghost_widgets();
133 }
134
135
136 /*
137 * Get the values of the widgets
138 */
139
140 static void get_drive_path(int num, const char *widget_name)
141 {
142 prefs->DrivePath[num][0] = 0;
143 const char *path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY(glade_xml_get_widget(xml, widget_name)), false);
144 if (path)
145 strncpy(prefs->DrivePath[num], path, 255);
146 prefs->DrivePath[num][255] = 0;
147 }
148
149 static void get_values()
150 {
151 prefs->Emul1541Proc = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "emul1541_proc")));
152 prefs->MapSlash = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "map_slash")));
153
154 get_drive_path(0, "drive8_path");
155 get_drive_path(1, "drive9_path");
156 get_drive_path(2, "drive10_path");
157 get_drive_path(3, "drive11_path");
158
159 prefs->DisplayType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "display_type")));
160 prefs->SpritesOn = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprites_on")));
161 prefs->SpriteCollisions = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sprite_collisions")));
162
163 prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
164 prefs->SIDFilters = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "sid_filters")));
165
166 prefs->Joystick1Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick1_port")));
167 prefs->Joystick2Port = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "joystick2_port")));
168 prefs->JoystickSwap = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "joystick_swap")));
169
170 prefs->SkipFrames = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "skip_frames")));
171 prefs->LimitSpeed = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "limit_speed")));
172 prefs->FastReset = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "fast_reset")));
173
174 prefs->REUSize = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "reu_size")));
175
176 prefs->NormalCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "normal_cycles")));
177 prefs->BadLineCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "bad_line_cycles")));
178 prefs->CIACycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "cia_cycles")));
179 prefs->FloppyCycles = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(glade_xml_get_widget(xml, "floppy_cycles")));
180
181 prefs->CIAIRQHack = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, "cia_irq_hack")));
182 }
183
184
185 /*
186 * Ghost/unghost widgets
187 */
188
189 static void ghost_widget(const char *name, bool ghosted)
190 {
191 gtk_widget_set_sensitive(glade_xml_get_widget(xml, name), !ghosted);
192 }
193
194 static void ghost_widgets()
195 {
196 ghost_widget("drive9_path", prefs->Emul1541Proc);
197 ghost_widget("drive10_path", prefs->Emul1541Proc);
198 ghost_widget("drive11_path", prefs->Emul1541Proc);
199
200 ghost_widget("sid_filters", prefs->SIDType != SIDTYPE_DIGITAL);
201 }
202
203
204 /*
205 * Signal handlers
206 */
207
208 extern "C" gboolean on_prefs_win_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
209 {
210 return false;
211 }
212
213 extern "C" void on_ok_clicked(GtkButton *button, gpointer user_data)
214 {
215 result = true;
216 get_values();
217 prefs->Save(prefs_path);
218 gtk_main_quit();
219 }
220
221 extern "C" void on_quit_clicked(GtkButton *button, gpointer user_data)
222 {
223 result = false;
224 gtk_main_quit();
225 }
226
227 extern "C" void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
228 {
229 gtk_widget_show(glade_xml_get_widget(xml, "about_win"));
230 }
231
232 extern "C" void on_emul1541_proc_toggled(GtkToggleButton *button, gpointer user_data)
233 {
234 prefs->Emul1541Proc = gtk_toggle_button_get_active(button);
235 ghost_widgets();
236 }
237
238 extern "C" void on_sid_type_activate(GtkMenuItem *menuitem, gpointer user_data)
239 {
240 prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type")));
241 ghost_widgets();
242 }