]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/map.cpp
Implement buffer operations
[xonotic/netradiant.git] / radiant / map.cpp
index cdcb1afeefcf1cc5e60a1e63955d3d46821d0f07..c94d8efc91b83d06a715e7c9ef1fdb4d5fb4f927 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "map.h"
 
+#include <gtk/gtk.h>
+
 #include "debugging/debugging.h"
 
 #include "imap.h"
@@ -43,6 +45,7 @@ MapModules& ReferenceAPI_getMapModules();
 #include <set>
 
 #include <gdk/gdkkeysyms.h>
+#include <util/buffer.h>
 #include "uilib/uilib.h"
 
 #include "scenelib.h"
@@ -149,8 +152,8 @@ void detach( const NameCallback& setName, const NameCallbackCallback& detachObse
 }
 
 void makeUnique( const char* name, const NameCallback& setName ) const {
-       char buffer[1024];
-       name_write( buffer, m_uniqueNames.make_unique( name_read( name ) ) );
+       auto buffer = u::buffer<1024>();
+       name_write( buffer.mut(), m_uniqueNames.make_unique( name_read( name ) ) );
        setName( buffer );
 }
 
@@ -171,8 +174,8 @@ void mergeNames( const BasicNamespace& other ) const {
                name_t uniqueName( uniqueNames.make_unique( name_read( ( *i ).first.c_str() ) ) );
                uniqueNames.insert( uniqueName );
 
-               char buffer[1024];
-               name_write( buffer, uniqueName );
+               auto buffer = u::buffer<1024>();
+               name_write( buffer.mut(), uniqueName );
 
                //globalOutputStream() << "renaming " << makeQuoted((*i).first.c_str()) << " to " << makeQuoted(buffer) << "\n";
 
@@ -761,17 +764,17 @@ WindowPosition g_posMapInfoWnd( c_default_window_pos );
 
 void DoMapInfo(){
        ModalDialog dialog;
-       GtkEntry* brushes_entry;
-       GtkEntry* entities_entry;
-       ui::ListStore EntityBreakdownWalker{nullptr};
+       ui::Entry brushes_entry{ui::null};
+       ui::Entry entities_entry{ui::null};
+       ui::ListStore EntityBreakdownWalker{ui::null};
 
        ui::Window window = MainFrame_getWindow().create_dialog_window("Map Info", G_CALLBACK(dialog_delete_callback ), &dialog );
 
        window_set_position( window, g_posMapInfoWnd );
 
        {
-               GtkVBox* vbox = create_dialog_vbox( 4, 4 );
-               gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) );
+               auto vbox = create_dialog_vbox( 4, 4 );
+               window.add(vbox);
 
                {
                        GtkHBox* hbox = create_dialog_hbox( 4 );
@@ -782,8 +785,8 @@ void DoMapInfo(){
                                gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
 
                                {
-                                       auto entry = ui::Entry();
-                                       gtk_widget_show( GTK_WIDGET( entry ) );
+                                       auto entry = ui::Entry(ui::New);
+                                       entry.show();
                                        gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
                                                                          (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -792,8 +795,8 @@ void DoMapInfo(){
                                        brushes_entry = entry;
                                }
                                {
-                                       auto entry = ui::Entry();
-                                       gtk_widget_show( GTK_WIDGET( entry ) );
+                                       auto entry = ui::Entry(ui::New);
+                                       entry.show();
                                        gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
                                                                          (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -803,7 +806,7 @@ void DoMapInfo(){
                                }
                                {
                                        ui::Widget label = ui::Label( "Total Brushes" );
-                                       gtk_widget_show( label );
+                                       label.show();
                                        gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -811,7 +814,7 @@ void DoMapInfo(){
                                }
                                {
                                        ui::Widget label = ui::Label( "Total Entities" );
-                                       gtk_widget_show( label );
+                                       label.show();
                                        gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
                                                                          (GtkAttachOptions) ( GTK_FILL ),
                                                                          (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -830,12 +833,12 @@ void DoMapInfo(){
                }
                {
                        ui::Widget label = ui::Label( "Entity breakdown" );
-                       gtk_widget_show( label );
+                       label.show();
                        gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, TRUE, 0 );
                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                }
                {
-                       GtkScrolledWindow* scr = create_scrolled_window( GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4 );
+                       auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 );
                        gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( scr ), TRUE, TRUE, 0 );
 
                        {
@@ -845,22 +848,22 @@ void DoMapInfo(){
                                gtk_tree_view_set_headers_clickable( GTK_TREE_VIEW( view ), TRUE );
 
                                {
-                                       auto renderer = ui::CellRendererText();
+                                       auto renderer = ui::CellRendererText(ui::New);
                                        GtkTreeViewColumn* column = ui::TreeViewColumn( "Entity", renderer, {{"text", 0}} );
                                        gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
                                        gtk_tree_view_column_set_sort_column_id( column, 0 );
                                }
 
                                {
-                                       auto renderer = ui::CellRendererText();
+                                       auto renderer = ui::CellRendererText(ui::New);
                                        GtkTreeViewColumn* column = ui::TreeViewColumn( "Count", renderer, {{"text", 1}} );
                                        gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
                                        gtk_tree_view_column_set_sort_column_id( column, 1 );
                                }
 
-                               gtk_widget_show( view );
+                               view.show();
 
-                               gtk_container_add( GTK_CONTAINER( scr ), view );
+                               scr.add(view);
 
                                EntityBreakdownWalker = store;
                        }
@@ -875,21 +878,21 @@ void DoMapInfo(){
 
                for ( EntityBreakdown::iterator i = entitymap.begin(); i != entitymap.end(); ++i )
                {
-                       char tmp[16];
-                       sprintf( tmp, "%u", Unsigned( ( *i ).second ) );
+                       auto tmp = u::buffer<16>();
+                       tmp.sprintf( "%u", Unsigned( ( *i ).second ) );
                        GtkTreeIter iter;
                        gtk_list_store_append( GTK_LIST_STORE( EntityBreakdownWalker ), &iter );
                        gtk_list_store_set( GTK_LIST_STORE( EntityBreakdownWalker ), &iter, 0, ( *i ).first.c_str(), 1, tmp, -1 );
                }
        }
 
-       g_object_unref( G_OBJECT( EntityBreakdownWalker ) );
+       EntityBreakdownWalker.unref();
 
-       char tmp[16];
-       sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) );
-       gtk_entry_set_text( GTK_ENTRY( brushes_entry ), tmp );
-       sprintf( tmp, "%u", Unsigned( g_entityCount.get() ) );
-       gtk_entry_set_text( GTK_ENTRY( entities_entry ), tmp );
+       auto tmp = u::buffer<16>();
+    tmp.sprintf( "%u", Unsigned( g_brushCount.get() ) );
+       brushes_entry.text(tmp);
+    tmp.sprintf( "%u", Unsigned( g_entityCount.get() ) );
+       entities_entry.text(tmp);
 
        modal_dialog_show( window, dialog );
 
@@ -1265,10 +1268,10 @@ void ConstructRegionStartpoint( scene::Node* startpoint, const Vector3& region_m
        }
 
        // write the info_playerstart
-       char sTmp[1024];
-       sprintf( sTmp, "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] );
+       auto sTmp = u::buffer<1024>();
+       sTmp.sprintf( "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] );
        Node_getEntity( *startpoint )->setKeyValue( "origin", sTmp );
-       sprintf( sTmp, "%d", (int)Camera_getAngles( *g_pParentWnd->GetCamWnd() )[CAMERA_YAW] );
+       sTmp.sprintf( "%d", (int)Camera_getAngles( *g_pParentWnd->GetCamWnd() )[CAMERA_YAW] );
        Node_getEntity( *startpoint )->setKeyValue( "angle", sTmp );
 }
 
@@ -2034,37 +2037,37 @@ static void GetSelectionIndex( int *ent, int *brush ){
 
 void DoFind(){
        ModalDialog dialog;
-       GtkEntry* entity;
-       GtkEntry* brush;
+       ui::Entry entity{ui::null};
+       ui::Entry brush{ui::null};
 
        ui::Window window = MainFrame_getWindow().create_dialog_window("Find Brush", G_CALLBACK(dialog_delete_callback ), &dialog );
 
-       auto accel = ui::AccelGroup();
+       auto accel = ui::AccelGroup(ui::New);
        window.add_accel_group( accel );
 
        {
-               GtkVBox* vbox = create_dialog_vbox( 4, 4 );
-               gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) );
+               auto vbox = create_dialog_vbox( 4, 4 );
+               window.add(vbox);
                {
                        GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
                        gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
                        {
                                ui::Widget label = ui::Label( "Entity number" );
-                               gtk_widget_show( label );
+                               label.show();
                                gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
                                                                  (GtkAttachOptions) ( 0 ),
                                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
                        }
                        {
                                ui::Widget label = ui::Label( "Brush number" );
-                               gtk_widget_show( label );
+                               label.show();
                                gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
                                                                  (GtkAttachOptions) ( 0 ),
                                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
                        }
                        {
-                               auto entry = ui::Entry();
-                               gtk_widget_show( GTK_WIDGET( entry ) );
+                               auto entry = ui::Entry(ui::New);
+                               entry.show();
                                gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
                                                                  (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
                                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -2072,8 +2075,8 @@ void DoFind(){
                                entity = entry;
                        }
                        {
-                               auto entry = ui::Entry();
-                               gtk_widget_show( GTK_WIDGET( entry ) );
+                               auto entry = ui::Entry(ui::New);
+                               entry.show();
                                gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
                                                                  (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
                                                                  (GtkAttachOptions) ( 0 ), 0, 0 );
@@ -2099,14 +2102,14 @@ void DoFind(){
        }
 
        // Initialize dialog
-       char buf[16];
+       auto buf = u::buffer<16>();
        int ent, br;
 
        GetSelectionIndex( &ent, &br );
-       sprintf( buf, "%i", ent );
-       gtk_entry_set_text( entity, buf );
-       sprintf( buf, "%i", br );
-       gtk_entry_set_text( brush, buf );
+       buf.sprintf( "%i", ent );
+       entity.text(buf);
+       buf.sprintf( "%i", br );
+       brush.text(buf);
 
        if ( modal_dialog_show( window, dialog ) == eIDOK ) {
                const char *entstr = gtk_entry_get_text( entity );