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.cpp50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp
index 29fc242..9ce6039 100644
--- a/src/View/TopView.cpp
+++ b/src/View/TopView.cpp
@@ -58,12 +58,12 @@ bool TopView::Edge::operator<(const Edge &e) const {
return false;
}
-void TopView::drawGrid(Gui::RenderArea *renderArea) {
+void TopView::drawGrid() {
float depth = 1.25f + 0.04f*zoomLevel;
float depth2 = std::floor(depth);
float step = std::pow(0.1f, depth2);
- float width = renderArea->get_width()/scale;
- float height = renderArea->get_height()/scale;
+ float width = viewWidth/scale;
+ float height = viewHeight/scale;
float x1 = xCenter - width/2;
float x2 = xCenter + width/2;
@@ -140,7 +140,34 @@ void TopView::renderRoom(Data::Room *room) {
glEnd();
}
-void TopView::zoom(Gui::RenderArea *renderArea, int zoom, float x, float y) {
+void TopView::init() {
+ glClearColor(0, 0, 0, 0);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POINT_SMOOTH);
+}
+
+void TopView::resize(float width, float height) {
+ if(width == viewWidth && height == viewHeight)
+ return;
+
+ viewWidth = width; viewHeight = height;
+
+ glViewport(0, 0, width, height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ if(width != 0 && height != 0)
+ glScalef(2.0f/width, -2.0f/height, 1);
+
+ signalUpdate().emit();
+}
+
+void TopView::zoom(int zoom, float x, float y) {
const float oldScale = scale;
zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100);
@@ -149,29 +176,29 @@ void TopView::zoom(Gui::RenderArea *renderArea, int zoom, float x, float y) {
xCenter += x*(1/oldScale - 1/scale);
yCenter += y*(1/oldScale - 1/scale);
- renderArea->queue_draw();
+ signalUpdate().emit();
}
-void TopView::move(Gui::RenderArea *renderArea, float x, float y, unsigned int state) {
+void TopView::move(float x, float y, unsigned int state) {
if(!(state & GDK_BUTTON3_MASK))
return;
xCenter += x/scale;
yCenter += y/scale;
- renderArea->queue_draw();
+ signalUpdate().emit();
}
-void TopView::render(Gui::RenderArea *renderArea) {
+void TopView::render() {
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
+ glLoadIdentity();
glScalef(scale, scale, 1);
glTranslatef(-xCenter, -yCenter, 0);
- drawGrid(renderArea);
+ drawGrid();
if(!level)
return;
@@ -180,9 +207,6 @@ void TopView::render(Gui::RenderArea *renderArea) {
for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room)
renderRoom(*room);
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
}
}