Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
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;
137
138// An array of mesh nodes.
140// Should be private
141public:
143 std::vector< std::vector< SPMeshNode* > > nodes;
144
145public:
146 // Draggables to nodes.
147 std::vector< SPMeshNode* > corners;
148 std::vector< SPMeshNode* > handles;
149 std::vector< SPMeshNode* > tensors;
150
151 friend class SPMeshPatchI;
152
153 SPMeshNodeArray() { built = false; mg = nullptr; };
155 SPMeshNodeArray( const SPMeshNodeArray& rhs );
157
159 bool built;
160
161 void update_node_vectors();
162
163 bool read( SPMeshGradient *mg );
164 void write( SPMeshGradient *mg );
166 void clear();
167 void print();
168
169 // Fill 'smooth' with a smoothed version by subdividing each patch.
171
172 // Get size of patch
173 unsigned patch_rows();
174 unsigned patch_columns();
175
176 SPMeshNode * node( unsigned i, unsigned j ) { return nodes[i][j]; }
177
178 // Operations on corners
179 bool adjacent_corners(unsigned i, unsigned j, SPMeshNode *n[4]);
180 unsigned side_toggle (std::vector<unsigned> const &);
181 unsigned side_arc (std::vector<unsigned> const &);
182 unsigned tensor_toggle(std::vector<unsigned> const &);
183 unsigned color_smooth (std::vector<unsigned> const &);
184 unsigned color_pick (std::vector<unsigned> const &, SPItem *);
185 unsigned insert (std::vector<unsigned> const &);
186
187 // Update other nodes in response to a node move.
188 void update_handles(unsigned corner,
189 std::vector<unsigned> const &selected_corners,
190 Geom::Point const &old_p, MeshNodeOperation op);
191
192 // Return outline path
194
195 // Transform array
196 void transform(Geom::Affine const &m);
197
198 // Transform mesh to fill box. Return true if not identity transform.
199 bool fill_box(Geom::OptRect &box);
200
201 // Find bounding box
202 // Geom::OptRect findBoundingBox();
203
204 void split_row( unsigned i, unsigned n );
205 void split_column( unsigned j, unsigned n );
206 void split_row( unsigned i, double coord );
207 void split_column( unsigned j, double coord );
208};
209
210#endif /* !SEEN_SP_MESH_ARRAY_H */
211
212/*
213 Local Variables:
214 mode:c++
215 c-file-style:"stroustrup"
216 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
217 c-basic-offset:2
218 indent-tabs-mode:nil
219 fill-column:99
220 End:
221*/
222// 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
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
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)
Geom::PathVector outline_path() const
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.
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