update dev300-m58
[ooovba.git] / agg / inc / agg_renderer_mclip.h
blob95a57009a8f6a3fd2574c7cb979b89a159bd3b6a
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
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.
9 //
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"
27 namespace agg
30 //----------------------------------------------------------renderer_mclip
31 template<class PixelFormat> class renderer_mclip
33 public:
34 typedef PixelFormat pixfmt_type;
35 typedef typename pixfmt_type::color_type color_type;
36 typedef renderer_base<pixfmt_type> base_ren_type;
38 //--------------------------------------------------------------------
39 renderer_mclip(pixfmt_type& ren) :
40 m_ren(ren),
41 m_curr_cb(0),
42 m_bounds(m_ren.xmin(), m_ren.ymin(), m_ren.xmax(), m_ren.ymax())
46 //--------------------------------------------------------------------
47 const pixfmt_type& ren() const { return m_ren.ren(); }
48 pixfmt_type& ren() { return m_ren.ren(); }
50 //--------------------------------------------------------------------
51 unsigned width() const { return m_ren.width(); }
52 unsigned height() const { return m_ren.height(); }
54 //--------------------------------------------------------------------
55 const rect& clip_box() const { return m_ren.clip_box(); }
56 int xmin() const { return m_ren.xmin(); }
57 int ymin() const { return m_ren.ymin(); }
58 int xmax() const { return m_ren.xmax(); }
59 int ymax() const { return m_ren.ymax(); }
61 //--------------------------------------------------------------------
62 const rect& bounding_clip_box() const { return m_bounds; }
63 int bounding_xmin() const { return m_bounds.x1; }
64 int bounding_ymin() const { return m_bounds.y1; }
65 int bounding_xmax() const { return m_bounds.x2; }
66 int bounding_ymax() const { return m_bounds.y2; }
68 //--------------------------------------------------------------------
69 void first_clip_box()
71 m_curr_cb = 0;
72 if(m_clip.size())
74 const rect& cb = m_clip[0];
75 m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2);
79 //--------------------------------------------------------------------
80 bool next_clip_box()
82 if(++m_curr_cb < m_clip.size())
84 const rect& cb = m_clip[m_curr_cb];
85 m_ren.clip_box_naked(cb.x1, cb.y1, cb.x2, cb.y2);
86 return true;
88 return false;
91 //--------------------------------------------------------------------
92 void reset_clipping(bool visibility)
94 m_ren.reset_clipping(visibility);
95 m_clip.remove_all();
96 m_curr_cb = 0;
97 m_bounds = m_ren.clip_box();
100 //--------------------------------------------------------------------
101 void add_clip_box(int x1, int y1, int x2, int y2)
103 rect cb(x1, y1, x2, y2);
104 cb.normalize();
105 if(cb.clip(rect(0, 0, width() - 1, height() - 1)))
107 m_clip.add(cb);
108 if(cb.x1 < m_bounds.x1) m_bounds.x1 = cb.x1;
109 if(cb.y1 < m_bounds.y1) m_bounds.y1 = cb.y1;
110 if(cb.x2 > m_bounds.x2) m_bounds.x2 = cb.x2;
111 if(cb.y2 > m_bounds.y2) m_bounds.y2 = cb.y2;
115 //--------------------------------------------------------------------
116 void clear(const color_type& c)
118 m_ren.clear(c);
121 //--------------------------------------------------------------------
122 void copy_pixel(int x, int y, const color_type& c)
124 first_clip_box();
127 if(m_ren.inbox(x, y))
129 m_ren.ren().copy_pixel(x, y, c);
130 break;
133 while(next_clip_box());
136 //--------------------------------------------------------------------
137 void blend_pixel(int x, int y, const color_type& c, cover_type cover)
139 first_clip_box();
142 if(m_ren.inbox(x, y))
144 m_ren.ren().blend_pixel(x, y, c, cover);
145 break;
148 while(next_clip_box());
151 //--------------------------------------------------------------------
152 color_type pixel(int x, int y) const
154 first_clip_box();
157 if(m_ren.inbox(x, y))
159 return m_ren.ren().pixel(x, y);
162 while(next_clip_box());
163 return color_type::no_color();
166 //--------------------------------------------------------------------
167 void copy_hline(int x1, int y, int x2, const color_type& c)
169 first_clip_box();
172 m_ren.copy_hline(x1, y, x2, c);
174 while(next_clip_box());
177 //--------------------------------------------------------------------
178 void copy_vline(int x, int y1, int y2, const color_type& c)
180 first_clip_box();
183 m_ren.copy_vline(x, y1, y2, c);
185 while(next_clip_box());
188 //--------------------------------------------------------------------
189 void blend_hline(int x1, int y, int x2,
190 const color_type& c, cover_type cover)
192 first_clip_box();
195 m_ren.blend_hline(x1, y, x2, c, cover);
197 while(next_clip_box());
200 //--------------------------------------------------------------------
201 void blend_vline(int x, int y1, int y2,
202 const color_type& c, cover_type cover)
204 first_clip_box();
207 m_ren.blend_vline(x, y1, y2, c, cover);
209 while(next_clip_box());
212 //--------------------------------------------------------------------
213 void copy_bar(int x1, int y1, int x2, int y2, const color_type& c)
215 first_clip_box();
218 m_ren.copy_bar(x1, y1, x2, y2, c);
220 while(next_clip_box());
223 //--------------------------------------------------------------------
224 void blend_bar(int x1, int y1, int x2, int y2,
225 const color_type& c, cover_type cover)
227 first_clip_box();
230 m_ren.blend_bar(x1, y1, x2, y2, c, cover);
232 while(next_clip_box());
236 //--------------------------------------------------------------------
237 void blend_solid_hspan(int x, int y, int len,
238 const color_type& c, const cover_type* covers)
240 first_clip_box();
243 m_ren.blend_solid_hspan(x, y, len, c, covers);
245 while(next_clip_box());
248 //--------------------------------------------------------------------
249 void blend_solid_vspan(int x, int y, int len,
250 const color_type& c, const cover_type* covers)
252 first_clip_box();
255 m_ren.blend_solid_vspan(x, y, len, c, covers);
257 while(next_clip_box());
260 //--------------------------------------------------------------------
261 void blend_color_hspan(int x, int y, int len,
262 const color_type* colors,
263 const cover_type* covers,
264 cover_type cover = cover_full)
266 first_clip_box();
269 m_ren.blend_color_hspan(x, y, len, colors, covers, cover);
271 while(next_clip_box());
274 //--------------------------------------------------------------------
275 void blend_color_vspan(int x, int y, int len,
276 const color_type* colors,
277 const cover_type* covers,
278 cover_type cover = cover_full)
280 first_clip_box();
283 m_ren.blend_color_hspan(x, y, len, colors, covers, cover);
285 while(next_clip_box());
289 //--------------------------------------------------------------------
290 void blend_qpaque_color_hspan(int x, int y, int len,
291 const color_type* colors,
292 const cover_type* covers,
293 cover_type cover = cover_full)
295 first_clip_box();
298 m_ren.blend_opaque_color_hspan(x, y, len, colors, covers, cover);
300 while(next_clip_box());
303 //--------------------------------------------------------------------
304 void blend_opaque_color_vspan(int x, int y, int len,
305 const color_type* colors,
306 const cover_type* covers,
307 cover_type cover = cover_full)
309 first_clip_box();
312 m_ren.blend_opaque_color_hspan(x, y, len, colors, covers, cover);
314 while(next_clip_box());
318 //--------------------------------------------------------------------
319 void blend_color_hspan_no_clip(int x, int y, int len,
320 const color_type* colors,
321 const cover_type* covers,
322 cover_type cover = cover_full)
324 m_ren.blend_color_hspan_no_clip(x, y, len, colors, covers, cover);
327 //--------------------------------------------------------------------
328 void blend_color_vspan_no_clip(int x, int y, int len,
329 const color_type* colors,
330 const cover_type* covers,
331 cover_type cover = cover_full)
333 m_ren.blend_color_vspan_no_clip(x, y, len, colors, covers, cover);
336 //--------------------------------------------------------------------
337 void blend_opaque_color_hspan_no_clip(int x, int y, int len,
338 const color_type* colors,
339 const cover_type* covers,
340 cover_type cover = cover_full)
342 m_ren.blend_opaque_color_hspan_no_clip(x, y, len, colors, covers, cover);
345 //--------------------------------------------------------------------
346 void blend_opaque_color_vspan_no_clip(int x, int y, int len,
347 const color_type* colors,
348 const cover_type* covers,
349 cover_type cover = cover_full)
351 m_ren.blend_opaque_color_vspan_no_clip(x, y, len, colors, covers, cover);
355 //--------------------------------------------------------------------
356 void copy_from(const rendering_buffer& from,
357 const rect* rc=0,
358 int x_to=0,
359 int y_to=0)
361 first_clip_box();
364 m_ren.copy_from(from, rc, x_to, y_to);
366 while(next_clip_box());
369 private:
370 renderer_mclip(const renderer_mclip<PixelFormat>&);
371 const renderer_mclip<PixelFormat>&
372 operator = (const renderer_mclip<PixelFormat>&);
374 base_ren_type m_ren;
375 pod_deque<rect, 4> m_clip;
376 unsigned m_curr_cb;
377 rect m_bounds;
383 #endif