Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-gradient.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_SP_GRADIENT_H
3#define SEEN_SP_GRADIENT_H
4/*
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
8 * Jon A. Cruz <jon@joncruz.org>
9 *
10 * Copyrigt (C) 2010 Jon A. Cruz
11 * Copyright (C) 2007 Johan Engelen
12 * Copyright (C) 1999-2002 Lauris Kaplinski
13 * Copyright (C) 2000-2001 Ximian, Inc.
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#include <2geom/affine.h>
19#include <cstddef>
20#include <glibmm/ustring.h>
21#include <sigc++/connection.h>
22#include <vector>
23
24#include "sp-paint-server.h"
25#include "sp-gradient-spread.h"
26#include "sp-gradient-units.h"
27#include "sp-gradient-vector.h"
28#include "sp-mesh-array.h"
29
31class SPStop;
32
39
45
63
64namespace Inkscape {
65
70
74std::vector<PaintTarget> const &allPaintTargets();
75
76} // namespace Inkscape
77
85 : public SPPaintServer
86{
87public:
88 SPGradient();
89 ~SPGradient() override;
90 int tag() const override { return tag_of<decltype(*this)>; }
91
92private:
95 unsigned int units_set : 1;
96public:
97
100 unsigned int gradientTransform_set : 1;
101
102private:
105 unsigned int spread_set : 1;
106
108 unsigned int has_stops : 1;
109
111 unsigned int has_patches : 1;
112
114 bool _pinned = false;
115
116public:
119
121 unsigned int state;
122
127 SPGradientVector const &getGradientVector() const;
128
129 sigc::connection modified_connection;
130
131 bool hasStops() const;
132
134 int getStopCount() const;
135
136 bool isEquivalent(SPGradient *b);
137 bool isAligned(SPGradient *b);
138
143 SPMeshNodeArray array_smoothed; // Smoothed version of array
144
145 bool hasPatches() const;
146
147
149 bool isUnitsSet() const;
152
153
154 bool isSpreadSet() const;
156
164 SPGradient *getVector(bool force_private = false);
165 SPGradient const *getVector(bool force_private = false) const
166 {
167 return const_cast<SPGradient *>(this)->getVector(force_private);
168 }
169
174 SPGradient *getArray(bool force_private = false);
175
176 //static GType getType();
177
179 void ensureVector();
180
182 void ensureArray();
183
188
191
192 void setSwatch(bool swatch = true);
193 void setPinned(bool pinned = true);
194 bool isPinned() const { return _pinned; }
195
196 bool isSolid() const;
197
198 static void gradientRefModified(SPObject *href, unsigned int flags, SPGradient *gradient);
199 static void gradientRefChanged(SPObject *old_ref, SPObject *ref, SPGradient *gr);
200
201 /* Gradient repr methods */
202 void repr_write_vector();
203 void repr_clear_vector();
204
206
209 Geom::Rect const &bbox) const;
211 Geom::Rect const &bbox) const;
212 void set_gs2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox,
213 Geom::Affine const &gs2d);
214
216
217private:
218 bool invalidateVector();
219 bool invalidateArray();
220 void rebuildVector() const;
221 void rebuildArray();
222
223protected:
225 void release() override;
226 void modified(unsigned int flags) override;
227 Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override;
228
230 void remove_child(Inkscape::XML::Node *child) override;
231
232 void set(SPAttr key, char const *value) override;
233};
234
235void
237 SPGradient *gr,
238 Geom::OptRect const &bbox,
239 double opacity);
240
241#endif // SEEN_SP_GRADIENT_H
242
243/*
244 Local Variables:
245 mode:c++
246 c-file-style:"stroustrup"
247 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
248 indent-tabs-mode:nil
249 fill-column:99
250 End:
251*/
252// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 affine transformation matrix.
SPAttr
Definition attributes.h:27
constexpr int tag_of
Convenience function to retrieve the tag (class id) of a given type.
Definition cast.h:26
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Axis aligned, non-empty rectangle.
Definition rect.h:92
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:101
Gradient.
Definition sp-gradient.h:86
SPGradient const * getVector(bool force_private=false) const
SPGradient * getArray(bool force_private=false)
Returns private mesh of given gradient (the gradient at the end of the href chain which has patches),...
unsigned int spread_set
void setPinned(bool pinned=true)
unsigned int state
State in Inkscape gradient system.
void ensureArray()
Forces array (mesh) to be built, if not present (i.e.
void build(SPDocument *document, Inkscape::XML::Node *repr) override
Virtual build: set gradient attributes from its associated repr.
void set_gs2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox, Geom::Affine const &gs2d)
~SPGradient() override
SPStop * getFirstStop()
SPGradientVector vector
Linear and Radial Gradients.
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Write gradient attributes to repr.
void remove_child(Inkscape::XML::Node *child) override
Callback for remove_child event.
Geom::Affine gradientTransform
gradientTransform attribute
Definition sp-gradient.h:99
SPGradientUnits fetchUnits()
Returns the effective units of given gradient (climbing up the refs chain if needed).
sigc::connection modified_connection
SPGradientSpread getSpread() const
bool invalidateVector()
Return true if change made.
unsigned int has_stops
Gradient stops.
void release() override
Virtual release of SPGradient members before destruction.
unsigned int units_set
Definition sp-gradient.h:95
void child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) override
Callback for child_added event.
static void gradientRefChanged(SPObject *old_ref, SPObject *ref, SPGradient *gr)
Gets called when the gradient is (re)attached to another gradient.
SPGradientSpread fetchSpread() const
Returns the effective spread of given gradient (climbing up the refs chain if needed).
bool hasStops() const
void modified(unsigned int flags) override
Callback for modified event.
bool isSpreadSet() const
SPGradientReference * ref
Reference (href)
unsigned int gradientTransform_set
SPGradient * getVector(bool force_private=false)
Returns private vector of given gradient (the gradient at the end of the href chain which has stops),...
bool invalidateArray()
Return true if change made.
void rebuildVector() const
Creates normalized color vector.
void setSpread(SPGradientSpread spread)
Set spread property of gradient and emit modified.
cairo_pattern_t * create_preview_pattern(double width)
SPGradientUnits getUnits() const
SPGradientUnits units
gradientUnits attribute
Definition sp-gradient.h:94
void repr_clear_vector()
Clears the gradient's svg:stop children from its repr.
unsigned int has_patches
Gradient patches.
int tag() const override
Definition sp-gradient.h:90
bool isEquivalent(SPGradient *b)
return true if this gradient is "equivalent" to that gradient.
bool isPinned() const
void rebuildArray()
Creates normalized color mesh patch array.
SPMeshNodeArray array
Mesh Gradients.
bool _pinned
Pinned in swatches dialog.
Geom::OptRect getAllItemsBox() const
Return a visual bounding box that covers every item this gradient would paint added together.
bool isUnitsSet() const
All Gradients.
bool isSolid() const
SPMeshNodeArray array_smoothed
bool isAligned(SPGradient *b)
return true if this gradient is "aligned" to that gradient.
int getStopCount() const
void setUnits(SPGradientUnits units)
Set units property of gradient and emit modified.
Geom::Affine get_g2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox) const
Transforms to/from gradient position space in given environment.
SPGradientSpread spread
spreadMethod attribute
static void gradientRefModified(SPObject *href, unsigned int flags, SPGradient *gradient)
bool hasPatches() const
SPGradientVector const & getGradientVector() const
void repr_write_vector()
Writes the gradient's internal vector (whether from its own stops, or inherited from refs) into the g...
Geom::Affine get_gs2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox) const
void ensureVector()
Forces vector to be built, if not present (i.e.
void setSwatch(bool swatch=true)
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Inkscape::XML::Node * repr
Definition sp-object.h:193
SPDocument * document
Definition sp-object.h:188
Gradient stop.
Definition sp-stop.h:31
_cairo_pattern cairo_pattern_t
Helper class to stream background task notifications as a series of messages.
std::vector< PaintTarget > const & allPaintTargets()
Convenience function to access a common vector of all enum values.
static cairo_user_data_key_t key
Ocnode * child[8]
Definition quantize.cpp:33
TODO: insert short description here.
SPGradientSpread
TODO: insert short description here.
SPGradientUnits
TODO: insert short description here.
SPGradientState
Definition sp-gradient.h:40
@ SP_GRADIENT_STATE_VECTOR
Definition sp-gradient.h:42
@ SP_GRADIENT_STATE_UNKNOWN
Definition sp-gradient.h:41
@ SP_GRADIENT_STATE_PRIVATE
Definition sp-gradient.h:43
GrPointType
Definition sp-gradient.h:46
@ POINT_LG_END
Definition sp-gradient.h:48
@ POINT_RG_R2
Definition sp-gradient.h:52
@ POINT_G_INVALID
Definition sp-gradient.h:61
@ POINT_RG_MID2
Definition sp-gradient.h:55
@ POINT_MG_CORNER
Definition sp-gradient.h:56
@ POINT_RG_CENTER
Definition sp-gradient.h:50
@ POINT_MG_TENSOR
Definition sp-gradient.h:58
@ POINT_LG_BEGIN
Definition sp-gradient.h:47
@ POINT_RG_MID1
Definition sp-gradient.h:54
@ POINT_RG_R1
Definition sp-gradient.h:51
@ POINT_MG_HANDLE
Definition sp-gradient.h:57
@ POINT_LG_MID
Definition sp-gradient.h:49
@ POINT_RG_FOCUS
Definition sp-gradient.h:53
void sp_gradient_pattern_common_setup(cairo_pattern_t *cp, SPGradient *gr, Geom::OptRect const &bbox, double opacity)
SPGradientType
Definition sp-gradient.h:33
@ SP_GRADIENT_TYPE_LINEAR
Definition sp-gradient.h:35
@ SP_GRADIENT_TYPE_MESH
Definition sp-gradient.h:37
@ SP_GRADIENT_TYPE_UNKNOWN
Definition sp-gradient.h:34
@ SP_GRADIENT_TYPE_RADIAL
Definition sp-gradient.h:36
Interface for XML documents.
Definition document.h:43
The effective gradient vector, after copying stops from the referenced gradient if necessary.
double width