1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // class renderer_mclip
18 //----------------------------------------------------------------------------
20 #ifndef AGG_RENDERER_MCLIP_INCLUDED
21 #define AGG_RENDERER_MCLIP_INCLUDED
23 #include "agg_basics.h"
24 #include "agg_array.h"
25 #include "agg_renderer_base.h"
30 //----------------------------------------------------------renderer_mclip
31 template<class PixelFormat
> class renderer_mclip
34 typedef PixelFormat pixfmt_type
;
35 typedef typename
pixfmt_type::color_type color_type
;
36 typedef typename
pixfmt_type::row_data row_data
;
37 typedef renderer_base
<pixfmt_type
> base_ren_type
;
39 //--------------------------------------------------------------------
40 renderer_mclip(pixfmt_type
& pixf
) :
43 m_bounds(m_ren
.xmin(), m_ren
.ymin(), m_ren
.xmax(), m_ren
.ymax())
45 void attach(pixfmt_type
& pixf
)
51 //--------------------------------------------------------------------
52 const pixfmt_type
& ren() const { return m_ren
.ren(); }
53 pixfmt_type
& ren() { return m_ren
.ren(); }
55 //--------------------------------------------------------------------
56 unsigned width() const { return m_ren
.width(); }
57 unsigned height() const { return m_ren
.height(); }
59 //--------------------------------------------------------------------
60 const rect_i
& clip_box() const { return m_ren
.clip_box(); }
61 int xmin() const { return m_ren
.xmin(); }
62 int ymin() const { return m_ren
.ymin(); }
63 int xmax() const { return m_ren
.xmax(); }
64 int ymax() const { return m_ren
.ymax(); }
66 //--------------------------------------------------------------------
67 const rect_i
& bounding_clip_box() const { return m_bounds
; }
68 int bounding_xmin() const { return m_bounds
.x1
; }
69 int bounding_ymin() const { return m_bounds
.y1
; }
70 int bounding_xmax() const { return m_bounds
.x2
; }
71 int bounding_ymax() const { return m_bounds
.y2
; }
73 //--------------------------------------------------------------------
79 const rect_i
& cb
= m_clip
[0];
80 m_ren
.clip_box_naked(cb
.x1
, cb
.y1
, cb
.x2
, cb
.y2
);
84 //--------------------------------------------------------------------
87 if(++m_curr_cb
< m_clip
.size())
89 const rect_i
& cb
= m_clip
[m_curr_cb
];
90 m_ren
.clip_box_naked(cb
.x1
, cb
.y1
, cb
.x2
, cb
.y2
);
96 //--------------------------------------------------------------------
97 void reset_clipping(bool visibility
)
99 m_ren
.reset_clipping(visibility
);
102 m_bounds
= m_ren
.clip_box();
105 //--------------------------------------------------------------------
106 void add_clip_box(int x1
, int y1
, int x2
, int y2
)
108 rect_i
cb(x1
, y1
, x2
, y2
);
110 if(cb
.clip(rect_i(0, 0, width() - 1, height() - 1)))
113 if(cb
.x1
< m_bounds
.x1
) m_bounds
.x1
= cb
.x1
;
114 if(cb
.y1
< m_bounds
.y1
) m_bounds
.y1
= cb
.y1
;
115 if(cb
.x2
> m_bounds
.x2
) m_bounds
.x2
= cb
.x2
;
116 if(cb
.y2
> m_bounds
.y2
) m_bounds
.y2
= cb
.y2
;
120 //--------------------------------------------------------------------
121 void clear(const color_type
& c
)
126 //--------------------------------------------------------------------
127 void copy_pixel(int x
, int y
, const color_type
& c
)
132 if(m_ren
.inbox(x
, y
))
134 m_ren
.ren().copy_pixel(x
, y
, c
);
138 while(next_clip_box());
141 //--------------------------------------------------------------------
142 void blend_pixel(int x
, int y
, const color_type
& c
, cover_type cover
)
147 if(m_ren
.inbox(x
, y
))
149 m_ren
.ren().blend_pixel(x
, y
, c
, cover
);
153 while(next_clip_box());
156 //--------------------------------------------------------------------
157 color_type
pixel(int x
, int y
) const
162 if(m_ren
.inbox(x
, y
))
164 return m_ren
.ren().pixel(x
, y
);
167 while(next_clip_box());
168 return color_type::no_color();
171 //--------------------------------------------------------------------
172 void copy_hline(int x1
, int y
, int x2
, const color_type
& c
)
177 m_ren
.copy_hline(x1
, y
, x2
, c
);
179 while(next_clip_box());
182 //--------------------------------------------------------------------
183 void copy_vline(int x
, int y1
, int y2
, const color_type
& c
)
188 m_ren
.copy_vline(x
, y1
, y2
, c
);
190 while(next_clip_box());
193 //--------------------------------------------------------------------
194 void blend_hline(int x1
, int y
, int x2
,
195 const color_type
& c
, cover_type cover
)
200 m_ren
.blend_hline(x1
, y
, x2
, c
, cover
);
202 while(next_clip_box());
205 //--------------------------------------------------------------------
206 void blend_vline(int x
, int y1
, int y2
,
207 const color_type
& c
, cover_type cover
)
212 m_ren
.blend_vline(x
, y1
, y2
, c
, cover
);
214 while(next_clip_box());
217 //--------------------------------------------------------------------
218 void copy_bar(int x1
, int y1
, int x2
, int y2
, const color_type
& c
)
223 m_ren
.copy_bar(x1
, y1
, x2
, y2
, c
);
225 while(next_clip_box());
228 //--------------------------------------------------------------------
229 void blend_bar(int x1
, int y1
, int x2
, int y2
,
230 const color_type
& c
, cover_type cover
)
235 m_ren
.blend_bar(x1
, y1
, x2
, y2
, c
, cover
);
237 while(next_clip_box());
240 //--------------------------------------------------------------------
241 void blend_solid_hspan(int x
, int y
, int len
,
242 const color_type
& c
, const cover_type
* covers
)
247 m_ren
.blend_solid_hspan(x
, y
, len
, c
, covers
);
249 while(next_clip_box());
252 //--------------------------------------------------------------------
253 void blend_solid_vspan(int x
, int y
, int len
,
254 const color_type
& c
, const cover_type
* covers
)
259 m_ren
.blend_solid_vspan(x
, y
, len
, c
, covers
);
261 while(next_clip_box());
265 //--------------------------------------------------------------------
266 void copy_color_hspan(int x
, int y
, int len
, const color_type
* colors
)
271 m_ren
.copy_color_hspan(x
, y
, len
, colors
);
273 while(next_clip_box());
276 //--------------------------------------------------------------------
277 void blend_color_hspan(int x
, int y
, int len
,
278 const color_type
* colors
,
279 const cover_type
* covers
,
280 cover_type cover
= cover_full
)
285 m_ren
.blend_color_hspan(x
, y
, len
, colors
, covers
, cover
);
287 while(next_clip_box());
290 //--------------------------------------------------------------------
291 void blend_color_vspan(int x
, int y
, int len
,
292 const color_type
* colors
,
293 const cover_type
* covers
,
294 cover_type cover
= cover_full
)
299 m_ren
.blend_color_vspan(x
, y
, len
, colors
, covers
, cover
);
301 while(next_clip_box());
304 //--------------------------------------------------------------------
305 void copy_from(const rendering_buffer
& from
,
313 m_ren
.copy_from(from
, rc
, x_to
, y_to
);
315 while(next_clip_box());
318 //--------------------------------------------------------------------
319 template<class SrcPixelFormatRenderer
>
320 void blend_from(const SrcPixelFormatRenderer
& src
,
321 const rect_i
* rect_src_ptr
= 0,
324 cover_type cover
= cover_full
)
329 m_ren
.blend_from(src
, rect_src_ptr
, dx
, dy
, cover
);
331 while(next_clip_box());
336 renderer_mclip(const renderer_mclip
<PixelFormat
>&);
337 const renderer_mclip
<PixelFormat
>&
338 operator = (const renderer_mclip
<PixelFormat
>&);
341 pod_bvector
<rect_i
, 4> m_clip
;