OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
preferencesdialog.c
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include <stdlib.h>
17 
18 #include "mape/preferences.h"
19 #include "mape/preferencesdialog.h"
20 
21 static void mape_preferences_dialog_cb_fixed_seed_toggled(GtkWidget* widget,
22  gpointer user_data)
23  /*MapePreferencesDialog* dialog)*/
24 {
25  MapePreferencesDialog* dialog;
26  dialog = (MapePreferencesDialog*)user_data;
27 
28  gtk_widget_set_sensitive(
29  GTK_WIDGET(dialog->hbox_random_seed),
30  gtk_toggle_button_get_active(
31  GTK_TOGGLE_BUTTON(dialog->cbx_fixed_seed)
32  )
33  );
34 }
35 
37  MapePreferences* prefs)
38 {
39  MapePreferencesDialog* dialog;
40  GtkBox* content_area;
41 
42  dialog = malloc(sizeof(MapePreferencesDialog) );
43 
44  dialog->lbl_tab_width = gtk_label_new("Tab width:");
45  gtk_widget_show(dialog->lbl_tab_width);
46 
47  dialog->ent_tab_width = gtk_spin_button_new_with_range(1, 8, 1);
48  gtk_widget_show(dialog->ent_tab_width);
49 
50  dialog->hbox_tab_width = gtk_hbox_new(FALSE, 5);
51 
52  gtk_box_pack_start(
53  GTK_BOX(dialog->hbox_tab_width),
54  dialog->lbl_tab_width,
55  FALSE,
56  TRUE,
57  0
58  );
59 
60  gtk_box_pack_start(
61  GTK_BOX(dialog->hbox_tab_width),
62  dialog->ent_tab_width,
63  TRUE,
64  TRUE,
65  0
66  );
67 
68  gtk_widget_show(dialog->hbox_tab_width);
69 
70  /* Map width */
71 
72  dialog->lbl_map_width = gtk_label_new("Map width:");
73  gtk_widget_show(dialog->lbl_map_width);
74 
75  dialog->ent_map_width = gtk_spin_button_new_with_range(50, 500, 5);
76  gtk_widget_show(dialog->ent_map_width);
77 
78  dialog->hbox_map_width = gtk_hbox_new(FALSE, 5);
79 
80  gtk_box_pack_start(
81  GTK_BOX(dialog->hbox_map_width),
82  dialog->lbl_map_width,
83  FALSE,
84  TRUE,
85  0
86  );
87 
88  gtk_box_pack_start(
89  GTK_BOX(dialog->hbox_map_width),
90  dialog->ent_map_width,
91  TRUE,
92  TRUE,
93  0
94  );
95 
96  gtk_widget_show(dialog->hbox_map_width);
97 
98  /* Map height */
99 
100  dialog->lbl_map_height = gtk_label_new("Map height:");
101  gtk_widget_show(dialog->lbl_map_height);
102 
103  dialog->ent_map_height = gtk_spin_button_new_with_range(50, 500, 5);
104  gtk_widget_show(dialog->ent_map_height);
105 
106  dialog->hbox_map_height = gtk_hbox_new(FALSE, 5);
107 
108  gtk_box_pack_start(
109  GTK_BOX(dialog->hbox_map_height),
110  dialog->lbl_map_height,
111  FALSE,
112  TRUE,
113  0
114  );
115 
116  gtk_box_pack_start(
117  GTK_BOX(dialog->hbox_map_height),
118  dialog->ent_map_height,
119  TRUE,
120  TRUE,
121  0
122  );
123 
124  gtk_widget_show(dialog->hbox_map_height);
125 
126  /* Map zoom */
127 
128  dialog->lbl_map_zoom = gtk_label_new("Map zoom:");
129  gtk_widget_show(dialog->lbl_map_zoom);
130 
131  dialog->ent_map_zoom = gtk_spin_button_new_with_range(0.2, 5.0, 0.1);
132  gtk_spin_button_set_digits(GTK_SPIN_BUTTON(dialog->ent_map_zoom), 2);
133  gtk_widget_show(dialog->ent_map_zoom);
134 
135  dialog->hbox_map_zoom = gtk_hbox_new(FALSE, 5);
136 
137  gtk_box_pack_start(
138  GTK_BOX(dialog->hbox_map_zoom),
139  dialog->lbl_map_zoom,
140  FALSE,
141  TRUE,
142  0
143  );
144 
145  gtk_box_pack_start(
146  GTK_BOX(dialog->hbox_map_zoom),
147  dialog->ent_map_zoom,
148  TRUE,
149  TRUE,
150  0
151  );
152 
153  gtk_widget_show(dialog->hbox_map_zoom);
154 
155  /* Checkboxes */
156 
157  dialog->cbx_tab_to_spaces = gtk_check_button_new_with_label(
158  "Insert spaces instead of tabs"
159  );
160  gtk_widget_show(dialog->cbx_tab_to_spaces);
161 
162  dialog->cbx_auto_indentation = gtk_check_button_new_with_label(
163  "Automatic indentation"
164  );
165  gtk_widget_show(dialog->cbx_auto_indentation);
166 
167  dialog->cbx_text_wrapping = gtk_check_button_new_with_label(
168  "Text wrapping"
169  );
170  gtk_widget_show(dialog->cbx_text_wrapping);
171 
172  dialog->cbx_line_numbers = gtk_check_button_new_with_label(
173  "Display line numbers"
174  );
175  gtk_widget_show(dialog->cbx_line_numbers);
176 
177  dialog->cbx_highlight_line = gtk_check_button_new_with_label(
178  "Highlight current line"
179  );
180  gtk_widget_show(dialog->cbx_highlight_line);
181 
182  dialog->cbx_bracket_matching = gtk_check_button_new_with_label(
183  "Highlight matching brackets"
184  );
185  gtk_widget_show(dialog->cbx_bracket_matching);
186 
187  dialog->cbx_fixed_seed = gtk_check_button_new_with_label(
188  "Fixed random seed"
189  );
190  gtk_widget_show(dialog->cbx_fixed_seed);
191 
192  dialog->lbl_random_seed = gtk_label_new("Random seed:");
193  gtk_widget_show(dialog->lbl_random_seed);
194 
195  dialog->ent_random_seed = gtk_spin_button_new_with_range(
196  0,
197  (1u << 31u) - 1,
198  1
199  );
200  gtk_widget_show(dialog->ent_random_seed);
201 
202  dialog->hbox_random_seed = gtk_hbox_new(FALSE, 5);
203 
204  gtk_box_pack_start(
205  GTK_BOX(dialog->hbox_random_seed),
206  dialog->lbl_random_seed,
207  FALSE,
208  TRUE,
209  0
210  );
211 
212  gtk_box_pack_start(
213  GTK_BOX(dialog->hbox_random_seed),
214  dialog->ent_random_seed,
215  TRUE,
216  TRUE,
217  0
218  );
219  gtk_widget_show(dialog->hbox_random_seed);
220 
221  g_signal_connect(
222  G_OBJECT(dialog->cbx_fixed_seed),
223  "toggled",
224  G_CALLBACK(mape_preferences_dialog_cb_fixed_seed_toggled),
225  dialog
226  );
227 
228  /* Read values from preferences */
229  gtk_spin_button_set_value(
230  GTK_SPIN_BUTTON(dialog->ent_tab_width),
231  prefs->tab_width
232  );
233 
234  gtk_spin_button_set_value(
235  GTK_SPIN_BUTTON(dialog->ent_map_width),
236  prefs->map_width
237  );
238 
239  gtk_spin_button_set_value(
240  GTK_SPIN_BUTTON(dialog->ent_map_height),
241  prefs->map_height
242  );
243 
244  gtk_spin_button_set_value(
245  GTK_SPIN_BUTTON(dialog->ent_map_zoom),
246  prefs->map_zoom
247  );
248 
249  gtk_toggle_button_set_active(
250  GTK_TOGGLE_BUTTON(dialog->cbx_tab_to_spaces),
251  prefs->tab_to_spaces
252  );
253 
254  gtk_toggle_button_set_active(
255  GTK_TOGGLE_BUTTON(dialog->cbx_auto_indentation),
256  prefs->auto_indentation
257  );
258 
259  gtk_toggle_button_set_active(
260  GTK_TOGGLE_BUTTON(dialog->cbx_text_wrapping),
261  prefs->text_wrapping
262  );
263 
264  gtk_toggle_button_set_active(
265  GTK_TOGGLE_BUTTON(dialog->cbx_line_numbers),
266  prefs->line_numbers
267  );
268 
269  gtk_toggle_button_set_active(
270  GTK_TOGGLE_BUTTON(dialog->cbx_highlight_line),
271  prefs->highlight_line
272  );
273 
274  gtk_toggle_button_set_active(
275  GTK_TOGGLE_BUTTON(dialog->cbx_bracket_matching),
276  prefs->bracket_matching
277  );
278 
279  gtk_toggle_button_set_active(
280  GTK_TOGGLE_BUTTON(dialog->cbx_fixed_seed),
281  prefs->fixed_seed
282  );
283 
284  /* Pseudo-emit toggled signal to hide the random seed entry if
285  * the fixed seed CheckButton is not active. */
286  mape_preferences_dialog_cb_fixed_seed_toggled(
287  dialog->cbx_fixed_seed,
288  dialog
289  );
290 
291  gtk_spin_button_set_value(
292  GTK_SPIN_BUTTON(dialog->ent_random_seed),
293  prefs->random_seed
294  );
295 
296  dialog->dialog = gtk_dialog_new_with_buttons(
297  "Preferences",
298  parent,
299  GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
300  GTK_STOCK_CANCEL,
301  GTK_RESPONSE_CANCEL,
302  GTK_STOCK_OK,
303  GTK_RESPONSE_OK,
304  NULL
305  );
306 
307  content_area = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog->dialog)));
308  gtk_box_pack_start(
309  content_area,
310  dialog->hbox_tab_width,
311  FALSE,
312  TRUE,
313  0
314  );
315 
316  gtk_box_pack_start(
317  content_area,
318  dialog->hbox_map_width,
319  FALSE,
320  TRUE,
321  0
322  );
323 
324  gtk_box_pack_start(
325  content_area,
326  dialog->hbox_map_height,
327  FALSE,
328  TRUE,
329  0
330  );
331 
332  gtk_box_pack_start(
333  content_area,
334  dialog->hbox_map_zoom,
335  FALSE,
336  TRUE,
337  0
338  );
339 
340  gtk_box_pack_start(
341  content_area,
342  dialog->cbx_tab_to_spaces,
343  FALSE,
344  TRUE,
345  0
346  );
347 
348  gtk_box_pack_start(
349  content_area,
350  dialog->cbx_auto_indentation,
351  FALSE,
352  TRUE,
353  0
354  );
355 
356  gtk_box_pack_start(
357  content_area,
358  dialog->cbx_text_wrapping,
359  FALSE,
360  TRUE,
361  0
362  );
363 
364  gtk_box_pack_start(
365  content_area,
366  dialog->cbx_line_numbers,
367  FALSE,
368  TRUE,
369  0
370  );
371 
372  gtk_box_pack_start(
373  content_area,
374  dialog->cbx_highlight_line,
375  FALSE,
376  TRUE,
377  0
378  );
379 
380  gtk_box_pack_start(
381  content_area,
382  dialog->cbx_bracket_matching,
383  FALSE,
384  TRUE,
385  0
386  );
387 
388  gtk_box_pack_start(
389  content_area,
390  dialog->cbx_fixed_seed,
391  FALSE,
392  TRUE,
393  0
394  );
395 
396  gtk_box_pack_start(
397  content_area,
398  dialog->hbox_random_seed,
399  FALSE,
400  TRUE,
401  0
402  );
403 
404  gtk_container_set_border_width(
405  GTK_CONTAINER(content_area),
406  10
407  );
408 
409  gtk_box_set_spacing(content_area, 5);
410 
411  gtk_window_set_transient_for(GTK_WINDOW(dialog->dialog), parent);
412  gtk_window_set_resizable(GTK_WINDOW(dialog->dialog), FALSE);
413 
414  return dialog;
415 }
416 
418 {
419  gtk_widget_destroy(dialog->dialog);
420  free(dialog);
421 }
422 
424 {
425  MapePreferences prefs;
426 
427  prefs.tab_width = gtk_spin_button_get_value_as_int(
428  GTK_SPIN_BUTTON(dialog->ent_tab_width)
429  );
430 
431  prefs.map_width = gtk_spin_button_get_value_as_int(
432  GTK_SPIN_BUTTON(dialog->ent_map_width)
433  );
434 
435  prefs.map_zoom = gtk_spin_button_get_value(
436  GTK_SPIN_BUTTON(dialog->ent_map_zoom)
437  );
438 
439  prefs.map_height = gtk_spin_button_get_value_as_int(
440  GTK_SPIN_BUTTON(dialog->ent_map_height)
441  );
442 
443  prefs.tab_to_spaces = gtk_toggle_button_get_active(
444  GTK_TOGGLE_BUTTON(dialog->cbx_tab_to_spaces)
445  );
446 
447  prefs.auto_indentation = gtk_toggle_button_get_active(
448  GTK_TOGGLE_BUTTON(dialog->cbx_auto_indentation)
449  );
450 
451  prefs.text_wrapping = gtk_toggle_button_get_active(
452  GTK_TOGGLE_BUTTON(dialog->cbx_text_wrapping)
453  );
454 
455  prefs.line_numbers = gtk_toggle_button_get_active(
456  GTK_TOGGLE_BUTTON(dialog->cbx_line_numbers)
457  );
458 
459  prefs.highlight_line = gtk_toggle_button_get_active(
460  GTK_TOGGLE_BUTTON(dialog->cbx_highlight_line)
461  );
462 
463  prefs.bracket_matching = gtk_toggle_button_get_active(
464  GTK_TOGGLE_BUTTON(dialog->cbx_bracket_matching)
465  );
466 
467  prefs.fixed_seed = gtk_toggle_button_get_active(
468  GTK_TOGGLE_BUTTON(dialog->cbx_fixed_seed)
469  );
470 
471  prefs.random_seed = gtk_spin_button_get_value_as_int(
472  GTK_SPIN_BUTTON(dialog->ent_random_seed)
473  );
474 
475  return prefs;
476 }
void mape_preferences_dialog_destroy(MapePreferencesDialog *dialog)
gboolean line_numbers
Definition: preferences.h:27
unsigned int tab_width
Definition: preferences.h:23
gboolean highlight_line
Definition: preferences.h:28
gboolean tab_to_spaces
Definition: preferences.h:24
MapePreferences mape_preferences_dialog_get(MapePreferencesDialog *dialog)
gboolean auto_indentation
Definition: preferences.h:25
GtkWidget * cbx_auto_indentation
GtkWidget * cbx_bracket_matching
gboolean text_wrapping
Definition: preferences.h:26
unsigned int random_seed
Definition: preferences.h:31
gboolean bracket_matching
Definition: preferences.h:29
unsigned int map_width
Definition: preferences.h:32
gboolean fixed_seed
Definition: preferences.h:30
unsigned int map_height
Definition: preferences.h:33
MapePreferencesDialog * mape_preferences_dialog_new(GtkWindow *parent, MapePreferences *prefs)