From: Jon A. Cruz Date: Tue, 9 Mar 2010 10:12:09 +0000 (-0800) Subject: Initial F&S dialog setting of swatch colors. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7e32c19e78592fbf120af717222bf4185b4bc4e9;p=inkscape.git Initial F&S dialog setting of swatch colors. --- diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 2afcd6109..f3b1b833d 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -475,8 +475,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill if (!SP_IS_LINEARGRADIENT(server)) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server - SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE ); - SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE ); + SPGradient *vector = SP_GRADIENT(server)->getVector(); + SPGradient *vector_res = SP_GRADIENT(server_res)->getVector(); if (vector_res != vector) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors @@ -485,8 +485,8 @@ objects_query_fillstroke (GSList *objects, SPStyle *style_res, bool const isfill if (!SP_IS_RADIALGRADIENT(server)) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different kind of server - SPGradient *vector = sp_gradient_get_vector ( SP_GRADIENT (server), FALSE ); - SPGradient *vector_res = sp_gradient_get_vector ( SP_GRADIENT (server_res), FALSE ); + SPGradient *vector = SP_GRADIENT(server)->getVector(); + SPGradient *vector_res = SP_GRADIENT(server_res)->getVector(); if (vector_res != vector) return QUERY_STYLE_MULTIPLE_DIFFERENT; // different gradient vectors diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 76b901023..5331c072c 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1659,7 +1659,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, GradientInfo gi; - SPGradient *grvec = sp_gradient_get_vector(gradient, FALSE); + SPGradient *grvec = gradient->getVector(FALSE); for (SPStop *stop = grvec->getFirstStop() ; stop ; stop = stop->getNextStop()) { diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 7382aa49b..b2e68c345 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -264,7 +264,7 @@ sp_gradient_fork_vector_if_necessary (SPGradient *gr) SPGradient * sp_gradient_get_forked_vector_if_necessary(SPGradient *gradient, bool force_vector) { - SPGradient *vector = sp_gradient_get_vector (gradient, force_vector); + SPGradient *vector = gradient->getVector(force_vector); vector = sp_gradient_fork_vector_if_necessary (vector); if ( gradient != vector && gradient->ref->getObject() != vector ) { sp_gradient_repr_set_link(SP_OBJECT_REPR(gradient), vector); @@ -336,7 +336,7 @@ sp_gradient_convert_to_userspace(SPGradient *gr, SPItem *item, gchar const *prop g_return_val_if_fail(SP_IS_GRADIENT(gr), NULL); // First, fork it if it is shared - gr = sp_gradient_fork_private_if_necessary(gr, sp_gradient_get_vector(gr, FALSE), + gr = sp_gradient_fork_private_if_necessary(gr, gr->getVector(), SP_IS_RADIALGRADIENT(gr) ? SP_GRADIENT_TYPE_RADIAL : SP_GRADIENT_TYPE_LINEAR, SP_OBJECT(item)); if (gr->units == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) { @@ -555,7 +555,7 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool if (!gradient || !SP_IS_GRADIENT(gradient)) return; - SPGradient *vector = sp_gradient_get_vector (gradient, false); + SPGradient *vector = gradient->getVector(); switch (point_type) { case POINT_LG_BEGIN: case POINT_RG_CENTER: @@ -596,7 +596,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i if (!gradient || !SP_IS_GRADIENT(gradient)) return 0; - SPGradient *vector = sp_gradient_get_vector (gradient, false); + SPGradient *vector = gradient->getVector(); if (!vector) // orphan! return 0; // what else to do? @@ -649,7 +649,7 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i, if (!gradient || !SP_IS_GRADIENT(gradient)) return; - SPGradient *vector = sp_gradient_get_vector (gradient, false); + SPGradient *vector = gradient->getVector(); if (!vector) // orphan! return; @@ -705,7 +705,7 @@ sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke) if (!gradient || !SP_IS_GRADIENT(gradient)) return; - SPGradient *vector = sp_gradient_get_vector (gradient, false); + SPGradient *vector = gradient->getVector(); if (!vector) // orphan! return; @@ -958,8 +958,9 @@ sp_item_gradient_get_vector (SPItem *item, bool fill_or_stroke) { SPGradient *gradient = sp_item_gradient (item, fill_or_stroke); - if (gradient) - return sp_gradient_get_vector (gradient, false); + if (gradient) { + return gradient->getVector(); + } return NULL; } @@ -1087,7 +1088,7 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_ // current is private and it's either used once, or all its uses are by children of item; // so just change its href to vector - if ( current != gr && sp_gradient_get_vector(current, false) != gr ) { + if ( current != gr && current->getVector() != gr ) { /* href is not the vector */ sp_gradient_repr_set_link(SP_OBJECT_REPR(current), gr); } @@ -1123,25 +1124,20 @@ sp_item_set_gradient(SPItem *item, SPGradient *gr, SPGradientType type, bool is_ } } -static void -sp_gradient_repr_set_link(Inkscape::XML::Node *repr, SPGradient *link) +static void sp_gradient_repr_set_link(Inkscape::XML::Node *repr, SPGradient *link) { g_return_if_fail(repr != NULL); - g_return_if_fail(link != NULL); - g_return_if_fail(SP_IS_GRADIENT(link)); + if (link) { + g_return_if_fail(SP_IS_GRADIENT(link)); + } - gchar *ref; if (link) { - gchar const *id = link->getId(); - size_t const len = strlen(id); - ref = (gchar*) alloca(len + 2); - *ref = '#'; - memcpy(ref + 1, id, len + 1); + Glib::ustring ref("#"); + ref += link->getId(); + repr->setAttribute("xlink:href", ref.c_str()); } else { - ref = NULL; + repr->setAttribute("xlink:href", 0); } - - repr->setAttribute("xlink:href", ref); } /* @@ -1225,7 +1221,7 @@ sp_gradient_vector_for_object(SPDocument *const doc, SPDesktop *const desktop, if (paint.isPaintserver()) { SPObject *server = is_fill? SP_OBJECT_STYLE_FILL_SERVER(o) : SP_OBJECT_STYLE_STROKE_SERVER(o); if (SP_IS_GRADIENT (server)) { - return sp_gradient_get_vector(SP_GRADIENT (server), TRUE); + return SP_GRADIENT(server)->getVector(true); } else { rgba = sp_desktop_get_color(desktop, is_fill); } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 13b422119..9796fc5da 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -905,7 +905,7 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data) if ( (state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK ) ) { // delete this knot from vector SPGradient *gradient = sp_item_gradient (draggable->item, draggable->fill_or_stroke); - gradient = sp_gradient_get_vector (gradient, false); + gradient = gradient->getVector(); if (gradient->vector.stops.size() > 2) { // 2 is the minimum SPStop *stop = NULL; switch (draggable->point_type) { // if we delete first or last stop, move the next/previous to the edge diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp index 575197fee..1c184da72 100644 --- a/src/helper/stock-items.cpp +++ b/src/helper/stock-items.cpp @@ -23,7 +23,7 @@ #include -#include "sp-gradient-fns.h" +#include "sp-gradient.h" #include "document-private.h" #include "sp-pattern.h" #include "marker.h" diff --git a/src/sp-gradient-fns.h b/src/sp-gradient-fns.h index 25729f5d7..dafa1646f 100644 --- a/src/sp-gradient-fns.h +++ b/src/sp-gradient-fns.h @@ -13,18 +13,6 @@ class SPGradient; -namespace Inkscape { -namespace XML { -class Node; -} -} - -#define SP_TYPE_GRADIENT (sp_gradient_get_type()) -#define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient)) -#define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass)) -#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT)) -#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT)) - #define SP_GRADIENT_STATE_IS_SET(g) (SP_GRADIENT(g)->state != SP_GRADIENT_STATE_UNKNOWN) #define SP_GRADIENT_IS_VECTOR(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_VECTOR) #define SP_GRADIENT_IS_PRIVATE(g) (SP_GRADIENT(g)->state == SP_GRADIENT_STATE_PRIVATE) @@ -32,8 +20,6 @@ class Node; #define SP_GRADIENT_SPREAD(g) (SP_GRADIENT(g)->spread) #define SP_GRADIENT_UNITS(g) (SP_GRADIENT(g)->units) -GType sp_gradient_get_type(); - /** Forces vector to be built, if not present (i.e. changed) */ void sp_gradient_ensure_vector(SPGradient *gradient); @@ -43,7 +29,6 @@ void sp_gradient_ensure_colors(SPGradient *gradient); void sp_gradient_set_units(SPGradient *gr, SPGradientUnits units); void sp_gradient_set_spread(SPGradient *gr, SPGradientSpread spread); -SPGradient *sp_gradient_get_vector (SPGradient *gradient, bool force_private); SPGradientSpread sp_gradient_get_spread (SPGradient *gradient); /* Gradient repr methods */ diff --git a/src/sp-gradient-reference.cpp b/src/sp-gradient-reference.cpp index 618e1085a..39ef9915a 100644 --- a/src/sp-gradient-reference.cpp +++ b/src/sp-gradient-reference.cpp @@ -1,5 +1,5 @@ #include "sp-gradient-reference.h" -#include "sp-gradient-fns.h" +#include "sp-gradient.h" bool SPGradientReference::_acceptObject(SPObject *obj) const diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 4e8e8e373..3d4d69672 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -815,8 +815,7 @@ chase_hrefs(SPGradient *const src, bool (*match)(SPGradient const *)) /** * True if gradient has stops. */ -static bool -has_stops(SPGradient const *gr) +static bool has_stopsFN(SPGradient const *gr) { return SP_GRADIENT_HAS_STOPS(gr); } @@ -840,23 +839,14 @@ has_units_set(SPGradient const *gr) } -/** - * Returns private vector of given gradient (the gradient at the end of the href chain which has - * stops), optionally normalizing it. - * - * \pre SP_IS_GRADIENT(gradient). - * \pre There exists a gradient in the chain that has stops. - */ -SPGradient * -sp_gradient_get_vector(SPGradient *gradient, bool force_vector) +SPGradient *SPGradient::getVector(bool force_vector) { - g_return_val_if_fail(gradient != NULL, NULL); - g_return_val_if_fail(SP_IS_GRADIENT(gradient), NULL); + SPGradient * src = chase_hrefs(this, has_stopsFN); - SPGradient *const src = chase_hrefs(gradient, has_stops); - return ( force_vector - ? sp_gradient_ensure_vector_normalized(src) - : src ); + if (force_vector) { + src = sp_gradient_ensure_vector_normalized(src); + } + return src; } /** diff --git a/src/sp-gradient.h b/src/sp-gradient.h index 045109234..e7488673d 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -1,5 +1,5 @@ -#ifndef __SP_GRADIENT_H__ -#define __SP_GRADIENT_H__ +#ifndef SEEN_SP_GRADIENT_H +#define SEEN_SP_GRADIENT_H /** \file * SVG and implementation @@ -7,7 +7,9 @@ * Authors: * Lauris Kaplinski * Johan Engelen + * Jon A. Cruz * + * Copyrigt (C) 2010 Jon A. Cruz * Copyright (C) 2007 Johan Engelen * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. @@ -26,6 +28,15 @@ struct SPGradientReference; + +#define SP_TYPE_GRADIENT (sp_gradient_get_type()) +#define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient)) +#define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass)) +#define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT)) +#define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT)) + +GType sp_gradient_get_type(); + typedef enum { SP_GRADIENT_TYPE_UNKNOWN, SP_GRADIENT_TYPE_LINEAR, @@ -93,6 +104,15 @@ struct SPGradient : public SPPaintServer { SPStop* getFirstStop(); int getStopCount() const; + +/** + * Returns private vector of given gradient (the gradient at the end of the href chain which has + * stops), optionally normalizing it. + * + * \pre SP_IS_GRADIENT(gradient). + * \pre There exists a gradient in the chain that has stops. + */ + SPGradient *getVector(bool force_private = false); }; /** @@ -105,7 +125,7 @@ struct SPGradientClass { #include "sp-gradient-fns.h" -#endif /* !__SP_GRADIENT_H__ */ +#endif // SEEN_SP_GRADIENT_H /* Local Variables: diff --git a/src/sp-paint-server.cpp b/src/sp-paint-server.cpp index 805aafaea..258323a93 100644 --- a/src/sp-paint-server.cpp +++ b/src/sp-paint-server.cpp @@ -157,8 +157,17 @@ static void sp_painter_stale_fill(SPPainter */*painter*/, NRPixBlock *pb) bool SPPaintServer::isSwatch() const { - // Temporary for now. Later expand to more - return isSolid(); + bool swatch = false; + if (SP_IS_GRADIENT(this)) { + SPGradient *grad = SP_GRADIENT(this); + if ( SP_GRADIENT_HAS_STOPS(grad) ) { + gchar const * attr = repr->attribute("osb:paint"); + if (attr && !strcmp(attr, "solid")) { + swatch = true; + } + } + } + return swatch; } bool SPPaintServer::isSolid() const diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index e7b0188d8..a8f9f9c60 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -103,7 +103,7 @@ static guint nui_drop_target_entries = ENTRIES_SIZE(ui_drop_target_entries); static Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop); SelectedStyle::SelectedStyle(bool /*layout*/) - : + : current_stroke_width(0), _desktop (NULL), @@ -955,13 +955,13 @@ SelectedStyle::update() _paintserver_id[i] += ")"; if (SP_IS_LINEARGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector(SP_GRADIENT(server), false); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_gradient_image_set_gradient ((SPGradientImage *) _gradient_preview_l[i], vector); place->add(_gradient_box_l[i]); _tooltips.set_tip(*place, __lgradient[i]); _mode[i] = SS_LGRADIENT; } else if (SP_IS_RADIALGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector(SP_GRADIENT(server), false); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_gradient_image_set_gradient ((SPGradientImage *) _gradient_preview_r[i], vector); place->add(_gradient_box_r[i]); _tooltips.set_tip(*place, __rgradient[i]); @@ -1165,7 +1165,7 @@ RotateableSwatch::RotateableSwatch(SelectedStyle *parent, guint mode) : undokey("ssrot1"), cr(0), cr_set(false) - + { } @@ -1426,14 +1426,14 @@ RotateableStrokeWidth::do_release(double by, guint modifier) { Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop) { - if (Dialog::PanelDialogBase *panel_dialog = + if (Dialog::PanelDialogBase *panel_dialog = dynamic_cast(desktop->_dlg_mgr->getDialog("FillAndStroke"))) { try { - Dialog::FillAndStroke &fill_and_stroke = + Dialog::FillAndStroke &fill_and_stroke = dynamic_cast(panel_dialog->getPanel()); return &fill_and_stroke; } catch (std::exception e) { } - } + } return 0; } diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 0b08f36b5..87cd238a7 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -210,10 +210,11 @@ sp_fill_style_widget_update (SPWidget *spw) SPPaintServer *server = SP_STYLE_FILL_SERVER (query); - if (server && server->isSwatch()) { - sp_paint_selector_set_swatch( psel, server ); + if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { + SPGradient *vector = SP_GRADIENT(server)->getVector(); + sp_paint_selector_set_swatch( psel, vector ); } else if (SP_IS_LINEARGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_paint_selector_set_gradient_linear (psel, vector); SPLinearGradient *lg = SP_LINEARGRADIENT (server); @@ -221,7 +222,7 @@ sp_fill_style_widget_update (SPWidget *spw) SP_GRADIENT_UNITS (lg), SP_GRADIENT_SPREAD (lg)); } else if (SP_IS_RADIALGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_paint_selector_set_gradient_radial (psel, vector); SPRadialGradient *rg = SP_RADIALGRADIENT (server); @@ -411,8 +412,9 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, case SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR: case SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL: + case SP_PAINT_SELECTOR_MODE_SWATCH: if (items) { - SPGradientType const gradient_type = ( psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR + SPGradientType const gradient_type = ( psel->mode != SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); @@ -518,10 +520,6 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, break; - case SP_PAINT_SELECTOR_MODE_SWATCH: - // TODO - break; - case SP_PAINT_SELECTOR_MODE_UNSET: if (items) { SPCSSAttr *css = sp_repr_css_attr_new (); diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index ada9b2f09..bc2413730 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -120,7 +120,7 @@ sp_gradient_selector_class_init (SPGradientSelectorClass *klass) static void sp_gradient_selector_init (SPGradientSelector *sel) { - GtkWidget *hb, *l, *m, *mi; + GtkWidget *hb, *m, *mi; sel->mode = SPGradientSelector::MODE_LINEAR; @@ -182,9 +182,9 @@ sp_gradient_selector_init (SPGradientSelector *sel) gtk_option_menu_set_menu (GTK_OPTION_MENU (sel->spread), m); - l = gtk_label_new (_("Repeat:")); - gtk_widget_show (l); - gtk_box_pack_end (GTK_BOX (hb), l, FALSE, FALSE, 4); + sel->spreadLbl = gtk_label_new (_("Repeat:")); + gtk_widget_show(sel->spreadLbl); + gtk_box_pack_end(GTK_BOX(hb), sel->spreadLbl, FALSE, FALSE, 4); } static void @@ -210,7 +210,28 @@ sp_gradient_selector_new (void) void SPGradientSelector::setMode(SelectorMode mode) { - this->mode = mode; + if (mode != this->mode) { + this->mode = mode; + if (mode == MODE_SWATCH) { + if (spread) { + GtkWidget *parent = gtk_widget_get_parent(spread); + if (parent) { + gtk_container_remove(GTK_CONTAINER(parent), spread); + spread = 0; + } + } + if (spreadLbl) { + GtkWidget *parent = gtk_widget_get_parent(spreadLbl); + if (parent) { + gtk_container_remove(GTK_CONTAINER(parent), spreadLbl); + spreadLbl = 0; + } + } + + SPGradientVectorSelector* vs = SP_GRADIENT_VECTOR_SELECTOR(vectors); + vs->setSwatched(); + } + } } void SPGradientSelector::setUnits(SPGradientUnits units) @@ -227,7 +248,6 @@ void SPGradientSelector::setSpread(SPGradientSpread spread) SPGradientUnits SPGradientSelector::getUnits() { - //return (SPGradientUnits) sel->gradientUnits; return gradientUnits; } diff --git a/src/widgets/gradient-selector.h b/src/widgets/gradient-selector.h index 85674b4a9..25f561a6e 100644 --- a/src/widgets/gradient-selector.h +++ b/src/widgets/gradient-selector.h @@ -36,7 +36,8 @@ struct SPGradientSelector { enum SelectorMode { MODE_LINEAR, - MODE_RADIAL + MODE_RADIAL, + MODE_SWATCH }; SelectorMode mode; @@ -56,6 +57,7 @@ struct SPGradientSelector { /* Spread selector */ GtkWidget *spread; + GtkWidget *spreadLbl; void setMode(SelectorMode mode); void setUnits(SPGradientUnits units); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 784e3f20f..077e038e7 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -315,7 +315,7 @@ void gr_read_selection( Inkscape::Selection *selection, if (style && (style->fill.isPaintserver())) { SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (item); if (SP_IS_GRADIENT(server)) { - SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false); + SPGradient *gradient = SP_GRADIENT(server)->getVector(); SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server)); if (gradient && gradient->isSolid()) { @@ -341,7 +341,7 @@ void gr_read_selection( Inkscape::Selection *selection, if (style && (style->stroke.isPaintserver())) { SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER (item); if (SP_IS_GRADIENT(server)) { - SPGradient *gradient = sp_gradient_get_vector (SP_GRADIENT (server), false); + SPGradient *gradient = SP_GRADIENT(server)->getVector(); SPGradientSpread spread = sp_gradient_get_spread (SP_GRADIENT (server)); if (gradient && gradient->isSolid()) { diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 751898f4f..147077f44 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -116,6 +116,8 @@ static void sp_gradient_vector_selector_init(SPGradientVectorSelector *gvs) { gvs->idlabel = TRUE; + gvs->swatched = false; + gvs->doc = NULL; gvs->gr = NULL; @@ -250,7 +252,7 @@ static void sp_gvs_rebuild_gui_full(SPGradientVectorSelector *gvs) const GSList *gradients = sp_document_get_resource_list(SP_OBJECT_DOCUMENT(gvs->gr), "gradient"); for (const GSList *curr = gradients; curr; curr = curr->next) { SPGradient* grad = SP_GRADIENT(curr->data); - if (SP_GRADIENT_HAS_STOPS(grad) && !grad->isSwatch()) { + if (SP_GRADIENT_HAS_STOPS(grad) && (grad->isSwatch() == gvs->swatched)) { gl = g_slist_prepend(gl, curr->data); } } @@ -402,6 +404,12 @@ static void sp_gvs_defs_modified(SPObject */*defs*/, guint /*flags*/, SPGradient sp_gvs_rebuild_gui_full(gvs); } +void SPGradientVectorSelector::setSwatched() +{ + swatched = true; + sp_gvs_rebuild_gui_full(this); +} + /*################################################################## ### Vector Editing Widget ##################################################################*/ diff --git a/src/widgets/gradient-vector.h b/src/widgets/gradient-vector.h index ea1f5159f..ceca9158c 100644 --- a/src/widgets/gradient-vector.h +++ b/src/widgets/gradient-vector.h @@ -6,7 +6,9 @@ * * Author: * Lauris Kaplinski + * Jon A. Cruz * + * Copyright (C) 2010 Jon A. Cruz * Copyright (C) 2001-2002 Lauris Kaplinski * Copyright (C) 2001 Ximian, Inc. * @@ -31,6 +33,8 @@ struct SPGradientVectorSelector { guint idlabel : 1; + bool swatched; + SPDocument *doc; SPGradient *gr; @@ -40,6 +44,9 @@ struct SPGradientVectorSelector { sigc::connection gradient_release_connection; sigc::connection defs_release_connection; sigc::connection defs_modified_connection; + + + void setSwatched(); }; struct SPGradientVectorSelectorClass { diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 59312b0d2..5898563a5 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -92,6 +92,40 @@ static void sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget static GtkVBoxClass *parent_class; static guint psel_signals[LAST_SIGNAL] = {0}; +#ifdef SP_PS_VERBOSE +static gchar const* modeStrings[] = { + "MODE_EMPTY", + "MODE_MULTIPLE", + "MODE_NONE", + "MODE_COLOR_RGB", + "MODE_COLOR_CMYK", + "MODE_GRADIENT_LINEAR", + "MODE_GRADIENT_RADIAL", + "MODE_PATTERN", + "MODE_SWATCH", + "MODE_UNSET", + ".", + ".", + ".", +}; +#endif + +static bool isPaintModeGradient( SPPaintSelectorMode mode ) +{ + bool isGrad = (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || + (mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL) || + (mode == SP_PAINT_SELECTOR_MODE_SWATCH); + + return isGrad; +} + +static SPGradientSelector *getGradientFromData(SPPaintSelector *psel) +{ + gchar const* key = (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH) ? "swatch-selector" : "gradient-selector"; + SPGradientSelector *grad = reinterpret_cast(gtk_object_get_data(GTK_OBJECT(psel->selector), key)); + return grad; +} + GType sp_paint_selector_get_type(void) { static GtkType type = 0; @@ -330,7 +364,7 @@ sp_paint_selector_set_mode(SPPaintSelector *psel, SPPaintSelectorMode mode) if (psel->mode != mode) { psel->update = TRUE; #ifdef SP_PS_VERBOSE - g_print("Mode change %d -> %d\n", psel->mode, mode); + g_print("Mode change %d -> %d %s -> %s\n", psel->mode, mode, modeStrings[psel->mode], modeStrings[mode]); #endif switch (mode) { case SP_PAINT_SELECTOR_MODE_EMPTY: @@ -407,24 +441,27 @@ sp_paint_selector_set_color_alpha(SPPaintSelector *psel, SPColor const *color, f csel->base->setColorAlpha( *color, alpha ); } -void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPPaintServer */*server*/ ) +void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector ) { #ifdef SP_PS_VERBOSE g_print("PaintSelector set SWATCH\n"); #endif sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_SWATCH); + + SPGradientSelector *gsel = static_cast(gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector")); + + gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } void sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector) { - SPGradientSelector *gsel; #ifdef SP_PS_VERBOSE g_print("PaintSelector set GRADIENT LINEAR\n"); #endif sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR); - gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); + SPGradientSelector *gsel = getGradientFromData(psel); gsel->setMode(SPGradientSelector::MODE_LINEAR); gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); @@ -433,39 +470,34 @@ sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector) void sp_paint_selector_set_gradient_radial(SPPaintSelector *psel, SPGradient *vector) { - SPGradientSelector *gsel; #ifdef SP_PS_VERBOSE g_print("PaintSelector set GRADIENT RADIAL\n"); #endif sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL); - gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); + SPGradientSelector *gsel = getGradientFromData(psel); gsel->setMode(SPGradientSelector::MODE_RADIAL); gsel->setVector((vector) ? SP_OBJECT_DOCUMENT(vector) : 0, vector); } -void -sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread) +void sp_paint_selector_set_gradient_properties(SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread) { - SPGradientSelector *gsel; g_return_if_fail(SP_IS_PAINT_SELECTOR(psel)); - g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || - (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL)); - gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); + g_return_if_fail(isPaintModeGradient(psel->mode)); + + SPGradientSelector *gsel = getGradientFromData(psel); gsel->setUnits(units); gsel->setSpread(spread); } -void -sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread) +void sp_paint_selector_get_gradient_properties(SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread) { - SPGradientSelector *gsel; g_return_if_fail(SP_IS_PAINT_SELECTOR(psel)); - g_return_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || - (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL)); - gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); + g_return_if_fail(isPaintModeGradient(psel->mode)); + + SPGradientSelector *gsel = getGradientFromData(psel); if (units) { *units = gsel->getUnits(); } @@ -491,24 +523,23 @@ sp_paint_selector_get_color_alpha(SPPaintSelector *psel, SPColor *color, gfloat && ( *alpha <= 1.0 ) ) ); } -SPGradient * -sp_paint_selector_get_gradient_vector(SPPaintSelector *psel) +SPGradient *sp_paint_selector_get_gradient_vector(SPPaintSelector *psel) { - SPGradientSelector *gsel; - - g_return_val_if_fail((psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR) || - (psel->mode == SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL), NULL); + SPGradient* vect = 0; - gsel = (SPGradientSelector*)gtk_object_get_data(GTK_OBJECT(psel->selector), "gradient-selector"); + if (isPaintModeGradient(psel->mode)) { + SPGradientSelector *gsel = getGradientFromData(psel); + vect = gsel->getVector(); + } - return gsel->getVector(); + return vect; } void sp_gradient_selector_attrs_to_gradient(SPGradient *gr, SPPaintSelector *psel) { - SPGradientUnits units; - SPGradientSpread spread; + SPGradientUnits units = SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX; + SPGradientSpread spread = SP_GRADIENT_SPREAD_PAD; sp_paint_selector_get_gradient_properties(psel, &units, &spread); sp_gradient_set_units(gr, units); sp_gradient_set_spread(gr, spread); @@ -1066,38 +1097,30 @@ sp_paint_selector_get_pattern(SPPaintSelector *psel) static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelectorMode mode) { if (mode == SP_PAINT_SELECTOR_MODE_SWATCH) { - sp_paint_selector_set_style_buttons(psel, psel->swatch); // TODO swatch + sp_paint_selector_set_style_buttons(psel, psel->swatch); } gtk_widget_set_sensitive(psel->style, TRUE); - GtkWidget *tbl = NULL; + GtkWidget *tbl = 0; if (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH){ /* Already have pattern menu */ - tbl = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector"); + tbl = static_cast(gtk_object_get_data(GTK_OBJECT(psel->selector), "swatch-selector")); } else { sp_paint_selector_clear_frame(psel); - - /* Create vbox */ - tbl = gtk_vbox_new(FALSE, 4); - gtk_widget_show(tbl); - - { - GtkWidget *hb = gtk_hbox_new(FALSE, 0); - GtkWidget *l = gtk_label_new(NULL); - gtk_label_set_markup(GTK_LABEL(l), _("Represents a swatch fill.")); - gtk_label_set_line_wrap(GTK_LABEL(l), true); - gtk_widget_set_size_request(l, 180, -1); - gtk_box_pack_start(GTK_BOX(hb), l, TRUE, TRUE, AUX_BETWEEN_BUTTON_GROUPS); - gtk_box_pack_start(GTK_BOX(tbl), hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS); - } - - gtk_widget_show_all(tbl); - - gtk_container_add(GTK_CONTAINER(psel->frame), tbl); - psel->selector = tbl; - gtk_object_set_data(GTK_OBJECT(psel->selector), "swatch-selector", tbl); + /* Create new gradient selector */ + GtkWidget *gsel = sp_gradient_selector_new(); + SP_GRADIENT_SELECTOR(gsel)->setMode(SPGradientSelector::MODE_SWATCH); + gtk_widget_show(gsel); + gtk_signal_connect(GTK_OBJECT(gsel), "grabbed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_grabbed), psel); + gtk_signal_connect(GTK_OBJECT(gsel), "dragged", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_dragged), psel); + gtk_signal_connect(GTK_OBJECT(gsel), "released", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_released), psel); + gtk_signal_connect(GTK_OBJECT(gsel), "changed", GTK_SIGNAL_FUNC(sp_paint_selector_gradient_changed), psel); + // Pack everything to frame + gtk_container_add(GTK_CONTAINER(psel->frame), gsel); + psel->selector = gsel; + gtk_object_set_data(GTK_OBJECT(psel->selector), "swatch-selector", gsel); gtk_frame_set_label(GTK_FRAME(psel->frame), _("Swatch fill")); } @@ -1145,7 +1168,13 @@ SPPaintSelectorMode sp_style_determine_paint_selector_mode(SPStyle *style, bool } else if ( target.isPaintserver() ) { SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style); - if (server && server->isSwatch()) { + +#ifdef SP_PS_VERBOSE + g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n")); +#endif // SP_PS_VERBOSE + + + if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { mode = SP_PAINT_SELECTOR_MODE_SWATCH; } else if (SP_IS_LINEARGRADIENT(server)) { mode = SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR; diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index 82dee4d16..2d7ac3011 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -101,7 +101,7 @@ void sp_paint_selector_set_gradient_linear (SPPaintSelector *psel, SPGradient *v void sp_paint_selector_set_gradient_radial (SPPaintSelector *psel, SPGradient *vector); -void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPPaintServer *server ); +void sp_paint_selector_set_swatch(SPPaintSelector *psel, SPGradient *vector ); void sp_paint_selector_set_gradient_properties (SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread); void sp_paint_selector_get_gradient_properties (SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 51e70807c..a981934dd 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -205,9 +205,10 @@ sp_stroke_style_paint_update (SPWidget *spw) SPPaintServer *server = SP_STYLE_STROKE_SERVER (query); if (server && server->isSwatch()) { - sp_paint_selector_set_swatch( psel, server ); + SPGradient *vector = SP_GRADIENT(server)->getVector(); + sp_paint_selector_set_swatch( psel, vector ); } else if (SP_IS_LINEARGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_paint_selector_set_gradient_linear (psel, vector); SPLinearGradient *lg = SP_LINEARGRADIENT (server); @@ -215,7 +216,7 @@ sp_stroke_style_paint_update (SPWidget *spw) SP_GRADIENT_UNITS (lg), SP_GRADIENT_SPREAD (lg)); } else if (SP_IS_RADIALGRADIENT (server)) { - SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); + SPGradient *vector = SP_GRADIENT(server)->getVector(); sp_paint_selector_set_gradient_radial (psel, vector); SPRadialGradient *rg = SP_RADIALGRADIENT (server);