diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2012-12-16 05:41:25 +0000 |
| commit | 7ec903c9898f872dbd9426ed7a62e1969fdb7be7 (patch) | |
| tree | a306139e829118a83516af02279c9eafd3440eaa /src/gradient-chemistry.cpp | |
| parent | Hershey Text: whitespace; py: docstring, modeline; inx: fix attribute value (diff) | |
| parent | Translations.Spanish translation update by Lucas Vieites. (diff) | |
| download | inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.tar.gz inkscape-7ec903c9898f872dbd9426ed7a62e1969fdb7be7.zip | |
merge from trunk (r11955)
(bzr r11687.1.3)
Diffstat (limited to 'src/gradient-chemistry.cpp')
| -rw-r--r-- | src/gradient-chemistry.cpp | 108 |
1 files changed, 105 insertions, 3 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 34934f75b..6b019ad2a 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -26,7 +26,14 @@ #include "style.h" #include "document-private.h" +#include "document-undo.h" +#include "desktop.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" @@ -36,6 +43,7 @@ #include "sp-stop.h" #include "widgets/gradient-vector.h" #include "gradient-drag.h" +#include "gradient-chemistry.h" #include "sp-text.h" #include "sp-tspan.h" @@ -47,6 +55,7 @@ #define noSP_GR_VERBOSE +using Inkscape::DocumentUndo; namespace { @@ -166,7 +175,7 @@ static SPGradient *sp_gradient_get_private_normalized(SPDocument *document, SPGr /** Count how many times gr is used by the styles of o and its descendants */ -guint count_gradient_hrefs(SPObject *o, SPGradient *gr) +static guint count_gradient_hrefs(SPObject *o, SPGradient *gr) { if (!o) return 1; @@ -200,8 +209,8 @@ guint count_gradient_hrefs(SPObject *o, SPGradient *gr) /** * If gr has other users, create a new private; also check if gr links to vector, relink if not */ -SPGradient *sp_gradient_fork_private_if_necessary(SPGradient *gr, SPGradient *vector, - SPGradientType type, SPObject *o) +static SPGradient *sp_gradient_fork_private_if_necessary(SPGradient *gr, SPGradient *vector, + SPGradientType type, SPObject *o) { #ifdef SP_GR_VERBOSE g_message("sp_gradient_fork_private_if_necessary(%p, %p, %d, %p)", gr, vector, type, o); @@ -952,6 +961,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 @@ -1507,7 +1554,62 @@ 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) { + 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, + _("Reverse gradient")); +} + +void sp_gradient_unset_swatch(SPDesktop *desktop, std::string id) +{ + SPDocument *doc = desktop ? desktop->doc() : 0; + + if (doc) { + const GSList *gradients = doc->getResourceList("gradient"); + for (const GSList *item = gradients; item; item = item->next) { + SPGradient* grad = SP_GRADIENT(item->data); + if ( id == grad->getId() ) { + grad->setSwatch(false); + DocumentUndo::done(doc, SP_VERB_CONTEXT_GRADIENT, + _("Delete swatch")); + break; + } + } + } +} /* Local Variables: mode:c++ |
