diff options
author | neoraider <devnull@localhost> | 2007-09-17 00:24:02 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-09-17 00:24:02 +0200 |
commit | d7a846e58a85ed311e83362af0b6474652d85c8a (patch) | |
tree | 965e42028a4eacb6790b908692dc321ddf5fc45f | |
parent | 96e9d04527dc17a2a4f8c2f7034c1c356ed5186e (diff) | |
download | zoomedit-d7a846e58a85ed311e83362af0b6474652d85c8a.tar zoomedit-d7a846e58a85ed311e83362af0b6474652d85c8a.zip |
zoomedit: Alle Datenstrukturen durch Klassen ersetzt.
-rw-r--r-- | Level.h | 11 | ||||
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | Makefile.in | 62 | ||||
-rw-r--r-- | Room.cpp | 3 | ||||
-rw-r--r-- | Room.h | 21 | ||||
-rw-r--r-- | draw.cpp | 46 | ||||
-rw-r--r-- | edit.cpp | 80 | ||||
-rw-r--r-- | edit.h | 11 | ||||
-rw-r--r-- | geometry.cpp | 8 | ||||
-rw-r--r-- | level.cpp | 51 | ||||
-rw-r--r-- | level.h | 26 | ||||
-rw-r--r-- | window.cpp | 22 | ||||
-rw-r--r-- | zoomedit.cpp | 8 |
13 files changed, 156 insertions, 196 deletions
@@ -0,0 +1,11 @@ +#ifndef LEVEL_H_ +#define LEVEL_H_ + + +#include "Room.h" +#include <vector> + +class Level : public std::vector<Room> { +}; + +#endif /*LEVEL_H_*/ diff --git a/Makefile.am b/Makefile.am index 243629a..4ae72e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ bin_PROGRAMS = zoomedit -zoomedit_SOURCES = zoomedit.cpp window.cpp ui.cpp draw.cpp level.cpp geometry.cpp edit.cpp Vertex.cpp Line.cpp Polygon.cpp Rectangle.cpp +zoomedit_SOURCES = zoomedit.cpp window.cpp ui.cpp draw.cpp edit.cpp geometry.cpp \ + Vertex.cpp Line.cpp Polygon.cpp Rectangle.cpp Room.cpp zoomedit_CPPFLAGS = @GTK_CFLAGS@ zoomedit_LDADD = @GTK_LIBS@
\ No newline at end of file diff --git a/Makefile.in b/Makefile.in index 8230eb9..ef8432a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -50,10 +50,10 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \ zoomedit-window.$(OBJEXT) zoomedit-ui.$(OBJEXT) \ - zoomedit-draw.$(OBJEXT) zoomedit-level.$(OBJEXT) \ - zoomedit-geometry.$(OBJEXT) zoomedit-edit.$(OBJEXT) \ - zoomedit-Vertex.$(OBJEXT) zoomedit-Line.$(OBJEXT) \ - zoomedit-Polygon.$(OBJEXT) zoomedit-Rectangle.$(OBJEXT) + zoomedit-draw.$(OBJEXT) zoomedit-edit.$(OBJEXT) \ + zoomedit-geometry.$(OBJEXT) zoomedit-Vertex.$(OBJEXT) \ + zoomedit-Line.$(OBJEXT) zoomedit-Polygon.$(OBJEXT) \ + zoomedit-Rectangle.$(OBJEXT) zoomedit-Room.$(OBJEXT) zoomedit_OBJECTS = $(am_zoomedit_OBJECTS) zoomedit_DEPENDENCIES = DEFAULT_INCLUDES = -I.@am__isrc@ @@ -171,7 +171,9 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -zoomedit_SOURCES = zoomedit.cpp window.cpp ui.cpp draw.cpp level.cpp geometry.cpp edit.cpp Vertex.cpp Line.cpp Polygon.cpp Rectangle.cpp +zoomedit_SOURCES = zoomedit.cpp window.cpp ui.cpp draw.cpp edit.cpp geometry.cpp \ + Vertex.cpp Line.cpp Polygon.cpp Rectangle.cpp Room.cpp + zoomedit_CPPFLAGS = @GTK_CFLAGS@ zoomedit_LDADD = @GTK_LIBS@ all: config.h @@ -265,11 +267,11 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Line.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Polygon.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Rectangle.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Room.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-draw.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-edit.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-geometry.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-level.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-ui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-window.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-zoomedit.Po@am__quote@ @@ -344,19 +346,19 @@ zoomedit-draw.obj: draw.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-draw.obj `if test -f 'draw.cpp'; then $(CYGPATH_W) 'draw.cpp'; else $(CYGPATH_W) '$(srcdir)/draw.cpp'; fi` -zoomedit-level.o: level.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-level.o -MD -MP -MF $(DEPDIR)/zoomedit-level.Tpo -c -o zoomedit-level.o `test -f 'level.cpp' || echo '$(srcdir)/'`level.cpp -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-level.Tpo $(DEPDIR)/zoomedit-level.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='level.cpp' object='zoomedit-level.o' libtool=no @AMDEPBACKSLASH@ +zoomedit-edit.o: edit.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.o -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-level.o `test -f 'level.cpp' || echo '$(srcdir)/'`level.cpp +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp -zoomedit-level.obj: level.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-level.obj -MD -MP -MF $(DEPDIR)/zoomedit-level.Tpo -c -o zoomedit-level.obj `if test -f 'level.cpp'; then $(CYGPATH_W) 'level.cpp'; else $(CYGPATH_W) '$(srcdir)/level.cpp'; fi` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-level.Tpo $(DEPDIR)/zoomedit-level.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='level.cpp' object='zoomedit-level.obj' libtool=no @AMDEPBACKSLASH@ +zoomedit-edit.obj: edit.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.obj -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-level.obj `if test -f 'level.cpp'; then $(CYGPATH_W) 'level.cpp'; else $(CYGPATH_W) '$(srcdir)/level.cpp'; fi` +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o zoomedit-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi` zoomedit-geometry.o: geometry.cpp @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-geometry.o -MD -MP -MF $(DEPDIR)/zoomedit-geometry.Tpo -c -o zoomedit-geometry.o `test -f 'geometry.cpp' || echo '$(srcdir)/'`geometry.cpp @@ -372,20 +374,6 @@ zoomedit-geometry.obj: geometry.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-geometry.obj `if test -f 'geometry.cpp'; then $(CYGPATH_W) 'geometry.cpp'; else $(CYGPATH_W) '$(srcdir)/geometry.cpp'; fi` -zoomedit-edit.o: edit.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.o -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-edit.o `test -f 'edit.cpp' || echo '$(srcdir)/'`edit.cpp - -zoomedit-edit.obj: edit.cpp -@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-edit.obj -MD -MP -MF $(DEPDIR)/zoomedit-edit.Tpo -c -o zoomedit-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi` -@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-edit.Tpo $(DEPDIR)/zoomedit-edit.Po -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='edit.cpp' object='zoomedit-edit.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-edit.obj `if test -f 'edit.cpp'; then $(CYGPATH_W) 'edit.cpp'; else $(CYGPATH_W) '$(srcdir)/edit.cpp'; fi` - zoomedit-Vertex.o: Vertex.cpp @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Vertex.o -MD -MP -MF $(DEPDIR)/zoomedit-Vertex.Tpo -c -o zoomedit-Vertex.o `test -f 'Vertex.cpp' || echo '$(srcdir)/'`Vertex.cpp @am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Vertex.Tpo $(DEPDIR)/zoomedit-Vertex.Po @@ -442,6 +430,20 @@ zoomedit-Rectangle.obj: Rectangle.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-Rectangle.obj `if test -f 'Rectangle.cpp'; then $(CYGPATH_W) 'Rectangle.cpp'; else $(CYGPATH_W) '$(srcdir)/Rectangle.cpp'; fi` +zoomedit-Room.o: Room.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Room.o -MD -MP -MF $(DEPDIR)/zoomedit-Room.Tpo -c -o zoomedit-Room.o `test -f 'Room.cpp' || echo '$(srcdir)/'`Room.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Room.Tpo $(DEPDIR)/zoomedit-Room.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Room.cpp' object='zoomedit-Room.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-Room.o `test -f 'Room.cpp' || echo '$(srcdir)/'`Room.cpp + +zoomedit-Room.obj: Room.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Room.obj -MD -MP -MF $(DEPDIR)/zoomedit-Room.Tpo -c -o zoomedit-Room.obj `if test -f 'Room.cpp'; then $(CYGPATH_W) 'Room.cpp'; else $(CYGPATH_W) '$(srcdir)/Room.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Room.Tpo $(DEPDIR)/zoomedit-Room.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Room.cpp' object='zoomedit-Room.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-Room.obj `if test -f 'Room.cpp'; then $(CYGPATH_W) 'Room.cpp'; else $(CYGPATH_W) '$(srcdir)/Room.cpp'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/Room.cpp b/Room.cpp new file mode 100644 index 0000000..806b1a9 --- /dev/null +++ b/Room.cpp @@ -0,0 +1,3 @@ +#include "Room.h" + + @@ -0,0 +1,21 @@ +#ifndef ROOM_H_ +#define ROOM_H_ + +#include "Polygon.h" +#include <string> + + +class Room : public Polygon { +private: + std::string name; +public: + Room() {} + Room(std::string name) {this->name = name;} + + + std::string &getName() {return name;} + const std::string &getName() const {return name;} + void setName(const std::string &name) {this->name = name;} +}; + +#endif /*ROOM_H_*/ @@ -1,6 +1,5 @@ #include "draw.h" #include "edit.h" -#include "level.h" #include "geometry.h" #include <math.h> #include <gtk/gtk.h> @@ -142,9 +141,9 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { drawGrid(cr, &rect); - for(i = 0; i < getLevel()->nRooms; i++) { - if(&getLevel()->rooms[i] != getActiveRoom()) { - polygon2path(cr, &getLevel()->rooms[i].polygon, &rect, TRUE); + for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { + if(&*room != getActiveRoom()) { + polygon2path(cr, &*room, &rect, TRUE); } } @@ -155,7 +154,7 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_stroke(cr); if(getEditMode() == EDIT_MODE_SELECTED) { - polygon2path(cr, &getActiveRoom()->polygon, &rect, TRUE); + polygon2path(cr, getActiveRoom(), &rect, TRUE); cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.2); cairo_fill_preserve(cr); @@ -182,22 +181,22 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { if(getHoveredRoom() != NULL && getHoveredRoom() != getActiveRoom() && (getEditMode() == EDIT_MODE_VIEW || getEditMode() == EDIT_MODE_SELECTED)) { - polygon2path(cr, &getHoveredRoom()->polygon, &rect, TRUE); + polygon2path(cr, getHoveredRoom(), &rect, TRUE); cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.7); cairo_stroke(cr); } else if(getEditMode() == EDIT_MODE_ADD) { - polygon2path(cr, &getActiveRoom()->polygon, NULL, FALSE); + polygon2path(cr, getActiveRoom(), NULL, FALSE); - if(isPolygonOk(&getActiveRoom()->polygon)) + if(isPolygonOk(getActiveRoom())) cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.2); else cairo_set_source_rgba(cr, 1.0, 0.3, 0.3, 0.2); cairo_fill_preserve(cr); - if(!getActiveRoom()->polygon.empty() && getHoveredVertex()) { + if(!getActiveRoom()->empty() && getHoveredVertex()) { vertexOk = isVertexOk(getHoveredVertex()); if(vertexOk) @@ -210,10 +209,10 @@ gboolean drawTopView(GtkWidget *widget, GdkEventExpose *event, gpointer data) { cairo_set_source_rgba(cr, 0.0, 0.7, 1.0, 0.7); cairo_stroke(cr); - if(!getActiveRoom()->polygon.empty() && getHoveredVertex() && !vertexOk) { + if(!getActiveRoom()->empty() && getHoveredVertex() && !vertexOk) { cairo_set_source_rgba(cr, 1.0, 0.3, 0.3, 0.7); - cairo_move_to(cr, getActiveRoom()->polygon.back().getX(), getActiveRoom()->polygon.back().getY()); + cairo_move_to(cr, getActiveRoom()->back().getX(), getActiveRoom()->back().getY()); cairo_line_to(cr, getHoveredVertex()->getX(), getHoveredVertex()->getY()); cairo_stroke(cr); @@ -246,16 +245,14 @@ void viewToImage(Vertex *v) { } double getImageWidth() { - const LEVEL *level = getLevel(); double min = 0.0, max = 0.0; - int i; - if(level) { - for(i = 0; i < level->nRooms; i++) { - for(Polygon::iterator it = level->rooms[i].polygon.begin(); it != level->rooms[i].polygon.end(); it++) { - min = MIN(min, it->getX()); - max = MAX(max, it->getX()); + if(getLevel()) { + for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { + for(Room::iterator v = room->begin(); v != room->end(); v++) { + min = MIN(min, v->getX()); + max = MAX(max, v->getX()); } } } @@ -264,15 +261,14 @@ double getImageWidth() { } double getImageHeight() { - const LEVEL *level = getLevel(); double min = 0.0, max = 0.0; - int i; - if(level) { - for(i = 0; i < level->nRooms; i++) { - for(Polygon::iterator it = level->rooms[i].polygon.begin(); it != level->rooms[i].polygon.end(); it++) { - min = MIN(min, it->getY()); - max = MAX(max, it->getY()); + + if(getLevel()) { + for(Level::iterator room = getLevel()->begin(); room != getLevel()->end(); room++) { + for(Room::iterator v = room->begin(); v != room->end(); v++) { + min = MIN(min, v->getY()); + max = MAX(max, v->getY()); } } } @@ -1,12 +1,16 @@ +#include "Level.h" #include "edit.h" -#include "level.h" #include "geometry.h" static int editMode = EDIT_MODE_VIEW; -static ROOM *activeRoom = NULL; -static ROOM *hoveredRoom = NULL; +static Level *level = NULL; + +static Room *activeRoom = NULL; +static Room *hoveredRoom = NULL; + +static Room addRoom; static Vertex hoveredVertex; static int hasHoveredVertex = 0; @@ -15,11 +19,19 @@ int getEditMode() { return editMode; } -ROOM *getActiveRoom() { +Level *getLevel() { + return level; +} + +void setLevel(Level *l) { + level = l; +} + +Room *getActiveRoom() { return activeRoom; } -void setActiveRoom(ROOM *room) { +void setActiveRoom(Room *room) { activeRoom = room; if(room == NULL) { @@ -36,19 +48,15 @@ Vertex *getHoveredVertex() { } void setHoveredVertex(Vertex *v) { - int i; - LEVEL *l; - if(v) { hasHoveredVertex = 1; hoveredVertex = *v; - l = getLevel(); hoveredRoom = NULL; - for(i = 0; i < l->nRooms; i++) { - if(l->rooms[i].polygon.contains(*v)) { - hoveredRoom = &l->rooms[i]; + for(Level::iterator room = level->begin(); room != level->end(); room++) { + if(room->contains(*v)) { + hoveredRoom = &*room; break; } } @@ -60,9 +68,8 @@ void setHoveredVertex(Vertex *v) { } void startAddMode() { - activeRoom = (ROOM*)calloc(1, sizeof(ROOM)); - activeRoom->polygon = Polygon(); - activeRoom->name = (char*)calloc(1, sizeof(unsigned char)); + addRoom = Room(); + activeRoom = &addRoom; editMode = EDIT_MODE_ADD; } @@ -71,32 +78,31 @@ void endAddMode() { editMode = activeRoom ? EDIT_MODE_SELECTED : EDIT_MODE_VIEW; } -ROOM *getHoveredRoom() { +Room *getHoveredRoom() { return hoveredRoom; } static bool isLineOk(Line *l) { - LEVEL *lvl = getLevel(); Line l2; if(activeRoom) { - for(int i = 0; i+2 < activeRoom->polygon.size(); i++) { - l2.setVertex1(activeRoom->polygon[i]); - l2.setVertex2(activeRoom->polygon[i+1]); + for(int i = 0; i+2 < activeRoom->size(); i++) { + l2.setVertex1(activeRoom->at(i)); + l2.setVertex2(activeRoom->at(i+1)); if(l->intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false; } - if(activeRoom->polygon.size() > 1) { - l2.setVertex1(activeRoom->polygon[activeRoom->polygon.size()-2]); - l2.setVertex2(activeRoom->polygon.back()); + if(activeRoom->size() > 1) { + l2.setVertex1(activeRoom->at(activeRoom->size()-2)); + l2.setVertex2(activeRoom->back()); if(l2.contains(l->getVertex2())) return false; } } - for(int i = 0; i < lvl->nRooms; i++) { - if(lvl->rooms[i].polygon.intersects(*l)) + for(Level::iterator room = level->begin(); room != level->end(); room++) { + if(room->intersects(*l)) return false; } @@ -104,19 +110,16 @@ static bool isLineOk(Line *l) { } bool isVertexOk(Vertex *v) { - LEVEL *lvl = getLevel(); Line l; - int i; - - for(i = 0; i < lvl->nRooms; i++) { - if(lvl->rooms[i].polygon.contains(*v)) return false; + for(Level::iterator room = level->begin(); room != level->end(); room++) { + if(room->contains(*v)) return false; } - if(!(getActiveRoom() && !getActiveRoom()->polygon.empty())) + if(!(getActiveRoom() && !getActiveRoom()->empty())) return true; - l.setVertex1(getActiveRoom()->polygon.back()); + l.setVertex1(getActiveRoom()->back()); l.setVertex2(*v); return isLineOk(&l); @@ -125,18 +128,17 @@ bool isVertexOk(Vertex *v) { bool isPolygonOk(Polygon *polygon) { - LEVEL *lvl = getLevel(); Line l, l2; if(polygon->empty()) return false; - for(int i = 0; i < lvl->nRooms; i++) { - if(lvl->rooms[i].polygon.empty()) continue; + for(Level::iterator room = level->begin(); room != level->end(); room++) { + if(room->empty()) continue; - if(lvl->rooms[i].polygon.contains(polygon->front())); + if(room->contains(polygon->front())) return false; - if(polygon->contains(lvl->rooms[i].polygon.front())); + if(polygon->contains(room->front())) return false; } @@ -150,8 +152,8 @@ bool isPolygonOk(Polygon *polygon) { l.setVertex1(*it); l.setVertex2(*it2); - for(int i = 0; i < lvl->nRooms; i++) { - if(lvl->rooms[i].polygon.intersects(l)) + for(Level::iterator room = level->begin(); room != level->end(); room++) { + if(room->intersects(l)) return false; } @@ -1,7 +1,7 @@ #ifndef EDIT_H_ #define EDIT_H_ -#include "level.h" +#include "Level.h" #include "geometry.h" #define EDIT_MODE_VIEW 0 @@ -10,13 +10,16 @@ int getEditMode(); -ROOM *getActiveRoom(); -void setActiveRoom(ROOM *room); +Level *getLevel(); +void setLevel(Level *l); + +Room *getActiveRoom(); +void setActiveRoom(Room *room); void startAddMode(); void endAddMode(); -ROOM *getHoveredRoom(); +Room *getHoveredRoom(); Vertex *getHoveredVertex(); void setHoveredVertex(Vertex *v); diff --git a/geometry.cpp b/geometry.cpp index 7f6bb6c..0967119 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -71,10 +71,10 @@ void simplifyPolygon(const Polygon *in, const Rectangle *rect, Polygon *out) { simplifyVertex(&v, &in->back(), rect); out->push_back(v); - for(Polygon::const_iterator it = in->begin(); it != in->end(); it++) { - Polygon::const_iterator it2 = it+1; - if(it2 == in->end()) it2 = in->begin(); + for(Polygon::const_iterator v2 = in->begin(); v2 != in->end(); v2++) { + Polygon::const_iterator v3 = v2+1; + if(v3 == in->end()) v3 = in->begin(); - addSimplifiedLine(&*it, &*it2, rect, (it2 == in->begin()), out); + addSimplifiedLine(&*v2, &*v3, rect, (v3 == in->begin()), out); } } diff --git a/level.cpp b/level.cpp deleted file mode 100644 index a8d3fdb..0000000 --- a/level.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "level.h" -#include <stdlib.h> - - -static LEVEL *level = NULL; - - -LEVEL *getLevel() { - return level; -} - -void setLevel(LEVEL *l) { - level = l; -} - -void addRoom(LEVEL *lvl, const ROOM *room) { - lvl->nRooms++; - if(lvl->nRooms > 1) - lvl->rooms = (ROOM*)realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM)); - else - lvl->rooms = (ROOM*)calloc(1, sizeof(ROOM)); - lvl->rooms[lvl->nRooms-1] = *room; -} - -void deleteRoom(LEVEL *lvl, unsigned int n) { - int i; - - lvl->nRooms--; - - for(i = n; i < lvl->nRooms; i++) - lvl->rooms[i] = lvl->rooms[i+1]; - - lvl->rooms = (ROOM*)realloc(lvl->rooms, lvl->nRooms*sizeof(ROOM)); -} - -void freeLevel(LEVEL *lvl) { - int i; - - if(lvl) { - if(lvl->rooms) { - for(i = 0; i < lvl->nRooms; i++) { - if(lvl->rooms[i].name) - free(lvl->rooms[i].name); - } - - free(lvl->rooms); - } - - free(lvl); - } -} diff --git a/level.h b/level.h deleted file mode 100644 index 0475a90..0000000 --- a/level.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef LEVEL_H_ -#define LEVEL_H_ - -#include "geometry.h" -#include "Polygon.h" - -typedef struct _ROOM { - Polygon polygon; - char *name; -} ROOM; - -typedef struct _LEVEL { - unsigned int nRooms; - ROOM *rooms; -} LEVEL; - - -LEVEL *getLevel(); -void setLevel(LEVEL *l); - -void addRoom(LEVEL *lvl, const ROOM *room); -void deleteRoom(LEVEL *lvl, unsigned int n); - -void freeLevel(LEVEL *lvl); - -#endif /*LEVEL_H_*/ @@ -3,7 +3,6 @@ #include "edit.h" #include "draw.h" #include "geometry.h" -#include "level.h" #include <gtk/gtk.h> #include <stdlib.h> #include <string.h> @@ -52,7 +51,7 @@ static gboolean buttonEvent(GtkWidget *widget, GdkEventButton *event, gpointer u viewToImage(&v); if(isVertexOk(&v)) { - getActiveRoom()->polygon.push_back(v); + getActiveRoom()->push_back(v); updateSidebar(); } } @@ -86,7 +85,7 @@ gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointe gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { Vertex v(event->x, event->y); - ROOM *last = getHoveredRoom(); + Room *last = getHoveredRoom(); viewToImage(&v); @@ -153,8 +152,7 @@ static void updateScrollbarsCentered() { static void sidebarNameChanged(GtkEditable *editable, gpointer user_data) { if(getActiveRoom() == NULL) return; - free(getActiveRoom()->name); - getActiveRoom()->name = strdup(gtk_entry_get_text(GTK_ENTRY(entryName))); + getActiveRoom()->setName(std::string(gtk_entry_get_text(GTK_ENTRY(entryName)))); } static void sidebarButtonClicked(GtkButton *button, gpointer user_data) { @@ -165,9 +163,9 @@ static void sidebarButtonClicked(GtkButton *button, gpointer user_data) { gtk_widget_queue_draw(drawingArea); } else if(button == GTK_BUTTON(buttonAddDo)) { - if(getActiveRoom() && getActiveRoom()->polygon.size() > 2 && isPolygonOk(&getActiveRoom()->polygon)) { - addRoom(getLevel(), getActiveRoom()); - setActiveRoom(&getLevel()->rooms[getLevel()->nRooms-1]); + if(getActiveRoom() && getActiveRoom()->size() > 2 && isPolygonOk(getActiveRoom())) { + getLevel()->push_back(*getActiveRoom()); + setActiveRoom(&getLevel()->back()); } endAddMode(); @@ -310,14 +308,14 @@ void updateSidebar() { gtk_widget_show(sidebarView); if(getActiveRoom()) { - gtk_entry_set_text(GTK_ENTRY(entryName), getActiveRoom()->name); + gtk_entry_set_text(GTK_ENTRY(entryName), getActiveRoom()->getName().c_str()); gtk_widget_set_sensitive(entryName, TRUE); - string = g_strdup_printf("%.2f", getActiveRoom()->polygon.area()); + string = g_strdup_printf("%.2f", getActiveRoom()->area()); gtk_label_set_text(GTK_LABEL(labelArea), string); g_free(string); - string = g_strdup_printf("%.2f", getActiveRoom()->polygon.perimeter()); + string = g_strdup_printf("%.2f", getActiveRoom()->perimeter()); gtk_label_set_text(GTK_LABEL(labelPerimeter), string); g_free(string); } @@ -335,7 +333,7 @@ void updateSidebar() { gtk_widget_show(sidebarAdd); if(getActiveRoom()) { - if(getActiveRoom()->polygon.size() > 2 && isPolygonOk(&getActiveRoom()->polygon)) + if(getActiveRoom()->size() > 2 && isPolygonOk(getActiveRoom())) gtk_widget_set_sensitive(buttonAddDo, TRUE); else gtk_widget_set_sensitive(buttonAddDo, FALSE); diff --git a/zoomedit.cpp b/zoomedit.cpp index a38dc3b..37b6159 100644 --- a/zoomedit.cpp +++ b/zoomedit.cpp @@ -1,14 +1,14 @@ #include <gtk/gtk.h> #include <stdlib.h> -#include "level.h" +#include "Level.h" #include "window.h" +#include "edit.h" int main(int argc, char *argv[]) { - LEVEL *lvl = (LEVEL*)calloc(1, sizeof(LEVEL)); GtkWidget *window; - setLevel(lvl); + setLevel(new Level()); gtk_init(&argc, &argv); @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) { gtk_main(); - freeLevel(lvl); + delete getLevel(); return 0; } |