From 6044e5bed1af42c85967272cb623fb7884f71dd3 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 14 Aug 2010 21:15:46 +0000 Subject: [PATCH] Switch editor building scheme to GtkBuilder. --- src/Makefile.am | 1 + src/gtk/editor.cpp | 29 ++++--- src/gtk/editor.xml | 195 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+), 13 deletions(-) create mode 100644 src/gtk/editor.xml diff --git a/src/Makefile.am b/src/Makefile.am index ccdd1c34..7180e9ae 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,4 +20,5 @@ editor_SOURCES = gtk/editor.cpp editor_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image gtk+-2.0 gtkgl-2.0` editor_LDADD = libcommon.a editor_LDFLAGS = `pkg-config --libs sdl gl gtk+-2.0 gtkgl-2.0 SDL_image` +EXTRA_DIST = gtk/editor.xml diff --git a/src/gtk/editor.cpp b/src/gtk/editor.cpp index 2a784e8b..dea7eb3f 100644 --- a/src/gtk/editor.cpp +++ b/src/gtk/editor.cpp @@ -101,14 +101,15 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - /* Create new top level window. */ - GtkWidget *window = gtk_window_new( GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(window), "Simple"); - gtk_container_set_border_width(GTK_CONTAINER(window), 5); + GtkBuilder *builder = gtk_builder_new(); + if (!gtk_builder_add_from_file(builder, "src/gtk/editor.xml", NULL)) + { + g_print("Cannot build from XML\n"); + return EXIT_FAILURE; + } - /* Quit form main if got delete event */ - gtk_signal_connect(GTK_OBJECT(window), "delete_event", - GTK_SIGNAL_FUNC(main_quit), NULL); + /* Create new top level window. */ + GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); /* You should always delete gtk_gl_area widgets before exit or else GLX contexts are left undeleted, this may cause problems (=core dump) @@ -136,6 +137,8 @@ int main(int argc, char **argv) gtk_widget_set_events(GTK_WIDGET(glarea), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); + gtk_signal_connect(GTK_OBJECT(window), "delete_event", + GTK_SIGNAL_FUNC(main_quit), NULL); gtk_signal_connect(GTK_OBJECT(glarea), "expose_event", GTK_SIGNAL_FUNC(draw), NULL); gtk_signal_connect(GTK_OBJECT(glarea), "configure_event", @@ -143,13 +146,12 @@ int main(int argc, char **argv) gtk_signal_connect(GTK_OBJECT(glarea), "realize", GTK_SIGNAL_FUNC(init), NULL); - // FIXME: is this needed? - gtk_widget_set_usize(GTK_WIDGET(glarea), 400, 300); + // Create a scrolled window around our GL widget + GtkWidget *sw = GTK_WIDGET(gtk_builder_get_object(builder, "scrolledwindow1")); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), glarea); - /* Put glarea into window and show it all */ - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea)); - gtk_widget_show(GTK_WIDGET(glarea)); - gtk_widget_show(GTK_WIDGET(window)); + /* Put scrolled window into main window */ + gtk_widget_show_all(GTK_WIDGET(window)); // FIXME: detect when the game is killed new Game("maps/testmap.tmx"); @@ -163,3 +165,4 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } + diff --git a/src/gtk/editor.xml b/src/gtk/editor.xml new file mode 100644 index 00000000..af6e41ec --- /dev/null +++ b/src/gtk/editor.xml @@ -0,0 +1,195 @@ + + + + + + Deus Hax Editor + + + True + vertical + + + True + + + True + _File + True + + + True + + + gtk-new + True + True + True + + + + + gtk-open + True + True + True + + + + + gtk-save + True + True + True + + + + + gtk-save-as + True + True + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + True + _Edit + True + + + True + + + gtk-cut + True + True + True + + + + + gtk-copy + True + True + True + + + + + gtk-paste + True + True + True + + + + + gtk-delete + True + True + True + + + + + + + + + True + _View + True + + + + + True + _Help + True + + + True + + + gtk-about + True + True + True + + + + + + + + + False + 0 + + + + + + + + True + True + + + 640 + 480 + True + True + + + False + True + + + + + True + Palette will be here + + + True + True + + + + + 2 + + + + + True + 2 + + + False + 3 + + + + + +