Code

03505cfc2af0a97a5914274d35e74941fd67d986
[inkscape.git] / src / display / nr-arena-shape.h
1 #ifndef __NR_ARENA_SHAPE_H__
2 #define __NR_ARENA_SHAPE_H__
4 /*
5  * RGBA display list system for inkscape
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * Copyright (C) 2001-2002 Lauris Kaplinski
11  * Copyright (C) 2001 Ximian, Inc.
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #define NR_TYPE_ARENA_SHAPE (nr_arena_shape_get_type ())
17 #define NR_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_CAST ((obj), NR_TYPE_ARENA_SHAPE, NRArenaShape))
18 #define NR_IS_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_TYPE ((obj), NR_TYPE_ARENA_SHAPE))
20 #include "display/display-forward.h"
21 #include "display/canvas-bpath.h"
22 #include "forward.h"
23 #include "sp-paint-server.h"
24 #include "nr-arena-item.h"
26 #include "../color.h"
28 #include "../livarot/Shape.h"
30 NRType nr_arena_shape_get_type (void);
32 struct NRArenaShape : public NRArenaItem {
33     class Paint {
34     public:
35         enum Type {
36             NONE,
37             COLOR,
38             SERVER
39         };
41         Paint() : _type(NONE), _color(0), _server(NULL) {}
42         Paint(Paint const &p) { _assign(p); }
43         virtual ~Paint() { clear(); }
45         Type type() const { return _type; }
46         SPPaintServer *server() const { return _server; }
47         SPColor const &color() const { return _color; }
49         Paint &operator=(Paint const &p) {
50             set(p);
51             return *this;
52         }
54         void set(Paint const &p) {
55             clear();
56             _assign(p);
57         }
58         void set(SPColor const &color) {
59             clear();
60             _type = COLOR;
61             _color = color;
62         }
63         void set(SPPaintServer *server) {
64             clear();
65             if (server) {
66                 _type = SERVER;
67                 _server = server;
68                 sp_object_ref(_server, NULL);
69             }
70         }
71         void clear() {
72             if ( _type == SERVER ) {
73                 sp_object_unref(_server, NULL);
74                 _server = NULL;
75             }
76             _type = NONE;
77         }
79     private:
80         Type _type;
81         SPColor _color;
82         SPPaintServer *_server;
84         void _assign(Paint const &p) {
85             _type = p._type;
86             _server = p._server;
87             _color = p._color;
88             if (_server) {
89                 sp_object_ref(_server, NULL);
90             }
91         }
92     };
94     enum FillRule {
95         EVEN_ODD,
96         NONZERO
97     };
99     enum CapType {
100         ROUND_CAP,
101         SQUARE_CAP,
102         BUTT_CAP
103     };
105     enum JoinType {
106         ROUND_JOIN,
107         BEVEL_JOIN,
108         MITRE_JOIN
109     };
111     /* Shape data */
112     SPCurve *curve;
113     SPStyle *style;
114     NRRect paintbox;
115     /* State data */
116     Geom::Matrix ctm;
118     SPPainter *fill_painter;
119     SPPainter *stroke_painter;
120     // the 2 cached polygons, for rasterizations uses
121     Shape *fill_shp;
122     Shape *stroke_shp;
123     // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild
124     float cached_width;
125     // delayed_shp=true means the *_shp polygons are not computed yet
126     // they'll be computed on demand in *_render(), *_pick() or *_clip()
127     // the goal is to not uncross polygons that are outside the viewing region
128     bool    delayed_shp;
129     // approximate bounding box, for the case when the polygons have been delayed
130     NRRectL approx_bbox;
131     // cache for transformations: cached_fill and cached_stroke are
132     // polygons computed for the cached_fctm and cache_sctm respectively
133     // when the transformation changes interactively (tracked by the
134     // SP_OBJECT_USER_MODIFIED_FLAG_B), we check if it's an isometry wrt
135     // the cached ctm. if it's an isometry, just apply it to the cached
136     // polygon to get the *_shp polygon.  Otherwise, recompute so this
137     // works fine for translation and rotation, but not scaling and
138     // skewing
139     Geom::Matrix cached_fctm;
140     Geom::Matrix cached_sctm;
141     NRRectL cached_farea;
142     NRRectL cached_sarea;
143     bool cached_fpartialy;
144     bool cached_spartialy;
146     Shape *cached_fill;
147     Shape *cached_stroke;
148     /* Markers */
149     NRArenaItem *markers;
151     NRArenaItem *last_pick;
152     guint repick_after;
154     static NRArenaShape *create(NRArena *arena) {
155         NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
156         obj->init(arena);
157         obj->key = 0;
158         return obj;
159     }
161     void setFill(SPPaintServer *server);
162     void setFill(SPColor const &color);
163     void setFillOpacity(double opacity);
164     void setFillRule(FillRule rule);
166     void setStroke(SPPaintServer *server);
167     void setStroke(SPColor const &color);
168     void setStrokeOpacity(double opacity);
169     void setStrokeWidth(double width);
170     void setLineCap(CapType cap);
171     void setLineJoin(JoinType join);
172     void setMitreLimit(double limit);
174     void setPaintBox(Geom::Rect const &pbox);
176     void _invalidateCachedFill() {
177         if (cached_fill) {
178             delete cached_fill;
179             cached_fill = NULL;
180         }
181     }
182     void _invalidateCachedStroke() {
183         if (cached_stroke) {
184             delete cached_stroke;
185             cached_stroke = NULL;
186         }
187     }
189     struct Style {
190         Style() : opacity(0.0) {}
191         Paint paint;
192         double opacity;
193     };
194     struct FillStyle : public Style {
195         FillStyle() : rule(EVEN_ODD) {}
196         FillRule rule;
197     } _fill;
198     struct StrokeStyle : public Style {
199         StrokeStyle()
200             : cap(ROUND_CAP), join(ROUND_JOIN),
201               width(0.0), mitre_limit(0.0)
202         {}
204         CapType cap;
205         JoinType join;
206         double width;
207         double mitre_limit;
208     } _stroke;
209 };
211 struct NRArenaShapeClass {
212     NRArenaItemClass parent_class;
213 };
215 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
216 void nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style);
217 void nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox);
220 #endif /* !__NR_ARENA_SHAPE_H__ */
222 /*
223   Local Variables:
224   mode:c++
225   c-file-style:"stroustrup"
226   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
227   indent-tabs-mode:nil
228   fill-column:99
229   End:
230 */
231 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :