summaryrefslogtreecommitdiffstats
path: root/src/View/TopView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/View/TopView.cpp')
-rw-r--r--src/View/TopView.cpp51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp
index 9ce6039..6ab00d9 100644
--- a/src/View/TopView.cpp
+++ b/src/View/TopView.cpp
@@ -22,6 +22,7 @@
#include <Data/Room.h>
#include <Data/Triangle.h>
#include <Gui/RenderArea.h>
+#include <Math/Triangle2D.h>
#include <GL/gl.h>
#include <cmath>
#include <set>
@@ -94,11 +95,14 @@ void TopView::drawGrid() {
glEnd();
}
-void TopView::renderRoom(Data::Room *room) {
+void TopView::renderRoom(Data::Room *room, bool selected) {
const std::list<Data::Triangle*> &floor = room->getFloorTriangles();
std::multiset<Edge> edges;
- glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
+ if(selected)
+ glColor4f(0.0f, 0.7f, 1.0f, 0.2f);
+ else
+ glColor4f(0.0f, 0.7f, 1.0f, 0.3f);
glBegin(GL_TRIANGLES);
@@ -127,8 +131,14 @@ void TopView::renderRoom(Data::Room *room) {
}
}
- glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
- glLineWidth(1.0f);
+ if(selected) {
+ glColor4f(1.0f, 1.0f, 1.0f, 0.9f);
+ glLineWidth(2.0f);
+ }
+ else {
+ glColor4f(0.0f, 0.7f, 1.0f, 0.7f);
+ glLineWidth(1.0f);
+ }
glBegin(GL_LINES);
@@ -206,8 +216,39 @@ void TopView::render() {
const std::list<Data::Room*> &rooms = level->getRooms();
for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room)
- renderRoom(*room);
+ renderRoom(*room, *room == selectedRoom);
}
+void TopView::click(float x, float y, unsigned int button) {
+ if(button != 1)
+ return;
+
+ Math::Vertex2D v(xCenter + x/scale, yCenter + y/scale);
+
+ selectedRoom = 0;
+
+ const std::list<Data::Room*>& rooms = level->getRooms();
+
+ for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) {
+ const std::list<Data::Triangle*>& triangles = (*room)->getFloorTriangles();
+
+ for(std::list<Data::Triangle*>::const_iterator t = triangles.begin(); t != triangles.end(); ++t) {
+ Math::Vertex2D v1((*t)->getVertex(0).getX(), (*t)->getVertex(0).getZ());
+ Math::Vertex2D v2((*t)->getVertex(1).getX(), (*t)->getVertex(1).getZ());
+ Math::Vertex2D v3((*t)->getVertex(2).getX(), (*t)->getVertex(2).getZ());
+
+ if(Math::Triangle2D(v1, v2, v3).contains(v)) {
+ selectedRoom = *room;
+ break;
+ }
+ }
+
+ if(selectedRoom)
+ break;
+ }
+
+ signalUpdate().emit();
+}
+
}
}