1 #ifndef SEEN_SP_GRADIENT_H
2 #define SEEN_SP_GRADIENT_H
4 /** \file
5 * SVG <stop> <linearGradient> and <radialGradient> implementation
6 *
7 * Authors:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
10 * Jon A. Cruz <jon@joncruz.org>
11 *
12 * Copyrigt (C) 2010 Jon A. Cruz
13 * Copyright (C) 2007 Johan Engelen
14 * Copyright (C) 1999-2002 Lauris Kaplinski
15 * Copyright (C) 2000-2001 Ximian, Inc.
16 *
17 * Released under GNU GPL, read the file 'COPYING' for more information
18 */
20 #include <gdk/gdktypes.h>
21 #include "libnr/nr-matrix.h"
22 #include "sp-paint-server.h"
23 #include "sp-gradient-spread.h"
24 #include "sp-gradient-units.h"
25 #include "sp-gradient-vector.h"
27 #include <sigc++/connection.h>
29 struct SPGradientReference;
32 #define SP_TYPE_GRADIENT (SPGradient::getType())
33 #define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient))
34 #define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass))
35 #define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
36 #define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
38 typedef enum {
39 SP_GRADIENT_TYPE_UNKNOWN,
40 SP_GRADIENT_TYPE_LINEAR,
41 SP_GRADIENT_TYPE_RADIAL
42 } SPGradientType;
44 typedef enum {
45 SP_GRADIENT_STATE_UNKNOWN,
46 SP_GRADIENT_STATE_VECTOR,
47 SP_GRADIENT_STATE_PRIVATE
48 } SPGradientState;
50 typedef enum {
51 POINT_LG_BEGIN =0, //start enum at 0 (for indexing into gr_knot_shapes array for example)
52 POINT_LG_END,
53 POINT_LG_MID,
54 POINT_RG_CENTER,
55 POINT_RG_R1,
56 POINT_RG_R2,
57 POINT_RG_FOCUS,
58 POINT_RG_MID1,
59 POINT_RG_MID2,
60 // insert new point types here.
62 POINT_G_INVALID
63 } GrPointType;
65 /**
66 * Gradient
67 *
68 * Implement spread, stops list
69 * \todo fixme: Implement more here (Lauris)
70 */
71 struct SPGradient : public SPPaintServer {
73 /** Reference (href) */
74 SPGradientReference *ref;
76 /** State in Inkscape gradient system */
77 guint state : 2;
79 private:
80 /** gradientUnits attribute */
81 SPGradientUnits units;
82 guint units_set : 1;
83 public:
85 /** gradientTransform attribute */
86 Geom::Matrix gradientTransform;
87 guint gradientTransform_set : 1;
89 private:
90 /** spreadMethod attribute */
91 SPGradientSpread spread;
92 guint spread_set : 1;
94 /** Gradient stops */
95 guint has_stops : 1;
96 public:
98 /** Composed vector */
99 SPGradientVector vector;
101 /** Rendered color array (4 * 1024 bytes) */
102 guchar *color;
104 sigc::connection modified_connection;
106 bool hasStops() const;
108 SPStop* getFirstStop();
109 int getStopCount() const;
112 bool isUnitsSet() const;
113 SPGradientUnits getUnits() const;
114 void setUnits(SPGradientUnits units);
117 bool isSpreadSet() const;
118 SPGradientSpread getSpread() const;
120 /**
121 * Returns private vector of given gradient (the gradient at the end of the href chain which has
122 * stops), optionally normalizing it.
123 *
124 * \pre SP_IS_GRADIENT(gradient).
125 * \pre There exists a gradient in the chain that has stops.
126 */
127 SPGradient *getVector(bool force_private = false);
129 static GType getType();
131 /** Forces vector to be built, if not present (i.e. changed) */
132 void ensureVector();
134 /** Ensures that color array is populated */
135 void ensureColors();
137 /**
138 * Set spread property of gradient and emit modified.
139 */
140 void setSpread(SPGradientSpread spread);
142 SPGradientSpread fetchSpread();
143 SPGradientUnits fetchUnits();
145 void setSwatch();
147 private:
148 bool invalidateVector();
149 void rebuildVector();
151 friend class SPGradientImpl;
152 friend class SPLGPainter;
153 friend class SPRGPainter;
154 };
156 /**
157 * The SPGradient vtable.
158 */
159 struct SPGradientClass {
160 SPPaintServerClass parent_class;
161 };
164 #include "sp-gradient-fns.h"
166 #endif // SEEN_SP_GRADIENT_H
168 /*
169 Local Variables:
170 mode:c++
171 c-file-style:"stroustrup"
172 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
173 indent-tabs-mode:nil
174 fill-column:99
175 End:
176 */
177 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :