Code

moving trunk for module inkscape
[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 <libnr/nr-svp.h>
22 #include "display/curve.h"
23 #include "display/canvas-bpath.h"
24 #include "forward.h"
25 #include "sp-paint-server.h"
26 #include "nr-arena-item.h"
28 #include "../color.h"
30 #include "../livarot/Shape.h"
32 NRType nr_arena_shape_get_type (void);
34 struct NRArenaShape : public NRArenaItem {
35         class Paint {
36         public:
37                 enum Type {
38                         NONE,
39                         COLOR,
40                         SERVER
41                 };
43                 Paint() : _type(NONE), _server(NULL) {
44                         sp_color_set_rgb_rgba32(&_color, 0);
45                 }
46                 Paint(Paint const &p) { _assign(p); }
47                 ~Paint() { clear(); }
49                 Type type() const { return _type; }
50                 SPPaintServer *server() const { return _server; }
51                 SPColor const &color() const { return _color; }
53                 Paint &operator=(Paint const &p) {
54                         set(p);
55                         return *this;
56                 }
58                 void set(Paint const &p) {
59                         clear();
60                         _assign(p);
61                 }
62                 void set(SPColor const &color) {
63                         clear();
64                         _type = COLOR;
65                         sp_color_copy(&_color, &color);
66                 }
67                 void set(SPPaintServer *server) {
68                         clear();
69                         if (server) {
70                                 _type = SERVER;
71                                 _server = server;
72                                 sp_object_ref(_server, NULL);
73                         }
74                 }
75                 void clear() {
76                         if ( _type == SERVER ) {
77                                 sp_object_unref(_server, NULL);
78                                 _server = NULL;
79                         }
80                         _type = NONE;
81                 }
83         private:
84                 Type _type;
85                 SPColor _color;
86                 SPPaintServer *_server;
88                 void _assign(Paint const &p) {
89                         _type = p._type;
90                         _server = p._server;
91                         sp_color_copy(&_color, &p._color);
92                         if (_server) {
93                                 sp_object_ref(_server, NULL);
94                         }
95                 }
96         };
98         enum FillRule {
99                 EVEN_ODD,
100                 NONZERO
101         };
103         enum CapType {
104                 ROUND_CAP,
105                 SQUARE_CAP,
106                 BUTT_CAP
107         };
109         enum JoinType {
110                 ROUND_JOIN,
111                 BEVEL_JOIN,
112                 MITRE_JOIN
113         };
115         /* Shape data */
116         SPCurve *curve;
117         SPStyle *style;
118         NRRect paintbox;
119         /* State data */
120         NR::Matrix ctm;
121         
122         SPPainter *fill_painter;
123         SPPainter *stroke_painter;
124         // the 2 cached polygons, for rasterizations uses
125         Shape *fill_shp;
126         Shape *stroke_shp;
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         
144         Shape    *cached_fill;
145         Shape    *cached_stroke;
146         /* Markers */
147         NRArenaItem *markers;
149         static NRArenaShape *create(NRArena *arena) {
150                 NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
151                 obj->init(arena);
152                 return obj;
153         }
155         void setFill(SPPaintServer *server);
156         void setFill(SPColor const &color);
157         void setFillOpacity(double opacity);
158         void setFillRule(FillRule rule);
160         void setStroke(SPPaintServer *server);
161         void setStroke(SPColor const &color);
162         void setStrokeOpacity(double opacity);
163         void setStrokeWidth(double width);
164         void setLineCap(CapType cap);
165         void setLineJoin(JoinType join);
166         void setMitreLimit(double limit);
168         void setPaintBox(NR::Rect const &pbox);
170         void _invalidateCachedFill() {
171                 if (cached_fill) {
172                         delete cached_fill;
173                         cached_fill = NULL;
174                 }
175         }
176         void _invalidateCachedStroke() {
177                 if (cached_stroke) {
178                         delete cached_stroke;
179                         cached_stroke = NULL;
180                 }
181         }
183         struct Style {
184                 Style() : opacity(0.0) {}
185                 Paint paint;
186                 double opacity;
187         };
188         struct FillStyle : public Style {
189                 FillStyle() : rule(EVEN_ODD) {}
190                 FillRule rule;
191         } _fill;
192         struct StrokeStyle : public Style {
193                 StrokeStyle()
194                 : cap(ROUND_CAP), join(ROUND_JOIN),
195                   width(0.0), mitre_limit(0.0)
196                 {}
198                 CapType cap;
199                 JoinType join;
200                 double width;
201                 double mitre_limit;
202         } _stroke;
203 };
205 struct NRArenaShapeClass {
206         NRArenaItemClass parent_class;
207 };
209 void nr_arena_shape_set_path(NRArenaShape *shape, SPCurve *curve, bool justTrans);
210 void nr_arena_shape_set_style (NRArenaShape *shape, SPStyle *style);
211 void nr_arena_shape_set_paintbox (NRArenaShape *shape, const NRRect *pbox);
213 #endif