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