]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.cpp
Wrap GtkGLArea
[xonotic/netradiant.git] / libs / uilib / uilib.cpp
index 1e37a1e05287b73f53b3d366d4370777b5299340..824af8cef43a7530754664e9739df4c70739fb92 100644 (file)
@@ -22,7 +22,14 @@ namespace ui {
         gtk_main();
     }
 
-    Widget root{nullptr};
+    void process()
+    {
+        while (gtk_events_pending()) {
+            gtk_main_iteration();
+        }
+    }
+
+    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)); } }
@@ -32,7 +39,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);
 
@@ -83,10 +90,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 :
@@ -310,4 +328,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
+    };
+
 }