diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-10-03 20:51:05 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-10-03 20:51:05 +0000 |
| commit | 4db35e8a6706ddece9e977e5f26d4a6867ff8cbe (patch) | |
| tree | f9711f260f694d96e26bf3216fb64f2b38611b2b /src/sp-gradient.cpp | |
| parent | update to trunk (diff) | |
| parent | Merge in jabiertxof's hover information for measure tool (diff) | |
| download | inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.tar.gz inkscape-4db35e8a6706ddece9e977e5f26d4a6867ff8cbe.zip | |
Update to trunk
(bzr r15017.1.35)
Diffstat (limited to 'src/sp-gradient.cpp')
| -rw-r--r-- | src/sp-gradient.cpp | 150 |
1 files changed, 66 insertions, 84 deletions
diff --git a/src/sp-gradient.cpp b/src/sp-gradient.cpp index 854d53dc4..d3e38485b 100644 --- a/src/sp-gradient.cpp +++ b/src/sp-gradient.cpp @@ -1,6 +1,6 @@ /** \file * SPGradient, SPStop, SPLinearGradient, SPRadialGradient, - * SPMesh, SPMeshRow, SPMeshPatch + * SPMeshGradient, SPMeshRow, SPMeshPatch */ /* * Authors: @@ -22,6 +22,7 @@ */ #define noSP_GRADIENT_VERBOSE +//#define OBJECT_TRACE #include <cstring> #include <string> @@ -35,7 +36,6 @@ #include "display/cairo-utils.h" #include "svg/svg.h" -#include "svg/svg-color.h" #include "svg/css-ostringstream.h" #include "attributes.h" #include "document-private.h" @@ -44,15 +44,9 @@ #include "sp-gradient-reference.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" -#include "sp-mesh.h" +#include "sp-mesh-gradient.h" #include "sp-mesh-row.h" -#include "sp-mesh-patch.h" #include "sp-stop.h" -#include "streq.h" -#include "uri.h" -#include "xml/repr.h" -#include "style.h" -#include "display/grayscale.h" /// Has to be power of 2 Seems to be unused. //#define NCOLORS NR_GRADIENT_VECTOR_LENGTH @@ -121,7 +115,7 @@ bool SPGradient::isEquivalent(SPGradient *that) else if ( (SP_IS_LINEARGRADIENT(this) && SP_IS_LINEARGRADIENT(that)) || (SP_IS_RADIALGRADIENT(this) && SP_IS_RADIALGRADIENT(that)) || - (SP_IS_MESH(this) && SP_IS_MESH(that))) { + (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that))) { if(!this->isAligned(that))break; } else { break; } // this should never happen, some unhandled type of gradient @@ -206,9 +200,9 @@ bool SPGradient::isAligned(SPGradient *that) (sg->fy.computed != tg->fy.computed) ) { break; } } else if( sg->cx._set || sg->cy._set || sg->fx._set || sg->fy._set || sg->r._set ) { break; } // some mix of set and not set // none set? assume aligned and fall through - } else if (SP_IS_MESH(this) && SP_IS_MESH(that)) { - SPMesh *sg=SP_MESH(this); - SPMesh *tg=SP_MESH(that); + } else if (SP_IS_MESHGRADIENT(this) && SP_IS_MESHGRADIENT(that)) { + SPMeshGradient *sg=SP_MESHGRADIENT(this); + SPMeshGradient *tg=SP_MESHGRADIENT(that); if( sg->x._set != !tg->x._set) { break; } if( sg->y._set != !tg->y._set) { break; } @@ -235,7 +229,7 @@ SPGradient::SPGradient() : SPPaintServer(), units(), state(2), vector() { - this->has_patches = 0; + this->has_patches = 0; this->ref = new SPGradientReference(this); this->ref->changedSignal().connect(sigc::bind(sigc::ptr_fun(SPGradient::gradientRefChanged), this)); @@ -276,8 +270,8 @@ void SPGradient::build(SPDocument *document, Inkscape::XML::Node *repr) SPPaintServer::build(document, repr); - for ( SPObject *ochild = this->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { + for (auto& ochild: children) { + if (SP_IS_STOP(&ochild)) { this->has_stops = TRUE; break; } @@ -325,6 +319,12 @@ void SPGradient::release() */ void SPGradient::set(unsigned key, gchar const *value) { +#ifdef OBJECT_TRACE + std::stringstream temp; + temp << "SPGradient::set: " << key << " " << (value?value:"null"); + objectTrace( temp.str() ); +#endif + switch (key) { case SP_ATTR_GRADIENTUNITS: if (value) { @@ -416,6 +416,10 @@ void SPGradient::set(unsigned key, gchar const *value) SPPaintServer::set(key, value); break; } + +#ifdef OBJECT_TRACE + objectTrace( "SPGradient::set", false ); +#endif } /** @@ -481,8 +485,8 @@ void SPGradient::remove_child(Inkscape::XML::Node *child) SPPaintServer::remove_child(child); this->has_stops = FALSE; - for ( SPObject *ochild = this->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { + for (auto& ochild: children) { + if (SP_IS_STOP(&ochild)) { this->has_stops = TRUE; break; } @@ -505,29 +509,24 @@ void SPGradient::remove_child(Inkscape::XML::Node *child) */ void SPGradient::modified(guint flags) { +#ifdef OBJECT_TRACE + objectTrace( "SPGradient::modified" ); +#endif + if (flags & SP_OBJECT_CHILD_MODIFIED_FLAG) { - // CPPIFY - // This comparison has never worked (i. e. always evaluated to false), - // the right value would have been SP_TYPE_MESH - //if( this->get_type() != SP_GRADIENT_TYPE_MESH ) { -// if (!SP_IS_MESH(this)) { -// this->invalidateVector(); -// } else { -// this->invalidateArray(); -// } - this->invalidateVector(); + if (SP_IS_MESHGRADIENT(this)) { + this->invalidateArray(); + } else { + this->invalidateVector(); + } } if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - // CPPIFY - // see above - //if( this->get_type() != SP_GRADIENT_TYPE_MESH ) { -// if (!SP_IS_MESH(this)) { -// this->ensureVector(); -// } else { -// this->ensureArray(); -// } - this->ensureVector(); + if (SP_IS_MESHGRADIENT(this)) { + this->ensureArray(); + } else { + this->ensureVector(); + } } if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -536,9 +535,9 @@ void SPGradient::modified(guint flags) // FIXME: climb up the ladder of hrefs GSList *l = NULL; - for (SPObject *child = this->firstChild() ; child; child = child->getNext() ) { - sp_object_ref(child); - l = g_slist_prepend(l, child); + for (auto& child: children) { + sp_object_ref(&child); + l = g_slist_prepend(l, &child); } l = g_slist_reverse(l); @@ -553,14 +552,19 @@ void SPGradient::modified(guint flags) sp_object_unref(child); } + +#ifdef OBJECT_TRACE + objectTrace( "SPGradient::modified", false ); +#endif } SPStop* SPGradient::getFirstStop() { - SPStop* first = 0; - for (SPObject *ochild = firstChild(); ochild && !first; ochild = ochild->getNext()) { - if (SP_IS_STOP(ochild)) { - first = SP_STOP(ochild); + SPStop* first = nullptr; + for (auto& ochild: children) { + if (SP_IS_STOP(&ochild)) { + first = SP_STOP(&ochild); + break; } } return first; @@ -582,13 +586,17 @@ int SPGradient::getStopCount() const */ Inkscape::XML::Node *SPGradient::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { +#ifdef OBJECT_TRACE + objectTrace( "SPGradient::write" ); +#endif + SPPaintServer::write(xml_doc, repr, flags); if (flags & SP_OBJECT_WRITE_BUILD) { GSList *l = NULL; - for (SPObject *child = this->firstChild(); child; child = child->getNext()) { - Inkscape::XML::Node *crepr = child->updateRepr(xml_doc, NULL, flags); + for (auto& child: children) { + Inkscape::XML::Node *crepr = child.updateRepr(xml_doc, NULL, flags); if (crepr) { l = g_slist_prepend(l, crepr); @@ -652,6 +660,9 @@ Inkscape::XML::Node *SPGradient::write(Inkscape::XML::Document *xml_doc, Inkscap repr->setAttribute( "osb:paint", 0 ); } +#ifdef OBJECT_TRACE + objectTrace( "SPGradient::write", false ); +#endif return repr; } @@ -904,7 +915,7 @@ bool SPGradient::invalidateArray() if (array.built) { array.built = false; - array.clear(); + // array.clear(); ret = true; } @@ -915,8 +926,8 @@ bool SPGradient::invalidateArray() void SPGradient::rebuildVector() { gint len = 0; - for ( SPObject *child = firstChild() ; child ; child = child->getNext() ) { - if (SP_IS_STOP(child)) { + for (auto& child: children) { + if (SP_IS_STOP(&child)) { len ++; } } @@ -937,9 +948,9 @@ void SPGradient::rebuildVector() } } - for ( SPObject *child = firstChild(); child; child = child->getNext() ) { - if (SP_IS_STOP(child)) { - SPStop *stop = SP_STOP(child); + for (auto& child: children) { + if (SP_IS_STOP(&child)) { + SPStop *stop = SP_STOP(&child); SPGradientStop gstop; if (!vector.stops.empty()) { @@ -1014,39 +1025,12 @@ void SPGradient::rebuildArray() { // std::cout << "SPGradient::rebuildArray()" << std::endl; - if( !SP_IS_MESH(this) ) { + if( !SP_IS_MESHGRADIENT(this) ) { g_warning( "SPGradient::rebuildArray() called for non-mesh gradient" ); return; } - array.read( SP_MESH( this ) ); - - has_patches = false; - for ( SPObject *ro = firstChild() ; ro ; ro = ro->getNext() ) { - if (SP_IS_MESHROW(ro)) { - has_patches = true; - // std::cout << " Has Patches" << std::endl; - break; - } - } - - // MESH_FIXME: TO PROPERLY COPY - SPGradient *reffed = ref->getObject(); - if ( !hasPatches() && reffed ) { - std::cout << "SPGradient::rebuildArray(): reffed array NOT IMPLEMENTED!!!" << std::endl; - /* Copy array from referenced gradient */ - array.built = true; // Prevent infinite recursion. - reffed->ensureArray(); - // if (!reffed->array.nodes.empty()) { - // array.built = reffed->array.built; - // for( uint i = 0; i < reffed->array.nodes.size(); ++i ) { - // array.nodes[i].assign(reffed->array.nodes[i].begin(), reffed->array.nodes[i].end()); - - // // FILL ME - // } - // return; - // } - } + array.read( SP_MESHGRADIENT( this ) ); } Geom::Affine @@ -1137,9 +1121,7 @@ sp_gradient_create_preview_pattern(SPGradient *gr, double width) { cairo_pattern_t *pat = NULL; - // CPPIFY - //if( gr->get_type() != SP_GRADIENT_TYPE_MESH ) { - if (!SP_IS_MESH(gr)) { + if (!SP_IS_MESHGRADIENT(gr)) { gr->ensureVector(); pat = cairo_pattern_create_linear(0, 0, width, 0); |
