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 void Scene_PatchSetFixedSubdivisions( const PatchFixedSubdivisions& subdivisions ){
141 UndoableCommand command( "patchSetFixedSubdivisions" );
142 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
143 Patch_setFixedSubdivisions(patch, subdivisions);
151 ui::CheckButton m_enabled;
152 ui::Entry m_horizontal;
153 ui::Entry m_vertical;
154 Subdivisions() : m_enabled( ui::null ), m_horizontal( ui::null ), m_vertical( ui::null ){
157 PatchFixedSubdivisions subdivisions;
158 Scene_PatchGetFixedSubdivisions( subdivisions );
160 toggle_button_set_active_no_signal( m_enabled, subdivisions.m_enabled );
162 if ( subdivisions.m_enabled ) {
163 entry_set_int( m_horizontal, static_cast<int>( subdivisions.m_x ) );
164 entry_set_int( m_vertical, static_cast<int>( subdivisions.m_y ) );
165 gtk_widget_set_sensitive( m_horizontal , TRUE );
166 gtk_widget_set_sensitive( m_vertical , TRUE );
170 m_horizontal.text("");
172 gtk_widget_set_sensitive( m_horizontal , FALSE );
173 gtk_widget_set_sensitive( m_vertical , FALSE );
179 typedef MemberCaller<Subdivisions, void(), &Subdivisions::cancel> CancelCaller;
181 Scene_PatchSetFixedSubdivisions(
182 PatchFixedSubdivisions(
183 gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( m_enabled ) ) != FALSE,
184 static_cast<std::size_t>( entry_get_int( m_horizontal ) ),
185 static_cast<std::size_t>( entry_get_int( m_vertical ) )
189 typedef MemberCaller<Subdivisions, void(), &Subdivisions::apply> ApplyCaller;
190 static void applyGtk( ui::ToggleButton toggle, Subdivisions* self ){
195 class PatchInspector : public Dialog
197 ui::Window BuildDialog();
198 Subdivisions m_subdivisions;
199 NonModalEntry m_horizontalSubdivisionsEntry;
200 NonModalEntry m_verticalSubdivisionsEntry;
203 WindowPositionTracker m_position_tracker;
207 CopiedString m_strName;
220 ui::ComboBoxText m_pRowCombo{ui::null};
221 ui::ComboBoxText m_pColCombo{ui::null};
222 std::size_t m_countRows;
223 std::size_t m_countCols;
225 // turn on/off processing of the "changed" "value_changed" messages
226 // (need to turn off when we are feeding data in)
227 // NOTE: much more simple than blocking signals
228 bool m_bListenChanged;
231 m_horizontalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
232 m_verticalSubdivisionsEntry( Subdivisions::ApplyCaller( m_subdivisions ), Subdivisions::CancelCaller( m_subdivisions ) ),
233 m_idleDraw( MemberCaller<PatchInspector, void(), &PatchInspector::GetPatchInfo>( *this ) ){
244 m_bListenChanged = true;
246 m_position_tracker.setPosition( c_default_window_pos );
250 return GetWidget().visible();
253 // void UpdateInfo();
254 // void SetPatchInfo();
256 void UpdateSpinners( bool bUp, int nID );
257 // read the current patch on map and initialize m_fX m_fY accordingly
258 void UpdateRowColInfo();
259 // sync the dialog our internal data structures
260 // depending on the flag it will read or write
261 // we use m_nCol m_nRow m_fX m_fY m_fZ m_fS m_fT m_strName
262 // (NOTE: this doesn't actually commit stuff to the map or read from it)
267 PatchInspector g_PatchInspector;
269 void PatchInspector_constructWindow( ui::Window main_window ){
270 g_PatchInspector.m_parent = main_window;
271 g_PatchInspector.Create();
273 void PatchInspector_destroyWindow(){
274 g_PatchInspector.Destroy();
277 void PatchInspector_queueDraw(){
278 if ( g_PatchInspector.visible() ) {
279 g_PatchInspector.m_idleDraw.queueDraw();
283 void DoPatchInspector(){
284 g_PatchInspector.GetPatchInfo();
285 if ( !g_PatchInspector.visible() ) {
286 g_PatchInspector.ShowDlg();
290 void PatchInspector_toggleShown(){
291 if ( g_PatchInspector.visible() ) {
292 g_PatchInspector.m_Patch = 0;
293 g_PatchInspector.HideDlg();
301 // =============================================================================
304 // memorize the current state (that is don't try to undo our do before changing something else)
305 static void OnApply( ui::Widget widget, gpointer data ){
306 g_PatchInspector.exportData();
307 if ( g_PatchInspector.m_Patch != 0 ) {
308 UndoableCommand command( "patchSetTexture" );
309 g_PatchInspector.m_Patch->undoSave();
311 if ( !texdef_name_valid( g_PatchInspector.m_strName.c_str() ) ) {
312 globalErrorStream() << "invalid texture name '" << g_PatchInspector.m_strName.c_str() << "'\n";
313 g_PatchInspector.m_strName = texdef_name_default();
315 g_PatchInspector.m_Patch->SetShader( g_PatchInspector.m_strName.c_str() );
317 std::size_t r = g_PatchInspector.m_nRow;
318 std::size_t c = g_PatchInspector.m_nCol;
319 if ( r < g_PatchInspector.m_Patch->getHeight()
320 && c < g_PatchInspector.m_Patch->getWidth() ) {
321 PatchControl& p = g_PatchInspector.m_Patch->ctrlAt( r,c );
322 p.m_vertex[0] = g_PatchInspector.m_fX;
323 p.m_vertex[1] = g_PatchInspector.m_fY;
324 p.m_vertex[2] = g_PatchInspector.m_fZ;
325 p.m_texcoord[0] = g_PatchInspector.m_fS;
326 p.m_texcoord[1] = g_PatchInspector.m_fT;
327 g_PatchInspector.m_Patch->controlPointsChanged();
332 static void OnSelchangeComboColRow( ui::Widget widget, gpointer data ){
333 if ( !g_PatchInspector.m_bListenChanged ) {
336 // retrieve the current m_nRow and m_nCol, other params are not relevant
337 g_PatchInspector.exportData();
338 // read the changed values ourselves
339 g_PatchInspector.UpdateRowColInfo();
340 // now reflect our changes
341 g_PatchInspector.importData();
344 void Scene_PatchTileTexture_Selected( scene::Graph& graph, float s, float t ){
345 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
346 patch.SetTextureRepeat(s, t);
351 static void OnBtnPatchdetails( ui::Widget widget, gpointer data ){
355 static void OnBtnPatchfit( ui::Widget widget, gpointer data ){
359 static void OnBtnPatchnatural( ui::Widget widget, gpointer data ){
360 Patch_NaturalTexture();
363 static void OnBtnPatchreset( ui::Widget widget, gpointer data ){
364 Patch_ResetTexture();
367 static void OnBtnPatchFlipX( ui::Widget widget, gpointer data ){
368 Patch_FlipTextureX();
371 static void OnBtnPatchFlipY( ui::Widget widget, gpointer data ){
372 Patch_FlipTextureY();
375 void Scene_PatchRotateTexture_Selected( scene::Graph& graph, float angle ){
376 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
377 patch.RotateTexture(angle);
381 float Patch_convertScale( float scale ){
391 void Scene_PatchScaleTexture_Selected( scene::Graph& graph, float s, float t ){
392 s = Patch_convertScale(s);
393 t = Patch_convertScale(t);
394 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
395 patch.ScaleTexture(s, t);
399 void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t ){
400 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
401 patch.TranslateTexture(s, t);
405 static void OnBtnPatchAutoCap( ui::Widget widget, gpointer data ){
406 Patch_AutoCapTexture();
409 static void OnSpinChanged(ui::Adjustment adj, gpointer data ){
413 td.scale[0] = td.scale[1] = 0;
414 td.shift[0] = td.shift[1] = 0;
416 if ( gtk_adjustment_get_value(adj) == 0 ) {
420 if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hshift_adj" ) ) {
421 g_pi_globals.shift[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
423 if ( gtk_adjustment_get_value(adj) > 0 ) {
424 td.shift[0] = g_pi_globals.shift[0];
427 td.shift[0] = -g_pi_globals.shift[0];
430 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vshift_adj" ) ) {
431 g_pi_globals.shift[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
433 if ( gtk_adjustment_get_value(adj) > 0 ) {
434 td.shift[1] = g_pi_globals.shift[1];
437 td.shift[1] = -g_pi_globals.shift[1];
440 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "hscale_adj" ) ) {
441 g_pi_globals.scale[0] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
442 if ( g_pi_globals.scale[0] == 0.0f ) {
445 if ( gtk_adjustment_get_value(adj) > 0 ) {
446 td.scale[0] = g_pi_globals.scale[0];
449 td.scale[0] = -g_pi_globals.scale[0];
452 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "vscale_adj" ) ) {
453 g_pi_globals.scale[1] = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
454 if ( g_pi_globals.scale[1] == 0.0f ) {
457 if ( gtk_adjustment_get_value(adj) > 0 ) {
458 td.scale[1] = g_pi_globals.scale[1];
461 td.scale[1] = -g_pi_globals.scale[1];
464 else if ( adj == g_object_get_data( G_OBJECT( g_PatchInspector.GetWidget() ), "rotate_adj" ) ) {
465 g_pi_globals.rotate = static_cast<float>( atof( gtk_entry_get_text( GTK_ENTRY( data ) ) ) );
467 if ( gtk_adjustment_get_value(adj) > 0 ) {
468 td.rotate = g_pi_globals.rotate;
471 td.rotate = -g_pi_globals.rotate;
475 gtk_adjustment_set_value(adj, 0);
477 // will scale shift rotate the patch accordingly
480 if ( td.shift[0] || td.shift[1] ) {
481 UndoableCommand command( "patchTranslateTexture" );
482 Scene_PatchTranslateTexture_Selected( GlobalSceneGraph(), td.shift[0], td.shift[1] );
484 else if ( td.scale[0] || td.scale[1] ) {
485 UndoableCommand command( "patchScaleTexture" );
486 Scene_PatchScaleTexture_Selected( GlobalSceneGraph(), td.scale[0], td.scale[1] );
488 else if ( td.rotate ) {
489 UndoableCommand command( "patchRotateTexture" );
490 Scene_PatchRotateTexture_Selected( GlobalSceneGraph(), td.rotate );
493 // update the point-by-point view
494 OnSelchangeComboColRow( ui::root, 0 );
497 static gint OnDialogKey( ui::Widget widget, GdkEventKey* event, gpointer data ){
498 if ( event->keyval == GDK_KEY_Return ) {
499 OnApply( ui::root, 0 );
502 else if ( event->keyval == GDK_KEY_Escape ) {
503 g_PatchInspector.GetPatchInfo();
509 // =============================================================================
510 // PatchInspector class
512 ui::Window PatchInspector::BuildDialog(){
513 ui::Window window = ui::Window(create_floating_window( "Patch Properties", m_parent ));
515 m_position_tracker.connect( window );
517 global_accel_connect_window( window );
519 window_connect_focus_in_clear_focus_widget( window );
523 auto vbox = ui::VBox( FALSE, 5 );
524 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
528 auto hbox = ui::HBox( FALSE, 5 );
530 vbox.pack_start( hbox, TRUE, TRUE, 0 );
532 auto vbox2 = ui::VBox( FALSE, 0 );
533 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 0 );
535 hbox.pack_start( vbox2, TRUE, TRUE, 0 );
537 auto frame = ui::Frame( "Details" );
539 vbox2.pack_start( frame, TRUE, TRUE, 0 );
541 auto vbox3 = ui::VBox( FALSE, 5 );
542 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
546 auto table = ui::Table( 2, 2, FALSE );
548 vbox3.pack_start( table, TRUE, TRUE, 0 );
549 gtk_table_set_row_spacings( table, 5 );
550 gtk_table_set_col_spacings( table, 5 );
552 auto label = ui::Label( "Row:" );
554 table.attach(label, {0, 1, 0, 1}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
557 auto label = ui::Label( "Column:" );
559 table.attach(label, {1, 2, 0, 1}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
562 auto combo = ui::ComboBoxText(ui::New);
563 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
564 AddDialogData( combo, m_nRow );
567 table.attach(combo, {0, 1, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
568 combo.dimensions(60, -1);
573 auto combo = ui::ComboBoxText(ui::New);
574 combo.connect( "changed", G_CALLBACK( OnSelchangeComboColRow ), this );
575 AddDialogData( combo, m_nCol );
578 table.attach(combo, {1, 2, 1, 2}, {(GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0)}, {0, 0});
579 combo.dimensions(60, -1);
583 auto table = ui::Table( 5, 2, FALSE );
585 vbox3.pack_start( table, TRUE, TRUE, 0 );
586 gtk_table_set_row_spacings( table, 5 );
587 gtk_table_set_col_spacings( table, 5 );
589 auto label = ui::Label( "X:" );
591 table.attach(label, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
594 auto label = ui::Label( "Y:" );
596 table.attach(label, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
599 auto label = ui::Label( "Z:" );
601 table.attach(label, {0, 1, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
604 auto label = ui::Label( "S:" );
606 table.attach(label, {0, 1, 3, 4}, {GTK_EXPAND | GTK_FILL, 0});
609 auto label = ui::Label( "T:" );
611 table.attach(label, {0, 1, 4, 5}, {GTK_EXPAND | GTK_FILL, 0});
614 auto entry = ui::Entry(ui::New);
616 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
617 AddDialogData( entry, m_fX );
619 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
622 auto entry = ui::Entry(ui::New);
624 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
625 AddDialogData( entry, m_fY );
627 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
630 auto entry = ui::Entry(ui::New);
632 table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
633 AddDialogData( entry, m_fZ );
635 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
638 auto entry = ui::Entry(ui::New);
640 table.attach(entry, {1, 2, 3, 4}, {GTK_EXPAND | GTK_FILL, 0});
641 AddDialogData( entry, m_fS );
643 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
646 auto entry = ui::Entry(ui::New);
648 table.attach(entry, {1, 2, 4, 5}, {GTK_EXPAND | GTK_FILL, 0});
649 AddDialogData( entry, m_fT );
651 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
655 if ( g_pGameDescription->mGameType == "doom3" ) {
656 auto frame = ui::Frame( "Tesselation" );
658 vbox2.pack_start( frame, TRUE, TRUE, 0 );
660 auto vbox3 = ui::VBox( FALSE, 5 );
661 gtk_container_set_border_width( GTK_CONTAINER( vbox3 ), 5 );
665 auto table = ui::Table( 3, 2, FALSE );
667 vbox3.pack_start( table, TRUE, TRUE, 0 );
668 gtk_table_set_row_spacings( table, 5 );
669 gtk_table_set_col_spacings( table, 5 );
671 auto label = ui::Label( "Fixed" );
673 table.attach(label, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
676 auto check = ui::CheckButton::from( gtk_check_button_new() );
678 table.attach(check, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
679 m_subdivisions.m_enabled = check;
680 guint handler_id = check.connect( "toggled", G_CALLBACK( &Subdivisions::applyGtk ), &m_subdivisions );
681 g_object_set_data( G_OBJECT( check ), "handler", gint_to_pointer( handler_id ) );
684 auto label = ui::Label( "Horizontal" );
686 table.attach(label, {0, 1, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
689 auto entry = ui::Entry(ui::New);
691 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
692 m_subdivisions.m_horizontal = entry;
693 m_horizontalSubdivisionsEntry.connect( entry );
696 auto label = ui::Label( "Vertical" );
698 table.attach(label, {0, 1, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
701 auto entry = ui::Entry(ui::New);
703 table.attach(entry, {1, 2, 2, 3}, {GTK_EXPAND | GTK_FILL, 0});
704 m_subdivisions.m_vertical = entry;
705 m_verticalSubdivisionsEntry.connect( entry );
712 auto frame = ui::Frame( "Texturing" );
714 hbox.pack_start( frame, TRUE, TRUE, 0 );
716 auto vbox2 = ui::VBox( FALSE, 5 );
719 gtk_container_set_border_width( GTK_CONTAINER( vbox2 ), 5 );
721 auto label = ui::Label( "Name:" );
723 vbox2.pack_start( label, TRUE, TRUE, 0 );
724 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
725 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
728 auto entry = ui::Entry(ui::New);
729 // gtk_editable_set_editable (GTK_ENTRY (entry), false);
731 vbox2.pack_start( entry, TRUE, TRUE, 0 );
732 AddDialogData( entry, m_strName );
734 entry.connect( "key_press_event", G_CALLBACK( OnDialogKey ), 0 );
737 auto table = ui::Table( 5, 4, FALSE );
739 vbox2.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( "Horizontal Shift Step" );
745 table.attach(label, {2, 4, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
746 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
749 auto label = ui::Label( "Vertical Shift Step" );
751 table.attach(label, {2, 4, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
752 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
755 auto label = ui::Label( "Horizontal Stretch Step" );
757 table.attach(label, {2, 3, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
758 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
761 auto button = ui::Button( "Flip" );
763 table.attach(button, {3, 4, 2, 3}, {GTK_FILL, 0});
764 button.connect( "clicked", G_CALLBACK( OnBtnPatchFlipX ), 0 );
765 button.dimensions(60, -1);
768 auto label = ui::Label( "Vertical Stretch Step" );
770 table.attach(label, {2, 3, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
771 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
774 auto button = ui::Button( "Flip" );
776 table.attach(button, {3, 4, 3, 4}, {GTK_FILL, 0});
777 button.connect( "clicked", G_CALLBACK( OnBtnPatchFlipY ), 0 );
778 button.dimensions(60, -1);
781 auto label = ui::Label( "Rotate Step" );
783 table.attach(label, {2, 4, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
784 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
787 auto entry = ui::Entry(ui::New);
789 table.attach(entry, {0, 1, 0, 1}, {GTK_FILL, 0});
790 entry.dimensions(50, -1);
791 g_object_set_data( G_OBJECT( window ), "hshift_entry", (void *) entry );
792 // we fill in this data, if no patch is selected the widgets are unmodified when the inspector is raised
793 // so we need to have at least one initialisation somewhere
794 entry_set_float( entry, g_pi_globals.shift[0] );
796 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
797 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), (gpointer) entry );
798 g_object_set_data( G_OBJECT( window ), "hshift_adj", (gpointer) adj );
800 auto spin = ui::SpinButton( adj, 1, 0 );
802 table.attach(spin, {1, 2, 0, 1}, {0, 0});
803 spin.dimensions(10, -1);
804 gtk_widget_set_can_focus( spin, false );
807 auto entry = ui::Entry(ui::New);
809 table.attach(entry, {0, 1, 1, 2}, {GTK_FILL, 0});
810 entry.dimensions(50, -1);
811 entry_set_float( entry, g_pi_globals.shift[1] );
813 auto adj = ui::Adjustment( 0, -8192, 8192, 1, 1, 0 );
814 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
815 g_object_set_data( G_OBJECT( window ), "vshift_adj", (gpointer) adj );
817 auto spin = ui::SpinButton( adj, 1, 0 );
819 table.attach(spin, {1, 2, 1, 2}, {0, 0});
820 spin.dimensions(10, -1);
821 gtk_widget_set_can_focus( spin, false );
824 auto entry = ui::Entry(ui::New);
826 table.attach(entry, {0, 1, 2, 3}, {GTK_FILL, 0});
827 entry.dimensions(50, -1);
828 entry_set_float( entry, g_pi_globals.scale[0] );
830 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
831 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
832 g_object_set_data( G_OBJECT( window ), "hscale_adj", (gpointer) adj );
834 auto spin = ui::SpinButton( adj, 1, 0 );
836 table.attach(spin, {1, 2, 2, 3}, {0, 0});
837 spin.dimensions(10, -1);
838 gtk_widget_set_can_focus( spin, false );
841 auto entry = ui::Entry(ui::New);
843 table.attach(entry, {0, 1, 3, 4}, {GTK_FILL, 0});
844 entry.dimensions(50, -1);
845 entry_set_float( entry, g_pi_globals.scale[1] );
847 auto adj = ui::Adjustment( 0, -1000, 1000, 1, 1, 0 );
848 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
849 g_object_set_data( G_OBJECT( window ), "vscale_adj", (gpointer) adj );
851 auto spin = ui::SpinButton( adj, 1, 0 );
853 table.attach(spin, {1, 2, 3, 4}, {0, 0});
854 spin.dimensions(10, -1);
855 gtk_widget_set_can_focus( spin, false );
858 auto entry = ui::Entry(ui::New);
860 table.attach(entry, {0, 1, 4, 5}, {GTK_FILL, 0});
861 entry.dimensions(50, -1);
862 entry_set_float( entry, g_pi_globals.rotate );
864 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
865 adj.connect( "value_changed", G_CALLBACK( OnSpinChanged ), entry );
866 g_object_set_data( G_OBJECT( window ), "rotate_adj", (gpointer) adj );
868 auto spin = ui::SpinButton( adj, 1, 0 );
870 table.attach(spin, {1, 2, 4, 5}, {0, 0});
871 spin.dimensions(10, -1);
872 gtk_widget_set_can_focus( spin, false );
875 auto hbox2 = ui::HBox( TRUE, 5 );
877 vbox2.pack_start( hbox2, TRUE, FALSE, 0 );
879 auto button = ui::Button( "Auto Cap" );
881 hbox2.pack_end(button, TRUE, FALSE, 0);
882 button.connect( "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 );
883 button.dimensions(60, -1);
886 auto button = ui::Button( "CAP" );
888 hbox2.pack_end(button, TRUE, FALSE, 0);
889 button.connect( "clicked", G_CALLBACK( OnBtnPatchdetails ), 0 );
890 button.dimensions(60, -1);
893 auto button = ui::Button( "Set..." );
895 hbox2.pack_end(button, TRUE, FALSE, 0);
896 button.connect( "clicked", G_CALLBACK( OnBtnPatchreset ), 0 );
897 button.dimensions(60, -1);
900 auto button = ui::Button( "Natural" );
902 hbox2.pack_end(button, TRUE, FALSE, 0);
903 button.connect( "clicked", G_CALLBACK( OnBtnPatchnatural ), 0 );
904 button.dimensions(60, -1);
907 auto button = ui::Button( "Fit" );
909 hbox2.pack_end(button, TRUE, FALSE, 0);
910 button.connect( "clicked", G_CALLBACK( OnBtnPatchfit ), 0 );
911 button.dimensions(60, -1);
921 // sync the dialog our internal data structures
922 void PatchInspector::exportData(){
923 m_bListenChanged = false;
924 Dialog::exportData();
925 m_bListenChanged = true;
927 void PatchInspector::importData(){
928 m_bListenChanged = false;
929 Dialog::importData();
930 m_bListenChanged = true;
933 // read the map and feed in the stuff to the dialog box
934 void PatchInspector::GetPatchInfo(){
935 if ( g_pGameDescription->mGameType == "doom3" ) {
936 m_subdivisions.update();
939 if ( GlobalSelectionSystem().countSelected() == 0 ) {
944 m_Patch = Node_getPatch( GlobalSelectionSystem().ultimateSelected().path().top() );
947 if ( m_Patch != 0 ) {
948 m_strName = m_Patch->GetShader();
950 // fill in the numbers for Row / Col selection
951 m_bListenChanged = false;
954 gtk_combo_box_set_active( m_pRowCombo, 0 );
956 for ( std::size_t i = 0; i < m_countRows; ++i )
958 gtk_combo_box_text_remove( m_pRowCombo, gint( m_countRows - i - 1 ) );
961 m_countRows = m_Patch->getHeight();
962 for ( std::size_t i = 0; i < m_countRows; ++i )
965 sprintf( buffer, "%u", Unsigned( i ) );
966 gtk_combo_box_text_append_text( m_pRowCombo, buffer );
969 gtk_combo_box_set_active( m_pRowCombo, 0 );
973 gtk_combo_box_set_active( m_pColCombo, 0 );
975 for ( std::size_t i = 0; i < m_countCols; ++i )
977 gtk_combo_box_text_remove( m_pColCombo, gint( m_countCols - i - 1 ) );
980 m_countCols = m_Patch->getWidth();
981 for ( std::size_t i = 0; i < m_countCols; ++i )
984 sprintf( buffer, "%u", Unsigned( i ) );
985 gtk_combo_box_text_append_text( m_pColCombo, buffer );
988 gtk_combo_box_set_active( m_pColCombo, 0 );
991 m_bListenChanged = true;
996 //globalOutputStream() << "WARNING: no patch\n";
998 // fill in our internal structs
999 m_nRow = 0; m_nCol = 0;
1001 // now update the dialog box
1005 // read the current patch on map and initialize m_fX m_fY accordingly
1006 // NOTE: don't call UpdateData in there, it's not meant for
1007 void PatchInspector::UpdateRowColInfo(){
1008 m_fX = m_fY = m_fZ = m_fS = m_fT = 0.0;
1010 if ( m_Patch != 0 ) {
1011 // we rely on whatever active row/column has been set before we get called
1012 std::size_t r = m_nRow;
1013 std::size_t c = m_nCol;
1014 if ( r < m_Patch->getHeight()
1015 && c < m_Patch->getWidth() ) {
1016 const PatchControl& p = m_Patch->ctrlAt( r,c );
1017 m_fX = p.m_vertex[0];
1018 m_fY = p.m_vertex[1];
1019 m_fZ = p.m_vertex[2];
1020 m_fS = p.m_texcoord[0];
1021 m_fT = p.m_texcoord[1];
1027 void PatchInspector_SelectionChanged( const Selectable& selectable ){
1028 PatchInspector_queueDraw();
1032 #include "preferencesystem.h"
1035 void PatchInspector_Construct(){
1036 GlobalCommands_insert( "PatchInspector", makeCallbackF(PatchInspector_toggleShown), Accelerator( 'S', (GdkModifierType)GDK_SHIFT_MASK ) );
1038 GlobalPreferenceSystem().registerPreference( "PatchWnd", make_property<WindowPositionTracker_String>( g_PatchInspector.m_position_tracker ) );
1039 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale1", make_property_string( g_pi_globals.scale[0] ) );
1040 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Scale2", make_property_string( g_pi_globals.scale[1] ) );
1041 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift1", make_property_string( g_pi_globals.shift[0] ) );
1042 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Shift2", make_property_string( g_pi_globals.shift[1] ) );
1043 GlobalPreferenceSystem().registerPreference( "SI_PatchTexdef_Rotate", make_property_string( g_pi_globals.rotate ) );
1045 typedef FreeCaller<void(const Selectable&), PatchInspector_SelectionChanged> PatchInspectorSelectionChangedCaller;
1046 GlobalSelectionSystem().addSelectionChangeCallback( PatchInspectorSelectionChangedCaller() );
1047 typedef FreeCaller<void(), PatchInspector_queueDraw> PatchInspectorQueueDrawCaller;
1048 Patch_addTextureChangedCallback( PatchInspectorQueueDrawCaller() );
1050 void PatchInspector_Destroy(){