]> Pileus Git - grits/blob - src/gis-test.c
Debugging and memory checking
[grits] / src / gis-test.c
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <config.h>
19 #include <gtk/gtk.h>
20 #include <gdk/gdkkeysyms.h>
21
22 #include "gis.h"
23
24 GisPrefs   *prefs   = NULL;
25 GisPlugins *plugins = NULL;
26 GisViewer  *viewer  = NULL;
27
28 /*************
29  * Callbacks *
30  *************/
31 static gboolean gis_shutdown(GtkWidget *window)
32 {
33         gis_plugins_free(plugins);
34         g_object_unref(prefs);
35         gtk_widget_destroy(window);
36
37         while (gtk_events_pending())
38                   gtk_main_iteration();
39
40         gtk_main_quit();
41         return TRUE;
42 }
43 static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
44 {
45         return gis_shutdown(widget);
46 }
47 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
48                 gpointer window)
49 {
50         if (event->keyval == GDK_q)
51                 return gis_shutdown(widget);
52         return FALSE;
53 }
54
55 /***********
56  * Methods *
57  ***********/
58 int main(int argc, char **argv)
59 {
60         g_thread_init(NULL);
61         gdk_threads_init();
62         gtk_init(&argc, &argv);
63
64         prefs   = gis_prefs_new(NULL, NULL);
65         plugins = gis_plugins_new(g_getenv("GIS_PLUGIN_PATH"), prefs);
66         viewer  = gis_opengl_new(plugins, prefs);
67
68         gdk_threads_enter();
69         GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
70         g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
71         g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
72         gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(viewer));
73         gtk_widget_show_all(window);
74
75
76         /* elev env map sat test */
77         gis_plugins_load(plugins, "elev",  viewer, prefs);
78         gis_plugins_load(plugins, "env",   viewer, prefs);
79         gis_plugins_load(plugins, "map",   viewer, prefs);
80         gis_plugins_load(plugins, "sat",   viewer, prefs);
81         gis_plugins_load(plugins, "test",  viewer, prefs);
82
83         gtk_main();
84
85         gdk_threads_leave();
86         return 0;
87 }