GTK SDL Level Editor
- From: S N Maynard <ma2snm bath ac uk>
- To: "" <gtk-app-devel-list gnome org>
- Subject: GTK SDL Level Editor
- Date: Fri, 16 Jan 2004 10:35:52 +0000
hi,
I'm attempting to code a GTK2 Level editor for a 2d sdl rpg game. My main
problem appears to be that I would like the level editor to be of a single
window appearence, rather than the multi-window gimp like appearence. I have
attempted to use the gtksdl widget -
http://drizzt.kilobug.org/pub/misc/gtksdl-gtk2.tar.gz - and got my editor to
have an sdl window inside a gtk table. However, whenever i try to draw to the
sdl surface, sdl segfaults during initialization, after sdl realize. Below I
have most of my code and would be apprecitative of any comments on the way i'm
doing it at the moment, any ideas on any other ways of creating a level editor (
sdl is not a definite necessity ), and any ideas on making this gtksdl widget
work. Here is the code, I can post more if necessary,
#include <gtk/gtk.h>
#include <SDL/SDL.h>
#include "gtksdl.h" //from gtksdl
int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *toolbar;
GtkWidget *gtktable;
if (SDL_InitSubSystem (SDL_INIT_VIDEO) < 0) {
fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
return (FALSE);
}
newfile.openornot= FALSE;
openfile.openornot = FALSE;
savefile.openornot = FALSE;
aboutwindow.openornot = FALSE;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(window), "destroy",
G_CALLBACK(quitprogram),G_OBJECT(window));
gtk_container_set_border_width(GTK_CONTAINER(window),10);
gtk_window_set_title(GTK_WINDOW(window), "Level Editor");
gtk_window_set_default_size(GTK_WINDOW(window), 800,600);
gtktable = gtk_table_new(2,3,FALSE);
gtk_container_add (GTK_CONTAINER (window), gtktable);
toolbar = gtk_toolbar_new();
gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
GTK_ORIENTATION_HORIZONTAL);
gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_TEXT);
gtk_container_set_border_width(GTK_CONTAINER(toolbar),5);
gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "New Level", "Click here to
create a new level", "Private", NULL,G_CALLBACK (newfilewidget), NULL);
gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Open Level", "Click here
to open
a saved level", "Private", NULL,G_CALLBACK (openfilewidget), NULL);
gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Save Level", "Click here
to save
the current level", "Private", NULL,G_CALLBACK (savefilewidget), NULL);
gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Level Settings", "Click
here to
edit the level settings", "Private", NULL,G_CALLBACK (aboutopen), NULL);
gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "About", "About this level
editor", "Private", NULL,G_CALLBACK (aboutopen), NULL);
gtk_table_attach_defaults(GTK_TABLE(gtktable),toolbar, 0,1,0,1);
GtkWidget *levelwind = gtk_sdl_new (640, 480, 0, SDL_HWSURFACE |
SDL_DOUBLEBUF);
gtk_widget_show (levelwind);
gtk_table_attach_defaults(GTK_TABLE(gtktable),levelwind, 0,1,1,2);
GtkSDL *gfty;
gfty = GTK_SDL(levelwind);
SDL_Surface *jump;
jump = gfty->surface;
gtk_widget_show(toolbar);
gtk_widget_show(gtktable);
gtk_widget_show(window);
//putting gtk_main() here does not cause the prob, but
//segfaults on close
SDL_FillRect(jump,NULL,SDL_MapRGB(jump->format,0,0,0));
SDL_UpdateRect( jump , 0 , 0 , 0 , 0 );
gtk_main(); //putting gtk_main() here causes initialization prob
return 0;
}
Thanks for your time,
Simon
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]