From c311c99f37bcc60d30955a47117368fc8b83d9da Mon Sep 17 00:00:00 2001 From: Mattia Basaglia Date: Sun, 19 Jul 2015 10:21:42 +0200 Subject: [PATCH] Auto cap button --- radiant/patchdialog.cpp | 11 +++++++++++ radiant/patchmanip.cpp | 28 ++++++++++++++++++++++++++++ radiant/patchmanip.h | 1 + 3 files changed, 40 insertions(+) diff --git a/radiant/patchdialog.cpp b/radiant/patchdialog.cpp index 6bacd9f8..f1bf09fb 100644 --- a/radiant/patchdialog.cpp +++ b/radiant/patchdialog.cpp @@ -455,6 +455,10 @@ void Scene_PatchTranslateTexture_Selected( scene::Graph& graph, float s, float t Scene_forEachVisibleSelectedPatch( PatchTranslateTexture( s, t ) ); } +static void OnBtnPatchAutoCap( GtkWidget *widget, gpointer data ){ + Patch_AutoCapTexture(); +} + static void OnSpinChanged( GtkAdjustment *adj, gpointer data ){ texdef_t td; @@ -998,6 +1002,13 @@ GtkWindow* PatchInspector::BuildDialog(){ GtkHBox* hbox2 = GTK_HBOX( gtk_hbox_new( TRUE, 5 ) ); gtk_widget_show( GTK_WIDGET( hbox2 ) ); gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( hbox2 ), TRUE, FALSE, 0 ); + { + GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "Auto Cap" ) ); + gtk_widget_show( GTK_WIDGET( button ) ); + gtk_box_pack_end( GTK_BOX( hbox2 ), GTK_WIDGET( button ), TRUE, FALSE, 0 ); + g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( OnBtnPatchAutoCap ), 0 ); + gtk_widget_set_usize( GTK_WIDGET( button ), 60, -1 ); + } { GtkButton* button = GTK_BUTTON( gtk_button_new_with_label( "CAP" ) ); gtk_widget_show( GTK_WIDGET( button ) ); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index e42fdc37..e7f543dc 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -196,6 +196,34 @@ void Scene_PatchCapTexture_Selected( scene::Graph& graph ){ SceneChangeNotify(); } + +void PatchAutoCapTexture( Patch& patch ) { + + AABB box = patch.localAABB(); + float x = box.extents.x(); + float y = box.extents.y(); + float z = box.extents.z(); + + int cap_direction = -1; + if ( x < y && x < z ) + cap_direction = 0; + else if ( y < x && y < z ) + cap_direction = 1; + else if ( z < x && z < x ) + cap_direction = 2; + + if ( cap_direction >= 0 ) + patch.ProjectTexture(cap_direction); + else + patch.NaturalTexture(); +} + +void Patch_AutoCapTexture(){ + UndoableCommand command( "patchAutoCapTexture" ); + Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture ); + SceneChangeNotify(); +} + class PatchFlipTexture { int m_axis; diff --git a/radiant/patchmanip.h b/radiant/patchmanip.h index d6d8764c..47f7f224 100644 --- a/radiant/patchmanip.h +++ b/radiant/patchmanip.h @@ -57,6 +57,7 @@ void Patch_ResetTexture(); void Patch_FitTexture(); void Patch_FlipTextureX(); void Patch_FlipTextureY(); +void Patch_AutoCapTexture(); class PatchCreator; extern PatchCreator* g_patchCreator; -- 2.39.2