diff options
Diffstat (limited to 'src/View/TopView.cpp')
-rw-r--r-- | src/View/TopView.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp index 8ca047f..da26242 100644 --- a/src/View/TopView.cpp +++ b/src/View/TopView.cpp @@ -59,18 +59,16 @@ bool TopView::Edge::operator<(const Edge &e) const { } void TopView::drawGrid(Gui::RenderArea *renderArea) { - float depth = std::log10(renderArea->getScale())-0.75f; + float depth = 1.25f + 0.04f*zoomLevel; float depth2 = std::floor(depth); float step = std::pow(0.1f, depth2); - float x1, x2; - float y1, y2; - float width = renderArea->getViewWidth(); - float height = renderArea->getViewHeight(); + float width = renderArea->get_width()/scale; + float height = renderArea->get_height()/scale; - x1 = x2 = renderArea->getXCenter(); - y1 = y2 = renderArea->getYCenter(); - x1 -= width/2; x2 += width/2; - y1 -= height/2; y2 += height/2; + float x1 = xCenter - width/2; + float x2 = xCenter + width/2; + float y1 = yCenter - height/2; + float y2 = yCenter + height/2; glLineWidth(1.0f); @@ -142,7 +140,34 @@ void TopView::renderRoom(Data::Room *room) { glEnd(); } +void TopView::zoom(Gui::RenderArea *renderArea, int zoom, float x, float y) { + const float oldScale = scale; + + zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100); + scale = 100*std::pow(1.1f, zoomLevel); + + xCenter += x*(1/oldScale - 1/scale); + yCenter += y*(1/oldScale - 1/scale); + + renderArea->queue_draw(); +} + +void TopView::move(Gui::RenderArea *renderArea, float x, float y) { + xCenter += x/scale; + yCenter += y/scale; + + renderArea->queue_draw(); +} + void TopView::render(Gui::RenderArea *renderArea) { + glClear(GL_COLOR_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + glScalef(scale, scale, 1); + glTranslatef(-xCenter, -yCenter, 0); + drawGrid(renderArea); if(!level) @@ -152,6 +177,9 @@ 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(); } } |