From eb096e97d63c3bdbb2913dc0bb8abacef5ee3bf1 Mon Sep 17 00:00:00 2001 From: neoraider Date: Sat, 3 May 2008 00:05:05 +0000 Subject: zoomedit: * Implemented MapView --- src/View/Makefile.am | 2 +- src/View/Makefile.in | 5 ++- src/View/MapView.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/View/MapView.h | 18 +++++++- src/View/TopView.cpp | 2 +- src/View/TopView.h | 16 ++++--- src/View/View.h | 1 + 7 files changed, 149 insertions(+), 13 deletions(-) (limited to 'src/View') diff --git a/src/View/Makefile.am b/src/View/Makefile.am index 4ee107d..40f956e 100644 --- a/src/View/Makefile.am +++ b/src/View/Makefile.am @@ -1,3 +1,3 @@ noinst_LTLIBRARIES = libview.la -libview_la_SOURCES = TopView.cpp +libview_la_SOURCES = TopView.cpp MapView.cpp diff --git a/src/View/Makefile.in b/src/View/Makefile.in index 6f9314c..bb598f4 100644 --- a/src/View/Makefile.in +++ b/src/View/Makefile.in @@ -43,7 +43,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h CONFIG_CLEAN_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libview_la_LIBADD = -am_libview_la_OBJECTS = TopView.lo +am_libview_la_OBJECTS = TopView.lo MapView.lo libview_la_OBJECTS = $(am_libview_la_OBJECTS) DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -179,7 +179,7 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ noinst_LTLIBRARIES = libview.la -libview_la_SOURCES = TopView.cpp +libview_la_SOURCES = TopView.cpp MapView.cpp all: all-am .SUFFIXES: @@ -231,6 +231,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MapView.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TopView.Plo@am__quote@ .cpp.o: diff --git a/src/View/MapView.cpp b/src/View/MapView.cpp index 263383f..69c9d2f 100644 --- a/src/View/MapView.cpp +++ b/src/View/MapView.cpp @@ -18,13 +18,131 @@ */ #include "MapView.h" +#include "TopView.h" +#include +#include +#include +#include +#include +#include +#include namespace ZoomEdit { namespace View { +void MapView::click(Gui::RenderArea *renderArea, float x, float y) { + if(!mainArea) + return; + + TopView *mainView = dynamic_cast(mainArea->getView()); + if(!mainView) + return; + + mainView->setXCenter(xCenter + (x - renderArea->get_width()/2)/scale); + mainView->setYCenter(yCenter + (y - renderArea->get_height()/2)/scale); + + mainArea->queue_draw(); +} + void MapView::render(Gui::RenderArea *renderArea) { + glClear(GL_COLOR_BUFFER_BIT); + + if(!level) + return; + + float minX, maxX, minY, maxY; + getBounds(&minX, &maxX, &minY, &maxY); + + xCenter = (minX+maxX)/2; yCenter = (minY+maxY)/2; + float width = maxX-minX, height=maxY-minY; + + if(width == 0 || height == 0) + return; + + scale = std::min(renderArea->get_width()/width, renderArea->get_height()/height)*0.75f; + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glScalef(scale, scale, 1); + glTranslatef(-xCenter, -yCenter, 0); + + const std::list &rooms = level->getRooms(); + + for(std::list::const_iterator room = rooms.begin(); room != rooms.end(); ++room) + TopView::renderRoom(*room); + + if(mainArea) { + TopView *mainView = dynamic_cast(mainArea->getView()); + + if(mainView) { + float mainXCenter = mainView->getXCenter(), mainYCenter = mainView->getYCenter(); + float mainScale = mainView->getScale(); + + float mainWidth = mainArea->get_width()/mainScale, mainHeight = mainArea->get_height()/mainScale; + + glColor4f(0.7f, 0.7f, 0.7f, 0.3f); + + glBegin(GL_POLYGON); + + glVertex2f(mainXCenter-mainWidth/2, mainYCenter-mainHeight/2); + glVertex2f(mainXCenter+mainWidth/2, mainYCenter-mainHeight/2); + glVertex2f(mainXCenter+mainWidth/2, mainYCenter+mainHeight/2); + glVertex2f(mainXCenter-mainWidth/2, mainYCenter+mainHeight/2); + + glEnd(); + + glColor4f(0.7f, 0.7f, 0.7f, 0.7f); + glLineWidth(1.0f); + + glBegin(GL_LINE_LOOP); + + glVertex2f(mainXCenter-mainWidth/2, mainYCenter-mainHeight/2); + glVertex2f(mainXCenter+mainWidth/2, mainYCenter-mainHeight/2); + glVertex2f(mainXCenter+mainWidth/2, mainYCenter+mainHeight/2); + glVertex2f(mainXCenter-mainWidth/2, mainYCenter+mainHeight/2); + + glEnd(); + } + } + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void MapView::getBounds(float *minX, float *maxX, float *minY, float *maxY) { + if(minX) + *minX = 0; + if(maxX) + *maxX = 0; + if(minY) + *minY = 0; + if(maxY) + *maxY = 0; + + if(!level) + return; + + const std::list &rooms = level->getRooms(); + + for(std::list::const_iterator room = rooms.begin(); room != rooms.end(); ++room) { + const std::list &triangles = (*room)->getFloorTriangles(); + + for(std::list::const_iterator t = triangles.begin(); t != triangles.end(); ++t) { + const Data::Vertex &v1 = (*t)->getVertex(0), &v2 = (*t)->getVertex(1), &v3 = (*t)->getVertex(2); + + if(minX) + *minX = std::min(std::min(*minX, v1.getX()), std::min(v2.getX(), v3.getX())); + if(maxX) + *maxX = std::max(std::max(*maxX, v1.getX()), std::max(v2.getX(), v3.getX())); + if(minY) + *minY = std::min(std::min(*minY, v1.getZ()), std::min(v2.getZ(), v3.getZ())); + if(maxY) + *maxY = std::max(std::max(*maxY, v1.getZ()), std::max(v2.getZ(), v3.getZ())); + } + } } + } } diff --git a/src/View/MapView.h b/src/View/MapView.h index 525eb97..b60304b 100644 --- a/src/View/MapView.h +++ b/src/View/MapView.h @@ -30,16 +30,30 @@ class Level; namespace View { +class TopView; + class MapView : public View { private: Data::Level *level; + Gui::RenderArea *mainArea; + + float scale, xCenter, yCenter; + + void getBounds(float *minX, float *maxX, float *minY, float *maxY); + public: - MapView(Data::Level *level0 = 0) : level(level0) {} + MapView(Gui::RenderArea *mainArea0 = 0, Data::Level *level0 = 0) + : level(level0), mainArea(mainArea0), scale(1), xCenter(0), yCenter(0) {} Data::Level* getLevel() {return level;} void setLevel(Data::Level *level0) {level = level0;} - + + Gui::RenderArea* getMainArea() {return mainArea;} + void setMainArea(Gui::RenderArea *mainArea0) {mainArea = mainArea0;} + + virtual void click(Gui::RenderArea *renderArea, float x, float y); + virtual void render(Gui::RenderArea *renderArea); }; diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp index da26242..e0004fb 100644 --- a/src/View/TopView.cpp +++ b/src/View/TopView.cpp @@ -74,7 +74,7 @@ void TopView::drawGrid(Gui::RenderArea *renderArea) { glBegin(GL_LINES); - for(int i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; i++) { + for(int i = 0; 0.4f*(depth-depth2+i-1) < 0.5f; ++i) { float f = std::min(0.4f*(depth-depth2+i), 0.5f); glColor3f(f, f, f); diff --git a/src/View/TopView.h b/src/View/TopView.h index ad2862c..b6221f9 100644 --- a/src/View/TopView.h +++ b/src/View/TopView.h @@ -50,25 +50,27 @@ class TopView : public View { 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), xCenter(0), yCenter(0), zoomLevel(0), scale(100) {} + float getXCenter() const {return xCenter;} + void setXCenter(float xCenter0) {xCenter = xCenter0;} + float getYCenter() const {return yCenter;} + void setYCenter(float yCenter0) {yCenter = yCenter0;} + + float getScale() const {return scale;} + 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); + + static void renderRoom(Data::Room *room); }; } diff --git a/src/View/View.h b/src/View/View.h index 6a0eaf8..f6a8606 100644 --- a/src/View/View.h +++ b/src/View/View.h @@ -36,6 +36,7 @@ class View { virtual void zoom(Gui::RenderArea*, int, float, float) {} virtual void move(Gui::RenderArea*, float, float) {} + virtual void click(Gui::RenderArea*, float, float) {} }; } -- cgit v1.2.3