Code

Fix change in revision 9947 to be consistent with rest of the codebase.
[inkscape.git] / src / sp-gradient.h
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 <glibmm/ustring.h>
22 #include "libnr/nr-matrix.h"
23 #include "sp-paint-server.h"
24 #include "sp-gradient-spread.h"
25 #include "sp-gradient-units.h"
26 #include "sp-gradient-vector.h"
28 #include <sigc++/connection.h>
30 struct SPGradientReference;
33 #define SP_TYPE_GRADIENT (SPGradient::getType())
34 #define SP_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_GRADIENT, SPGradient))
35 #define SP_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_GRADIENT, SPGradientClass))
36 #define SP_IS_GRADIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_GRADIENT))
37 #define SP_IS_GRADIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_GRADIENT))
39 typedef enum {
40     SP_GRADIENT_TYPE_UNKNOWN,
41     SP_GRADIENT_TYPE_LINEAR,
42     SP_GRADIENT_TYPE_RADIAL
43 } SPGradientType;
45 typedef enum {
46     SP_GRADIENT_STATE_UNKNOWN,
47     SP_GRADIENT_STATE_VECTOR,
48     SP_GRADIENT_STATE_PRIVATE
49 } SPGradientState;
51 typedef enum {
52     POINT_LG_BEGIN =0, //start enum at 0 (for indexing into gr_knot_shapes array for example)
53     POINT_LG_END,
54     POINT_LG_MID,
55     POINT_RG_CENTER,
56     POINT_RG_R1,
57     POINT_RG_R2,
58     POINT_RG_FOCUS,
59     POINT_RG_MID1,
60     POINT_RG_MID2,
61     // insert new point types here.
63     POINT_G_INVALID
64 } GrPointType;
66 /**
67  * Gradient
68  *
69  * Implement spread, stops list
70  * \todo fixme: Implement more here (Lauris)
71  */
72 struct SPGradient : public SPPaintServer {
74     /** Reference (href) */
75     SPGradientReference *ref;
77     /** State in Inkscape gradient system */
78     guint state : 2;
80 private:
81     /** gradientUnits attribute */
82     SPGradientUnits units;
83     guint units_set : 1;
84 public:
86     /** gradientTransform attribute */
87     Geom::Matrix gradientTransform;
88     guint gradientTransform_set : 1;
90 private:
91     /** spreadMethod attribute */
92     SPGradientSpread spread;
93     guint spread_set : 1;
95     /** Gradient stops */
96     guint has_stops : 1;
97 public:
99     /** Composed vector */
100     SPGradientVector vector;
102     /** Rendered color array (4 * 1024 bytes) */
103     guchar *color;
105     sigc::connection modified_connection;
107     bool hasStops() const;
109     SPStop* getFirstStop();
110     int getStopCount() const;
113     bool isUnitsSet() const;
114     SPGradientUnits getUnits() const;
115     void setUnits(SPGradientUnits units);
118     bool isSpreadSet() const;
119     SPGradientSpread getSpread() const;
121 /**
122  * Returns private vector of given gradient (the gradient at the end of the href chain which has
123  * stops), optionally normalizing it.
124  *
125  * \pre SP_IS_GRADIENT(gradient).
126  * \pre There exists a gradient in the chain that has stops.
127  */
128     SPGradient *getVector(bool force_private = false);
130     static GType getType();
132     /** Forces vector to be built, if not present (i.e. changed) */
133     void ensureVector();
135     /** Ensures that color array is populated */
136     void ensureColors();
138     /**
139      * Set spread property of gradient and emit modified.
140      */
141     void setSpread(SPGradientSpread spread);
143     SPGradientSpread fetchSpread();
144     SPGradientUnits fetchUnits();
146     void setSwatch(bool swatch = true);
148 private:
149     bool invalidateVector();
150     void rebuildVector();
152     friend class SPGradientImpl;
153     friend class SPLGPainter;
154     friend class SPRGPainter;
155 };
157 /**
158  * The SPGradient vtable.
159  */
160 struct SPGradientClass {
161     SPPaintServerClass parent_class;
162 };
165 #include "sp-gradient-fns.h"
167 #endif // SEEN_SP_GRADIENT_H
169 /*
170   Local Variables:
171   mode:c++
172   c-file-style:"stroustrup"
173   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
174   indent-tabs-mode:nil
175   fill-column:99
176   End:
177 */
178 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :