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_primitives
18 //----------------------------------------------------------------------------
20 #ifndef AGG_RENDERER_PRIMITIVES_INCLUDED
21 #define AGG_RENDERER_PRIMITIVES_INCLUDED
23 #include "agg_basics.h"
24 #include "agg_renderer_base.h"
25 #include "agg_dda_line.h"
26 #include "agg_ellipse_bresenham.h"
30 //-----------------------------------------------------renderer_primitives
31 template<class BaseRenderer
> class renderer_primitives
34 typedef BaseRenderer base_ren_type
;
35 typedef typename
base_ren_type::color_type color_type
;
37 //--------------------------------------------------------------------
38 renderer_primitives(base_ren_type
& ren
) :
45 void attach(base_ren_type
& ren
) { m_ren
= &ren
; }
47 //--------------------------------------------------------------------
48 static int coord(double c
)
50 return iround(c
* line_bresenham_interpolator::subpixel_scale
);
53 //--------------------------------------------------------------------
54 void fill_color(const color_type
& c
) { m_fill_color
= c
; }
55 void line_color(const color_type
& c
) { m_line_color
= c
; }
56 const color_type
& fill_color() const { return m_fill_color
; }
57 const color_type
& line_color() const { return m_line_color
; }
59 //--------------------------------------------------------------------
60 void rectangle(int x1
, int y1
, int x2
, int y2
)
62 m_ren
->blend_hline(x1
, y1
, x2
-1, m_line_color
, cover_full
);
63 m_ren
->blend_vline(x2
, y1
, y2
-1, m_line_color
, cover_full
);
64 m_ren
->blend_hline(x1
+1, y2
, x2
, m_line_color
, cover_full
);
65 m_ren
->blend_vline(x1
, y1
+1, y2
, m_line_color
, cover_full
);
68 //--------------------------------------------------------------------
69 void solid_rectangle(int x1
, int y1
, int x2
, int y2
)
71 m_ren
->blend_bar(x1
, y1
, x2
, y2
, m_fill_color
, cover_full
);
74 //--------------------------------------------------------------------
75 void outlined_rectangle(int x1
, int y1
, int x2
, int y2
)
77 rectangle(x1
, y1
, x2
, y2
);
78 m_ren
->blend_bar(x1
+1, y1
+1, x2
-1, y2
-1, m_fill_color
, cover_full
);
81 //--------------------------------------------------------------------
82 void ellipse(int x
, int y
, int rx
, int ry
)
84 ellipse_bresenham_interpolator
ei(rx
, ry
);
91 m_ren
->blend_pixel(x
+ dx
, y
+ dy
, m_line_color
, cover_full
);
92 m_ren
->blend_pixel(x
+ dx
, y
- dy
, m_line_color
, cover_full
);
93 m_ren
->blend_pixel(x
- dx
, y
- dy
, m_line_color
, cover_full
);
94 m_ren
->blend_pixel(x
- dx
, y
+ dy
, m_line_color
, cover_full
);
100 //--------------------------------------------------------------------
101 void solid_ellipse(int x
, int y
, int rx
, int ry
)
103 ellipse_bresenham_interpolator
ei(rx
, ry
);
116 m_ren
->blend_hline(x
-dx0
, y
+dy0
, x
+dx0
, m_fill_color
, cover_full
);
117 m_ren
->blend_hline(x
-dx0
, y
-dy0
, x
+dx0
, m_fill_color
, cover_full
);
124 m_ren
->blend_hline(x
-dx0
, y
+dy0
, x
+dx0
, m_fill_color
, cover_full
);
127 //--------------------------------------------------------------------
128 void outlined_ellipse(int x
, int y
, int rx
, int ry
)
130 ellipse_bresenham_interpolator
ei(rx
, ry
);
139 m_ren
->blend_pixel(x
+ dx
, y
+ dy
, m_line_color
, cover_full
);
140 m_ren
->blend_pixel(x
+ dx
, y
- dy
, m_line_color
, cover_full
);
141 m_ren
->blend_pixel(x
- dx
, y
- dy
, m_line_color
, cover_full
);
142 m_ren
->blend_pixel(x
- dx
, y
+ dy
, m_line_color
, cover_full
);
146 m_ren
->blend_hline(x
-dx
+1, y
+dy
, x
+dx
-1, m_fill_color
, cover_full
);
147 m_ren
->blend_hline(x
-dx
+1, y
-dy
, x
+dx
-1, m_fill_color
, cover_full
);
154 //--------------------------------------------------------------------
155 void line(int x1
, int y1
, int x2
, int y2
, bool last
=false)
157 line_bresenham_interpolator
li(x1
, y1
, x2
, y2
);
159 unsigned len
= li
.len();
164 m_ren
->blend_pixel(li
.line_lr(x1
), li
.line_lr(y1
), m_line_color
, cover_full
);
175 m_ren
->blend_pixel(li
.x2(), li
.y1(), m_line_color
, cover_full
);
184 m_ren
->blend_pixel(li
.x1(), li
.y2(), m_line_color
, cover_full
);
191 //--------------------------------------------------------------------
192 void move_to(int x
, int y
)
198 //--------------------------------------------------------------------
199 void line_to(int x
, int y
, bool last
=false)
201 line(m_curr_x
, m_curr_y
, x
, y
, last
);
206 //--------------------------------------------------------------------
207 const base_ren_type
& ren() const { return *m_ren
; }
208 base_ren_type
& ren() { return *m_ren
; }
210 //--------------------------------------------------------------------
211 const rendering_buffer
& rbuf() const { return m_ren
->rbuf(); }
212 rendering_buffer
& rbuf() { return m_ren
->rbuf(); }
215 base_ren_type
* m_ren
;
216 color_type m_fill_color
;
217 color_type m_line_color
;