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 // 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 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 static NRArenaShape *create(NRArena *arena) {
152 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
153 obj->init(arena);
154 return obj;
155 }
157 void setFill(SPPaintServer *server);
158 void setFill(SPColor const &color);
159 void setFillOpacity(double opacity);
160 void setFillRule(FillRule rule);
162 void setStroke(SPPaintServer *server);
163 void setStroke(SPColor const &color);
164 void setStrokeOpacity(double opacity);
165 void setStrokeWidth(double width);
166 void setLineCap(CapType cap);
167 void setLineJoin(JoinType join);
168 void setMitreLimit(double limit);
170 void setPaintBox(NR::Rect const &pbox);
172 void _invalidateCachedFill() {
173 if (cached_fill) {
174 delete cached_fill;
175 cached_fill = NULL;
176 }
177 }
178 void _invalidateCachedStroke() {
179 if (cached_stroke) {
180 delete cached_stroke;
181 cached_stroke = NULL;
182 }
183 }
185 struct Style {
186 Style() : opacity(0.0) {}
187 Paint paint;
188 double opacity;
189 };
190 struct FillStyle : public Style {
191 FillStyle() : rule(EVEN_ODD) {}
192 FillRule rule;
193 } _fill;
194 struct StrokeStyle : public Style {
195 StrokeStyle()
196 : cap(ROUND_CAP), join(ROUND_JOIN),
197 width(0.0), mitre_limit(0.0)
198 {}
200 CapType cap;
201 JoinType join;
202 double width;
203 double mitre_limit;
204 } _stroke;
205 };
207 struct NRArenaShapeClass {
208 NRArenaItemClass parent_class;
209 };
211 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
212 void nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style);
213 void nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox);
215 #endif