2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
25 // Leonardo Zide (leo@lokigames.com)
28 #include "patchdialog.h"
34 #include "debugging/debugging.h"
36 #include "gtkutil/idledraw.h"
37 #include "gtkutil/entry.h"
38 #include "gtkutil/button.h"
39 #include "gtkutil/nonmodal.h"
42 #include "mainframe.h"
43 #include "patchmanip.h"
46 #include "preferences.h"
47 #include "signal/isignal.h"
50 #include <gdk/gdkkeysyms.h>
52 // the increment we are using for the patch inspector (this is saved in the prefs)
68 pi_globals_t g_pi_globals;
70 class PatchFixedSubdivisions
73 PatchFixedSubdivisions() : m_enabled( false ), m_x( 0 ), m_y( 0 ){
75 PatchFixedSubdivisions( bool enabled, std::size_t x, std::size_t y ) : m_enabled( enabled ), m_x( x ), m_y( y ){
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;
88 const std::size_t MAX_PATCH_SUBDIVISIONS = 32;
90 void Patch_setFixedSubdivisions( Patch& patch, const PatchFixedSubdivisions& subdivisions ){
93 patch.m_patchDef3 = subdivisions.m_enabled;
94 patch.m_subdivisions_x = subdivisions.m_x;
95 patch.m_subdivisions_y = subdivisions.m_y;
97 if ( patch.m_subdivisions_x == 0 ) {
98 patch.m_subdivisions_x = 4;
100 else if ( patch.m_subdivisions_x > MAX_PATCH_SUBDIVISIONS ) {
101 patch.m_subdivisions_x = MAX_PATCH_SUBDIVISIONS;
103 if ( patch.m_subdivisions_y == 0 ) {
104 patch.m_subdivisions_y = 4;
106 else if ( patch.m_subdivisions_y > MAX_PATCH_SUBDIVISIONS ) {
107 patch.m_subdivisions_y = MAX_PATCH_SUBDIVISIONS;
111 Patch_textureChanged();
112 patch.controlPointsChanged();
115 class PatchGetFixedSubdivisions
117 PatchFixedSubdivisions& m_subdivisions;
119 PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
121 void operator()( Patch& patch ){
122 Patch_getFixedSubdivisions( patch, m_subdivisions );
127 void Scene_PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ){
129 if ( GlobalSelectionSystem().countSelected() != 0 ) {
130 Patch* patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
132 Patch_getFixedSubdivisions( *patch, subdivisions );
136 Scene_forEachVisibleSelectedPatch( PatchGetFixedSubdivisions( subdivisions ) );
140 class PatchSetFixedSubdivisions
142 const PatchFixedSubdivisions& m_subdivisions;
144 PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
146 void operator()( Patch& patch ) const {
147 Patch_setFixedSubdivisions( patch, m_subdivisions );
151 void Scene_PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ){
152 UndoableCommand command( "patchSetFixedSubdivisions" );
153 Scene_forEachVisibleSelectedPatch( PatchSetFixedSubdivisions( subdivisions ) );
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 ){
166 PatchFixedSubdivisions subdivisions;
167 Scene_PatchGetFixedSubdivisions( subdivisions );
169 toggle_button_set_active_no_signal( m_enabled, subdivisions.m_enabled );
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 );
179 m_horizontal.text("");
181 gtk_widget_set_sensitive( m_horizontal , FALSE );
182 gtk_widget_set_sensitive( m_vertical , FALSE );
188 typedef MemberCaller<Subdivisions, &Subdivisions::cancel> CancelCaller;
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 ) )
198 typedef MemberCaller<Subdivisions, &Subdivisions::apply> ApplyCaller;
199 static void applyGtk( GtkToggleButton* toggle, Subdivisions* self ){
204 class PatchInspector : public Dialog
206 ui::Window BuildDialog();
207 Subdivisions m_subdivisions;
208 NonModalEntry m_horizontalSubdivisionsEntry;
209 NonModalEntry m_verticalSubdivisionsEntry;
212 WindowPositionTracker m_position_tracker;
216 CopiedString m_strName;
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;
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;
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 ) ){
253 m_bListenChanged = true;
255 m_position_tracker.setPosition( c_default_window_pos );
259 return GetWidget().visible();
262 // void UpdateInfo();
263 // void SetPatchInfo();
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)
276 PatchInspector g_PatchInspector;
278 void PatchInspector_constructWindow( ui::Window main_window ){
279 g_PatchInspector.m_parent = main_window;
280 g_PatchInspector.Create();
282 void PatchInspector_destroyWindow(){
283 g_PatchInspector.Destroy();
286 void PatchInspector_queueDraw(){
287 if ( g_PatchInspector.visible() ) {
288 g_PatchInspector.m_idleDraw.queueDraw();
292 void DoPatchInspector(){
293 g_PatchInspector.GetPatchInfo();
294 if ( !g_PatchInspector.visible() ) {
295 g_PatchInspector.ShowDlg();
299 void PatchInspector_toggleShown(){
300 if ( g_PatchInspector.visible() ) {
301 g_PatchInspector.m_Patch = 0;
302 g_PatchInspector.HideDlg();
310 // =============================================================================
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();
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();
324 g_PatchInspector.m_Patch->SetShader( g_PatchInspector.m_strName.c_str() );
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();
341 static void OnSelchangeComboColRow( ui::Widget widget, gpointer data ){
342 if ( !g_PatchInspector.m_bListenChanged ) {
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();
353 class PatchSetTextureRepeat
357 PatchSetTextureRepeat( float s, float t ) : m_s( s ), m_t( t ){
359 void operator()( Patch& patch ) const {
360 patch.SetTextureRepeat( m_s, m_t );
364 void Scene_PatchTileTexture_Selected( scene::Graph& graph, float s, float t ){
365 Scene_forEachVisibleSelectedPatch( PatchSetTextureRepeat( s, t ) );
369 static void OnBtnPatchdetails( ui::Widget widget, gpointer data ){
373 static void OnBtnPatchfit( ui::Widget widget, gpointer data ){
377 static void OnBtnPatchnatural( ui::Widget widget, gpointer data ){
378 Patch_NaturalTexture();
381 static void OnBtnPatchreset( ui::Widget widget, gpointer data ){
382 Patch_ResetTexture();
385 static void OnBtnPatchFlipX( ui::Widget widget, gpointer data ){
386 Patch_FlipTextureX();
389 static void OnBtnPatchFlipY( ui::Widget widget, gpointer data ){
390 Patch_FlipTextureY();
393 struct PatchRotateTexture
397 PatchRotateTexture( float angle ) : m_angle( angle ){
399 void operator()( Patch& patch ) const {
400 patch.RotateTexture( m_angle );
404 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
405 Scene_forEachVisibleSelectedPatch( PatchRotateTexture( angle ) );
408 class PatchScaleTexture
412 PatchScaleTexture( float s, float t ) : m_s( s ), m_t( t ){
414 void operator()( Patch& patch ) const {
415 patch.ScaleTexture( m_s, m_t );
419 float Patch_convertScale( float scale ){
429 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
430 Scene_forEachVisibleSelectedPatch( PatchScaleTexture( Patch_convertScale( s ), Patch_convertScale( t ) ) );
433 class PatchTranslateTexture
437 PatchTranslateTexture( float s, float t )
438 : m_s( s ), m_t( t ){
440 void operator()( Patch& patch ) const {
441 patch.TranslateTexture( m_s, m_t );
445 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
446 Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) );
449 static void OnBtnPatchAutoCap( ui::Widget widget, gpointer data ){
450 Patch_AutoCapTexture();
453 static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){
457 td.scale[0] = td.scale[1] = 0;
458 td.shift[0] = td.shift[1] = 0;
460 if ( gtk_adjustment_get_value(adj) == 0 ) {
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 ) ) ) );
467 if ( gtk_adjustment_get_value(adj) > 0 ) {
468 td.shift[0] = g_pi_globals.shift[0];
471 td.shift[0] = -g_pi_globals.shift[0];
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 ) ) ) );
477 if ( gtk_adjustment_get_value(adj) > 0 ) {
478 td.shift[1] = g_pi_globals.shift[1];
481 td.shift[1] = -g_pi_globals.shift[1];
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 ) {
489 if ( gtk_adjustment_get_value(adj) > 0 ) {
490 td.scale[0] = g_pi_globals.scale[0];
493 td.scale[0] = -g_pi_globals.scale[0];
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 ) {
501 if ( gtk_adjustment_get_value(adj) > 0 ) {
502 td.scale[1] = g_pi_globals.scale[1];
505 td.scale[1] = -g_pi_globals.scale[1];
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 ) ) ) );
511 if ( gtk_adjustment_get_value(adj) > 0 ) {
512 td.rotate = g_pi_globals.rotate;
515 td.rotate = -g_pi_globals.rotate;
519 gtk_adjustment_set_value(adj, 0);
521 // will scale shift rotate the patch accordingly
524 if ( td.shift[0] || td.shift[1] ) {
525 UndoableCommand command( "patchTranslateTexture" );
526 Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), td.shift[0], td.shift[1] );
528 else if ( td.scale[0] || td.scale[1] ) {
529 UndoableCommand command( "patchScaleTexture" );
530 Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), td.scale[0], td.scale[1] );
532 else if ( td.rotate ) {
533 UndoableCommand command( "patchRotateTexture" );
534 Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), td.rotate );
537 // update the point-by-point view
538 OnSelchangeComboColRow( ui::root ,0 );
541 static gint OnDialogKey( ui::Widget widget, GdkEventKey* event, gpointer data ){
542 if ( event->keyval == GDK_KEY_Return ) {
543 OnApply( ui::root, 0 );
546 else if ( event->keyval == GDK_KEY_Escape ) {
547 g_PatchInspector.GetPatchInfo();
553 // =============================================================================
554 // PatchInspector class
556 ui::Window PatchInspector::BuildDialog(){
557 ui::Window window = ui::Window(create_floating_window( "Patch Properties", m_parent ));
559 m_position_tracker.connect( window );
561 global_accel_connect_window( window );
563 window_connect_focus_in_clear_focus_widget( window );
567 auto vbox = ui::VBox( FALSE, 5 );
568 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
572 auto hbox = ui::HBox( FALSE, 5 );
574 vbox.pack_start( hbox, TRUE, TRUE, 0 );
576 auto vbox2 = ui::VBox( FALSE, 0 );
577 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 0 );
579 hbox.pack_start( vbox2, TRUE, TRUE, 0 );
581 auto frame = ui::Frame( "Details" );
583 vbox2.pack_start( frame, TRUE, TRUE, 0 );
585 auto vbox3 = ui::VBox( FALSE, 5 );
586 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
590 auto table = ui::Table( 2, 2, FALSE );
592 vbox3.pack_start( table, TRUE, TRUE, 0 );
593 gtk_table_set_row_spacings( table, 5 );
594 gtk_table_set_col_spacings( table, 5 );
596 auto label = ui::Label( "Row:" );
598 table.attach(label, {0, 1, 0, 1}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
601 auto label = ui::Label( "Column:" );
603 table.attach(label, {1, 2, 0, 1}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
606 auto combo = ui::ComboBoxText(ui::New);
607 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
608 AddDialogData( *GTK_COMBO_BOX(combo), m_nRow );
611 table.attach(combo, {0, 1, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
612 gtk_widget_set_size_request( combo , 60, -1 );
617 auto combo = ui::ComboBoxText(ui::New);
618 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
619 AddDialogData( *GTK_COMBO_BOX(combo), m_nCol );
622 table.attach(combo, {1, 2, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
623 gtk_widget_set_size_request( combo , 60, -1 );
627 auto table = ui::Table( 5, 2, FALSE );
629 vbox3.pack_start( table, TRUE, TRUE, 0 );
630 gtk_table_set_row_spacings( table, 5 );
631 gtk_table_set_col_spacings( table, 5 );
633 auto label = ui::Label( "X:" );
635 table.attach(label, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
638 auto label = ui::Label( "Y:" );
640 table.attach(label, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
643 auto label = ui::Label( "Z:" );
645 table.attach(label, {0, 1, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
648 auto label = ui::Label( "S:" );
650 table.attach(label, {0, 1, 3, 4}, {GTK_EXPAND | GTK_FILL, 0});
653 auto label = ui::Label( "T:" );
655 table.attach(label, {0, 1, 4, 5}, {GTK_EXPAND | GTK_FILL, 0});
658 auto entry = ui::Entry(ui::New);
660 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
661 AddDialogData( *GTK_ENTRY(entry), m_fX );
663 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
666 auto entry = ui::Entry(ui::New);
668 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
669 AddDialogData( *GTK_ENTRY(entry), m_fY );
671 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
674 auto entry = ui::Entry(ui::New);
676 table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
677 AddDialogData( *GTK_ENTRY(entry), m_fZ );
679 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
682 auto entry = ui::Entry(ui::New);
684 table.attach(entry, {1, 2, 3, 4}, {GTK_EXPAND | GTK_FILL, 0});
685 AddDialogData( *GTK_ENTRY(entry), m_fS );
687 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
690 auto entry = ui::Entry(ui::New);
692 table.attach(entry, {1, 2, 4, 5}, {GTK_EXPAND | GTK_FILL, 0});
693 AddDialogData( *GTK_ENTRY(entry), m_fT );
695 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
699 if ( g_pGameDescription->mGameType == "doom3" ) {
700 auto frame = ui::Frame( "Tesselation" );
702 vbox2.pack_start( frame, TRUE, TRUE, 0 );
704 auto vbox3 = ui::VBox( FALSE, 5 );
705 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
709 auto table = ui::Table( 3, 2, FALSE );
711 vbox3.pack_start( table, TRUE, TRUE, 0 );
712 gtk_table_set_row_spacings( table, 5 );
713 gtk_table_set_col_spacings( table, 5 );
715 auto label = ui::Label( "Fixed" );
717 table.attach(label, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
720 auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() ));
722 table.attach(check, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
723 m_subdivisions.m_enabled = check;
724 guint handler_id = check.connect( "toggled", G_CALLBACK( &Subdivisions::applyGtk ), &m_subdivisions );
725 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) );
728 auto label = ui::Label( "Horizontal" );
730 table.attach(label, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
733 auto entry = ui::Entry(ui::New);
735 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
736 m_subdivisions.m_horizontal = entry;
737 m_horizontalSubdivisionsEntry.connect( entry );
740 auto label = ui::Label( "Vertical" );
742 table.attach(label, {0, 1, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
745 auto entry = ui::Entry(ui::New);
747 table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
748 m_subdivisions.m_vertical = entry;
749 m_verticalSubdivisionsEntry.connect( entry );
756 auto frame = ui::Frame( "Texturing" );
758 hbox.pack_start( frame, TRUE, TRUE, 0 );
760 auto vbox2 = ui::VBox( FALSE, 5 );
763 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
765 auto label = ui::Label( "Name:" );
767 vbox2.pack_start( label, TRUE, TRUE, 0 );
768 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
769 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
772 auto entry = ui::Entry(ui::New);
773 // gtk_editable_set_editable (GTK_ENTRY (entry), false);
775 vbox2.pack_start( entry, TRUE, TRUE, 0 );
776 AddDialogData( *GTK_ENTRY(entry), m_strName );
778 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
781 auto table = ui::Table( 5, 4, FALSE );
783 vbox2.pack_start( table, TRUE, TRUE, 0 );
784 gtk_table_set_row_spacings( table, 5 );
785 gtk_table_set_col_spacings( table, 5 );
787 auto label = ui::Label( "Horizontal Shift Step" );
789 table.attach(label, {2, 4, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
790 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
793 auto label = ui::Label( "Vertical Shift Step" );
795 table.attach(label, {2, 4, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
796 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
799 auto label = ui::Label( "Horizontal Stretch Step" );
801 table.attach(label, {2, 3, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
802 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
805 auto button = ui::Button( "Flip" );
807 table.attach(button, {3, 4, 2, 3}, {GTK_FILL, 0});
808 button.connect( "clicked", G_CALLBACK( OnBtnPatchFlipX ), 0 );
809 gtk_widget_set_size_request( button , 60, -1 );
812 auto label = ui::Label( "Vertical Stretch Step" );
814 table.attach(label, {2, 3, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
815 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
818 auto button = ui::Button( "Flip" );
820 table.attach(button, {3, 4, 3, 4}, {GTK_FILL, 0});
821 button.connect( "clicked", G_CALLBACK( OnBtnPatchFlipY ), 0 );
822 gtk_widget_set_size_request( button , 60, -1 );
825 auto label = ui::Label( "Rotate Step" );
827 table.attach(label, {2, 4, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
828 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
831 auto entry = ui::Entry(ui::New);
833 table.attach(entry, {0, 1, 0, 1}, {GTK_FILL, 0});
834 gtk_widget_set_size_request( entry , 50, -1 );
835 g_object_set_data( G_OBJECT( window ), "hshift_entry", (void *) entry );
836 // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
837 // so we need to have at least one initialisation somewhere
838 entry_set_float( entry, g_pi_globals.shift[0] );
840 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
841 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), (gpointer) entry );
842 g_object_set_data( G_OBJECT( window ), "hshift_adj", (gpointer) adj );
844 auto spin = ui::SpinButton( adj, 1, 0 );
846 table.attach(spin, {1, 2, 0, 1}, {0, 0});
847 gtk_widget_set_size_request( spin , 10, -1 );
848 gtk_widget_set_can_focus( spin, false );
851 auto entry = ui::Entry(ui::New);
853 table.attach(entry, {0, 1, 1, 2}, {GTK_FILL, 0});
854 gtk_widget_set_size_request( entry , 50, -1 );
855 entry_set_float( entry, g_pi_globals.shift[1] );
857 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
858 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
859 g_object_set_data( G_OBJECT( window ), "vshift_adj", (gpointer) adj );
861 auto spin = ui::SpinButton( adj, 1, 0 );
863 table.attach(spin, {1, 2, 1, 2}, {0, 0});
864 gtk_widget_set_size_request( spin , 10, -1 );
865 gtk_widget_set_can_focus( spin, false );
868 auto entry = ui::Entry(ui::New);
870 table.attach(entry, {0, 1, 2, 3}, {GTK_FILL, 0});
871 gtk_widget_set_size_request( entry , 50, -1 );
872 entry_set_float( entry, g_pi_globals.scale[0] );
874 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
875 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
876 g_object_set_data( G_OBJECT( window ), "hscale_adj", (gpointer) adj );
878 auto spin = ui::SpinButton( adj, 1, 0 );
880 table.attach(spin, {1, 2, 2, 3}, {0, 0});
881 gtk_widget_set_size_request( spin , 10, -1 );
882 gtk_widget_set_can_focus( spin, false );
885 auto entry = ui::Entry(ui::New);
887 table.attach(entry, {0, 1, 3, 4}, {GTK_FILL, 0});
888 gtk_widget_set_size_request( entry , 50, -1 );
889 entry_set_float( entry, g_pi_globals.scale[1] );
891 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
892 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
893 g_object_set_data( G_OBJECT( window ), "vscale_adj", (gpointer) adj );
895 auto spin = ui::SpinButton( adj, 1, 0 );
897 table.attach(spin, {1, 2, 3, 4}, {0, 0});
898 gtk_widget_set_size_request( spin , 10, -1 );
899 gtk_widget_set_can_focus( spin, false );
902 auto entry = ui::Entry(ui::New);
904 table.attach(entry, {0, 1, 4, 5}, {GTK_FILL, 0});
905 gtk_widget_set_size_request( entry , 50, -1 );
906 entry_set_float( entry, g_pi_globals.rotate );
908 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
909 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
910 g_object_set_data( G_OBJECT( window ), "rotate_adj", (gpointer) adj );
912 auto spin = ui::SpinButton( adj, 1, 0 );
914 table.attach(spin, {1, 2, 4, 5}, {0, 0});
915 gtk_widget_set_size_request( spin , 10, -1 );
916 gtk_widget_set_can_focus( spin, false );
919 auto hbox2 = ui::HBox( TRUE, 5 );
921 vbox2.pack_start( hbox2, TRUE, FALSE, 0 );
923 auto button = ui::Button( "Auto Cap" );
925 hbox2.pack_end(button, TRUE, FALSE, 0);
926 button.connect( "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 );
927 gtk_widget_set_size_request( button , 60, -1 );
930 auto button = ui::Button( "CAP" );
932 hbox2.pack_end(button, TRUE, FALSE, 0);
933 button.connect( "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
934 gtk_widget_set_size_request( button , 60, -1 );
937 auto button = ui::Button( "Set..." );
939 hbox2.pack_end(button, TRUE, FALSE, 0);
940 button.connect( "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
941 gtk_widget_set_size_request( button , 60, -1 );
944 auto button = ui::Button( "Natural" );
946 hbox2.pack_end(button, TRUE, FALSE, 0);
947 button.connect( "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
948 gtk_widget_set_size_request( button , 60, -1 );
951 auto button = ui::Button( "Fit" );
953 hbox2.pack_end(button, TRUE, FALSE, 0);
954 button.connect( "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
955 gtk_widget_set_size_request( button , 60, -1 );
965 // sync the dialog our internal data structures
966 void PatchInspector::exportData(){
967 m_bListenChanged = false;
968 Dialog::exportData();
969 m_bListenChanged = true;
971 void PatchInspector::importData(){
972 m_bListenChanged = false;
973 Dialog::importData();
974 m_bListenChanged = true;
977 // read the map and feed in the stuff to the dialog box
978 void PatchInspector::GetPatchInfo(){
979 if ( g_pGameDescription->mGameType == "doom3" ) {
980 m_subdivisions.update();
983 if ( GlobalSelectionSystem().countSelected() == 0 ) {
988 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
991 if ( m_Patch != 0 ) {
992 m_strName = m_Patch->GetShader();
994 // fill in the numbers for Row / Col selection
995 m_bListenChanged = false;
998 gtk_combo_box_set_active( m_pRowCombo, 0 );
1000 for ( std::size_t i = 0; i < m_countRows; ++i )
1002 gtk_combo_box_text_remove( m_pRowCombo, gint( m_countRows - i - 1 ) );
1005 m_countRows = m_Patch->getHeight();
1006 for ( std::size_t i = 0; i < m_countRows; ++i )
1009 sprintf( buffer, "%u", Unsigned( i ) );
1010 gtk_combo_box_text_append_text( m_pRowCombo, buffer );
1013 gtk_combo_box_set_active( m_pRowCombo, 0 );
1017 gtk_combo_box_set_active( m_pColCombo, 0 );
1019 for ( std::size_t i = 0; i < m_countCols; ++i )
1021 gtk_combo_box_text_remove( m_pColCombo, gint( m_countCols - i - 1 ) );
1024 m_countCols = m_Patch->getWidth();
1025 for ( std::size_t i = 0; i < m_countCols; ++i )
1028 sprintf( buffer, "%u", Unsigned( i ) );
1029 gtk_combo_box_text_append_text( m_pColCombo, buffer );
1032 gtk_combo_box_set_active( m_pColCombo, 0 );
1035 m_bListenChanged = true;
1040 //globalOutputStream() << "WARNING: no patch\n";
1042 // fill in our internal structs
1043 m_nRow = 0; m_nCol = 0;
1045 // now update the dialog box
1049 // read the current patch on map and initialize m_fX m_fY accordingly
1050 // NOTE: don't call UpdateData in there, it's not meant for
1051 void PatchInspector::UpdateRowColInfo(){
1052 m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
1054 if ( m_Patch != 0 ) {
1055 // we rely on whatever active row/column has been set before we get called
1056 std::size_t r = m_nRow;
1057 std::size_t c = m_nCol;
1058 if ( r < m_Patch->getHeight()
1059 && c < m_Patch->getWidth() ) {
1060 const PatchControl& p = m_Patch->ctrlAt( r,c );
1061 m_fX = p.m_vertex[0];
1062 m_fY = p.m_vertex[1];
1063 m_fZ = p.m_vertex[2];
1064 m_fS = p.m_texcoord[0];
1065 m_fT = p.m_texcoord[1];
1071 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1072 PatchInspector_queueDraw();
1076 #include "preferencesystem.h"
1079 void PatchInspector_Construct(){
1080 GlobalCommands_insert( "PatchInspector", FreeCaller<PatchInspector_toggleShown>(), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
1082 GlobalPreferenceSystem().registerPreference( "PatchWnd", WindowPositionTrackerImportStringCaller( g_PatchInspector.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_PatchInspector.m_position_tracker ) );
1083 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", FloatImportStringCaller( g_pi_globals.scale[0] ), FloatExportStringCaller( g_pi_globals.scale[0] ) );
1084 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", FloatImportStringCaller( g_pi_globals.scale[1] ), FloatExportStringCaller( g_pi_globals.scale[1] ) );
1085 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", FloatImportStringCaller( g_pi_globals.shift[0] ), FloatExportStringCaller( g_pi_globals.shift[0] ) );
1086 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", FloatImportStringCaller( g_pi_globals.shift[1] ), FloatExportStringCaller( g_pi_globals.shift[1] ) );
1087 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", FloatImportStringCaller( g_pi_globals.rotate ), FloatExportStringCaller( g_pi_globals.rotate ) );
1089 typedef FreeCaller1<const Selectable&, PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1090 GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1091 typedef FreeCaller<PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1092 Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1094 void PatchInspector_Destroy(){