diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-09-19 22:33:11 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-09-19 22:33:11 +0000 |
| commit | 4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch) | |
| tree | caeb924426bcc861badc6fa81318b67460b26d47 /src/zoom-context.cpp | |
| parent | Update to trunk (diff) | |
| parent | updates for cmake (diff) | |
| download | inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip | |
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/zoom-context.cpp')
| -rw-r--r-- | src/zoom-context.cpp | 151 |
1 files changed, 67 insertions, 84 deletions
diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp index 8b06c3e08..6efc122f7 100644 --- a/src/zoom-context.cpp +++ b/src/zoom-context.cpp @@ -25,96 +25,71 @@ #include "selection-chemistry.h" #include "zoom-context.h" +#include "tool-factory.h" -static void sp_zoom_context_setup(SPEventContext *ec); -static void sp_zoom_context_finish (SPEventContext *ec); +namespace { + SPEventContext* createZoomContext() { + return new SPZoomContext(); + } -static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent *event); -static gint sp_zoom_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event); - -static gint xp = 0, yp = 0; // where drag started -static gint tolerance = 0; -static bool within_tolerance = false; -static bool escaped; - -G_DEFINE_TYPE(SPZoomContext, sp_zoom_context, SP_TYPE_EVENT_CONTEXT); + bool zoomContextRegistered = ToolFactory::instance().registerObject("/tools/zoom", createZoomContext); +} -static void sp_zoom_context_class_init(SPZoomContextClass *klass) -{ - SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); +const std::string& SPZoomContext::getPrefsPath() { + return SPZoomContext::prefsPath; +} - event_context_class->setup = sp_zoom_context_setup; - event_context_class->finish = sp_zoom_context_finish; +const std::string SPZoomContext::prefsPath = "/tools/zoom"; - event_context_class->root_handler = sp_zoom_context_root_handler; - event_context_class->item_handler = sp_zoom_context_item_handler; +SPZoomContext::SPZoomContext() : SPEventContext() { + this->grabbed = 0; + this->cursor_shape = cursor_zoom_xpm; + this->hot_x = 6; + this->hot_y = 6; + this->escaped = false; } -static void sp_zoom_context_init (SPZoomContext *zoom_context) -{ - SPEventContext *event_context = SP_EVENT_CONTEXT(zoom_context); - - event_context->cursor_shape = cursor_zoom_xpm; - event_context->hot_x = 6; - event_context->hot_y = 6; +SPZoomContext::~SPZoomContext() { } -static void -sp_zoom_context_finish (SPEventContext *ec) -{ - SPZoomContext *zc = SP_ZOOM_CONTEXT(ec); - - ec->enableGrDrag(false); +void SPZoomContext::finish() { + this->enableGrDrag(false); - if (zc->grabbed) { - sp_canvas_item_ungrab(zc->grabbed, GDK_CURRENT_TIME); - zc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, GDK_CURRENT_TIME); + this->grabbed = NULL; } } -static void sp_zoom_context_setup(SPEventContext *ec) -{ +void SPZoomContext::setup() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/zoom/selcue")) { - ec->enableSelectionCue(); - } - if (prefs->getBool("/tools/zoom/gradientdrag")) { - ec->enableGrDrag(); - } - if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup) { - (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->setup(ec); + if (prefs->getBool("/tools/zoom/selcue")) { + this->enableSelectionCue(); } -} -static gint sp_zoom_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event) -{ - gint ret = FALSE; - - if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->item_handler (event_context, item, event); + if (prefs->getBool("/tools/zoom/gradientdrag")) { + this->enableGrDrag(); } - return ret; + SPEventContext::setup(); } -static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent *event) -{ - SPDesktop *desktop = event_context->desktop; +bool SPZoomContext::root_handler(GdkEvent* event) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - SPZoomContext *zc = SP_ZOOM_CONTEXT(event_context); tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); double const zoom_inc = prefs->getDoubleLimited("/options/zoomincrement/value", M_SQRT2, 1.01, 10); - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - if (event->button.button == 1 && !event_context->space_panning) { + + if (event->button.button == 1 && !this->space_panning) { // save drag origin xp = (gint) event->button.x; yp = (gint) event->button.y; @@ -124,26 +99,27 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent escaped = false; - ret = TRUE; + ret = true; } else if (event->button.button == 3) { double const zoom_rel( (event->button.state & GDK_SHIFT_MASK) ? zoom_inc : 1 / zoom_inc ); + desktop->zoom_relative_keep_point(button_dt, zoom_rel); - ret = TRUE; + ret = true; } sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - zc->grabbed = SP_CANVAS_ITEM(desktop->acetate); - + + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); break; } case GDK_MOTION_NOTIFY: - if (event->motion.state & GDK_BUTTON1_MASK && !event_context->space_panning) { - ret = TRUE; + if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { + ret = true; if ( within_tolerance && ( abs( (gint) event->motion.x - xp ) < tolerance ) @@ -166,23 +142,28 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent { Geom::Point const button_w(event->button.x, event->button.y); Geom::Point const button_dt(desktop->w2d(button_w)); - if ( event->button.button == 1 && !event_context->space_panning) { + + if ( event->button.button == 1 && !this->space_panning) { Geom::OptRect const b = Inkscape::Rubberband::get(desktop)->getRectangle(); + if (b && !within_tolerance) { desktop->set_display_area(*b, 10); } else if (!escaped) { double const zoom_rel( (event->button.state & GDK_SHIFT_MASK) ? 1 / zoom_inc : zoom_inc ); + desktop->zoom_relative_keep_point(button_dt, zoom_rel); } - ret = TRUE; - } + + ret = true; + } + Inkscape::Rubberband::get(desktop)->stop(); - if (zc->grabbed) { - sp_canvas_item_ungrab(zc->grabbed, event->button.time); - zc->grabbed = NULL; + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; } xp = yp = 0; @@ -195,28 +176,32 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent if (!Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::SelectionHelper::selectNone(desktop); } + Inkscape::Rubberband::get(desktop)->stop(); xp = yp = 0; escaped = true; - ret = TRUE; + ret = true; break; + case GDK_KEY_Up: case GDK_KEY_Down: case GDK_KEY_KP_Up: case GDK_KEY_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY(event)) - ret = TRUE; + ret = true; break; + case GDK_KEY_Shift_L: case GDK_KEY_Shift_R: - event_context->cursor_shape = cursor_zoom_out_xpm; - sp_event_context_update_cursor(event_context); + this->cursor_shape = cursor_zoom_out_xpm; + this->sp_event_context_update_cursor(); break; + case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = event_context->deleteSelectedDrag(MOD__CTRL_ONLY(event)); + ret = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); break; default: @@ -225,23 +210,21 @@ static gint sp_zoom_context_root_handler(SPEventContext *event_context, GdkEvent break; case GDK_KEY_RELEASE: switch (get_group0_keyval (&event->key)) { - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - event_context->cursor_shape = cursor_zoom_xpm; - sp_event_context_update_cursor(event_context); + case GDK_KEY_Shift_L: + case GDK_KEY_Shift_R: + this->cursor_shape = cursor_zoom_xpm; + this->sp_event_context_update_cursor(); break; - default: + default: break; - } + } break; default: break; } if (!ret) { - if ((SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler) { - ret = (SP_EVENT_CONTEXT_CLASS(sp_zoom_context_parent_class))->root_handler(event_context, event); - } + ret = SPEventContext::root_handler(event); } return ret; |
