summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-08-04 16:10:37 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-08-04 16:10:37 +0000
commitacd8f135f2a901c5f046e51ad7783e442c43997a (patch)
tree12418cabb430ca8041c12e7c3d014185c4b4541b /src
parentExporting. Fix for bug #1350897 (XAML export formats numbers in the top-level... (diff)
downloadinkscape-acd8f135f2a901c5f046e51ad7783e442c43997a.tar.gz
inkscape-acd8f135f2a901c5f046e51ad7783e442c43997a.zip
Allow editing of fill and stroke patterns simultaneously. Fixes #601336, #604025, #486192
Fixed bugs: - https://launchpad.net/bugs/601336 - https://launchpad.net/bugs/604025 - https://launchpad.net/bugs/486192 (bzr r13489)
Diffstat (limited to 'src')
-rw-r--r--src/knot-holder-entity.cpp18
-rw-r--r--src/knot-holder-entity.h10
-rw-r--r--src/knotholder.cpp32
-rw-r--r--src/object-edit.cpp4
-rw-r--r--src/sp-item.cpp8
-rw-r--r--src/sp-item.h9
6 files changed, 60 insertions, 21 deletions
diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp
index 6af5c6a56..b66156b09 100644
--- a/src/knot-holder-entity.cpp
+++ b/src/knot-holder-entity.cpp
@@ -158,7 +158,7 @@ static Geom::Point sp_pattern_extract_trans(SPPattern const *pat)
void
PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
{
- SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
// FIXME: this snapping should be done together with knowing whether control was pressed. If GDK_CONTROL_MASK, then constrained snapping should be used.
Geom::Point p_snapped = snap_knot_position(p, state);
@@ -173,7 +173,7 @@ PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &ori
if (state) {
Geom::Point const q = p_snapped - sp_pattern_extract_trans(pat);
- item->adjust_pattern(Geom::Affine(Geom::Translate(q)));
+ item->adjust_pattern(Geom::Translate(q), false, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE);
}
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -182,14 +182,14 @@ PatternKnotHolderEntityXY::knot_set(Geom::Point const &p, Geom::Point const &ori
Geom::Point
PatternKnotHolderEntityXY::knot_get() const
{
- SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
return sp_pattern_extract_trans(pat);
}
Geom::Point
PatternKnotHolderEntityAngle::knot_get() const
{
- SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
gdouble x = pattern_width(pat);
gdouble y = 0;
@@ -207,7 +207,7 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const &
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
int const snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
- SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
// get the angle from pattern 0,0 to the cursor pos
Geom::Point delta = p - sp_pattern_extract_trans(pat);
@@ -223,14 +223,14 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const &
Geom::Point const t = sp_pattern_extract_trans(pat);
rot[4] = t[Geom::X];
rot[5] = t[Geom::Y];
- item->adjust_pattern(rot, true);
+ item->adjust_pattern(rot, true, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE);
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
void
PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
- SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
// FIXME: this snapping should be done together with knowing whether control was pressed. If GDK_CONTROL_MASK, then constrained snapping should be used.
Geom::Point p_snapped = snap_knot_position(p, state);
@@ -257,7 +257,7 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const &
Geom::Point const t = sp_pattern_extract_trans(pat);
rot[4] = t[Geom::X];
rot[5] = t[Geom::Y];
- item->adjust_pattern(rot, true);
+ item->adjust_pattern(rot, true, _fill ? TRANSFORM_FILL : TRANSFORM_STROKE);
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
@@ -265,7 +265,7 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const &
Geom::Point
PatternKnotHolderEntityScale::knot_get() const
{
- SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
+ SPPattern *pat = _fill ? SP_PATTERN(item->style->getFillPaintServer()) : SP_PATTERN(item->style->getStrokePaintServer());
gdouble x = pattern_width(pat);
gdouble y = pattern_height(pat);
diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h
index a9268d396..dde60f515 100644
--- a/src/knot-holder-entity.h
+++ b/src/knot-holder-entity.h
@@ -101,20 +101,30 @@ protected:
class PatternKnotHolderEntityXY : public KnotHolderEntity {
public:
+ PatternKnotHolderEntityXY(bool fill) : KnotHolderEntity(), _fill(fill) {}
virtual Geom::Point knot_get() const;
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+private:
+ // true if the entity tracks fill, false for stroke
+ bool _fill;
};
class PatternKnotHolderEntityAngle : public KnotHolderEntity {
public:
+ PatternKnotHolderEntityAngle(bool fill) : KnotHolderEntity(), _fill(fill) {}
virtual Geom::Point knot_get() const;
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+private:
+ bool _fill;
};
class PatternKnotHolderEntityScale : public KnotHolderEntity {
public:
+ PatternKnotHolderEntityScale(bool fill) : KnotHolderEntity(), _fill(fill) {}
virtual Geom::Point knot_get() const;
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+private:
+ bool _fill;
};
#endif /* !SEEN_KNOT_HOLDER_ENTITY_H */
diff --git a/src/knotholder.cpp b/src/knotholder.cpp
index cf87423d4..f0e69716b 100644
--- a/src/knotholder.cpp
+++ b/src/knotholder.cpp
@@ -247,12 +247,32 @@ void KnotHolder::add(KnotHolderEntity *e)
void KnotHolder::add_pattern_knotholder()
{
- if ((item->style->fill.isPaintserver())
- && SP_IS_PATTERN(item->style->getFillPaintServer()))
- {
- PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY();
- PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle();
- PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale();
+ if ((item->style->fill.isPaintserver()) && SP_IS_PATTERN(item->style->getFillPaintServer())) {
+ PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(true);
+ PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(true);
+ PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(true);
+ entity_xy->create(desktop, item, this, Inkscape::CTRL_TYPE_POINT,
+ // TRANSLATORS: This refers to the pattern that's inside the object
+ _("<b>Move</b> the pattern fill inside the object"),
+ SP_KNOT_SHAPE_CROSS);
+
+ entity_scale->create(desktop, item, this, Inkscape::CTRL_TYPE_SIZER,
+ _("<b>Scale</b> the pattern fill; uniformly if with <b>Ctrl</b>"),
+ SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR);
+
+ entity_angle->create(desktop, item, this, Inkscape::CTRL_TYPE_ROTATE,
+ _("<b>Rotate</b> the pattern fill; with <b>Ctrl</b> to snap angle"),
+ SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR);
+
+ entity.push_back(entity_xy);
+ entity.push_back(entity_angle);
+ entity.push_back(entity_scale);
+ }
+
+ if ((item->style->stroke.isPaintserver()) && SP_IS_PATTERN(item->style->getStrokePaintServer())) {
+ PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(false);
+ PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(false);
+ PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(false);
entity_xy->create(desktop, item, this, Inkscape::CTRL_TYPE_POINT,
// TRANSLATORS: This refers to the pattern that's inside the object
_("<b>Move</b> the pattern fill inside the object"),
diff --git a/src/object-edit.cpp b/src/object-edit.cpp
index e9b183eca..fe22f6c1c 100644
--- a/src/object-edit.cpp
+++ b/src/object-edit.cpp
@@ -79,8 +79,8 @@ KnotHolder *createKnotHolder(SPItem *item, SPDesktop *desktop)
knotholder = new OffsetKnotHolder(desktop, item, NULL);
} else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) {
knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL);
- } else if ((item->style->fill.isPaintserver())
- && SP_IS_PATTERN(item->style->getFillPaintServer())) {
+ } else if ((item->style->fill.isPaintserver() && SP_IS_PATTERN(item->style->getFillPaintServer())) ||
+ (item->style->stroke.isPaintserver() && SP_IS_PATTERN(item->style->getStrokePaintServer()))) {
knotholder = new KnotHolder(desktop, item, NULL);
knotholder->add_pattern_knotholder();
}
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 6c2ada9d7..780845deb 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -1109,9 +1109,10 @@ void SPItem::invoke_hide(unsigned key)
// Adjusters
-void SPItem::adjust_pattern (Geom::Affine const &postmul, bool set)
+void SPItem::adjust_pattern(Geom::Affine const &postmul, bool set, PatternTransform pt)
{
- if (style && (style->fill.isPaintserver())) {
+ bool fill = (pt == TRANSFORM_FILL || pt == TRANSFORM_BOTH);
+ if (fill && style && (style->fill.isPaintserver())) {
SPObject *server = style->getFillPaintServer();
if ( SP_IS_PATTERN(server) ) {
SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "fill");
@@ -1119,7 +1120,8 @@ void SPItem::adjust_pattern (Geom::Affine const &postmul, bool set)
}
}
- if (style && (style->stroke.isPaintserver())) {
+ bool stroke = (pt == TRANSFORM_STROKE || pt == TRANSFORM_BOTH);
+ if (stroke && style && (style->stroke.isPaintserver())) {
SPObject *server = style->getStrokePaintServer();
if ( SP_IS_PATTERN(server) ) {
SPPattern *pattern = sp_pattern_clone_if_necessary(this, SP_PATTERN(server), "stroke");
diff --git a/src/sp-item.h b/src/sp-item.h
index ce93b1d40..2880f4a8e 100644
--- a/src/sp-item.h
+++ b/src/sp-item.h
@@ -51,6 +51,13 @@ enum {
SP_EVENT_MOUSEOUT
};
+// TODO fix this
+enum PatternTransform {
+ TRANSFORM_BOTH,
+ TRANSFORM_FILL,
+ TRANSFORM_STROKE
+};
+
/**
* Event structure.
*
@@ -199,7 +206,7 @@ public:
Inkscape::DrawingItem *invoke_show(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags);
void invoke_hide(unsigned int key);
void getSnappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs=0) const;
- void adjust_pattern(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false);
+ void adjust_pattern(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false, PatternTransform = TRANSFORM_BOTH);
void adjust_gradient(/* Geom::Affine const &premul, */ Geom::Affine const &postmul, bool set = false);
void adjust_stroke(gdouble ex);
void adjust_stroke_width_recursive(gdouble ex);