From: Mattia Basaglia Date: Sun, 19 Jul 2015 08:21:42 +0000 (+0200) Subject: Auto cap button X-Git-Tag: xonotic-v0.8.1~1^2~5^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c311c99f37bcc60d30955a47117368fc8b83d9da;p=xonotic%2Fnetradiant.git Auto cap button --- 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;