5 * Copyright (C) 2005 Kevin Webb
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "../TextureLoader.h"
27 #include "callbacks.h"
28 #include "interface.h"
33 gui_get_dimensions (GtkButton
*button
)
36 GtkWidget
*optResolutions
;
39 optResolutions
= lookup_widget(GTK_WIDGET(button
), "optResolutions");
41 resolution
= (int) gtk_option_menu_get_history((GtkOptionMenu
*) optResolutions
);
44 // These resolution values should proabably be constants somewhere, rather
45 // than hardcoding them in two places...
48 return GC_RESOLUTION_1
;
50 return GC_RESOLUTION_2
;
52 return GC_RESOLUTION_3
;
54 return GC_RESOLUTION_4
;
56 return GC_RESOLUTION_0
;
62 gui_data_save (GtkButton
*button
)
66 GtkEntry
*entPlayerName
;
67 GtkWidget
*optResolutions
;
68 GtkWidget
*cbtnLowGraphics
;
69 GtkWidget
*cbtnReallyLowGraphics
;
71 char player_name
[GC_PLAYER_NAME_LENGTH
];
76 // Get the current name in the name text box.
77 entPlayerName
= GTK_ENTRY(lookup_widget(GTK_WIDGET(button
), "entPlayerName"));
79 tmp
= (gchar
*) gtk_entry_get_text(entPlayerName
);
81 if (strlen(tmp
) == 0) {
82 gtk_entry_set_text(entPlayerName
, g_get_user_name());
85 g_strlcpy(player_name
, tmp
, 256);
89 // Get the currently selected resolution.
90 optResolutions
= lookup_widget(GTK_WIDGET(button
), "optResolutions");
92 resolution
= (int) gtk_option_menu_get_history((GtkOptionMenu
*) optResolutions
);
95 // Get the status of the low and really low graphics check boxes.
96 cbtnLowGraphics
= lookup_widget(GTK_WIDGET(button
), "cbtnLowGraphics");
97 cbtnReallyLowGraphics
= lookup_widget(GTK_WIDGET(button
), "cbtnReallyLowGraphics");
98 if (cbtnLowGraphics
&& cbtnReallyLowGraphics
) {
99 low
= gtk_toggle_button_get_active((GtkToggleButton
*) cbtnLowGraphics
);
100 reallylow
= gtk_toggle_button_get_active((GtkToggleButton
*) cbtnReallyLowGraphics
);
103 // Generate the file name and write the data,
104 TextureLoader::buildLocalDataFileName(GC_GUI_FILE_NAME
, file_name
);
106 ofstream
file(file_name
);
108 cerr
<< "Unable to write gui data to file!\n";
112 file
<< player_name
<< endl
;
113 file
<< resolution
<< endl
;
115 file
<< reallylow
<< endl
;
122 gui_data_read (GtkWidget
*widget
)
127 GtkEntry
*entPlayerName
;
128 GtkWidget
*optResolutions
;
129 GtkWidget
*cbtnLowGraphics
;
130 GtkWidget
*cbtnReallyLowGraphics
;
131 char player_name
[GC_PLAYER_NAME_LENGTH
];
136 // Generate the name of the file and read the data.
137 TextureLoader::buildLocalDataFileName(GC_GUI_FILE_NAME
, file_name
);
139 ifstream
file(file_name
);
142 cerr
<< "Unable to find gui data file!\n";
148 file
.getline(buffer
, 256);
149 strcpy(player_name
, buffer
);
151 file
.getline(buffer
, 256);
152 resolution
= atoi(buffer
);
154 if (resolution
< 0 || resolution
> 4) {
158 file
.getline(buffer
, 256);
161 file
.getline(buffer
, 256);
162 reallylow
= atoi(buffer
);
171 entPlayerName
= GTK_ENTRY(lookup_widget(GTK_WIDGET(widget
), "entPlayerName"));
173 gtk_entry_set_text (GTK_ENTRY (entPlayerName
), player_name
);
176 /* Set the resolution in the option box. This does not actually change the
177 * value of the height and width. That is done with the gui_get_dimensions
178 * function before the game is launched...
180 optResolutions
= lookup_widget(GTK_WIDGET(widget
), "optResolutions");
181 if (optResolutions
) {
182 gtk_option_menu_set_history((GtkOptionMenu
*) optResolutions
, (guint
) resolution
);
185 // Set the low and really low graphics check boxes.
186 cbtnLowGraphics
= lookup_widget(GTK_WIDGET(widget
), "cbtnLowGraphics");
187 cbtnReallyLowGraphics
= lookup_widget(GTK_WIDGET(widget
), "cbtnReallyLowGraphics");
188 if (cbtnLowGraphics
&& cbtnReallyLowGraphics
) {
189 gtk_toggle_button_set_active((GtkToggleButton
*) cbtnLowGraphics
, low
);
190 gtk_toggle_button_set_active((GtkToggleButton
*) cbtnReallyLowGraphics
, reallylow
);