]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Auto cap button
authorMattia Basaglia <mattia.basaglia@gmail.com>
Sun, 19 Jul 2015 08:21:42 +0000 (10:21 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Sun, 19 Jul 2015 08:21:42 +0000 (10:21 +0200)
radiant/patchdialog.cpp
radiant/patchmanip.cpp
radiant/patchmanip.h

index 6bacd9f8b6c4ec5c28bb8c23b646d929ffb5c43c..f1bf09fb44154aff7d618f99fed30e8fe2b76337 100644 (file)
@@ -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 ) );
index e42fdc37edce1823c24d8a04d838b2ee07d341cb..e7f543dc27ff71cc1f15b64081be4a4ee3cf30c0 100644 (file)
@@ -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;
index d6d8764cb65389f41ea4337a29a9568800d35d8a..47f7f2248e201e26aeb70d7cdb8eabcd3ad406fc 100644 (file)
@@ -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;