]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patchmanip.cpp
Callback: remove fixed-arity wrappers
[xonotic/netradiant.git] / radiant / patchmanip.cpp
index 572e8e9b533eeebc4f2bbf5f1cf6366f673de51d..ceca948de79954d58c3141c1f2bdc64359a6c50d 100644 (file)
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <gdk/gdkkeysyms.h>
 #include "patchmanip.h"
 
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
 #include "debugging/debugging.h"
 
 
@@ -145,17 +147,6 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co
 
 typedef std::vector<scene::Instance*> InstanceVector;
 
-class PatchStoreInstance
-{
-InstanceVector& m_instances;
-public:
-PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
-}
-void operator()( PatchInstance& patch ) const {
-       m_instances.push_back( &patch );
-}
-};
-
 enum ECapDialog {
        PATCHCAP_BEVEL = 0,
        PATCHCAP_ENDCAP,
@@ -194,7 +185,9 @@ void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
                }
 
                InstanceVector instances;
-               Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
+               Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
+                       instances.push_back(&patch);
+               });
                for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
                {
                        Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
@@ -213,132 +206,62 @@ Patch* Scene_GetUltimateSelectedVisiblePatch(){
 }
 
 
-class PatchCapTexture
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.ProjectTexture( Patch::m_CycleCapIndex );
-}
-};
-
 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.ProjectTexture(Patch::m_CycleCapIndex);
+       });
        Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
        SceneChangeNotify();
 }
 
-class PatchFlipTexture
-{
-int m_axis;
-public:
-PatchFlipTexture( int axis ) : m_axis( axis ){
-}
-void operator()( Patch& patch ) const {
-       patch.FlipTexture( m_axis );
-}
-};
-
 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
-       Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.FlipTexture(axis);
+       });
 }
 
-class PatchNaturalTexture
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.NaturalTexture();
-}
-};
-
 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.NaturalTexture();
+       });
        SceneChangeNotify();
 }
 
 
-class PatchInsertRemove
-{
-bool m_insert, m_column, m_first;
-public:
-PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
-}
-void operator()( Patch& patch ) const {
-       patch.InsertRemove( m_insert, m_column, m_first );
-}
-};
-
 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
-       Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.InsertRemove(bInsert, bColumn, bFirst);
+       });
 }
 
-class PatchInvertMatrix
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.InvertMatrix();
-}
-};
-
 void Scene_PatchInvert_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.InvertMatrix();
+       });
 }
 
-class PatchRedisperse
-{
-EMatrixMajor m_major;
-public:
-PatchRedisperse( EMatrixMajor major ) : m_major( major ){
-}
-void operator()( Patch& patch ) const {
-       patch.Redisperse( m_major );
-}
-};
-
 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
-       Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
-}
-
-class PatchSmooth
-{
-EMatrixMajor m_major;
-public:
-PatchSmooth( EMatrixMajor major ) : m_major( major ){
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.Redisperse(major);
+       });
 }
-void operator()( Patch& patch ) const {
-       patch.Smooth( m_major );
-}
-};
 
 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
-       Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.Smooth(major);
+       });
 }
 
-class PatchTransposeMatrix
-{
-public:
-void operator()( Patch& patch ) const {
-       patch.TransposeMatrix();
-}
-};
-
 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
-       Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
-}
-
-class PatchSetShader
-{
-const char* m_name;
-public:
-PatchSetShader( const char* name )
-       : m_name( name ){
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.TransposeMatrix();
+       });
 }
-void operator()( Patch& patch ) const {
-       patch.SetShader( m_name );
-}
-};
 
 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
-       Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               patch.SetShader(name);
+       });
        SceneChangeNotify();
 }
 
@@ -349,45 +272,29 @@ void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
        }
 }
 
-class PatchSelectByShader
-{
-const char* m_name;
-public:
-inline PatchSelectByShader( const char* name )
-       : m_name( name ){
-}
-void operator()( PatchInstance& patch ) const {
-       if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
-               patch.setSelected( true );
-       }
-}
-};
-
 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
-       Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
+       Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
+               if (shader_equal(patch.getPatch().GetShader(), name)) {
+                       patch.setSelected(true);
+               }
+       });
 }
 
 
-class PatchFindReplaceShader
-{
-const char* m_find;
-const char* m_replace;
-public:
-PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
-}
-void operator()( Patch& patch ) const {
-       if ( shader_equal( patch.GetShader(), m_find ) ) {
-               patch.SetShader( m_replace );
-       }
-}
-};
-
 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
+       Scene_forEachVisiblePatch([&](Patch &patch) {
+               if (shader_equal(patch.GetShader(), find)) {
+                       patch.SetShader(replace);
+               }
+       });
 }
 
 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
+       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
+               if (shader_equal(patch.GetShader(), find)) {
+                       patch.SetShader(replace);
+               }
+       });
 }
 
 
@@ -693,7 +600,7 @@ void Patch_constructPage( PreferenceGroup& group ){
        Patch_constructPreferences( page );
 }
 void Patch_registerPreferencesPage(){
-       PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
+       PreferencesDialog_addDisplayPage( FreeCaller<void(PreferenceGroup&), Patch_constructPage>() );
 }
 
 
@@ -707,41 +614,41 @@ void PatchPreferences_construct(){
 #include "generic/callback.h"
 
 void Patch_registerCommands(){
-       GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
-       GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
-       GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
-       GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
-       GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
-       GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
-       GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
-       GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
-       GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
-       GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
-       GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
-       GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
-       GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
-       GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
-       GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
-       GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>() );
-       GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>() );
-       GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
-       GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>() );
-       GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
-       GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
-       GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
-       GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
-       GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<void(), Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<void(), Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
+       GlobalCommands_insert( "NaturalizePatch", FreeCaller<void(), Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "PatchCylinder", FreeCaller<void(), Patch_Cylinder>() );
+       GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<void(), Patch_DenseCylinder>() );
+       GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<void(), Patch_VeryDenseCylinder>() );
+       GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<void(), Patch_SquareCylinder>() );
+       GlobalCommands_insert( "PatchXactCylinder", FreeCaller<void(), Patch_XactCylinder>() );
+       GlobalCommands_insert( "PatchXactSphere", FreeCaller<void(), Patch_XactSphere>() );
+       GlobalCommands_insert( "PatchXactCone", FreeCaller<void(), Patch_XactCone>() );
+       GlobalCommands_insert( "PatchEndCap", FreeCaller<void(), Patch_Endcap>() );
+       GlobalCommands_insert( "PatchBevel", FreeCaller<void(), Patch_Bevel>() );
+       GlobalCommands_insert( "PatchSquareBevel", FreeCaller<void(), Patch_SquareBevel>() );
+       GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<void(), Patch_SquareEndcap>() );
+       GlobalCommands_insert( "PatchCone", FreeCaller<void(), Patch_Cone>() );
+       GlobalCommands_insert( "PatchSphere", FreeCaller<void(), Patch_Sphere>() );
+       GlobalCommands_insert( "SimplePatchMesh", FreeCaller<void(), Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
+       GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<void(), Patch_InsertInsertColumn>(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<void(), Patch_InsertAddColumn>() );
+       GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<void(), Patch_InsertInsertRow>(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<void(), Patch_InsertAddRow>() );
+       GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<void(), Patch_DeleteFirstColumn>() );
+       GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<void(), Patch_DeleteLastColumn>(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<void(), Patch_DeleteFirstRow>(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<void(), Patch_DeleteLastRow>() );
+       GlobalCommands_insert( "InvertCurve", FreeCaller<void(), Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "RedisperseRows", FreeCaller<void(), Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "RedisperseCols", FreeCaller<void(), Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "SmoothRows", FreeCaller<void(), Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "SmoothCols", FreeCaller<void(), Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "MatrixTranspose", FreeCaller<void(), Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "CapCurrentCurve", FreeCaller<void(), Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
+       GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<void(), Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<void(), Patch_OverlayOn>(), Accelerator( 'Y' ) );
+       GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<void(), Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
 }
 
 void Patch_constructToolbar( ui::Toolbar toolbar ){
@@ -848,35 +755,31 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
 
        ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
 
-       auto accel = ui::AccelGroup();
+       auto accel = ui::AccelGroup(ui::New);
        window.add_accel_group( accel );
 
        {
-               GtkHBox* hbox = create_dialog_hbox( 4, 4 );
-               gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
+               auto hbox = create_dialog_hbox( 4, 4 );
+               window.add(hbox);
                {
-                       GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
+                       auto table = create_dialog_table( 2, 2, 4, 4 );
+                       hbox.pack_start( table, TRUE, TRUE, 0 );
                        {
                                auto label = ui::Label( "Width:" );
                                label.show();
-                               gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
-                                                                 (GtkAttachOptions) ( GTK_FILL ),
-                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+                table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
                                gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                        }
                        {
                                auto label = ui::Label( "Height:" );
                                label.show();
-                               gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
-                                                                 (GtkAttachOptions) ( GTK_FILL ),
-                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+                table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
                                gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                        }
 
                        {
-                               auto combo = ui::ComboBoxText();
-#define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, # x )
+                               auto combo = ui::ComboBoxText(ui::New);
+#define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x )
                                D_ITEM( 3 );
                                D_ITEM( 5 );
                                D_ITEM( 7 );
@@ -894,15 +797,13 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
                                D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
 #undef D_ITEM
                                combo.show();
-                               gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
-                                                                 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+                table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
 
                                width = combo;
                        }
                        {
-                               auto combo = ui::ComboBoxText();
-#define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, # x )
+                               auto combo = ui::ComboBoxText(ui::New);
+#define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x )
                                D_ITEM( 3 );
                                D_ITEM( 5 );
                                D_ITEM( 7 );
@@ -920,28 +821,26 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
                                D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
 #undef D_ITEM
                                combo.show();
-                               gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
-                                                                 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+                table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
 
                                height = combo;
                        }
                }
 
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+                       auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, TRUE, TRUE, 0 );
                        {
                                auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_grab_focus( GTK_WIDGET( button ) );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+                               gtk_widget_grab_focus( button  );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                        {
-                               GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+                               auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                }
        }
@@ -957,7 +856,7 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
                Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 }
 
 
@@ -967,76 +866,64 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
        ModalDialog dialog;
        ModalDialogButton ok_button( dialog, eIDOK );
        ModalDialogButton cancel_button( dialog, eIDCANCEL );
-       ui::Widget bevel;
-       ui::Widget ibevel;
-       ui::Widget endcap;
-       ui::Widget iendcap;
-       ui::Widget cylinder;
+       ui::Widget bevel{ui::null};
+       ui::Widget ibevel{ui::null};
+       ui::Widget endcap{ui::null};
+       ui::Widget iendcap{ui::null};
+       ui::Widget cylinder{ui::null};
 
        ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
 
-       auto accel_group = ui::AccelGroup();
+       auto accel_group = ui::AccelGroup(ui::New);
        window.add_accel_group( accel_group );
 
        {
-               GtkHBox* hbox = create_dialog_hbox( 4, 4 );
-               gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
+               auto hbox = create_dialog_hbox( 4, 4 );
+               window.add(hbox);
 
                {
                        // Gef: Added a vbox to contain the toggle buttons
-                       GtkVBox* radio_vbox = create_dialog_vbox( 4 );
-                       gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
+                       auto radio_vbox = create_dialog_vbox( 4 );
+                       hbox.add(radio_vbox);
 
                        {
                                auto table = ui::Table( 5, 2, FALSE );
                                table.show();
-                               gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
+                               radio_vbox.pack_start( table, TRUE, TRUE, 0 );
                                gtk_table_set_row_spacings( table, 5 );
                                gtk_table_set_col_spacings( table, 5 );
 
                                {
                                        auto image = new_local_image( "cap_bevel.png" );
                                        image.show();
-                                       gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(image, {0, 1, 0, 1}, {GTK_FILL, 0});
                                }
                                {
                                        auto image = new_local_image( "cap_endcap.png" );
                                        image.show();
-                                       gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(image, {0, 1, 1, 2}, {GTK_FILL, 0});
                                }
                                {
                                        auto image = new_local_image( "cap_ibevel.png" );
                                        image.show();
-                                       gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(image, {0, 1, 2, 3}, {GTK_FILL, 0});
                                }
                                {
                                        auto image = new_local_image( "cap_iendcap.png" );
                                        image.show();
-                                       gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(image, {0, 1, 3, 4}, {GTK_FILL, 0});
                                }
                                {
                                        auto image = new_local_image( "cap_cylinder.png" );
                                        image.show();
-                                       gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(image, {0, 1, 4, 5}, {GTK_FILL, 0});
                                }
 
                                GSList* group = 0;
                                {
                                        ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Bevel" ));
                                        button.show();
-                                       gtk_table_attach( table, button, 1, 2, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
                                        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
 
                                        bevel = button;
@@ -1044,9 +931,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                {
                                        ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Endcap" ));
                                        button.show();
-                                       gtk_table_attach( table, button, 1, 2, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
                                        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
 
                                        endcap = button;
@@ -1054,9 +939,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                {
                                        ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
                                        button.show();
-                                       gtk_table_attach( table, button, 1, 2, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
                                        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
 
                                        ibevel = button;
@@ -1064,9 +947,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                {
                                        ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
                                        button.show();
-                                       gtk_table_attach( table, button, 1, 2, 3, 4,
-                                                                         (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
                                        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
 
                                        iendcap = button;
@@ -1074,9 +955,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                                {
                                        ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Cylinder" ));
                                        button.show();
-                                       gtk_table_attach( table, button, 1, 2, 4, 5,
-                                                                         (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
                                        group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
 
                                        cylinder = button;
@@ -1085,18 +964,18 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                }
 
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
+                       auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
                        {
                                auto button = create_modal_dialog_button( "OK", ok_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                        {
-                               GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                               auto button = create_modal_dialog_button( "Cancel", cancel_button );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                }
        }
@@ -1123,7 +1002,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){
                }
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 
        return ret;
 }