diff options
-rw-r--r-- | Drawer.cpp | 21 | ||||
-rw-r--r-- | EditManager.cpp | 67 | ||||
-rw-r--r-- | EditManager.h | 15 | ||||
-rw-r--r-- | FileManager.cpp | 54 | ||||
-rw-r--r-- | FileManager.h | 2 | ||||
-rw-r--r-- | Level.h | 10 | ||||
-rw-r--r-- | LevelObject.h | 20 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | Makefile.in | 40 | ||||
-rw-r--r-- | PlayerStart.h | 19 | ||||
-rw-r--r-- | Renderer.cpp | 110 | ||||
-rw-r--r-- | Renderer.h | 11 | ||||
-rw-r--r-- | Room.cpp | 3 | ||||
-rw-r--r-- | Room.h | 10 | ||||
-rw-r--r-- | SharedPtr.h | 46 | ||||
-rw-r--r-- | SidebarView.cpp | 156 | ||||
-rw-r--r-- | SidebarView.h | 6 | ||||
-rw-r--r-- | Vertex.h | 3 | ||||
-rw-r--r-- | Vertex3d.cpp | 35 | ||||
-rw-r--r-- | Vertex3d.h | 33 |
20 files changed, 498 insertions, 167 deletions
@@ -17,6 +17,7 @@ void Drawer::realize(GtkWidget *widget, Drawer *drawer) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -238,9 +239,13 @@ void Drawer::viewToImage(Vertex *v) const { float Drawer::getImageWidth() const { float max = 0; - for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - for(Room::iterator v = room->begin(); v != room->end(); v++) { - max = fmaxf(max, fabsf(v->getX())); + for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) { + if((*object)->isOfType("Room")) { + Room *room = (Room*)&**object; + + for(Room::iterator v = room->begin(); v != room->end(); v++) { + max = fmaxf(max, fabsf(v->getX())); + } } } @@ -250,9 +255,13 @@ float Drawer::getImageWidth() const { float Drawer::getImageHeight() const { float max = 0; - for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - for(Room::iterator v = room->begin(); v != room->end(); v++) { - max = fmaxf(max, fabsf(v->getY())); + for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) { + if((*object)->isOfType("Room")) { + Room *room = (Room*)&**object; + + for(Room::iterator v = room->begin(); v != room->end(); v++) { + max = fmaxf(max, fabsf(v->getY())); + } } } diff --git a/EditManager.cpp b/EditManager.cpp index 8e2c045..0656939 100644 --- a/EditManager.cpp +++ b/EditManager.cpp @@ -5,23 +5,21 @@ bool EditManager::lineOk(const Line& l) const { Line l2; - if(activeRoom) { - for(size_t 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; - } + for(size_t i = 0; i+2 < newRoom.size(); i++) { + l2.setVertex1(newRoom.at(i)); + l2.setVertex2(newRoom.at(i+1)); - if(activeRoom->size() > 1) { - l2.setVertex1(activeRoom->at(activeRoom->size()-2)); - l2.setVertex2(activeRoom->back()); - if(l2.contains(l.getVertex2())) return false; - } + if(l.intersects(l2, NULL) == INTERSECTION_SEGMENT_SEGMENT) return false; + } + + if(newRoom.size() > 1) { + l2.setVertex1(newRoom.at(newRoom.size()-2)); + l2.setVertex2(newRoom.back()); + if(l2.contains(l.getVertex2())) return false; } for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - if(room->intersects(l)) + if((*room)->isOfType("Room") && ((Room*)&**room)->intersects(l)) return false; } @@ -32,20 +30,24 @@ bool EditManager::lineOk(const Line& l) const { EditManager::EditManager(Window *window) { this->window = window; - activeRoom = NULL; + selectedObject = NULL; mode = VIEW; - hoveredRoom = NULL; + hoveredObject = NULL; hasHoveredVertex = false; } +void EditManager::update() { + window->update(); +} + void EditManager::addRoom() { if(mode == VIEW) { newRoom = Room(); mode = ADD; - activeRoom = &newRoom; + selectedObject = &newRoom; window->update(); } @@ -57,11 +59,11 @@ void EditManager::finishRoom() { if(newRoom.size() > 2 && polygonOk(newRoom)) { newRoom.setName(idManager.generate("room")); - window->getLevel().push_back(newRoom); - activeRoom = &window->getLevel().back(); + window->getLevel().push_back(SharedPtr<LevelObject>(new Room(newRoom))); + selectedObject = &*window->getLevel().back(); } else { - activeRoom = NULL; + selectedObject = NULL; } window->update(); @@ -86,18 +88,18 @@ void EditManager::setHoveredVertex(Vertex *v) { hasHoveredVertex = true; hoveredVertex = *v; - hoveredRoom = NULL; + hoveredObject = NULL; - for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - if(room->contains(*v)) { - hoveredRoom = &*room; + for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) { + if((*object)->hit(*v)) { + hoveredObject = &**object; break; } } } else { hasHoveredVertex = false; - hoveredRoom = NULL; + hoveredObject = NULL; } window->update(); @@ -111,7 +113,7 @@ void EditManager::buttonPress(unsigned int button) { switch(mode) { case VIEW: - activeRoom = getHoveredRoom(); + selectedObject = hoveredObject; break; case ADD: @@ -127,13 +129,13 @@ bool EditManager::vertexOk(const Vertex& v) const { Line l; for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - if(room->contains(v)) return false; + if((*room)->isOfType("Room") && ((Room*)&**room)->contains(v)) return false; } - if(!(activeRoom && !activeRoom->empty())) + if(newRoom.empty()) return true; - l.setVertex1(activeRoom->back()); + l.setVertex1(newRoom.back()); l.setVertex2(v); return lineOk(l); @@ -144,7 +146,12 @@ bool EditManager::polygonOk(const Polygon& polygon) const { if(polygon.empty()) return false; - for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { + for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) { + if(!(*object)->isOfType("Room")) + continue; + + Room *room = (Room*)&**object; + if(room->empty()) continue; if(room->contains(polygon.front())) @@ -168,7 +175,7 @@ bool EditManager::polygonOk(const Polygon& polygon) const { l.setVertex2(*it2); for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { - if(room->intersects(l)) + if((*room)->isOfType("Room") && ((Room*)&**room)->intersects(l)) return false; } } diff --git a/EditManager.h b/EditManager.h index 6b52389..00729bf 100644 --- a/EditManager.h +++ b/EditManager.h @@ -1,6 +1,7 @@ #ifndef EDITMANAGER_H_ #define EDITMANAGER_H_ +#include "SharedPtr.h" #include "Room.h" #include "IdManager.h" @@ -22,9 +23,9 @@ class EditManager { Window *window; Room newRoom; - Room *activeRoom; + LevelObject *selectedObject; - Room *hoveredRoom; + LevelObject *hoveredObject; Vertex hoveredVertex; bool hasHoveredVertex; @@ -34,6 +35,8 @@ class EditManager { public: EditManager(Window *window); + void update(); + void addRoom(); void finishRoom(); @@ -43,12 +46,12 @@ class EditManager { return mode; } - Room* getActiveRoom() { - return activeRoom; + LevelObject* getSelectedObject() { + return selectedObject; } - Room* getHoveredRoom() { - return hoveredRoom; + LevelObject* getHoveredObject() { + return hoveredObject; } Vertex* getHoveredVertex(); diff --git a/FileManager.cpp b/FileManager.cpp index 0025cf2..89c6d41 100644 --- a/FileManager.cpp +++ b/FileManager.cpp @@ -159,6 +159,27 @@ bool FileManager::writeTexCoords(xmlTextWriterPtr writer, float s, float t) { return true; } +bool FileManager::writeStart(xmlTextWriterPtr writer, const Vertex3d &start) { + // <vertex> + if(xmlTextWriterStartElement(writer, (xmlChar*)"start") < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"x", "%f", start.getX()) < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"y", "%f", start.getY()) < 0) + return false; + + if(xmlTextWriterWriteFormatAttribute(writer, (xmlChar*)"z", "%f", start.getZ()) < 0) + return false; + + // </vertex> + if(xmlTextWriterEndElement(writer) < 0) + return false; + + return true; +} + FileManager::FileManager(Window *window) { this->window = window; @@ -261,32 +282,10 @@ bool FileManager::write() { return false; } - // <start> - 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) { + /*if(!writeStart(writer, window->getLevel().getPlayerStart())) { xmlFreeTextWriter(writer); return false; - } - - // </start> - if(xmlTextWriterEndElement(writer) < 0) { - xmlFreeTextWriter(writer); - return false; - } + }*/ // </info> if(xmlTextWriterEndElement(writer) < 0) { @@ -300,7 +299,12 @@ bool FileManager::write() { return false; } - for(Level::iterator room = window->getLevel().begin(); room != window->getLevel().end(); room++) { + for(Level::iterator object = window->getLevel().begin(); object != window->getLevel().end(); object++) { + if(!(*object)->isOfType("Room")) + continue; + + Room *room = (Room*)&**object; + // <room> if(xmlTextWriterStartElement(writer, (xmlChar*)"room") < 0) { xmlFreeTextWriter(writer); diff --git a/FileManager.h b/FileManager.h index 2309190..93c9ec2 100644 --- a/FileManager.h +++ b/FileManager.h @@ -4,6 +4,7 @@ #include <gtk/gtk.h> #include <libxml/xmlwriter.h> #include "Triangle.h" +#include "Vertex3d.h" class Window; @@ -25,6 +26,7 @@ class FileManager 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); + bool writeStart(xmlTextWriterPtr writer, const Vertex3d &start); public: FileManager(Window *window); @@ -2,10 +2,16 @@ #define LEVEL_H_ -#include "Room.h" +#include "LevelObject.h" +#include "SharedPtr.h" +#include "PlayerStart.h" #include <vector> -class Level : public std::vector<Room> { +class Level : public std::vector<SharedPtr<LevelObject> > { + public: + Level() { + push_back(SharedPtr<LevelObject>(new PlayerStart())); + } }; #endif /*LEVEL_H_*/ diff --git a/LevelObject.h b/LevelObject.h new file mode 100644 index 0000000..6ab93a4 --- /dev/null +++ b/LevelObject.h @@ -0,0 +1,20 @@ +#ifndef LEVELOBJECT_H_ +#define LEVELOBJECT_H_ + +#include "Vertex.h" +#include <cstring> + + +class LevelObject { + public: + virtual ~LevelObject() {} + + virtual const char* getType() const = 0; + virtual bool hit(const Vertex &v) const = 0; + + bool isOfType(const char *type) const { + return (std::strcmp(getType(), type) == 0); + } +}; + +#endif /*LEVELOBJECT_H_*/ diff --git a/Makefile.am b/Makefile.am index aeb0122..adfd9d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,9 @@ bin_PROGRAMS = zoomedit zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \ - Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ + Line.cpp Polygon.cpp Rectangle.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ EditManager.cpp FileManager.cpp SidebarToolbox.cpp \ - ToolSelector.cpp ToolAddPolygon.cpp + ToolSelector.cpp ToolAddPolygon.cpp Vertex3d.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 35421b0..619fa70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -52,15 +52,15 @@ am_zoomedit_OBJECTS = zoomedit-zoomedit.$(OBJEXT) \ zoomedit-UIManager.$(OBJEXT) zoomedit-Renderer.$(OBJEXT) \ zoomedit-Vertex.$(OBJEXT) zoomedit-Line.$(OBJEXT) \ zoomedit-Polygon.$(OBJEXT) zoomedit-Rectangle.$(OBJEXT) \ - zoomedit-Room.$(OBJEXT) zoomedit-Triangle.$(OBJEXT) \ - zoomedit-IdManager.$(OBJEXT) zoomedit-WindowManager.$(OBJEXT) \ + zoomedit-Triangle.$(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-FileManager.$(OBJEXT) \ zoomedit-SidebarToolbox.$(OBJEXT) \ zoomedit-ToolSelector.$(OBJEXT) \ - zoomedit-ToolAddPolygon.$(OBJEXT) + zoomedit-ToolAddPolygon.$(OBJEXT) zoomedit-Vertex3d.$(OBJEXT) zoomedit_OBJECTS = $(am_zoomedit_OBJECTS) zoomedit_DEPENDENCIES = DEFAULT_INCLUDES = -I.@am__isrc@ @@ -183,11 +183,11 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ zoomedit_SOURCES = zoomedit.cpp UIManager.cpp Renderer.cpp Vertex.cpp \ - Line.cpp Polygon.cpp Rectangle.cpp Room.cpp Triangle.cpp \ + Line.cpp Polygon.cpp Rectangle.cpp Triangle.cpp \ IdManager.cpp WindowManager.cpp SidebarManager.cpp \ Window.cpp SidebarView.cpp SidebarAdd.cpp Drawer.cpp \ EditManager.cpp FileManager.cpp SidebarToolbox.cpp \ - ToolSelector.cpp ToolAddPolygon.cpp + ToolSelector.cpp ToolAddPolygon.cpp Vertex3d.cpp zoomedit_CPPFLAGS = @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@ @libxml2_CFLAGS@ zoomedit_LDADD = @GTK_LIBS@ @GTKGLEXT_LIBS@ @libxml2_LIBS@ @@ -287,7 +287,6 @@ distclean-compile: @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-Renderer.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Room.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarAdd.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-SidebarToolbox.Po@am__quote@ @@ -297,6 +296,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Triangle.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-UIManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Vertex3d.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-Window.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-WindowManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zoomedit-zoomedit.Po@am__quote@ @@ -413,20 +413,6 @@ 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` - zoomedit-Triangle.o: Triangle.cpp @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Triangle.o -MD -MP -MF $(DEPDIR)/zoomedit-Triangle.Tpo -c -o zoomedit-Triangle.o `test -f 'Triangle.cpp' || echo '$(srcdir)/'`Triangle.cpp @am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Triangle.Tpo $(DEPDIR)/zoomedit-Triangle.Po @@ -609,6 +595,20 @@ zoomedit-ToolAddPolygon.obj: ToolAddPolygon.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-ToolAddPolygon.obj `if test -f 'ToolAddPolygon.cpp'; then $(CYGPATH_W) 'ToolAddPolygon.cpp'; else $(CYGPATH_W) '$(srcdir)/ToolAddPolygon.cpp'; fi` +zoomedit-Vertex3d.o: Vertex3d.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Vertex3d.o -MD -MP -MF $(DEPDIR)/zoomedit-Vertex3d.Tpo -c -o zoomedit-Vertex3d.o `test -f 'Vertex3d.cpp' || echo '$(srcdir)/'`Vertex3d.cpp +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Vertex3d.Tpo $(DEPDIR)/zoomedit-Vertex3d.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Vertex3d.cpp' object='zoomedit-Vertex3d.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-Vertex3d.o `test -f 'Vertex3d.cpp' || echo '$(srcdir)/'`Vertex3d.cpp + +zoomedit-Vertex3d.obj: Vertex3d.cpp +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(zoomedit_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT zoomedit-Vertex3d.obj -MD -MP -MF $(DEPDIR)/zoomedit-Vertex3d.Tpo -c -o zoomedit-Vertex3d.obj `if test -f 'Vertex3d.cpp'; then $(CYGPATH_W) 'Vertex3d.cpp'; else $(CYGPATH_W) '$(srcdir)/Vertex3d.cpp'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/zoomedit-Vertex3d.Tpo $(DEPDIR)/zoomedit-Vertex3d.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Vertex3d.cpp' object='zoomedit-Vertex3d.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-Vertex3d.obj `if test -f 'Vertex3d.cpp'; then $(CYGPATH_W) 'Vertex3d.cpp'; else $(CYGPATH_W) '$(srcdir)/Vertex3d.cpp'; fi` + ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ unique=`for i in $$list; do \ diff --git a/PlayerStart.h b/PlayerStart.h new file mode 100644 index 0000000..003583d --- /dev/null +++ b/PlayerStart.h @@ -0,0 +1,19 @@ +#ifndef PLAYERSTART_H_ +#define PLAYERSTART_H_ + +#include "LevelObject.h" +#include "Vertex3d.h" + + +class PlayerStart : public Vertex3d, public LevelObject { + public: + virtual bool hit(const Vertex &v) const { + return (v.distanceSq(Vertex(getX(), getZ())) < 0.09); + } + + virtual const char* getType() const { + return "PlayerStart"; + } +}; + +#endif /*PLAYERSTART_H_*/ diff --git a/Renderer.cpp b/Renderer.cpp index 9365589..1463d21 100644 --- a/Renderer.cpp +++ b/Renderer.cpp @@ -1,4 +1,5 @@ #include "Renderer.h" +#include "PlayerStart.h" #include <GL/gl.h> @@ -77,70 +78,111 @@ void Renderer::fillPolygon(const Polygon &polygon) { } void Renderer::drawPolygon(const Polygon &polygon, bool close) { - glBegin(GL_LINE_STRIP); + glBegin(close ? GL_LINE_LOOP : GL_LINE_STRIP); for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++) - glVertex2d(vertex->getX(), vertex->getY()); + glVertex2f(vertex->getX(), vertex->getY()); - if(close) - glVertex2d(polygon.front().getX(), polygon.front().getY()); + glEnd(); +} + +void Renderer::drawCircle(const Vertex &m, float r, int n) { + glBegin(GL_LINE_LOOP); + + for(int i = 0; i < n; i++) + glVertex2f(m.getX()+r*cosf(2*M_PI*i/n), m.getY()+r*sinf(2*M_PI*i/n)); + + glEnd(); +} + +void Renderer::drawCross(const Vertex &m, float r) { + glBegin(GL_LINES); + + glVertex2f(m.getX()-r*M_SQRT1_2, m.getY()-r*M_SQRT1_2); + glVertex2f(m.getX()+r*M_SQRT1_2, m.getY()+r*M_SQRT1_2); + + glVertex2f(m.getX()+r*M_SQRT1_2, m.getY()-r*M_SQRT1_2); + glVertex2f(m.getX()-r*M_SQRT1_2, m.getY()+r*M_SQRT1_2); glEnd(); } +void Renderer::renderObject(const LevelObject &object, bool selected, bool hovered, float scale) { + if(object.isOfType("Room")) + renderRoom(*(Room*)&object, selected, hovered, scale); + else if(object.isOfType("PlayerStart")) + renderPlayerStart(*(PlayerStart*)&object, selected, hovered, scale); +} + +void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float scale) { + if(selected) + glColor4f(0.0f, 0.7f, 1.0f, 0.2f); + else + glColor4f(0.0f, 0.7f, 1.0f, 0.3f); + + fillPolygon(room); + + if(selected) { + glColor4f(1.0f, 1.0f, 1.0f, 0.9f); + glLineWidth(2.0f); + } + else if(hovered && editManager->getMode() == EditManager::VIEW) { + glColor4f(0.0f, 0.7f, 1.0f, 0.7f); + glLineWidth(2.0f); + } + else { + glColor4f(0.0f, 0.7f, 1.0f, 0.7f); + glLineWidth(1.0f); + } + + drawPolygon(room); +} + +void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) { + glLineWidth(1.0f); + glColor4f(0.0f, 0.7f, 0.7f, 0.7f); + drawCircle(Vertex(start.getX(), start.getZ()), 0.3f, 128); + + glLineWidth(2.0f); + glColor4f(1.0f, 1.0f, 1.0f, 0.7f); + drawCross(Vertex(start.getX(), start.getZ()), 0.5f/sqrtf(scale)); +} + void Renderer::render(const Level &level, const Rectangle &rect, float scale) { glClear(GL_COLOR_BUFFER_BIT); glLineWidth(1.0f); + glPointSize(10.0f); drawGrid(rect, scale); - for(Level::const_iterator room = level.begin(); room != level.end(); room++) { - if(&*room == editManager->getActiveRoom() && editManager->getMode() == EditManager::ADD) continue; - - if(&*room == editManager->getActiveRoom()) - glColor4f(0.0f, 0.7f, 1.0f, 0.2f); - else - glColor4f(0.0f, 0.7f, 1.0f, 0.3f); - - fillPolygon(*room); - - if(&*room == editManager->getActiveRoom()) { - glColor4f(1.0f, 1.0f, 1.0f, 0.9f); - glLineWidth(2.0f); - } - else if(&*room == editManager->getHoveredRoom() && editManager->getMode() == EditManager::VIEW) { - glColor4f(0.0f, 0.7f, 1.0f, 0.7f); - glLineWidth(2.0f); - } - else { - glColor4f(0.0f, 0.7f, 1.0f, 0.7f); - glLineWidth(1.0f); - } - - drawPolygon(*room, true); + for(Level::const_iterator object = level.begin(); object != level.end(); object++) { + renderObject(**object, (&**object == editManager->getSelectedObject()), + (&**object == editManager->getHoveredObject()), scale); } if(editManager->getMode() == EditManager::ADD) { - if(editManager->polygonOk(*editManager->getActiveRoom())) + Room *activeRoom = (Room*)editManager->getSelectedObject(); + + if(editManager->polygonOk(*activeRoom)) glColor4f(0.0f, 0.7f, 1.0f, 0.2f); else glColor4f(1.0f, 0.3f, 0.3f, 0.2f); - fillPolygon(*editManager->getActiveRoom()); + fillPolygon(*activeRoom); glLineWidth(2.0f); glColor4f(0.0f, 0.7f, 1.0f, 0.7f); - drawPolygon(*editManager->getActiveRoom(), false); + drawPolygon(*activeRoom, false); - if(!editManager->getActiveRoom()->empty() && editManager->getHoveredVertex()) { + if(!activeRoom->empty() && editManager->getHoveredVertex()) { if(!editManager->vertexOk(*editManager->getHoveredVertex())) glColor4f(1.0f, 0.3f, 0.3f, 0.7f); glBegin(GL_LINES); - glVertex2d(editManager->getActiveRoom()->back().getX(), editManager->getActiveRoom()->back().getY()); - glVertex2d(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY()); + glVertex2f(activeRoom->back().getX(), activeRoom->back().getY()); + glVertex2f(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY()); glEnd(); } @@ -5,6 +5,8 @@ #include "Polygon.h" #include "EditManager.h" #include "Level.h" +#include "Room.h" +#include "PlayerStart.h" class Renderer { @@ -13,7 +15,14 @@ class Renderer { void drawGrid(const Rectangle &rect, float scale); void fillPolygon(const Polygon &polygon); - void drawPolygon(const Polygon &polygon, bool close); + void drawPolygon(const Polygon &polygon, bool close = true); + void drawCircle(const Vertex &m, float r, int n); + void drawCross(const Vertex &m, float r); + + void renderObject(const LevelObject &object, bool selected, bool hovered, float scale); + + void renderRoom(const Room &room, bool selected, bool hovered, float scale); + void renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale); public: Renderer(EditManager *editManager) { diff --git a/Room.cpp b/Room.cpp deleted file mode 100644 index 806b1a9..0000000 --- a/Room.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "Room.h" - - @@ -2,10 +2,11 @@ #define ROOM_H_ #include "Polygon.h" +#include "LevelObject.h" #include <string> -class Room : public Polygon { +class Room : public Polygon, public LevelObject { private: std::string name; float height; @@ -14,13 +15,18 @@ class Room : public Polygon { Room() {height = 10;} Room(std::string name) {this->name = name; height = 10;} - std::string &getName() {return name;} const std::string &getName() const {return name;} void setName(const std::string &name) {this->name = name;} float getHeight() const {return height;} void setHeight(float height) {this->height = height;} + + virtual bool hit(const Vertex &v) const {return contains(v);} + + virtual const char* getType() const { + return "Room"; + } }; #endif /*ROOM_H_*/ diff --git a/SharedPtr.h b/SharedPtr.h new file mode 100644 index 0000000..1b5d2bc --- /dev/null +++ b/SharedPtr.h @@ -0,0 +1,46 @@ +#ifndef SHAREDPTR_H_ +#define SHAREDPTR_H_ + +template <class T> +class SharedPtr { + private: + class Counter { + public: + Counter(T *o) : object(o), refCount(1) {} + ~Counter() {delete object;} + + T *object; + unsigned int refCount; + }; + + Counter *counter; + + public: + SharedPtr(T *o) : counter(new Counter(o)) {} + + SharedPtr(const SharedPtr<T> &c) : counter(c.counter) { + counter->refCount++; + } + + virtual ~SharedPtr() { + if(--counter->refCount == 0) + delete counter; + } + + SharedPtr<T>& operator=(const SharedPtr<T>& c) { + c.counter->refCount++; + if(--counter->refCount == 0) + delete counter; + + counter = c.counter; + return *this; + } + + T* operator->() {return counter->object;} + T& operator*() {return *counter->object;} + + const T* operator->() const {return counter->object;} + const T& operator*() const {return *counter->object;} +}; + +#endif /*SHAREDPTR_H_*/ diff --git a/SidebarView.cpp b/SidebarView.cpp index 8e58967..cdf4a2e 100644 --- a/SidebarView.cpp +++ b/SidebarView.cpp @@ -1,11 +1,25 @@ #include "SidebarView.h" +#include "PlayerStart.h" -void SidebarView::spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView *view) { - if(!view->editor->getActiveRoom()) +void SidebarView::spinButtonChanged(GtkWidget *spinbutton, SidebarView *view) { + if(!view->editor->getSelectedObject()) return; - view->editor->getActiveRoom()->setHeight(gtk_spin_button_get_value(spinbutton)); + if(view->editor->getSelectedObject()->isOfType("Room")) { + if(spinbutton == view->spinButtonHeight) + ((Room*)view->editor->getSelectedObject())->setHeight(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + } + else if(view->editor->getSelectedObject()->isOfType("PlayerStart")) { + if(spinbutton == view->spinButtonX) + ((PlayerStart*)view->editor->getSelectedObject())->setX(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + else if(spinbutton == view->spinButtonY) + ((PlayerStart*)view->editor->getSelectedObject())->setY(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + else if(spinbutton == view->spinButtonZ) + ((PlayerStart*)view->editor->getSelectedObject())->setZ(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + } + + view->editor->update(); } SidebarView::SidebarView(EditManager *editor) { @@ -14,54 +28,114 @@ SidebarView::SidebarView(EditManager *editor) { sidebar = gtk_vbox_new(FALSE, 0); g_object_ref_sink(G_OBJECT(sidebar)); - GtkWidget *labelRoomInfo = gtk_label_new(NULL); - gtk_label_set_markup(GTK_LABEL(labelRoomInfo), "<b>Room info:</b>"); - gtk_misc_set_alignment(GTK_MISC(labelRoomInfo), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(sidebar), labelRoomInfo, FALSE, FALSE, 5); + labelType = gtk_label_new(NULL); + gtk_misc_set_alignment(GTK_MISC(labelType), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(sidebar), labelType, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5); - GtkWidget *labelName = gtk_label_new("Name: "); + labelName = gtk_label_new("Name: "); gtk_misc_set_alignment(GTK_MISC(labelName), 0.0, 0.5); + gtk_widget_set_no_show_all(labelName, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), labelName, FALSE, FALSE, 0); entryName = gtk_entry_new(); gtk_widget_set_size_request(entryName, 0, -1); //g_signal_connect(G_OBJECT(entryName), "focus-out-event", G_CALLBACK(sidebarNameFocusOutEvent), NULL); //gtk_widget_add_events(entryName, GDK_FOCUS_CHANGE_MASK); + gtk_widget_set_no_show_all(entryName, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), entryName, FALSE, FALSE, 0); - GtkWidget *tableRoomData = gtk_table_new(2, 3, FALSE); + tableRoomData = gtk_table_new(2, 3, FALSE); gtk_table_set_row_spacings(GTK_TABLE(tableRoomData), 5); + gtk_widget_set_no_show_all(tableRoomData, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), tableRoomData, FALSE, FALSE, 5); GtkWidget *labelAreaLabel = gtk_label_new("Room area: "); gtk_misc_set_alignment(GTK_MISC(labelAreaLabel), 0.0, 0.5); + gtk_widget_show(labelAreaLabel); gtk_table_attach(GTK_TABLE(tableRoomData), labelAreaLabel, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); labelArea = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(labelArea), 1.0, 0.5); + gtk_widget_show(labelArea); gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelArea, 1, 2, 0, 1); GtkWidget *labelPerimeterLabel = gtk_label_new("Room perimeter: "); gtk_misc_set_alignment(GTK_MISC(labelPerimeterLabel), 0.0, 0.5); + gtk_widget_show(labelPerimeterLabel); gtk_table_attach(GTK_TABLE(tableRoomData), labelPerimeterLabel, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); labelPerimeter = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(labelPerimeter), 1.0, 0.5); + gtk_widget_show(labelPerimeter); gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeter, 1, 2, 1, 2); GtkWidget *labelHeight = gtk_label_new("Height: "); gtk_misc_set_alignment(GTK_MISC(labelHeight), 0.0, 0.5); + gtk_widget_show(labelHeight); gtk_table_attach(GTK_TABLE(tableRoomData), labelHeight, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); spinButtonHeight = gtk_spin_button_new_with_range(0, 10000, 0.1f); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonHeight), 2); gtk_entry_set_alignment(GTK_ENTRY(spinButtonHeight), 1.0); + gtk_widget_show(spinButtonHeight); gtk_table_attach(GTK_TABLE(tableRoomData), spinButtonHeight, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); gtk_widget_set_size_request(spinButtonHeight, 0, -1); - g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonHeightChanged), this); + g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonChanged), this); + + tablePlayerStart = gtk_table_new(2, 4, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(tablePlayerStart), 5); + gtk_widget_set_no_show_all(tablePlayerStart, TRUE); + gtk_box_pack_start(GTK_BOX(sidebar), tablePlayerStart, FALSE, FALSE, 5); + + GtkWidget *labelCoordinates = gtk_label_new("Coordinates:"); + gtk_misc_set_alignment(GTK_MISC(labelCoordinates), 0.0, 0.5); + gtk_widget_show(labelCoordinates); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelCoordinates, 0, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + + GtkWidget *labelX = gtk_label_new("X: "); + gtk_misc_set_alignment(GTK_MISC(labelX), 0.0, 0.5); + gtk_widget_show(labelX); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelX, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonX = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonX), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonX), 1.0); + gtk_widget_show(spinButtonX); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonX, 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonX, 0, -1); + g_signal_connect(G_OBJECT(spinButtonX), "value-changed", G_CALLBACK(spinButtonChanged), this); + + GtkWidget *labelY = gtk_label_new("Y: "); + gtk_misc_set_alignment(GTK_MISC(labelY), 0.0, 0.5); + gtk_widget_show(labelY); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelY, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonY = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonY), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonY), 1.0); + gtk_widget_show(spinButtonY); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonY, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonY, 0, -1); + g_signal_connect(G_OBJECT(spinButtonY), "value-changed", G_CALLBACK(spinButtonChanged), this); + + GtkWidget *labelZ = gtk_label_new("Z: "); + gtk_misc_set_alignment(GTK_MISC(labelZ), 0.0, 0.5); + gtk_widget_show(labelZ); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelZ, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonZ = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonZ), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonZ), 1.0); + gtk_widget_show(spinButtonZ); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonZ, 1, 2, 3, 4, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonZ, 0, -1); + g_signal_connect(G_OBJECT(spinButtonZ), "value-changed", G_CALLBACK(spinButtonChanged), this); gtk_widget_show_all(sidebar); } @@ -75,29 +149,47 @@ GtkWidget* SidebarView::getWidget() { } void SidebarView::update() { - if(editor->getActiveRoom()) { - gtk_entry_set_text(GTK_ENTRY(entryName), editor->getActiveRoom()->getName().c_str()); - gtk_widget_set_sensitive(entryName, TRUE); - - gchar *string = g_strdup_printf("%.2f", editor->getActiveRoom()->area()); - gtk_label_set_text(GTK_LABEL(labelArea), string); - g_free(string); - - string = g_strdup_printf("%.2f", editor->getActiveRoom()->perimeter()); - gtk_label_set_text(GTK_LABEL(labelPerimeter), string); - g_free(string); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), editor->getActiveRoom()->getHeight()); - gtk_widget_set_sensitive(spinButtonHeight, TRUE); + gtk_widget_hide(labelName); + gtk_widget_hide(entryName); + gtk_widget_hide(tableRoomData); + gtk_widget_hide(tablePlayerStart); + + if(editor->getSelectedObject()) { + if(editor->getSelectedObject()->isOfType("Room")) { + Room *room = (Room*)editor->getSelectedObject(); + + gtk_label_set_markup(GTK_LABEL(labelType), "<b>Room info:</b>"); + + gtk_widget_show(labelName); + + gtk_entry_set_text(GTK_ENTRY(entryName), room->getName().c_str()); + gtk_widget_show(entryName); + + gchar *string = g_strdup_printf("%.2f", room->area()); + gtk_label_set_text(GTK_LABEL(labelArea), string); + g_free(string); + + string = g_strdup_printf("%.2f", room->perimeter()); + gtk_label_set_text(GTK_LABEL(labelPerimeter), string); + g_free(string); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), room->getHeight()); + + gtk_widget_show(tableRoomData); + } + else if(editor->getSelectedObject()->isOfType("PlayerStart")) { + PlayerStart *playerStart = (PlayerStart*)editor->getSelectedObject(); + + gtk_label_set_markup(GTK_LABEL(labelType), "<b>Player start:</b>"); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonX), playerStart->getX()); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonY), playerStart->getY()); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonZ), playerStart->getZ()); + + gtk_widget_show(tablePlayerStart); + } } else { - gtk_entry_set_text(GTK_ENTRY(entryName), ""); - gtk_widget_set_sensitive(entryName, FALSE); - - gtk_label_set_text(GTK_LABEL(labelArea), NULL); - gtk_label_set_text(GTK_LABEL(labelPerimeter), NULL); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), 0.0); - gtk_widget_set_sensitive(spinButtonHeight, FALSE); + gtk_label_set_markup(GTK_LABEL(labelType), "<b>[Nothing selected]</b>"); } } diff --git a/SidebarView.h b/SidebarView.h index c0249fa..01cdcb9 100644 --- a/SidebarView.h +++ b/SidebarView.h @@ -8,7 +8,9 @@ class SidebarView : public Sidebar { private: GtkWidget *sidebar; - GtkWidget *entryName, *labelArea, *labelPerimeter, *spinButtonHeight; + GtkWidget *labelType, *labelName, *entryName; + GtkWidget *tableRoomData, *labelArea, *labelPerimeter, *spinButtonHeight; + GtkWidget *tablePlayerStart, *spinButtonX, *spinButtonY, *spinButtonZ; EditManager *editor; @@ -16,7 +18,7 @@ class SidebarView : public Sidebar { SidebarView(const SidebarView &w); const SidebarView& operator=(const SidebarView &w); - static void spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView *view); + static void spinButtonChanged(GtkWidget *spinbutton, SidebarView *view); public: SidebarView(EditManager *editor); @@ -4,9 +4,9 @@ class Vertex { private: float x, y; + public: Vertex() {x = y = 0.0;} - Vertex(const Vertex &v) {x = v.x; y = v.y;} Vertex(float x, float y) {this->x = x; this->y = y;} float getX() const {return x;} @@ -15,7 +15,6 @@ class Vertex { float getY() const {return y;} void setY(float y) {this->y = y;} - void setLocation(const Vertex &v) {x = v.x; y = v.y;} void setLocation(float x, float y) {this->x = x; this->y = y;} float distanceSq(const Vertex &v) const; diff --git a/Vertex3d.cpp b/Vertex3d.cpp new file mode 100644 index 0000000..16c0e27 --- /dev/null +++ b/Vertex3d.cpp @@ -0,0 +1,35 @@ +#include "Vertex3d.h" +#include <math.h> + +float Vertex3d::distanceSq(const Vertex3d &v) const { + return (x - v.x)*(x - v.x) + (y - v.y)*(y - v.y) + (z - v.z)*(z - v.z); +} + +float Vertex3d::distance(const Vertex3d &v) const { + return sqrtf(distanceSq(v)); +} + + +Vertex3d Vertex3d::operator+(const Vertex3d &v) const { + return Vertex3d(x + v.x, y + v.y, z + v.z); +} + +Vertex3d Vertex3d::operator-(const Vertex3d &v) const { + return Vertex3d(x - v.x, y - v.y, z - v.z); +} + +Vertex3d& Vertex3d::operator+=(const Vertex3d &v) { + x += v.x; + y += v.y; + z += v.z; + + return *this; +} + +Vertex3d& Vertex3d::operator-=(const Vertex3d &v) { + x -= v.x; + y -= v.y; + z -= v.z; + + return *this; +} diff --git a/Vertex3d.h b/Vertex3d.h new file mode 100644 index 0000000..faad420 --- /dev/null +++ b/Vertex3d.h @@ -0,0 +1,33 @@ +#ifndef VERTEX3D_H_ +#define VERTEX3D_H_ + +class Vertex3d { + private: + float x, y, z; + + public: + Vertex3d() {x = y = z = 0.0;} + Vertex3d(float x, float y, float z) {this->x = x; this->y = y; this->z = z;} + + float getX() const {return x;} + void setX(float x) {this->x = x;} + + float getY() const {return y;} + void setY(float y) {this->y = y;} + + float getZ() const {return z;} + void setZ(float z) {this->z = z;} + + void setLocation(float x, float y, float z) {this->x = x; this->y = y; this->z = z;} + + float distanceSq(const Vertex3d &v) const; + float distance(const Vertex3d &v) const; + + Vertex3d operator+(const Vertex3d &v) const; + Vertex3d operator-(const Vertex3d &v) const; + + Vertex3d& operator+=(const Vertex3d &v); + Vertex3d& operator-=(const Vertex3d &v); +}; + +#endif /*VERTEX3D_H_*/ |