Code

fix bug: stroke width was not changed when switching to outline and back
[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         // 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;
147         
148         Shape    *cached_fill;
149         Shape    *cached_stroke;
150         /* Markers */
151         NRArenaItem *markers;
153         static NRArenaShape *create(NRArena *arena) {
154                 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
155                 obj->init(arena);
156                 return obj;
157         }
159         void setFill(SPPaintServer *server);
160         void setFill(SPColor const &color);
161         void setFillOpacity(double opacity);
162         void setFillRule(FillRule rule);
164         void setStroke(SPPaintServer *server);
165         void setStroke(SPColor const &color);
166         void setStrokeOpacity(double opacity);
167         void setStrokeWidth(double width);
168         void setLineCap(CapType cap);
169         void setLineJoin(JoinType join);
170         void setMitreLimit(double limit);
172         void setPaintBox(NR::Rect const &pbox);
174         void _invalidateCachedFill() {
175                 if (cached_fill) {
176                         delete cached_fill;
177                         cached_fill = NULL;
178                 }
179         }
180         void _invalidateCachedStroke() {
181                 if (cached_stroke) {
182                         delete cached_stroke;
183                         cached_stroke = NULL;
184                 }
185         }
187         struct Style {
188                 Style() : opacity(0.0) {}
189                 Paint paint;
190                 double opacity;
191         };
192         struct FillStyle : public Style {
193                 FillStyle() : rule(EVEN_ODD) {}
194                 FillRule rule;
195         } _fill;
196         struct StrokeStyle : public Style {
197                 StrokeStyle()
198                 : cap(ROUND_CAP), join(ROUND_JOIN),
199                   width(0.0), mitre_limit(0.0)
200                 {}
202                 CapType cap;
203                 JoinType join;
204                 double width;
205                 double mitre_limit;
206         } _stroke;
207 };
209 struct NRArenaShapeClass {
210         NRArenaItemClass parent_class;
211 };
213 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
214 void nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style);
215 void nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox);
217 #endif