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"
32 #include "debugging/debugging.h"
34 #include "gtkutil/idledraw.h"
35 #include "gtkutil/entry.h"
36 #include "gtkutil/button.h"
37 #include "gtkutil/nonmodal.h"
40 #include "mainframe.h"
41 #include "patchmanip.h"
44 #include "preferences.h"
45 #include "signal/isignal.h"
48 #include <gdk/gdkkeysyms.h>
50 // the increment we are using for the patch inspector (this is saved in the prefs)
66 pi_globals_t g_pi_globals;
68 class PatchFixedSubdivisions
71 PatchFixedSubdivisions() : m_enabled( false ), m_x( 0 ), m_y( 0 ){
73 PatchFixedSubdivisions( bool enabled, std::size_t x, std::size_t y ) : m_enabled( enabled ), m_x( x ), m_y( y ){
80 void Patch_getFixedSubdivisions( const Patch& patch, PatchFixedSubdivisions& subdivisions ){
81 subdivisions.m_enabled = patch.m_patchDef3;
82 subdivisions.m_x = patch.m_subdivisions_x;
83 subdivisions.m_y = patch.m_subdivisions_y;
86 const std::size_t MAX_PATCH_SUBDIVISIONS = 32;
88 void Patch_setFixedSubdivisions( Patch& patch, const PatchFixedSubdivisions& subdivisions ){
91 patch.m_patchDef3 = subdivisions.m_enabled;
92 patch.m_subdivisions_x = subdivisions.m_x;
93 patch.m_subdivisions_y = subdivisions.m_y;
95 if ( patch.m_subdivisions_x == 0 ) {
96 patch.m_subdivisions_x = 4;
98 else if ( patch.m_subdivisions_x > MAX_PATCH_SUBDIVISIONS ) {
99 patch.m_subdivisions_x = MAX_PATCH_SUBDIVISIONS;
101 if ( patch.m_subdivisions_y == 0 ) {
102 patch.m_subdivisions_y = 4;
104 else if ( patch.m_subdivisions_y > MAX_PATCH_SUBDIVISIONS ) {
105 patch.m_subdivisions_y = MAX_PATCH_SUBDIVISIONS;
109 Patch_textureChanged();
110 patch.controlPointsChanged();
113 class PatchGetFixedSubdivisions
115 PatchFixedSubdivisions& m_subdivisions;
117 PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
119 void operator()( Patch& patch ){
120 Patch_getFixedSubdivisions( patch, m_subdivisions );
125 void Scene_PatchGetFixedSubdivisions( PatchFixedSubdivisions& subdivisions ){
127 if ( GlobalSelectionSystem().countSelected() != 0 ) {
128 Patch* patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
130 Patch_getFixedSubdivisions( *patch, subdivisions );
134 Scene_forEachVisibleSelectedPatch( PatchGetFixedSubdivisions( subdivisions ) );
138 class PatchSetFixedSubdivisions
140 const PatchFixedSubdivisions& m_subdivisions;
142 PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ) : m_subdivisions( subdivisions ){
144 void operator()( Patch& patch ) const {
145 Patch_setFixedSubdivisions( patch, m_subdivisions );
149 void Scene_PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ){
150 UndoableCommand command( "patchSetFixedSubdivisions" );
151 Scene_forEachVisibleSelectedPatch( PatchSetFixedSubdivisions( subdivisions ) );
158 ui::CheckButton m_enabled;
159 ui::Entry m_horizontal;
160 ui::Entry m_vertical;
161 Subdivisions() : m_enabled( (GtkCheckButton *) 0 ), m_horizontal( nullptr ), m_vertical( nullptr ){
164 PatchFixedSubdivisions subdivisions;
165 Scene_PatchGetFixedSubdivisions( subdivisions );
167 toggle_button_set_active_no_signal( m_enabled, subdivisions.m_enabled );
169 if ( subdivisions.m_enabled ) {
170 entry_set_int( m_horizontal, static_cast<int>( subdivisions.m_x ) );
171 entry_set_int( m_vertical, static_cast<int>( subdivisions.m_y ) );
172 gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), TRUE );
173 gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), TRUE );
177 gtk_entry_set_text( m_horizontal, "" );
178 gtk_entry_set_text( m_vertical, "" );
179 gtk_widget_set_sensitive( GTK_WIDGET( m_horizontal ), FALSE );
180 gtk_widget_set_sensitive( GTK_WIDGET( m_vertical ), FALSE );
186 typedef MemberCaller<Subdivisions, &Subdivisions::cancel> CancelCaller;
188 Scene_PatchSetFixedSubdivisions(
189 PatchFixedSubdivisions(
190 gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_enabled ) ) != FALSE,
191 static_cast<std::size_t>( entry_get_int( m_horizontal ) ),
192 static_cast<std::size_t>( entry_get_int( m_vertical ) )
196 typedef MemberCaller<Subdivisions, &Subdivisions::apply> ApplyCaller;
197 static void applyGtk( GtkToggleButton* toggle, Subdivisions* self ){
202 class PatchInspector : public Dialog
204 ui::Window BuildDialog();
205 Subdivisions m_subdivisions;
206 NonModalEntry m_horizontalSubdivisionsEntry;
207 NonModalEntry m_verticalSubdivisionsEntry;
210 WindowPositionTracker m_position_tracker;
214 CopiedString m_strName;
227 ui::ComboBoxText m_pRowCombo{nullptr};
228 ui::ComboBoxText m_pColCombo{nullptr};
229 std::size_t m_countRows;
230 std::size_t m_countCols;
232 // turn on/off processing of the "changed" "value_changed" messages
233 // (need to turn off when we are feeding data in)
234 // NOTE: much more simple than blocking signals
235 bool m_bListenChanged;
238 m_horizontalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
239 m_verticalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
240 m_idleDraw( MemberCaller<PatchInspector, &PatchInspector::GetPatchInfo>( *this ) ){
251 m_bListenChanged = true;
253 m_position_tracker.setPosition( c_default_window_pos );
257 return gtk_widget_get_visible( GetWidget() );
260 // void UpdateInfo();
261 // void SetPatchInfo();
263 void UpdateSpinners( bool bUp, int nID );
264 // read the current patch on map and initialize m_fX m_fY accordingly
265 void UpdateRowColInfo();
266 // sync the dialog our internal data structures
267 // depending on the flag it will read or write
268 // we use m_nCol m_nRow m_fX m_fY m_fZ m_fS m_fT m_strName
269 // (NOTE: this doesn't actually commit stuff to the map or read from it)
274 PatchInspector g_PatchInspector;
276 void PatchInspector_constructWindow( ui::Window main_window ){
277 g_PatchInspector.m_parent = main_window;
278 g_PatchInspector.Create();
280 void PatchInspector_destroyWindow(){
281 g_PatchInspector.Destroy();
284 void PatchInspector_queueDraw(){
285 if ( g_PatchInspector.visible() ) {
286 g_PatchInspector.m_idleDraw.queueDraw();
290 void DoPatchInspector(){
291 g_PatchInspector.GetPatchInfo();
292 if ( !g_PatchInspector.visible() ) {
293 g_PatchInspector.ShowDlg();
297 void PatchInspector_toggleShown(){
298 if ( g_PatchInspector.visible() ) {
299 g_PatchInspector.m_Patch = 0;
300 g_PatchInspector.HideDlg();
308 // =============================================================================
311 // memorize the current state (that is don't try to undo our do before changing something else)
312 static void OnApply( ui::Widget widget, gpointer data ){
313 g_PatchInspector.exportData();
314 if ( g_PatchInspector.m_Patch != 0 ) {
315 UndoableCommand command( "patchSetTexture" );
316 g_PatchInspector.m_Patch->undoSave();
318 if ( !texdef_name_valid( g_PatchInspector.m_strName.c_str() ) ) {
319 globalErrorStream() << "invalid texture name '" << g_PatchInspector.m_strName.c_str() << "'\n";
320 g_PatchInspector.m_strName = texdef_name_default();
322 g_PatchInspector.m_Patch->SetShader( g_PatchInspector.m_strName.c_str() );
324 std::size_t r = g_PatchInspector.m_nRow;
325 std::size_t c = g_PatchInspector.m_nCol;
326 if ( r < g_PatchInspector.m_Patch->getHeight()
327 && c < g_PatchInspector.m_Patch->getWidth() ) {
328 PatchControl& p = g_PatchInspector.m_Patch->ctrlAt( r,c );
329 p.m_vertex[0] = g_PatchInspector.m_fX;
330 p.m_vertex[1] = g_PatchInspector.m_fY;
331 p.m_vertex[2] = g_PatchInspector.m_fZ;
332 p.m_texcoord[0] = g_PatchInspector.m_fS;
333 p.m_texcoord[1] = g_PatchInspector.m_fT;
334 g_PatchInspector.m_Patch->controlPointsChanged();
339 static void OnSelchangeComboColRow( ui::Widget widget, gpointer data ){
340 if ( !g_PatchInspector.m_bListenChanged ) {
343 // retrieve the current m_nRow and m_nCol, other params are not relevant
344 g_PatchInspector.exportData();
345 // read the changed values ourselves
346 g_PatchInspector.UpdateRowColInfo();
347 // now reflect our changes
348 g_PatchInspector.importData();
351 class PatchSetTextureRepeat
355 PatchSetTextureRepeat( float s, float t ) : m_s( s ), m_t( t ){
357 void operator()( Patch& patch ) const {
358 patch.SetTextureRepeat( m_s, m_t );
362 void Scene_PatchTileTexture_Selected( scene::Graph& graph, float s, float t ){
363 Scene_forEachVisibleSelectedPatch( PatchSetTextureRepeat( s, t ) );
367 static void OnBtnPatchdetails( ui::Widget widget, gpointer data ){
371 static void OnBtnPatchfit( ui::Widget widget, gpointer data ){
375 static void OnBtnPatchnatural( ui::Widget widget, gpointer data ){
376 Patch_NaturalTexture();
379 static void OnBtnPatchreset( ui::Widget widget, gpointer data ){
380 Patch_ResetTexture();
383 static void OnBtnPatchFlipX( ui::Widget widget, gpointer data ){
384 Patch_FlipTextureX();
387 static void OnBtnPatchFlipY( ui::Widget widget, gpointer data ){
388 Patch_FlipTextureY();
391 struct PatchRotateTexture
395 PatchRotateTexture( float angle ) : m_angle( angle ){
397 void operator()( Patch& patch ) const {
398 patch.RotateTexture( m_angle );
402 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
403 Scene_forEachVisibleSelectedPatch( PatchRotateTexture( angle ) );
406 class PatchScaleTexture
410 PatchScaleTexture( float s, float t ) : m_s( s ), m_t( t ){
412 void operator()( Patch& patch ) const {
413 patch.ScaleTexture( m_s, m_t );
417 float Patch_convertScale( float scale ){
427 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
428 Scene_forEachVisibleSelectedPatch( PatchScaleTexture( Patch_convertScale( s ), Patch_convertScale( t ) ) );
431 class PatchTranslateTexture
435 PatchTranslateTexture( float s, float t )
436 : m_s( s ), m_t( t ){
438 void operator()( Patch& patch ) const {
439 patch.TranslateTexture( m_s, m_t );
443 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
444 Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) );
447 static void OnBtnPatchAutoCap( ui::Widget widget, gpointer data ){
448 Patch_AutoCapTexture();
451 static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){
455 td.scale[0] = td.scale[1] = 0;
456 td.shift[0] = td.shift[1] = 0;
458 if ( gtk_adjustment_get_value(adj) == 0 ) {
462 if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hshift_adj" ) ) {
463 g_pi_globals.shift[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
465 if ( gtk_adjustment_get_value(adj) > 0 ) {
466 td.shift[0] = g_pi_globals.shift[0];
469 td.shift[0] = -g_pi_globals.shift[0];
472 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vshift_adj" ) ) {
473 g_pi_globals.shift[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
475 if ( gtk_adjustment_get_value(adj) > 0 ) {
476 td.shift[1] = g_pi_globals.shift[1];
479 td.shift[1] = -g_pi_globals.shift[1];
482 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hscale_adj" ) ) {
483 g_pi_globals.scale[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
484 if ( g_pi_globals.scale[0] == 0.0f ) {
487 if ( gtk_adjustment_get_value(adj) > 0 ) {
488 td.scale[0] = g_pi_globals.scale[0];
491 td.scale[0] = -g_pi_globals.scale[0];
494 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vscale_adj" ) ) {
495 g_pi_globals.scale[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
496 if ( g_pi_globals.scale[1] == 0.0f ) {
499 if ( gtk_adjustment_get_value(adj) > 0 ) {
500 td.scale[1] = g_pi_globals.scale[1];
503 td.scale[1] = -g_pi_globals.scale[1];
506 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "rotate_adj" ) ) {
507 g_pi_globals.rotate = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
509 if ( gtk_adjustment_get_value(adj) > 0 ) {
510 td.rotate = g_pi_globals.rotate;
513 td.rotate = -g_pi_globals.rotate;
517 gtk_adjustment_set_value(adj, 0);
519 // will scale shift rotate the patch accordingly
522 if ( td.shift[0] || td.shift[1] ) {
523 UndoableCommand command( "patchTranslateTexture" );
524 Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), td.shift[0], td.shift[1] );
526 else if ( td.scale[0] || td.scale[1] ) {
527 UndoableCommand command( "patchScaleTexture" );
528 Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), td.scale[0], td.scale[1] );
530 else if ( td.rotate ) {
531 UndoableCommand command( "patchRotateTexture" );
532 Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), td.rotate );
535 // update the point-by-point view
536 OnSelchangeComboColRow( ui::root ,0 );
539 static gint OnDialogKey( ui::Widget widget, GdkEventKey* event, gpointer data ){
540 if ( event->keyval == GDK_Return ) {
541 OnApply( ui::root, 0 );
544 else if ( event->keyval == GDK_Escape ) {
545 g_PatchInspector.GetPatchInfo();
551 // =============================================================================
552 // PatchInspector class
554 ui::Window PatchInspector::BuildDialog(){
555 ui::Window window = ui::Window(create_floating_window( "Patch Properties", m_parent ));
557 m_position_tracker.connect( window );
559 global_accel_connect_window( window );
561 window_connect_focus_in_clear_focus_widget( window );
565 auto vbox = ui::VBox( FALSE, 5 );
566 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
570 auto hbox = ui::HBox( FALSE, 5 );
572 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), TRUE, TRUE, 0 );
574 auto vbox2 = ui::VBox( FALSE, 0 );
575 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 0 );
577 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox2 ), TRUE, TRUE, 0 );
579 auto frame = ui::Frame( "Details" );
581 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
583 auto vbox3 = ui::VBox( FALSE, 5 );
584 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
588 auto table = ui::Table( 2, 2, FALSE );
590 gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
591 gtk_table_set_row_spacings( table, 5 );
592 gtk_table_set_col_spacings( table, 5 );
594 auto label = ui::Label( "Row:" );
596 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
597 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
598 (GtkAttachOptions)( 0 ), 0, 0 );
601 auto label = ui::Label( "Column:" );
603 gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 0, 1,
604 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
605 (GtkAttachOptions)( 0 ), 0, 0 );
608 auto combo = ui::ComboBoxText();
609 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
610 AddDialogData( *GTK_COMBO_BOX(combo), m_nRow );
613 gtk_table_attach( table, GTK_WIDGET( combo ), 0, 1, 1, 2,
614 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
615 (GtkAttachOptions)( 0 ), 0, 0 );
616 gtk_widget_set_size_request( GTK_WIDGET( combo ), 60, -1 );
621 auto combo = ui::ComboBoxText();
622 g_signal_connect( G_OBJECT( combo ), "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
623 AddDialogData( *GTK_COMBO_BOX(combo), m_nCol );
626 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
627 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
628 (GtkAttachOptions)( 0 ), 0, 0 );
629 gtk_widget_set_size_request( GTK_WIDGET( combo ), 60, -1 );
633 auto table = ui::Table( 5, 2, FALSE );
635 gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
636 gtk_table_set_row_spacings( table, 5 );
637 gtk_table_set_col_spacings( table, 5 );
639 auto label = ui::Label( "X:" );
641 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
642 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
643 (GtkAttachOptions)( 0 ), 0, 0 );
646 auto label = ui::Label( "Y:" );
648 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
649 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
650 (GtkAttachOptions)( 0 ), 0, 0 );
653 auto label = ui::Label( "Z:" );
655 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
656 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
657 (GtkAttachOptions)( 0 ), 0, 0 );
660 auto label = ui::Label( "S:" );
662 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 3, 4,
663 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
664 (GtkAttachOptions)( 0 ), 0, 0 );
667 auto label = ui::Label( "T:" );
669 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 4, 5,
670 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
671 (GtkAttachOptions)( 0 ), 0, 0 );
674 auto entry = ui::Entry();
676 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
677 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
678 (GtkAttachOptions)( 0 ), 0, 0 );
679 AddDialogData( *GTK_ENTRY(entry), m_fX );
681 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
684 auto entry = ui::Entry();
686 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
687 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
688 (GtkAttachOptions)( 0 ), 0, 0 );
689 AddDialogData( *GTK_ENTRY(entry), m_fY );
691 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
694 auto entry = ui::Entry();
696 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
697 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
698 (GtkAttachOptions)( 0 ), 0, 0 );
699 AddDialogData( *GTK_ENTRY(entry), m_fZ );
701 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
704 auto entry = ui::Entry();
706 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 3, 4,
707 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
708 (GtkAttachOptions)( 0 ), 0, 0 );
709 AddDialogData( *GTK_ENTRY(entry), m_fS );
711 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
714 auto entry = ui::Entry();
716 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 4, 5,
717 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
718 (GtkAttachOptions)( 0 ), 0, 0 );
719 AddDialogData( *GTK_ENTRY(entry), m_fT );
721 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
725 if ( g_pGameDescription->mGameType == "doom3" ) {
726 auto frame = ui::Frame( "Tesselation" );
728 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
730 auto vbox3 = ui::VBox( FALSE, 5 );
731 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
735 auto table = ui::Table( 3, 2, FALSE );
737 gtk_box_pack_start( GTK_BOX( vbox3 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
738 gtk_table_set_row_spacings( table, 5 );
739 gtk_table_set_col_spacings( table, 5 );
741 auto label = ui::Label( "Fixed" );
743 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
744 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
745 (GtkAttachOptions)( 0 ), 0, 0 );
748 auto check = ui::CheckButton(GTK_CHECK_BUTTON( gtk_check_button_new() ));
750 gtk_table_attach( table, GTK_WIDGET( check ), 1, 2, 0, 1,
751 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
752 (GtkAttachOptions)( 0 ), 0, 0 );
753 m_subdivisions.m_enabled = check;
754 guint handler_id = g_signal_connect( G_OBJECT( check ), "toggled", G_CALLBACK( &Subdivisions::applyGtk ), &m_subdivisions );
755 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) );
758 auto label = ui::Label( "Horizontal" );
760 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
761 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
762 (GtkAttachOptions)( 0 ), 0, 0 );
765 auto entry = ui::Entry();
767 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
768 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
769 (GtkAttachOptions)( 0 ), 0, 0 );
770 m_subdivisions.m_horizontal = entry;
771 m_horizontalSubdivisionsEntry.connect( entry );
774 auto label = ui::Label( "Vertical" );
776 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
777 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
778 (GtkAttachOptions)( 0 ), 0, 0 );
781 auto entry = ui::Entry();
783 gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 2, 3,
784 (GtkAttachOptions)( GTK_EXPAND | GTK_FILL ),
785 (GtkAttachOptions)( 0 ), 0, 0 );
786 m_subdivisions.m_vertical = entry;
787 m_verticalSubdivisionsEntry.connect( entry );
794 auto frame = ui::Frame( "Texturing" );
796 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
798 auto vbox2 = ui::VBox( FALSE, 5 );
801 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
803 auto label = ui::Label( "Name:" );
805 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( label ), TRUE, TRUE, 0 );
806 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
807 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
810 auto entry = ui::Entry();
811 // gtk_editable_set_editable (GTK_ENTRY (entry), false);
813 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
814 AddDialogData( *GTK_ENTRY(entry), m_strName );
816 g_signal_connect( G_OBJECT( entry ), "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
819 auto table = ui::Table( 5, 4, FALSE );
821 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
822 gtk_table_set_row_spacings( table, 5 );
823 gtk_table_set_col_spacings( table, 5 );
825 auto label = ui::Label( "Horizontal Shift Step" );
827 gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 0, 1,
828 (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
829 (GtkAttachOptions)( 0 ), 0, 0 );
830 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
833 auto label = ui::Label( "Vertical Shift Step" );
835 gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 1, 2,
836 (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
837 (GtkAttachOptions)( 0 ), 0, 0 );
838 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
841 auto label = ui::Label( "Horizontal Stretch Step" );
843 gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 2, 3,
844 (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
845 (GtkAttachOptions)( 0 ), 0, 0 );
846 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
849 auto button = ui::Button( "Flip" );
851 gtk_table_attach( table, GTK_WIDGET( button ), 3, 4, 2, 3,
852 (GtkAttachOptions)( GTK_FILL ),
853 (GtkAttachOptions)( 0 ), 0, 0 );
854 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchFlipX ), 0 );
855 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
858 auto label = ui::Label( "Vertical Stretch Step" );
860 gtk_table_attach( table, GTK_WIDGET( label ), 2, 3, 3, 4,
861 (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
862 (GtkAttachOptions)( 0 ), 0, 0 );
863 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
866 auto button = ui::Button( "Flip" );
868 gtk_table_attach( table, GTK_WIDGET( button ), 3, 4, 3, 4,
869 (GtkAttachOptions)( GTK_FILL ),
870 (GtkAttachOptions)( 0 ), 0, 0 );
871 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchFlipY ), 0 );
872 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
875 auto label = ui::Label( "Rotate Step" );
877 gtk_table_attach( table, GTK_WIDGET( label ), 2, 4, 4, 5,
878 (GtkAttachOptions)( GTK_FILL|GTK_EXPAND ),
879 (GtkAttachOptions)( 0 ), 0, 0 );
880 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
883 auto entry = ui::Entry();
885 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 0, 1,
886 (GtkAttachOptions)( GTK_FILL ),
887 (GtkAttachOptions)( 0 ), 0, 0 );
888 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
889 g_object_set_data( G_OBJECT( window ), "hshift_entry", entry );
890 // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
891 // so we need to have at least one initialisation somewhere
892 entry_set_float( entry, g_pi_globals.shift[0] );
894 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
895 g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), (gpointer) entry );
896 g_object_set_data( G_OBJECT( window ), "hshift_adj", (gpointer) adj );
898 auto spin = ui::SpinButton( adj, 1, 0 );
900 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 0, 1,
901 (GtkAttachOptions)( 0 ),
902 (GtkAttachOptions)( 0 ), 0, 0 );
903 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
904 gtk_widget_set_can_focus( spin, false );
907 auto entry = ui::Entry();
909 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 1, 2,
910 (GtkAttachOptions)( GTK_FILL ),
911 (GtkAttachOptions)( 0 ), 0, 0 );
912 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
913 entry_set_float( entry, g_pi_globals.shift[1] );
915 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
916 g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
917 g_object_set_data( G_OBJECT( window ), "vshift_adj", (gpointer) adj );
919 auto spin = ui::SpinButton( adj, 1, 0 );
921 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 1, 2,
922 (GtkAttachOptions)( 0 ),
923 (GtkAttachOptions)( 0 ), 0, 0 );
924 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
925 gtk_widget_set_can_focus( spin, false );
928 auto entry = ui::Entry();
930 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 2, 3,
931 (GtkAttachOptions)( GTK_FILL ),
932 (GtkAttachOptions)( 0 ), 0, 0 );
933 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
934 entry_set_float( entry, g_pi_globals.scale[0] );
936 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
937 g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
938 g_object_set_data( G_OBJECT( window ), "hscale_adj", (gpointer) adj );
940 auto spin = ui::SpinButton( adj, 1, 0 );
942 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 2, 3,
943 (GtkAttachOptions)( 0 ),
944 (GtkAttachOptions)( 0 ), 0, 0 );
945 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
946 gtk_widget_set_can_focus( spin, false );
949 auto entry = ui::Entry();
951 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 3, 4,
952 (GtkAttachOptions)( GTK_FILL ),
953 (GtkAttachOptions)( 0 ), 0, 0 );
954 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
955 entry_set_float( entry, g_pi_globals.scale[1] );
957 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
958 g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
959 g_object_set_data( G_OBJECT( window ), "vscale_adj", (gpointer) adj );
961 auto spin = ui::SpinButton( adj, 1, 0 );
963 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 3, 4,
964 (GtkAttachOptions)( 0 ),
965 (GtkAttachOptions)( 0 ), 0, 0 );
966 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
967 gtk_widget_set_can_focus( spin, false );
970 auto entry = ui::Entry();
972 gtk_table_attach( table, GTK_WIDGET( entry ), 0, 1, 4, 5,
973 (GtkAttachOptions)( GTK_FILL ),
974 (GtkAttachOptions)( 0 ), 0, 0 );
975 gtk_widget_set_size_request( GTK_WIDGET( entry ), 50, -1 );
976 entry_set_float( entry, g_pi_globals.rotate );
978 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
979 g_signal_connect( G_OBJECT( adj ), "value_changed", G_CALLBACK( OnSpinChanged ), entry );
980 g_object_set_data( G_OBJECT( window ), "rotate_adj", (gpointer) adj );
982 auto spin = ui::SpinButton( adj, 1, 0 );
984 gtk_table_attach( table, GTK_WIDGET( spin ), 1, 2, 4, 5,
985 (GtkAttachOptions)( 0 ),
986 (GtkAttachOptions)( 0 ), 0, 0 );
987 gtk_widget_set_size_request( GTK_WIDGET( spin ), 10, -1 );
988 gtk_widget_set_can_focus( spin, false );
991 auto hbox2 = ui::HBox( TRUE, 5 );
993 gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox2 ), TRUE, FALSE, 0 );
995 auto button = ui::Button( "Auto Cap" );
997 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
998 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 );
999 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1002 auto button = ui::Button( "CAP" );
1004 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1005 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
1006 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1009 auto button = ui::Button( "Set..." );
1011 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1012 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
1013 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1016 auto button = ui::Button( "Natural" );
1018 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1019 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
1020 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1023 auto button = ui::Button( "Fit" );
1025 gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 );
1026 g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
1027 gtk_widget_set_size_request( GTK_WIDGET( button ), 60, -1 );
1037 // sync the dialog our internal data structures
1038 void PatchInspector::exportData(){
1039 m_bListenChanged = false;
1040 Dialog::exportData();
1041 m_bListenChanged = true;
1043 void PatchInspector::importData(){
1044 m_bListenChanged = false;
1045 Dialog::importData();
1046 m_bListenChanged = true;
1049 // read the map and feed in the stuff to the dialog box
1050 void PatchInspector::GetPatchInfo(){
1051 if ( g_pGameDescription->mGameType == "doom3" ) {
1052 m_subdivisions.update();
1055 if ( GlobalSelectionSystem().countSelected() == 0 ) {
1060 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
1063 if ( m_Patch != 0 ) {
1064 m_strName = m_Patch->GetShader();
1066 // fill in the numbers for Row / Col selection
1067 m_bListenChanged = false;
1070 gtk_combo_box_set_active( m_pRowCombo, 0 );
1072 for ( std::size_t i = 0; i < m_countRows; ++i )
1074 gtk_combo_box_text_remove( m_pRowCombo, gint( m_countRows - i - 1 ) );
1077 m_countRows = m_Patch->getHeight();
1078 for ( std::size_t i = 0; i < m_countRows; ++i )
1081 sprintf( buffer, "%u", Unsigned( i ) );
1082 gtk_combo_box_text_append_text( m_pRowCombo, buffer );
1085 gtk_combo_box_set_active( m_pRowCombo, 0 );
1089 gtk_combo_box_set_active( m_pColCombo, 0 );
1091 for ( std::size_t i = 0; i < m_countCols; ++i )
1093 gtk_combo_box_text_remove( m_pColCombo, gint( m_countCols - i - 1 ) );
1096 m_countCols = m_Patch->getWidth();
1097 for ( std::size_t i = 0; i < m_countCols; ++i )
1100 sprintf( buffer, "%u", Unsigned( i ) );
1101 gtk_combo_box_text_append_text( m_pColCombo, buffer );
1104 gtk_combo_box_set_active( m_pColCombo, 0 );
1107 m_bListenChanged = true;
1112 //globalOutputStream() << "WARNING: no patch\n";
1114 // fill in our internal structs
1115 m_nRow = 0; m_nCol = 0;
1117 // now update the dialog box
1121 // read the current patch on map and initialize m_fX m_fY accordingly
1122 // NOTE: don't call UpdateData in there, it's not meant for
1123 void PatchInspector::UpdateRowColInfo(){
1124 m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
1126 if ( m_Patch != 0 ) {
1127 // we rely on whatever active row/column has been set before we get called
1128 std::size_t r = m_nRow;
1129 std::size_t c = m_nCol;
1130 if ( r < m_Patch->getHeight()
1131 && c < m_Patch->getWidth() ) {
1132 const PatchControl& p = m_Patch->ctrlAt( r,c );
1133 m_fX = p.m_vertex[0];
1134 m_fY = p.m_vertex[1];
1135 m_fZ = p.m_vertex[2];
1136 m_fS = p.m_texcoord[0];
1137 m_fT = p.m_texcoord[1];
1143 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1144 PatchInspector_queueDraw();
1148 #include "preferencesystem.h"
1151 void PatchInspector_Construct(){
1152 GlobalCommands_insert( "PatchInspector", FreeCaller<PatchInspector_toggleShown>(), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
1154 GlobalPreferenceSystem().registerPreference( "PatchWnd", WindowPositionTrackerImportStringCaller( g_PatchInspector.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_PatchInspector.m_position_tracker ) );
1155 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", FloatImportStringCaller( g_pi_globals.scale[0] ), FloatExportStringCaller( g_pi_globals.scale[0] ) );
1156 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", FloatImportStringCaller( g_pi_globals.scale[1] ), FloatExportStringCaller( g_pi_globals.scale[1] ) );
1157 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", FloatImportStringCaller( g_pi_globals.shift[0] ), FloatExportStringCaller( g_pi_globals.shift[0] ) );
1158 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", FloatImportStringCaller( g_pi_globals.shift[1] ), FloatExportStringCaller( g_pi_globals.shift[1] ) );
1159 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", FloatImportStringCaller( g_pi_globals.rotate ), FloatExportStringCaller( g_pi_globals.rotate ) );
1161 typedef FreeCaller1<const Selectable&, PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1162 GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1163 typedef FreeCaller<PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1164 Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1166 void PatchInspector_Destroy(){