summaryrefslogtreecommitdiffstats
path: root/src/Gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/Gui')
-rw-r--r--src/Gui/RenderArea.cpp36
-rw-r--r--src/Gui/RenderArea.h6
2 files changed, 41 insertions, 1 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);