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