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( GTK_WIDGET( m_horizontal ), TRUE );
175 gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), TRUE );
179 m_horizontal.text("");
181 gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), FALSE );
182 gtk_widget_set_sensitive( GTK_WIDGET( 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 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
599 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
600 (GtkAttachOptions)( 0 ), 0, 0 );
603 auto label = ui::Label( "Column:" );
605 gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 0, 1,
606 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
607 (GtkAttachOptions)( 0 ), 0, 0 );
610 auto combo = ui::ComboBoxText(ui::New);
611 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
612 AddDialogData( *GTK_COMBO_BOX(combo), m_nRow );
615 gtk_table_attach( table, GTK_WIDGET( combo ), 0, 1, 1, 2,
616 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
617 (GtkAttachOptions)( 0 ), 0, 0 );
618 gtk_widget_set_size_request( GTK_WIDGET( combo ), 60, -1 );
623 auto combo = ui::ComboBoxText(ui::New);
624 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
625 AddDialogData( *GTK_COMBO_BOX(combo), m_nCol );
628 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
629 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
630 (GtkAttachOptions)( 0 ), 0, 0 );
631 gtk_widget_set_size_request( GTK_WIDGET( combo ), 60, -1 );
635 auto table = ui::Table( 5, 2, FALSE );
637 vbox3.pack_start( table, TRUE, TRUE, 0 );
638 gtk_table_set_row_spacings( table, 5 );
639 gtk_table_set_col_spacings( table, 5 );
641 auto label = ui::Label( "X:" );
643 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
644 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
645 (GtkAttachOptions)( 0 ), 0, 0 );
648 auto label = ui::Label( "Y:" );
650 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
651 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
652 (GtkAttachOptions)( 0 ), 0, 0 );
655 auto label = ui::Label( "Z:" );
657 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
658 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
659 (GtkAttachOptions)( 0 ), 0, 0 );
662 auto label = ui::Label( "S:" );
664 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 3, 4,
665 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
666 (GtkAttachOptions)( 0 ), 0, 0 );
669 auto label = ui::Label( "T:" );
671 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 4, 5,
672 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
673 (GtkAttachOptions)( 0 ), 0, 0 );
676 auto entry = ui::Entry(ui::New);
678 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
679 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
680 (GtkAttachOptions)( 0 ), 0, 0 );
681 AddDialogData( *GTK_ENTRY(entry), m_fX );
683 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
686 auto entry = ui::Entry(ui::New);
688 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
689 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
690 (GtkAttachOptions)( 0 ), 0, 0 );
691 AddDialogData( *GTK_ENTRY(entry), m_fY );
693 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
696 auto entry = ui::Entry(ui::New);
698 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
699 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
700 (GtkAttachOptions)( 0 ), 0, 0 );
701 AddDialogData( *GTK_ENTRY(entry), m_fZ );
703 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
706 auto entry = ui::Entry(ui::New);
708 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 3, 4,
709 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
710 (GtkAttachOptions)( 0 ), 0, 0 );
711 AddDialogData( *GTK_ENTRY(entry), m_fS );
713 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
716 auto entry = ui::Entry(ui::New);
718 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 4, 5,
719 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
720 (GtkAttachOptions)( 0 ), 0, 0 );
721 AddDialogData( *GTK_ENTRY(entry), m_fT );
723 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
727 if ( g_pGameDescription->mGameType == "doom3" ) {
728 auto frame = ui::Frame( "Tesselation" );
730 vbox2.pack_start( frame, TRUE, TRUE, 0 );
732 auto vbox3 = ui::VBox( FALSE, 5 );
733 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
737 auto table = ui::Table( 3, 2, FALSE );
739 vbox3.pack_start( table, TRUE, TRUE, 0 );
740 gtk_table_set_row_spacings( table, 5 );
741 gtk_table_set_col_spacings( table, 5 );
743 auto label = ui::Label( "Fixed" );
745 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
746 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
747 (GtkAttachOptions)( 0 ), 0, 0 );
750 auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() ));
752 gtk_table_attach( table, GTK_WIDGET( 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 ) );
760 auto label = ui::Label( "Horizontal" );
762 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
763 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
764 (GtkAttachOptions)( 0 ), 0, 0 );
767 auto entry = ui::Entry(ui::New);
769 gtk_table_attach( table, GTK_WIDGET( 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 );
776 auto label = ui::Label( "Vertical" );
778 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
779 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
780 (GtkAttachOptions)( 0 ), 0, 0 );
783 auto entry = ui::Entry(ui::New);
785 gtk_table_attach( table, GTK_WIDGET( 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 );
796 auto frame = ui::Frame( "Texturing" );
798 hbox.pack_start( frame, TRUE, TRUE, 0 );
800 auto vbox2 = ui::VBox( FALSE, 5 );
803 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
805 auto label = ui::Label( "Name:" );
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 );
812 auto entry = ui::Entry(ui::New);
813 // gtk_editable_set_editable (GTK_ENTRY (entry), false);
815 vbox2.pack_start( entry, TRUE, TRUE, 0 );
816 AddDialogData( *GTK_ENTRY(entry), m_strName );
818 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
821 auto table = ui::Table( 5, 4, FALSE );
823 vbox2.pack_start( table, TRUE, TRUE, 0 );
824 gtk_table_set_row_spacings( table, 5 );
825 gtk_table_set_col_spacings( table, 5 );
827 auto label = ui::Label( "Horizontal Shift Step" );
829 gtk_table_attach( table, GTK_WIDGET( 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 );
835 auto label = ui::Label( "Vertical Shift Step" );
837 gtk_table_attach( table, GTK_WIDGET( 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 );
843 auto label = ui::Label( "Horizontal Stretch Step" );
845 gtk_table_attach( table, GTK_WIDGET( 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 );
851 auto button = ui::Button( "Flip" );
853 gtk_table_attach( table, GTK_WIDGET( 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( GTK_WIDGET( button ), 60, -1 );
860 auto label = ui::Label( "Vertical Stretch Step" );
862 gtk_table_attach( table, GTK_WIDGET( 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 );
868 auto button = ui::Button( "Flip" );
870 gtk_table_attach( table, GTK_WIDGET( 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( GTK_WIDGET( button ), 60, -1 );
877 auto label = ui::Label( "Rotate Step" );
879 gtk_table_attach( table, GTK_WIDGET( 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 );
885 auto entry = ui::Entry(ui::New);
887 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 0, 1,
888 (GtkAttachOptions)( GTK_FILL ),
889 (GtkAttachOptions)( 0 ), 0, 0 );
890 gtk_widget_set_size_request( GTK_WIDGET( 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] );
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 );
900 auto spin = ui::SpinButton( adj, 1, 0 );
902 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 0, 1,
903 (GtkAttachOptions)( 0 ),
904 (GtkAttachOptions)( 0 ), 0, 0 );
905 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
906 gtk_widget_set_can_focus( spin, false );
909 auto entry = ui::Entry(ui::New);
911 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 1, 2,
912 (GtkAttachOptions)( GTK_FILL ),
913 (GtkAttachOptions)( 0 ), 0, 0 );
914 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
915 entry_set_float( entry, g_pi_globals.shift[1] );
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 );
921 auto spin = ui::SpinButton( adj, 1, 0 );
923 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 1, 2,
924 (GtkAttachOptions)( 0 ),
925 (GtkAttachOptions)( 0 ), 0, 0 );
926 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
927 gtk_widget_set_can_focus( spin, false );
930 auto entry = ui::Entry(ui::New);
932 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 2, 3,
933 (GtkAttachOptions)( GTK_FILL ),
934 (GtkAttachOptions)( 0 ), 0, 0 );
935 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
936 entry_set_float( entry, g_pi_globals.scale[0] );
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 );
942 auto spin = ui::SpinButton( adj, 1, 0 );
944 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 2, 3,
945 (GtkAttachOptions)( 0 ),
946 (GtkAttachOptions)( 0 ), 0, 0 );
947 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
948 gtk_widget_set_can_focus( spin, false );
951 auto entry = ui::Entry(ui::New);
953 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 3, 4,
954 (GtkAttachOptions)( GTK_FILL ),
955 (GtkAttachOptions)( 0 ), 0, 0 );
956 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
957 entry_set_float( entry, g_pi_globals.scale[1] );
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 );
963 auto spin = ui::SpinButton( adj, 1, 0 );
965 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 3, 4,
966 (GtkAttachOptions)( 0 ),
967 (GtkAttachOptions)( 0 ), 0, 0 );
968 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
969 gtk_widget_set_can_focus( spin, false );
972 auto entry = ui::Entry(ui::New);
974 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 4, 5,
975 (GtkAttachOptions)( GTK_FILL ),
976 (GtkAttachOptions)( 0 ), 0, 0 );
977 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
978 entry_set_float( entry, g_pi_globals.rotate );
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 );
984 auto spin = ui::SpinButton( adj, 1, 0 );
986 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 4, 5,
987 (GtkAttachOptions)( 0 ),
988 (GtkAttachOptions)( 0 ), 0, 0 );
989 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
990 gtk_widget_set_can_focus( spin, false );
993 auto hbox2 = ui::HBox( TRUE, 5 );
995 vbox2.pack_start( hbox2, TRUE, FALSE, 0 );
997 auto button = ui::Button( "Auto Cap" );
999 hbox2.pack_end(button, TRUE, FALSE, 0);
1000 button.connect( "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 );
1001 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1004 auto button = ui::Button( "CAP" );
1006 hbox2.pack_end(button, TRUE, FALSE, 0);
1007 button.connect( "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
1008 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1011 auto button = ui::Button( "Set..." );
1013 hbox2.pack_end(button, TRUE, FALSE, 0);
1014 button.connect( "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
1015 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1018 auto button = ui::Button( "Natural" );
1020 hbox2.pack_end(button, TRUE, FALSE, 0);
1021 button.connect( "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
1022 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1025 auto button = ui::Button( "Fit" );
1027 hbox2.pack_end(button, TRUE, FALSE, 0);
1028 button.connect( "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
1029 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1039 // sync the dialog our internal data structures
1040 void PatchInspector::exportData(){
1041 m_bListenChanged = false;
1042 Dialog::exportData();
1043 m_bListenChanged = true;
1045 void PatchInspector::importData(){
1046 m_bListenChanged = false;
1047 Dialog::importData();
1048 m_bListenChanged = true;
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();
1057 if ( GlobalSelectionSystem().countSelected() == 0 ) {
1062 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
1065 if ( m_Patch != 0 ) {
1066 m_strName = m_Patch->GetShader();
1068 // fill in the numbers for Row / Col selection
1069 m_bListenChanged = false;
1072 gtk_combo_box_set_active( m_pRowCombo, 0 );
1074 for ( std::size_t i = 0; i < m_countRows; ++i )
1076 gtk_combo_box_text_remove( m_pRowCombo, gint( m_countRows - i - 1 ) );
1079 m_countRows = m_Patch->getHeight();
1080 for ( std::size_t i = 0; i < m_countRows; ++i )
1083 sprintf( buffer, "%u", Unsigned( i ) );
1084 gtk_combo_box_text_append_text( m_pRowCombo, buffer );
1087 gtk_combo_box_set_active( m_pRowCombo, 0 );
1091 gtk_combo_box_set_active( m_pColCombo, 0 );
1093 for ( std::size_t i = 0; i < m_countCols; ++i )
1095 gtk_combo_box_text_remove( m_pColCombo, gint( m_countCols - i - 1 ) );
1098 m_countCols = m_Patch->getWidth();
1099 for ( std::size_t i = 0; i < m_countCols; ++i )
1102 sprintf( buffer, "%u", Unsigned( i ) );
1103 gtk_combo_box_text_append_text( m_pColCombo, buffer );
1106 gtk_combo_box_set_active( m_pColCombo, 0 );
1109 m_bListenChanged = true;
1114 //globalOutputStream() << "WARNING: no patch\n";
1116 // fill in our internal structs
1117 m_nRow = 0; m_nCol = 0;
1119 // now update the dialog box
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;
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];
1145 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1146 PatchInspector_queueDraw();
1150 #include "preferencesystem.h"
1153 void PatchInspector_Construct(){
1154 GlobalCommands_insert( "PatchInspector", FreeCaller<PatchInspector_toggleShown>(), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
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 ) );
1163 typedef FreeCaller1<const Selectable&, PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1164 GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1165 typedef FreeCaller<PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1166 Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1168 void PatchInspector_Destroy(){