From: Jon A. Cruz Date: Sat, 6 Mar 2010 06:31:33 +0000 (-0800) Subject: New tab in Fill&Stroke dialog for swatch fills. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ea4c3217d91f40557abd8519207aea1ad5ff1e68;p=inkscape.git New tab in Fill&Stroke dialog for swatch fills. --- diff --git a/share/icons/icons.svg b/share/icons/icons.svg index dc64eb31b..f1d666787 100644 --- a/share/icons/icons.svg +++ b/share/icons/icons.svg @@ -2129,6 +2129,12 @@ http://www.inkscape.org/ + + + + + + diff --git a/src/extension/internal/odf.cpp b/src/extension/internal/odf.cpp index 46e0361ce..3537be450 100644 --- a/src/extension/internal/odf.cpp +++ b/src/extension/internal/odf.cpp @@ -1660,7 +1660,7 @@ bool OdfOutput::processGradient(Writer &outs, SPItem *item, GradientInfo gi; SPGradient *grvec = sp_gradient_get_vector(gradient, FALSE); - for (SPStop *stop = sp_first_stop(grvec) ; + for (SPStop *stop = grvec->getFirstStop() ; stop ; stop = sp_next_stop(stop)) { unsigned long rgba = sp_stop_get_rgba32(stop); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 59a22756e..04eaeb08d 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1,5 +1,3 @@ -#define __SP_GRADIENT_CHEMISTRY_C__ - /* * Various utility methods for gradients * @@ -7,7 +5,9 @@ * Lauris Kaplinski * bulia byak * Johan Engelen + * Jon A. Cruz * + * Copyright (C) 2010 Authors * Copyright (C) 2007 Johan Engelen * Copyright (C) 2001-2005 authors * Copyright (C) 2001 Ximian, Inc. @@ -482,18 +482,6 @@ sp_item_gradient (SPItem *item, bool fill_or_stroke) return gradient; } - -SPStop* -sp_first_stop(SPGradient *gradient) -{ - for (SPObject *ochild = sp_object_first_child(gradient); ochild != NULL; ochild = SP_OBJECT_NEXT(ochild)) { - if (SP_IS_STOP (ochild)) { - return SP_STOP(ochild); - } - } - return NULL; -} - SPStop* sp_prev_stop(SPStop *stop, SPGradient *gradient) { @@ -525,44 +513,17 @@ sp_next_stop(SPStop *stop) SPStop* sp_last_stop(SPGradient *gradient) { - for (SPStop *stop = sp_first_stop (gradient); stop != NULL; stop = sp_next_stop (stop)) { + for (SPStop *stop = gradient->getFirstStop(); stop != NULL; stop = sp_next_stop (stop)) { if (sp_next_stop (stop) == NULL) return stop; } return NULL; } -guint sp_number_of_stops(SPGradient const *gradient) -{ - guint n = 0; - for (SPStop *stop = sp_first_stop(const_cast(gradient)); stop; stop = sp_next_stop(stop)) { - if ( sp_next_stop(stop) ) { - n++; - } else { - break; - } - } - return n; -} - -guint sp_number_of_stops_before_stop(SPGradient const *gradient, SPStop *target) -{ - guint n = 0; - for (SPStop *stop = sp_first_stop(const_cast(gradient)); stop; stop = sp_next_stop(stop)) { - if (stop != target) { - n++; - } else { - break; - } - } - return n; -} - - SPStop* sp_get_stop_i(SPGradient *gradient, guint stop_i) { - SPStop *stop = sp_first_stop (gradient); + SPStop *stop = gradient->getFirstStop(); // if this is valid but weird gradient without an offset-zero stop element, // inkscape has created a handle for the start of gradient anyway, @@ -627,7 +588,7 @@ sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool case POINT_RG_CENTER: case POINT_RG_FOCUS: { - GtkWidget *dialog = sp_gradient_vector_editor_new (vector, sp_first_stop (vector)); + GtkWidget *dialog = sp_gradient_vector_editor_new (vector, vector->getFirstStop()); gtk_widget_show (dialog); } break; @@ -672,7 +633,7 @@ sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint point_i case POINT_RG_CENTER: case POINT_RG_FOCUS: { - SPStop *first = sp_first_stop (vector); + SPStop *first = vector->getFirstStop(); if (first) { return sp_stop_get_rgba32(first); } @@ -730,7 +691,7 @@ sp_item_gradient_stop_set_style (SPItem *item, guint point_type, guint point_i, case POINT_RG_CENTER: case POINT_RG_FOCUS: { - SPStop *first = sp_first_stop (vector); + SPStop *first = vector->getFirstStop(); if (first) { sp_repr_css_change (SP_OBJECT_REPR (first), stop, "style"); } diff --git a/src/gradient-chemistry.h b/src/gradient-chemistry.h index dfc16ec32..c6089a658 100644 --- a/src/gradient-chemistry.h +++ b/src/gradient-chemistry.h @@ -1,5 +1,5 @@ -#ifndef __SP_GRADIENT_CHEMISTRY_H__ -#define __SP_GRADIENT_CHEMISTRY_H__ +#ifndef SEEN_SP_GRADIENT_CHEMISTRY_H +#define SEEN_SP_GRADIENT_CHEMISTRY_H /* * Various utility methods for gradients @@ -8,7 +8,9 @@ * Lauris Kaplinski * bulia byak * Johan Engelen + * Jon A. Cruz * + * Copyright (C) 2010 Authors * Copyright (C) 2007 Johan Engelen * Copyright (C) 2001-2002 Lauris Kaplinski * Copyright (C) 2001 Ximian, Inc. @@ -54,7 +56,6 @@ SPGradient *sp_gradient_fork_vector_if_necessary (SPGradient *gr); SPGradient *sp_gradient_get_forked_vector_if_necessary(SPGradient *gradient, bool force_vector); -SPStop* sp_first_stop(SPGradient *gradient); SPStop* sp_last_stop(SPGradient *gradient); SPStop* sp_prev_stop(SPStop *stop, SPGradient *gradient); SPStop* sp_next_stop(SPStop *stop); @@ -80,7 +81,7 @@ guint32 sp_item_gradient_stop_query_style (SPItem *item, guint point_type, guint void sp_item_gradient_edit_stop (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke); void sp_item_gradient_reverse_vector (SPItem *item, bool fill_or_stroke); -#endif +#endif // SEEN_SP_GRADIENT_CHEMISTRY_H /* Local Variables: diff --git a/src/gradient-context.h b/src/gradient-context.h index f4d8c572a..6f8a804ae 100644 --- a/src/gradient-context.h +++ b/src/gradient-context.h @@ -7,9 +7,10 @@ * Authors: * bulia byak * Johan Engelen + * Jon A. Cruz * Johan Engelen + * Jon A. Cruz * * Copyright (C) 2007 Johan Engelen - * Copyright (C) 2005 Authors + * Copyright (C) 2005,2010 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -332,7 +333,7 @@ GrDrag::addStopNearPoint (SPItem *item, Geom::Point mouse_p, double tolerance) if (addknot) { SPGradient *vector = sp_gradient_get_forked_vector_if_necessary (gradient, false); - SPStop* prev_stop = sp_first_stop(vector); + SPStop* prev_stop = vector->getFirstStop(); SPStop* next_stop = sp_next_stop(prev_stop); guint i = 1; while ( (next_stop) && (next_stop->offset < offset) ) { @@ -910,7 +911,7 @@ gr_knot_clicked_handler(SPKnot */*knot*/, guint state, gpointer data) switch (draggable->point_type) { // if we delete first or last stop, move the next/previous to the edge case POINT_LG_BEGIN: case POINT_RG_CENTER: - stop = sp_first_stop(gradient); + stop = gradient->getFirstStop(); { SPStop *next = sp_next_stop (stop); if (next) { @@ -1955,7 +1956,7 @@ GrDrag::deleteSelected (bool just_one) { SPStop *stop = NULL; if ( (draggable->point_type == POINT_LG_BEGIN) || (draggable->point_type == POINT_RG_CENTER) ) { - stop = sp_first_stop(vector); + stop = vector->getFirstStop(); } else { stop = sp_last_stop(vector); } @@ -2016,7 +2017,7 @@ GrDrag::deleteSelected (bool just_one) SPLinearGradient *lg = SP_LINEARGRADIENT(stopinfo->gradient); Geom::Point oldbegin = Geom::Point (lg->x1.computed, lg->y1.computed); Geom::Point end = Geom::Point (lg->x2.computed, lg->y2.computed); - SPStop *stop = sp_first_stop(stopinfo->vector); + SPStop *stop = stopinfo->vector->getFirstStop(); gdouble offset = stop->offset; Geom::Point newbegin = oldbegin + offset * (end - oldbegin); lg->x1.computed = newbegin[Geom::X]; @@ -2058,7 +2059,7 @@ GrDrag::deleteSelected (bool just_one) sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1); // iterate through midstops to set new offset values such that they won't move on canvas. - SPStop *stop = sp_first_stop(stopinfo->vector); + SPStop *stop = stopinfo->vector->getFirstStop(); stop = sp_next_stop(stop); while ( stop != laststop ) { stop->offset = stop->offset / offset; @@ -2094,7 +2095,7 @@ GrDrag::deleteSelected (bool just_one) sp_repr_set_css_double (SP_OBJECT_REPR (laststop), "offset", 1); // iterate through midstops to set new offset values such that they won't move on canvas. - SPStop *stop = sp_first_stop(stopinfo->vector); + SPStop *stop = stopinfo->vector->getFirstStop(); stop = sp_next_stop(stop); while ( stop != laststop ) { stop->offset = stop->offset / offset; diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 3fd120fb3..fb16e9e5a 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -638,19 +638,27 @@ sp_gradient_modified(SPObject *object, guint flags) } } - -bool SPGradient::isSolid() const +SPStop* SPGradient::getFirstStop() { - bool solid = false; - if ( SP_GRADIENT_HAS_STOPS(this) && (sp_number_of_stops(this) == 0) ) { - gchar const * attr = repr->attribute("osb:paint"); - if (attr && !strcmp(attr, "solid")) { - solid = true; + SPStop* first = 0; + for (SPObject *ochild = sp_object_first_child(this); ochild && !first; ochild = SP_OBJECT_NEXT(ochild)) { + if (SP_IS_STOP(ochild)) { + first = SP_STOP(ochild); } } - return solid; + return first; } +int SPGradient::getStopCount() const +{ + int count = 0; + + for (SPStop *stop = const_cast(this)->getFirstStop(); stop && sp_next_stop(stop); stop = sp_next_stop(stop)) { + count++; + } + + return count; +} /** * Write gradient attributes to repr. diff --git a/src/sp-gradient.h b/src/sp-gradient.h index 947cc49cc..045109234 100644 --- a/src/sp-gradient.h +++ b/src/sp-gradient.h @@ -91,7 +91,8 @@ struct SPGradient : public SPPaintServer { sigc::connection modified_connection; - bool isSolid() const; + SPStop* getFirstStop(); + int getStopCount() const; }; /** diff --git a/src/sp-paint-server.cpp b/src/sp-paint-server.cpp index b85b0f279..805aafaea 100644 --- a/src/sp-paint-server.cpp +++ b/src/sp-paint-server.cpp @@ -1,20 +1,25 @@ -#define __SP_PAINT_SERVER_C__ - /* * Base class for gradients and patterns * * Author: * Lauris Kaplinski + * Jon A. Cruz * * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2010 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include +#include +#include "libnr/nr-pixblock-pattern.h" #include "sp-paint-server.h" +#include "sp-gradient.h" +#include "xml/node.h" + static void sp_paint_server_class_init(SPPaintServerClass *psc); static void sp_paint_server_init(SPPaintServer *ps); @@ -31,15 +36,15 @@ GType sp_paint_server_get_type (void) if (!type) { GTypeInfo info = { sizeof(SPPaintServerClass), - NULL, /* base_init */ - NULL, /* base_finalize */ + NULL, /* base_init */ + NULL, /* base_finalize */ (GClassInitFunc) sp_paint_server_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ + NULL, /* class_finalize */ + NULL, /* class_data */ sizeof(SPPaintServer), - 16, /* n_preallocs */ + 16, /* n_preallocs */ (GInstanceInitFunc) sp_paint_server_init, - NULL, /* value_table */ + NULL, /* value_table */ }; type = g_type_register_static(SP_TYPE_OBJECT, "SPPaintServer", &info, (GTypeFlags) 0); } @@ -150,6 +155,29 @@ static void sp_painter_stale_fill(SPPainter */*painter*/, NRPixBlock *pb) nr_pixblock_render_gray_noise(pb, NULL); } +bool SPPaintServer::isSwatch() const +{ + // Temporary for now. Later expand to more + return isSolid(); +} + +bool SPPaintServer::isSolid() const +{ + bool solid = false; + if (SP_IS_GRADIENT(this)) { + SPGradient *grad = SP_GRADIENT(this); + if ( SP_GRADIENT_HAS_STOPS(grad) && (grad->getStopCount() == 0) ) { + gchar const * attr = repr->attribute("osb:paint"); + if (attr && !strcmp(attr, "solid")) { + solid = true; + } + } + } + return solid; +} + + + /* Local Variables: diff --git a/src/sp-paint-server.h b/src/sp-paint-server.h index 998f1556b..a76daf4d1 100644 --- a/src/sp-paint-server.h +++ b/src/sp-paint-server.h @@ -1,14 +1,16 @@ -#ifndef __SP_PAINT_SERVER_H__ -#define __SP_PAINT_SERVER_H__ +#ifndef SEEN_SP_PAINT_SERVER_H +#define SEEN_SP_PAINT_SERVER_H /* * Base class for gradients and patterns * * Author: * Lauris Kaplinski + * Jon A. Cruz * * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2010 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -26,32 +28,35 @@ class SPPainter; #define SP_IS_PAINT_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_PAINT_SERVER)) typedef enum { - SP_PAINTER_IND, - SP_PAINTER_DEP + SP_PAINTER_IND, + SP_PAINTER_DEP } SPPainterType; typedef void (* SPPainterFillFunc) (SPPainter *painter, NRPixBlock *pb); /* fixme: I do not like that class thingie (Lauris) */ struct SPPainter { - SPPainter *next; - SPPaintServer *server; - GType server_type; - SPPainterType type; - SPPainterFillFunc fill; + SPPainter *next; + SPPaintServer *server; + GType server_type; + SPPainterType type; + SPPainterFillFunc fill; }; struct SPPaintServer : public SPObject { - /* List of paints */ - SPPainter *painters; + /** List of paints */ + SPPainter *painters; + + bool isSwatch() const; + bool isSolid() const; }; struct SPPaintServerClass { - SPObjectClass sp_object_class; - /* Get SPPaint instance */ - SPPainter * (* painter_new) (SPPaintServer *ps, Geom::Matrix const &full_transform, Geom::Matrix const &parent_transform, const NRRect *bbox); - /* Free SPPaint instance */ - void (* painter_free) (SPPaintServer *ps, SPPainter *painter); + SPObjectClass sp_object_class; + /** Get SPPaint instance. */ + SPPainter * (* painter_new) (SPPaintServer *ps, Geom::Matrix const &full_transform, Geom::Matrix const &parent_transform, const NRRect *bbox); + /** Free SPPaint instance. */ + void (* painter_free) (SPPaintServer *ps, SPPainter *painter); }; GType sp_paint_server_get_type (void); @@ -62,15 +67,25 @@ SPPainter *sp_painter_free (SPPainter *painter); class SPPaintServerReference : public Inkscape::URIReference { public: - SPPaintServerReference (SPObject *obj) : URIReference(obj) {} - SPPaintServerReference (SPDocument *doc) : URIReference(doc) {} - SPPaintServer *getObject() const { - return (SPPaintServer *)URIReference::getObject(); - } + SPPaintServerReference (SPObject *obj) : URIReference(obj) {} + SPPaintServerReference (SPDocument *doc) : URIReference(doc) {} + SPPaintServer *getObject() const { + return static_cast(URIReference::getObject()); + } protected: - virtual bool _acceptObject(SPObject *obj) const { - return SP_IS_PAINT_SERVER (obj); - } + virtual bool _acceptObject(SPObject *obj) const { + return SP_IS_PAINT_SERVER (obj); + } }; -#endif +#endif // SEEN_SP_PAINT_SERVER_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/ui/icon-names.h b/src/ui/icon-names.h index 76e76ea34..d36d4a41a 100644 --- a/src/ui/icon-names.h +++ b/src/ui/icon-names.h @@ -350,6 +350,8 @@ "paint-pattern" #define INKSCAPE_ICON_PAINT_SOLID \ "paint-solid" +#define INKSCAPE_ICON_PAINT_SWATCH \ + "paint-swatch" #define INKSCAPE_ICON_PAINT_UNKNOWN \ "paint-unknown" #define INKSCAPE_ICON_PATH_BREAK_APART \ diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 5e9d30bcd..0b08f36b5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -184,7 +184,7 @@ sp_fill_style_widget_update (SPWidget *spw) // create temporary style SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FILL); + int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FILL); switch (result) { case QUERY_STYLE_NOTHING: @@ -196,12 +196,12 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_SINGLE: case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector - case QUERY_STYLE_MULTIPLE_SAME: + case QUERY_STYLE_MULTIPLE_SAME: { SPPaintSelectorMode pselmode = sp_style_determine_paint_selector_mode (query, true); sp_paint_selector_set_mode (psel, pselmode); - sp_paint_selector_set_fillrule (psel, query->fill_rule.computed == ART_WIND_RULE_NONZERO? + sp_paint_selector_set_fillrule (psel, query->fill_rule.computed == ART_WIND_RULE_NONZERO? SP_PAINT_SELECTOR_FILLRULE_NONZERO : SP_PAINT_SELECTOR_FILLRULE_EVENODD); if (query->fill.set && query->fill.isColor()) { @@ -210,7 +210,9 @@ sp_fill_style_widget_update (SPWidget *spw) SPPaintServer *server = SP_STYLE_FILL_SERVER (query); - if (SP_IS_LINEARGRADIENT (server)) { + if (server && server->isSwatch()) { + sp_paint_selector_set_swatch( psel, server ); + } else if (SP_IS_LINEARGRADIENT (server)) { SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); sp_paint_selector_set_gradient_linear (psel, vector); @@ -279,7 +281,7 @@ sp_fill_style_widget_fillrule_changed ( SPPaintSelector */*psel*/, sp_repr_css_attr_unref (css); - sp_document_done (SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done (SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, _("Change fill rule")); } @@ -305,8 +307,8 @@ sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw) } if (g_object_get_data (G_OBJECT (spw), "local")) { - // previous local flag not cleared yet; - // this means dragged events come too fast, so we better skip this one to speed up display + // previous local flag not cleared yet; + // this means dragged events come too fast, so we better skip this one to speed up display // (it's safe to do this in any case) return; } @@ -319,7 +321,7 @@ sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw) case SP_PAINT_SELECTOR_MODE_COLOR_CMYK: { sp_paint_selector_set_flat_color (psel, SP_ACTIVE_DESKTOP, "fill", "fill-opacity"); - sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, + sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, _("Set fill color")); g_object_set_data (G_OBJECT (spw), "local", GINT_TO_POINTER (TRUE)); // local change, do not update from selection break; @@ -381,7 +383,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, sp_repr_css_attr_unref (css); - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, _("Remove fill")); break; } @@ -462,7 +464,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, sp_repr_css_attr_unref (css); - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, _("Set gradient on fill")); } break; @@ -509,13 +511,17 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, } // end if - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, _("Set pattern on fill")); } // end if break; + case SP_PAINT_SELECTOR_MODE_SWATCH: + // TODO + break; + case SP_PAINT_SELECTOR_MODE_UNSET: if (items) { SPCSSAttr *css = sp_repr_css_attr_new (); @@ -524,7 +530,7 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, sp_desktop_set_style (desktop, css); sp_repr_css_attr_unref (css); - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, _("Unset fill")); } break; diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 0a53cfb3e..8ffacb9f5 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -1170,7 +1170,7 @@ sp_gradient_vector_color_changed (SPColorSelector *csel, GtkObject *object) /* Set start parameters */ /* We rely on normalized vector, i.e. stops HAVE to exist */ - g_return_if_fail (sp_first_stop(ngr) != NULL); + g_return_if_fail(ngr->getFirstStop() != NULL); GtkOptionMenu *mnu = (GtkOptionMenu *)g_object_get_data (G_OBJECT(object), "stopmenu"); SPStop *stop = SP_STOP(g_object_get_data (G_OBJECT(gtk_menu_get_active (GTK_MENU(gtk_option_menu_get_menu (mnu)))), "stop")); diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index a101b9eeb..b91f24105 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -1,13 +1,16 @@ -#define __SP_PAINT_SELECTOR_C__ - /** \file * SPPaintSelector: Generic paint selector widget. */ /* - * Copyright (C) Lauris Kaplinski 2002 + * Authors: + * Lauris Kaplinski * bulia byak * John Cliff + * Jon A. Cruz + * + * Copyright (C) Lauris Kaplinski 2002 + * Copyright (C) 2010 Authors */ #define noSP_PS_VERBOSE @@ -80,6 +83,7 @@ static void sp_paint_selector_set_mode_none(SPPaintSelector *psel); static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelectorMode mode); static void sp_paint_selector_set_mode_gradient(SPPaintSelector *psel, SPPaintSelectorMode mode); static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSelectorMode mode); +static void sp_paint_selector_set_mode_swatch(SPPaintSelector *psel, SPPaintSelectorMode mode); static void sp_paint_selector_set_mode_unset(SPPaintSelector *psel); @@ -187,6 +191,8 @@ sp_paint_selector_init(SPPaintSelector *psel) SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL, tt, _("Radial gradient")); psel->pattern = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON_PAINT_PATTERN, SP_PAINT_SELECTOR_MODE_PATTERN, tt, _("Pattern")); + psel->swatch = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON_PAINT_SWATCH, + SP_PAINT_SELECTOR_MODE_SWATCH, tt, _("Swatch")); psel->unset = sp_paint_selector_style_button_add(psel, INKSCAPE_ICON_PAINT_UNKNOWN, SP_PAINT_SELECTOR_MODE_UNSET, tt, _("Unset paint (make it undefined so it can be inherited)")); @@ -347,6 +353,9 @@ sp_paint_selector_set_mode(SPPaintSelector *psel, SPPaintSelectorMode mode) case SP_PAINT_SELECTOR_MODE_PATTERN: sp_paint_selector_set_mode_pattern(psel, mode); break; + case SP_PAINT_SELECTOR_MODE_SWATCH: + sp_paint_selector_set_mode_swatch(psel, mode); + break; case SP_PAINT_SELECTOR_MODE_UNSET: sp_paint_selector_set_mode_unset(psel); break; @@ -398,6 +407,14 @@ 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*/ ) +{ +#ifdef SP_PS_VERBOSE + g_print("PaintSelector set SWATCH\n"); +#endif + sp_paint_selector_set_mode(psel, SP_PAINT_SELECTOR_MODE_SWATCH); +} + void sp_paint_selector_set_gradient_linear(SPPaintSelector *psel, SPGradient *vector) { @@ -722,6 +739,7 @@ sp_paint_selector_set_style_buttons(SPPaintSelector *psel, GtkWidget *active) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->gradient), (active == psel->gradient)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->radial), (active == psel->radial)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->pattern), (active == psel->pattern)); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->swatch), (active == psel->swatch)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(psel->unset), (active == psel->unset)); } @@ -1039,6 +1057,49 @@ sp_paint_selector_get_pattern(SPPaintSelector *psel) return NULL; } +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 + } + + gtk_widget_set_sensitive(psel->style, TRUE); + + GtkWidget *tbl = NULL; + + if (psel->mode == SP_PAINT_SELECTOR_MODE_SWATCH){ + /* Already have pattern menu */ + tbl = (GtkWidget*)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); + + gtk_frame_set_label(GTK_FRAME(psel->frame), _("Swatch fill")); + } +#ifdef SP_PS_VERBOSE + g_print("Swatch req\n"); +#endif +} + void sp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gchar const *color_property, gchar const *opacity_property) { @@ -1068,8 +1129,7 @@ sp_paint_selector_set_flat_color(SPPaintSelector *psel, SPDesktop *desktop, gcha sp_repr_css_attr_unref(css); } -SPPaintSelectorMode -sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill) +SPPaintSelectorMode sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill) { SPPaintSelectorMode mode = SP_PAINT_SELECTOR_MODE_UNSET; SPIPaint& target = isfill ? style->fill : style->stroke; @@ -1079,7 +1139,9 @@ sp_style_determine_paint_selector_mode(SPStyle *style, bool isfill) } else if ( target.isPaintserver() ) { SPPaintServer *server = isfill? SP_STYLE_FILL_SERVER(style) : SP_STYLE_STROKE_SERVER(style); - if (SP_IS_LINEARGRADIENT(server)) { + if (server && server->isSwatch()) { + mode = SP_PAINT_SELECTOR_MODE_SWATCH; + } else if (SP_IS_LINEARGRADIENT(server)) { mode = SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR; } else if (SP_IS_RADIALGRADIENT(server)) { mode = SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL; diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index de8bbf46a..82dee4d16 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -1,16 +1,22 @@ -#ifndef __SP_PAINT_SELECTOR_H__ -#define __SP_PAINT_SELECTOR_H__ +#ifndef SEEN_SP_PAINT_SELECTOR_H +#define SEEN_SP_PAINT_SELECTOR_H /** \file * Generic paint selector widget * + * Authors: + * Lauris + * Jon A. Cruz + * * Copyright (C) Lauris 2002 + * Copyright (C) 2010 Authors * */ #include #include "sp-gradient-spread.h" #include "sp-gradient-units.h" + class SPGradient; #define SP_TYPE_PAINT_SELECTOR (sp_paint_selector_get_type ()) @@ -26,53 +32,60 @@ class SPGradient; #include typedef enum { - SP_PAINT_SELECTOR_MODE_EMPTY, - SP_PAINT_SELECTOR_MODE_MULTIPLE, - SP_PAINT_SELECTOR_MODE_NONE, - SP_PAINT_SELECTOR_MODE_COLOR_RGB, - SP_PAINT_SELECTOR_MODE_COLOR_CMYK, - SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR, + SP_PAINT_SELECTOR_MODE_EMPTY, + SP_PAINT_SELECTOR_MODE_MULTIPLE, + SP_PAINT_SELECTOR_MODE_NONE, + SP_PAINT_SELECTOR_MODE_COLOR_RGB, + SP_PAINT_SELECTOR_MODE_COLOR_CMYK, + SP_PAINT_SELECTOR_MODE_GRADIENT_LINEAR, SP_PAINT_SELECTOR_MODE_GRADIENT_RADIAL, SP_PAINT_SELECTOR_MODE_PATTERN, + SP_PAINT_SELECTOR_MODE_SWATCH, SP_PAINT_SELECTOR_MODE_UNSET } SPPaintSelectorMode; typedef enum { - SP_PAINT_SELECTOR_FILLRULE_NONZERO, - SP_PAINT_SELECTOR_FILLRULE_EVENODD + SP_PAINT_SELECTOR_FILLRULE_NONZERO, + SP_PAINT_SELECTOR_FILLRULE_EVENODD } SPPaintSelectorFillRule; /// Generic paint selector widget struct SPPaintSelector { - GtkVBox vbox; + GtkVBox vbox; - guint update : 1; + guint update : 1; - SPPaintSelectorMode mode; + SPPaintSelectorMode mode; - GtkWidget *style; - GtkWidget *none, *solid, *gradient, *radial, *pattern, *unset; + GtkWidget *style; + GtkWidget *none; + GtkWidget *solid; + GtkWidget *gradient; + GtkWidget *radial; + GtkWidget *pattern; + GtkWidget *swatch; + GtkWidget *unset; - GtkWidget *fillrulebox; - GtkWidget *evenodd, *nonzero; + GtkWidget *fillrulebox; + GtkWidget *evenodd, *nonzero; - GtkWidget *frame, *selector; + GtkWidget *frame, *selector; - SPColor color; - float alpha; + SPColor color; + float alpha; }; /// The SPPaintSelector vtable struct SPPaintSelectorClass { - GtkVBoxClass parent_class; + GtkVBoxClass parent_class; - void (* mode_changed) (SPPaintSelector *psel, SPPaintSelectorMode mode); + void (* mode_changed) (SPPaintSelector *psel, SPPaintSelectorMode mode); - void (* grabbed) (SPPaintSelector *psel); - void (* dragged) (SPPaintSelector *psel); - void (* released) (SPPaintSelector *psel); - void (* changed) (SPPaintSelector *psel); - void (* fillrule_changed) (SPPaintSelector *psel, SPPaintSelectorFillRule fillrule); + void (* grabbed) (SPPaintSelector *psel); + void (* dragged) (SPPaintSelector *psel); + void (* released) (SPPaintSelector *psel); + void (* changed) (SPPaintSelector *psel); + void (* fillrule_changed) (SPPaintSelector *psel, SPPaintSelectorFillRule fillrule); }; GtkType sp_paint_selector_get_type (void); @@ -88,6 +101,8 @@ 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_gradient_properties (SPPaintSelector *psel, SPGradientUnits units, SPGradientSpread spread); void sp_paint_selector_get_gradient_properties (SPPaintSelector *psel, SPGradientUnits *units, SPGradientSpread *spread); @@ -107,4 +122,15 @@ void sp_paint_selector_set_flat_color (SPPaintSelector *psel, SPDesktop *desktop SPPaintSelectorMode sp_style_determine_paint_selector_mode (SPStyle *style, bool isfill); -#endif +#endif // SEEN_SP_PAINT_SELECTOR_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index f502f87d3..51e70807c 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -204,7 +204,9 @@ sp_stroke_style_paint_update (SPWidget *spw) SPPaintServer *server = SP_STYLE_STROKE_SERVER (query); - if (SP_IS_LINEARGRADIENT (server)) { + if (server && server->isSwatch()) { + sp_paint_selector_set_swatch( psel, server ); + } else if (SP_IS_LINEARGRADIENT (server)) { SPGradient *vector = sp_gradient_get_vector (SP_GRADIENT (server), FALSE); sp_paint_selector_set_gradient_linear (psel, vector); @@ -443,6 +445,10 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) break; + case SP_PAINT_SELECTOR_MODE_SWATCH: + // TODO + break; + case SP_PAINT_SELECTOR_MODE_UNSET: if (items) { SPCSSAttr *css = sp_repr_css_attr_new ();