]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.cpp
Rebase onto master
[xonotic/netradiant.git] / libs / uilib / uilib.cpp
index e91f03fe813e0be768cae3a01faeff81b35735a4..f25172242acbcd48fe45e534039a50bd7802cf9e 100644 (file)
 
 namespace ui {
 
-    void init(int argc, char *argv[])
+    bool init(int *argc, char **argv[], char const *parameter_string, char const **error)
     {
         gtk_disable_setlocale();
-        gtk_init(&argc, &argv);
+        static GOptionEntry entries[] = {{NULL}};
+        char const *translation_domain = NULL;
+        GError *gerror = NULL;
+        bool ret = gtk_init_with_args(argc, argv, parameter_string, entries, translation_domain, &gerror) != 0;
+        if (!ret) {
+            *error = gerror->message;
+        }
+        return ret;
     }
 
     void main()
@@ -29,7 +36,7 @@ namespace ui {
         }
     }
 
-    Widget root{nullptr};
+    Widget root;
 
 #define IMPL(T, F) template<> _IMPL(T, F)
 #define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self(F(it)); } }
@@ -39,7 +46,7 @@ namespace ui {
 
     template<class T> _IMPL(T,);
 
-#define this verify<self>::test(*static_cast<self>(this))
+#define this (verify<self>::test(*static_cast<self>(this)))
 
     IMPL(Editable, GTK_EDITABLE);
 
@@ -90,10 +97,21 @@ namespace ui {
         gtk_widget_show(this);
     }
 
-    IMPL(Window, GTK_WINDOW);
+    IMPL(Container, GTK_CONTAINER);
 
-    Window::Window() : Window(nullptr)
-    {}
+    void IContainer::add(Widget widget)
+    {
+        gtk_container_add(this, widget);
+    }
+
+    void IContainer::remove(Widget widget)
+    {
+        gtk_container_remove(this, widget);
+    }
+
+    IMPL(Bin, GTK_BIN);
+
+    IMPL(Window, GTK_WINDOW);
 
     Window::Window(window_type type) : Window(GTK_WINDOW(gtk_window_new(
             type == window_type::TOP ? GTK_WINDOW_TOPLEVEL :
@@ -317,4 +335,16 @@ namespace ui {
     TreePath::TreePath(const char *path) : TreePath(gtk_tree_path_new_from_string(path))
     {}
 
+    // Custom
+
+    guint IGLArea::on_render(GCallback pFunction, void *data)
+    {
+#if GTK_TARGET == 3
+        return this.connect("render", pFunction, data);
+#endif
+#if GTK_TARGET == 2
+        return this.connect("expose_event", pFunction, data);
+#endif
+    };
+
 }