summaryrefslogtreecommitdiffstats
path: root/src/viewbox.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-10-10 12:08:35 +0000
committerjabiertxof <info@marker.es>2016-10-10 12:08:35 +0000
commitc7f5c676fa15f59f5f78c934263539981a26bbd2 (patch)
tree12eb2965e90018d418ed4b31a9a84c278dcefb98 /src/viewbox.cpp
parentAdded widget to to rotate (diff)
downloadinkscape-c7f5c676fa15f59f5f78c934263539981a26bbd2.tar.gz
inkscape-c7f5c676fa15f59f5f78c934263539981a26bbd2.zip
Fix some canvas problems and refactorization
(bzr r15142.1.8)
Diffstat (limited to 'src/viewbox.cpp')
-rw-r--r--src/viewbox.cpp63
1 files changed, 15 insertions, 48 deletions
diff --git a/src/viewbox.cpp b/src/viewbox.cpp
index d4e64a4da..15b5b19c4 100644
--- a/src/viewbox.cpp
+++ b/src/viewbox.cpp
@@ -17,10 +17,6 @@
#include "viewbox.h"
#include "enums.h"
#include "sp-item.h"
-#include "sp-root.h"
-#include "display/sp-canvas-group.h"
-#include "display/canvas-bpath.h"
-#include "display/curve.h"
#include "inkscape.h"
#include "desktop.h"
@@ -31,6 +27,7 @@ SPViewBox::SPViewBox()
, aspect_align(SP_ASPECT_XMID_YMID) // Default per spec
, aspect_clip(SP_ASPECT_MEET)
, c2p(Geom::identity())
+ , vbt(Geom::identity())
, rotation(Geom::identity())
, angle(0)
, previous_angle(0)
@@ -243,7 +240,7 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) {
}
}
/* Viewbox transform from scale and position */
- Geom::Affine vbt = Geom::identity();
+ vbt = Geom::identity();
vbt[0] = scale_x;
vbt[1] = 0.0;
vbt[2] = 0.0;
@@ -251,57 +248,27 @@ void SPViewBox::apply_viewbox(const Geom::Rect& in, double scale_none) {
vbt[4] = x - scale_x * this->viewBox.left();
vbt[5] = y - scale_y * this->viewBox.top();
/* Append viewbox and turn transformation */
- Geom::Point rot_center = Geom::Point();
- Geom::Point p = this->viewBox.midpoint();
- Geom::Affine rotcenter = Geom::identity();
+ Geom::Point page_center = this->viewBox.midpoint();
+ Geom::Affine center_rotation = Geom::identity();
SPDesktop * desktop = SP_ACTIVE_DESKTOP;
if (this->angle > 0.0 || this->angle < 0.0 ) { //!0
- SPCanvasItem *vw_rot = NULL;
if (desktop) {
- if (this->page_border_rotated) {
- desktop->remove_temporary_canvasitem(this->page_border_rotated);
- this->page_border_rotated = NULL;
- }
- SPCurve *c = new SPCurve();
- c->moveto(this->viewBox.min());
- c->lineto(Geom::Point(this->viewBox.max()[Geom::X],this->viewBox.min()[Geom::Y]));
- c->lineto(Geom::Point(this->viewBox.max()[Geom::X],this->viewBox.max()[Geom::Y]));
- c->lineto(Geom::Point(this->viewBox.min()[Geom::X],this->viewBox.max()[Geom::Y]));
- c->closepath();
- vw_rot = sp_canvas_bpath_new(desktop->getTempGroup(), c, true);
- sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(vw_rot), 0xFF00009A, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
- sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(vw_rot), 0, SP_WIND_RULE_NONZERO);
- this->page_border_rotated = desktop->add_temporary_canvasitem(vw_rot, 0);
- Geom::PathVector const box = c->get_pathvector();
- Geom::OptRect bbox = box.boundsFast();
- if (bbox){
- 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);
- sp_canvas_item_affine_absolute(vw_rot, rot * vbt);
- this->page_border_rotated = desktop->add_temporary_canvasitem(vw_rot, 0);
- rotcenter *= Geom::Translate(p * vbt).inverse() * Geom::Rotate(Geom::rad_from_deg(this->angle - this->previous_angle)) * Geom::Translate(p * vbt);
+ rotation = Geom::Translate(page_center).inverse() * Geom::Rotate(Geom::rad_from_deg(angle)) * Geom::Translate(page_center);
+ this->c2p = rotation * vbt * this->c2p;
+ } else {
+ this->c2p = vbt * this->c2p;
}
- rotation = Geom::Translate(p).inverse() * Geom::Rotate(Geom::rad_from_deg(angle)) * Geom::Translate(p);
- this->c2p = rotation * vbt * this->c2p;
} else {
- if (desktop) {
- Geom::Rect view = desktop->get_display_area();
- rot_center = desktop->doc2dt(view.midpoint());
- rotcenter *= Geom::Translate(p * vbt).inverse() * Geom::Rotate(Geom::rad_from_deg(this->angle - this->previous_angle)) * Geom::Translate(p * vbt);
- if (this->page_border_rotated) {
- desktop->remove_temporary_canvasitem(this->page_border_rotated);
- this->page_border_rotated = NULL;
- }
- }
this->c2p = vbt * this->c2p;
}
if (desktop && this->rotated) {
- rot_center = desktop->dt2doc(rot_center * rotcenter);
- desktop->zoom_relative(rot_center[Geom::X], rot_center[Geom::Y], 1.0);
+ Geom::Rect view = desktop->get_display_area();
+ Geom::Point view_center = desktop->doc2dt(view.midpoint());
+ center_rotation *= Geom::Translate(page_center * vbt).inverse();
+ center_rotation *= Geom::Rotate(Geom::rad_from_deg(this->angle - this->previous_angle));
+ center_rotation *= Geom::Translate(page_center * vbt);
+ view_center = desktop->dt2doc(view_center * center_rotation);
+ desktop->zoom_relative(view_center[Geom::X], view_center[Geom::Y], 1.0);
this->rotated = false;
}
}