@@ -8,7 +8,7 @@ libcommon_a_SOURCES = \ | |||||
scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ | scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ | ||||
entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ | entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ | ||||
forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ | forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ | ||||
profiler.cpp profiler.h input.h input.cpp \ | |||||
profiler.cpp profiler.h input.h input.cpp mapviewer.cpp mapviewer.h \ | |||||
debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ | debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ | ||||
debugrecord.cpp debugrecord.h | debugrecord.cpp debugrecord.h | ||||
libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | ||||
@@ -26,6 +26,7 @@ | |||||
#include "font.h" | #include "font.h" | ||||
#include "game.h" | #include "game.h" | ||||
#include "tileset.h" | #include "tileset.h" | ||||
#include "mapviewer.h" | |||||
// Other objects | // Other objects | ||||
#include "dict.h" | #include "dict.h" | ||||
@@ -76,7 +76,7 @@ static gint draw(GtkWidget *widget, GdkEventExpose *event) | |||||
ticking = 0; | ticking = 0; | ||||
/* Clear the screen, tick the renderer, show the frame and | /* Clear the screen, tick the renderer, show the frame and | ||||
* clamp to desired framerate. */ | |||||
* clamp to desired framerate */ | |||||
Video::Clear(); | Video::Clear(); | ||||
Ticker::TickDraw(); | Ticker::TickDraw(); | ||||
gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); | gtk_gl_area_swapbuffers(GTK_GL_AREA(widget)); | ||||
@@ -100,6 +100,7 @@ int main(int argc, char **argv) | |||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
/* Build the rest of the application */ | |||||
GtkBuilder *builder = gtk_builder_new(); | GtkBuilder *builder = gtk_builder_new(); | ||||
if (!gtk_builder_add_from_file(builder, "src/gtk/editor.xml", NULL)) | if (!gtk_builder_add_from_file(builder, "src/gtk/editor.xml", NULL)) | ||||
{ | { | ||||
@@ -107,20 +108,11 @@ int main(int argc, char **argv) | |||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
} | } | ||||
/* Create new top level window. */ | |||||
GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); | GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); | ||||
GtkWidget *sw = GTK_WIDGET(gtk_builder_get_object(builder, "sw1")); | |||||
g_object_unref(G_OBJECT(builder)); | |||||
/* You should always delete gtk_gl_area widgets before exit or else | |||||
GLX contexts are left undeleted, this may cause problems (=core dump) | |||||
in some systems. | |||||
Destroy method of objects is not automatically called on exit. | |||||
You need to manually enable this feature. Do gtk_quit_add_destroy() | |||||
for all your top level windows unless you are certain that they get | |||||
destroy signal by other means. | |||||
*/ | |||||
gtk_quit_add_destroy(1, GTK_OBJECT(window)); | |||||
/* Create new OpenGL widget. */ | |||||
/* Create new OpenGL widget */ | |||||
int attrlist[] = | int attrlist[] = | ||||
{ | { | ||||
GDK_GL_RGBA, | GDK_GL_RGBA, | ||||
@@ -132,10 +124,10 @@ int main(int argc, char **argv) | |||||
}; | }; | ||||
GtkWidget *glarea = gtk_gl_area_new(attrlist); | GtkWidget *glarea = gtk_gl_area_new(attrlist); | ||||
gtk_widget_set_events(glarea, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); | |||||
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(sw), glarea); | |||||
gtk_widget_set_events(GTK_WIDGET(glarea), | |||||
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); | |||||
/* Connect signals and show window */ | |||||
gtk_signal_connect(GTK_OBJECT(window), "delete_event", | gtk_signal_connect(GTK_OBJECT(window), "delete_event", | ||||
GTK_SIGNAL_FUNC(main_quit), NULL); | GTK_SIGNAL_FUNC(main_quit), NULL); | ||||
gtk_signal_connect(GTK_OBJECT(glarea), "expose_event", | gtk_signal_connect(GTK_OBJECT(glarea), "expose_event", | ||||
@@ -145,19 +137,15 @@ int main(int argc, char **argv) | |||||
gtk_signal_connect(GTK_OBJECT(glarea), "realize", | gtk_signal_connect(GTK_OBJECT(glarea), "realize", | ||||
GTK_SIGNAL_FUNC(init), NULL); | GTK_SIGNAL_FUNC(init), NULL); | ||||
// 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 scrolled window into main window */ | |||||
gtk_widget_show_all(GTK_WIDGET(window)); | |||||
gtk_widget_show_all(window); | |||||
// FIXME: detect when the game is killed | |||||
new Game("maps/testmap.tmx"); | |||||
// FIXME: detect when the map viewer is killed | |||||
new MapViewer("maps/testmap.tmx"); | |||||
new DebugFps(); | new DebugFps(); | ||||
/* We tick from the idle function instead of a timeout to avoid | /* We tick from the idle function instead of a timeout to avoid | ||||
* stealing time from the GTK loop. */ | |||||
* stealing time from the GTK loop when the callback time exceeds | |||||
* the timeout value. */ | |||||
gtk_idle_add(tick, glarea); | gtk_idle_add(tick, glarea); | ||||
gtk_main(); | gtk_main(); | ||||
@@ -153,7 +153,7 @@ | |||||
<property name="visible">True</property> | <property name="visible">True</property> | ||||
<property name="can_focus">True</property> | <property name="can_focus">True</property> | ||||
<child> | <child> | ||||
<object class="GtkScrolledWindow" id="scrolledwindow1"> | |||||
<object class="GtkScrolledWindow" id="sw1"> | |||||
<property name="width_request">640</property> | <property name="width_request">640</property> | ||||
<property name="height_request">480</property> | <property name="height_request">480</property> | ||||
<property name="visible">True</property> | <property name="visible">True</property> | ||||
@@ -0,0 +1,85 @@ | |||||
// | |||||
// Deus Hax (working title) | |||||
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
#if defined HAVE_CONFIG_H | |||||
# include "config.h" | |||||
#endif | |||||
#include <cstdio> | |||||
#include "core.h" | |||||
/* | |||||
* MapViewer implementation class | |||||
*/ | |||||
class MapViewerData | |||||
{ | |||||
friend class MapViewer; | |||||
private: | |||||
Map *map; | |||||
int x, y; | |||||
int mousex, mousey; | |||||
int done; | |||||
Scene *scene; | |||||
}; | |||||
/* | |||||
* Public MapViewer class | |||||
*/ | |||||
MapViewer::MapViewer(char const *mapname) | |||||
{ | |||||
data = new MapViewerData(); | |||||
data->map = new Map(mapname); | |||||
data->x = data->y = 0; | |||||
data->done = 0; | |||||
data->scene = NULL; | |||||
} | |||||
MapViewer::~MapViewer() | |||||
{ | |||||
delete data->map; | |||||
delete data; | |||||
} | |||||
Entity::Group MapViewer::GetGroup() | |||||
{ | |||||
return Entity::GetGroup(); | |||||
} | |||||
void MapViewer::TickGame(float deltams) | |||||
{ | |||||
Entity::TickGame(deltams); | |||||
} | |||||
void MapViewer::TickDraw(float deltams) | |||||
{ | |||||
Entity::TickDraw(deltams); | |||||
GetScene(); | |||||
data->map->Render(data->scene, -data->mousex, -data->mousey, 0); | |||||
data->scene->Render(); | |||||
delete data->scene; | |||||
data->scene = NULL; | |||||
} | |||||
Scene *MapViewer::GetScene() | |||||
{ | |||||
if (!data->scene) | |||||
data->scene = new Scene(); | |||||
return data->scene; | |||||
} | |||||
void MapViewer::SetMouse(int x, int y) | |||||
{ | |||||
data->mousex = x; | |||||
data->mousey = y; | |||||
} | |||||
@@ -0,0 +1,41 @@ | |||||
// | |||||
// Deus Hax (working title) | |||||
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// | |||||
// The MapViewer class | |||||
// ------------------- | |||||
// | |||||
#if !defined __DH_MAPVIEWER_H__ | |||||
#define __DH_MAPVIEWER_H__ | |||||
#include "entity.h" | |||||
#include "scene.h" | |||||
class MapViewerData; | |||||
class MapViewer : public Entity | |||||
{ | |||||
public: | |||||
MapViewer(char const *mapname); | |||||
~MapViewer(); | |||||
protected: | |||||
/* Inherited from Entity */ | |||||
virtual Group GetGroup(); | |||||
virtual void TickGame(float deltams); | |||||
virtual void TickDraw(float deltams); | |||||
public: | |||||
/* New methods */ | |||||
Scene *GetScene(); | |||||
void SetMouse(int x, int y); | |||||
private: | |||||
MapViewerData *data; | |||||
}; | |||||
#endif // __DH_MAPVIEWER_H__ | |||||