diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-10-08 14:48:24 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-10-08 14:48:24 +0000 |
| commit | f5e77f7f48954ec3bed892fa6763b0ed099a044e (patch) | |
| tree | e65905c9e315da34868ec7f94a0878c527f7a34f /src | |
| parent | Update to trunk (diff) | |
| download | inkscape-f5e77f7f48954ec3bed892fa6763b0ed099a044e.tar.gz inkscape-f5e77f7f48954ec3bed892fa6763b0ed099a044e.zip | |
add rotate from current desktop center
(bzr r15142.1.3)
Diffstat (limited to 'src')
| -rw-r--r-- | src/sp-namedview.cpp | 40 | ||||
| -rw-r--r-- | src/viewbox.cpp | 24 | ||||
| -rw-r--r-- | src/viewbox.h | 2 |
3 files changed, 43 insertions, 23 deletions
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 69fc78b33..b4199e4c4 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -39,6 +39,9 @@ #include "conn-avoid-ref.h" // for defaultConnSpacing. #include <gtkmm/window.h> +#include "display/sodipodi-ctrl.h" +#include "ui/dialog/knot-properties.h" + using Inkscape::DocumentUndo; using Inkscape::Util::unit_table; @@ -416,7 +419,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { break; case SP_ATTR_INKSCAPE_DOCUMENT_ROTATION: this->document_rotation = value ? g_ascii_strtod(value, NULL) : 0; // zero means not set - if (value && document) { + if (document) { sp_namedview_set_document_rotation(document, this); } this->requestModified(SP_OBJECT_MODIFIED_FLAG); @@ -950,18 +953,26 @@ static void sp_namedview_lock_guides(SPNamedView *nv) sp_namedview_lock_single_guide(*it, nv->lockguides); } } - +void hp2(Geom::Point a) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + a = desktop->dt2doc(a); + guint32 color = 0xff0000ff; + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", color, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); + + SP_CTRL(canvasitem)->moveto(a); + sp_canvas_item_show(canvasitem); +} static void sp_namedview_set_document_rotation(SPDocument *doc, SPNamedView *nv) { SPDesktop * desktop = SP_ACTIVE_DESKTOP; - Geom::Rect area; - Geom::Point p = Geom::Point(); - if (desktop) { - area = desktop->get_display_area(); - p = area.midpoint(); - p *= desktop->doc2dt(); - p *= doc->getRoot()->rotation.inverse(); - } doc->getRoot()->set_rotation(nv->document_rotation); if (nv->document_rotation) { nv->showborder = FALSE; @@ -970,15 +981,6 @@ static void sp_namedview_set_document_rotation(SPDocument *doc, SPNamedView *nv) nv->showborder = prefs->getBool("/template/base/showborder", 1.0); } if (desktop) { - p *= doc->getRoot()->rotation; - //desktop->scroll_world_in_svg_coords (p[Geom::X], p[Geom::Y], true); - // *= doc->getRoot()->c2p * doc->getRoot()->rotation(); - //desktop->zoom_absolute (p[Geom::X], p[Geom::Y], desktop->current_zoom()); - std::cout << p << "pppppp\n"; -// Geom::Point min_pt = Geom::Point(p[Geom::X] - (area.width() / 2.0), p[Geom::Y] - (area.height() / 2.0)); -// Geom::Point max_pt = Geom::Point(p[Geom::X] + (area.width() / 2.0), p[Geom::Y] + (area.height() / 2.0)); -// Geom::Rect const new_area(min_pt, max_pt); -// desktop->set_display_area (new_area, 0, false); Inkscape::Selection * sel = desktop->getSelection(); sel->clear(); } diff --git a/src/viewbox.cpp b/src/viewbox.cpp index e40e477ef..ba316e2c2 100644 --- a/src/viewbox.cpp +++ b/src/viewbox.cpp @@ -23,6 +23,8 @@ #include "inkscape.h" #include "desktop.h" +#include "display/sodipodi-ctrl.h" +#include "ui/dialog/knot-properties.h" SPViewBox::SPViewBox() : viewBox_set(false) @@ -33,6 +35,8 @@ SPViewBox::SPViewBox() , c2p(Geom::identity()) , rotation(Geom::identity()) , angle(0) + , previous_angle(0) + , rotated(false) { } @@ -172,6 +176,8 @@ double SPViewBox::get_rotation() { } void SPViewBox::set_rotation(double angle_val) { + this->previous_angle = this->angle; + this->rotated = true; this->angle = angle_val; } @@ -255,6 +261,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { Geom::Point p = (r0 + r1) / 2; SPDesktop * desktop = SP_ACTIVE_DESKTOP; SPCanvasItem *vw_rot = NULL; + Geom::Point rot_center = Geom::Point(); if (desktop) { if (this->page_border_rotated) { desktop->remove_temporary_canvasitem(this->page_border_rotated); @@ -273,17 +280,25 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { Geom::PathVector const box = c->get_pathvector(); Geom::OptRect bbox = box.boundsFast(); if (bbox){ - r0 = (*bbox).min(); - r1 = (*bbox).max(); - p = (r0 + r1) / 2; + p = (*bbox).midpoint(); } + Geom::Rect view = desktop->get_display_area(); + rot_center = desktop->doc2dt(view.midpoint()); Geom::Affine rot = Geom::identity(); - rot *= Geom::Translate(p).inverse() * Geom::Rotate(Geom::rad_from_deg(-angle)) * Geom::Translate(p); + rot *= Geom::Translate(p).inverse() * Geom::Rotate(Geom::rad_from_deg(-angle)) * Geom::Translate(p); sp_canvas_item_affine_absolute(vw_rot, rot * vbt); this->page_border_rotated = desktop->add_temporary_canvasitem(vw_rot, 0); + Geom::Affine rotcenter = Geom::identity(); + rotcenter *= Geom::Translate(p * vbt).inverse() * Geom::Rotate(Geom::rad_from_deg(this->angle - this->previous_angle)) * Geom::Translate(p * vbt); + rot_center = rot_center * rotcenter; } rotation = Geom::Translate(p).inverse() * Geom::Rotate(Geom::rad_from_deg(angle)) * Geom::Translate(p); this->c2p = rotation * vbt * this->c2p; + rot_center = desktop->dt2doc(rot_center); + if (desktop && this->rotated) { + desktop->zoom_relative(rot_center[Geom::X], rot_center[Geom::Y], 1.0); + this->rotated = false; + } } else { SPDesktop * desktop = SP_ACTIVE_DESKTOP; if (desktop) { @@ -296,6 +311,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) { } } + SPItemCtx SPViewBox::get_rctx(const SPItemCtx* ictx, double scale_none) { /* Create copy of item context */ diff --git a/src/viewbox.h b/src/viewbox.h index df47c025b..70afa38a1 100644 --- a/src/viewbox.h +++ b/src/viewbox.h @@ -45,6 +45,8 @@ public: Geom::Affine c2p; Geom::Affine rotation; double angle; + double previous_angle; + bool rotated; double get_rotation(); void set_rotation(double angle_val); Inkscape::Display::TemporaryItem *page_border_rotated; |
