zoomedit:

* Moved much stuff from RenderArea to TopView to make MapView possible
* Created MapView class
This commit is contained in:
neoraider 2008-04-20 00:08:05 +00:00
parent c771232b74
commit 12ebbe18e1
9 changed files with 200 additions and 97 deletions

30
src/View/MapView.cpp Normal file
View file

@ -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) {
}
}
}

49
src/View/MapView.h Normal file
View file

@ -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_*/

View file

@ -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();
}
}

View file

@ -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);
};

View file

@ -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) {}
};
}