source: trunk/deushax/gtk/editor.cpp @ 824

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

gtk: refactor the GtkGlArea handling so that it can be destroyed even if
we are not actually closing the whole application.

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