diff options
author | neoraider <devnull@localhost> | 2008-05-03 02:05:05 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2008-05-03 02:05:05 +0200 |
commit | eb096e97d63c3bdbb2913dc0bb8abacef5ee3bf1 (patch) | |
tree | 8ffa42f6f90d9377f417a033ce5b5f5a0746d5b8 /src | |
parent | 12ebbe18e1c54c854286e38a4cf9e15433cd1bb2 (diff) | |
download | zoomedit-eb096e97d63c3bdbb2913dc0bb8abacef5ee3bf1.tar zoomedit-eb096e97d63c3bdbb2913dc0bb8abacef5ee3bf1.zip |
zoomedit:
* Implemented MapView
Diffstat (limited to 'src')
-rw-r--r-- | src/Gui/RenderArea.cpp | 8 | ||||
-rw-r--r-- | src/Gui/RenderArea.h | 1 | ||||
-rw-r--r-- | src/Gui/Window.cpp | 12 | ||||
-rw-r--r-- | src/Gui/Window.h | 5 | ||||
-rw-r--r-- | src/Instance.cpp | 10 | ||||
-rw-r--r-- | src/Instance.h | 2 | ||||
-rw-r--r-- | src/View/Makefile.am | 2 | ||||
-rw-r--r-- | src/View/Makefile.in | 5 | ||||
-rw-r--r-- | src/View/MapView.cpp | 118 | ||||
-rw-r--r-- | src/View/MapView.h | 18 | ||||
-rw-r--r-- | src/View/TopView.cpp | 2 | ||||
-rw-r--r-- | src/View/TopView.h | 16 | ||||
-rw-r--r-- | src/View/View.h | 1 |
13 files changed, 186 insertions, 14 deletions
diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp index 0cec471..2611102 100644 --- a/src/Gui/RenderArea.cpp +++ b/src/Gui/RenderArea.cpp @@ -44,6 +44,7 @@ RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade: signal_configure_event().connect(sigc::mem_fun(this, &RenderArea::onConfigureEvent)); signal_expose_event().connect(sigc::mem_fun(this, &RenderArea::onExposeEvent)); signal_scroll_event().connect(sigc::mem_fun(this, &RenderArea::onScrollEvent)); + signal_button_press_event().connect(sigc::mem_fun(this, &RenderArea::onButtonPressEvent)); signal_enter_notify_event().connect(sigc::mem_fun(this, &RenderArea::onEnterNotifyEvent)); signal_leave_notify_event().connect(sigc::mem_fun(this, &RenderArea::onLeaveNotifyEvent)); signal_motion_notify_event().connect(sigc::mem_fun(this, &RenderArea::onMotionNotifyEvent)); @@ -118,6 +119,13 @@ bool RenderArea::onScrollEvent(GdkEventScroll *event) { return false; } +bool RenderArea::onButtonPressEvent(GdkEventButton *event) { + if(view && event->button == 1) + view->click(this, event->x, event->y); + + return true; +} + bool RenderArea::onEnterNotifyEvent(GdkEventCrossing *event) { inWindow = true; xHover = event->x; diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h index 08cb841..6aa66df 100644 --- a/src/Gui/RenderArea.h +++ b/src/Gui/RenderArea.h @@ -55,6 +55,7 @@ class RenderArea : public Gtk::DrawingArea { bool onConfigureEvent(GdkEventConfigure*); bool onExposeEvent(GdkEventExpose*); bool onScrollEvent(GdkEventScroll *event); + bool onButtonPressEvent(GdkEventButton *event); bool onEnterNotifyEvent(GdkEventCrossing *event); bool onLeaveNotifyEvent(GdkEventCrossing*); bool onMotionNotifyEvent(GdkEventMotion *event); diff --git a/src/Gui/Window.cpp b/src/Gui/Window.cpp index f1af3cd..df20876 100644 --- a/src/Gui/Window.cpp +++ b/src/Gui/Window.cpp @@ -28,11 +28,23 @@ Window::Window(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &x xml->connect_clicked("MenuItemQuit", sigc::mem_fun(this, &Window::hide)); xml->get_widget_derived("RenderArea", renderArea); + xml->get_widget_derived("MapArea", mapArea); + + if(renderArea) + renderArea->signal_expose_event().connect_notify(sigc::mem_fun(this, &Window::updateMap)); } Window::~Window() { if(renderArea) delete renderArea; + + if(mapArea) + delete mapArea; +} + +void Window::updateMap(GdkEventExpose*) { + if(mapArea) + mapArea->queue_draw(); } } diff --git a/src/Gui/Window.h b/src/Gui/Window.h index ae22d42..9b4f4ef 100644 --- a/src/Gui/Window.h +++ b/src/Gui/Window.h @@ -30,13 +30,16 @@ class RenderArea; class Window : public Gtk::Window { private: - RenderArea *renderArea; + RenderArea *renderArea, *mapArea; + + void updateMap(GdkEventExpose*); public: Window(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml); virtual ~Window(); RenderArea* getRenderArea() const {return renderArea;} + RenderArea* getMapArea() const {return mapArea;} }; } diff --git a/src/Instance.cpp b/src/Instance.cpp index 0f53dab..29a912b 100644 --- a/src/Instance.cpp +++ b/src/Instance.cpp @@ -26,6 +26,7 @@ #include <Gui/RenderArea.h> #include <Data/Level.h> #include <View/TopView.h> +#include <View/MapView.h> namespace ZoomEdit { @@ -65,6 +66,9 @@ Instance::Instance(const Glib::ustring &file) : window(0), levelXml(0), level(0) view = new View::TopView(); window->getRenderArea()->setView(view); + mapView = new View::MapView(window->getRenderArea()); + window->getMapArea()->setView(mapView); + Gtk::ToolButton *button; xml->get_widget("ToolButtonZoomIn", button); button->signal_clicked().connect(sigc::bind(sigc::mem_fun(view, &View::TopView::zoom), window->getRenderArea(), 2, 0, 0)); @@ -84,6 +88,9 @@ Instance::~Instance() { if(window) delete window; + if(mapView) + delete mapView; + if(view) delete view; @@ -129,11 +136,13 @@ void Instance::createLevel() { level = new Data::Level(root); view->setLevel(level); + mapView->setLevel(level); } bool Instance::loadLevel(const Glib::ustring &file) { if(level) { view->setLevel(0); + mapView->setLevel(0); delete level; level = 0; } @@ -153,6 +162,7 @@ bool Instance::loadLevel(const Glib::ustring &file) { level = new Data::Level(doc->get_root_node()); view->setLevel(level); + mapView->setLevel(level); return true; } diff --git a/src/Instance.h b/src/Instance.h index a85999a..679ccbe 100644 --- a/src/Instance.h +++ b/src/Instance.h @@ -36,6 +36,7 @@ class Level; namespace View { class TopView; +class MapView; } class Instance { @@ -58,6 +59,7 @@ class Instance { Data::Level *level; View::TopView *view; + View::MapView *mapView; Instance(const Glib::ustring &file); 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 <Data/Level.h> +#include <Data/Room.h> +#include <Data/Triangle.h> +#include <Gui/RenderArea.h> +#include <GL/gl.h> +#include <cmath> +#include <list> namespace ZoomEdit { namespace View { +void MapView::click(Gui::RenderArea *renderArea, float x, float y) { + if(!mainArea) + return; + + TopView *mainView = dynamic_cast<TopView*>(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<Data::Room*> &rooms = level->getRooms(); + + for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) + TopView::renderRoom(*room); + + if(mainArea) { + TopView *mainView = dynamic_cast<TopView*>(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<Data::Room*> &rooms = level->getRooms(); + + for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) { + const std::list<Data::Triangle*> &triangles = (*room)->getFloorTriangles(); + + for(std::list<Data::Triangle*>::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) {} }; } |