]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchdialog.cpp
Hack around segfault at launch, patch from danfe: https://github.com/TTimo/GtkRadiant...
[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         UndoableCommand command( "patchCapTexture" );
380
381         Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
382 }
383
384 static void OnBtnPatchfit( GtkWidget *widget, gpointer data ){
385         UndoableCommand command( "patchFitTexture" );
386
387         Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
388 }
389
390 static void OnBtnPatchnatural( GtkWidget *widget, gpointer data ){
391         UndoableCommand command( "patchNaturalTexture" );
392
393         Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
394 }
395
396 static void OnBtnPatchreset( GtkWidget *widget, gpointer data ){
397         float fx, fy;
398         if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
399                 UndoableCommand command( "patchTileTexture" );
400                 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
401         }
402 }
403
404 struct PatchRotateTexture
405 {
406         float m_angle;
407 public:
408         PatchRotateTexture( float angle ) : m_angle( angle ){
409         }
410         void operator()( Patch& patch ) const {
411                 patch.RotateTexture( m_angle );
412         }
413 };
414
415 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
416         Scene_forEachVisibleSelectedPatch( PatchRotateTexture( angle ) );
417 }
418
419 class PatchScaleTexture
420 {
421 float m_s, m_t;
422 public:
423 PatchScaleTexture( float s, float t ) : m_s( s ), m_t( t ){
424 }
425 void operator()( Patch& patch ) const {
426         patch.ScaleTexture( m_s, m_t );
427 }
428 };
429
430 float Patch_convertScale( float scale ){
431         if ( scale > 0 ) {
432                 return scale;
433         }
434         if ( scale < 0 ) {
435                 return -1 / scale;
436         }
437         return 1;
438 }
439
440 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
441         Scene_forEachVisibleSelectedPatch( PatchScaleTexture( Patch_convertScale( s ), Patch_convertScale( t ) ) );
442 }
443
444 class PatchTranslateTexture
445 {
446 float m_s, m_t;
447 public:
448 PatchTranslateTexture( float s, float t )
449         : m_s( s ), m_t( t ){
450 }
451 void operator()( Patch& patch ) const {
452         patch.TranslateTexture( m_s, m_t );
453 }
454 };
455
456 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
457         Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) );
458 }
459
460 static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){
461         texdef_t td;
462
463         td.rotate = 0;
464         td.scale[0] = td.scale[1] = 0;
465         td.shift[0] = td.shift[1] = 0;
466
467         if ( adj->value == 0 ) {
468                 return;
469         }
470
471         if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hshift_adj" ) ) {
472                 g_pi_globals.shift[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
473
474                 if ( adj->value > 0 ) {
475                         td.shift[0] = g_pi_globals.shift[0];
476                 }
477                 else{
478                         td.shift[0] = -g_pi_globals.shift[0];
479                 }
480         }
481         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vshift_adj" ) ) {
482                 g_pi_globals.shift[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
483
484                 if ( adj->value > 0 ) {
485                         td.shift[1] = g_pi_globals.shift[1];
486                 }
487                 else{
488                         td.shift[1] = -g_pi_globals.shift[1];
489                 }
490         }
491         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hscale_adj" ) ) {
492                 g_pi_globals.scale[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
493                 if ( g_pi_globals.scale[0] == 0.0f ) {
494                         return;
495                 }
496                 if ( adj->value > 0 ) {
497                         td.scale[0] = g_pi_globals.scale[0];
498                 }
499                 else{
500                         td.scale[0] = -g_pi_globals.scale[0];
501                 }
502         }
503         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vscale_adj" ) ) {
504                 g_pi_globals.scale[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
505                 if ( g_pi_globals.scale[1] == 0.0f ) {
506                         return;
507                 }
508                 if ( adj->value > 0 ) {
509                         td.scale[1] = g_pi_globals.scale[1];
510                 }
511                 else{
512                         td.scale[1] = -g_pi_globals.scale[1];
513                 }
514         }
515         else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "rotate_adj" ) ) {
516                 g_pi_globals.rotate = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
517
518                 if ( adj->value > 0 ) {
519                         td.rotate = g_pi_globals.rotate;
520                 }
521                 else{
522                         td.rotate = -g_pi_globals.rotate;
523                 }
524         }
525
526         adj->value = 0;
527
528         // will scale shift rotate the patch accordingly
529
530
531         if ( td.shift[0] || td.shift[1] ) {
532                 UndoableCommand command( "patchTranslateTexture" );
533                 Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), td.shift[0], td.shift[1] );
534         }
535         else if ( td.scale[0] || td.scale[1] ) {
536                 UndoableCommand command( "patchScaleTexture" );
537                 Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), td.scale[0], td.scale[1] );
538         }
539         else if ( td.rotate ) {
540                 UndoableCommand command( "patchRotateTexture" );
541                 Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), td.rotate );
542         }
543
544         // update the point-by-point view
545         OnSelchangeComboColRow( 0,0 );
546 }
547
548 static gint OnDialogKey( GtkWidget* widget, GdkEventKey* event, gpointer data ){
549         if ( event->keyval == GDK_Return ) {
550                 OnApply( 0, 0 );
551                 return TRUE;
552         }
553         else if ( event->keyval == GDK_Escape ) {
554                 g_PatchInspector.GetPatchInfo();
555                 return TRUE;
556         }
557         return FALSE;
558 }
559
560 // =============================================================================
561 // PatchInspector class
562
563 GtkWindow* PatchInspector::BuildDialog(){
564         GtkWindow* window = create_floating_window( "Patch Properties", m_parent );
565
566         m_position_tracker.connect( window );
567
568         global_accel_connect_window( window );
569
570         window_connect_focus_in_clear_focus_widget( window );
571
572
573         {
574                 GtkVBox* vbox = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
575                 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
576                 gtk_widget_show( GTK_WIDGET( vbox ) );
577                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) );
578                 {
579                         GtkHBox* hbox = GTK_HBOX( gtk_hbox_new( FALSE, 5 ) );
580                         gtk_widget_show( GTK_WIDGET( hbox ) );
581                         gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), TRUE, TRUE, 0 );
582                         {
583                                 GtkVBox* vbox2 = GTK_VBOX( gtk_vbox_new( FALSE, 0 ) );
584                                 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 0 );
585                                 gtk_widget_show( GTK_WIDGET( vbox2 ) );
586                                 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox2 ), TRUE, TRUE, 0 );
587                                 {
588                                         GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Details" ) );
589                                         gtk_widget_show( GTK_WIDGET( frame ) );
590                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
591                                         {
592                                                 GtkVBox* vbox3 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
593                                                 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
594                                                 gtk_widget_show( GTK_WIDGET( vbox3 ) );
595                                                 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox3 ) );
596                                                 {
597                                                         GtkTable* table = GTK_TABLE( gtk_table_new( 2, 2, FALSE ) );
598                                                         gtk_widget_show( GTK_WIDGET( table ) );
599                                                         gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
600                                                         gtk_table_set_row_spacings( table, 5 );
601                                                         gtk_table_set_col_spacings( table, 5 );
602                                                         {
603                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Row:" ) );
604                                                                 gtk_widget_show( GTK_WIDGET( label ) );
605                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
606                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
607                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
608                                                         }
609                                                         {
610                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Column:" ) );
611                                                                 gtk_widget_show( GTK_WIDGET( label ) );
612                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 0, 1,
613                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
614                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
615                                                         }
616                                                         {
617                                                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
618                                                                 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
619                                                                 AddDialogData( *combo, m_nRow );
620
621                                                                 gtk_widget_show( GTK_WIDGET( combo ) );
622                                                                 gtk_table_attach( table, GTK_WIDGET( combo ), 0, 1, 1, 2,
623                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
624                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
625                                                                 gtk_widget_set_usize( GTK_WIDGET( combo ), 60, -1 );
626                                                                 m_pRowCombo = combo;
627                                                         }
628
629                                                         {
630                                                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
631                                                                 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
632                                                                 AddDialogData( *combo, m_nCol );
633
634                                                                 gtk_widget_show( GTK_WIDGET( combo ) );
635                                                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
636                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
637                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
638                                                                 gtk_widget_set_usize( GTK_WIDGET( combo ), 60, -1 );
639                                                                 m_pColCombo = combo;
640                                                         }
641                                                 }
642                                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
643                                                 gtk_widget_show( GTK_WIDGET( table ) );
644                                                 gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
645                                                 gtk_table_set_row_spacings( table, 5 );
646                                                 gtk_table_set_col_spacings( table, 5 );
647                                                 {
648                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "X:" ) );
649                                                         gtk_widget_show( GTK_WIDGET( label ) );
650                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
651                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
652                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
653                                                 }
654                                                 {
655                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Y:" ) );
656                                                         gtk_widget_show( GTK_WIDGET( label ) );
657                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
658                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
659                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
660                                                 }
661                                                 {
662                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Z:" ) );
663                                                         gtk_widget_show( GTK_WIDGET( label ) );
664                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
665                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
666                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
667                                                 }
668                                                 {
669                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "S:" ) );
670                                                         gtk_widget_show( GTK_WIDGET( label ) );
671                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 3, 4,
672                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
673                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
674                                                 }
675                                                 {
676                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "T:" ) );
677                                                         gtk_widget_show( GTK_WIDGET( label ) );
678                                                         gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 4, 5,
679                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
680                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
681                                                 }
682                                                 {
683                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
684                                                         gtk_widget_show( GTK_WIDGET( entry ) );
685                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
686                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
687                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
688                                                         AddDialogData( *entry, m_fX );
689
690                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
691                                                 }
692                                                 {
693                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
694                                                         gtk_widget_show( GTK_WIDGET( entry ) );
695                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
696                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
697                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
698                                                         AddDialogData( *entry, m_fY );
699
700                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
701                                                 }
702                                                 {
703                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
704                                                         gtk_widget_show( GTK_WIDGET( entry ) );
705                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
706                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
707                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
708                                                         AddDialogData( *entry, m_fZ );
709
710                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
711                                                 }
712                                                 {
713                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
714                                                         gtk_widget_show( GTK_WIDGET( entry ) );
715                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 3, 4,
716                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
717                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
718                                                         AddDialogData( *entry, m_fS );
719
720                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
721                                                 }
722                                                 {
723                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
724                                                         gtk_widget_show( GTK_WIDGET( entry ) );
725                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 4, 5,
726                                                                                           (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
727                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
728                                                         AddDialogData( *entry, m_fT );
729
730                                                         g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
731                                                 }
732                                         }
733                                 }
734                                 if ( g_pGameDescription->mGameType == "doom3" ) {
735                                         GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Tesselation" ) );
736                                         gtk_widget_show( GTK_WIDGET( frame ) );
737                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
738                                         {
739                                                 GtkVBox* vbox3 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
740                                                 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
741                                                 gtk_widget_show( GTK_WIDGET( vbox3 ) );
742                                                 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox3 ) );
743                                                 {
744                                                         GtkTable* table = GTK_TABLE( gtk_table_new( 3, 2, FALSE ) );
745                                                         gtk_widget_show( GTK_WIDGET( table ) );
746                                                         gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
747                                                         gtk_table_set_row_spacings( table, 5 );
748                                                         gtk_table_set_col_spacings( table, 5 );
749                                                         {
750                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Fixed" ) );
751                                                                 gtk_widget_show( GTK_WIDGET( label ) );
752                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
753                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
754                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
755                                                         }
756                                                         {
757                                                                 GtkCheckButton* check = GTK_CHECK_BUTTON( gtk_check_button_new() );
758                                                                 gtk_widget_show( GTK_WIDGET( check ) );
759                                                                 gtk_table_attach( table, GTK_WIDGET( check ), 1, 2, 0, 1,
760                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
761                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
762                                                                 m_subdivisions.m_enabled = check;
763                                                                 guint handler_id = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( &Subdivisions::applyGtk ), &m_subdivisions );
764                                                                 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) );
765                                                         }
766                                                         {
767                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal" ) );
768                                                                 gtk_widget_show( GTK_WIDGET( label ) );
769                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
770                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
771                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
772                                                         }
773                                                         {
774                                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
775                                                                 gtk_widget_show( GTK_WIDGET( entry ) );
776                                                                 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
777                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
778                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
779                                                                 m_subdivisions.m_horizontal = entry;
780                                                                 m_horizontalSubdivisionsEntry.connect( entry );
781                                                         }
782                                                         {
783                                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical" ) );
784                                                                 gtk_widget_show( GTK_WIDGET( label ) );
785                                                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
786                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
787                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
788                                                         }
789                                                         {
790                                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
791                                                                 gtk_widget_show( GTK_WIDGET( entry ) );
792                                                                 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
793                                                                                                   (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
794                                                                                                   (GtkAttachOptions)( 0 ), 0, 0 );
795                                                                 m_subdivisions.m_vertical = entry;
796                                                                 m_verticalSubdivisionsEntry.connect( entry );
797                                                         }
798                                                 }
799                                         }
800                                 }
801                         }
802                         {
803                                 GtkFrame* frame = GTK_FRAME( gtk_frame_new( "Texturing" ) );
804                                 gtk_widget_show( GTK_WIDGET( frame ) );
805                                 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
806                                 {
807                                         GtkVBox* vbox2 = GTK_VBOX( gtk_vbox_new( FALSE, 5 ) );
808                                         gtk_widget_show( GTK_WIDGET( vbox2 ) );
809                                         gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( vbox2 ) );
810                                         gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
811                                         {
812                                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Name:" ) );
813                                                 gtk_widget_show( GTK_WIDGET( label ) );
814                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( label ), TRUE, TRUE, 0 );
815                                                 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
816                                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
817                                         }
818                                         {
819                                                 GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
820                                                 //  gtk_entry_set_editable (GTK_ENTRY (entry), false);
821                                                 gtk_widget_show( GTK_WIDGET( entry ) );
822                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
823                                                 AddDialogData( *entry, m_strName );
824
825                                                 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
826                                         }
827                                         {
828                                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 3, FALSE ) );
829                                                 gtk_widget_show( GTK_WIDGET( table ) );
830                                                 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
831                                                 gtk_table_set_row_spacings( table, 5 );
832                                                 gtk_table_set_col_spacings( table, 5 );
833                                                 {
834                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal Shift Step" ) );
835                                                         gtk_widget_show( GTK_WIDGET( label ) );
836                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 0, 1,
837                                                                                           (GtkAttachOptions)( GTK_FILL ),
838                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
839                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
840                                                 }
841                                                 {
842                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical Shift Step" ) );
843                                                         gtk_widget_show( GTK_WIDGET( label ) );
844                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 1, 2,
845                                                                                           (GtkAttachOptions)( GTK_FILL ),
846                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
847                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
848                                                 }
849                                                 {
850                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Horizontal Stretch Step" ) );
851                                                         gtk_widget_show( GTK_WIDGET( label ) );
852                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 2, 3,
853                                                                                           (GtkAttachOptions)( GTK_FILL ),
854                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
855                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
856                                                 }
857                                                 {
858                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Vertical Stretch Step" ) );
859                                                         gtk_widget_show( GTK_WIDGET( label ) );
860                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 3, 4,
861                                                                                           (GtkAttachOptions)( GTK_FILL ),
862                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
863                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
864                                                 }
865                                                 {
866                                                         GtkLabel* label = GTK_LABEL( gtk_label_new( "Rotate Step" ) );
867                                                         gtk_widget_show( GTK_WIDGET( label ) );
868                                                         gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 4, 5,
869                                                                                           (GtkAttachOptions)( GTK_FILL ),
870                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
871                                                         gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
872                                                 }
873                                                 {
874                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
875                                                         gtk_widget_show( GTK_WIDGET( entry ) );
876                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 0, 1,
877                                                                                           (GtkAttachOptions)( GTK_FILL ),
878                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
879                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
880                                                         g_object_set_data( G_OBJECT( window ), "hshift_entry", entry );
881                                                         // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
882                                                         // so we need to have at least one initialisation somewhere
883                                                         entry_set_float( entry, g_pi_globals.shift[0] );
884
885                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ) );
886                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
887                                                         g_object_set_data( G_OBJECT( window ), "hshift_adj", adj );
888
889                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
890                                                         gtk_widget_show( GTK_WIDGET( spin ) );
891                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 0, 1,
892                                                                                           (GtkAttachOptions)( 0 ),
893                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
894                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
895                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
896                                                 }
897                                                 {
898                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
899                                                         gtk_widget_show( GTK_WIDGET( entry ) );
900                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 1, 2,
901                                                                                           (GtkAttachOptions)( GTK_FILL ),
902                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
903                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
904                                                         entry_set_float( entry, g_pi_globals.shift[1] );
905
906                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -8192, 8192, 1, 1, 0 ) );
907                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
908                                                         g_object_set_data( G_OBJECT( window ), "vshift_adj", adj );
909
910                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
911                                                         gtk_widget_show( GTK_WIDGET( spin ) );
912                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 1, 2,
913                                                                                           (GtkAttachOptions)( 0 ),
914                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
915                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
916                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
917                                                 }
918                                                 {
919                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
920                                                         gtk_widget_show( GTK_WIDGET( entry ) );
921                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 2, 3,
922                                                                                           (GtkAttachOptions)( GTK_FILL ),
923                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
924                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
925                                                         entry_set_float( entry, g_pi_globals.scale[0] );
926
927                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ) );
928                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
929                                                         g_object_set_data( G_OBJECT( window ), "hscale_adj", adj );
930
931                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
932                                                         gtk_widget_show( GTK_WIDGET( spin ) );
933                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 2, 3,
934                                                                                           (GtkAttachOptions)( 0 ),
935                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
936                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
937                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
938                                                 }
939                                                 {
940                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
941                                                         gtk_widget_show( GTK_WIDGET( entry ) );
942                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 3, 4,
943                                                                                           (GtkAttachOptions)( GTK_FILL ),
944                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
945                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
946                                                         entry_set_float( entry, g_pi_globals.scale[1] );
947
948                                                         GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0, -1000, 1000, 1, 1, 0 ) );
949                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
950                                                         g_object_set_data( G_OBJECT( window ), "vscale_adj", adj );
951
952                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
953                                                         gtk_widget_show( GTK_WIDGET( spin ) );
954                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 3, 4,
955                                                                                           (GtkAttachOptions)( 0 ),
956                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
957                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
958                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
959                                                 }
960                                                 {
961                                                         GtkEntry* entry = GTK_ENTRY( gtk_entry_new() );
962                                                         gtk_widget_show( GTK_WIDGET( entry ) );
963                                                         gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 4, 5,
964                                                                                           (GtkAttachOptions)( GTK_FILL ),
965                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
966                                                         gtk_widget_set_usize( GTK_WIDGET( entry ), 50, -2 );
967                                                         entry_set_float( entry, g_pi_globals.rotate );
968
969                                                         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
970                                                         g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
971                                                         g_object_set_data( G_OBJECT( window ), "rotate_adj", adj );
972
973                                                         GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
974                                                         gtk_widget_show( GTK_WIDGET( spin ) );
975                                                         gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 4, 5,
976                                                                                           (GtkAttachOptions)( 0 ),
977                                                                                           (GtkAttachOptions)( 0 ), 0, 0 );
978                                                         gtk_widget_set_usize( GTK_WIDGET( spin ), 10, -2 );
979                                                         GTK_WIDGET_UNSET_FLAGS( spin, GTK_CAN_FOCUS );
980                                                 }
981                                         }
982                                         GtkHBox* hbox2 = GTK_HBOX( gtk_hbox_new( TRUE, 5 ) );
983                                         gtk_widget_show( GTK_WIDGET( hbox2 ) );
984                                         gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox2 ), TRUE, FALSE, 0 );
985                                         {
986                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "CAP" ) );
987                                                 gtk_widget_show( GTK_WIDGET( button ) );
988                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
989                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
990                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
991                                         }
992                                         {
993                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Set..." ) );
994                                                 gtk_widget_show( GTK_WIDGET( button ) );
995                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
996                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
997                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
998                                         }
999                                         {
1000                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Natural" ) );
1001                                                 gtk_widget_show( GTK_WIDGET( button ) );
1002                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1003                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
1004                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1005                                         }
1006                                         {
1007                                                 GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Fit" ) );
1008                                                 gtk_widget_show( GTK_WIDGET( button ) );
1009                                                 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1010                                                 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
1011                                                 gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 );
1012                                         }
1013                                 }
1014                         }
1015                 }
1016         }
1017
1018         return window;
1019 }
1020
1021 // sync the dialog our internal data structures
1022 void PatchInspector::exportData(){
1023         m_bListenChanged = false;
1024         Dialog::exportData();
1025         m_bListenChanged = true;
1026 }
1027 void PatchInspector::importData(){
1028         m_bListenChanged = false;
1029         Dialog::importData();
1030         m_bListenChanged = true;
1031 }
1032
1033 // read the map and feed in the stuff to the dialog box
1034 void PatchInspector::GetPatchInfo(){
1035         if ( g_pGameDescription->mGameType == "doom3" ) {
1036                 m_subdivisions.update();
1037         }
1038
1039         if ( GlobalSelectionSystem().countSelected() == 0 ) {
1040                 m_Patch = 0;
1041         }
1042         else
1043         {
1044                 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
1045         }
1046
1047         if ( m_Patch != 0 ) {
1048                 m_strName = m_Patch->GetShader();
1049
1050                 // fill in the numbers for Row / Col selection
1051                 m_bListenChanged = false;
1052
1053                 {
1054                         gtk_combo_box_set_active( m_pRowCombo, 0 );
1055
1056                         for ( std::size_t i = 0; i < m_countRows; ++i )
1057                         {
1058                                 gtk_combo_box_remove_text( m_pRowCombo, gint( m_countRows - i - 1 ) );
1059                         }
1060
1061                         m_countRows = m_Patch->getHeight();
1062                         for ( std::size_t i = 0; i < m_countRows; ++i )
1063                         {
1064                                 char buffer[16];
1065                                 sprintf( buffer, "%u", Unsigned( i ) );
1066                                 gtk_combo_box_append_text( m_pRowCombo, buffer );
1067                         }
1068
1069                         gtk_combo_box_set_active( m_pRowCombo, 0 );
1070                 }
1071
1072                 {
1073                         gtk_combo_box_set_active( m_pColCombo, 0 );
1074
1075                         for ( std::size_t i = 0; i < m_countCols; ++i )
1076                         {
1077                                 gtk_combo_box_remove_text( m_pColCombo, gint( m_countCols - i - 1 ) );
1078                         }
1079
1080                         m_countCols = m_Patch->getWidth();
1081                         for ( std::size_t i = 0; i < m_countCols; ++i )
1082                         {
1083                                 char buffer[16];
1084                                 sprintf( buffer, "%u", Unsigned( i ) );
1085                                 gtk_combo_box_append_text( m_pColCombo, buffer );
1086                         }
1087
1088                         gtk_combo_box_set_active( m_pColCombo, 0 );
1089                 }
1090
1091                 m_bListenChanged = true;
1092
1093         }
1094         else
1095         {
1096                 //globalOutputStream() << "WARNING: no patch\n";
1097         }
1098         // fill in our internal structs
1099         m_nRow = 0; m_nCol = 0;
1100         UpdateRowColInfo();
1101         // now update the dialog box
1102         importData();
1103 }
1104
1105 // read the current patch on map and initialize m_fX m_fY accordingly
1106 // NOTE: don't call UpdateData in there, it's not meant for
1107 void PatchInspector::UpdateRowColInfo(){
1108         m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
1109
1110         if ( m_Patch != 0 ) {
1111                 // we rely on whatever active row/column has been set before we get called
1112                 std::size_t r = m_nRow;
1113                 std::size_t c = m_nCol;
1114                 if ( r < m_Patch->getHeight()
1115                          && c < m_Patch->getWidth() ) {
1116                         const PatchControl& p = m_Patch->ctrlAt( r,c );
1117                         m_fX = p.m_vertex[0];
1118                         m_fY = p.m_vertex[1];
1119                         m_fZ = p.m_vertex[2];
1120                         m_fS = p.m_texcoord[0];
1121                         m_fT = p.m_texcoord[1];
1122                 }
1123         }
1124 }
1125
1126
1127 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1128         PatchInspector_queueDraw();
1129 }
1130
1131
1132 #include "preferencesystem.h"
1133
1134
1135 void PatchInspector_Construct(){
1136         GlobalCommands_insert( "PatchInspector", FreeCaller<PatchInspector_toggleShown>(), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
1137
1138         GlobalPreferenceSystem().registerPreference( "PatchWnd", WindowPositionTrackerImportStringCaller( g_PatchInspector.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_PatchInspector.m_position_tracker ) );
1139         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", FloatImportStringCaller( g_pi_globals.scale[0] ), FloatExportStringCaller( g_pi_globals.scale[0] ) );
1140         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", FloatImportStringCaller( g_pi_globals.scale[1] ), FloatExportStringCaller( g_pi_globals.scale[1] ) );
1141         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", FloatImportStringCaller( g_pi_globals.shift[0] ), FloatExportStringCaller( g_pi_globals.shift[0] ) );
1142         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", FloatImportStringCaller( g_pi_globals.shift[1] ), FloatExportStringCaller( g_pi_globals.shift[1] ) );
1143         GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", FloatImportStringCaller( g_pi_globals.rotate ), FloatExportStringCaller( g_pi_globals.rotate ) );
1144
1145         typedef FreeCaller1<const Selectable&, PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1146         GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1147         typedef FreeCaller<PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1148         Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1149 }
1150 void PatchInspector_Destroy(){
1151 }