diff options
Diffstat (limited to 'src/View')
-rw-r--r-- | src/View/MapView.cpp | 30 | ||||
-rw-r--r-- | src/View/MapView.h | 49 | ||||
-rw-r--r-- | src/View/TopView.cpp | 46 | ||||
-rw-r--r-- | src/View/TopView.h | 16 | ||||
-rw-r--r-- | src/View/View.h | 3 |
5 files changed, 134 insertions, 10 deletions
diff --git a/src/View/MapView.cpp b/src/View/MapView.cpp new file mode 100644 index 0000000..263383f --- /dev/null +++ b/src/View/MapView.cpp @@ -0,0 +1,30 @@ +/* + * MapView.cpp + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "MapView.h" + +namespace ZoomEdit { +namespace View { + +void MapView::render(Gui::RenderArea *renderArea) { + +} + +} +} diff --git a/src/View/MapView.h b/src/View/MapView.h new file mode 100644 index 0000000..525eb97 --- /dev/null +++ b/src/View/MapView.h @@ -0,0 +1,49 @@ +/* + * MapView.h + * + * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de> + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef ZOOMEDIT_VIEW_MAPVIEW_H_ +#define ZOOMEDIT_VIEW_MAPVIEW_H_ + +#include "View.h" + +namespace ZoomEdit { + +namespace Data { +class Level; +} + +namespace View { + +class MapView : public View { + private: + Data::Level *level; + + public: + MapView(Data::Level *level0 = 0) : level(level0) {} + + Data::Level* getLevel() {return level;} + void setLevel(Data::Level *level0) {level = level0;} + + virtual void render(Gui::RenderArea *renderArea); +}; + +} +} + +#endif /*ZOOMEDIT_VIEW_MAPVIEW_H_*/ 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(); } } diff --git a/src/View/TopView.h b/src/View/TopView.h index 914b1e5..ad2862c 100644 --- a/src/View/TopView.h +++ b/src/View/TopView.h @@ -45,15 +45,29 @@ class TopView : public View { Data::Level *level; + float xCenter, yCenter; + + int zoomLevel; + float scale; + + float getXCenter() const {return xCenter;} + float getYCenter() const {return yCenter;} + + float getScale() const {return scale;} + void drawGrid(Gui::RenderArea *renderArea); void renderRoom(Data::Room *room); public: - TopView(Data::Level *level0 = 0) : level(level0) {} + TopView(Data::Level *level0 = 0) : level(level0), xCenter(0), yCenter(0), zoomLevel(0), scale(100) {} Data::Level* getLevel() {return level;} void setLevel(Data::Level *level0) {level = level0;} + virtual void zoom(Gui::RenderArea *renderArea, int zoom, float x, float y); + + virtual void move(Gui::RenderArea *renderArea, float x, float y); + virtual void render(Gui::RenderArea *renderArea); }; diff --git a/src/View/View.h b/src/View/View.h index ad0a6cd..6a0eaf8 100644 --- a/src/View/View.h +++ b/src/View/View.h @@ -33,6 +33,9 @@ class View { virtual ~View() {} virtual void render(Gui::RenderArea *renderArea) = 0; + + virtual void zoom(Gui::RenderArea*, int, float, float) {} + virtual void move(Gui::RenderArea*, float, float) {} }; } |