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