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