]> Pileus Git - grits/blobdiff - src/grits-test.c
Add support for GTK 3
[grits] / src / grits-test.c
index 43d014b471401c99c2773efdba860230b7464fae..cde36cdc533fdb0786450bc881026ba65696f243 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #include <config.h>
 #include <gtk/gtk.h>
-#include <gtk/gtkgl.h>
 #include <gdk/gdkkeysyms.h>
 
 #include "grits.h"
 
-GisPrefs   *prefs   = NULL;
-GisPlugins *plugins = NULL;
-GisViewer  *viewer  = NULL;
+#include "compat.h"
+
+GritsPrefs   *prefs   = NULL;
+GritsPlugins *plugins = NULL;
+GritsViewer  *viewer  = NULL;
 
 /*************
  * Callbacks *
  *************/
-static gboolean gis_shutdown(GtkWidget *window)
+static gboolean grits_shutdown(GtkWidget *window)
 {
-       gis_plugins_free(plugins);
+       static gboolean shutdown = FALSE;
+       if (shutdown) return TRUE;
+       shutdown = TRUE;
+
+       grits_plugins_free(plugins);
        g_object_unref(prefs);
        gtk_widget_destroy(window);
-
-       while (gtk_events_pending())
-                 gtk_main_iteration();
-
        gtk_main_quit();
        return TRUE;
 }
 static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-       return gis_shutdown(widget);
+       return grits_shutdown(widget);
 }
 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
-               gpointer window)
+               gpointer _)
 {
-       if (event->keyval == GDK_q)
-               return gis_shutdown(widget);
+       if (event->keyval == GDK_KEY_q)
+               return grits_shutdown(widget);
        return FALSE;
 }
-static void load_plugin(GisPlugins *plugins, gchar *name,
-               GisViewer *viewer, GisPrefs *prefs, GtkNotebook *notebook)
+static void load_plugin(GritsPlugins *plugins, gchar *name,
+               GritsViewer *viewer, GritsPrefs *prefs, GtkNotebook *notebook)
 {
-       GisPlugin *plugin = gis_plugins_load(plugins, name, viewer, prefs);
-       GtkWidget *config = gis_plugin_get_config(plugin);
-       gtk_notebook_append_page(notebook, config, gtk_label_new(name));
+       GritsPlugin *plugin = grits_plugins_load(plugins, name, viewer, prefs);
+       GtkWidget *config = grits_plugin_get_config(plugin);
+       if (config)
+               gtk_notebook_append_page(notebook, config, gtk_label_new(name));
 }
 
 /***********
@@ -65,21 +67,18 @@ static void load_plugin(GisPlugins *plugins, gchar *name,
  ***********/
 int main(int argc, char **argv)
 {
-       g_thread_init(NULL);
-       gdk_threads_init();
        gtk_init(&argc, &argv);
-       gtk_gl_init(&argc, &argv);
 
-       prefs   = gis_prefs_new(NULL, NULL);
-       plugins = gis_plugins_new(g_getenv("GIS_PLUGIN_PATH"), prefs);
-       viewer  = gis_opengl_new(plugins, prefs);
+       prefs   = grits_prefs_new(NULL, NULL);
+       plugins = grits_plugins_new(g_getenv("GRITS_PLUGIN_PATH"), prefs);
+       viewer  = grits_opengl_new(plugins, prefs);
 
-       gdk_threads_enter();
        GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-       GtkWidget *vbox   = gtk_vbox_new(FALSE, 0);
+       GtkWidget *vbox   = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
        GtkWidget *config = gtk_notebook_new();
        g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
        g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
+       gtk_widget_set_size_request(GTK_WIDGET(viewer), 300, 300);
        gtk_notebook_set_tab_pos(GTK_NOTEBOOK(config), GTK_POS_BOTTOM);
        gtk_container_add(GTK_CONTAINER(window), vbox);
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(viewer), TRUE,  TRUE,  0);
@@ -87,18 +86,24 @@ int main(int argc, char **argv)
        gtk_widget_show_all(window);
 
        /* Configurable stuff */
-       gis_viewer_set_offline(viewer, TRUE);
-       load_plugin(plugins, "elev",  viewer, prefs, GTK_NOTEBOOK(config));
+       grits_viewer_set_offline(viewer, TRUE);
+       (void)load_plugin;
        load_plugin(plugins, "env",   viewer, prefs, GTK_NOTEBOOK(config));
-       //load_plugin(plugins, "map",   viewer, prefs, GTK_NOTEBOOK(config));
-       load_plugin(plugins, "sat",   viewer, prefs, GTK_NOTEBOOK(config));
-       load_plugin(plugins, "test",  viewer, prefs, GTK_NOTEBOOK(config));
+       //load_plugin(plugins, "elev",  viewer, prefs, GTK_NOTEBOOK(config));
+       //load_plugin(plugins, "sat",   viewer, prefs, GTK_NOTEBOOK(config));
+       load_plugin(plugins, "map",   viewer, prefs, GTK_NOTEBOOK(config));
+       //load_plugin(plugins, "alert", viewer, prefs, GTK_NOTEBOOK(config));
        //load_plugin(plugins, "radar", viewer, prefs, GTK_NOTEBOOK(config));
+       load_plugin(plugins, "test",  viewer, prefs, GTK_NOTEBOOK(config));
 
        gtk_widget_show_all(config);
        gtk_main();
-       gdk_threads_leave();
 
-       gdk_display_close(gdk_display_get_default());
+       //gdk_display_close(gdk_display_get_default());
+
+       prefs   = NULL;
+       plugins = NULL;
+       viewer  = NULL;
+       window  = vbox = config = NULL;
        return 0;
 }