e6484de9f1d7748278a373f30ac7a671a317961f
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;
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 // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild
126 float cached_width;
127 // delayed_shp=true means the *_shp polygons are not computed yet
128 // they'll be computed on demand in *_render(), *_pick() or *_clip()
129 // the goal is to not uncross polygons that are outside the viewing region
130 bool delayed_shp;
131 // approximate bounding box, for the case when the polygons have been delayed
132 NRRectL approx_bbox;
133 // cache for transformations: cached_fill and cached_stroke are
134 // polygons computed for the cached_fctm and cache_sctm respectively
135 // when the transformation changes interactively (tracked by the
136 // SP_OBJECT_USER_MODIFIED_FLAG_B), we check if it's an isometry wrt
137 // the cached ctm. if it's an isometry, just apply it to the cached
138 // polygon to get the *_shp polygon. Otherwise, recompute so this
139 // works fine for translation and rotation, but not scaling and
140 // skewing
141 NR::Matrix cached_fctm;
142 NR::Matrix cached_sctm;
143 NRRectL cached_farea;
144 NRRectL cached_sarea;
145 bool cached_fpartialy;
146 bool cached_spartialy;
148 Shape *cached_fill;
149 Shape *cached_stroke;
150 /* Markers */
151 NRArenaItem *markers;
153 NRArenaItem *last_pick;
154 guint repick_after;
156 static NRArenaShape *create(NRArena *arena) {
157 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
158 obj->init(arena);
159 return obj;
160 }
162 void setFill(SPPaintServer *server);
163 void setFill(SPColor const &color);
164 void setFillOpacity(double opacity);
165 void setFillRule(FillRule rule);
167 void setStroke(SPPaintServer *server);
168 void setStroke(SPColor const &color);
169 void setStrokeOpacity(double opacity);
170 void setStrokeWidth(double width);
171 void setLineCap(CapType cap);
172 void setLineJoin(JoinType join);
173 void setMitreLimit(double limit);
175 void setPaintBox(NR::Rect const &pbox);
177 void _invalidateCachedFill() {
178 if (cached_fill) {
179 delete cached_fill;
180 cached_fill = NULL;
181 }
182 }
183 void _invalidateCachedStroke() {
184 if (cached_stroke) {
185 delete cached_stroke;
186 cached_stroke = NULL;
187 }
188 }
190 struct Style {
191 Style() : opacity(0.0) {}
192 Paint paint;
193 double opacity;
194 };
195 struct FillStyle : public Style {
196 FillStyle() : rule(EVEN_ODD) {}
197 FillRule rule;
198 } _fill;
199 struct StrokeStyle : public Style {
200 StrokeStyle()
201 : cap(ROUND_CAP), join(ROUND_JOIN),
202 width(0.0), mitre_limit(0.0)
203 {}
205 CapType cap;
206 JoinType join;
207 double width;
208 double mitre_limit;
209 } _stroke;
210 };
212 struct NRArenaShapeClass {
213 NRArenaItemClass parent_class;
214 };
216 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
217 void nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style);
218 void nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox);
220 #endif