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/canvas-bpath.h"
21 #include "forward.h"
22 #include "sp-paint-server.h"
23 #include "nr-arena-item.h"
25 #include "../color.h"
27 #include "../livarot/Shape.h"
29 NRType nr_arena_shape_get_type (void);
31 struct NRArenaShape : public NRArenaItem {
32 class Paint {
33 public:
34 enum Type {
35 NONE,
36 COLOR,
37 SERVER
38 };
40 Paint() : _type(NONE), _color(0), _server(NULL) {}
41 Paint(Paint const &p) { _assign(p); }
42 virtual ~Paint() { clear(); }
44 Type type() const { return _type; }
45 SPPaintServer *server() const { return _server; }
46 SPColor const &color() const { return _color; }
48 Paint &operator=(Paint const &p) {
49 set(p);
50 return *this;
51 }
53 void set(Paint const &p) {
54 clear();
55 _assign(p);
56 }
57 void set(SPColor const &color) {
58 clear();
59 _type = COLOR;
60 _color = color;
61 }
62 void set(SPPaintServer *server) {
63 clear();
64 if (server) {
65 _type = SERVER;
66 _server = server;
67 sp_object_ref(_server, NULL);
68 }
69 }
70 void clear() {
71 if ( _type == SERVER ) {
72 sp_object_unref(_server, NULL);
73 _server = NULL;
74 }
75 _type = NONE;
76 }
78 private:
79 Type _type;
80 SPColor _color;
81 SPPaintServer *_server;
83 void _assign(Paint const &p) {
84 _type = p._type;
85 _server = p._server;
86 _color = p._color;
87 if (_server) {
88 sp_object_ref(_server, NULL);
89 }
90 }
91 };
93 enum FillRule {
94 EVEN_ODD,
95 NONZERO
96 };
98 enum CapType {
99 ROUND_CAP,
100 SQUARE_CAP,
101 BUTT_CAP
102 };
104 enum JoinType {
105 ROUND_JOIN,
106 BEVEL_JOIN,
107 MITRE_JOIN
108 };
110 /* Shape data */
111 SPCurve *curve;
112 SPStyle *style;
113 NRRect paintbox;
114 /* State data */
115 Geom::Matrix ctm;
117 SPPainter *fill_painter;
118 SPPainter *stroke_painter;
119 // the 2 cached polygons, for rasterizations uses
120 Shape *fill_shp;
121 Shape *stroke_shp;
122 // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild
123 float cached_width;
124 // delayed_shp=true means the *_shp polygons are not computed yet
125 // they'll be computed on demand in *_render(), *_pick() or *_clip()
126 // the goal is to not uncross polygons that are outside the viewing region
127 bool delayed_shp;
128 // approximate bounding box, for the case when the polygons have been delayed
129 NRRectL approx_bbox;
130 // cache for transformations: cached_fill and cached_stroke are
131 // polygons computed for the cached_fctm and cache_sctm respectively
132 // when the transformation changes interactively (tracked by the
133 // SP_OBJECT_USER_MODIFIED_FLAG_B), we check if it's an isometry wrt
134 // the cached ctm. if it's an isometry, just apply it to the cached
135 // polygon to get the *_shp polygon. Otherwise, recompute so this
136 // works fine for translation and rotation, but not scaling and
137 // skewing
138 Geom::Matrix cached_fctm;
139 Geom::Matrix cached_sctm;
140 NRRectL cached_farea;
141 NRRectL cached_sarea;
142 bool cached_fpartialy;
143 bool cached_spartialy;
145 Shape *cached_fill;
146 Shape *cached_stroke;
147 /* Markers */
148 NRArenaItem *markers;
150 NRArenaItem *last_pick;
151 guint repick_after;
153 static NRArenaShape *create(NRArena *arena) {
154 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
155 obj->init(arena);
156 obj->key = 0;
157 return obj;
158 }
160 void setFill(SPPaintServer *server);
161 void setFill(SPColor const &color);
162 void setFillOpacity(double opacity);
163 void setFillRule(FillRule rule);
165 void setStroke(SPPaintServer *server);
166 void setStroke(SPColor const &color);
167 void setStrokeOpacity(double opacity);
168 void setStrokeWidth(double width);
169 void setLineCap(CapType cap);
170 void setLineJoin(JoinType join);
171 void setMitreLimit(double limit);
173 void setPaintBox(Geom::Rect const &pbox);
175 void _invalidateCachedFill() {
176 if (cached_fill) {
177 delete cached_fill;
178 cached_fill = NULL;
179 }
180 }
181 void _invalidateCachedStroke() {
182 if (cached_stroke) {
183 delete cached_stroke;
184 cached_stroke = NULL;
185 }
186 }
188 struct Style {
189 Style() : opacity(0.0) {}
190 Paint paint;
191 double opacity;
192 };
193 struct FillStyle : public Style {
194 FillStyle() : rule(EVEN_ODD) {}
195 FillRule rule;
196 } _fill;
197 struct StrokeStyle : public Style {
198 StrokeStyle()
199 : cap(ROUND_CAP), join(ROUND_JOIN),
200 width(0.0), mitre_limit(0.0)
201 {}
203 CapType cap;
204 JoinType join;
205 double width;
206 double mitre_limit;
207 } _stroke;
208 };
210 struct NRArenaShapeClass {
211 NRArenaItemClass parent_class;
212 };
214 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
215 void nr_arena_shape_set_style(NRArenaShape *shape, SPStyle *style);
216 void nr_arena_shape_set_paintbox(NRArenaShape *shape, NRRect const *pbox);
219 #endif /* !__NR_ARENA_SHAPE_H__ */
221 /*
222 Local Variables:
223 mode:c++
224 c-file-style:"stroustrup"
225 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
226 indent-tabs-mode:nil
227 fill-column:99
228 End:
229 */
230 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :