]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/surface_heretic2/surfacedialog.cpp
7c016fcbec4e8e63222edd15446c219f6f70b4d9
[xonotic/netradiant.git] / plugins / surface_heretic2 / surfacedialog.cpp
1 /*
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant 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.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // Surface Dialog Module
24 //
25
26 //
27 // Nurail: Implemented to Module from the main Radiant Surface Dialog code
28 //
29
30
31 #include <gtk/gtk.h>
32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
34
35 #include "surfdlg_plugin.h"
36
37
38
39 #ifdef _DEBUG
40 //#define DBG_SI 1
41 #endif
42
43 #include "gtkr_vector.h"
44
45 std::vector<texdef_to_face_t> g_texdef_face_vector;
46
47 inline texdef_to_face_t* get_texdef_face_list()
48 {
49   return &(*g_texdef_face_vector.begin());
50 }
51
52 inline unsigned int texdef_face_list_empty()
53 {
54   return g_texdef_face_vector.empty();
55 }
56
57 inline unsigned int texdef_face_list_size()
58 {
59   return g_texdef_face_vector.size();
60 }
61
62 // For different faces having different values
63 bool is_HShift_conflicting;
64 bool is_VShift_conflicting;
65 bool is_HScale_conflicting;
66 bool is_VScale_conflicting;
67 bool is_Rotate_conflicting;
68 bool is_TextureName_conflicting;
69
70 void ShowDlg();
71 void HideDlg();
72 void SetTexMods();
73 void GetTexMods(bool b_SetUndoPoint = FALSE);
74 void BuildDialog();
75 void FitAll();
76 void InitDefaultIncrement(texdef_t *);
77 void DoSnapTToGrid(float hscale, float vscale);
78 // called to perform a fitting from the outside (shortcut key)
79 void SurfaceDialogFitAll();
80
81 // Heretic2 Flags Functions
82 void SetFlagButtons_Heretic2(texdef_to_face_t *texdef_face_list,  bool b_isListEmpty);
83 void SetChangeInFlags_Face_Heretic2 (texdef_to_face_t *texdef_face_list);
84 GtkWidget* Create_Heretic2FlagsDialog (GtkWidget* surfacedialog_widget);
85
86
87 // Dialog Data
88 int m_nHeight;
89 int m_nWidth;
90
91 // 0 is invalid, otherwise it's the Id of the last 'do' we are responsible for
92 int m_nUndoId;
93
94
95 texturewin_t *texturewin;
96 texdef_t *l_pIncrement;
97 texdef_t texdef_offset;
98 texdef_t texdef_SI_values;
99
100 // For Texture Entry, activate only on entry change
101 char old_texture_entry[128];
102
103 // the texdef to switch back to when the OnCancel is called
104 texdef_t        g_old_texdef;
105
106 // when TRUE, this thing means the surface inspector is currently being displayed
107 bool  g_surfwin = FALSE;
108 // turn on/off processing of the "changed" "value_changed" messages
109 // (need to turn off when we are feeding data in)
110 bool g_bListenChanged = true;
111 // turn on/off listening of the update messages
112 bool g_bListenUpdate = true;
113
114 GtkWidget* create_SurfaceInspector (void);
115 GtkWidget *SurfaceInspector = NULL;
116
117 GtkWidget *m_pWidget;
118 GtkWidget *GetWidget () { return SurfaceInspector; }
119 GtkWidget *Get_SI_Module_Widget () { return SurfaceInspector; }
120 void SetWidget(GtkWidget *new_widget) { m_pWidget = new_widget; }
121 GtkWidget *GetDlgWidget (const char* name)
122   { return GTK_WIDGET (g_object_get_data (G_OBJECT (SurfaceInspector), name)); }
123
124 // Spins for FitTexture
125 GtkWidget *spin_width;
126 GtkWidget *spin_height;
127
128
129 GtkWidget *texture_combo;
130 GtkWidget *texture_combo_entry;
131
132 GtkWidget *match_grid_button;
133 GtkWidget *lock_valuechange_togglebutton;
134
135 GtkObject *hshift_value_spinbutton_adj;
136 GtkWidget *hshift_value_spinbutton;
137 GtkObject *vshift_value_spinbutton_adj;
138 GtkWidget *vshift_value_spinbutton;
139 GtkObject *hscale_value_spinbutton_adj;
140 GtkWidget *hscale_value_spinbutton;
141 GtkObject *vscale_value_spinbutton_adj;
142 GtkWidget *vscale_value_spinbutton;
143 GtkObject *rotate_value_spinbutton_adj;
144 GtkWidget *rotate_value_spinbutton;
145
146 GtkObject *hshift_offset_spinbutton_adj;
147 GtkWidget *hshift_offset_spinbutton;
148 GtkObject *vshift_offset_spinbutton_adj;
149 GtkWidget *vshift_offset_spinbutton;
150 GtkObject *hscale_offset_spinbutton_adj;
151 GtkWidget *hscale_offset_spinbutton;
152 GtkObject *vscale_offset_spinbutton_adj;
153 GtkWidget *vscale_offset_spinbutton;
154 GtkObject *rotate_offset_spinbutton_adj;
155 GtkWidget *rotate_offset_spinbutton;
156
157 GtkObject *hshift_step_spinbutton_adj;
158 GtkWidget *hshift_step_spinbutton;
159 GtkObject *vshift_step_spinbutton_adj;
160 GtkWidget *vshift_step_spinbutton;
161 GtkObject *hscale_step_spinbutton_adj;
162 GtkWidget *hscale_step_spinbutton;
163 GtkObject *vscale_step_spinbutton_adj;
164 GtkWidget *vscale_step_spinbutton;
165 GtkObject *rotate_step_spinbutton_adj;
166 GtkWidget *rotate_step_spinbutton;
167
168 GtkObject *fit_width_spinbutton_adj;
169 GtkWidget *fit_width_spinbutton;
170 GtkObject *fit_height_spinbutton_adj;
171 GtkWidget *fit_height_spinbutton;
172 GtkWidget *fit_button;
173 GtkWidget *axial_button;
174
175 GtkWidget *done_button;
176 GtkWidget *apply_button;
177 GtkWidget *cancel_button;
178
179 // Callbacks
180 gboolean on_texture_combo_entry_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data);
181 void on_texture_combo_entry_activate (GtkEntry *entry, gpointer user_data);
182
183 static void on_match_grid_button_clicked (GtkButton *button, gpointer user_data);
184 static void on_lock_valuechange_togglebutton_toggled (GtkToggleButton *togglebutton, gpointer user_data);
185
186 static void on_hshift_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
187 static void on_vshift_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
188 static void on_hscale_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
189 static void on_vscale_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
190 static void on_rotate_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
191
192 static void on_hshift_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
193 static void on_vshift_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
194 static void on_hscale_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
195 static void on_vscale_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
196 static void on_rotate_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
197
198 static void on_hshift_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
199 static void on_vshift_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
200 static void on_hscale_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
201 static void on_vscale_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
202 static void on_rotate_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
203
204 static void on_fit_width_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
205 static void on_fit_height_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data);
206 static void on_fit_button_clicked (GtkButton *button, gpointer user_data);
207 static void on_axial_button_clicked (GtkButton *button, gpointer user_data);
208
209 static void on_done_button_clicked (GtkButton *button, gpointer user_data);
210 static void on_apply_button_clicked (GtkButton *button, gpointer user_data);
211 static void on_cancel_button_clicked (GtkButton *button, gpointer user_data);
212
213
214 /*
215 ===================================================
216
217   SURFACE INSPECTOR
218
219 ===================================================
220 */
221
222
223 void IsFaceConflicting()
224 {
225   texdef_t* tmp_texdef;
226   texdef_to_face_t* temp_texdef_face_list;
227   char buf[12];
228   char texture_name[128];
229
230   if (texdef_face_list_empty())
231   {
232     gtk_entry_set_text( GTK_ENTRY (hshift_value_spinbutton), "");
233     gtk_entry_set_text( GTK_ENTRY (vshift_value_spinbutton), "");
234     gtk_entry_set_text( GTK_ENTRY (hscale_value_spinbutton), "");
235     gtk_entry_set_text( GTK_ENTRY (vscale_value_spinbutton), "");
236     gtk_entry_set_text( GTK_ENTRY (rotate_value_spinbutton), "");
237     gtk_entry_set_text( GTK_ENTRY (texture_combo_entry), "");
238     return;
239   }
240
241   g_bListenChanged = FALSE;
242
243   tmp_texdef = &get_texdef_face_list()->texdef;
244
245   strcpy(texture_name, tmp_texdef->GetName() );
246
247   texdef_SI_values.shift[0] = tmp_texdef->shift[0];
248   texdef_SI_values.shift[1] = tmp_texdef->shift[1];
249   texdef_SI_values.scale[0] = tmp_texdef->scale[0];
250   texdef_SI_values.scale[1] = tmp_texdef->scale[1];
251   texdef_SI_values.rotate = tmp_texdef->rotate;
252   texdef_SI_values.SetName( texture_name );
253
254   is_HShift_conflicting = FALSE;
255   is_VShift_conflicting = FALSE;
256   is_HScale_conflicting = FALSE;
257   is_VScale_conflicting = FALSE;
258   is_Rotate_conflicting = FALSE;
259   is_TextureName_conflicting = FALSE;
260
261   if (texdef_face_list_size() > 1)
262   {
263     temp_texdef_face_list = get_texdef_face_list()->next;
264
265     for (; temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
266     {
267       tmp_texdef = &temp_texdef_face_list->texdef;
268       if ( texdef_SI_values.shift[0] != tmp_texdef->shift[0] )
269         is_HShift_conflicting = TRUE;
270
271       if ( texdef_SI_values.shift[1] != tmp_texdef->shift[1] )
272         is_VShift_conflicting = TRUE;
273
274       if ( texdef_SI_values.scale[0] != tmp_texdef->scale[0] )
275         is_HScale_conflicting = TRUE;
276
277       if ( texdef_SI_values.scale[1] != tmp_texdef->scale[1] )
278         is_VScale_conflicting = TRUE;
279
280       if ( texdef_SI_values.rotate != tmp_texdef->rotate )
281         is_Rotate_conflicting = TRUE;
282
283       if ( strcmp( texture_name, tmp_texdef->GetName() ) )
284         is_TextureName_conflicting = TRUE;
285     }
286   }
287
288   if(is_HShift_conflicting)
289     gtk_entry_set_text( GTK_ENTRY (hshift_value_spinbutton), "");
290   else
291     gtk_spin_button_set_value( GTK_SPIN_BUTTON(hshift_value_spinbutton) , texdef_SI_values.shift[0] );
292
293   if(is_VShift_conflicting)
294     gtk_entry_set_text( GTK_ENTRY (vshift_value_spinbutton), "");
295   else
296     gtk_spin_button_set_value( GTK_SPIN_BUTTON(vshift_value_spinbutton) , texdef_SI_values.shift[1] );
297
298   if(is_HScale_conflicting)
299     gtk_entry_set_text( GTK_ENTRY (hscale_value_spinbutton), "");
300   else
301     gtk_spin_button_set_value( GTK_SPIN_BUTTON(hscale_value_spinbutton) , texdef_SI_values.scale[0] );
302
303   if(is_VScale_conflicting)
304     gtk_entry_set_text( GTK_ENTRY (vscale_value_spinbutton), "");
305   else
306     gtk_spin_button_set_value( GTK_SPIN_BUTTON(vscale_value_spinbutton) , texdef_SI_values.scale[1] );
307
308   if(is_Rotate_conflicting)
309     gtk_entry_set_text( GTK_ENTRY (rotate_value_spinbutton), "");
310   else
311     gtk_spin_button_set_value( GTK_SPIN_BUTTON(rotate_value_spinbutton) , texdef_SI_values.rotate );
312
313   g_bListenChanged = TRUE;
314 }
315
316 #define MAX_NUM_LIST_ITEMS 15
317 static void PopulateTextureComboList()
318 {
319   texdef_t* tmp_texdef;
320   texdef_to_face_t* temp_texdef_face_list;
321   char blank[1];
322   GList *items = NULL;
323   GList *tmp_item;
324   int num_of_list_items = 0;
325
326   blank[0] = 0;
327
328   if (texdef_face_list_empty())
329   {
330     items = g_list_append (items, (gpointer) blank);
331     // For Texture Entry, activate only on entry change
332     strcpy (old_texture_entry, blank);
333   }
334   else if ( !is_TextureName_conflicting )
335   {
336     temp_texdef_face_list = get_texdef_face_list();
337     tmp_texdef = (texdef_t *) &get_texdef_face_list()->texdef;
338     items = g_list_append( items, (gpointer) tmp_texdef->GetName() );
339     // For Texture Entry, activate only on entry change
340     strcpy (old_texture_entry, tmp_texdef->GetName());
341   }
342   else
343   {
344     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
345     {
346       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
347       // Need to do a string compare, hence the custom search
348       if (!( g_list_find_custom (items, tmp_texdef->GetName(), (GCompareFunc) strcmp ) ))
349       {
350         items = g_list_append( items, (gpointer) tmp_texdef->GetName() );
351         num_of_list_items++;
352       }
353       // Make sure the combo list isn't too long
354       if (num_of_list_items >= MAX_NUM_LIST_ITEMS)
355         break;
356     }
357     // If this isn't added last (to the top of the list), g_list_find freaks.
358     items = g_list_prepend (items, (gpointer) blank);
359     // For Texture Entry, activate only on entry change
360     strcpy (old_texture_entry, blank);
361   }
362
363   gtk_combo_set_popdown_strings (GTK_COMBO (texture_combo), items);
364   g_list_free(items);
365
366 }
367
368 static void ZeroOffsetValues()
369 {
370   texdef_offset.shift[0] = 0.0;
371   texdef_offset.shift[1] = 0.0;
372   texdef_offset.scale[0] = 0.0;
373   texdef_offset.scale[1] = 0.0;
374   texdef_offset.rotate = 0.0;
375 }
376
377 static void GetTexdefInfo_from_Radiant()
378 {
379   g_texdef_face_vector.clear();
380
381   unsigned int count = GetSelectedFaceCountfromBrushes();
382   if(count == 0)
383     count = GetSelectedFaceCount();
384
385   g_texdef_face_vector.resize(count);
386
387   if (!texdef_face_list_empty())
388   {
389     texdef_to_face_t* p = get_texdef_face_list();
390     GetSelFacesTexdef( get_texdef_face_list() );
391   }
392
393   IsFaceConflicting();
394   PopulateTextureComboList();
395   ZeroOffsetValues();
396   if ( texdef_face_list_empty() )
397     SetFlagButtons_Heretic2( get_texdef_face_list() , TRUE);
398   else
399     SetFlagButtons_Heretic2( get_texdef_face_list() , FALSE);
400
401 }
402
403 static gint delete_event_callback(GtkWidget *widget, GdkEvent* event, gpointer data)
404 {
405   HideDlg();
406   return TRUE;
407 }
408
409 // make the shift increments match the grid settings
410 // the objective being that the shift+arrows shortcuts move the texture by the corresponding grid size
411 // this depends on a scale value if you have selected a particular texture on which you want it to work:
412 // we move the textures in pixels, not world units. (i.e. increment values are in pixel)
413 // depending on the texture scale it doesn't take the same amount of pixels to move of g_qeglobals.d_gridsize
414 // increment * scale = gridsize
415 // hscale and vscale are optional parameters, if they are zero they will be set to the default scale
416 // NOTE: the default scale depends if you are using BP mode or regular.
417 // For regular it's 0.5f (128 pixels cover 64 world units), for BP it's simply 1.0f
418 // see fenris #2810
419 void DoSnapTToGrid(float hscale, float vscale)
420 {
421   l_pIncrement = Get_SI_Inc();
422
423   if (hscale == 0.0f)
424   {
425     hscale = 0.5f;
426   }
427   if (vscale == 0.0f)
428   {
429      vscale = 0.5f;
430   }
431 #ifdef _DEBUG
432   Sys_Printf ("DoSnapTToGrid: hscale %g vscale %g\n", hscale, vscale);
433 #endif
434   l_pIncrement->shift[0] = GridSize() / hscale;
435   l_pIncrement->shift[1] = GridSize() / vscale;
436   // now some update work
437   // FIXME: doesn't look good here, seems to be called several times
438   SetTexMods();
439 }
440
441 void UpdateSurfaceDialog()
442 {
443   if (!g_bListenUpdate)
444     return;
445
446   if (!SurfaceInspector)
447     return;
448
449   // avoid long delays on slow computers
450   while (gtk_events_pending ())
451     gtk_main_iteration ();
452
453   if (g_surfwin)
454   {
455 #ifdef DBG_SI
456     Sys_Printf("UpdateSurfaceDialog\n");
457 #endif
458     GetTexdefInfo_from_Radiant();
459     SetTexMods();
460   }
461
462 }
463
464 // DoSurface will always try to show the surface inspector
465 // or update it because something new has been selected
466 void DoSurface (void)
467 {
468 #ifdef DBG_SI
469   Sys_Printf("DoSurface\n");
470 #endif
471   if (!SurfaceInspector)
472     create_SurfaceInspector ();
473
474   ShowDlg();
475   SetTexMods ();
476 }
477
478 void ToggleSurface()
479 {
480 #ifdef DBG_SI
481   Sys_Printf("ToggleSurface Module\n");
482 #endif
483   if (!g_surfwin)
484     DoSurface ();
485   else
486     on_cancel_button_clicked(NULL, NULL);
487 }
488
489 // NOTE: will raise and show the Surface inspector and exec fit for patches and brushes
490 void SurfaceDlgFitAll()
491 {
492   DoSurface();
493   FitAll();
494 }
495
496 // =============================================================================
497 // SurfaceDialog class
498
499 void ShowDlg()
500 {
501
502   if(!SurfaceInspector)
503     create_SurfaceInspector();
504   else
505     gtk_widget_show (SurfaceInspector);
506
507   GetTexdefInfo_from_Radiant();
508   GetTexMods(TRUE); // Set Initial Undo Point
509   g_surfwin = TRUE;
510 }
511
512 void HideDlg()
513 {
514   g_surfwin = FALSE;
515   gtk_widget_hide (SurfaceInspector);
516 }
517
518
519 // set default values for increments (shift scale and rot)
520 // this is called by the prefs code if can't find the values
521 void InitDefaultIncrement(texdef_t *tex)
522 {
523   tex->SetName("foo");
524   tex->shift[0] = 8;
525   tex->shift[1] = 8;
526   tex->scale[0] = 0.25;
527   tex->scale[1] = 0.25;
528   tex->rotate = 10;
529 }
530
531 void BuildDialog ()
532 {
533    if ( !SurfaceInspector )
534     create_SurfaceInspector();
535 }
536
537 /*
538 ==============
539 SetTexMods
540
541 Set the fields to the current texdef (i.e. map/texdef -> dialog widgets)
542 ===============
543 */
544
545 void SetTexMods()
546 {
547   texdef_t *pt;
548   GtkSpinButton *spin;
549   GtkAdjustment *adjust;
550
551   texturewin = Texturewin ();
552   l_pIncrement = Get_SI_Inc();
553
554 #ifdef DBG_SI
555   Sys_Printf("SurfaceDlg SetTexMods\n");
556 #endif
557
558   if (!g_surfwin)
559     return;
560
561   pt = &texturewin->texdef;
562
563   g_bListenChanged = false;
564
565   if(strncmp(pt->GetName(), "textures/", 9) != 0)
566     texdef_offset.SetName(SHADER_NOT_FOUND);
567
568
569   spin = GTK_SPIN_BUTTON (hshift_offset_spinbutton);
570   gtk_spin_button_set_value (spin, texdef_offset.shift[0]);
571   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
572   adjust->step_increment = l_pIncrement->shift[0];
573   gtk_spin_button_set_value (GTK_SPIN_BUTTON(hshift_step_spinbutton), l_pIncrement->shift[0]);
574
575   spin = GTK_SPIN_BUTTON (hshift_value_spinbutton);
576   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
577   adjust->step_increment = l_pIncrement->shift[0];
578
579
580   spin = GTK_SPIN_BUTTON (vshift_offset_spinbutton);
581   gtk_spin_button_set_value (spin, texdef_offset.shift[1]);
582   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
583   adjust->step_increment = l_pIncrement->shift[1];
584   gtk_spin_button_set_value (GTK_SPIN_BUTTON(vshift_step_spinbutton), l_pIncrement->shift[1]);
585
586   spin = GTK_SPIN_BUTTON (vshift_value_spinbutton);
587   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
588   adjust->step_increment = l_pIncrement->shift[1];
589
590
591   spin = GTK_SPIN_BUTTON (hscale_offset_spinbutton);
592   gtk_spin_button_set_value (spin, texdef_offset.scale[0]);
593   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
594   adjust->step_increment = l_pIncrement->scale[0];
595   gtk_spin_button_set_value (GTK_SPIN_BUTTON(hscale_step_spinbutton), l_pIncrement->scale[0]);
596
597   spin = GTK_SPIN_BUTTON (hscale_value_spinbutton);
598   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
599   adjust->step_increment = l_pIncrement->scale[0];
600
601
602   spin = GTK_SPIN_BUTTON (vscale_offset_spinbutton);
603   gtk_spin_button_set_value (spin, texdef_offset.scale[1]);
604   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
605   adjust->step_increment = l_pIncrement->scale[1];
606   gtk_spin_button_set_value (GTK_SPIN_BUTTON(vscale_step_spinbutton), l_pIncrement->scale[1]);
607
608   spin = GTK_SPIN_BUTTON (vscale_value_spinbutton);
609   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
610   adjust->step_increment = l_pIncrement->scale[1];
611
612
613   spin = GTK_SPIN_BUTTON (rotate_offset_spinbutton);
614   gtk_spin_button_set_value (spin, texdef_offset.rotate);
615   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
616   adjust->step_increment = l_pIncrement->rotate;
617   gtk_spin_button_set_value (GTK_SPIN_BUTTON(rotate_step_spinbutton), l_pIncrement->rotate);
618
619   spin = GTK_SPIN_BUTTON (rotate_value_spinbutton);
620   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spin));
621   adjust->step_increment = l_pIncrement->rotate;
622
623
624   g_bListenChanged = true;
625
626   // store the current texdef as our escape route if user hits OnCancel
627   g_old_texdef = texturewin->texdef;
628 }
629
630 /*
631 ==============
632 GetTexMods
633
634 Shows any changes to the main Radiant windows
635 ===============
636 */
637 void GetTexMods(bool b_SetUndoPoint)
638 {
639
640 #ifdef DBG_SI
641   Sys_Printf("SurfaceDlg GetTexMods\n");
642 #endif
643
644    if ( !texdef_face_list_empty() )
645   {
646     g_bListenUpdate=FALSE;
647     SetChangeInFlags_Face_Heretic2 ( get_texdef_face_list() );
648     SetTexdef_FaceList( get_texdef_face_list(), b_SetUndoPoint, false );
649     g_bListenUpdate=TRUE;
650
651     if (b_SetUndoPoint)
652       m_nUndoId = Undo_GetUndoId();
653   }
654 }
655
656 void FitAll()
657 {
658   on_fit_button_clicked(NULL, NULL);
659 }
660
661
662 ////////////////////////////////////////////////////////////////////
663 //
664 //  GUI Section
665 //
666 ////////////////////////////////////////////////////////////////////
667
668 GtkWidget* create_SurfaceInspector (void)
669 {
670
671   GtkWidget *label;
672   GtkWidget *hseparator;
673   GtkWidget *eventbox;
674
675   GtkWidget *viewport8;
676   GtkWidget *viewport9;
677   GtkWidget *viewport2;
678   GtkWidget *viewport7;
679   GtkWidget *viewport5;
680   GtkWidget *viewport6;
681   GtkWidget *viewport10;
682
683   GtkWidget *table1;
684   GtkWidget *table4;
685   GtkWidget *table5;
686   GtkWidget *table7;
687
688   GtkWidget *alignment1;
689   GtkWidget *alignment2;
690   GtkWidget *alignment3;
691
692   GtkWidget *vbox7;
693
694   GtkWidget *hbox1;
695   GtkWidget *hbox2;
696   GtkWidget *hbox3;
697   GtkWidget *hbox4;
698
699   GtkWidget *image1;
700   GtkWidget *image2;
701   GtkWidget *image3;
702
703   GtkWidget *hbuttonbox1;
704
705   SurfaceInspector = gtk_window_new (GTK_WINDOW_TOPLEVEL);
706   gtk_container_set_border_width (GTK_CONTAINER (SurfaceInspector), 4);
707   gtk_window_set_title (GTK_WINDOW (SurfaceInspector), "Surface Inspector");
708
709   SetWinPos_from_Prefs(SurfaceInspector);
710
711   viewport8 = gtk_viewport_new (NULL, NULL);
712   gtk_widget_show (viewport8);
713   gtk_container_add (GTK_CONTAINER (SurfaceInspector), viewport8);
714   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport8), GTK_SHADOW_NONE);
715
716   vbox7 = gtk_vbox_new (FALSE, 0);
717   gtk_widget_show (vbox7);
718   gtk_container_add (GTK_CONTAINER (viewport8), vbox7);
719
720   viewport9 = gtk_viewport_new (NULL, NULL);
721   gtk_widget_show (viewport9);
722   gtk_box_pack_start (GTK_BOX (vbox7), viewport9, FALSE, FALSE, 0);
723   gtk_container_set_border_width (GTK_CONTAINER (viewport9), 2);
724   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport9), GTK_SHADOW_ETCHED_IN);
725
726   hbox1 = gtk_hbox_new (FALSE, 0);
727   gtk_widget_show (hbox1);
728   gtk_container_add (GTK_CONTAINER (viewport9), hbox1);
729   gtk_container_set_border_width (GTK_CONTAINER (hbox1), 4);
730
731   label = gtk_label_new ("Texture: ");
732   gtk_widget_show (label);
733   gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
734   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
735
736   texture_combo = gtk_combo_new ();
737   g_object_set_data (G_OBJECT (GTK_COMBO (texture_combo)->popwin),
738                      "KeepMeAround", texture_combo);
739   gtk_combo_disable_activate ( (GtkCombo*) texture_combo);
740   gtk_widget_show (texture_combo);
741   gtk_box_pack_start (GTK_BOX (hbox1), texture_combo, TRUE, TRUE, 0);
742
743   texture_combo_entry = GTK_COMBO (texture_combo)->entry;
744   gtk_widget_show (texture_combo_entry);
745   gtk_entry_set_max_length (GTK_ENTRY (texture_combo_entry), 128);
746
747   viewport2 = gtk_viewport_new (NULL, NULL);
748   gtk_widget_show (viewport2);
749   gtk_box_pack_start (GTK_BOX (vbox7), viewport2, FALSE, TRUE, 0);
750   gtk_container_set_border_width (GTK_CONTAINER (viewport2), 2);
751   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport2), GTK_SHADOW_ETCHED_IN);
752
753   table1 = gtk_table_new (13, 4, FALSE);
754   gtk_widget_show (table1);
755   gtk_container_add (GTK_CONTAINER (viewport2), table1);
756
757   hseparator = gtk_hseparator_new ();
758   gtk_widget_show (hseparator);
759   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 1, 2,
760                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
761                     (GtkAttachOptions) (GTK_FILL), 0, 0);
762
763   hseparator = gtk_hseparator_new ();
764   gtk_widget_show (hseparator);
765   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 1, 2,
766                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
767                     (GtkAttachOptions) (GTK_FILL), 0, 0);
768
769   hseparator = gtk_hseparator_new ();
770   gtk_widget_show (hseparator);
771   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 1, 2,
772                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
773                     (GtkAttachOptions) (GTK_FILL), 0, 0);
774
775   hseparator = gtk_hseparator_new ();
776   gtk_widget_show (hseparator);
777   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 3, 4,
778                     (GtkAttachOptions) (GTK_FILL),
779                     (GtkAttachOptions) (GTK_FILL), 0, 0);
780
781   hseparator = gtk_hseparator_new ();
782   gtk_widget_show (hseparator);
783   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 3, 4,
784                     (GtkAttachOptions) (GTK_FILL),
785                     (GtkAttachOptions) (GTK_FILL), 0, 0);
786
787   hseparator = gtk_hseparator_new ();
788   gtk_widget_show (hseparator);
789   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 3, 4,
790                     (GtkAttachOptions) (GTK_FILL),
791                     (GtkAttachOptions) (GTK_FILL), 0, 0);
792
793   hseparator = gtk_hseparator_new ();
794   gtk_widget_show (hseparator);
795   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 5, 6,
796                     (GtkAttachOptions) (GTK_FILL),
797                     (GtkAttachOptions) (GTK_FILL), 0, 0);
798
799   hseparator = gtk_hseparator_new ();
800   gtk_widget_show (hseparator);
801   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 5, 6,
802                     (GtkAttachOptions) (GTK_FILL),
803                     (GtkAttachOptions) (GTK_FILL), 0, 0);
804
805   hseparator = gtk_hseparator_new ();
806   gtk_widget_show (hseparator);
807   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 5, 6,
808                     (GtkAttachOptions) (GTK_FILL),
809                     (GtkAttachOptions) (GTK_FILL), 0, 0);
810
811   hseparator = gtk_hseparator_new ();
812   gtk_widget_show (hseparator);
813   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 7, 8,
814                     (GtkAttachOptions) (GTK_FILL),
815                     (GtkAttachOptions) (GTK_FILL), 0, 0);
816
817   hseparator = gtk_hseparator_new ();
818   gtk_widget_show (hseparator);
819   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 7, 8,
820                     (GtkAttachOptions) (GTK_FILL),
821                     (GtkAttachOptions) (GTK_FILL), 0, 0);
822
823   hseparator = gtk_hseparator_new ();
824   gtk_widget_show (hseparator);
825   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 7, 8,
826                     (GtkAttachOptions) (GTK_FILL),
827                     (GtkAttachOptions) (GTK_FILL), 0, 0);
828
829   hseparator = gtk_hseparator_new ();
830   gtk_widget_show (hseparator);
831   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 9, 10,
832                     (GtkAttachOptions) (GTK_FILL),
833                     (GtkAttachOptions) (GTK_FILL), 0, 0);
834
835   hseparator = gtk_hseparator_new ();
836   gtk_widget_show (hseparator);
837   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 9, 10,
838                     (GtkAttachOptions) (GTK_FILL),
839                     (GtkAttachOptions) (GTK_FILL), 0, 0);
840
841   hseparator = gtk_hseparator_new ();
842   gtk_widget_show (hseparator);
843   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 9, 10,
844                     (GtkAttachOptions) (GTK_FILL),
845                     (GtkAttachOptions) (GTK_FILL), 0, 0);
846
847   hseparator = gtk_hseparator_new ();
848   gtk_widget_show (hseparator);
849   gtk_table_attach (GTK_TABLE (table1), hseparator, 1, 2, 11, 12,
850                     (GtkAttachOptions) (GTK_FILL),
851                     (GtkAttachOptions) (GTK_FILL), 0, 0);
852
853   hseparator = gtk_hseparator_new ();
854   gtk_widget_show (hseparator);
855   gtk_table_attach (GTK_TABLE (table1), hseparator, 2, 3, 11, 12,
856                     (GtkAttachOptions) (GTK_FILL),
857                     (GtkAttachOptions) (GTK_FILL), 0, 0);
858
859   hseparator = gtk_hseparator_new ();
860   gtk_widget_show (hseparator);
861   gtk_table_attach (GTK_TABLE (table1), hseparator, 3, 4, 11, 12,
862                     (GtkAttachOptions) (GTK_FILL),
863                     (GtkAttachOptions) (GTK_FILL), 0, 0);
864
865   label = gtk_label_new ("Offset");
866   gtk_widget_show (label);
867   gtk_table_attach (GTK_TABLE (table1), label, 2, 3, 0, 1,
868                     (GtkAttachOptions) (GTK_FILL),
869                     (GtkAttachOptions) (0), 0, 0);
870
871   label = gtk_label_new ("Step");
872   gtk_widget_show (label);
873   gtk_table_attach (GTK_TABLE (table1), label, 3, 4, 0, 1,
874                     (GtkAttachOptions) (GTK_FILL),
875                     (GtkAttachOptions) (0), 0, 0);
876
877   eventbox = gtk_event_box_new ();
878   gtk_widget_show (eventbox);
879   gtk_table_attach (GTK_TABLE (table1), eventbox, 3, 4, 12, 13,
880                     (GtkAttachOptions) (GTK_FILL),
881                     (GtkAttachOptions) (GTK_FILL), 0, 0);
882
883   match_grid_button = gtk_button_new_with_mnemonic ("Match Grid");
884   gtk_widget_show (match_grid_button);
885   gtk_container_add (GTK_CONTAINER (eventbox), match_grid_button);
886
887   label = gtk_label_new ("Value");
888   gtk_widget_show (label);
889   gtk_table_attach (GTK_TABLE (table1), label, 1, 2, 0, 1,
890                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
891                     (GtkAttachOptions) (0), 0, 0);
892   gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1);
893
894   hseparator = gtk_hseparator_new ();
895   gtk_widget_show (hseparator);
896   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 3, 4,
897                     (GtkAttachOptions) (GTK_SHRINK | GTK_FILL),
898                     (GtkAttachOptions) (GTK_FILL), 0, 0);
899
900   hseparator = gtk_hseparator_new ();
901   gtk_widget_show (hseparator);
902   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 5, 6,
903                     (GtkAttachOptions) (GTK_FILL),
904                     (GtkAttachOptions) (GTK_FILL), 0, 0);
905
906   hseparator = gtk_hseparator_new ();
907   gtk_widget_show (hseparator);
908   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 7, 8,
909                     (GtkAttachOptions) (GTK_FILL),
910                     (GtkAttachOptions) (GTK_FILL), 0, 0);
911
912   hseparator = gtk_hseparator_new ();
913   gtk_widget_show (hseparator);
914   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 9, 10,
915                     (GtkAttachOptions) (GTK_FILL),
916                     (GtkAttachOptions) (GTK_FILL), 0, 0);
917
918   hseparator = gtk_hseparator_new ();
919   gtk_widget_show (hseparator);
920   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 11, 12,
921                     (GtkAttachOptions) (GTK_FILL),
922                     (GtkAttachOptions) (GTK_FILL), 0, 0);
923
924   eventbox = gtk_event_box_new ();
925   gtk_widget_show (eventbox);
926   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 4, 5,
927                     (GtkAttachOptions) (GTK_FILL),
928                     (GtkAttachOptions) (GTK_FILL), 0, 0);
929
930   label = gtk_label_new ("V Shift: ");
931   gtk_widget_show (label);
932   gtk_container_add (GTK_CONTAINER (eventbox), label);
933   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
934   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
935
936   eventbox = gtk_event_box_new ();
937   gtk_widget_show (eventbox);
938   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 6, 7,
939                     (GtkAttachOptions) (GTK_FILL),
940                     (GtkAttachOptions) (GTK_FILL), 0, 0);
941
942   label = gtk_label_new (" H Scale: ");
943   gtk_widget_show (label);
944   gtk_container_add (GTK_CONTAINER (eventbox), label);
945   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
946   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
947
948   eventbox = gtk_event_box_new ();
949   gtk_widget_show (eventbox);
950   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 8, 9,
951                     (GtkAttachOptions) (GTK_FILL),
952                     (GtkAttachOptions) (GTK_FILL), 0, 0);
953
954   label = gtk_label_new ("V Scale: ");
955   gtk_widget_show (label);
956   gtk_container_add (GTK_CONTAINER (eventbox), label);
957   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
958   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
959
960   eventbox = gtk_event_box_new ();
961   gtk_widget_show (eventbox);
962   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 10, 11,
963                     (GtkAttachOptions) (GTK_FILL),
964                     (GtkAttachOptions) (GTK_FILL), 0, 0);
965
966   label = gtk_label_new ("Rotate: ");
967   gtk_widget_show (label);
968   gtk_container_add (GTK_CONTAINER (eventbox), label);
969   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
970   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
971
972   eventbox = gtk_event_box_new ();
973   gtk_widget_show (eventbox);
974   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 2, 3,
975                     (GtkAttachOptions) (GTK_FILL),
976                     (GtkAttachOptions) (GTK_FILL), 0, 0);
977
978   label = gtk_label_new ("H Shift: ");
979   gtk_widget_show (label);
980   gtk_container_add (GTK_CONTAINER (eventbox), label);
981   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
982   gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
983
984   hseparator = gtk_hseparator_new ();
985   gtk_widget_show (hseparator);
986   gtk_table_attach (GTK_TABLE (table1), hseparator, 0, 1, 1, 2,
987                     (GtkAttachOptions) (GTK_FILL),
988                     (GtkAttachOptions) (GTK_FILL), 0, 0);
989
990   eventbox = gtk_event_box_new ();
991   gtk_widget_show (eventbox);
992   gtk_table_attach (GTK_TABLE (table1), eventbox, 1, 2, 12, 13,
993                     (GtkAttachOptions) (GTK_FILL),
994                     (GtkAttachOptions) (GTK_FILL), 0, 0);
995
996   lock_valuechange_togglebutton = gtk_toggle_button_new_with_mnemonic ("UNLOCK");
997   gtk_widget_show (lock_valuechange_togglebutton);
998   gtk_container_add (GTK_CONTAINER (eventbox), lock_valuechange_togglebutton);
999
1000   // Value Spins
1001   hshift_value_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1002   hshift_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hshift_value_spinbutton_adj), 1, 2);
1003   gtk_widget_show (hshift_value_spinbutton);
1004   gtk_table_attach (GTK_TABLE (table1), hshift_value_spinbutton, 1, 2, 2, 3,
1005                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1006                     (GtkAttachOptions) (0), 0, 0);
1007   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hshift_value_spinbutton), GTK_UPDATE_IF_VALID);
1008   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (hshift_value_spinbutton), TRUE);
1009   gtk_widget_set_sensitive( GTK_WIDGET( hshift_value_spinbutton ), FALSE );
1010
1011   vshift_value_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1012   vshift_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vshift_value_spinbutton_adj), 1, 2);
1013   gtk_widget_show (vshift_value_spinbutton);
1014   gtk_table_attach (GTK_TABLE (table1), vshift_value_spinbutton, 1, 2, 4, 5,
1015                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1016                     (GtkAttachOptions) (0), 0, 0);
1017   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vshift_value_spinbutton), GTK_UPDATE_IF_VALID);
1018   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (vshift_value_spinbutton), TRUE);
1019   gtk_widget_set_sensitive( GTK_WIDGET( vshift_value_spinbutton ), FALSE );
1020
1021   hscale_value_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1022   hscale_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hscale_value_spinbutton_adj), 1, 4);
1023   gtk_widget_show (hscale_value_spinbutton);
1024   gtk_table_attach (GTK_TABLE (table1), hscale_value_spinbutton, 1, 2, 6, 7,
1025                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1026                     (GtkAttachOptions) (0), 0, 0);
1027   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hscale_value_spinbutton), GTK_UPDATE_IF_VALID);
1028   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (hscale_value_spinbutton), TRUE);
1029   gtk_widget_set_sensitive( GTK_WIDGET( hscale_value_spinbutton ), FALSE );
1030
1031   vscale_value_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1032   vscale_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vscale_value_spinbutton_adj), 1, 4);
1033   gtk_widget_show (vscale_value_spinbutton);
1034   gtk_table_attach (GTK_TABLE (table1), vscale_value_spinbutton, 1, 2, 8, 9,
1035                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1036                     (GtkAttachOptions) (0), 0, 0);
1037   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vscale_value_spinbutton), GTK_UPDATE_IF_VALID);
1038   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (vscale_value_spinbutton), TRUE);
1039   gtk_widget_set_sensitive( GTK_WIDGET( vscale_value_spinbutton ), FALSE );
1040
1041   rotate_value_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0);
1042   rotate_value_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_value_spinbutton_adj), 1, 0);
1043   gtk_widget_show (rotate_value_spinbutton);
1044   gtk_table_attach (GTK_TABLE (table1), rotate_value_spinbutton, 1, 2, 10, 11,
1045                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1046                     (GtkAttachOptions) (0), 0, 0);
1047   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (rotate_value_spinbutton), GTK_UPDATE_IF_VALID);
1048   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (rotate_value_spinbutton), TRUE);
1049   gtk_widget_set_sensitive( GTK_WIDGET( rotate_value_spinbutton ), FALSE );
1050
1051   // Offset Spins
1052   hshift_offset_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1053   hshift_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hshift_offset_spinbutton_adj), 0, 2);
1054   gtk_widget_show (hshift_offset_spinbutton);
1055   gtk_table_attach (GTK_TABLE (table1), hshift_offset_spinbutton, 2, 3, 2, 3,
1056                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1057                     (GtkAttachOptions) (0), 4, 0);
1058   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (hshift_offset_spinbutton), TRUE);
1059   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hshift_offset_spinbutton), GTK_UPDATE_IF_VALID);
1060   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (hshift_offset_spinbutton), TRUE);
1061
1062   vshift_offset_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1063   vshift_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vshift_offset_spinbutton_adj), 0, 2);
1064   gtk_widget_show (vshift_offset_spinbutton);
1065   gtk_table_attach (GTK_TABLE (table1), vshift_offset_spinbutton, 2, 3, 4, 5,
1066                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1067                     (GtkAttachOptions) (0), 4, 0);
1068   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (vshift_offset_spinbutton), TRUE);
1069   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vshift_offset_spinbutton), GTK_UPDATE_IF_VALID);
1070   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (vshift_offset_spinbutton), TRUE);
1071
1072   hscale_offset_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1073   hscale_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hscale_offset_spinbutton_adj), 0, 4);
1074   gtk_widget_show (hscale_offset_spinbutton);
1075   gtk_table_attach (GTK_TABLE (table1), hscale_offset_spinbutton, 2, 3, 6, 7,
1076                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1077                     (GtkAttachOptions) (0), 4, 0);
1078   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (hscale_offset_spinbutton), TRUE);
1079   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hscale_offset_spinbutton), GTK_UPDATE_IF_VALID);
1080   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (hscale_offset_spinbutton), TRUE);
1081
1082   vscale_offset_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1083   vscale_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vscale_offset_spinbutton_adj), 0, 4);
1084   gtk_widget_show (vscale_offset_spinbutton);
1085   gtk_table_attach (GTK_TABLE (table1), vscale_offset_spinbutton, 2, 3, 8, 9,
1086                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1087                     (GtkAttachOptions) (0), 4, 0);
1088   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (vscale_offset_spinbutton), TRUE);
1089   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vscale_offset_spinbutton), GTK_UPDATE_IF_VALID);
1090   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (vscale_offset_spinbutton), TRUE);
1091
1092   rotate_offset_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0);
1093   rotate_offset_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_offset_spinbutton_adj), 0, 2);
1094   gtk_widget_show (rotate_offset_spinbutton);
1095   gtk_table_attach (GTK_TABLE (table1), rotate_offset_spinbutton, 2, 3, 10, 11,
1096                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1097                     (GtkAttachOptions) (0), 4, 0);
1098   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (rotate_offset_spinbutton), TRUE);
1099   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (rotate_offset_spinbutton), GTK_UPDATE_IF_VALID);
1100   gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (rotate_offset_spinbutton), TRUE);
1101
1102     // Step Spins
1103   hshift_step_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1104   hshift_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hshift_step_spinbutton_adj), 1, 2);
1105   gtk_widget_show (hshift_step_spinbutton);
1106   gtk_table_attach (GTK_TABLE (table1), hshift_step_spinbutton, 3, 4, 2, 3,
1107                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1108                     (GtkAttachOptions) (0), 0, 0);
1109   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hshift_step_spinbutton), GTK_UPDATE_IF_VALID);
1110
1111   vshift_step_spinbutton_adj = gtk_adjustment_new (0.0, -8192.0, 8192.0, 2.0, 8.0, 8.0);
1112   vshift_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vshift_step_spinbutton_adj), 1, 2);
1113   gtk_widget_show (vshift_step_spinbutton);
1114   gtk_table_attach (GTK_TABLE (table1), vshift_step_spinbutton, 3, 4, 4, 5,
1115                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1116                     (GtkAttachOptions) (0), 0, 0);
1117   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vshift_step_spinbutton), GTK_UPDATE_IF_VALID);
1118
1119   hscale_step_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1120   hscale_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (hscale_step_spinbutton_adj), 1, 4);
1121   gtk_widget_show (hscale_step_spinbutton);
1122   gtk_table_attach (GTK_TABLE (table1), hscale_step_spinbutton, 3, 4, 6, 7,
1123                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1124                     (GtkAttachOptions) (0), 0, 0);
1125   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (hscale_step_spinbutton), GTK_UPDATE_IF_VALID);
1126
1127   vscale_step_spinbutton_adj = gtk_adjustment_new (0.0, -1024.0, 1024.0, 1.0, 4.0, 4.0);
1128   vscale_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (vscale_step_spinbutton_adj), 1, 4);
1129   gtk_widget_show (vscale_step_spinbutton);
1130   gtk_table_attach (GTK_TABLE (table1), vscale_step_spinbutton, 3, 4, 8, 9,
1131                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1132                     (GtkAttachOptions) (0), 0, 0);
1133   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (vscale_step_spinbutton), GTK_UPDATE_IF_VALID);
1134
1135   rotate_step_spinbutton_adj = gtk_adjustment_new (0.0, -360.0, 360.0, 1.0, 10.0, 10.0);
1136   rotate_step_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (rotate_step_spinbutton_adj), 1, 2);
1137   gtk_widget_show (rotate_step_spinbutton);
1138   gtk_table_attach (GTK_TABLE (table1), rotate_step_spinbutton, 3, 4, 10, 11,
1139                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1140                     (GtkAttachOptions) (0), 0, 0);
1141   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (rotate_step_spinbutton), GTK_UPDATE_IF_VALID);
1142
1143   eventbox = gtk_event_box_new ();
1144   gtk_widget_show (eventbox);
1145   gtk_table_attach (GTK_TABLE (table1), eventbox, 2, 3, 12, 13,
1146                     (GtkAttachOptions) (0),
1147                     (GtkAttachOptions) (0), 0, 0);
1148
1149   eventbox = gtk_event_box_new ();
1150   gtk_widget_show (eventbox);
1151   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 12, 13,
1152                     (GtkAttachOptions) (0),
1153                     (GtkAttachOptions) (0), 0, 0);
1154
1155   eventbox = gtk_event_box_new ();
1156   gtk_widget_show (eventbox);
1157   gtk_table_attach (GTK_TABLE (table1), eventbox, 0, 1, 0, 1,
1158                     (GtkAttachOptions) (0),
1159                     (GtkAttachOptions) (0), 0, 0);
1160
1161   viewport7 = gtk_viewport_new (NULL, NULL);
1162   gtk_widget_show (viewport7);
1163   gtk_box_pack_start (GTK_BOX (vbox7), viewport7, FALSE, TRUE, 0);
1164   gtk_container_set_border_width (GTK_CONTAINER (viewport7), 2);
1165   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport7), GTK_SHADOW_ETCHED_IN);
1166
1167   table4 = gtk_table_new (4, 7, FALSE);
1168   gtk_widget_show (table4);
1169   gtk_container_add (GTK_CONTAINER (viewport7), table4);
1170
1171   viewport5 = gtk_viewport_new (NULL, NULL);
1172   gtk_widget_show (viewport5);
1173   gtk_table_attach (GTK_TABLE (table4), viewport5, 1, 7, 0, 4,
1174                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1175                     (GtkAttachOptions) (0), 0, 0);
1176   gtk_container_set_border_width (GTK_CONTAINER (viewport5), 6);
1177   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport5), GTK_SHADOW_ETCHED_OUT);
1178
1179   table5 = gtk_table_new (2, 3, FALSE);
1180   gtk_widget_show (table5);
1181   gtk_container_add (GTK_CONTAINER (viewport5), table5);
1182   gtk_container_set_border_width (GTK_CONTAINER (table5), 5);
1183   gtk_table_set_col_spacings (GTK_TABLE (table5), 2);
1184
1185   label = gtk_label_new ("Height");
1186   gtk_widget_show (label);
1187   gtk_table_attach (GTK_TABLE (table5), label, 2, 3, 0, 1,
1188                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1189                     (GtkAttachOptions) (GTK_FILL), 0, 0);
1190   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1191   gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1);
1192
1193   label = gtk_label_new ("Width");
1194   gtk_widget_show (label);
1195   gtk_table_attach (GTK_TABLE (table5), label, 1, 2, 0, 1,
1196                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1197                     (GtkAttachOptions) (GTK_FILL), 0, 0);
1198   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1199   gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1);
1200
1201   fit_width_spinbutton_adj = gtk_adjustment_new (1, 1, 32, 1, 10, 10);
1202   fit_width_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (fit_width_spinbutton_adj), 1, 0);
1203   gtk_widget_show (fit_width_spinbutton);
1204   gtk_table_attach (GTK_TABLE (table5), fit_width_spinbutton, 1, 2, 1, 2,
1205                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1206                     (GtkAttachOptions) (GTK_FILL), 0, 0);
1207   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (fit_width_spinbutton), TRUE);
1208   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (fit_width_spinbutton), GTK_UPDATE_IF_VALID);
1209
1210   fit_height_spinbutton_adj = gtk_adjustment_new (1, 1, 32, 1, 10, 10);
1211   fit_height_spinbutton = gtk_spin_button_new (GTK_ADJUSTMENT (fit_height_spinbutton_adj), 1, 0);
1212   gtk_widget_show (fit_height_spinbutton);
1213   gtk_table_attach (GTK_TABLE (table5), fit_height_spinbutton, 2, 3, 1, 2,
1214                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1215                     (GtkAttachOptions) (GTK_FILL), 3, 0);
1216   gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (fit_height_spinbutton), TRUE);
1217   gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (fit_height_spinbutton), GTK_UPDATE_IF_VALID);
1218
1219   eventbox = gtk_event_box_new ();
1220   gtk_widget_show (eventbox);
1221   gtk_table_attach (GTK_TABLE (table5), eventbox, 0, 1, 0, 1,
1222                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1223                     (GtkAttachOptions) (GTK_FILL), 0, 0);
1224
1225   eventbox = gtk_event_box_new ();
1226   gtk_widget_show (eventbox);
1227   gtk_table_attach (GTK_TABLE (table5), eventbox, 0, 1, 1, 2,
1228                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1229                     (GtkAttachOptions) (GTK_FILL), 4, 0);
1230
1231   fit_button = gtk_button_new_with_mnemonic ("    Fit    ");
1232   gtk_widget_show (fit_button);
1233   gtk_container_add (GTK_CONTAINER (eventbox), fit_button);
1234
1235   viewport6 = gtk_viewport_new (NULL, NULL);
1236   gtk_widget_show (viewport6);
1237   gtk_table_attach (GTK_TABLE (table4), viewport6, 0, 1, 0, 4,
1238                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1239                     (GtkAttachOptions) (0), 0, 0);
1240   gtk_container_set_border_width (GTK_CONTAINER (viewport6), 4);
1241   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport6), GTK_SHADOW_NONE);
1242
1243   table7 = gtk_table_new (2, 1, FALSE);
1244   gtk_widget_show (table7);
1245   gtk_container_add (GTK_CONTAINER (viewport6), table7);
1246
1247   eventbox = gtk_event_box_new ();
1248   gtk_widget_show (eventbox);
1249   gtk_table_attach (GTK_TABLE (table7), eventbox, 0, 1, 0, 2,
1250                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1251                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
1252
1253   axial_button = gtk_button_new_with_mnemonic ("Axial");
1254   gtk_widget_show (axial_button);
1255   gtk_container_add (GTK_CONTAINER (eventbox), axial_button);
1256   gtk_widget_set_size_request (axial_button, 56, 29);
1257   gtk_container_set_border_width (GTK_CONTAINER (axial_button), 4);
1258
1259   // Fit in Flags sub-dialog
1260   Create_Heretic2FlagsDialog(vbox7);
1261
1262   viewport10 = gtk_viewport_new (NULL, NULL);
1263   gtk_widget_show (viewport10);
1264   gtk_box_pack_start (GTK_BOX (vbox7), viewport10, FALSE, TRUE, 0);
1265   gtk_container_set_border_width (GTK_CONTAINER (viewport10), 2);
1266   gtk_viewport_set_shadow_type (GTK_VIEWPORT (viewport10), GTK_SHADOW_ETCHED_IN);
1267
1268   hbuttonbox1 = gtk_hbutton_box_new ();
1269   gtk_widget_show (hbuttonbox1);
1270   gtk_container_add (GTK_CONTAINER (viewport10), hbuttonbox1);
1271   gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 4);
1272   gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_SPREAD);
1273
1274   done_button = gtk_button_new ();
1275   gtk_widget_show (done_button);
1276   gtk_container_add (GTK_CONTAINER (hbuttonbox1), done_button);
1277   GTK_WIDGET_SET_FLAGS (done_button, GTK_CAN_DEFAULT);
1278
1279   alignment1 = gtk_alignment_new (0.5, 0.5, 0, 0);
1280   gtk_widget_show (alignment1);
1281   gtk_container_add (GTK_CONTAINER (done_button), alignment1);
1282
1283   hbox2 = gtk_hbox_new (FALSE, 2);
1284   gtk_widget_show (hbox2);
1285   gtk_container_add (GTK_CONTAINER (alignment1), hbox2);
1286
1287   image1 = gtk_image_new_from_stock ("gtk-yes", GTK_ICON_SIZE_BUTTON);
1288   gtk_widget_show (image1);
1289   gtk_box_pack_start (GTK_BOX (hbox2), image1, FALSE, FALSE, 0);
1290
1291   label = gtk_label_new_with_mnemonic ("Done");
1292   gtk_widget_show (label);
1293   gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
1294   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1295
1296   apply_button = gtk_button_new ();
1297   gtk_widget_show (apply_button);
1298   gtk_container_add (GTK_CONTAINER (hbuttonbox1), apply_button);
1299   GTK_WIDGET_SET_FLAGS (apply_button, GTK_CAN_DEFAULT);
1300
1301   alignment3 = gtk_alignment_new (0.5, 0.5, 0, 0);
1302   gtk_widget_show (alignment3);
1303   gtk_container_add (GTK_CONTAINER (apply_button), alignment3);
1304
1305   hbox4 = gtk_hbox_new (FALSE, 2);
1306   gtk_widget_show (hbox4);
1307   gtk_container_add (GTK_CONTAINER (alignment3), hbox4);
1308
1309   image3 = gtk_image_new_from_stock ("gtk-apply", GTK_ICON_SIZE_BUTTON);
1310   gtk_widget_show (image3);
1311   gtk_box_pack_start (GTK_BOX (hbox4), image3, FALSE, FALSE, 0);
1312
1313   label = gtk_label_new_with_mnemonic ("Apply");
1314   gtk_widget_show (label);
1315   gtk_box_pack_start (GTK_BOX (hbox4), label, FALSE, FALSE, 0);
1316   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1317
1318   cancel_button = gtk_button_new ();
1319   gtk_widget_show (cancel_button);
1320   gtk_container_add (GTK_CONTAINER (hbuttonbox1), cancel_button);
1321   GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
1322
1323   alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0);
1324   gtk_widget_show (alignment2);
1325   gtk_container_add (GTK_CONTAINER (cancel_button), alignment2);
1326
1327   hbox3 = gtk_hbox_new (FALSE, 2);
1328   gtk_widget_show (hbox3);
1329   gtk_container_add (GTK_CONTAINER (alignment2), hbox3);
1330
1331   image2 = gtk_image_new_from_stock ("gtk-no", GTK_ICON_SIZE_BUTTON);
1332   gtk_widget_show (image2);
1333   gtk_box_pack_start (GTK_BOX (hbox3), image2, FALSE, FALSE, 0);
1334
1335   label = gtk_label_new_with_mnemonic ("Cancel");
1336   gtk_widget_show (label);
1337   gtk_box_pack_start (GTK_BOX (hbox3), label, FALSE, FALSE, 0);
1338   gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1339
1340
1341   g_signal_connect ( (gpointer) SurfaceInspector,
1342                       "delete_event",
1343                       G_CALLBACK (delete_event_callback),
1344                       NULL );
1345   g_signal_connect ((gpointer) SurfaceInspector, "destroy",
1346                     G_CALLBACK (gtk_widget_destroy),
1347                     NULL);
1348
1349   g_signal_connect ((gpointer) texture_combo_entry, "key_press_event",
1350                     G_CALLBACK (on_texture_combo_entry_key_press_event),
1351                     NULL);
1352   g_signal_connect ((gpointer) texture_combo_entry, "activate",
1353                     G_CALLBACK (on_texture_combo_entry_activate),
1354                     NULL);
1355
1356
1357   g_signal_connect ((gpointer) hshift_offset_spinbutton, "value_changed",
1358                     G_CALLBACK (on_hshift_offset_spinbutton_value_changed),
1359                     NULL);
1360   g_signal_connect ((gpointer) vshift_offset_spinbutton, "value_changed",
1361                     G_CALLBACK (on_vshift_offset_spinbutton_value_changed),
1362                     NULL);
1363   g_signal_connect ((gpointer) hscale_offset_spinbutton, "value_changed",
1364                     G_CALLBACK (on_hscale_offset_spinbutton_value_changed),
1365                     NULL);
1366   g_signal_connect ((gpointer) vscale_offset_spinbutton, "value_changed",
1367                     G_CALLBACK (on_vscale_offset_spinbutton_value_changed),
1368                     NULL);
1369   g_signal_connect ((gpointer) rotate_offset_spinbutton, "value_changed",
1370                     G_CALLBACK (on_rotate_offset_spinbutton_value_changed),
1371                     NULL);
1372
1373   g_signal_connect ((gpointer) hshift_value_spinbutton, "value_changed",
1374                     G_CALLBACK (on_hshift_value_spinbutton_value_changed),
1375                     NULL);
1376   g_signal_connect ((gpointer) vshift_value_spinbutton, "value_changed",
1377                     G_CALLBACK (on_vshift_value_spinbutton_value_changed),
1378                     NULL);
1379   g_signal_connect ((gpointer) hscale_value_spinbutton, "value_changed",
1380                     G_CALLBACK (on_hscale_value_spinbutton_value_changed),
1381                     NULL);
1382   g_signal_connect ((gpointer) vscale_value_spinbutton, "value_changed",
1383                     G_CALLBACK (on_vscale_value_spinbutton_value_changed),
1384                     NULL);
1385   g_signal_connect ((gpointer) rotate_value_spinbutton, "value_changed",
1386                     G_CALLBACK (on_rotate_value_spinbutton_value_changed),
1387                     NULL);
1388
1389   g_signal_connect ((gpointer) hshift_step_spinbutton, "value_changed",
1390                     G_CALLBACK (on_hshift_step_spinbutton_value_changed),
1391                     NULL);
1392   g_signal_connect ((gpointer) vshift_step_spinbutton, "value_changed",
1393                     G_CALLBACK (on_vshift_step_spinbutton_value_changed),
1394                     NULL);
1395   g_signal_connect ((gpointer) hscale_step_spinbutton, "value_changed",
1396                     G_CALLBACK (on_hscale_step_spinbutton_value_changed),
1397                     NULL);
1398   g_signal_connect ((gpointer) vscale_step_spinbutton, "value_changed",
1399                     G_CALLBACK (on_vscale_step_spinbutton_value_changed),
1400                     NULL);
1401   g_signal_connect ((gpointer) rotate_step_spinbutton, "value_changed",
1402                     G_CALLBACK (on_rotate_step_spinbutton_value_changed),
1403                     NULL);
1404
1405   g_signal_connect ((gpointer) match_grid_button, "clicked",
1406                     G_CALLBACK (on_match_grid_button_clicked),
1407                     NULL);
1408   g_signal_connect ((gpointer) lock_valuechange_togglebutton, "toggled",
1409                     G_CALLBACK (on_lock_valuechange_togglebutton_toggled),
1410                     NULL);
1411
1412   g_signal_connect ((gpointer) fit_width_spinbutton, "value_changed",
1413                     G_CALLBACK (on_fit_width_spinbutton_value_changed),
1414                     NULL);
1415   g_signal_connect ((gpointer) fit_height_spinbutton, "value_changed",
1416                     G_CALLBACK (on_fit_height_spinbutton_value_changed),
1417                     NULL);
1418   g_signal_connect ((gpointer) fit_button, "clicked",
1419                     G_CALLBACK (on_fit_button_clicked),
1420                     NULL);
1421
1422   g_signal_connect ((gpointer) axial_button, "clicked",
1423                     G_CALLBACK (on_axial_button_clicked),
1424                     NULL);
1425
1426   g_signal_connect ((gpointer) done_button, "clicked",
1427                     G_CALLBACK (on_done_button_clicked),
1428                     NULL);
1429   g_signal_connect ((gpointer) apply_button, "clicked",
1430                     G_CALLBACK (on_apply_button_clicked),
1431                     NULL);
1432   g_signal_connect ((gpointer) cancel_button, "clicked",
1433                     G_CALLBACK (on_cancel_button_clicked),
1434                     NULL);
1435
1436
1437   return SurfaceInspector;
1438 }
1439
1440
1441 // Texture Combo
1442 gboolean on_texture_combo_entry_key_press_event (GtkWidget *widget, GdkEventKey *event,
1443                                                  gpointer user_data)
1444 {
1445   // Have Tab activate selection as well as Return
1446   if (event->keyval == GDK_Tab)
1447     g_signal_emit_by_name ( texture_combo_entry, "activate" );
1448
1449   return FALSE;
1450 }
1451
1452 void on_texture_combo_entry_activate (GtkEntry *entry, gpointer user_data)
1453 {
1454   texdef_t* tmp_texdef;
1455   texdef_t* tmp_orig_texdef;
1456   texdef_to_face_t* temp_texdef_face_list;
1457   char text[128] = { 0 };
1458
1459   if (!texdef_face_list_empty() && g_bListenChanged)
1460   {
1461     // activate only on entry change
1462     strcpy( text, gtk_entry_get_text(entry));
1463     if ( strcmp( old_texture_entry, text ))
1464     {
1465       // Check for spaces in shader name
1466       if (text[0] <= ' ' || strchr(text, ' '))
1467         Sys_FPrintf(SYS_WRN, "WARNING: spaces in shader names are not allowed, ignoring '%s'\n", text);
1468       else
1469       {
1470         for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1471         {
1472           tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1473           tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1474           strcpy( old_texture_entry, text );
1475           tmp_texdef->SetName( text );
1476         }
1477         GetTexMods();
1478       }
1479     }
1480   }
1481 }
1482
1483 // Offset Spins
1484 static void on_hshift_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1485 {
1486   texdef_t* tmp_texdef;
1487   texdef_t* tmp_orig_texdef;
1488   texdef_to_face_t* temp_texdef_face_list;
1489
1490   texdef_offset.shift[0] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hshift_offset_spinbutton) );
1491
1492   if (!texdef_face_list_empty() && g_bListenChanged)
1493   {
1494     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1495     {
1496       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1497       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1498       if (is_HShift_conflicting)
1499         tmp_texdef->shift[0] = tmp_orig_texdef->shift[0] + texdef_offset.shift[0];
1500       else
1501         tmp_texdef->shift[0] = texdef_SI_values.shift[0] + texdef_offset.shift[0];
1502     }
1503     GetTexMods();
1504   }
1505 }
1506
1507 static void on_vshift_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1508 {
1509   texdef_t* tmp_texdef;
1510   texdef_t* tmp_orig_texdef;
1511   texdef_to_face_t* temp_texdef_face_list;
1512
1513   texdef_offset.shift[1] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vshift_offset_spinbutton) );
1514
1515   if (!texdef_face_list_empty() && g_bListenChanged)
1516   {
1517     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1518     {
1519       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1520       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1521       if (is_VShift_conflicting)
1522         tmp_texdef->shift[1] = tmp_orig_texdef->shift[1] + texdef_offset.shift[1];
1523       else
1524         tmp_texdef->shift[1] = texdef_SI_values.shift[1] + texdef_offset.shift[1];
1525     }
1526     GetTexMods();
1527   }
1528
1529 }
1530
1531 static void on_hscale_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1532 {
1533   texdef_t* tmp_texdef;
1534   texdef_t* tmp_orig_texdef;
1535   texdef_to_face_t* temp_texdef_face_list;
1536
1537   texdef_offset.scale[0] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hscale_offset_spinbutton) );
1538
1539   if (!texdef_face_list_empty() && g_bListenChanged)
1540   {
1541     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1542     {
1543       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1544       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1545       if (is_HScale_conflicting)
1546         tmp_texdef->scale[0] = tmp_orig_texdef->scale[0] + texdef_offset.scale[0];
1547       else
1548         tmp_texdef->scale[0] = texdef_SI_values.scale[0] + texdef_offset.scale[0];
1549     }
1550     GetTexMods();
1551   }
1552
1553
1554 }
1555
1556 static void on_vscale_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1557 {
1558   texdef_t* tmp_texdef;
1559   texdef_t* tmp_orig_texdef;
1560   texdef_to_face_t* temp_texdef_face_list;
1561
1562   texdef_offset.scale[1] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vscale_offset_spinbutton) );
1563
1564   if (!texdef_face_list_empty() && g_bListenChanged)
1565   {
1566     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1567     {
1568       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1569       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1570       if (is_VScale_conflicting)
1571         tmp_texdef->scale[1] = tmp_orig_texdef->scale[1] + texdef_offset.scale[1];
1572       else
1573         tmp_texdef->scale[1] = texdef_SI_values.scale[1] + texdef_offset.scale[1];
1574     }
1575     GetTexMods();
1576   }
1577
1578 }
1579
1580 static void on_rotate_offset_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1581 {
1582   texdef_t* tmp_texdef;
1583   texdef_t* tmp_orig_texdef;
1584   texdef_to_face_t* temp_texdef_face_list;
1585
1586   texdef_offset.rotate = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(rotate_offset_spinbutton) );
1587
1588   if (!texdef_face_list_empty() && g_bListenChanged)
1589   {
1590     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1591     {
1592       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1593       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1594       if (is_Rotate_conflicting)
1595         tmp_texdef->rotate = tmp_orig_texdef->rotate + texdef_offset.rotate;
1596       else
1597         tmp_texdef->rotate = texdef_SI_values.rotate + texdef_offset.rotate;
1598     }
1599     GetTexMods();
1600   }
1601
1602 }
1603
1604
1605 // Match Grid
1606 static void on_match_grid_button_clicked (GtkButton *button, gpointer user_data)
1607 {
1608   float hscale, vscale;
1609
1610   if( !strcmp(gtk_entry_get_text (GTK_ENTRY (hscale_value_spinbutton)), "") )
1611     hscale = 0.0;
1612   else
1613     hscale = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hscale_value_spinbutton) );
1614
1615   if( !strcmp( gtk_entry_get_text (GTK_ENTRY (vscale_value_spinbutton)), "") )
1616     vscale = 0.0;
1617   else
1618     vscale = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vscale_value_spinbutton) );
1619   DoSnapTToGrid (hscale, vscale);
1620 }
1621
1622
1623 // Lock out changes to Value
1624 static void on_lock_valuechange_togglebutton_toggled (GtkToggleButton *togglebutton, gpointer user_data)
1625 {
1626   bool is_Locked;
1627
1628   is_Locked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lock_valuechange_togglebutton));
1629
1630   gtk_widget_set_sensitive( GTK_WIDGET( hscale_value_spinbutton ), is_Locked );
1631   gtk_widget_set_sensitive( GTK_WIDGET( vscale_value_spinbutton ), is_Locked );
1632   gtk_widget_set_sensitive( GTK_WIDGET( hshift_value_spinbutton ), is_Locked );
1633   gtk_widget_set_sensitive( GTK_WIDGET( vshift_value_spinbutton ), is_Locked );
1634   gtk_widget_set_sensitive( GTK_WIDGET( rotate_value_spinbutton ), is_Locked );
1635 }
1636
1637
1638 // Value Spins
1639 static void on_hshift_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1640 {
1641   texdef_t* tmp_texdef;
1642   texdef_t* tmp_orig_texdef;
1643   texdef_to_face_t* temp_texdef_face_list;
1644
1645   texdef_SI_values.shift[0] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hshift_value_spinbutton) );
1646
1647   if (!texdef_face_list_empty() && g_bListenChanged)
1648   {
1649     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1650     {
1651       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1652       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1653       tmp_texdef->shift[0] = texdef_SI_values.shift[0] + texdef_offset.shift[0];
1654       is_HShift_conflicting = FALSE;
1655     }
1656     GetTexMods();
1657   }
1658 }
1659
1660 static void on_vshift_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1661 {
1662   texdef_t* tmp_texdef;
1663   texdef_t* tmp_orig_texdef;
1664   texdef_to_face_t* temp_texdef_face_list;
1665
1666   texdef_SI_values.shift[1]  = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vshift_value_spinbutton) );
1667
1668   if (!texdef_face_list_empty() && g_bListenChanged)
1669   {
1670     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1671     {
1672       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1673       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1674       tmp_texdef->shift[1] = texdef_SI_values.shift[1] + texdef_offset.shift[1];
1675       is_VShift_conflicting = FALSE;
1676     }
1677     GetTexMods();
1678   }
1679 }
1680
1681 static void on_hscale_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1682 {
1683   texdef_t* tmp_texdef;
1684   texdef_t* tmp_orig_texdef;
1685   texdef_to_face_t* temp_texdef_face_list;
1686
1687   texdef_SI_values.scale[0] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hscale_value_spinbutton) );
1688
1689   if (!texdef_face_list_empty() && g_bListenChanged)
1690   {
1691     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1692     {
1693       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1694       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1695       tmp_texdef->scale[0] = texdef_SI_values.scale[0] + texdef_offset.scale[0];
1696       is_HScale_conflicting = FALSE;
1697     }
1698     GetTexMods();
1699   }
1700 }
1701
1702 static void on_vscale_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1703 {
1704   texdef_t* tmp_texdef;
1705   texdef_t* tmp_orig_texdef;
1706   texdef_to_face_t* temp_texdef_face_list;
1707
1708   texdef_SI_values.scale[1] = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vscale_value_spinbutton) );
1709
1710   if (!texdef_face_list_empty() && g_bListenChanged)
1711   {
1712     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1713     {
1714       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1715       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1716       tmp_texdef->scale[1] = texdef_SI_values.scale[1] + texdef_offset.scale[1];
1717       is_VScale_conflicting = FALSE;
1718     }
1719     GetTexMods();
1720   }
1721 }
1722
1723 static void on_rotate_value_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1724 {
1725   texdef_t* tmp_texdef;
1726   texdef_t* tmp_orig_texdef;
1727   texdef_to_face_t* temp_texdef_face_list;
1728
1729   texdef_SI_values.rotate = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(rotate_value_spinbutton) );
1730
1731   if (!texdef_face_list_empty() && g_bListenChanged)
1732   {
1733     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1734     {
1735       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1736       tmp_orig_texdef = (texdef_t *) &temp_texdef_face_list->orig_texdef;
1737       tmp_texdef->rotate = texdef_SI_values.rotate + texdef_offset.rotate;
1738       is_Rotate_conflicting = FALSE;
1739     }
1740     GetTexMods();
1741   }
1742 }
1743
1744
1745 // Step Spins
1746 static void on_hshift_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1747 {
1748   gfloat val;
1749   GtkAdjustment * adjust;
1750
1751   if (!g_bListenChanged)
1752     return;
1753
1754   l_pIncrement = Get_SI_Inc();
1755
1756 #ifdef DBG_SI
1757   Sys_Printf("OnIncrementChanged HShift\n");
1758 #endif
1759
1760   val = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hshift_step_spinbutton) ) ;
1761   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( hshift_offset_spinbutton ));
1762   adjust->step_increment = val;
1763   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( hshift_value_spinbutton ));
1764   adjust->step_increment = val;
1765   l_pIncrement->shift[0] = val;
1766 }
1767
1768 static void on_vshift_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1769 {
1770   gfloat val;
1771   GtkAdjustment * adjust;
1772
1773   if (!g_bListenChanged)
1774     return;
1775
1776   l_pIncrement = Get_SI_Inc();
1777
1778 #ifdef DBG_SI
1779   Sys_Printf("OnIncrementChanged VShift\n");
1780 #endif
1781
1782   val = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vshift_step_spinbutton) ) ;
1783   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( vshift_offset_spinbutton ));
1784   adjust->step_increment = val;
1785   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( vshift_value_spinbutton ));
1786   adjust->step_increment = val;
1787   l_pIncrement->shift[1] = val;
1788 }
1789
1790 static void on_hscale_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1791 {
1792   gfloat val;
1793   GtkAdjustment * adjust;
1794
1795   if (!g_bListenChanged)
1796     return;
1797
1798   l_pIncrement = Get_SI_Inc();
1799
1800 #ifdef DBG_SI
1801   Sys_Printf("OnIncrementChanged HShift\n");
1802 #endif
1803
1804   val = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(hscale_step_spinbutton) ) ;
1805   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( hscale_offset_spinbutton ));
1806   adjust->step_increment = val;
1807   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( hscale_value_spinbutton ));
1808   adjust->step_increment = val;
1809   l_pIncrement->scale[0] = val;
1810 }
1811
1812 static void on_vscale_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1813 {
1814   gfloat val;
1815   GtkAdjustment * adjust;
1816
1817   if (!g_bListenChanged)
1818     return;
1819
1820   l_pIncrement = Get_SI_Inc();
1821
1822 #ifdef DBG_SI
1823   Sys_Printf("OnIncrementChanged HShift\n");
1824 #endif
1825
1826   val = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(vscale_step_spinbutton) ) ;
1827   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( vscale_offset_spinbutton ));
1828   adjust->step_increment = val;
1829   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( vscale_value_spinbutton ));
1830   adjust->step_increment = val;
1831   l_pIncrement->scale[1] = val;
1832 }
1833
1834 static void on_rotate_step_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1835 {
1836   gfloat val;
1837   GtkAdjustment * adjust;
1838
1839   if (!g_bListenChanged)
1840     return;
1841
1842   l_pIncrement = Get_SI_Inc();
1843
1844 #ifdef DBG_SI
1845   Sys_Printf("OnIncrementChanged HShift\n");
1846 #endif
1847
1848   val = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(rotate_step_spinbutton) ) ;
1849   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( rotate_offset_spinbutton ));
1850   adjust->step_increment = val;
1851   adjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON ( rotate_value_spinbutton ));
1852   adjust->step_increment = val;
1853   l_pIncrement->rotate = val;
1854 }
1855
1856
1857 // Fit Texture
1858 static void on_fit_width_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1859 {
1860   m_nWidth = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(fit_width_spinbutton) );
1861 }
1862
1863 static void on_fit_height_spinbutton_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
1864 {
1865   m_nHeight = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(fit_height_spinbutton) );
1866 }
1867
1868 static void on_fit_button_clicked (GtkButton *button, gpointer user_data)
1869 {
1870   FaceList_FitTexture(get_texdef_face_list(), m_nHeight, m_nWidth);
1871   Sys_UpdateWindows(W_ALL);
1872 }
1873
1874
1875 // Axial Button
1876 static void on_axial_button_clicked (GtkButton *button, gpointer user_data)
1877 {
1878   texdef_t* tmp_texdef;
1879   texdef_t* tmp_orig_texdef;
1880   texdef_to_face_t* temp_texdef_face_list;
1881
1882   if (!texdef_face_list_empty() && g_bListenChanged)
1883   {
1884     for (temp_texdef_face_list = get_texdef_face_list(); temp_texdef_face_list; temp_texdef_face_list = temp_texdef_face_list->next)
1885     {
1886       tmp_texdef = (texdef_t *) &temp_texdef_face_list->texdef;
1887       tmp_texdef->shift[0] = 0.0;
1888       tmp_texdef->shift[1] = 0.0;
1889       tmp_texdef->scale[0] = 0.5;
1890       tmp_texdef->scale[1] = 0.5;
1891       tmp_texdef->rotate = 0.0;
1892     }
1893   }
1894
1895   SetTexdef_FaceList( get_texdef_face_list(), FALSE, TRUE );
1896   Sys_UpdateWindows(W_ALL);
1897 }
1898
1899
1900 // Action Buttons
1901 static void on_done_button_clicked (GtkButton *button, gpointer user_data)
1902 {
1903   if ( !texdef_face_list_empty() )
1904     GetTexMods(TRUE);
1905   HideDlg();
1906   Sys_UpdateWindows(W_ALL);
1907 }
1908
1909 static void on_apply_button_clicked (GtkButton *button, gpointer user_data)
1910 {
1911   if (!g_bListenChanged)
1912     return;
1913
1914   if ( !texdef_face_list_empty() )
1915   {
1916     GetTexMods (TRUE);
1917     Sys_UpdateWindows(W_CAMERA);
1918     GetTexdefInfo_from_Radiant();
1919     SetTexMods();
1920   }
1921 }
1922
1923 static void on_cancel_button_clicked (GtkButton *button, gpointer user_data)
1924 {
1925   texturewin = Texturewin ();
1926   texturewin->texdef = g_old_texdef;
1927   // cancel the last do if we own it
1928   if ( (m_nUndoId == Undo_GetUndoId()) && ( m_nUndoId != 0 ))
1929   {
1930 #ifdef DBG_SI
1931     Sys_Printf("OnCancel calling Undo_Undo\n");
1932 #endif
1933     g_bListenUpdate = false;
1934     Undo_Undo(TRUE);
1935     g_bListenUpdate = true;
1936     m_nUndoId = 0;
1937   }
1938   HideDlg();
1939 }
1940
1941