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