diff options
author | neoraider <devnull@localhost> | 2008-04-17 10:53:05 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2008-04-17 10:53:05 +0200 |
commit | c771232b7433c076290c2ac6c8c53090a1ad3592 (patch) | |
tree | 44ba6ccc2a1657b295d8dfe4f9572a106c9ac2c7 /src | |
parent | 1464f336773cf9758fc0427ff5fbefbcd58d2eb9 (diff) | |
download | zoomedit-c771232b7433c076290c2ac6c8c53090a1ad3592.tar zoomedit-c771232b7433c076290c2ac6c8c53090a1ad3592.zip |
zoomedit:
* Can grab level view now to change view position.
Diffstat (limited to 'src')
-rw-r--r-- | src/Gui/RenderArea.cpp | 36 | ||||
-rw-r--r-- | src/Gui/RenderArea.h | 6 | ||||
-rw-r--r-- | src/View/TopView.cpp | 42 | ||||
-rw-r--r-- | src/View/TopView.h | 2 | ||||
-rw-r--r-- | src/View/View.h | 1 |
5 files changed, 41 insertions, 46 deletions
diff --git a/src/Gui/RenderArea.cpp b/src/Gui/RenderArea.cpp index f27e009..1904aa8 100644 --- a/src/Gui/RenderArea.cpp +++ b/src/Gui/RenderArea.cpp @@ -32,7 +32,8 @@ namespace Gui { GdkGLConfig *RenderArea::glconfig = 0; RenderArea::RenderArea(BaseObjectType *cobject, const Glib::RefPtr<Gnome::Glade::Xml> &xml) -: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), viewWidth(0), viewHeight(0), zoomLevel(0), scale(100) { +: Gtk::DrawingArea(cobject), view(0), xCenter(0), yCenter(0), viewWidth(0), viewHeight(0), zoomLevel(0), +scale(100), inWindow(false) { if(!glconfig) { glconfig = gdk_gl_config_new_by_mode((GdkGLConfigMode)(GDK_GL_MODE_RGB | GDK_GL_MODE_DOUBLE)); if(!glconfig) glconfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB); // Hmm, can't find double buffered config @@ -46,6 +47,9 @@ 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_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)); Gtk::ToolButton *button; xml->get_widget("ToolButtonZoomIn", button); @@ -134,6 +138,36 @@ bool RenderArea::onScrollEvent(GdkEventScroll *event) { } } +bool RenderArea::onEnterNotifyEvent(GdkEventCrossing *event) { + inWindow = true; + xHover = event->x/scale - getViewWidth()/2 + xCenter; + yHover = event->y/scale - getViewHeight()/2 + yCenter; + + return true; +} + +bool RenderArea::onLeaveNotifyEvent(GdkEventCrossing*) { + inWindow = false; + + return true; +} + +bool RenderArea::onMotionNotifyEvent(GdkEventMotion *event) { + inWindow = true; + + if(event->state & GDK_BUTTON3_MASK) { + xCenter = xHover - event->x/scale + getViewWidth()/2; + yCenter = yHover - event->y/scale + getViewHeight()/2; + queue_draw(); + } + else { + xHover = event->x/scale - getViewWidth()/2 + xCenter; + yHover = event->y/scale - getViewHeight()/2 + yCenter; + } + + return true; +} + void RenderArea::zoom(int zoom, float x, float y) { zoomLevel = std::max(std::min(zoomLevel + zoom, 50), -100); scale = 100*std::pow(1.1f, zoomLevel); diff --git a/src/Gui/RenderArea.h b/src/Gui/RenderArea.h index a757467..c8b6d6e 100644 --- a/src/Gui/RenderArea.h +++ b/src/Gui/RenderArea.h @@ -67,10 +67,16 @@ class RenderArea : public Gtk::DrawingArea { int zoomLevel; float scale; + bool inWindow; + float xHover, yHover; + void onRealize(); bool onConfigureEvent(GdkEventConfigure*); bool onExposeEvent(GdkEventExpose*); bool onScrollEvent(GdkEventScroll *event); + bool onEnterNotifyEvent(GdkEventCrossing *event); + bool onLeaveNotifyEvent(GdkEventCrossing*); + bool onMotionNotifyEvent(GdkEventMotion *event); void zoom(int zoom, float x = 0.5f, float y = 0.5f); diff --git a/src/View/TopView.cpp b/src/View/TopView.cpp index 80f3f8e..8ca047f 100644 --- a/src/View/TopView.cpp +++ b/src/View/TopView.cpp @@ -154,47 +154,5 @@ void TopView::render(Gui::RenderArea *renderArea) { renderRoom(*room); } -void TopView::getBounds(float *minX, float *maxX, float *minY, float *maxY) { - if(!level) - return; - - if(minX) - *minX = 0; - if(maxX) - *maxX = 0; - if(minY) - *minY = 0; - if(maxY) - *maxY = 0; - - 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())); - } - } - - if(minX) - *minX -= 2.5f; - if(maxX) - *maxX += 2.5f; - if(minY) - *minY -= 2.5f; - if(maxY) - *maxY += 2.5f; -} - } } diff --git a/src/View/TopView.h b/src/View/TopView.h index 82f5875..914b1e5 100644 --- a/src/View/TopView.h +++ b/src/View/TopView.h @@ -55,8 +55,6 @@ class TopView : public View { void setLevel(Data::Level *level0) {level = level0;} virtual void render(Gui::RenderArea *renderArea); - - virtual void getBounds(float *minX, float *maxX, float *minY, float *maxY); }; } diff --git a/src/View/View.h b/src/View/View.h index cd4d5f5..ad0a6cd 100644 --- a/src/View/View.h +++ b/src/View/View.h @@ -33,7 +33,6 @@ class View { virtual ~View() {} virtual void render(Gui::RenderArea *renderArea) = 0; - virtual void getBounds(float *minX, float *maxX, float *minY, float *maxY) = 0; }; } |