diff options
Diffstat (limited to 'src/View/MapView.cpp')
-rw-r--r-- | src/View/MapView.cpp | 133 |
1 files changed, 74 insertions, 59 deletions
diff --git a/src/View/MapView.cpp b/src/View/MapView.cpp index 5727c86..1d074bc 100644 --- a/src/View/MapView.cpp +++ b/src/View/MapView.cpp @@ -30,22 +30,51 @@ namespace ZoomEdit { namespace View { -void MapView::zoom(Gui::RenderArea*, int zoom, float, float) { - if(!mainArea) - return; +void MapView::setMainView(TopView *mainView0) { + mainView = mainView0; - TopView *mainView = dynamic_cast<TopView*>(mainArea->getView()); - if(!mainView) + if(mainViewUpdate) + mainViewUpdate.disconnect(); + + if(mainView) + mainViewUpdate = mainView->signalUpdate().connect(signalUpdate()); +} + +void MapView::init() { + glClearColor(0, 0, 0, 0); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + + glEnable(GL_LINE_SMOOTH); + glEnable(GL_POINT_SMOOTH); +} + +void MapView::resize(float width, float height) { + if(width == viewWidth && height == viewHeight) return; - mainView->zoom(mainArea, zoom, 0, 0); + viewWidth = width; viewHeight = height; + + glViewport(0, 0, width, height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + if(width != 0 && height != 0) + glScalef(2.0f/width, -2.0f/height, 1); + + signalUpdate().emit(); } -void MapView::move(Gui::RenderArea*, float x, float y, unsigned int state) { - if(!mainArea) +void MapView::zoom(int zoom, float, float) { + if(!mainView) return; - TopView *mainView = dynamic_cast<TopView*>(mainArea->getView()); + mainView->zoom(zoom, 0, 0); +} + +void MapView::move(float x, float y, unsigned int state) { if(!mainView) return; @@ -54,28 +83,20 @@ void MapView::move(Gui::RenderArea*, float x, float y, unsigned int state) { mainView->setXCenter(mainView->getXCenter() - x/scale); mainView->setYCenter(mainView->getYCenter() - y/scale); - - mainArea->queue_draw(); } -void MapView::click(Gui::RenderArea *renderArea, float x, float y) { - if(!mainArea) - return; - - TopView *mainView = dynamic_cast<TopView*>(mainArea->getView()); +void MapView::click(float x, float y) { if(!mainView) return; - mainView->setXCenter(xCenter + (x - renderArea->get_width()/2)/scale); - mainView->setYCenter(yCenter + (y - renderArea->get_height()/2)/scale); - - mainArea->queue_draw(); + mainView->setXCenter(xCenter + (x - viewWidth/2)/scale); + mainView->setYCenter(yCenter + (y - viewHeight/2)/scale); } -void MapView::render(Gui::RenderArea *renderArea) { +void MapView::render() { glClear(GL_COLOR_BUFFER_BIT); - if(!level) + if(!mainView || !mainView->getLevel()) return; float minX, maxX, minY, maxY; @@ -87,7 +108,7 @@ void MapView::render(Gui::RenderArea *renderArea) { if(width == 0 || height == 0) return; - scale = std::min(renderArea->get_width()/width, renderArea->get_height()/height)*0.75f; + scale = std::min(viewWidth/width, viewHeight/height)*0.75f; glMatrixMode(GL_MODELVIEW); glPushMatrix(); @@ -95,44 +116,38 @@ void MapView::render(Gui::RenderArea *renderArea) { glScalef(scale, scale, 1); glTranslatef(-xCenter, -yCenter, 0); - const std::list<Data::Room*> &rooms = level->getRooms(); + const std::list<Data::Room*> &rooms = mainView->getLevel()->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(); - } - } + float mainXCenter = mainView->getXCenter(), mainYCenter = mainView->getYCenter(); + float mainScale = mainView->getScale(); + + float mainWidth = mainView->getWidth()/mainScale, mainHeight = mainView->getHeight()/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(); @@ -148,10 +163,10 @@ void MapView::getBounds(float *minX, float *maxX, float *minY, float *maxY) { if(maxY) *maxY = 0; - if(!level) + if(!mainView || !mainView->getLevel()) return; - const std::list<Data::Room*> &rooms = level->getRooms(); + const std::list<Data::Room*> &rooms = mainView->getLevel()->getRooms(); for(std::list<Data::Room*>::const_iterator room = rooms.begin(); room != rooms.end(); ++room) { const std::list<Data::Triangle*> &triangles = (*room)->getFloorTriangles(); |