diff options
| -rw-r--r-- | src/gradient-chemistry.cpp | 37 | ||||
| -rw-r--r-- | src/gradient-chemistry.h | 1 | ||||
| -rw-r--r-- | src/gradient-context.cpp | 13 | ||||
| -rw-r--r-- | src/sp-gradient.h | 3 | ||||
| -rw-r--r-- | src/ui/widget/selected-style.cpp | 12 | ||||
| -rw-r--r-- | src/widgets/gradient-toolbar.cpp | 22 |
6 files changed, 54 insertions, 34 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 34934f75b..2ddfe5ff7 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -26,7 +26,13 @@ #include "style.h" #include "document-private.h" +#include "document-undo.h" #include "desktop-style.h" +#include "desktop-handles.h" +#include "event-context.h" +#include "selection.h" +#include "verbs.h" +#include <glibmm/i18n.h> #include "sp-gradient-reference.h" #include "sp-gradient-vector.h" @@ -47,6 +53,7 @@ #define noSP_GR_VERBOSE +using Inkscape::DocumentUndo; namespace { @@ -1508,6 +1515,36 @@ SPGradient *sp_gradient_vector_for_object( SPDocument *const doc, SPDesktop *con } +void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTarget fill_or_stroke) +{ + Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPEventContext *ev = sp_desktop_event_context(desktop); + + if (!ev) { + return; + } + + GrDrag *drag = ev->get_drag(); + + // First try selected dragger + if (drag && drag->selected) { + 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); + } + } + } + + // we did an undoable action + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_GRADIENT, + _("Invert gradient")); +} + /* Local Variables: mode:c++ diff --git a/src/gradient-chemistry.h b/src/gradient-chemistry.h index 2f3ea4303..ff1f32dc7 100644 --- a/src/gradient-chemistry.h +++ b/src/gradient-chemistry.h @@ -70,6 +70,7 @@ 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_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTarget fill_or_stroke); /** * Fetches either the fill or the stroke gradient from the given item. diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index aa8c8b929..356743eed 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -837,18 +837,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event) case GDK_KEY_r: case GDK_KEY_R: if (MOD__SHIFT_ONLY) { - // First try selected dragger - if (drag && drag->selected) { - 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) { - 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")); + sp_gradient_invert_selected_gradients(desktop, Inkscape::FOR_FILL_AND_STROKE); ret = TRUE; } break; diff --git a/src/sp-gradient.h b/src/sp-gradient.h index a21a413f4..36f6f92e6 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -77,7 +77,8 @@ namespace Inkscape { enum PaintTarget { FOR_FILL, - FOR_STROKE + FOR_STROKE, + FOR_FILL_AND_STROKE }; /** diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index a37f36eea..b3c4fbdcd 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -48,6 +48,7 @@ #include "pixmaps/cursor-adj-s.xpm" #include "pixmaps/cursor-adj-l.xpm" #include "sp-cursor.h" +#include "gradient-chemistry.h" static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 }; static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"}; @@ -598,6 +599,12 @@ void SelectedStyle::on_fill_invert() { SPCSSAttr *css = sp_repr_css_attr_new (); 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; sp_svg_write_color (c, sizeof(c), SP_RGBA32_U_COMPOSE( @@ -618,6 +625,11 @@ 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"); + sp_gradient_invert_selected_gradients(_desktop, Inkscape::FOR_STROKE); + return; + } if (_mode[SS_STROKE] != SS_COLOR) return; sp_svg_write_color (c, sizeof(c), SP_RGBA32_U_COMPOSE( diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index ae85ed515..cc6b04413 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -633,27 +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); - Inkscape::Selection *selection = sp_desktop_selection(desktop); - SPEventContext *ev = sp_desktop_event_context(desktop); - - if (!ev) { - return; - } - - GrDrag *drag = ev->get_drag(); - - // First try selected dragger - if (drag && drag->selected) { - 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) { - 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")); + sp_gradient_invert_selected_gradients(desktop, Inkscape::FOR_FILL_AND_STROKE); } /* |
