]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchdialog.cpp
Merge branch 'iqmmodel' into 'master'
[xonotic/netradiant.git] / radiant / patchdialog.cpp
1 /*
2    Copyright (C) 1999-2006 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 // Patch Dialog
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "patchdialog.h"
29
30 #include "itexdef.h"
31
32 #include "debugging/debugging.h"
33
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtkhbox.h>
36 #include <gtk/gtkframe.h>
37 #include <gtk/gtklabel.h>
38 #include <gtk/gtktable.h>
39 #include <gtk/gtkcombobox.h>
40 #include <gtk/gtkbutton.h>
41 #include <gtk/gtkspinbutton.h>
42 #include <gtk/gtkcheckbutton.h>
43
44 #include "gtkutil/idledraw.h"
45 #include "gtkutil/entry.h"
46 #include "gtkutil/button.h"
47 #include "gtkutil/nonmodal.h"
48 #include "dialog.h"
49 #include "gtkdlgs.h"
50 #include "mainframe.h"
51 #include "patchmanip.h"
52 #include "patch.h"
53 #include "commands.h"
54 #include "preferences.h"
55 #include "signal/isignal.h"
56
57
58 #include <gdk/gdkkeysyms.h>
59
60 // the increment we are using for the patch inspector (this is saved in the prefs)
61 struct pi_globals_t
62 {
63         float shift[2];
64         float scale[2];
65         float rotate;
66
67         pi_globals_t(){
68                 shift[0] = 8.0f;
69                 shift[1] = 8.0f;
70                 scale[0] = 0.5f;
71                 scale[1] = 0.5f;
72                 rotate = 45.0f;
73         }
74 };
75
76 pi_globals_t g_pi_globals;
77
78 class PatchFixedSubdivisions
79 {
80 public:
81 PatchFixedSubdivisions() : m_enabled( false ), m_x( 0 ), m_y( 0 ){
82 }
83 PatchFixedSubdivisions( bool enabled, std::size_t x, std::size_t y ) : m_enabled( enabled ), m_x( x ), m_y( y ){
84 }
85 bool m_enabled;
86 std::size_t m_x;
87 std::size_t m_y;
88 };
89
90 void Patch_getFixedSubdivisions( const Patch& patch, PatchFixedSubdivisions& subdivisions ){
91         subdivisions.m_enabled = patch.m_patchDef3;
92         subdivisions.m_x = patch.m_subdivisions_x;
93         subdivisions.m_y = patch.m_subdivisions_y;
94 }
95
96 const std::size_t MAX_PATCH_SUBDIVISIONS = 32;
97
98 void Patch_setFixedSubdivisions( Patch& patch, const PatchFixedSubdivisions& subdivisions ){
99         patch.undoSave();
100
101         patch.m_patchDef3 = subdivisions.m_enabled;
102         patch.m_subdivisions_x = subdivisions.m_x;
103         patch.m_subdivisions_y = subdivisions.m_y;
104
105         if ( patch.m_subdivisions_x == 0 ) {
106                 patch.m_subdivisions_x = 4;
107         }
108         else if ( patch.m_subdivisions_x > MAX_PATCH_SUBDIVISIONS ) {
109                 patch.m_subdivisions_x = MAX_PATCH_SUBDIVISIONS;
110         }
111         if ( patch.m_subdivisions_y == 0 ) {
112                 patch.m_subdivisions_y = 4;
113         }
114         else if ( patch.m_subdivisions_y > MAX_PATCH_SUBDIVISIONS ) {
115                 patch.m_subdivisions_y = MAX_PATCH_SUBDIVISIONS;
116         }
117
118         SceneChangeNotify();
119         Patch_textureChanged();
120         patch.controlPointsChanged();
121 }
122
123 class PatchGetFixedSubdivisions
124 {
125 PatchFixedSubdivisions& m_subdivisions;
126 public:
127 PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
128 }
129 void operator()( Patch& patch ){
130         Patch_getFixedSubdivisions( patch, m_subdivisions );
131         SceneChangeNotify();
132 }
133 };
134
135 void Scene_PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ){
136 #if 1
137         if ( GlobalSelectionSystem().countSelected() != 0 ) {
138                 Patch* patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
139                 if ( patch != 0 ) {
140                         Patch_getFixedSubdivisions( *patch, subdivisions );
141                 }
142         }
143 #else
144         Scene_forEachVisibleSelectedPatch( PatchGetFixedSubdivisions( subdivisions ) );
145 #endif
146 }
147
148 class PatchSetFixedSubdivisions
149 {
150 const PatchFixedSubdivisions& m_subdivisions;
151 public:
152 PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
153 }
154 void operator()( Patch& patch ) const {
155         Patch_setFixedSubdivisions( patch, m_subdivisions );
156 }
157 };
158
159 void Scene_PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ){
160         UndoableCommand command( "patchSetFixedSubdivisions" );
161         Scene_forEachVisibleSelectedPatch( PatchSetFixedSubdivisions( subdivisions ) );
162 }
163
164 typedef struct _GtkCheckButton GtkCheckButton;
165
166 class Subdivisions
167 {
168 public:
169 GtkCheckButton* m_enabled;
170 GtkEntry* m_horizontal;
171 GtkEntry* m_vertical;
172 Subdivisions() : m_enabled( 0 ), m_horizontal( 0 ), m_vertical( 0 ){
173 }
174 void update(){
175         PatchFixedSubdivisions subdivisions;
176         Scene_PatchGetFixedSubdivisions( subdivisions );
177
178         toggle_button_set_active_no_signal( GTK_TOGGLE_BUTTON( m_enabled ), subdivisions.m_enabled );
179
180         if ( subdivisions.m_enabled ) {
181                 entry_set_int( m_horizontal, static_cast<int>( subdivisions.m_x ) );
182                 entry_set_int( m_vertical, static_cast<int>( subdivisions.m_y ) );
183                 gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), TRUE );
184                 gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), TRUE );
185         }
186         else
187         {
188                 gtk_entry_set_text( m_horizontal, "" );
189                 gtk_entry_set_text( m_vertical, "" );
190                 gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), FALSE );
191                 gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), FALSE );
192         }
193 }
194 void cancel(){
195         update();
196 }
197 typedef MemberCaller<Subdivisions, &Subdivisions::cancel> CancelCaller;
198 void apply(){
199         Scene_PatchSetFixedSubdivisions(
200                 PatchFixedSubdivisions(
201                         gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_enabled ) ) != FALSE,
202                         static_cast<std::size_t>( entry_get_int( m_horizontal ) ),
203                         static_cast<std::size_t>( entry_get_int( m_vertical ) )
204                         )
205                 );
206 }
207 typedef MemberCaller<Subdivisions, &Subdivisions::apply> ApplyCaller;
208 static void applyGtk( GtkToggleButton* toggle, Subdivisions* self ){
209         self->apply();
210 }
211 };
212
213 class PatchInspector : public Dialog
214 {
215 GtkWindow* BuildDialog();
216 Subdivisions m_subdivisions;
217 NonModalEntry m_horizontalSubdivisionsEntry;
218 NonModalEntry m_verticalSubdivisionsEntry;
219 public:
220 IdleDraw m_idleDraw;
221 WindowPositionTracker m_position_tracker;
222
223 Patch *m_Patch;
224
225 CopiedString m_strName;
226 float m_fS;
227 float m_fT;
228 float m_fX;
229 float m_fY;
230 float m_fZ;
231 /*  float       m_fHScale;
232    float        m_fHShift;
233    float        m_fRotate;
234    float        m_fVScale;
235    float        m_fVShift; */
236 int m_nCol;
237 int m_nRow;
238 GtkComboBox *m_pRowCombo;
239 GtkComboBox *m_pColCombo;
240 std::size_t m_countRows;
241 std::size_t m_countCols;
242
243 // turn on/off processing of the "changed" "value_changed" messages
244 // (need to turn off when we are feeding data in)
245 // NOTE: much more simple than blocking signals
246 bool m_bListenChanged;
247
248 PatchInspector() :
249         m_horizontalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
250         m_verticalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
251         m_idleDraw( MemberCaller<PatchInspector, &PatchInspector::GetPatchInfo>( *this ) ){
252         m_fS = 0.0f;
253         m_fT = 0.0f;
254         m_fX = 0.0f;
255         m_fY = 0.0f;
256         m_fZ = 0.0f;
257         m_nCol = 0;
258         m_nRow = 0;
259         m_countRows = 0;
260         m_countCols = 0;
261         m_Patch = 0;
262         m_bListenChanged = true;
263
264         m_position_tracker.setPosition( c_default_window_pos );
265 }
266
267 bool visible(){
268         return GTK_WIDGET_VISIBLE( GetWidget() );
269 }
270
271 //  void UpdateInfo();
272 //  void SetPatchInfo();
273 void GetPatchInfo();
274 void UpdateSpinners( bool bUp, int nID );
275 // read the current patch on map and initialize m_fX m_fY accordingly
276 void UpdateRowColInfo();
277 // sync the dialog our internal data structures
278 // depending on the flag it will read or write
279 // we use m_nCol m_nRow m_fX m_fY m_fZ m_fS m_fT m_strName
280 // (NOTE: this doesn't actually commit stuff to the map or read from it)
281 void importData();
282 void exportData();
283 };
284
285 PatchInspector g_PatchInspector;
286
287 void PatchInspector_constructWindow( GtkWindow* main_window ){
288         g_PatchInspector.m_parent = main_window;
289         g_PatchInspector.Create();
290 }
291 void PatchInspector_destroyWindow(){
292         g_PatchInspector.Destroy();
293 }
294
295 void PatchInspector_queueDraw(){
296         if ( g_PatchInspector.visible() ) {
297                 g_PatchInspector.m_idleDraw.queueDraw();
298         }
299 }
300
301 void DoPatchInspector(){
302         g_PatchInspector.GetPatchInfo();
303         if ( !g_PatchInspector.visible() ) {
304                 g_PatchInspector.ShowDlg();
305         }
306 }
307
308 void PatchInspector_toggleShown(){
309         if ( g_PatchInspector.visible() ) {
310                 g_PatchInspector.m_Patch = 0;
311                 g_PatchInspector.HideDlg();
312         }
313         else{
314                 DoPatchInspector();
315         }
316 }
317
318
319 // =============================================================================
320 // static functions
321
322 // memorize the current state (that is don't try to undo our do before changing something else)
323 static void OnApply( GtkWidget *widget, gpointer data ){
324         g_PatchInspector.exportData();
325         if ( g_PatchInspector.m_Patch != 0 ) {
326                 UndoableCommand command( "patchSetTexture" );
327                 g_PatchInspector.m_Patch->undoSave();
328
329                 if ( !texdef_name_valid( g_PatchInspector.m_strName.c_str() ) ) {
330                         globalErrorStream() << "invalid texture name '" << g_PatchInspector.m_strName.c_str() << "'\n";
331                         g_PatchInspector.m_strName = texdef_name_default();
332                 }
333                 g_PatchInspector.m_Patch->SetShader( g_PatchInspector.m_strName.c_str() );
334
335                 std::size_t r = g_PatchInspector.m_nRow;
336                 std::size_t c = g_PatchInspector.m_nCol;
337                 if ( r < g_PatchInspector.m_Patch->getHeight()
338                          && c < g_PatchInspector.m_Patch->getWidth() ) {
339                         PatchControl& p = g_PatchInspector.m_Patch->ctrlAt( r,c );
340                         p.m_vertex[0] = g_PatchInspector.m_fX;
341                         p.m_vertex[1] = g_PatchInspector.m_fY;
342                         p.m_vertex[2] = g_PatchInspector.m_fZ;
343                         p.m_texcoord[0] = g_PatchInspector.m_fS;
344                         p.m_texcoord[1] = g_PatchInspector.m_fT;
345                         g_PatchInspector.m_Patch->controlPointsChanged();
346                 }
347         }
348 }
349
350 static void OnSelchangeComboColRow( GtkWidget *widget, gpointer data ){
351         if ( !g_PatchInspector.m_bListenChanged ) {
352                 return;
353         }
354         // retrieve the current m_nRow and m_nCol, other params are not relevant
355         g_PatchInspector.exportData();
356         // read the changed values ourselves
357         g_PatchInspector.UpdateRowColInfo();
358         // now reflect our changes
359         g_PatchInspector.importData();
360 }
361
362 class PatchSetTextureRepeat
363 {
364 float m_s, m_t;
365 public:
366 PatchSetTextureRepeat( float s, float t ) : m_s( s ), m_t( t ){
367 }
368 void operator()( Patch& patch ) const {
369         patch.SetTextureRepeat( m_s, m_t );
370 }
371 };
372
373 void Scene_PatchTileTexture_Selected( scene::Graph& graph, float s, float t ){
374         Scene_forEachVisibleSelectedPatch( PatchSetTextureRepeat( s, t ) );
375         SceneChangeNotify();
376 }
377
378 static void OnBtnPatchdetails( GtkWidget *widget, gpointer data ){
379         Patch_CapTexture();
380 }
381
382 static void OnBtnPatchfit( GtkWidget *widget, gpointer data ){
383         Patch_FitTexture();
384 }
385
386 static void OnBtnPatchnatural( GtkWidget *widget, gpointer data ){
387         Patch_NaturalTexture();
388 }
389
390 static void OnBtnPatchreset( GtkWidget *widget, gpointer data ){
391         Patch_ResetTexture();
392 }
393
394 static void OnBtnPatchFlipX( GtkWidget *widget, gpointer data ){
395         Patch_FlipTextureX();
396 }
397
398 static void OnBtnPatchFlipY( GtkWidget *widget, gpointer data ){
399         Patch_FlipTextureY();
400 }
401
402 struct PatchRotateTexture
403 {
404         float m_angle;
405 public:
406         PatchRotateTexture( float angle ) : m_angle( angle ){
407         }
408         void operator()( Patch& patch ) const {
409                 patch.RotateTexture( m_angle );
410         }
411 };
412
413 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
414         Scene_forEachVisibleSelectedPatch( PatchRotateTexture( angle ) );
415 }
416
417 class PatchScaleTexture
418 {
419 float m_s, m_t;
420 public:
421 PatchScaleTexture( float s, float t ) : m_s( s ), m_t( t ){
422 }
423 void operator()( Patch& patch ) const {
424         patch.ScaleTexture( m_s, m_t );
425 }
426 };
427
428 float Patch_convertScale( float scale ){
429         if ( scale > 0 ) {
430                 return scale;
431         }
432         if ( scale < 0 ) {
433                 return -1 / scale;
434         }
435         return 1;
436 }
437
438 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
439         Scene_forEachVisibleSelectedPatch( PatchScaleTexture( Patch_convertScale( s ), Patch_convertScale( t ) ) );
440 }
441
442 class PatchTranslateTexture
443 {
444 float m_s, m_t;
445 public:
446 PatchTranslateTexture( float s, float t )
447         : m_s( s ), m_t( t ){
448 }
449 void operator()( Patch& patch ) const {
450         patch.TranslateTexture( m_s, m_t );
451 }
452 };
453
454 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
455         Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) );
456 }
457
458 static void OnBtnPatchAutoCap( GtkWidget *widget, gpointer data ){
459         Patch_AutoCapTexture();
460 }
461
462 static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){
463         texdef_t td;
464
465         td.rotate = 0;
466         td.scale[0] = td.scale[1] = 0;
467         td.shift[0] = td.shift[1] = 0;
468
469         if ( adj->value == 0 ) {
470                 return;
471         }
472
473         if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hshift_adj" ) ) {
474                 g_pi_globals.shift[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
475
476                 if ( adj->value > 0 ) {
477                         td.shift[0] = g_pi_globals.shift[0];
478                 }
479                 else{
480                         td.shift[0] = -g_pi_globals.shift[0];
481                 }
482         }
483         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vshift_adj" ) ) {
484                 g_pi_globals.shift[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
485
486                 if ( adj->value > 0 ) {
487                         td.shift[1] = g_pi_globals.shift[1];
488                 }
489                 else{
490                         td.shift[1] = -g_pi_globals.shift[1];
491                 }
492         }
493         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hscale_adj" ) ) {
494                 g_pi_globals.scale[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
495                 if ( g_pi_globals.scale[0] == 0.0f ) {
496                         return;
497                 }
498                 if ( adj->value > 0 ) {
499                         td.scale[0] = g_pi_globals.scale[0];
500                 }
501                 else{
502                         td.scale[0] = -g_pi_globals.scale[0];
503                 }
504         }
505         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vscale_adj" ) ) {
506                 g_pi_globals.scale[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
507                 if ( g_pi_globals.scale[1] == 0.0f ) {
508                         return;
509                 }
510                 if ( adj->value > 0 ) {
511                         td.scale[1] = g_pi_globals.scale[1];
512                 }
513                 else{
514                         td.scale[1] = -g_pi_globals.scale[1];
515                 }
516         }
517         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "rotate_adj" ) ) {
518                 g_pi_globals.rotate = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
519
520                 if ( adj->value > 0 ) {
521                         td.rotate = g_pi_globals.rotate;
522                 }
523                 else{
524                         td.rotate = -g_pi_globals.rotate;
525                 }
526         }
527
528         adj->value = 0;
529
530         // will scale shift rotate the patch accordingly
531
532
533         if ( td.shift[0] || td.shift[1] ) {
534                 UndoableCommand command( "patchTranslateTexture" );
535                 Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), td.shift[0], td.shift[1] );
536         }
537         else if ( td.scale[0] || td.scale[1] ) {
538                 UndoableCommand command( "patchScaleTexture" );
539                 Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), td.scale[0], td.scale[1] );
540         }
541         else if ( td.rotate ) {
542                 UndoableCommand command( "patchRotateTexture" );
543                 Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), td.rotate );
544         }
545
546         // update the point-by-point view
547         OnSelchangeComboColRow( 0,0 );
548 }
549
550 static gint OnDialogKey( GtkWidget* widget, GdkEventKey* event, gpointer data ){
551         if ( event->keyval == GDK_Return ) {
552                 OnApply( 0, 0 );
553                 return TRUE;
554         }
555         else if ( event->keyval == GDK_Escape ) {
556                 g_PatchInspector.GetPatchInfo();
557                 return TRUE;
558         }
559         return FALSE;
560 }
561
562 // =============================================================================
563 // PatchInspector class
564
565 GtkWindow* PatchInspector::BuildDialog(){
566         GtkWindow* window = create_floating_window( "Patch Properties", m_parent );
567
568         m_position_tracker.connect( window );
569
570         global_accel_connect_window( window );
571
572         window_connect_focus_in_clear_focus_widget( window );
573
574
575         {
576                 GtkVBox* vbox = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
577                 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
578                 gtk_widget_show( GTK_WIDGET( vbox ) );
579                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) );
580                 {
581                         GtkHBox* hbox = GTK_HBOX( gtk_hbox_new( FALSE, 5 ) );
582                         gtk_widget_show( GTK_WIDGET( hbox ) );
583                         gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), TRUE, TRUE, 0 );
584                         {
585                                 GtkVBox* vbox2 = GTK_VBOX( gtk_vbox_new( FALSE, 0 ) );
586                                 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 0 );
587                                 gtk_widget_show( GTK_WIDGET( vbox2 ) );
588                                 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox2 ), TRUE, TRUE, 0 );
589                                 {
590                                         GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Details" ) );
591                                         gtk_widget_show( GTK_WIDGET( frame ) );
592                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
593                                         {
594                                                 GtkVBox* vbox3 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
595                                                 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
596                                                 gtk_widget_show( GTK_WIDGET( vbox3 ) );
597                                                 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox3 ) );
598                                                 {
599                                                         GtkTable* table = GTK_TABLE( gtk_table_new( 2, 2, FALSE ) );
600                                                         gtk_widget_show( GTK_WIDGET( table ) );
601                                                         gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
602                                                         gtk_table_set_row_spacings( table, 5 );
603                                                         gtk_table_set_col_spacings( table, 5 );
604                                                         {
605                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Row:" ) );
606                                                                 gtk_widget_show( GTK_WIDGET( label ) );
607                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
608                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
609                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
610                                                         }
611                                                         {
612                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Column:" ) );
613                                                                 gtk_widget_show( GTK_WIDGET( label ) );
614                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 0, 1,
615                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
616                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
617                                                         }
618                                                         {
619                                                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
620                                                                 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
621                                                                 AddDialogData( *combo, m_nRow );
622
623                                                                 gtk_widget_show( GTK_WIDGET( combo ) );
624                                                                 gtk_table_attach( table, GTK_WIDGET( combo ), 0, 1, 1, 2,
625                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
626                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
627                                                                 gtk_widget_set_usize( GTK_WIDGET( combo ), 60, -1 );
628                                                                 m_pRowCombo = combo;
629                                                         }
630
631                                                         {
632                                                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
633                                                                 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
634                                                                 AddDialogData( *combo, m_nCol );
635
636                                                                 gtk_widget_show( GTK_WIDGET( combo ) );
637                                                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
638                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
639                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
640                                                                 gtk_widget_set_usize( GTK_WIDGET( combo ), 60, -1 );
641                                                                 m_pColCombo = combo;
642                                                         }
643                                                 }
644                                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
645                                                 gtk_widget_show( GTK_WIDGET( table ) );
646                                                 gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
647                                                 gtk_table_set_row_spacings( table, 5 );
648                                                 gtk_table_set_col_spacings( table, 5 );
649                                                 {
650                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "X:" ) );
651                                                         gtk_widget_show( GTK_WIDGET( label ) );
652                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
653                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
654                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
655                                                 }
656                                                 {
657                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Y:" ) );
658                                                         gtk_widget_show( GTK_WIDGET( label ) );
659                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
660                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
661                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
662                                                 }
663                                                 {
664                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Z:" ) );
665                                                         gtk_widget_show( GTK_WIDGET( label ) );
666                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
667                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
668                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
669                                                 }
670                                                 {
671                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "S:" ) );
672                                                         gtk_widget_show( GTK_WIDGET( label ) );
673                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 3, 4,
674                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
675                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
676                                                 }
677                                                 {
678                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "T:" ) );
679                                                         gtk_widget_show( GTK_WIDGET( label ) );
680                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 4, 5,
681                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
682                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
683                                                 }
684                                                 {
685                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
686                                                         gtk_widget_show( GTK_WIDGET( entry ) );
687                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
688                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
689                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
690                                                         AddDialogData( *entry, m_fX );
691
692                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
693                                                 }
694                                                 {
695                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
696                                                         gtk_widget_show( GTK_WIDGET( entry ) );
697                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
698                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
699                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
700                                                         AddDialogData( *entry, m_fY );
701
702                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
703                                                 }
704                                                 {
705                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
706                                                         gtk_widget_show( GTK_WIDGET( entry ) );
707                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
708                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
709                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
710                                                         AddDialogData( *entry, m_fZ );
711
712                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
713                                                 }
714                                                 {
715                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
716                                                         gtk_widget_show( GTK_WIDGET( entry ) );
717                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 3, 4,
718                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
719                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
720                                                         AddDialogData( *entry, m_fS );
721
722                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
723                                                 }
724                                                 {
725                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
726                                                         gtk_widget_show( GTK_WIDGET( entry ) );
727                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 4, 5,
728                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
729                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
730                                                         AddDialogData( *entry, m_fT );
731
732                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
733                                                 }
734                                         }
735                                 }
736                                 if ( g_pGameDescription->mGameType == "doom3" ) {
737                                         GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Tesselation" ) );
738                                         gtk_widget_show( GTK_WIDGET( frame ) );
739                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
740                                         {
741                                                 GtkVBox* vbox3 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
742                                                 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
743                                                 gtk_widget_show( GTK_WIDGET( vbox3 ) );
744                                                 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox3 ) );
745                                                 {
746                                                         GtkTable* table = GTK_TABLE( gtk_table_new( 3, 2, FALSE ) );
747                                                         gtk_widget_show( GTK_WIDGET( table ) );
748                                                         gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
749                                                         gtk_table_set_row_spacings( table, 5 );
750                                                         gtk_table_set_col_spacings( table, 5 );
751                                                         {
752                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Fixed" ) );
753                                                                 gtk_widget_show( GTK_WIDGET( label ) );
754                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
755                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
756                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
757                                                         }
758                                                         {
759                                                                 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
760                                                                 gtk_widget_show( GTK_WIDGET( check ) );
761                                                                 gtk_table_attach( table, GTK_WIDGET( check ), 1, 2, 0, 1,
762                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
763                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
764                                                                 m_subdivisions.m_enabled = check;
765                                                                 guint handler_id = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( &Subdivisions::applyGtk ), &m_subdivisions );
766                                                                 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) );
767                                                         }
768                                                         {
769                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal" ) );
770                                                                 gtk_widget_show( GTK_WIDGET( label ) );
771                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
772                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
773                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
774                                                         }
775                                                         {
776                                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
777                                                                 gtk_widget_show( GTK_WIDGET( entry ) );
778                                                                 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
779                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
780                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
781                                                                 m_subdivisions.m_horizontal = entry;
782                                                                 m_horizontalSubdivisionsEntry.connect( entry );
783                                                         }
784                                                         {
785                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical" ) );
786                                                                 gtk_widget_show( GTK_WIDGET( label ) );
787                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
788                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
789                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
790                                                         }
791                                                         {
792                                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
793                                                                 gtk_widget_show( GTK_WIDGET( entry ) );
794                                                                 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
795                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
796                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
797                                                                 m_subdivisions.m_vertical = entry;
798                                                                 m_verticalSubdivisionsEntry.connect( entry );
799                                                         }
800                                                 }
801                                         }
802                                 }
803                         }
804                         {
805                                 GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Texturing" ) );
806                                 gtk_widget_show( GTK_WIDGET( frame ) );
807                                 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
808                                 {
809                                         GtkVBox* vbox2 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
810                                         gtk_widget_show( GTK_WIDGET( vbox2 ) );
811                                         gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox2 ) );
812                                         gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
813                                         {
814                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Name:" ) );
815                                                 gtk_widget_show( GTK_WIDGET( label ) );
816                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( label ), TRUE, TRUE, 0 );
817                                                 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
818                                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
819                                         }
820                                         {
821                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
822                                                 //  gtk_entry_set_editable (GTK_ENTRY (entry), false);
823                                                 gtk_widget_show( GTK_WIDGET( entry ) );
824                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
825                                                 AddDialogData( *entry, m_strName );
826
827                                                 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
828                                         }
829                                         {
830                                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 4, FALSE ) );
831                                                 gtk_widget_show( GTK_WIDGET( table ) );
832                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
833                                                 gtk_table_set_row_spacings( table, 5 );
834                                                 gtk_table_set_col_spacings( table, 5 );
835                                                 {
836                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal Shift Step" ) );
837                                                         gtk_widget_show( GTK_WIDGET( label ) );
838                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 0, 1,
839                                                                                           (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
840                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
841                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
842                                                 }
843                                                 {
844                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical Shift Step" ) );
845                                                         gtk_widget_show( GTK_WIDGET( label ) );
846                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 1, 2,
847                                                                                           (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
848                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
849                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
850                                                 }
851                                                 {
852                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal Stretch Step" ) );
853                                                         gtk_widget_show( GTK_WIDGET( label ) );
854                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 2, 3,
855                                                                                           (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
856                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
857                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
858                                                 }
859                                                 {
860                                                         GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Flip" ) );
861                                                         gtk_widget_show( GTK_WIDGET( button ) );
862                                                         gtk_table_attach( table, GTK_WIDGET( button ), 3, 4, 2, 3,
863                                                                                           (GtkAttachOptions)( GTK_FILL ),
864                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
865                                                         g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchFlipX ), 0 );
866                                                         gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
867                                                 }
868                                                 {
869                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical Stretch Step" ) );
870                                                         gtk_widget_show( GTK_WIDGET( label ) );
871                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 3, 4,
872                                                                                           (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
873                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
874                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
875                                                 }
876                                                 {
877                                                         GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Flip" ) );
878                                                         gtk_widget_show( GTK_WIDGET( button ) );
879                                                         gtk_table_attach( table, GTK_WIDGET( button ), 3, 4, 3, 4,
880                                                                                           (GtkAttachOptions)( GTK_FILL ),
881                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
882                                                         g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchFlipY ), 0 );
883                                                         gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
884                                                 }
885                                                 {
886                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Rotate Step" ) );
887                                                         gtk_widget_show( GTK_WIDGET( label ) );
888                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 4, 5,
889                                                                                           (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
890                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
891                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
892                                                 }
893                                                 {
894                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
895                                                         gtk_widget_show( GTK_WIDGET( entry ) );
896                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 0, 1,
897                                                                                           (GtkAttachOptions)( GTK_FILL ),
898                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
899                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
900                                                         g_object_set_data( G_OBJECT( window ), "hshift_entry", entry );
901                                                         // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
902                                                         // so we need to have at least one initialisation somewhere
903                                                         entry_set_float( entry, g_pi_globals.shift[0] );
904
905                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ) );
906                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
907                                                         g_object_set_data( G_OBJECT( window ), "hshift_adj", adj );
908
909                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
910                                                         gtk_widget_show( GTK_WIDGET( spin ) );
911                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 0, 1,
912                                                                                           (GtkAttachOptions)( 0 ),
913                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
914                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
915                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
916                                                 }
917                                                 {
918                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
919                                                         gtk_widget_show( GTK_WIDGET( entry ) );
920                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 1, 2,
921                                                                                           (GtkAttachOptions)( GTK_FILL ),
922                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
923                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
924                                                         entry_set_float( entry, g_pi_globals.shift[1] );
925
926                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ) );
927                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
928                                                         g_object_set_data( G_OBJECT( window ), "vshift_adj", adj );
929
930                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
931                                                         gtk_widget_show( GTK_WIDGET( spin ) );
932                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 1, 2,
933                                                                                           (GtkAttachOptions)( 0 ),
934                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
935                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
936                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
937                                                 }
938                                                 {
939                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
940                                                         gtk_widget_show( GTK_WIDGET( entry ) );
941                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 2, 3,
942                                                                                           (GtkAttachOptions)( GTK_FILL ),
943                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
944                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
945                                                         entry_set_float( entry, g_pi_globals.scale[0] );
946
947                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ) );
948                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
949                                                         g_object_set_data( G_OBJECT( window ), "hscale_adj", adj );
950
951                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
952                                                         gtk_widget_show( GTK_WIDGET( spin ) );
953                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 2, 3,
954                                                                                           (GtkAttachOptions)( 0 ),
955                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
956                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
957                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
958                                                 }
959                                                 {
960                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
961                                                         gtk_widget_show( GTK_WIDGET( entry ) );
962                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 3, 4,
963                                                                                           (GtkAttachOptions)( GTK_FILL ),
964                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
965                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
966                                                         entry_set_float( entry, g_pi_globals.scale[1] );
967
968                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ) );
969                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
970                                                         g_object_set_data( G_OBJECT( window ), "vscale_adj", adj );
971
972                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
973                                                         gtk_widget_show( GTK_WIDGET( spin ) );
974                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 3, 4,
975                                                                                           (GtkAttachOptions)( 0 ),
976                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
977                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
978                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
979                                                 }
980                                                 {
981                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
982                                                         gtk_widget_show( GTK_WIDGET( entry ) );
983                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 4, 5,
984                                                                                           (GtkAttachOptions)( GTK_FILL ),
985                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
986                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
987                                                         entry_set_float( entry, g_pi_globals.rotate );
988
989                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ) ); // NOTE: Arnout - this really should be 360 but can't change it anymore as it could break existing maps
990                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
991                                                         g_object_set_data( G_OBJECT( window ), "rotate_adj", adj );
992
993                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
994                                                         gtk_widget_show( GTK_WIDGET( spin ) );
995                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 4, 5,
996                                                                                           (GtkAttachOptions)( 0 ),
997                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
998                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
999                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
1000                                                 }
1001                                         }
1002                                         GtkHBox* hbox2 = GTK_HBOX( gtk_hbox_new( TRUE, 5 ) );
1003                                         gtk_widget_show( GTK_WIDGET( hbox2 ) );
1004                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox2 ), TRUE, FALSE, 0 );
1005                                         {
1006                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Auto Cap" ) );
1007                                                 gtk_widget_show( GTK_WIDGET( button ) );
1008                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1009                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 );
1010                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1011                                         }
1012                                         {
1013                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "CAP" ) );
1014                                                 gtk_widget_show( GTK_WIDGET( button ) );
1015                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1016                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
1017                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1018                                         }
1019                                         {
1020                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Set..." ) );
1021                                                 gtk_widget_show( GTK_WIDGET( button ) );
1022                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1023                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
1024                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1025                                         }
1026                                         {
1027                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Natural" ) );
1028                                                 gtk_widget_show( GTK_WIDGET( button ) );
1029                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1030                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
1031                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1032                                         }
1033                                         {
1034                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Fit" ) );
1035                                                 gtk_widget_show( GTK_WIDGET( button ) );
1036                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1037                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
1038                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1039                                         }
1040                                 }
1041                         }
1042                 }
1043         }
1044
1045         return window;
1046 }
1047
1048 // sync the dialog our internal data structures
1049 void PatchInspector::exportData(){
1050         m_bListenChanged = false;
1051         Dialog::exportData();
1052         m_bListenChanged = true;
1053 }
1054 void PatchInspector::importData(){
1055         m_bListenChanged = false;
1056         Dialog::importData();
1057         m_bListenChanged = true;
1058 }
1059
1060 // read the map and feed in the stuff to the dialog box
1061 void PatchInspector::GetPatchInfo(){
1062         if ( g_pGameDescription->mGameType == "doom3" ) {
1063                 m_subdivisions.update();
1064         }
1065
1066         if ( GlobalSelectionSystem().countSelected() == 0 ) {
1067                 m_Patch = 0;
1068         }
1069         else
1070         {
1071                 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
1072         }
1073
1074         if ( m_Patch != 0 ) {
1075                 m_strName = m_Patch->GetShader();
1076
1077                 // fill in the numbers for Row / Col selection
1078                 m_bListenChanged = false;
1079
1080                 {
1081                         gtk_combo_box_set_active( m_pRowCombo, 0 );
1082
1083                         for ( std::size_t i = 0; i < m_countRows; ++i )
1084                         {
1085                                 gtk_combo_box_remove_text( m_pRowCombo, gint( m_countRows - i - 1 ) );
1086                         }
1087
1088                         m_countRows = m_Patch->getHeight();
1089                         for ( std::size_t i = 0; i < m_countRows; ++i )
1090                         {
1091                                 char buffer[16];
1092                                 sprintf( buffer, "%u", Unsigned( i ) );
1093                                 gtk_combo_box_append_text( m_pRowCombo, buffer );
1094                         }
1095
1096                         gtk_combo_box_set_active( m_pRowCombo, 0 );
1097                 }
1098
1099                 {
1100                         gtk_combo_box_set_active( m_pColCombo, 0 );
1101
1102                         for ( std::size_t i = 0; i < m_countCols; ++i )
1103                         {
1104                                 gtk_combo_box_remove_text( m_pColCombo, gint( m_countCols - i - 1 ) );
1105                         }
1106
1107                         m_countCols = m_Patch->getWidth();
1108                         for ( std::size_t i = 0; i < m_countCols; ++i )
1109                         {
1110                                 char buffer[16];
1111                                 sprintf( buffer, "%u", Unsigned( i ) );
1112                                 gtk_combo_box_append_text( m_pColCombo, buffer );
1113                         }
1114
1115                         gtk_combo_box_set_active( m_pColCombo, 0 );
1116                 }
1117
1118                 m_bListenChanged = true;
1119
1120         }
1121         else
1122         {
1123                 //globalOutputStream() << "WARNING: no patch\n";
1124         }
1125         // fill in our internal structs
1126         m_nRow = 0; m_nCol = 0;
1127         UpdateRowColInfo();
1128         // now update the dialog box
1129         importData();
1130 }
1131
1132 // read the current patch on map and initialize m_fX m_fY accordingly
1133 // NOTE: don't call UpdateData in there, it's not meant for
1134 void PatchInspector::UpdateRowColInfo(){
1135         m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
1136
1137         if ( m_Patch != 0 ) {
1138                 // we rely on whatever active row/column has been set before we get called
1139                 std::size_t r = m_nRow;
1140                 std::size_t c = m_nCol;
1141                 if ( r < m_Patch->getHeight()
1142                          && c < m_Patch->getWidth() ) {
1143                         const PatchControl& p = m_Patch->ctrlAt( r,c );
1144                         m_fX = p.m_vertex[0];
1145                         m_fY = p.m_vertex[1];
1146                         m_fZ = p.m_vertex[2];
1147                         m_fS = p.m_texcoord[0];
1148                         m_fT = p.m_texcoord[1];
1149                 }
1150         }
1151 }
1152
1153
1154 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1155         PatchInspector_queueDraw();
1156 }
1157
1158
1159 #include "preferencesystem.h"
1160
1161
1162 void PatchInspector_Construct(){
1163         GlobalCommands_insert( "PatchInspector", FreeCaller<PatchInspector_toggleShown>(), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
1164
1165         GlobalPreferenceSystem().registerPreference( "PatchWnd", WindowPositionTrackerImportStringCaller( g_PatchInspector.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_PatchInspector.m_position_tracker ) );
1166         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", FloatImportStringCaller( g_pi_globals.scale[0] ), FloatExportStringCaller( g_pi_globals.scale[0] ) );
1167         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", FloatImportStringCaller( g_pi_globals.scale[1] ), FloatExportStringCaller( g_pi_globals.scale[1] ) );
1168         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", FloatImportStringCaller( g_pi_globals.shift[0] ), FloatExportStringCaller( g_pi_globals.shift[0] ) );
1169         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", FloatImportStringCaller( g_pi_globals.shift[1] ), FloatExportStringCaller( g_pi_globals.shift[1] ) );
1170         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", FloatImportStringCaller( g_pi_globals.rotate ), FloatExportStringCaller( g_pi_globals.rotate ) );
1171
1172         typedef FreeCaller1<const Selectable&, PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1173         GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1174         typedef FreeCaller<PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1175         Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1176 }
1177 void PatchInspector_Destroy(){
1178 }