summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-06-21 11:02:15 +0000
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-06-21 13:02:08 +0000
commit5c0d72139f0baf3463c6dcb939b58f8e6cb92610 (patch)
tree85da8ab0767a9a65184617d67b931262339867f4 /src
parentMove global functions into SPPrintContext methods. (diff)
downloadinkscape-5c0d72139f0baf3463c6dcb939b58f8e6cb92610.tar.gz
inkscape-5c0d72139f0baf3463c6dcb939b58f8e6cb92610.zip
Move global functions into SPGradient methods.
Diffstat (limited to 'src')
-rw-r--r--src/gradient-chemistry.cpp2
-rw-r--r--src/object/sp-gradient.cpp59
-rw-r--r--src/object/sp-gradient.h28
-rw-r--r--src/ui/dialog/color-item.cpp2
-rw-r--r--src/ui/dialog/swatches.cpp2
-rw-r--r--src/widgets/gradient-image.cpp6
6 files changed, 48 insertions, 51 deletions
diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp
index 17c61d3c0..97c77d146 100644
--- a/src/gradient-chemistry.cpp
+++ b/src/gradient-chemistry.cpp
@@ -112,7 +112,7 @@ SPGradient *sp_gradient_ensure_vector_normalized(SPGradient *gr)
gr->ensureVector();
g_assert(gr->vector.built);
// this adds stops from gr->vector as children to gr
- sp_gradient_repr_write_vector (gr);
+ gr->repr_write_vector ();
}
/* If gr hrefs some other gradient, remove the href */
diff --git a/src/object/sp-gradient.cpp b/src/object/sp-gradient.cpp
index 0e3fa8e77..e36af38de 100644
--- a/src/object/sp-gradient.cpp
+++ b/src/object/sp-gradient.cpp
@@ -863,9 +863,9 @@ SPGradientUnits SPGradient::fetchUnits()
* Clears the gradient's svg:stop children from its repr.
*/
void
-sp_gradient_repr_clear_vector(SPGradient *gr)
+SPGradient::repr_clear_vector()
{
- Inkscape::XML::Node *repr = gr->getRepr();
+ Inkscape::XML::Node *repr = getRepr();
/* Collect stops from original repr */
std::vector<Inkscape::XML::Node *> l;
@@ -889,30 +889,27 @@ sp_gradient_repr_clear_vector(SPGradient *gr)
* inherited from refs) into the gradient repr as svg:stop elements.
*/
void
-sp_gradient_repr_write_vector(SPGradient *gr)
+SPGradient::repr_write_vector()
{
- g_return_if_fail(gr != nullptr);
- g_return_if_fail(SP_IS_GRADIENT(gr));
-
- Inkscape::XML::Document *xml_doc = gr->document->getReprDoc();
- Inkscape::XML::Node *repr = gr->getRepr();
+ Inkscape::XML::Document *xml_doc = document->getReprDoc();
+ Inkscape::XML::Node *repr = getRepr();
/* We have to be careful, as vector may be our own, so construct repr list at first */
std::vector<Inkscape::XML::Node *> l;
- for (guint i = 0; i < gr->vector.stops.size(); i++) {
+ for (guint i = 0; i < vector.stops.size(); i++) {
Inkscape::CSSOStringStream os;
Inkscape::XML::Node *child = xml_doc->createElement("svg:stop");
- sp_repr_set_css_double(child, "offset", gr->vector.stops[i].offset);
+ sp_repr_set_css_double(child, "offset", vector.stops[i].offset);
/* strictly speaking, offset an SVG <number> rather than a CSS one, but exponents make no
* sense for offset proportions. */
- os << "stop-color:" << gr->vector.stops[i].color.toString() << ";stop-opacity:" << gr->vector.stops[i].opacity;
+ os << "stop-color:" << vector.stops[i].color.toString() << ";stop-opacity:" << vector.stops[i].opacity;
child->setAttribute("style", os.str().c_str());
/* Order will be reversed here */
l.push_back(child);
}
- sp_gradient_repr_clear_vector(gr);
+ repr_clear_vector();
/* And insert new children from list */
for (auto i=l.rbegin();i!=l.rend();++i) {
@@ -1072,9 +1069,9 @@ void SPGradient::rebuildArray()
}
Geom::Affine
-sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, Geom::Rect const &bbox)
+SPGradient::get_g2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox) const
{
- if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ if (getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
return ( Geom::Scale(bbox.dimensions())
* Geom::Translate(bbox.min())
* Geom::Affine(ctm) );
@@ -1084,31 +1081,31 @@ sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, Geom::
}
Geom::Affine
-sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Affine const &ctm, Geom::Rect const &bbox)
+SPGradient::get_gs2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox) const
{
- if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
- return ( gr->gradientTransform
+ if (getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX) {
+ return ( gradientTransform
* Geom::Scale(bbox.dimensions())
* Geom::Translate(bbox.min())
* Geom::Affine(ctm) );
} else {
- return gr->gradientTransform * ctm;
+ return gradientTransform * ctm;
}
}
void
-sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Affine const &ctm,
+SPGradient::set_gs2d_matrix(Geom::Affine const &ctm,
Geom::Rect const &bbox, Geom::Affine const &gs2d)
{
- gr->gradientTransform = gs2d * ctm.inverse();
- if (gr->getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ) {
- gr->gradientTransform = ( gr->gradientTransform
+ gradientTransform = gs2d * ctm.inverse();
+ if (getUnits() == SP_GRADIENT_UNITS_OBJECTBOUNDINGBOX ) {
+ gradientTransform = ( gradientTransform
* Geom::Translate(-bbox.min())
* Geom::Scale(bbox.dimensions()).inverse() );
}
- gr->gradientTransform_set = TRUE;
+ gradientTransform_set = TRUE;
- gr->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ requestModified(SP_OBJECT_MODIFIED_FLAG);
}
@@ -1157,17 +1154,17 @@ sp_gradient_pattern_common_setup(cairo_pattern_t *cp,
}
cairo_pattern_t *
-sp_gradient_create_preview_pattern(SPGradient *gr, double width)
+SPGradient::create_preview_pattern(double width)
{
cairo_pattern_t *pat = nullptr;
- if (!SP_IS_MESHGRADIENT(gr)) {
- gr->ensureVector();
+ if (!SP_IS_MESHGRADIENT(this)) {
+ ensureVector();
pat = cairo_pattern_create_linear(0, 0, width, 0);
- for (std::vector<SPGradientStop>::iterator i = gr->vector.stops.begin();
- i != gr->vector.stops.end(); ++i)
+ for (std::vector<SPGradientStop>::iterator i = vector.stops.begin();
+ i != vector.stops.end(); ++i)
{
cairo_pattern_add_color_stop_rgba(pat, i->offset,
i->color.v.c[0], i->color.v.c[1], i->color.v.c[2], i->opacity);
@@ -1175,14 +1172,14 @@ sp_gradient_create_preview_pattern(SPGradient *gr, double width)
} else {
// For the moment, use the top row of nodes for preview.
- unsigned columns = gr->array.patch_columns();
+ unsigned columns = array.patch_columns();
double offset = 1.0/double(columns);
pat = cairo_pattern_create_linear(0, 0, width, 0);
for (unsigned i = 0; i < columns+1; ++i) {
- SPMeshNode* node = gr->array.node( 0, i*3 );
+ SPMeshNode* node = array.node( 0, i*3 );
cairo_pattern_add_color_stop_rgba(pat, i*offset,
node->color.v.c[0], node->color.v.c[1], node->color.v.c[2], node->opacity);
}
diff --git a/src/object/sp-gradient.h b/src/object/sp-gradient.h
index 5d644925a..e03937c5b 100644
--- a/src/object/sp-gradient.h
+++ b/src/object/sp-gradient.h
@@ -185,6 +185,20 @@ public:
static void gradientRefModified(SPObject *href, unsigned int flags, SPGradient *gradient);
static void gradientRefChanged(SPObject *old_ref, SPObject *ref, SPGradient *gr);
+ /* Gradient repr methods */
+ void repr_write_vector();
+ void repr_clear_vector();
+
+ cairo_pattern_t *create_preview_pattern(double width);
+
+ /** Transforms to/from gradient position space in given environment */
+ Geom::Affine get_g2d_matrix(Geom::Affine const &ctm,
+ Geom::Rect const &bbox) const;
+ Geom::Affine get_gs2d_matrix(Geom::Affine const &ctm,
+ Geom::Rect const &bbox) const;
+ void set_gs2d_matrix(Geom::Affine const &ctm, Geom::Rect const &bbox,
+ Geom::Affine const &gs2d);
+
private:
bool invalidateVector();
bool invalidateArray();
@@ -209,20 +223,6 @@ sp_gradient_pattern_common_setup(cairo_pattern_t *cp,
Geom::OptRect const &bbox,
double opacity);
-/* Gradient repr methods */
-void sp_gradient_repr_write_vector(SPGradient *gr);
-void sp_gradient_repr_clear_vector(SPGradient *gr);
-
-cairo_pattern_t *sp_gradient_create_preview_pattern(SPGradient *gradient, double width);
-
-/** Transforms to/from gradient position space in given environment */
-Geom::Affine sp_gradient_get_g2d_matrix(SPGradient const *gr, Geom::Affine const &ctm,
- Geom::Rect const &bbox);
-Geom::Affine sp_gradient_get_gs2d_matrix(SPGradient const *gr, Geom::Affine const &ctm,
- Geom::Rect const &bbox);
-void sp_gradient_set_gs2d_matrix(SPGradient *gr, Geom::Affine const &ctm, Geom::Rect const &bbox,
- Geom::Affine const &gs2d);
-
#endif // SEEN_SP_GRADIENT_H
diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp
index 61709f791..53f0d4c34 100644
--- a/src/ui/dialog/color-item.cpp
+++ b/src/ui/dialog/color-item.cpp
@@ -215,7 +215,7 @@ static void colorItemDragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpoin
GdkPixbuf* pixbuf = nullptr;
if ( item->getGradient() ){
cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
- cairo_pattern_t *gradient = sp_gradient_create_preview_pattern(item->getGradient(), width);
+ cairo_pattern_t *gradient = item->getGradient()->create_preview_pattern(width);
cairo_t *ct = cairo_create(s);
cairo_set_source(ct, gradient);
cairo_paint(ct);
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index 8dc982b82..0eef5ecc3 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -1207,7 +1207,7 @@ static void recalcSwatchContents(SPDocument* doc,
ColorItem* item = new ColorItem( 0, 0, 0, name );
cairo_pattern_t *check = ink_cairo_pattern_create_checkerboard();
- cairo_pattern_t *gradient = sp_gradient_create_preview_pattern(grad, PREVIEW_PIXBUF_WIDTH);
+ cairo_pattern_t *gradient = grad->create_preview_pattern(PREVIEW_PIXBUF_WIDTH);
cairo_set_source(ct, check);
cairo_paint(ct);
cairo_set_source(ct, gradient);
diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp
index aae0cc063..1dfc11795 100644
--- a/src/widgets/gradient-image.cpp
+++ b/src/widgets/gradient-image.cpp
@@ -113,7 +113,7 @@ static gboolean sp_gradient_image_draw(GtkWidget *widget, cairo_t *ct)
cairo_pattern_destroy(check);
if (gr) {
- cairo_pattern_t *p = sp_gradient_create_preview_pattern(gr, allocation.width);
+ cairo_pattern_t *p = gr->create_preview_pattern(allocation.width);
cairo_set_source(ct, p);
cairo_paint(ct);
cairo_pattern_destroy(p);
@@ -144,7 +144,7 @@ sp_gradient_to_pixbuf (SPGradient *gr, int width, int height)
cairo_pattern_destroy(check);
if (gr) {
- cairo_pattern_t *p = sp_gradient_create_preview_pattern(gr, width);
+ cairo_pattern_t *p = gr->create_preview_pattern(width);
cairo_set_source(ct, p);
cairo_paint(ct);
cairo_pattern_destroy(p);
@@ -171,7 +171,7 @@ sp_gradient_to_pixbuf_ref (SPGradient *gr, int width, int height)
cairo_pattern_destroy(check);
if (gr) {
- cairo_pattern_t *p = sp_gradient_create_preview_pattern(gr, width);
+ cairo_pattern_t *p = gr->create_preview_pattern(width);
cairo_set_source(ct, p);
cairo_paint(ct);
cairo_pattern_destroy(p);