summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-09-19 02:48:33 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-09-19 02:48:33 +0000
commite399f5cabc2a4ec7ef739cabfbc9b8284307ba32 (patch)
treed40b85940ea96b79616d0bd477d0033ab1b0f465 /src
parentFix for 643150 : Auto-palette swatches duplicated on copy and paste (diff)
downloadinkscape-e399f5cabc2a4ec7ef739cabfbc9b8284307ba32.tar.gz
inkscape-e399f5cabc2a4ec7ef739cabfbc9b8284307ba32.zip
Fix for 509891 : User defined linear gradient angle
(bzr r11678)
Diffstat (limited to 'src')
-rw-r--r--src/gradient-chemistry.cpp46
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp5
-rw-r--r--src/ui/dialog/inkscape-preferences.h1
3 files changed, 48 insertions, 4 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 6b1376fb5..34934f75b 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -20,6 +20,9 @@
#include <2geom/transforms.h>
#include <2geom/bezier-curve.h>
+#include <2geom/crossing.h>
+#include <2geom/line.h>
+#include <2geom/angle.h>
#include "style.h"
#include "document-private.h"
@@ -355,10 +358,45 @@ SPGradient *sp_gradient_reset_to_userspace(SPGradient *gr, SPItem *item)
g_free(c);
}
} else if (SP_IS_LINEARGRADIENT(gr)) {
- sp_repr_set_svg_double(repr, "x1", (center - Geom::Point(width/2, 0))[Geom::X]);
- sp_repr_set_svg_double(repr, "y1", (center - Geom::Point(width/2, 0))[Geom::Y]);
- sp_repr_set_svg_double(repr, "x2", (center + Geom::Point(width/2, 0))[Geom::X]);
- sp_repr_set_svg_double(repr, "y2", (center + Geom::Point(width/2, 0))[Geom::Y]);
+
+ // Assume horizontal gradient by default (as per SVG 1.1)
+ Geom::Point pStart = center - Geom::Point(width/2, 0);
+ Geom::Point pEnd = center + Geom::Point(width/2, 0);
+
+ // Get the preferred gradient angle from prefs
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ double angle = prefs->getDouble("/dialogs/gradienteditor/angle", 0.0);
+
+ if (angle != 0.0) {
+
+ Geom::Line grl(center, Geom::deg_to_rad(angle));
+ Geom::LineSegment bbl1(bbox->corner(0), bbox->corner(1));
+ Geom::LineSegment bbl2(bbox->corner(1), bbox->corner(2));
+ Geom::LineSegment bbl3(bbox->corner(2), bbox->corner(3));
+ Geom::LineSegment bbl4(bbox->corner(3), bbox->corner(0));
+
+ // Find where our gradient line intersects the bounding box.
+ if (intersection(bbl1, grl)) {
+ pStart = bbl1.pointAt((*intersection(bbl1, grl)).ta);
+ pEnd = bbl3.pointAt((*intersection(bbl3, grl)).ta);
+ if (intersection(bbl1, grl.ray(grl.angle()))) {
+ std::swap(pStart, pEnd);
+ }
+ } else if (intersection(bbl2, grl)) {
+ pStart = bbl2.pointAt((*intersection(bbl2, grl)).ta);
+ pEnd = bbl4.pointAt((*intersection(bbl4, grl)).ta);
+ if (intersection(bbl2, grl.ray(grl.angle()))) {
+ std::swap(pStart, pEnd);
+ }
+ }
+
+ }
+
+ sp_repr_set_svg_double(repr, "x1", pStart[Geom::X]);
+ sp_repr_set_svg_double(repr, "y1", pStart[Geom::Y]);
+ sp_repr_set_svg_double(repr, "x2", pEnd[Geom::X]);
+ sp_repr_set_svg_double(repr, "y2", pEnd[Geom::Y]);
+
} else {
// Mesh
// THIS IS BEING CALLED TWICE WHENEVER A NEW GRADIENT IS CREATED, WRITING HERE CAUSES PROBLEMS
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 7ee2aa444..9182aaad1 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -478,6 +478,11 @@ void InkscapePreferences::initPageTools()
_page_gradient.add_line( false, "", _misc_gradienteditor, "",
_("When on, the Gradient Edit button in the Fill & Stroke dialog will show the legacy Gradient Editor dialog, when off the Gradient Tool will be used"), true);
+ _misc_gradientangle.init("/dialogs/gradienteditor/angle", -359, 359, 1, 90, 0, false, false);
+ _page_gradient.add_line( false, _("Linear gradient _angle:"), _misc_gradientangle, "",
+ _("Default angle of new linear gradients in degrees (clockwise from horizontal"), false);
+
+
//Dropper
this->AddPage(_page_dropper, _("Dropper"), iter_tools, PREFS_PAGE_TOOLS_DROPPER);
this->AddSelcueCheckbox(_page_dropper, "/tools/dropper", true);
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index 948a3f87b..f4bfe5565 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -300,6 +300,7 @@ protected:
UI::Widget::PrefCheckButton _misc_default_metadata;
UI::Widget::PrefCheckButton _misc_forkvectors;
UI::Widget::PrefCheckButton _misc_gradienteditor;
+ UI::Widget::PrefSpinButton _misc_gradientangle;
UI::Widget::PrefCheckButton _misc_scripts;
UI::Widget::PrefCheckButton _misc_namedicon_delay;