1 |
cebix |
1.1 |
/* |
2 |
|
|
* Prefs_glade.h - Global preferences, Glade/Gnome/Gtk+ specific stuff |
3 |
|
|
* |
4 |
cebix |
1.7 |
* Frodo (C) 1994-1997,2002-2005 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 |
cebix |
1.5 |
return startup; |
67 |
cebix |
1.1 |
|
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 |
cebix |
1.6 |
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)); |
202 |
cebix |
1.1 |
} |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
/* |
206 |
|
|
* Signal handlers |
207 |
|
|
*/ |
208 |
|
|
|
209 |
|
|
extern "C" gboolean on_prefs_win_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data) |
210 |
|
|
{ |
211 |
|
|
return false; |
212 |
|
|
} |
213 |
|
|
|
214 |
|
|
extern "C" void on_ok_clicked(GtkButton *button, gpointer user_data) |
215 |
|
|
{ |
216 |
|
|
result = true; |
217 |
|
|
get_values(); |
218 |
|
|
prefs->Save(prefs_path); |
219 |
|
|
gtk_main_quit(); |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
extern "C" void on_quit_clicked(GtkButton *button, gpointer user_data) |
223 |
|
|
{ |
224 |
|
|
result = false; |
225 |
|
|
gtk_main_quit(); |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
extern "C" void on_about_activate(GtkMenuItem *menuitem, gpointer user_data) |
229 |
|
|
{ |
230 |
cebix |
1.4 |
GladeXML *about_xml = glade_xml_new(DATADIR "Frodo.glade", "about_win", NULL); |
231 |
|
|
if (about_xml) |
232 |
|
|
gtk_widget_show(glade_xml_get_widget(about_xml, "about_win")); |
233 |
cebix |
1.1 |
} |
234 |
|
|
|
235 |
|
|
extern "C" void on_emul1541_proc_toggled(GtkToggleButton *button, gpointer user_data) |
236 |
|
|
{ |
237 |
|
|
prefs->Emul1541Proc = gtk_toggle_button_get_active(button); |
238 |
|
|
ghost_widgets(); |
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
extern "C" void on_sid_type_activate(GtkMenuItem *menuitem, gpointer user_data) |
242 |
|
|
{ |
243 |
|
|
prefs->SIDType = gtk_option_menu_get_history(GTK_OPTION_MENU(glade_xml_get_widget(xml, "sid_type"))); |
244 |
|
|
ghost_widgets(); |
245 |
cebix |
1.6 |
} |
246 |
|
|
|
247 |
|
|
extern "C" void on_sid_filters_toggled(GtkToggleButton *button, gpointer user_data) |
248 |
|
|
{ |
249 |
|
|
prefs->SIDFilters = gtk_toggle_button_get_active(button); |
250 |
cebix |
1.1 |
} |