summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-09-23 02:19:28 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-09-23 02:19:28 +0000
commita01a3fa9d658218f3afbe5ab9922deb9c3ce38be (patch)
tree695eae486fd113e903abd7353155f5abd183bf2b /src
parentFix for 172222 : Move direct to specified layer (diff)
downloadinkscape-a01a3fa9d658218f3afbe5ab9922deb9c3ce38be.tar.gz
inkscape-a01a3fa9d658218f3afbe5ab9922deb9c3ce38be.zip
Fix for 367548 : Invert doesnt work on objects with gradients
(bzr r11696)
Diffstat (limited to 'src')
-rw-r--r--src/gradient-chemistry.cpp62
-rw-r--r--src/gradient-chemistry.h3
-rw-r--r--src/gradient-context.cpp2
-rw-r--r--src/sp-gradient.h3
-rw-r--r--src/ui/widget/selected-style.cpp5
-rw-r--r--src/widgets/gradient-toolbar.cpp2
6 files changed, 62 insertions, 15 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 2ddfe5ff7..ed4e81f0d 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -959,6 +959,44 @@ void sp_item_gradient_reverse_vector(SPItem *item, Inkscape::PaintTarget fill_or
g_slist_free (child_objects);
}
+void sp_item_gradient_invert_vector_color(SPItem *item, Inkscape::PaintTarget fill_or_stroke)
+{
+#ifdef SP_GR_VERBOSE
+ g_message("sp_item_gradient_invert_vector_color(%p, %d)", item, fill_or_stroke);
+#endif
+ SPGradient *gradient = getGradient(item, fill_or_stroke);
+ if (!gradient || !SP_IS_GRADIENT(gradient))
+ return;
+
+ SPGradient *vector = gradient->getVector();
+ if (!vector) // orphan!
+ return;
+
+ vector = sp_gradient_fork_vector_if_necessary (vector);
+ if ( gradient != vector && gradient->ref->getObject() != vector ) {
+ sp_gradient_repr_set_link(gradient->getRepr(), vector);
+ }
+
+ for ( SPObject *child = vector->firstChild(); child; child = child->getNext()) {
+ if (SP_IS_STOP(child)) {
+ guint32 color = sp_stop_get_rgba32(SP_STOP(child));
+ //g_message("Stop color %d", color);
+ gchar c[64];
+ sp_svg_write_color (c, sizeof(c),
+ SP_RGBA32_U_COMPOSE(
+ (255 - SP_RGBA32_R_U(color)),
+ (255 - SP_RGBA32_G_U(color)),
+ (255 - SP_RGBA32_B_U(color)),
+ SP_RGBA32_A_U(color)
+ )
+ );
+ SPCSSAttr *css = sp_repr_css_attr_new ();
+ sp_repr_css_set_property (css, "stop-color", c);
+ sp_repr_css_change(child->getRepr(), css, "style");
+ sp_repr_css_attr_unref (css);
+ }
+ }
+}
/**
Set the position of point point_type of the gradient applied to item (either fill_or_stroke) to
@@ -1514,10 +1552,22 @@ SPGradient *sp_gradient_vector_for_object( SPDocument *const doc, SPDesktop *con
return sp_document_default_gradient_vector( doc, color, singleStop );
}
-
void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTarget fill_or_stroke)
{
Inkscape::Selection *selection = sp_desktop_selection(desktop);
+
+ for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
+ sp_item_gradient_invert_vector_color(SP_ITEM(i->data), fill_or_stroke);
+ }
+
+ // we did an undoable action
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT,
+ _("Invert gradient colors"));
+}
+
+void sp_gradient_reverse_selected_gradients(SPDesktop *desktop)
+{
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPEventContext *ev = sp_desktop_event_context(desktop);
if (!ev) {
@@ -1531,18 +1581,14 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa
drag->selected_reverse_vector();
} else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients)
for (GSList const* i = selection->itemList(); i != NULL; i = i->next) {
- if (fill_or_stroke == Inkscape::FOR_FILL_AND_STROKE) {
- sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL);
- sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE);
- } else {
- sp_item_gradient_reverse_vector(SP_ITEM(i->data), fill_or_stroke);
- }
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_FILL);
+ sp_item_gradient_reverse_vector(SP_ITEM(i->data), Inkscape::FOR_STROKE);
}
}
// we did an undoable action
DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT,
- _("Invert gradient"));
+ _("Reverse gradient"));
}
/*
diff --git a/src/gradient-chemistry.h b/src/gradient-chemistry.h
index ff1f32dc7..50422458c 100644
--- a/src/gradient-chemistry.h
+++ b/src/gradient-chemistry.h
@@ -70,6 +70,8 @@ SPStop *sp_vector_add_stop(SPGradient *vector, SPStop* prev_stop, SPStop* next_s
void sp_gradient_transform_multiply(SPGradient *gradient, Geom::Affine postmul, bool set);
+void sp_gradient_reverse_selected_gradients(SPDesktop *desktop);
+
void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTarget fill_or_stroke);
/**
@@ -98,6 +100,7 @@ void sp_item_gradient_stop_set_style(SPItem *item, GrPointType point_type, guint
guint32 sp_item_gradient_stop_query_style(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
void sp_item_gradient_edit_stop(SPItem *item, GrPointType point_type, guint point_i, Inkscape::PaintTarget fill_or_stroke);
void sp_item_gradient_reverse_vector(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
+void sp_item_gradient_invert_vector_color(SPItem *item, Inkscape::PaintTarget fill_or_stroke);
#endif // SEEN_SP_GRADIENT_CHEMISTRY_H
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index 356743eed..5b0e261de 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -837,7 +837,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
case GDK_KEY_r:
case GDK_KEY_R:
if (MOD__SHIFT_ONLY) {
- sp_gradient_invert_selected_gradients(desktop, Inkscape::FOR_FILL_AND_STROKE);
+ sp_gradient_reverse_selected_gradients(desktop);
ret = TRUE;
}
break;
diff --git a/src/sp-gradient.h b/src/sp-gradient.h
index 36f6f92e6..a21a413f4 100644
--- a/src/sp-gradient.h
+++ b/src/sp-gradient.h
@@ -77,8 +77,7 @@ namespace Inkscape {
enum PaintTarget {
FOR_FILL,
- FOR_STROKE,
- FOR_FILL_AND_STROKE
+ FOR_STROKE
};
/**
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index b3c4fbdcd..a4313f677 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -600,9 +600,9 @@ void SelectedStyle::on_fill_invert() {
guint32 color = _thisselected[SS_FILL];
gchar c[64];
if (_mode[SS_FILL] == SS_LGRADIENT || _mode[SS_FILL] == SS_RGRADIENT) {
- g_message("Gradient");
sp_gradient_invert_selected_gradients(_desktop, Inkscape::FOR_FILL);
return;
+
}
if (_mode[SS_FILL] != SS_COLOR) return;
@@ -625,8 +625,7 @@ void SelectedStyle::on_stroke_invert() {
SPCSSAttr *css = sp_repr_css_attr_new ();
guint32 color = _thisselected[SS_STROKE];
gchar c[64];
- if (_mode[SS_FILL] == SS_LGRADIENT || _mode[SS_FILL] == SS_RGRADIENT) {
- g_message("Gradient");
+ if (_mode[SS_STROKE] == SS_LGRADIENT || _mode[SS_STROKE] == SS_RGRADIENT) {
sp_gradient_invert_selected_gradients(_desktop, Inkscape::FOR_STROKE);
return;
}
diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp
index cc6b04413..7542e16b3 100644
--- a/src/widgets/gradient-toolbar.cpp
+++ b/src/widgets/gradient-toolbar.cpp
@@ -633,7 +633,7 @@ static void gr_linked_changed(GtkToggleAction *act, gpointer /*data*/)
static void gr_reverse(GtkWidget * /*button*/, gpointer data)
{
SPDesktop *desktop = static_cast<SPDesktop *>(data);
- sp_gradient_invert_selected_gradients(desktop, Inkscape::FOR_FILL_AND_STROKE);
+ sp_gradient_reverse_selected_gradients(desktop);
}
/*