source: trunk/src/gtk/editor.cpp @ 170

Last change on this file since 170 was 170, checked in by sam, 10 years ago

Properly implement program termination, including in the GTK program.

  • Property svn:keywords set to Id
File size: 1.5 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdlib>
11
12#include <gtk/gtk.h>
13#include <gtkgl/gtkglarea.h>
14
15#include "core.h"
16#include "glmapview.h"
17#include "debugfps.h"
18
19static gboolean delayed_quit(GtkWidget *w, GdkEvent *e, void *data)
20{
21    (void)w;
22    (void)e;
23    (void)data;
24    gtk_main_quit();
25    return TRUE;
26}
27
28int main(int argc, char **argv)
29{
30    /* Initialize GTK */
31    g_thread_init(NULL);
32    gtk_init(&argc, &argv);
33
34    if (gdk_gl_query() == FALSE)
35    {
36        g_print("OpenGL not supported\n");
37        return EXIT_FAILURE;
38    }
39
40    /* Build the application interface */
41    GtkBuilder *builder = gtk_builder_new();
42    if (!gtk_builder_add_from_file(builder, "src/gtk/editor.xml", NULL))
43    {
44        g_print("Cannot build from XML\n");
45        return EXIT_FAILURE;
46    }
47    gtk_builder_connect_signals(builder, NULL);
48
49    /* Add our custom GL map viewer */
50    GlMapView *glmapview = new GlMapView(builder);
51
52    /* Show window. We're good to go! */
53    GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window"));
54    gtk_widget_show_all(window);
55    gtk_signal_connect(GTK_OBJECT(window), "delete_event",
56                       GTK_SIGNAL_FUNC(delayed_quit), NULL);
57    g_object_unref(G_OBJECT(builder));
58
59    glmapview->LoadMap("maps/testmap.tmx");
60    new DebugFps();
61
62    gtk_main();
63
64    delete glmapview;
65
66    return EXIT_SUCCESS;
67}
68
Note: See TracBrowser for help on using the repository browser.