diff options
| author | Tomasz Boczkowski <penginsbacon@gmail.com> | 2014-05-27 19:57:33 +0000 |
|---|---|---|
| committer | Tomasz Boczkowski <penginsbacon@gmail.com> | 2014-05-27 19:57:33 +0000 |
| commit | 22db6068f172d060429f17a489bdce59e5836c69 (patch) | |
| tree | 4640eaae672933789ec41ec10dca546c7b28382d | |
| parent | SPPattern c++-sification: replaced GSList by std::list (diff) | |
| download | inkscape-22db6068f172d060429f17a489bdce59e5836c69.tar.gz inkscape-22db6068f172d060429f17a489bdce59e5836c69.zip | |
SPPattern c++-sification: replacing pattern_ functions by methods pt1
(bzr r13341.6.19)
| -rw-r--r-- | src/extension/internal/cairo-render-context.cpp | 16 | ||||
| -rw-r--r-- | src/extension/internal/emf-print.cpp | 8 | ||||
| -rw-r--r-- | src/extension/internal/wmf-print.cpp | 4 | ||||
| -rw-r--r-- | src/knot-holder-entity.cpp | 10 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 7 | ||||
| -rw-r--r-- | src/sp-pattern.cpp | 66 | ||||
| -rw-r--r-- | src/sp-pattern.h | 20 |
7 files changed, 68 insertions, 63 deletions
diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 2ace19ae5..aac2c517a 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1006,16 +1006,16 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver ps2user = Geom::identity(); pcs2dev = Geom::identity(); - double x = pattern_x(pat); - double y = pattern_y(pat); - double width = pattern_width(pat); - double height = pattern_height(pat); + double x = pat->get_x(); + double y = pat->get_y(); + double width = pat->get_width(); + double height = pat->get_height(); double bbox_width_scaler; double bbox_height_scaler; TRACE(("%f x %f pattern\n", width, height)); - if (pbox && pattern_patternUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { + if (pbox && pat->get_pattern_units() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { //Geom::Affine bbox2user (pbox->x1 - pbox->x0, 0.0, 0.0, pbox->y1 - pbox->y0, pbox->x0, pbox->y0); bbox_width_scaler = pbox->width(); bbox_height_scaler = pbox->height(); @@ -1029,13 +1029,13 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver } // apply pattern transformation - Geom::Affine pattern_transform(pattern_patternTransform(pat)); + Geom::Affine pattern_transform(pat->get_transform()); ps2user *= pattern_transform; Geom::Point ori (ps2user[4], ps2user[5]); // create pattern contents coordinate system if (pat->viewBox_set) { - Geom::Rect view_box = *pattern_viewBox(pat); + Geom::Rect view_box = *pat->get_viewbox(); double x, y, w, h; x = 0; @@ -1048,7 +1048,7 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver pcs2dev[3] = h / view_box.height(); pcs2dev[4] = x - view_box.left() * pcs2dev[0]; pcs2dev[5] = y - view_box.top() * pcs2dev[3]; - } else if (pbox && pattern_patternContentUnits(pat) == SPPattern::UNITS_OBJECTBOUNDINGBOX) { + } else if (pbox && pat->get_pattern_content_units() == SPPattern::UNITS_OBJECTBOUNDINGBOX) { pcs2dev[0] = pbox->width(); pcs2dev[3] = pbox->height(); } diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 9c68e40a4..2953efd7d 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -381,8 +381,8 @@ int PrintEmf::create_brush(SPStyle const *style, PU_COLORREF fcolor) } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->fill.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); @@ -567,8 +567,8 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) if (SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->stroke.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); diff --git a/src/extension/internal/wmf-print.cpp b/src/extension/internal/wmf-print.cpp index 55ad5da5f..8f3115693 100644 --- a/src/extension/internal/wmf-print.cpp +++ b/src/extension/internal/wmf-print.cpp @@ -378,8 +378,8 @@ int PrintWmf::create_brush(SPStyle const *style, U_COLORREF *fcolor) } else if (SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style))) { // must be paint-server SPPaintServer *paintserver = style->fill.value.href->getObject(); SPPattern *pat = SP_PATTERN(paintserver); - double dwidth = pattern_width(pat); - double dheight = pattern_height(pat); + double dwidth = pat->get_width(); + double dheight = pat->get_height(); width = dwidth; height = dheight; brush_classify(pat, 0, &pixbuf, &hatchType, &hatchColor, &bkColor); diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp index 6471124ec..7b79d86a8 100644 --- a/src/knot-holder-entity.cpp +++ b/src/knot-holder-entity.cpp @@ -187,7 +187,7 @@ PatternKnotHolderEntityAngle::knot_get() const { SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - gdouble x = pattern_width(pat); + gdouble x = pat->get_width(); gdouble y = 0; Geom::Point delta = Geom::Point(x,y); Geom::Point scale = sp_pattern_extract_scale(pat); @@ -236,8 +236,8 @@ PatternKnotHolderEntityScale::knot_set(Geom::Point const &p, Geom::Point const & // Get the new scale from the position of the knotholder Geom::Point d = p_snapped - sp_pattern_extract_trans(pat); - gdouble pat_x = pattern_width(pat); - gdouble pat_y = pattern_height(pat); + gdouble pat_x = pat->get_width(); + gdouble pat_y = pat->get_height(); Geom::Scale scl(1); if ( state & GDK_CONTROL_MASK ) { // if ctrl is pressed: use 1:1 scaling @@ -263,8 +263,8 @@ PatternKnotHolderEntityScale::knot_get() const { SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - gdouble x = pattern_width(pat); - gdouble y = pattern_height(pat); + gdouble x = pat->get_width(); + gdouble y = pat->get_height(); Geom::Point delta = Geom::Point(x,y); Geom::Affine a = pat->patternTransform; a[4] = 0; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 19eba8ddd..9d07ec046 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3344,12 +3344,13 @@ void sp_selection_untile(SPDesktop *desktop) did = true; - SPPattern *pattern = pattern_getroot(SP_PATTERN(server)); + SPPattern *pattern = SP_PATTERN(server); + SPPattern *pattern_root = pattern_getroot(pattern); - Geom::Affine pat_transform = pattern_patternTransform(SP_PATTERN(server)); + Geom::Affine pat_transform = pattern->get_transform(); pat_transform *= item->transform; - for (SPObject *child = pattern->firstChild() ; child != NULL; child = child->next ) { + for (SPObject *child = pattern_root->firstChild() ; child != NULL; child = child->next ) { if (SP_IS_ITEM(child)) { Inkscape::XML::Node *copy = child->getRepr()->duplicate(xml_doc); SPItem *i = SP_ITEM(desktop->currentLayer()->appendChildRepr(copy)); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index a3de09368..81e11ecb2 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -392,7 +392,7 @@ sp_pattern_transform_multiply (SPPattern *pattern, Geom::Affine postmul, bool se if (set) { pattern->patternTransform = postmul; } else { - pattern->patternTransform = pattern_patternTransform(pattern) * postmul; + pattern->patternTransform = pattern->get_transform() * postmul; } pattern->patternTransform_set = true; @@ -451,73 +451,73 @@ SPPattern *pattern_getroot(SPPattern *pat) // Access functions that look up fields up the chain of referenced patterns and return the first one which is set // FIXME: all of them must use chase_hrefs the same as in SPGradient, to avoid lockup on circular refs -SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat) +SPPattern::PatternUnits SPPattern::get_pattern_units() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternUnits_set) return pat_i->patternUnits; } - return pat->patternUnits; + return patternUnits; } -SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat) +SPPattern::PatternUnits SPPattern::get_pattern_content_units() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternContentUnits_set) return pat_i->patternContentUnits; } - return pat->patternContentUnits; + return patternContentUnits; } -Geom::Affine const &pattern_patternTransform(SPPattern const *pat) +Geom::Affine const &SPPattern::get_transform() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->patternTransform_set) return pat_i->patternTransform; } - return pat->patternTransform; + return patternTransform; } -gdouble pattern_x (SPPattern const *pat) +gdouble SPPattern::get_x() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->x._set) return pat_i->x.computed; } return 0; } -gdouble pattern_y (SPPattern const *pat) +gdouble SPPattern::get_y() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->y._set) return pat_i->y.computed; } return 0; } -gdouble pattern_width (SPPattern const* pat) +gdouble SPPattern::get_width() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->width._set) return pat_i->width.computed; } return 0; } -gdouble pattern_height (SPPattern const *pat) +gdouble SPPattern::get_height() const { - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->height._set) return pat_i->height.computed; } return 0; } -Geom::OptRect pattern_viewBox (SPPattern const *pat) +Geom::OptRect SPPattern::get_viewbox() const { Geom::OptRect viewbox; - for (SPPattern const *pat_i = pat; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { + for (SPPattern const *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { if (pat_i->viewBox_set) { viewbox = pat_i->viewBox; break; @@ -526,10 +526,10 @@ Geom::OptRect pattern_viewBox (SPPattern const *pat) return viewbox; } -static bool pattern_hasItemChildren (SPPattern const *pat) +bool SPPattern::_has_item_children() const { bool hasChildren = false; - for (SPObject const *child = pat->firstChild() ; child && !hasChildren ; child = child->getNext() ) { + for (SPObject const *child = firstChild() ; child && !hasChildren ; child = child->getNext() ) { if (SP_IS_ITEM(child)) { hasChildren = true; } @@ -539,8 +539,8 @@ static bool pattern_hasItemChildren (SPPattern const *pat) bool SPPattern::isValid() const { - double tile_width = pattern_width(this); - double tile_height = pattern_height(this); + double tile_width = get_width(); + double tile_height = get_height(); if (tile_width <= 0 || tile_height <= 0) return false; @@ -561,7 +561,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b for (SPPattern *pat_i = this; pat_i != NULL; pat_i = pat_i->ref ? pat_i->ref->getObject() : NULL) { // find the first one with item children - if (pat_i && SP_IS_OBJECT(pat_i) && pattern_hasItemChildren(pat_i)) { + if (pat_i && SP_IS_OBJECT(pat_i) && pat_i->_has_item_children()) { shown = pat_i; break; // do not go further up the chain if children are found } @@ -595,11 +595,11 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b // * "x", "y", and "patternTransform" transform tile to user space after tile is generated. // These functions recursively search up the tree to find the values. - double tile_x = pattern_x(this); - double tile_y = pattern_y(this); - double tile_width = pattern_width(this); - double tile_height = pattern_height(this); - if ( bbox && (pattern_patternUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { + double tile_x = get_x(); + double tile_y = get_y(); + double tile_width = get_width(); + double tile_height = get_height(); + if ( bbox && (get_pattern_units() == UNITS_OBJECTBOUNDINGBOX) ) { tile_x *= bbox->width(); tile_y *= bbox->height(); tile_width *= bbox->width(); @@ -611,7 +611,7 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b // Content to tile (pattern space) Geom::Affine content2ps; - Geom::OptRect effective_view_box = pattern_viewBox(this); + Geom::OptRect effective_view_box = get_viewbox(); if (effective_view_box) { // viewBox to pattern server (using SPViewBox) viewBox = *effective_view_box; @@ -621,14 +621,14 @@ cairo_pattern_t* SPPattern::pattern_new(cairo_t *base_ct, Geom::OptRect const &b } else { // Content to bbox - if (bbox && (pattern_patternContentUnits(this) == UNITS_OBJECTBOUNDINGBOX) ) { + if (bbox && (get_pattern_content_units() == UNITS_OBJECTBOUNDINGBOX) ) { content2ps = Geom::Affine(bbox->width(), 0.0, 0.0, bbox->height(), 0,0); } } // Tile (pattern space) to user. - Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * pattern_patternTransform(this); + Geom::Affine ps2user = Geom::Translate(tile_x,tile_y) * get_transform(); // Transform of object with pattern (includes screen scaling) diff --git a/src/sp-pattern.h b/src/sp-pattern.h index 3f7433d62..f1dcc7963 100644 --- a/src/sp-pattern.h +++ b/src/sp-pattern.h @@ -70,6 +70,15 @@ public: bool isValid() const; + gdouble get_x() const; + gdouble get_y() const; + gdouble get_width() const; + gdouble get_height() const; + Geom::OptRect get_viewbox() const; + SPPattern::PatternUnits get_pattern_units() const; + SPPattern::PatternUnits get_pattern_content_units() const; + Geom::Affine const &get_transform() const; + virtual cairo_pattern_t* pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity); protected: @@ -78,6 +87,9 @@ protected: virtual void set(unsigned int key, const gchar* value); virtual void update(SPCtx* ctx, unsigned int flags); virtual void modified(unsigned int flags); + +private: + bool _has_item_children() const; }; @@ -103,14 +115,6 @@ const gchar *pattern_tile (const std::list<Inkscape::XML::Node*> &reprs, Geom::R SPPattern *pattern_getroot (SPPattern *pat); -SPPattern::PatternUnits pattern_patternUnits (SPPattern const *pat); -SPPattern::PatternUnits pattern_patternContentUnits (SPPattern const *pat); -Geom::Affine const &pattern_patternTransform(SPPattern const *pat); -gdouble pattern_x (SPPattern const *pat); -gdouble pattern_y (SPPattern const *pat); -gdouble pattern_width (SPPattern const *pat); -gdouble pattern_height (SPPattern const *pat); -Geom::OptRect pattern_viewBox (SPPattern const *pat); #endif // SEEN_SP_PATTERN_H |
