]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/uilib/uilib.cpp
Suppress GTK warnings and errors
[xonotic/netradiant.git] / libs / uilib / uilib.cpp
index e4fb3d321351e25f3c429ed19c6e19c427f4eed9..1f4acb1fc7fec334f8501cd33d285bea319d40e3 100644 (file)
@@ -36,10 +36,8 @@ namespace ui {
         }
     }
 
-    Widget root{ui::null};
-
 #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)); } }
+#define _IMPL(T, F) struct verify<T *> { using self = T; static self test(self it) { return self::from(F(it)); } }
 
     template<class T>
     struct verify;
@@ -145,31 +143,6 @@ namespace ui {
     )))
     {}
 
-    alert_response IWindow::alert(std::string text, std::string title, alert_type type, alert_icon icon)
-    {
-        auto ret = gtk_MessageBox(this, text.c_str(),
-                                  title.c_str(),
-                                  type == alert_type::OK ? eMB_OK :
-                                  type == alert_type::OKCANCEL ? eMB_OKCANCEL :
-                                  type == alert_type::YESNO ? eMB_YESNO :
-                                  type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
-                                  type == alert_type::NOYES ? eMB_NOYES :
-                                  eMB_OK,
-                                  icon == alert_icon::Default ? eMB_ICONDEFAULT :
-                                  icon == alert_icon::Error ? eMB_ICONERROR :
-                                  icon == alert_icon::Warning ? eMB_ICONWARNING :
-                                  icon == alert_icon::Question ? eMB_ICONQUESTION :
-                                  icon == alert_icon::Asterisk ? eMB_ICONASTERISK :
-                                  eMB_ICONDEFAULT
-        );
-        return
-                ret == eIDOK ? alert_response::OK :
-                ret == eIDCANCEL ? alert_response::CANCEL :
-                ret == eIDYES ? alert_response::YES :
-                ret == eIDNO ? alert_response::NO :
-                alert_response::OK;
-    }
-
     Window IWindow::create_dialog_window(const char *title, void func(), void *data, int default_w, int default_h)
     {
         return Window(::create_dialog_window(this, title, func, data, default_w, default_h));
@@ -196,7 +169,7 @@ namespace ui {
             delete data;
         };
         auto func = [](_GtkWidget *widget, GdkEventKey *event, user_data *args) -> bool {
-            return args->f(Widget(widget), event, args->extra);
+            return args->f(Widget::from(widget), event, args->extra);
         };
         auto clos = g_cclosure_new(G_CALLBACK(+func), pass, reinterpret_cast<GClosureNotify>(+dtor));
         return g_signal_connect_closure(G_OBJECT(this), "key-press-event", clos, false);
@@ -448,6 +421,16 @@ namespace ui {
 
     // Custom
 
+#if GTK_TARGET == 3
+
+    IMPL(GLArea, (void *));
+
+#elif GTK_TARGET == 2
+
+    IMPL(GLArea, GTK_DRAWING_AREA);
+
+#endif
+
     guint IGLArea::on_render(GCallback pFunction, void *data)
     {
 #if GTK_TARGET == 3
@@ -458,4 +441,33 @@ namespace ui {
 #endif
     }
 
+    // global
+
+    Window root{ui::null};
+
+    alert_response alert(Window parent, std::string text, std::string title, alert_type type, alert_icon icon)
+    {
+        auto ret = gtk_MessageBox(parent, text.c_str(),
+                                  title.c_str(),
+                                  type == alert_type::OK ? eMB_OK :
+                                  type == alert_type::OKCANCEL ? eMB_OKCANCEL :
+                                  type == alert_type::YESNO ? eMB_YESNO :
+                                  type == alert_type::YESNOCANCEL ? eMB_YESNOCANCEL :
+                                  type == alert_type::NOYES ? eMB_NOYES :
+                                  eMB_OK,
+                                  icon == alert_icon::Default ? eMB_ICONDEFAULT :
+                                  icon == alert_icon::Error ? eMB_ICONERROR :
+                                  icon == alert_icon::Warning ? eMB_ICONWARNING :
+                                  icon == alert_icon::Question ? eMB_ICONQUESTION :
+                                  icon == alert_icon::Asterisk ? eMB_ICONASTERISK :
+                                  eMB_ICONDEFAULT
+        );
+        return
+                ret == eIDOK ? alert_response::OK :
+                ret == eIDCANCEL ? alert_response::CANCEL :
+                ret == eIDYES ? alert_response::YES :
+                ret == eIDNO ? alert_response::NO :
+                alert_response::OK;
+    }
+
 }