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