]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patchmanip.cpp
Wrap GtkAccelGroup
[xonotic/netradiant.git] / radiant / patchmanip.cpp
index e42fdc37edce1823c24d8a04d838b2ee07d341cb..f4e9c17d85e84e9f0a436a5da64443eb174deba9 100644 (file)
@@ -67,6 +67,32 @@ void Scene_PatchConstructPrefab( scene::Graph& graph, const AABB aabb, const cha
        }
 }
 
+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();
+}
 
 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
        if ( ( type == eCapEndCap || type == eCapIEndCap )
@@ -89,8 +115,10 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co
                NodeSmartReference cap( g_patchCreator->createPatch() );
                Node_getTraversable( instance.path().parent() )->insert( cap );
 
-               patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
-               Node_getPatch( cap )->SetShader( shader );
+               Patch* cap_patch = Node_getPatch( cap );
+               patch.MakeCap( cap_patch, type, ROW, true );
+               cap_patch->SetShader( shader );
+               PatchAutoCapTexture(*cap_patch);
 
                scene::Path path( instance.path() );
                path.pop();
@@ -102,8 +130,10 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co
                NodeSmartReference cap( g_patchCreator->createPatch() );
                Node_getTraversable( instance.path().parent() )->insert( cap );
 
-               patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
-               Node_getPatch( cap )->SetShader( shader );
+               Patch* cap_patch = Node_getPatch( cap );
+               patch.MakeCap( cap_patch, type, ROW, false );
+               cap_patch->SetShader( shader );
+               PatchAutoCapTexture(*cap_patch);
 
                scene::Path path( instance.path() );
                path.pop();
@@ -311,7 +341,7 @@ void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
        SceneChangeNotify();
 }
 
-void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
+void Scene_PatchGetShader_Selected( scene::Graph& graph, std::string& name ){
        Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
        if ( patch != 0 ) {
                name = patch->GetShader();
@@ -714,7 +744,7 @@ void Patch_registerCommands(){
 }
 
 void Patch_constructToolbar( GtkToolbar* toolbar ){
-       toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.bmp", "CapCurrentCurve" );
+       toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
 }
 
 void Patch_constructMenu( GtkMenu* menu ){
@@ -821,9 +851,9 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
        GtkComboBox* width;
        GtkComboBox* height;
 
-       GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
+       ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
 
-       GtkAccelGroup* accel = gtk_accel_group_new();
+       GtkAccelGroup* accel = ui::AccelGroup();
        gtk_window_add_accel_group( window, accel );
 
        {
@@ -833,7 +863,7 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
                        GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
                        gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
                        {
-                               GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
+                               GtkLabel* label = GTK_LABEL( ui::Label( "Width:" ) );
                                gtk_widget_show( GTK_WIDGET( label ) );
                                gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
                                                                  (GtkAttachOptions) ( GTK_FILL ),
@@ -841,7 +871,7 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
                                gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                        }
                        {
-                               GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
+                               GtkLabel* label = GTK_LABEL( ui::Label( "Height:" ) );
                                gtk_widget_show( GTK_WIDGET( label ) );
                                gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
                                                                  (GtkAttachOptions) ( GTK_FILL ),
@@ -942,15 +972,15 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
        ModalDialog dialog;
        ModalDialogButton ok_button( dialog, eIDOK );
        ModalDialogButton cancel_button( dialog, eIDCANCEL );
-       GtkWidget* bevel;
-       GtkWidget* ibevel;
-       GtkWidget* endcap;
-       GtkWidget* iendcap;
-       GtkWidget* cylinder;
+       ui::Widget bevel;
+       ui::Widget ibevel;
+       ui::Widget endcap;
+       ui::Widget iendcap;
+       ui::Widget cylinder;
 
-       GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
+       ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
 
-       GtkAccelGroup *accel_group = gtk_accel_group_new();
+       GtkAccelGroup *accel_group = ui::AccelGroup();
        gtk_window_add_accel_group( window, accel_group );
 
        {
@@ -963,42 +993,42 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                        gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
 
                        {
-                               GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
+                               GtkTable* table = ui::Table( 5, 2, FALSE );
                                gtk_widget_show( GTK_WIDGET( table ) );
                                gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
                                gtk_table_set_row_spacings( table, 5 );
                                gtk_table_set_col_spacings( table, 5 );
 
                                {
-                                       GtkImage* image = new_local_image( "cap_bevel.bmp" );
+                                       GtkImage* image = new_local_image( "cap_bevel.png" );
                                        gtk_widget_show( GTK_WIDGET( image ) );
                                        gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
                                }
                                {
-                                       GtkImage* image = new_local_image( "cap_endcap.bmp" );
+                                       GtkImage* image = new_local_image( "cap_endcap.png" );
                                        gtk_widget_show( GTK_WIDGET( image ) );
                                        gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
                                }
                                {
-                                       GtkImage* image = new_local_image( "cap_ibevel.bmp" );
+                                       GtkImage* image = new_local_image( "cap_ibevel.png" );
                                        gtk_widget_show( GTK_WIDGET( image ) );
                                        gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
                                }
                                {
-                                       GtkImage* image = new_local_image( "cap_iendcap.bmp" );
+                                       GtkImage* image = new_local_image( "cap_iendcap.png" );
                                        gtk_widget_show( GTK_WIDGET( image ) );
                                        gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
                                }
                                {
-                                       GtkImage* image = new_local_image( "cap_cylinder.bmp" );
+                                       GtkImage* image = new_local_image( "cap_cylinder.png" );
                                        gtk_widget_show( GTK_WIDGET( image ) );
                                        gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
@@ -1007,7 +1037,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
 
                                GSList* group = 0;
                                {
-                                       GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
+                                       ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Bevel" ));
                                        gtk_widget_show( button );
                                        gtk_table_attach( table, button, 1, 2, 0, 1,
                                                                          (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
@@ -1017,7 +1047,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                        bevel = button;
                                }
                                {
-                                       GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
+                                       ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Endcap" ));
                                        gtk_widget_show( button );
                                        gtk_table_attach( table, button, 1, 2, 1, 2,
                                                                          (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
@@ -1027,7 +1057,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                        endcap = button;
                                }
                                {
-                                       GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
+                                       ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
                                        gtk_widget_show( button );
                                        gtk_table_attach( table, button, 1, 2, 2, 3,
                                                                          (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
@@ -1037,7 +1067,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                        ibevel = button;
                                }
                                {
-                                       GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
+                                       ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
                                        gtk_widget_show( button );
                                        gtk_table_attach( table, button, 1, 2, 3, 4,
                                                                          (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
@@ -1047,7 +1077,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                        iendcap = button;
                                }
                                {
-                                       GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
+                                       ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Cylinder" ));
                                        gtk_widget_show( button );
                                        gtk_table_attach( table, button, 1, 2, 4, 5,
                                                                          (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),