]> Pileus Git - grits/blob - src/gis-test.c
[Re]add gis-test
[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 /*************
25  * Callbacks *
26  *************/
27 static gboolean on_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
28 {
29         gtk_main_quit();
30         return TRUE;
31 }
32 static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event,
33                 gpointer window)
34 {
35         if (event->keyval == GDK_q) {
36                 gtk_main_quit();
37                 return TRUE;
38         }
39         return FALSE;
40 }
41
42 /***********
43  * Methods *
44  ***********/
45 int main(int argc, char **argv)
46 {
47         g_thread_init(NULL);
48         gdk_threads_init();
49         gtk_init(&argc, &argv);
50
51         GisPrefs   *prefs   = gis_prefs_new(NULL, NULL);
52         GisPlugins *plugins = gis_plugins_new(g_getenv("GIS_PLUGIN_PATH"), prefs);
53         GisViewer  *viewer  = gis_opengl_new(plugins, prefs);
54
55         gdk_threads_enter();
56         GtkWidget  *window  = gtk_window_new(GTK_WINDOW_TOPLEVEL);
57         g_signal_connect(window, "delete-event",    G_CALLBACK(on_delete),    NULL);
58         g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);
59         gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(viewer));
60         gtk_widget_show_all(window);
61
62         gis_plugins_load(plugins, "test", viewer, prefs);
63         gis_plugins_load(plugins, "env",  viewer, prefs);
64
65         gtk_main();
66
67         gis_plugins_free(plugins);
68         g_object_unref(prefs);
69         gtk_widget_destroy(window);
70
71         gdk_threads_leave();
72         return 0;
73 }