Code

New tab in Fill&Stroke dialog for swatch fills.
authorJon A. Cruz <jon@joncruz.org>
Sat, 6 Mar 2010 06:31:33 +0000 (22:31 -0800)
committerJon A. Cruz <jon@joncruz.org>
Sat, 6 Mar 2010 06:31:33 +0000 (22:31 -0800)
16 files changed:
share/icons/icons.svg
src/extension/internal/odf.cpp
src/gradient-chemistry.cpp
src/gradient-chemistry.h
src/gradient-context.h
src/gradient-drag.cpp
src/sp-gradient.cpp
src/sp-gradient.h
src/sp-paint-server.cpp
src/sp-paint-server.h
src/ui/icon-names.h
src/widgets/fill-style.cpp
src/widgets/gradient-vector.cpp
src/widgets/paint-selector.cpp
src/widgets/paint-selector.h
src/widgets/stroke-style.cpp

index dc64eb31b1e364116b980510794ae4c06774d576..f1d666787db211bf664953433c47bf925fda98bc 100644 (file)
@@ -2129,6 +2129,12 @@ http://www.inkscape.org/</dc:description>
 <path style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:0;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1" d="m 676.7274,66.00001 -3.2727,3.42857 4.0909,4.28572 4.0909,-4.28572 -3.2727,-3.42857 -1.6364,0 z m 4.9091,3.42857 4.0909,4.28572 3.2727,-3.42858 0,-1.71428 -2.4545,-2.57143 -1.6364,0 -3.2727,3.42857 z m 4.0909,4.28572 -4.0909,4.28571 4.0909,4.28572 3.2727,-3.42858 0,-1.71428 -3.2727,-3.42857 z m 0,8.57143 -1.6364,1.71428 3.2728,0 -1.6364,-1.71428 z m -4.0909,-4.28572 -4.0909,-4.28571 -4.0909,4.28571 4.0909,4.28572 4.0909,-4.28572 z m -4.0909,4.28572 -1.6364,1.71428 3.2727,0 -1.6363,-1.71428 z m -4.0909,-4.28572 -2.4546,-2.57143 0,5.14286 2.4546,-2.57143 z m 0,-8.57143 -2.4546,-2.57143 0,5.14286 2.4546,-2.57143 z" id="rect4545" />
 <rect style="color:#000000;fill:none;stroke:#000000;stroke-width:0.99999893;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;display:inline" id="rect4381" width="19.000811" height="18.99999" x="670.49939" y="65.5" />
 </g>
+<g id="paint-swatch" transform="translate(395.00061,282)" inkscape:label="#fill_swatch">
+<rect inkscape:label="#ccc" y="66" x="671" height="18" width="18" id="rect4541" style="color:#000000;fill:#99b6d4;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1.00000036;marker:none;display:inline" />
+<rect style="color:#000000;fill:none;stroke:#000000;stroke-width:0.99999893;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;display:inline" id="rect4381" width="19.000811" height="18.99999" x="670.49939" y="65.5" />
+<rect style="fill:#000000;stroke:none;marker:none;display:inline" id="rect4382" width="13.000811" height="12.99999" x="674.49939" y="69.5" />
+<rect style="fill:#ffffff;stroke:none;marker:none;display:inline" id="rect4382" width="13.000811" height="12.99999" x="673.49939" y="68.5" />
+</g>
 <g id="distribute-graph" transform="matrix(0.173978,0,0,0.208504,867.70076,70.054562)" inkscape:label="#graph_layout">
 <g transform="matrix(4.416533,0,0,3.725389,-3265.91,88.05639)" id="g3559" />
 <path id="path3569" d="M 1003.929,599.4599 980.8144,612.551" style="fill:none;stroke:#000000;stroke-width:4.125;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" sodipodi:nodetypes="cc" />
index 46e0361ce5740941dc444a00dfa0f66fe675ad8d..3537be4504646f29236e8d0f7578112a798a0273 100644 (file)
@@ -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);
index 59a22756e9ea38ebd4f0b6cb0e365de47a3599c2..04eaeb08de582814f09e125eb61830e6de867117 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_GRADIENT_CHEMISTRY_C__
-
 /*
  * Various utility methods for gradients
  *
@@ -7,7 +5,9 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   bulia byak
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
+ * 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<SPGradient*>(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<SPGradient*>(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");
             }
index dfc16ec32fb02b8004e5435704ba5862d4480582..c6089a658b0e9bf9c2f04e99379c4a11d3218752 100644 (file)
@@ -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 <lauris@kaplinski.com>
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
+ * 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:
index f4d8c572a66e70ad848906b09909fee28a1a2386..6f8a804ae3fe757236053769159e58475279c89b 100644 (file)
@@ -7,9 +7,10 @@
  * Authors:
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org.
  *
  * Copyright (C) 2007 Johan Engelen
- * Copyright (C) 2005 Authors
+ * Copyright (C) 2005,2010 Authors
  *
  * Released under GNU GPL
  */
@@ -29,13 +30,13 @@ class SPGradientContextClass;
 struct SPGradientContext : public SPEventContext {
 
     Geom::Point origin;
-        
+
     bool cursor_addnode;
-    
+
     bool node_added;
 
     Geom::Point mousepoint_doc; // stores mousepoint when over_line in doc coords
-        
+
     Inkscape::MessageContext *_message_context;
 
     sigc::connection *selcon;
index 246573e3f3fc0d05de413632b0f68b5c257404a6..f96775360f0ea80ae9edfa31594c63a2e3e30798 100644 (file)
@@ -6,9 +6,10 @@
  * Authors:
  *   bulia byak <buliabyak@users.sf.net>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * 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;
index 3fd120fb3d0b492c82fd086fc46f588f9361546a..fb16e9e5a495f44e3c5625b6ffa9cb34a58d4612 100644 (file)
@@ -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<SPGradient*>(this)->getFirstStop(); stop && sp_next_stop(stop); stop = sp_next_stop(stop)) {
+        count++;
+    }
+
+    return count;
+}
 
 /**
  * Write gradient attributes to repr.
index 947cc49ccf727fc196d77eabf85f8368a6634d58..0451092345c54cf75ebed78cb4293ea3870f0537 100644 (file)
@@ -91,7 +91,8 @@ struct SPGradient : public SPPaintServer {
     sigc::connection modified_connection;
 
 
-    bool isSolid() const;
+    SPStop* getFirstStop();
+    int getStopCount() const;
 };
 
 /**
index b85b0f279ccca975c0566f27c2d52d66f6429a63..805aafaeaf98b4f815b0504ec52d41044442ea0c 100644 (file)
@@ -1,20 +1,25 @@
-#define __SP_PAINT_SERVER_C__
-
 /*
  * Base class for gradients and patterns
  *
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * 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 <libnr/nr-pixblock-pattern.h>
+#include <string.h>
+#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:
index 998f1556bf9d29f17df364850a2970121d061def..a76daf4d14643695fc990c7d8284a0dc14c9cf95 100644 (file)
@@ -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 <lauris@kaplinski.com>
+ *   Jon A. Cruz <jon@joncruz.org>
  *
  * 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<SPPaintServer *>(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 :
index 76e76ea34aba168665baad11fbd36e89cf041ee4..d36d4a41a029f9412e99f2114d515e7117ae2f3e 100644 (file)
     "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 \
index 5e9d30bcdbe6cd651eb6f3aecde17cac628f1c2c..0b08f36b57f8bb7b95baea562d006b41dfe2f6ac 100644 (file)
@@ -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;
index 0a53cfb3e92f7b869a17c1142feb13a9904fc571..8ffacb9f55498cca663a5bb1628bcefe3e4c7da5 100644 (file)
@@ -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"));
index a101b9eeb32bb159671d8d8fa03d1ec04719975e..b91f241058f182720404cd678bf3363c865ef7fa 100644 (file)
@@ -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 <buliabyak@users.sf.net>
  *   John Cliff <simarilius@yahoo.com>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *
+ * 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;
index de8bbf46a950bf38bdc38a851ce73a817c8b1fab..82dee4d16ff45b07e7b4df6a3fb2fac5fdd23262 100644 (file)
@@ -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 <jon@joncruz.org>
+ *
  * Copyright (C) Lauris 2002
+ * Copyright (C) 2010 Authors
  *
  */
 
 #include <glib.h>
 #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 <libnr/nr-forward.h>
 
 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 :
index f502f87d30056c941514065ccc6eb21c6d700124..51e70807c3055070ece8d12ad02894277f49e475 100644 (file)
@@ -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 ();