Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
sp-mesh-array.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Tavmjong Bah <tavmjong@free.fr>
5 *
6 * Copyrigt (C) 2012 Tavmjong Bah
7 *
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
11#ifndef SEEN_SP_MESH_ARRAY_H
12#define SEEN_SP_MESH_ARRAY_H
13
44#include <memory>
45#include <vector>
46#include <2geom/point.h>
47
48#include "colors/color.h"
49// For color picking
50#include "sp-item.h"
51
56
61
68
69// Is a node along an edge?
77
86
92
93class SPStop;
94
96public:
97 SPMeshNode() = default;
98
101 bool set = false;
103 unsigned draggable = -1; // index of on-screen node
104 char path_type = 'u';
105 std::optional<Inkscape::Colors::Color> color;
106 SPStop *stop = nullptr; // Stop corresponding to node.
107};
108
109// I for Internal to distinguish it from the Object class
110// This is a convenience class...
112private:
113 std::vector<std::vector< SPMeshNode* > > *nodes;
114 int row;
115 int col;
116
117public:
118 SPMeshPatchI( std::vector<std::vector< SPMeshNode* > > *n, int r, int c );
119 Geom::Point getPoint( unsigned side, unsigned point );
120 std::vector< Geom::Point > getPointsForSide( unsigned i );
121 void setPoint( unsigned side, unsigned point, Geom::Point const &p, bool set = true );
122 char getPathType( unsigned i );
123 void setPathType( unsigned, char t );
124 Geom::Point getTensorPoint( unsigned i );
125 void setTensorPoint( unsigned i, Geom::Point const &p );
126 bool tensorIsSet();
127 bool tensorIsSet( unsigned i );
128 Geom::Point coonsTensorPoint( unsigned i );
129 void updateNodes();
130 std::optional<Inkscape::Colors::Color> getColor(unsigned i);
131 void setColor(unsigned i, Inkscape::Colors::Color const &c);
132 SPStop* getStopPtr( unsigned i );
133 void setStopPtr( unsigned i, SPStop* );
134};
135
136class SPMeshGradient;
137class SPCurve;
138
139// An array of mesh nodes.
141// Should be private
142public:
144 std::vector< std::vector< SPMeshNode* > > nodes;
145
146public:
147 // Draggables to nodes.
148 std::vector< SPMeshNode* > corners;
149 std::vector< SPMeshNode* > handles;
150 std::vector< SPMeshNode* > tensors;
151
152 friend class SPMeshPatchI;
153
154 SPMeshNodeArray() { built = false; mg = nullptr; };
156 SPMeshNodeArray( const SPMeshNodeArray& rhs );
158
160 bool built;
161
162 void update_node_vectors();
163
164 bool read( SPMeshGradient *mg );
165 void write( SPMeshGradient *mg );
167 void clear();
168 void print();
169
170 // Fill 'smooth' with a smoothed version by subdividing each patch.
172
173 // Get size of patch
174 unsigned patch_rows();
175 unsigned patch_columns();
176
177 SPMeshNode * node( unsigned i, unsigned j ) { return nodes[i][j]; }
178
179 // Operations on corners
180 bool adjacent_corners(unsigned i, unsigned j, SPMeshNode *n[4]);
181 unsigned side_toggle (std::vector<unsigned> const &);
182 unsigned side_arc (std::vector<unsigned> const &);
183 unsigned tensor_toggle(std::vector<unsigned> const &);
184 unsigned color_smooth (std::vector<unsigned> const &);
185 unsigned color_pick (std::vector<unsigned> const &, SPItem *);
186 unsigned insert (std::vector<unsigned> const &);
187
188 // Update other nodes in response to a node move.
189 void update_handles(unsigned corner,
190 std::vector<unsigned> const &selected_corners,
191 Geom::Point const &old_p, MeshNodeOperation op);
192
193 // Return outline path
194 SPCurve outline_path() const;
195
196 // Transform array
197 void transform(Geom::Affine const &m);
198
199 // Transform mesh to fill box. Return true if not identity transform.
200 bool fill_box(Geom::OptRect &box);
201
202 // Find bounding box
203 // Geom::OptRect findBoundingBox();
204
205 void split_row( unsigned i, unsigned n );
206 void split_column( unsigned j, unsigned n );
207 void split_row( unsigned i, double coord );
208 void split_column( unsigned j, double coord );
209};
210
211#endif /* !SEEN_SP_MESH_ARRAY_H */
212
213/*
214 Local Variables:
215 mode:c++
216 c-file-style:"stroustrup"
217 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
218 c-basic-offset:2
219 indent-tabs-mode:nil
220 fill-column:99
221 End:
222*/
223// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Wrapper around a Geom::PathVector object.
Definition curve.h:26
Base class for visual SVG elements.
Definition sp-item.h:109
Mesh gradient.
std::vector< std::vector< SPMeshNode * > > nodes
bool fill_box(Geom::OptRect &box)
unsigned insert(std::vector< unsigned > const &)
Splits selected rows and/or columns in half (according to the path 't' parameter).
void split_row(unsigned i, unsigned n)
void split_column(unsigned j, unsigned n)
SPMeshGradient * mg
unsigned color_smooth(std::vector< unsigned > const &)
Attempts to smooth color transitions across corners.
void clear()
Clear mesh gradient.
unsigned patch_columns()
Number of patch columns.
unsigned side_arc(std::vector< unsigned > const &)
Converts generic Beziers to Beziers approximating elliptical arcs, preserving handle direction.
std::vector< SPMeshNode * > handles
bool read(SPMeshGradient *mg)
void bicubic(SPMeshNodeArray *smooth, SPMeshType type)
Fill 'smooth' with a smoothed version of the array by subdividing each patch into smaller patches.
unsigned side_toggle(std::vector< unsigned > const &)
Toggle sides between lineto and curve to if both corners selected.
unsigned tensor_toggle(std::vector< unsigned > const &)
Toggle sides between lineto and curve to if both corners selected.
void split_column(unsigned j, double coord)
std::vector< SPMeshNode * > corners
void transform(Geom::Affine const &m)
SPMeshNodeArray & operator=(const SPMeshNodeArray &rhs)
void print()
Print mesh gradient (for debugging).
void update_handles(unsigned corner, std::vector< unsigned > const &selected_corners, Geom::Point const &old_p, MeshNodeOperation op)
Moves handles in response to a corner node move.
bool adjacent_corners(unsigned i, unsigned j, SPMeshNode *n[4])
Inputs: i, j: Corner draggable indices.
void write(SPMeshGradient *mg)
Write repr using our array.
SPCurve outline_path() const
void split_row(unsigned i, double coord)
unsigned patch_rows()
Number of patch rows.
unsigned color_pick(std::vector< unsigned > const &, SPItem *)
Pick color from background for selected corners.
std::vector< SPMeshNode * > tensors
SPMeshNode * node(unsigned i, unsigned j)
SPStop * stop
Geom::Point p
SPMeshNode()=default
unsigned draggable
unsigned node_edge
NodeType node_type
std::optional< Inkscape::Colors::Color > color
void setColor(unsigned i, Inkscape::Colors::Color const &c)
Set color for corner of patch.
void setPoint(unsigned side, unsigned point, Geom::Point const &p, bool set=true)
Set point for side in proper order for patch.
char getPathType(unsigned i)
Get path type for side (stored in handle nodes).
std::vector< Geom::Point > getPointsForSide(unsigned i)
Returns vector of points for a side in proper order for a patch (clockwise order).
void setTensorPoint(unsigned i, Geom::Point const &p)
Set tensor control point for "corner" i.
bool tensorIsSet()
Return if any tensor control point is set.
void setStopPtr(unsigned i, SPStop *)
Set stop pointer for corner of patch.
bool tensorIsSet(unsigned i)
std::vector< std::vector< SPMeshNode * > > * nodes
Geom::Point getTensorPoint(unsigned i)
Return tensor control point for "corner" i.
SPStop * getStopPtr(unsigned i)
Return stop pointer for corner of patch.
Geom::Point coonsTensorPoint(unsigned i)
Find default tensor point (equivalent point to Coons Patch).
std::optional< Inkscape::Colors::Color > getColor(unsigned i)
Return color for corner of patch.
Geom::Point getPoint(unsigned side, unsigned point)
Returns point for side in proper order for patch.
void setPathType(unsigned, char t)
Set path type for side (stored in handle nodes).
void updateNodes()
Update default values for handle and tensor nodes.
Gradient stop.
Definition sp-stop.h:31
double c[8][4]
SPItem * item
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
SPMeshGeometry
@ SP_MESH_GEOMETRY_NORMAL
@ SP_MESH_GEOMETRY_CONICAL
SPMeshType
A group of classes and functions for manipulating mesh gradients.
@ SP_MESH_TYPE_BICUBIC
@ SP_MESH_TYPE_COONS
MeshNodeOperation
@ MG_NODE_NO_SCALE
@ MG_NODE_SCALE_HANDLE
@ MG_NODE_SCALE
NodeType
@ MG_NODE_TYPE_TENSOR
@ MG_NODE_TYPE_HANDLE
@ MG_NODE_TYPE_CORNER
@ MG_NODE_TYPE_UNKNOWN
MeshCornerOperation
@ MG_CORNER_COLOR_PICK
@ MG_CORNER_SIDE_TOGGLE
@ MG_CORNER_INSERT
@ MG_CORNER_COLOR_SMOOTH
@ MG_CORNER_SIDE_ARC
@ MG_CORNER_TENSOR_TOGGLE
NodeEdge
@ MG_NODE_EDGE_LEFT
@ MG_NODE_EDGE_NONE
@ MG_NODE_EDGE_RIGHT
@ MG_NODE_EDGE_TOP
@ MG_NODE_EDGE_BOTTOM
std::unique_ptr< Toolbar >(* create)()
Definition toolbars.cpp:56
Glib::RefPtr< Gtk::Adjustment > smooth