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