]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/csg.cpp
Merge commit '7ca59bef0ae15880f51b2f68104b933e918d543c' into garux-merge
[xonotic/netradiant.git] / radiant / csg.cpp
index 1b0d6004e622366d14852a53e312386afff429b3..27f05bf5b64396d23e9eaa2d4dd1bcbce00da033 100644 (file)
@@ -29,6 +29,7 @@
 #include "brushmanip.h"
 #include "brushnode.h"
 #include "grid.h"
+
 /*
 void Face_makeBrush( Face& face, const Brush& brush, brush_vector_t& out, float offset ){
        if ( face.contributes() ) {
@@ -368,6 +369,7 @@ public:
 BrushGatherSelected( brush_vector_t& brushlist )
        : m_brushlist( brushlist ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        if ( path.top().get().visible() ) {
                Brush* brush = Node_getBrush( path.top() );
@@ -430,11 +432,9 @@ class Dereference
 {
 const Functor& functor;
 public:
-typedef typename RemoveReference<typename Functor::first_argument_type>::type* first_argument_type;
-typedef typename Functor::result_type result_type;
 Dereference( const Functor& functor ) : functor( functor ){
 }
-result_type operator()( first_argument_type firstArgument ) const {
+get_result_type<Functor> operator()( typename RemoveReference<get_argument<Functor, 0>>::type *firstArgument ) const {
        return functor( *firstArgument );
 }
 };
@@ -456,15 +456,14 @@ Face* Brush_findIf( const Brush& brush, const Predicate& predicate ){
 template<typename Caller>
 class BindArguments1
 {
-typedef typename Caller::second_argument_type FirstBound;
+typedef get_argument<Caller, 1> FirstBound;
 FirstBound firstBound;
 public:
-typedef typename Caller::result_type result_type;
-typedef typename Caller::first_argument_type first_argument_type;
 BindArguments1( FirstBound firstBound )
        : firstBound( firstBound ){
 }
-result_type operator()( first_argument_type firstArgument ) const {
+
+get_result_type<Caller> operator()( get_argument<Caller, 0> firstArgument ) const {
        return Caller::call( firstArgument, firstBound );
 }
 };
@@ -472,17 +471,16 @@ result_type operator()( first_argument_type firstArgument ) const {
 template<typename Caller>
 class BindArguments2
 {
-typedef typename Caller::second_argument_type FirstBound;
-typedef typename Caller::third_argument_type SecondBound;
+typedef get_argument<Caller, 1> FirstBound;
+typedef get_argument<Caller, 2> SecondBound;
 FirstBound firstBound;
 SecondBound secondBound;
 public:
-typedef typename Caller::result_type result_type;
-typedef typename Caller::first_argument_type first_argument_type;
 BindArguments2( FirstBound firstBound, SecondBound secondBound )
        : firstBound( firstBound ), secondBound( secondBound ){
 }
-result_type operator()( first_argument_type firstArgument ) const {
+
+get_result_type<Caller> operator()( get_argument<Caller, 0> firstArgument ) const {
        return Caller::call( firstArgument, firstBound, secondBound );
 }
 };
@@ -495,8 +493,8 @@ BindArguments2<Caller> bindArguments( const Caller& caller, FirstBound firstBoun
 inline bool Face_testPlane( const Face& face, const Plane3& plane, bool flipped ){
        return face.contributes() && !Winding_TestPlane( face.getWinding(), plane, flipped );
 }
-typedef Function3<const Face&, const Plane3&, bool, bool, Face_testPlane> FaceTestPlane;
 
+typedef Function<bool ( const Face &, const Plane3 &, bool ), Face_testPlane> FaceTestPlane;
 
 
 /// \brief Returns true if
@@ -572,9 +570,11 @@ public:
 SubtractBrushesFromUnselected( const brush_vector_t& brushlist, std::size_t& before, std::size_t& after )
        : m_brushlist( brushlist ), m_before( before ), m_after( after ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        return true;
 }
+
 void post( const scene::Path& path, scene::Instance& instance ) const {
        if ( path.top().get().visible() ) {
                Brush* brush = Node_getBrush( path.top() );
@@ -669,9 +669,11 @@ public:
 BrushSplitByPlaneSelected( const Vector3& p0, const Vector3& p1, const Vector3& p2, const char* shader, const TextureProjection& projection, EBrushSplit split )
        : m_p0( p0 ), m_p1( p1 ), m_p2( p2 ), m_shader( shader ), m_projection( projection ), m_split( split ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        return true;
 }
+
 void post( const scene::Path& path, scene::Instance& instance ) const {
        if ( path.top().get().visible() ) {
                Brush* brush = Node_getBrush( path.top() );
@@ -735,6 +737,7 @@ public:
 BrushInstanceSetClipPlane( const Plane3& plane )
        : m_plane( plane ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        BrushInstance* brush = Instance_getBrush( instance );
        if ( brush != 0
@@ -900,7 +903,8 @@ void CSG_Merge( void ){
 struct CSGToolDialog
 {
        GtkSpinButton* spin;
-       GtkWindow *window;
+       bool allocated{false};
+       ui::Window window{ui::null};
        GtkToggleButton *radXYZ, *radX, *radY, *radZ, *caulk, *removeInner;
 };
 
@@ -1024,8 +1028,9 @@ static gboolean CSGdlg_delete( GtkWidget *widget, GdkEventAny *event, CSGToolDia
 }
 
 void CSG_Tool(){
-       if ( g_csgtool_dialog.window == NULL ) {
-               g_csgtool_dialog.window = create_dialog_window( MainFrame_getWindow(), "CSG Tool", G_CALLBACK( CSGdlg_delete ), &g_csgtool_dialog );
+       if ( !g_csgtool_dialog.allocated ) {
+               g_csgtool_dialog.allocated = true;
+               g_csgtool_dialog.window = MainFrame_getWindow().create_dialog_window( "CSG Tool", G_CALLBACK( CSGdlg_delete ), &g_csgtool_dialog );
                gtk_window_set_type_hint( g_csgtool_dialog.window, GDK_WINDOW_TYPE_HINT_UTILITY );
 
                //GtkAccelGroup* accel = gtk_accel_group_new();
@@ -1033,19 +1038,17 @@ void CSG_Tool(){
                global_accel_connect_window( g_csgtool_dialog.window );
 
                {
-                       GtkHBox* hbox = create_dialog_hbox( 4, 4 );
+                       auto hbox = create_dialog_hbox( 4, 4 );
                        gtk_container_add( GTK_CONTAINER( g_csgtool_dialog.window ), GTK_WIDGET( hbox ) );
                        {
-                               GtkTable* table = create_dialog_table( 3, 8, 4, 4 );
+                               auto table = create_dialog_table( 3, 8, 4, 4 );
                                gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
                                {
                                        //GtkWidget* label = gtk_label_new( "<->" );
                                        //gtk_widget_show( label );
-                                       GtkWidget* button = gtk_button_new_with_label( "Grid->" );
-                                       gtk_table_attach( table, button, 0, 1, 0, 1,
-                                                                         (GtkAttachOptions) ( 0 ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
-                                       gtk_widget_show( button );
+                                       auto button = ui::Button( "Grid->" );
+                                       table.attach( button, {0, 1, 0, 1}, {0, 0} );
+                                       button.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_grid2spin ), &g_csgtool_dialog );
                                }
                                {
@@ -1092,26 +1095,24 @@ void CSG_Tool(){
                                }
                                {
                                        GtkWidget* button = gtk_toggle_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "f-caulk.png" );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "f-caulk.png" );
                                        gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
-                                       gtk_table_attach( table, button, 6, 7, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       table.attach( ubutton, { 6, 7, 0, 1 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Caulk some faces" );
                                        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_csgtool_dialog.caulk = GTK_TOGGLE_BUTTON( button );
                                }
                                {
                                        GtkWidget* button = gtk_toggle_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_removeinner.png" );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_removeinner.png" );
                                        gtk_button_set_relief( GTK_BUTTON( button ), GTK_RELIEF_NONE );
-                                       gtk_table_attach( table, button, 7, 8, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       table.attach( ubutton, { 7, 8, 0, 1 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Remove inner brush" );
                                        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( button ), TRUE );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_csgtool_dialog.removeInner = GTK_TOGGLE_BUTTON( button );
                                }
                                {
@@ -1123,62 +1124,56 @@ void CSG_Tool(){
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_shrink.png" );
-                                       gtk_table_attach( table, button, 0, 1, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_shrink.png" );
+                                       table.attach( ubutton, { 0, 1, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Shrink brush" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_BrushShrink ), &g_csgtool_dialog );
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_expand.png" );
-                                       gtk_table_attach( table, button, 1, 2, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_expand.png" );
+                                       table.attach( ubutton, { 1, 2, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Expand brush" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_BrushExpand ), &g_csgtool_dialog );
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_diagonal.png" );
-                                       gtk_table_attach( table, button, 3, 4, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_diagonal.png" );
+                                       table.attach( ubutton, { 3, 4, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Hollow::diagonal joints" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_HollowDiag ), &g_csgtool_dialog );
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_wrap.png" );
-                                       gtk_table_attach( table, button, 4, 5, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_wrap.png" );
+                                       table.attach( ubutton, { 4, 5, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Hollow::warp" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_HollowWrap ), &g_csgtool_dialog );
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_extrude.png" );
-                                       gtk_table_attach( table, button, 5, 6, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_extrude.png" );
+                                       table.attach( ubutton, { 5, 6, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Hollow::extrude faces" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_HollowExtrude ), &g_csgtool_dialog );
                                }
                                {
                                        GtkWidget* button = gtk_button_new();
-                                       button_set_icon( GTK_BUTTON( button ), "csgtool_pull.png" );
-                                       gtk_table_attach( table, button, 6, 7, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                                       auto ubutton = ui::Button::from( button );
+                                       button_set_icon( ubutton, "csgtool_pull.png" );
+                                       table.attach( ubutton, { 6, 7, 2, 3 }, { GTK_EXPAND, 0 } );
                                        gtk_widget_set_tooltip_text( button, "Hollow::pull faces" );
-                                       gtk_widget_show( button );
+                                       ubutton.show();
                                        g_signal_connect( G_OBJECT( button ), "clicked", G_CALLBACK( CSGdlg_HollowPull ), &g_csgtool_dialog );
                                }