From b478ad79508f5a06e8c0fc5937b28585c747fb04 Mon Sep 17 00:00:00 2001 From: neoraider Date: Wed, 31 Oct 2007 23:03:04 +0000 Subject: zoomedit: Speichern jetzt m?glich. --- FileManager.cpp | 390 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ FileManager.h | 39 ++++++ Makefile.am | 6 +- Makefile.in | 26 +++- Polygon.cpp | 12 +- Polygon.h | 3 +- UIManager.cpp | 12 +- UIManager.h | 2 +- Window.cpp | 11 +- Window.h | 3 + aclocal.m4 | 158 +++++++++++++++++++++++ configure | 216 ++++++++++++++++++++++++++++++- configure.in | 2 + 13 files changed, 856 insertions(+), 24 deletions(-) create mode 100644 FileManager.cpp create mode 100644 FileManager.h diff --git a/FileManager.cpp b/FileManager.cpp new file mode 100644 index 0000000..7650a2f --- /dev/null +++ b/FileManager.cpp @@ -0,0 +1,390 @@ +#include "FileManager.h" +#include "Window.h" + + +bool FileManager::writeTriangle(xmlTextWriterPtr writer, const Triangle &triangle, float height) { + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"triangle") < 0) + return false; + + //if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"texture", (xmlChar*)"t0") < 0) + // return false; + + float y = 0.0f; + if(triangle.getDirection() == Triangle::CW) y = height; + + if(!writeVertex(writer, triangle.getVertexA().getX(), y, triangle.getVertexA().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexA().getX(), triangle.getVertexA().getY())) + // return false; + + if(!writeVertex(writer, triangle.getVertexB().getX(), y, triangle.getVertexB().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexB().getX(), triangle.getVertexB().getY())) + // return false; + + if(!writeVertex(writer, triangle.getVertexC().getX(), y, triangle.getVertexC().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexC().getX(), triangle.getVertexC().getY())) + // return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"triangle") < 0) + return false; + + //if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"texture", (xmlChar*)"t0") < 0) + // return false; + + y = height; + if(triangle.getDirection() == Triangle::CW) y = 0.0f; + + if(!writeVertex(writer, triangle.getVertexC().getX(), y, triangle.getVertexC().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexC().getX(), triangle.getVertexC().getY())) + // return false; + + if(!writeVertex(writer, triangle.getVertexB().getX(), y, triangle.getVertexB().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexB().getX(), triangle.getVertexB().getY())) + // return false; + + if(!writeVertex(writer, triangle.getVertexA().getX(), y, triangle.getVertexA().getY())) + return false; + //if(!writeTexCoords(writer, triangle.getVertexA().getX(), triangle.getVertexA().getY())) + // return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + return true; +} + +bool FileManager::writeSide(xmlTextWriterPtr writer, const Vertex &v1, const Vertex &v2, float height) { + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"triangle") < 0) + return false; + + //if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"texture", (xmlChar*)"t0") < 0) + // return false; + + if(!writeVertex(writer, v1.getX(), 0, v1.getY())) + return false; + if(!writeTexCoords(writer, v1.getX(), v1.getY())) + return false; + + if(!writeVertex(writer, v2.getX(), 0, v2.getY())) + return false; + if(!writeTexCoords(writer, v2.getX(), v2.getY())) + return false; + + if(!writeVertex(writer, v2.getX(), height, v2.getY())) + return false; + if(!writeTexCoords(writer, v2.getX(), v2.getY())) + return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"triangle") < 0) + return false; + + //if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"texture", (xmlChar*)"t0") < 0) + // return false; + + if(!writeVertex(writer, v2.getX(), height, v2.getY())) + return false; + if(!writeTexCoords(writer, v2.getX(), v2.getY())) + return false; + + if(!writeVertex(writer, v1.getX(), height, v1.getY())) + return false; + if(!writeTexCoords(writer, v1.getX(), v1.getY())) + return false; + + if(!writeVertex(writer, v1.getX(), 0, v1.getY())) + return false; + if(!writeTexCoords(writer, v1.getX(), v1.getY())) + return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + return true; +} + +bool FileManager::writeVertex(xmlTextWriterPtr writer, float x, float y, float z) { + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"vertex") < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"x", "%f", x) < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"y", "%f", y) < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"z", "%f", z) < 0) + return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + return true; +} + +bool FileManager::writeTexCoords(xmlTextWriterPtr writer, float s, float t) { + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"texcoords") < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"s", "%f", s) < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"t", "%f", t) < 0) + return false; + + // + if(xmlTextWriterEndElement(writer) < 0) + return false; + + return true; +} + +FileManager::FileManager(Window *window) { + this->window = window; + + filename = NULL; + dirty = false; +} + +FileManager::~FileManager() { + if(filename) + g_free(filename); +} + +bool FileManager::save(GtkWindow *parent) { + if(filename == NULL) + return saveAs(parent); + + return write(); +} + +bool FileManager::saveAs(GtkWindow *parent) { + GtkWidget *dialog = gtk_file_chooser_dialog_new(NULL, parent, GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); + + if(filename) + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), filename); + else + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "level.lvl"); + + if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { + gtk_widget_destroy(dialog); + return false; + } + + if(filename) + g_free(filename); + + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + gtk_widget_destroy(dialog); + + if(!filename) + return false; + + return write(); +} + +bool FileManager::write() { + xmlTextWriterPtr writer; + + writer = xmlNewTextWriterFilename(filename, 9); + if(!writer) + return false; + + if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterStartDTD(writer, (xmlChar*)"level", (xmlChar*)"-//libzoom//DTD level 0.1//EN", (xmlChar*)"level.dtd") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterSetIndent(writer, 1) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterSetIndentString(writer, (xmlChar*)" ") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterEndDTD(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"level") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"info") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteElement(writer, (xmlChar*)"name", (xmlChar*)"Level") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteElement(writer, (xmlChar*)"desc", (xmlChar*)"Description") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"start") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"x", (xmlChar*)"0.0") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"y", (xmlChar*)"2.0") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"z", (xmlChar*)"0.0") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"rooms") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"room") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterWriteAttribute(writer, (xmlChar*)"id", (xmlChar*)room->getName().c_str()) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + std::vector triangles; + room->triangulate(triangles); + + for(std::vector::iterator triangle = triangles.begin(); triangle != triangles.end(); triangle++) { + if(!writeTriangle(writer, *triangle, room->getHeight())) { + xmlFreeTextWriter(writer); + return false; + } + } + + std::vector vertices = *room; + + if(room->getDirection() == Triangle::CCW) { + vertices = std::vector(vertices.rbegin(), vertices.rend()); + } + + for(std::vector::iterator v1 = vertices.begin(); v1 != vertices.end(); v1++) { + std::vector::iterator v2 = v1+1; + if(v2 == vertices.end()) v2 = vertices.begin(); + + if(!writeSide(writer, *v1, *v2, room->getHeight())) { + xmlFreeTextWriter(writer); + return false; + } + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"gates") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterStartElement(writer, (xmlChar*)"textures") < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + // + if(xmlTextWriterEndElement(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + if(xmlTextWriterEndDocument(writer) < 0) { + xmlFreeTextWriter(writer); + return false; + } + + xmlFreeTextWriter(writer); + + return true; +} diff --git a/FileManager.h b/FileManager.h new file mode 100644 index 0000000..2309190 --- /dev/null +++ b/FileManager.h @@ -0,0 +1,39 @@ +#ifndef FILEMANAGER_H_ +#define FILEMANAGER_H_ + +#include +#include +#include "Triangle.h" + + +class Window; + + +class FileManager +{ + private: + Window *window; + + gchar *filename; + bool dirty; + + // prevent shallow copy + FileManager(const FileManager &f); + const FileManager& operator=(const FileManager &f); + + bool writeTriangle(xmlTextWriterPtr writer, const Triangle &triangle, float height); + bool writeSide(xmlTextWriterPtr writer, const Vertex &v1, const Vertex &v2, float height); + bool writeVertex(xmlTextWriterPtr writer, float x, float y, float z); + bool writeTexCoords(xmlTextWriterPtr writer, float s, float t); + + public: + FileManager(Window *window); + virtual ~FileManager(); + + bool save(GtkWindow *parent); + bool saveAs(GtkWindow *parent); + + bool write(); +}; + +#endif /*FILEMANAGER_H_*/ diff --git a/Makefile.am b/Makefile.am index 25ebf7c..72e9e31 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,6 +3,6 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \ Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ - EditManager.cpp -zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ -zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ \ No newline at end of file + EditManager.cpp FileManager.cpp +zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@ +zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@ \ No newline at end of file diff --git a/Makefile.in b/Makefile.in index 4b1ccda..44dea16 100644 --- a/Makefile.in +++ b/Makefile.in @@ -56,7 +56,8 @@ am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \ zoomedit-IdManager.$(OBJEXT) zoomedit-WindowManager.$(OBJEXT) \ zoomedit-SidebarManager.$(OBJEXT) zoomedit-Window.$(OBJEXT) \ zoomedit-SidebarView.$(OBJEXT) zoomedit-SidebarAdd.$(OBJEXT) \ - zoomedit-Drawer.$(OBJEXT) zoomedit-EditManager.$(OBJEXT) + zoomedit-Drawer.$(OBJEXT) zoomedit-EditManager.$(OBJEXT) \ + zoomedit-FileManager.$(OBJEXT) zoomedit_OBJECTS = $(am_zoomedit_OBJECTS) zoomedit_DEPENDENCIES = DEFAULT_INCLUDES = -I.@am__isrc@ @@ -160,6 +161,8 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +libxml2_CFLAGS = @libxml2_CFLAGS@ +libxml2_LIBS = @libxml2_LIBS@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -180,10 +183,10 @@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \ Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ - EditManager.cpp + EditManager.cpp FileManager.cpp -zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ -zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ +zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@ +zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@ all: config.h $(MAKE) $(AM_MAKEFLAGS) all-am @@ -274,6 +277,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Drawer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-EditManager.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-FileManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-IdManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Line.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Polygon.Po@am__quote@ @@ -542,6 +546,20 @@ zoomedit-EditManager.obj: EditManager.cpp @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-EditManager.obj `if test -f 'EditManager.cpp'; then $(CYGPATH_W) 'EditManager.cpp'; else $(CYGPATH_W) '$(srcdir)/EditManager.cpp'; fi` +zoomedit-FileManager.o: FileManager.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-FileManager.o -MD -MP -MF $(DEPDIR)/zoomedit-FileManager.Tpo -c -o zoomedit-FileManager.o `test -f 'FileManager.cpp' || echo '$(srcdir)/'`FileManager.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-FileManager.Tpo $(DEPDIR)/zoomedit-FileManager.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='FileManager.cpp' object='zoomedit-FileManager.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-FileManager.o `test -f 'FileManager.cpp' || echo '$(srcdir)/'`FileManager.cpp + +zoomedit-FileManager.obj: FileManager.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-FileManager.obj -MD -MP -MF $(DEPDIR)/zoomedit-FileManager.Tpo -c -o zoomedit-FileManager.obj `if test -f 'FileManager.cpp'; then $(CYGPATH_W) 'FileManager.cpp'; else $(CYGPATH_W) '$(srcdir)/FileManager.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-FileManager.Tpo $(DEPDIR)/zoomedit-FileManager.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='FileManager.cpp' object='zoomedit-FileManager.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-FileManager.obj `if test -f 'FileManager.cpp'; then $(CYGPATH_W) 'FileManager.cpp'; else $(CYGPATH_W) '$(srcdir)/FileManager.cpp'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/Polygon.cpp b/Polygon.cpp index 8b32bb4..650fbb0 100644 --- a/Polygon.cpp +++ b/Polygon.cpp @@ -17,12 +17,6 @@ float Polygon::signedArea() const { return d/2; } -Polygon::Direction Polygon::getDirection() const { - float area = signedArea(); - - return (area > 0) ? Triangle::CW : (area < 0) ? Triangle::CCW : Triangle::UNKNOWN; -} - float Polygon::area() const { return fabsf(signedArea()); } @@ -170,6 +164,12 @@ bool Polygon::intersections(std::vector *intersections) const { return ret; } +Polygon::Direction Polygon::getDirection() const { + float area = signedArea(); + + return (area > 0) ? Triangle::CW : (area < 0) ? Triangle::CCW : Triangle::UNKNOWN; +} + bool Polygon::isSimple() const { return !intersections(); } diff --git a/Polygon.h b/Polygon.h index e52206a..33ba873 100644 --- a/Polygon.h +++ b/Polygon.h @@ -20,7 +20,6 @@ class Polygon : public std::vector { float signedArea() const; - Triangle::Direction getDirection() const; bool isConcave(const Triangle::Direction &dir, const Vertex &v1, const Vertex &v2, const Vertex &v3) const; bool intersections(std::vector *intersections = NULL) const; @@ -33,6 +32,8 @@ class Polygon : public std::vector { bool contains(const Vertex &v) const; bool intersects(const Line &l) const; + Triangle::Direction getDirection() const; + bool isSimple() const; bool simplify(std::list &polygons) const; diff --git a/UIManager.cpp b/UIManager.cpp index c1b1e45..2b4fefd 100644 --- a/UIManager.cpp +++ b/UIManager.cpp @@ -26,12 +26,14 @@ const gchar* const UIManager::uiData = (const gchar*) void UIManager::handleAction(GtkAction *action, UIManager *uiManager) { const gchar* name = gtk_action_get_name(action); - if(!strcmp(name, "zoomIn")) + if(!strcmp(name, "save")) + uiManager->window->handleAction(SAVE); + else if(!strcmp(name, "saveAs")) + uiManager->window->handleAction(SAVE_AS); + else if(!strcmp(name, "zoomIn")) uiManager->window->handleAction(ZOOM_IN); - //zoomInCentered(1.2f); else if(!strcmp(name, "zoomOut")) uiManager->window->handleAction(ZOOM_OUT); - //zoomOutCentered(1.2f); } GtkActionGroup* UIManager::createActions() { @@ -47,18 +49,22 @@ GtkActionGroup* UIManager::createActions() { g_object_unref(G_OBJECT(action)); action = gtk_action_new("new", "_New", NULL, GTK_STOCK_NEW); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); gtk_action_group_add_action_with_accel(actionGroup, action, NULL); g_object_unref(G_OBJECT(action)); action = gtk_action_new("open", "_Open", NULL, GTK_STOCK_OPEN); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); gtk_action_group_add_action_with_accel(actionGroup, action, NULL); g_object_unref(G_OBJECT(action)); action = gtk_action_new("save", "_Save", NULL, GTK_STOCK_SAVE); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); gtk_action_group_add_action_with_accel(actionGroup, action, NULL); g_object_unref(G_OBJECT(action)); action = gtk_action_new("saveAs", "Save _As", NULL, NULL); + g_signal_connect(G_OBJECT(action), "activate", G_CALLBACK(handleAction), this); gtk_action_group_add_action(actionGroup, action); g_object_unref(G_OBJECT(action)); diff --git a/UIManager.h b/UIManager.h index 4d833e0..2ec7d6b 100644 --- a/UIManager.h +++ b/UIManager.h @@ -21,7 +21,7 @@ class UIManager { public: enum Action { - ZOOM_IN, ZOOM_OUT + SAVE, SAVE_AS, ZOOM_IN, ZOOM_OUT }; UIManager(Window *window); diff --git a/Window.cpp b/Window.cpp index f69e148..af0357b 100644 --- a/Window.cpp +++ b/Window.cpp @@ -11,7 +11,8 @@ gboolean Window::deleteEvent(GtkWidget *widget, GdkEvent *event, Window *window) } Window::Window(GdkGLConfig *glconfig, WindowManager *manager) - : uiManager(this), editor(this), drawer(this, glconfig), sidebar(&editor) + : uiManager(this), editor(this), drawer(this, glconfig), sidebar(&editor), + fileManager(this) { this->manager = manager; @@ -53,6 +54,14 @@ void Window::update() { void Window::handleAction(UIManager::Action action) { switch(action) { + case UIManager::SAVE: + fileManager.save(GTK_WINDOW(window)); + break; + + case UIManager::SAVE_AS: + fileManager.saveAs(GTK_WINDOW(window)); + break; + case UIManager::ZOOM_IN: drawer.zoom(2); break; diff --git a/Window.h b/Window.h index 3dd36d5..00c447c 100644 --- a/Window.h +++ b/Window.h @@ -6,6 +6,7 @@ #include "UIManager.h" #include "Drawer.h" #include "SidebarManager.h" +#include "FileManager.h" #include "EditManager.h" #include "Level.h" @@ -24,6 +25,8 @@ class Window { Drawer drawer; SidebarManager sidebar; + FileManager fileManager; + WindowManager *manager; Level level; diff --git a/aclocal.m4 b/aclocal.m4 index 680d62e..dd9403c 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -444,6 +444,164 @@ AC_DEFUN([AC_GTKGLEXT_SUPPORTS_MULTIHEAD], fi ]) +# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- +# +# Copyright © 2004 Scott James Remnant . +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# PKG_PROG_PKG_CONFIG([MIN-VERSION]) +# ---------------------------------- +AC_DEFUN([PKG_PROG_PKG_CONFIG], +[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) +m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=m4_default([$1], [0.9.0]) + AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + PKG_CONFIG="" + fi + +fi[]dnl +])# PKG_PROG_PKG_CONFIG + +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# +# Check to see whether a particular set of modules exists. Similar +# to PKG_CHECK_MODULES(), but does not set variables or print errors. +# +# +# Similar to PKG_CHECK_MODULES, make sure that the first instance of +# this or PKG_CHECK_MODULES is called, or make sure to call +# PKG_CHECK_EXISTS manually +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_EXISTS], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +if test -n "$PKG_CONFIG" && \ + AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then + m4_ifval([$2], [$2], [:]) +m4_ifvaln([$3], [else + $3])dnl +fi]) + + +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) +# --------------------------------------------- +m4_define([_PKG_CONFIG], +[if test -n "$PKG_CONFIG"; then + if test -n "$$1"; then + pkg_cv_[]$1="$$1" + else + PKG_CHECK_EXISTS([$3], + [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], + [pkg_failed=yes]) + fi +else + pkg_failed=untried +fi[]dnl +])# _PKG_CONFIG + +# _PKG_SHORT_ERRORS_SUPPORTED +# ----------------------------- +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi[]dnl +])# _PKG_SHORT_ERRORS_SUPPORTED + + +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# +# +# Note that if there is a possibility the first call to +# PKG_CHECK_MODULES might not happen, you should be sure to include an +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac +# +# +# -------------------------------------------------------------- +AC_DEFUN([PKG_CHECK_MODULES], +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl + +pkg_failed=no +AC_MSG_CHECKING([for $1]) + +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) +_PKG_CONFIG([$1][_LIBS], [libs], [$2]) + +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS +and $1[]_LIBS to avoid the need to call pkg-config. +See the pkg-config man page for more details.]) + +if test $pkg_failed = yes; then + _PKG_SHORT_ERRORS_SUPPORTED + if test $_pkg_short_errors_supported = yes; then + $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"` + else + $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` + fi + # Put the nasty error message in config.log where it belongs + echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD + + ifelse([$4], , [AC_MSG_ERROR(dnl +[Package requirements ($2) were not met: + +$$1_PKG_ERRORS + +Consider adjusting the PKG_CONFIG_PATH environment variable if you +installed software in a non-standard prefix. + +_PKG_TEXT +])], + [AC_MSG_RESULT([no]) + $4]) +elif test $pkg_failed = untried; then + ifelse([$4], , [AC_MSG_FAILURE(dnl +[The pkg-config script could not be found or is too old. Make sure it +is in your PATH or set the PKG_CONFIG environment variable to the full +path to pkg-config. + +_PKG_TEXT + +To get pkg-config, see .])], + [$4]) +else + $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS + $1[]_LIBS=$pkg_cv_[]$1[]_LIBS + AC_MSG_RESULT([yes]) + ifelse([$3], , :, [$3]) +fi[]dnl +])# PKG_CHECK_MODULES + # Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation diff --git a/configure b/configure index 535b686..8a30f30 100755 --- a/configure +++ b/configure @@ -704,6 +704,8 @@ GTK_CFLAGS GTK_LIBS GTKGLEXT_CFLAGS GTKGLEXT_LIBS +libxml2_CFLAGS +libxml2_LIBS CPP GREP EGREP @@ -721,6 +723,9 @@ CPPFLAGS CCC CC CFLAGS +PKG_CONFIG +libxml2_CFLAGS +libxml2_LIBS CPP' @@ -1314,6 +1319,11 @@ Some influential environment variables: you have headers in a nonstandard directory CC C compiler command CFLAGS C compiler flags + PKG_CONFIG path to pkg-config utility + libxml2_CFLAGS + C compiler flags for libxml2, overriding pkg-config + libxml2_LIBS + linker flags for libxml2, overriding pkg-config CPP C preprocessor Use these variables to override the choices made by `configure' or to help @@ -4591,6 +4601,202 @@ echo "$as_me: error: zoomedit needs GtkGLExt" >&2;} rm -f conf.gtkgltest + +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}pkg-config", so it can be a program name with args. +set dummy ${ac_tool_prefix}pkg-config; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_path_PKG_CONFIG+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { echo "$as_me:$LINENO: result: $PKG_CONFIG" >&5 +echo "${ECHO_T}$PKG_CONFIG" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_path_PKG_CONFIG"; then + ac_pt_PKG_CONFIG=$PKG_CONFIG + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_path_ac_pt_PKG_CONFIG+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + case $ac_pt_PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_ac_pt_PKG_CONFIG="$ac_pt_PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_ac_pt_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + + ;; +esac +fi +ac_pt_PKG_CONFIG=$ac_cv_path_ac_pt_PKG_CONFIG +if test -n "$ac_pt_PKG_CONFIG"; then + { echo "$as_me:$LINENO: result: $ac_pt_PKG_CONFIG" >&5 +echo "${ECHO_T}$ac_pt_PKG_CONFIG" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_pt_PKG_CONFIG" = x; then + PKG_CONFIG="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + PKG_CONFIG=$ac_pt_PKG_CONFIG + fi +else + PKG_CONFIG="$ac_cv_path_PKG_CONFIG" +fi + +fi +if test -n "$PKG_CONFIG"; then + _pkg_min_version=0.9.0 + { echo "$as_me:$LINENO: checking pkg-config is at least version $_pkg_min_version" >&5 +echo $ECHO_N "checking pkg-config is at least version $_pkg_min_version... $ECHO_C" >&6; } + if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + PKG_CONFIG="" + fi + +fi + +pkg_failed=no +{ echo "$as_me:$LINENO: checking for libxml2" >&5 +echo $ECHO_N "checking for libxml2... $ECHO_C" >&6; } + +if test -n "$PKG_CONFIG"; then + if test -n "$libxml2_CFLAGS"; then + pkg_cv_libxml2_CFLAGS="$libxml2_CFLAGS" + else + if test -n "$PKG_CONFIG" && \ + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libxml-2.0\"") >&5 + ($PKG_CONFIG --exists --print-errors "libxml-2.0") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + pkg_cv_libxml2_CFLAGS=`$PKG_CONFIG --cflags "libxml-2.0" 2>/dev/null` +else + pkg_failed=yes +fi + fi +else + pkg_failed=untried +fi +if test -n "$PKG_CONFIG"; then + if test -n "$libxml2_LIBS"; then + pkg_cv_libxml2_LIBS="$libxml2_LIBS" + else + if test -n "$PKG_CONFIG" && \ + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"libxml-2.0\"") >&5 + ($PKG_CONFIG --exists --print-errors "libxml-2.0") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + pkg_cv_libxml2_LIBS=`$PKG_CONFIG --libs "libxml-2.0" 2>/dev/null` +else + pkg_failed=yes +fi + fi +else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + libxml2_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "libxml-2.0"` + else + libxml2_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "libxml-2.0"` + fi + # Put the nasty error message in config.log where it belongs + echo "$libxml2_PKG_ERRORS" >&5 + + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } + { { echo "$as_me:$LINENO: error: Test for libxml2 failed." >&5 +echo "$as_me: error: Test for libxml2 failed." >&2;} + { (exit 1); exit 1; }; } +elif test $pkg_failed = untried; then + { { echo "$as_me:$LINENO: error: Test for libxml2 failed." >&5 +echo "$as_me: error: Test for libxml2 failed." >&2;} + { (exit 1); exit 1; }; } +else + libxml2_CFLAGS=$pkg_cv_libxml2_CFLAGS + libxml2_LIBS=$pkg_cv_libxml2_LIBS + { echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + : +fi + + # Checks for header files. #AC_HEADER_STDC #AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) @@ -6455,6 +6661,8 @@ GTK_CFLAGS!$GTK_CFLAGS$ac_delim GTK_LIBS!$GTK_LIBS$ac_delim GTKGLEXT_CFLAGS!$GTKGLEXT_CFLAGS$ac_delim GTKGLEXT_LIBS!$GTKGLEXT_LIBS$ac_delim +libxml2_CFLAGS!$libxml2_CFLAGS$ac_delim +libxml2_LIBS!$libxml2_LIBS$ac_delim CPP!$CPP$ac_delim GREP!$GREP$ac_delim EGREP!$EGREP$ac_delim @@ -6462,7 +6670,7 @@ LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 94; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 96; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 @@ -6481,7 +6689,7 @@ fi cat >>$CONFIG_STATUS <<_ACEOF cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof -/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b _ACEOF sed ' s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g @@ -6494,8 +6702,6 @@ N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n ' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF -:end -s/|#_!!_#|//g CEOF$ac_eof _ACEOF @@ -6749,7 +6955,7 @@ s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack -" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" | sed 's/|#_!!_#|//g' >$tmp/out test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && diff --git a/configure.in b/configure.in index 9b98a75..f55269d 100644 --- a/configure.in +++ b/configure.in @@ -17,6 +17,8 @@ AM_PROG_CC_C_O #AC_CHECK_LIB(m, [sqrt]) AM_PATH_GTK_2_0(2.8.0,,AC_MSG_ERROR(zoomedit needs GTK+ 2.8.0)) AM_PATH_GTKGLEXT_1_0(1.0.0,,AC_MSG_ERROR(zoomedit needs GtkGLExt)) +PKG_CHECK_MODULES(libxml2, libxml-2.0, , AC_MSG_ERROR(Test for libxml2 failed.)) + # Checks for header files. #AC_HEADER_STDC -- cgit v1.2.3