Code

optimized includes
[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/curve.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), _server(NULL) {
42                         sp_color_set_rgb_rgba32(&_color, 0);
43                 }
44                 Paint(Paint const &p) { _assign(p); }
45                 ~Paint() { clear(); }
47                 Type type() const { return _type; }
48                 SPPaintServer *server() const { return _server; }
49                 SPColor const &color() const { return _color; }
51                 Paint &operator=(Paint const &p) {
52                         set(p);
53                         return *this;
54                 }
56                 void set(Paint const &p) {
57                         clear();
58                         _assign(p);
59                 }
60                 void set(SPColor const &color) {
61                         clear();
62                         _type = COLOR;
63                         sp_color_copy(&_color, &color);
64                 }
65                 void set(SPPaintServer *server) {
66                         clear();
67                         if (server) {
68                                 _type = SERVER;
69                                 _server = server;
70                                 sp_object_ref(_server, NULL);
71                         }
72                 }
73                 void clear() {
74                         if ( _type == SERVER ) {
75                                 sp_object_unref(_server, NULL);
76                                 _server = NULL;
77                         }
78                         _type = NONE;
79                 }
81         private:
82                 Type _type;
83                 SPColor _color;
84                 SPPaintServer *_server;
86                 void _assign(Paint const &p) {
87                         _type = p._type;
88                         _server = p._server;
89                         sp_color_copy(&_color, &p._color);
90                         if (_server) {
91                                 sp_object_ref(_server, NULL);
92                         }
93                 }
94         };
96         enum FillRule {
97                 EVEN_ODD,
98                 NONZERO
99         };
101         enum CapType {
102                 ROUND_CAP,
103                 SQUARE_CAP,
104                 BUTT_CAP
105         };
107         enum JoinType {
108                 ROUND_JOIN,
109                 BEVEL_JOIN,
110                 MITRE_JOIN
111         };
113         /* Shape data */
114         SPCurve *curve;
115         SPStyle *style;
116         NRRect paintbox;
117         /* State data */
118         NR::Matrix ctm;
119         
120         SPPainter *fill_painter;
121         SPPainter *stroke_painter;
122         // the 2 cached polygons, for rasterizations uses
123         Shape *fill_shp;
124         Shape *stroke_shp;
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         NR::Matrix cached_fctm;
140         NR::Matrix cached_sctm;
141         
142         Shape    *cached_fill;
143         Shape    *cached_stroke;
144         /* Markers */
145         NRArenaItem *markers;
147         static NRArenaShape *create(NRArena *arena) {
148                 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
149                 obj->init(arena);
150                 return obj;
151         }
153         void setFill(SPPaintServer *server);
154         void setFill(SPColor const &color);
155         void setFillOpacity(double opacity);
156         void setFillRule(FillRule rule);
158         void setStroke(SPPaintServer *server);
159         void setStroke(SPColor const &color);
160         void setStrokeOpacity(double opacity);
161         void setStrokeWidth(double width);
162         void setLineCap(CapType cap);
163         void setLineJoin(JoinType join);
164         void setMitreLimit(double limit);
166         void setPaintBox(NR::Rect const &pbox);
168         void _invalidateCachedFill() {
169                 if (cached_fill) {
170                         delete cached_fill;
171                         cached_fill = NULL;
172                 }
173         }
174         void _invalidateCachedStroke() {
175                 if (cached_stroke) {
176                         delete cached_stroke;
177                         cached_stroke = NULL;
178                 }
179         }
181         struct Style {
182                 Style() : opacity(0.0) {}
183                 Paint paint;
184                 double opacity;
185         };
186         struct FillStyle : public Style {
187                 FillStyle() : rule(EVEN_ODD) {}
188                 FillRule rule;
189         } _fill;
190         struct StrokeStyle : public Style {
191                 StrokeStyle()
192                 : cap(ROUND_CAP), join(ROUND_JOIN),
193                   width(0.0), mitre_limit(0.0)
194                 {}
196                 CapType cap;
197                 JoinType join;
198                 double width;
199                 double mitre_limit;
200         } _stroke;
201 };
203 struct NRArenaShapeClass {
204         NRArenaItemClass parent_class;
205 };
207 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
208 void nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style);
209 void nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox);
211 #endif