~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/sp-pattern.h

  • Committer: scislac
  • Date: 2009-08-12 07:57:52 UTC
  • Revision ID: scislac@users.sourceforge.net-20090812075752-3zt99jgeqr3bm16j
much better quality multi-size windows icon, thanks ChrisMorgan

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** @file
 
1
#ifndef __SP_PATTERN_H__
 
2
#define __SP_PATTERN_H__
 
3
 
 
4
/*
2
5
 * SVG <pattern> implementation
3
 
 *//*
 
6
 *
4
7
 * Author:
5
8
 *   Lauris Kaplinski <lauris@kaplinski.com>
6
 
 *   Abhishek Sharma
7
9
 *
8
10
 * Copyright (C) 2002 Lauris Kaplinski
9
11
 *
10
12
 * Released under GNU GPL, read the file 'COPYING' for more information
11
13
 */
12
14
 
13
 
#ifndef SEEN_SP_PATTERN_H
14
 
#define SEEN_SP_PATTERN_H
15
 
 
16
 
#include <list>
17
 
#include <stddef.h>
18
 
#include <glibmm/ustring.h>
19
 
#include <sigc++/connection.h>
20
 
 
 
15
#include <gtk/gtktypeutils.h>
 
16
 
 
17
#include "forward.h"
 
18
 
 
19
#define SP_TYPE_PATTERN (sp_pattern_get_type ())
 
20
#define SP_PATTERN(o) (GTK_CHECK_CAST ((o), SP_TYPE_PATTERN, SPPattern))
 
21
#define SP_PATTERN_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), SP_TYPE_PATTERN, SPPatternClass))
 
22
#define SP_IS_PATTERN(o) (GTK_CHECK_TYPE ((o), SP_TYPE_PATTERN))
 
23
#define SP_IS_PATTERN_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), SP_TYPE_PATTERN))
 
24
 
 
25
GType sp_pattern_get_type (void);
 
26
 
 
27
class SPPatternClass;
 
28
 
 
29
#include <libnr/nr-rect.h>
 
30
#include <libnr/nr-matrix.h>
21
31
#include "svg/svg-length.h"
22
32
#include "sp-paint-server.h"
23
33
#include "uri-references.h"
24
 
#include "viewbox.h"
25
 
 
26
 
class SPPatternReference;
27
 
class SPItem;
28
 
 
29
 
namespace Inkscape {
30
 
namespace XML {
31
 
 
32
 
class Node;
33
 
}
34
 
}
35
 
 
36
 
#define SP_PATTERN(obj) (dynamic_cast<SPPattern *>((SPObject *)obj))
37
 
#define SP_IS_PATTERN(obj) (dynamic_cast<const SPPattern *>((SPObject *)obj) != NULL)
38
 
 
39
 
class SPPattern : public SPPaintServer, public SPViewBox {
 
34
 
 
35
#include <sigc++/connection.h>
 
36
 
 
37
class SPPatternReference : public Inkscape::URIReference {
40
38
public:
41
 
    enum PatternUnits { UNITS_USERSPACEONUSE, UNITS_OBJECTBOUNDINGBOX };
42
 
 
43
 
    SPPattern();
44
 
    virtual ~SPPattern();
45
 
 
 
39
    SPPatternReference (SPObject *obj) : URIReference(obj) {}
 
40
    SPPattern *getObject() const {
 
41
        return (SPPattern *)URIReference::getObject();
 
42
    }
 
43
 
 
44
protected:
 
45
    virtual bool _acceptObject(SPObject *obj) const {
 
46
        return SP_IS_PATTERN (obj);
 
47
    }
 
48
};
 
49
 
 
50
enum {
 
51
    SP_PATTERN_UNITS_USERSPACEONUSE,
 
52
    SP_PATTERN_UNITS_OBJECTBOUNDINGBOX
 
53
};
 
54
 
 
55
struct SPPattern : public SPPaintServer {
46
56
    /* Reference (href) */
47
 
    Glib::ustring href;
 
57
    gchar *href;
48
58
    SPPatternReference *ref;
49
59
 
50
 
    gdouble x() const;
51
 
    gdouble y() const;
52
 
    gdouble width() const;
53
 
    gdouble height() const;
54
 
    Geom::OptRect viewbox() const;
55
 
    SPPattern::PatternUnits patternUnits() const;
56
 
    SPPattern::PatternUnits patternContentUnits() const;
57
 
    Geom::Affine const &getTransform() const;
58
 
    SPPattern *rootPattern(); // TODO: const
59
 
 
60
 
    SPPattern *clone_if_necessary(SPItem *item, const gchar *property);
61
 
    void transform_multiply(Geom::Affine postmul, bool set);
62
 
 
63
 
    /**
64
 
     * @brief create a new pattern in XML tree
65
 
     * @return created pattern id
66
 
     */
67
 
    static const gchar *produce(const std::vector<Inkscape::XML::Node *> &reprs, Geom::Rect bounds,
68
 
                                SPDocument *document, Geom::Affine transform, Geom::Affine move);
69
 
 
70
 
    bool isValid() const;
71
 
 
72
 
    virtual cairo_pattern_t *pattern_new(cairo_t *ct, Geom::OptRect const &bbox, double opacity);
73
 
 
74
 
protected:
75
 
    virtual void build(SPDocument *doc, Inkscape::XML::Node *repr);
76
 
    virtual void release();
77
 
    virtual void set(unsigned int key, const gchar *value);
78
 
    virtual void update(SPCtx *ctx, unsigned int flags);
79
 
    virtual void modified(unsigned int flags);
80
 
 
81
 
private:
82
 
    bool _hasItemChildren() const;
83
 
    void _getChildren(std::list<SPObject *> &l);
84
 
    SPPattern *_chain() const;
85
 
 
86
 
    /**
87
 
    Count how many times pattern is used by the styles of o and its descendants
88
 
    */
89
 
    guint _countHrefs(SPObject *o) const;
90
 
 
91
 
    /**
92
 
    Gets called when the pattern is reattached to another <pattern>
93
 
    */
94
 
    void _onRefChanged(SPObject *old_ref, SPObject *ref);
95
 
 
96
 
    /**
97
 
    Gets called when the referenced <pattern> is changed
98
 
    */
99
 
    void _onRefModified(SPObject *ref, guint flags);
100
 
 
101
60
    /* patternUnits and patternContentUnits attribute */
102
 
    PatternUnits _pattern_units : 1;
103
 
    bool _pattern_units_set : 1;
104
 
    PatternUnits _pattern_content_units : 1;
105
 
    bool _pattern_content_units_set : 1;
 
61
    guint patternUnits : 1;
 
62
    guint patternUnits_set : 1;
 
63
    guint patternContentUnits : 1;
 
64
    guint patternContentUnits_set : 1;
106
65
    /* patternTransform attribute */
107
 
    Geom::Affine _pattern_transform;
108
 
    bool _pattern_transform_set : 1;
 
66
    Geom::Matrix patternTransform;
 
67
    guint patternTransform_set : 1;
109
68
    /* Tile rectangle */
110
 
    SVGLength _x;
111
 
    SVGLength _y;
112
 
    SVGLength _width;
113
 
    SVGLength _height;
114
 
 
115
 
    sigc::connection _modified_connection;
116
 
};
117
 
 
118
 
 
119
 
class SPPatternReference : public Inkscape::URIReference {
120
 
public:
121
 
    SPPatternReference(SPObject *obj)
122
 
        : URIReference(obj)
123
 
    {
124
 
    }
125
 
 
126
 
    SPPattern *getObject() const
127
 
    {
128
 
        return reinterpret_cast<SPPattern *>(URIReference::getObject());
129
 
    }
130
 
 
131
 
protected:
132
 
    virtual bool _acceptObject(SPObject *obj) const {
133
 
        return SP_IS_PATTERN (obj)&& URIReference::_acceptObject(obj);
134
 
    }
135
 
};
136
 
 
137
 
#endif // SEEN_SP_PATTERN_H
 
69
    SVGLength x;
 
70
    SVGLength y;
 
71
    SVGLength width;
 
72
    SVGLength height;
 
73
    /* VieBox */
 
74
    NRRect viewBox;
 
75
    guint viewBox_set : 1;
 
76
 
 
77
    sigc::connection modified_connection;
 
78
};
 
79
 
 
80
struct SPPatternClass {
 
81
    SPPaintServerClass parent_class;
 
82
};
 
83
 
 
84
guint pattern_users (SPPattern *pattern);
 
85
SPPattern *pattern_chain (SPPattern *pattern);
 
86
SPPattern *sp_pattern_clone_if_necessary (SPItem *item, SPPattern *pattern, const gchar *property);
 
87
void sp_pattern_transform_multiply (SPPattern *pattern, Geom::Matrix postmul, bool set);
 
88
 
 
89
const gchar *pattern_tile (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Matrix transform, Geom::Matrix move);
 
90
 
 
91
SPPattern *pattern_getroot (SPPattern *pat);
 
92
 
 
93
guint pattern_patternUnits (SPPattern *pat);
 
94
guint pattern_patternContentUnits (SPPattern *pat);
 
95
Geom::Matrix const &pattern_patternTransform(SPPattern const *pat);
 
96
gdouble pattern_x (SPPattern *pat);
 
97
gdouble pattern_y (SPPattern *pat);
 
98
gdouble pattern_width (SPPattern *pat);
 
99
gdouble pattern_height (SPPattern *pat);
 
100
NRRect *pattern_viewBox (SPPattern *pat);
 
101
 
 
102
#endif //__SP_PATTERN_H__
138
103
 
139
104
/*
140
105
  Local Variables:
145
110
  fill-column:99
146
111
  End:
147
112
*/
148
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
 
113
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :