summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Renderer.cpp14
-rw-r--r--Renderer.h2
-rw-r--r--Room.cpp6
-rw-r--r--Room.h10
-rw-r--r--ToolAddPolygon.cpp15
5 files changed, 34 insertions, 13 deletions
diff --git a/Renderer.cpp b/Renderer.cpp
index 40150df..7255a4a 100644
--- a/Renderer.cpp
+++ b/Renderer.cpp
@@ -51,8 +51,8 @@ void Renderer::fillPolygon(const Polygon &polygon) {
glEnd();
}
-void Renderer::drawPolygon(const Polygon &polygon, bool close) {
- glBegin(close ? GL_LINE_LOOP : GL_LINE_STRIP);
+void Renderer::drawPolygon(const Polygon &polygon) {
+ glBegin(GL_LINE_LOOP);
for(Polygon::const_iterator vertex = polygon.begin(); vertex != polygon.end(); vertex++)
glVertex2f(vertex->getX(), vertex->getY());
@@ -172,7 +172,15 @@ void Renderer::renderRoom(const Room &room, bool selected, bool hovered, float s
glLineWidth(1.0f);
}
- drawPolygon(room.getPolygon());
+ glBegin(GL_LINES);
+
+ for(size_t i = 0; i < room.getEdgeCount(); i++) {
+ const Edge *edge = room.getEdge(i);
+ glVertex2f(edge->getVertex1()->getX(), edge->getVertex1()->getY());
+ glVertex2f(edge->getVertex2()->getX(), edge->getVertex2()->getY());
+ }
+
+ glEnd();
}
void Renderer::renderPlayerStart(const PlayerStart &start, bool selected, bool hovered, float scale) {
diff --git a/Renderer.h b/Renderer.h
index d4e5ba0..80c268f 100644
--- a/Renderer.h
+++ b/Renderer.h
@@ -19,7 +19,7 @@ class Renderer {
protected:
void fillPolygon(const Polygon &polygon);
- void drawPolygon(const Polygon &polygon, bool close = true);
+ void drawPolygon(const Polygon &polygon);
void fillCircle(const Vertex &m, float r, int n = 64);
void drawCircle(const Vertex &m, float r, int n = 64);
void drawCircleDotted(const Vertex &m, float r, int n = 64, int d = 8, float rot = 0);
diff --git a/Room.cpp b/Room.cpp
index e364293..4923169 100644
--- a/Room.cpp
+++ b/Room.cpp
@@ -23,8 +23,10 @@ const Room& Room::operator=(const Room &room) {
std::vector<SharedPtr<LevelObject> > Room::getChildren() {
std::vector<SharedPtr<LevelObject> > children;
- for(size_t i = 0; i < vertices.size(); i++)
- children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this)));
+ for(size_t i = 0; i < vertices.size(); i++) {
+ if(vertices[i]->isDirect())
+ children.push_back(SharedPtr<LevelObject>(new LevelVertex(this, i, this)));
+ }
for(size_t i = 0; i < edges.size(); i++)
children.push_back(SharedPtr<LevelObject>(new LevelEdge(this, i, this)));
diff --git a/Room.h b/Room.h
index e7e7ffb..7dde7d1 100644
--- a/Room.h
+++ b/Room.h
@@ -22,6 +22,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual const Vertex& operator-=(const Vertex &v) {return **this;}
virtual void setLocation(float x, float y) {}
+
+ virtual bool isDirect() const = 0;
};
class RoomVertexDirect : public RoomVertex {
@@ -48,6 +50,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual void setLocation(float x, float y) {
vertex.setLocation(x, y);
}
+
+ virtual bool isDirect() const {return true;}
};
class RoomVertexIndirect : public RoomVertex {
@@ -60,6 +64,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
virtual const Vertex& operator*() const {
return *vertex;
}
+
+ virtual bool isDirect() const {return false;}
};
@@ -132,8 +138,8 @@ class Room : public LevelObject, private VertexProvider, private EdgeProvider {
}
void close() {
- if(!edges.empty())
- edges.push_back(Edge(edges.back().getVertex2(), edges.front().getVertex1()));
+ if(vertices.size() >= 2)
+ edges.push_back(Edge(LevelVertex(this, vertices.size()-1, this), LevelVertex(this, 0, this)));
}
Polygon getPolygon() const {
diff --git a/ToolAddPolygon.cpp b/ToolAddPolygon.cpp
index 8e68939..9730318 100644
--- a/ToolAddPolygon.cpp
+++ b/ToolAddPolygon.cpp
@@ -34,19 +34,24 @@ void ToolAddPolygon::render(const Level &level, const Rectangle &rect, float sca
glLineWidth(2.0f);
glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- drawPolygon(newRoom.getPolygon(), false);
+
+ glBegin(GL_LINES);
+
+ for(size_t i = 0; i < newRoom.getEdgeCount(); i++) {
+ const Edge *edge = newRoom.getEdge(i);
+ glVertex2f(edge->getVertex1()->getX(), edge->getVertex1()->getY());
+ glVertex2f(edge->getVertex2()->getX(), edge->getVertex2()->getY());
+ }
if(!newRoom.getPolygon().empty() && editManager->getHoveredVertex()) {
if(!editManager->vertexOk(*editManager->getHoveredVertex(), &newRoom))
glColor4f(1.0f, 0.3f, 0.3f, 0.7f);
- glBegin(GL_LINES);
-
glVertex2f(newRoom.getPolygon().back().getX(), newRoom.getPolygon().back().getY());
glVertex2f(editManager->getHoveredVertex()->getX(), editManager->getHoveredVertex()->getY());
-
- glEnd();
}
+
+ glEnd();
}
bool ToolAddPolygon::buttonPress(unsigned int button, const Vertex *v) {