summaryrefslogtreecommitdiffstats
path: root/src/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/View')
-rw-r--r--src/View/MapView.cpp8
-rw-r--r--src/View/MapView.h2
-rw-r--r--src/View/TopView.cpp51
-rw-r--r--src/View/TopView.h10
-rw-r--r--src/View/View.h2
5 files changed, 60 insertions, 13 deletions
diff --git a/src/View/MapView.cpp b/src/View/MapView.cpp
index 1d074bc..7aa5482 100644
--- a/src/View/MapView.cpp
+++ b/src/View/MapView.cpp
@@ -85,12 +85,12 @@ void MapView::move(float x, float y, unsigned int state) {
mainView->setYCenter(mainView->getYCenter() - y/scale);
}
-void MapView::click(float x, float y) {
- if(!mainView)
+void MapView::click(float x, float y, unsigned int button) {
+ if(!mainView || button != 1)
return;
- mainView->setXCenter(xCenter + (x - viewWidth/2)/scale);
- mainView->setYCenter(yCenter + (y - viewHeight/2)/scale);
+ mainView->setXCenter(xCenter + x/scale);
+ mainView->setYCenter(yCenter + y/scale);
}
void MapView::render() {
diff --git a/src/View/MapView.h b/src/View/MapView.h
index e34cae5..b5e9572 100644
--- a/src/View/MapView.h
+++ b/src/View/MapView.h
@@ -61,7 +61,7 @@ class MapView : public View {
virtual void zoom(int zoom, float, float);
virtual void move(float x, float y, unsigned int state);
- virtual void click(float x, float y);
+ virtual void click(float x, float y, unsigned int button);
};
}
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();
+}
+
}
}
diff --git a/src/View/TopView.h b/src/View/TopView.h
index abbb77b..17a324d 100644
--- a/src/View/TopView.h
+++ b/src/View/TopView.h
@@ -52,10 +52,13 @@ class TopView : public View {
int zoomLevel;
float scale;
+ Data::Room *selectedRoom;
+
void drawGrid();
public:
- TopView(Data::Level *level0 = 0) : level(level0), viewWidth(0), viewHeight(0), xCenter(0), yCenter(0), zoomLevel(0), scale(100) {}
+ TopView(Data::Level *level0 = 0)
+ : level(level0), viewWidth(0), viewHeight(0), xCenter(0), yCenter(0), zoomLevel(0), scale(100), selectedRoom(0) {}
float getWidth() const {return viewWidth;}
float getHeight() const {return viewHeight;}
@@ -67,6 +70,8 @@ class TopView : public View {
float getScale() const {return scale;}
+ Data::Room* getSelectedRoom() {return selectedRoom;}
+
Data::Level* getLevel() {return level;}
void setLevel(Data::Level *level0) {level = level0; signalUpdate().emit();}
@@ -77,8 +82,9 @@ class TopView : public View {
virtual void zoom(int zoom, float x, float y);
virtual void move(float x, float y, unsigned int state);
+ virtual void click(float x, float y, unsigned int button);
- static void renderRoom(Data::Room *room);
+ static void renderRoom(Data::Room *room, bool selected = false);
};
}
diff --git a/src/View/View.h b/src/View/View.h
index 56e2542..9cfeee8 100644
--- a/src/View/View.h
+++ b/src/View/View.h
@@ -39,7 +39,7 @@ class View {
virtual void zoom(int, float, float) {}
virtual void move(float, float, unsigned int) {}
- virtual void click(float, float) {}
+ virtual void click(float, float, unsigned int) {}
sigc::signal<void> signalUpdate() const {return update;}
};