Code

noop: CodingStyle: re-indent a few files that had mixtures of spaces & tabs for inden...
[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), _color(0), _server(NULL) {}
42         Paint(Paint const &p) { _assign(p); }
43         ~Paint() { clear(); }
45         Type type() const { return _type; }
46         SPPaintServer *server() const { return _server; }
47         SPColor const &color() const { return _color; }
49         Paint &operator=(Paint const &p) {
50             set(p);
51             return *this;
52         }
54         void set(Paint const &p) {
55             clear();
56             _assign(p);
57         }
58         void set(SPColor const &color) {
59             clear();
60             _type = COLOR;
61             _color = color;
62         }
63         void set(SPPaintServer *server) {
64             clear();
65             if (server) {
66                 _type = SERVER;
67                 _server = server;
68                 sp_object_ref(_server, NULL);
69             }
70         }
71         void clear() {
72             if ( _type == SERVER ) {
73                 sp_object_unref(_server, NULL);
74                 _server = NULL;
75             }
76             _type = NONE;
77         }
79     private:
80         Type _type;
81         SPColor _color;
82         SPPaintServer *_server;
84         void _assign(Paint const &p) {
85             _type = p._type;
86             _server = p._server;
87             _color = p._color;
88             if (_server) {
89                 sp_object_ref(_server, NULL);
90             }
91         }
92     };
94     enum FillRule {
95         EVEN_ODD,
96         NONZERO
97     };
99     enum CapType {
100         ROUND_CAP,
101         SQUARE_CAP,
102         BUTT_CAP
103     };
105     enum JoinType {
106         ROUND_JOIN,
107         BEVEL_JOIN,
108         MITRE_JOIN
109     };
111     /* Shape data */
112     SPCurve *curve;
113     SPStyle *style;
114     NRRect paintbox;
115     /* State data */
116     NR::Matrix ctm;
118     SPPainter *fill_painter;
119     SPPainter *stroke_painter;
120     // the 2 cached polygons, for rasterizations uses
121     Shape *fill_shp;
122     Shape *stroke_shp;
123     // the stroke width of stroke_shp, to detect when it changes (on normal/outline switching) and rebuild
124     float cached_width;
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     NRArenaItem *last_pick;
152     guint repick_after;
154     static NRArenaShape *create(NRArena *arena) {
155         NRArenaShape *obj=reinterpret_cast<NRArenaShape *>(nr_object_new(NR_TYPE_ARENA_SHAPE));
156         obj->init(arena);
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(NR::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:encoding=utf-8:textwidth=99 :