wxArt2D
graphicagg.h
1 /*! \file wx/aggdrawer/aggdrawer.h
2 
3  \brief the antigrain based drawing context derived from a2dDrawer2D
4 
5  This drawing context does anti aliased and alpha drawing. And uses a wxImage as a buffer.
6  A strong feature is the ability to draw (rotated) wxImage's
7 
8  \author Klaas Holwerda
9 
10  Copyright: 2000-2004 (c) Klaas Holwerda
11 
12  Licence: wxWidgets Licence
13 
14  RCS-ID: $Id: graphicagg.h,v 1.11 2009/10/06 18:40:31 titato Exp $
15 */
16 
17 #ifndef __WXAGGGRAPHICS_H__
18 #define __WXAGGGRAPHICS_H__
19 
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif
23 
24 // where we keep all our configuration symbol (wxART2D_USE_*)
25 #include "a2dprivate.h"
26 
27 #if wxART2D_USE_GRAPHICS_CONTEXT
28 #if wxART2D_USE_AGGDRAWER
29 
30 #include "wx/artbase/artglob.h"
31 #include "wx/artbase/stylebase.h"
32 #include "wx/genart/imagergba.h"
33 #include "wx/artbase/graphica.h"
34 
35 #include "wx/aggdrawer/aggdrawer.h"
36 
37 
38 //! wxGraphicsContext based drawing context.
39 /*!
40  Use a2dAggContext derived from a2dContext and therefore wxGraphicsContext from wxWidgets to draw.
41 
42  a2dContext uses a2dFill, a2dStroke, a2dVpath for storing the brush,pen and path data.
43 
44  \ingroup drawer
45 */
46 class a2dAggContext : public a2dContext
47 {
48  DECLARE_NO_COPY_CLASS( a2dAggContext )
49 
50 public:
51  a2dAggContext( wxGraphicsRenderer* renderer, const wxImage& drawable );
52  a2dAggContext( wxGraphicsRenderer* renderer, a2dImageRGBA* drawable );
53  virtual ~a2dAggContext();
54 
55  virtual void Clip( const wxRegion& region );
56 
57  // clips drawings to the rect
58  virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
59 
60  // resets the clipping to original extent
61  virtual void ResetClip();
62 
63  virtual void Translate( wxDouble dx , wxDouble dy );
64  virtual void Scale( wxDouble xScale , wxDouble yScale );
65  virtual void Rotate( wxDouble angle );
66 
67  // concatenates this transform with the current transform of this context
68  virtual void ConcatTransform( const wxGraphicsMatrix& matrix );
69 
70  // sets the transform of this context
71  virtual void SetTransform( const wxGraphicsMatrix& matrix );
72 
73  // gets the matrix of this context
74  virtual wxGraphicsMatrix GetTransform() const;
75 
76  virtual void SetDrawStyle( a2dDrawStyle drawstyle );
77 
78 #if wxCHECK_VERSION(2,9,0)
79  virtual void DrawBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
80 #else
81  virtual void DrawGraphicsBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
82 #endif
83 
84  virtual void GetTextExtent( const wxString& str, wxDouble* width, wxDouble* height,
85  wxDouble* descent, wxDouble* externalLeading ) const;
86  virtual void GetPartialTextExtents( const wxString& text, wxArrayDouble& widths ) const;
87 
88 #if wxCHECK_VERSION(2,9,0)
89  bool SetCompositionMode( wxCompositionMode op );
90 #endif
91 
92  // sets the current logical function, returns true if it supported
93  virtual bool SetLogicalFunction( int function ) ;
94 
95  virtual void DrawCharDc( wxChar c );
96  virtual void DrawTextDc( const wxString& text, double x, double y );
97  virtual void DrawCharStroke( wxChar c );
98  virtual void DrawCharFreetype( wxChar c );
99 
100  void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius );
101  void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
102 
103  void SetPreStroke( bool preStroke ) { m_preStroke = preStroke; }
104 
105  bool GetPreStroke() { return m_preStroke; }
106 
107 private:
108 
109  void Render( bool fillColor );
110  virtual void RenderGradient( bool radial );
111  virtual void RenderBitmapFill();
112 
113  int ToAggPath( a2dVertexArray* points, bool transform );
114  int ToAggPath( const a2dVertexList* list, bool transform );
115 
116  void DrawPolygon( const a2dVertexList* list, wxPolygonFillMode fillStyle );
117  void DrawLines( const a2dVertexList* list );
118 
119  agg::trans_affine _get_agg_user_to_device_transform() const
120  {
121  return agg::trans_affine(
122  m_usertodevice( 0, 0 ), m_usertodevice( 0, 1 ),
123  m_usertodevice( 1, 0 ), m_usertodevice( 1, 1 ),
124  m_usertodevice( 2, 0 ), m_usertodevice( 2, 1 ) );
125  }
126 
127  //! per drawer implementation
128  virtual void DoSetActiveStroke();
129 
130  //! per drawer implementation
131  virtual void DoSetActiveFill();
132 
133  void DeviceDrawBitmap( const wxBitmap& bmp, double x, double y, bool useMask );
134 
135  a2dImageRGBA* m_buffer;
136 
137  bool m_needbufferupdate;
138 
139  wxClientDC* m_deviceDC;
140 
141  PixFormatA m_pixFormat;
142  PixFormatComp m_pixFormatComp;
143  RendererBaseA m_renBase;
144  RendererBaseComp m_renBaseComp;
145  RendererSolidComp m_renSolidComp;
146  RendererSolidAaA m_renderer;
147  agg::rasterizer_scanline_aa<> m_rasterizer;
148  agg::comp_op_e m_blendMode;
149 
150  template <class PathT>
151  void _ras_add_stroked_path_xform( PathT& path, const agg::trans_affine& mtx );
152 
153  unsigned char* m_pdata;
154 
155  agg::rendering_buffer m_rendering_buffer;
156 
157  double m_strokewidth;
158  double m_strokewidthDev;
159 
160  bool m_preStroke;
161 
162  a2dStrokeStyle m_style;
163 
164  agg::line_join_e m_join;
165 
166  agg::line_cap_e m_cap;
167 
168  wxImage m_pattern;
169  agg::rendering_buffer m_pattern_rbuf;
170 
171  agg::scanline_u8 m_sl;
172 
173  void _stipple_render_scanlines( agg::rasterizer_scanline_aa<>& ras,
174  agg::scanline_u8& sl,
175  RendererBaseA& renb,
176  agg::rendering_buffer pat,
177  double alpha );
178 
179  agg::path_storage m_path;
180  double m_fillGradientD1;
181  double m_lineGradientD1;
182  double m_fillGradientD2;
183  double m_lineGradientD2;
184  GradientArray m_fillGradient;
185  GradientArray m_lineGradient;
186  agg::trans_affine m_fillGradientMatrix;
187  agg::trans_affine m_lineGradientMatrix;
188  agg::span_interpolator_linear<> m_fillGradientInterpolator;
189  agg::span_interpolator_linear<> m_lineGradientInterpolator;
190 
191  agg::gradient_x m_linearGradientFunction;
192  agg::gradient_circle m_radialGradientFunction;
193 };
194 
195 //! Drawing context derived from a2dDrawer2D
196 /*!
197  Uses a2dAggContext internal, which is derived from a2dContext and therefore wxGraphicsContext from wxWidgets to draw.
198 
199  a2dContext uses a2dFill, a2dStroke, a2dVpath for storing the brush,pen and path data.
200 
201  \ingroup drawer
202 */
203 class a2dGcAggDrawer : public a2dGcBaseDrawer
204 {
205  DECLARE_DYNAMIC_CLASS( a2dGcAggDrawer )
206 
207 public:
208 
209  //! Drawer having a buffer of w pixel wide and h pixels heigh
210  a2dGcAggDrawer( int width = 0, int height = 0 );
211 
212  //! Drawer having a buffer of w pixel wide and h pixels height given by size
213  a2dGcAggDrawer( const wxSize& size );
214 
215  //! bitmap is converted to image on which you can draw.
216  //! Use GetBuffer() to get a bitmap back.
217  a2dGcAggDrawer( const wxBitmap& bitmap );
218 
219  bool HasAlpha() { return true; }
220 
221  //!return buffer as a bitmap
222  wxBitmap GetBuffer() const;
223 
224  //! copy constructor
225  a2dGcAggDrawer( const a2dGcAggDrawer& other );
226 
227  a2dGcAggDrawer( const a2dDrawer2D& other );
228 
229  //!set buffer size to w pixel wide and h pixels heigh
230  void SetBufferSize( int w, int h );
231 
232  //!get part of the buffer given a rect
233  wxBitmap GetSubBitmap( wxRect sub_rect ) const;
234 
235  void CopyIntoBuffer( const wxBitmap& bitm );
236 
237  virtual ~a2dGcAggDrawer();
238 
239  virtual void SetYaxis( bool up );
240 
241  void InitContext();
242 
243  void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
244 
245  void ShiftBuffer( int dxy, bool yshift );
246 
247  void DrawPoint( double xc, double yc );
248 
249  void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
250 
251  void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
252 
253 protected:
254 
255  void DoSetActiveStroke();
256 
257  void DoSetActiveFill();
258 
259  void DoSetActiveFont( const a2dFont& font );
260 
261  //!the buffer that is used for rendering
262  a2dImageRGBA m_buffer;
263 
264  unsigned char* m_pdata;
265 };
266 
267 #endif
268 
269 #endif //wxART2D_USE_GRAPHICS_CONTEXT
270 
271 #endif
Stroke and fill base classes.
agg::renderer_scanline_aa_solid< RendererBaseA > RendererSolidAaA
solid rendering on top of base rendering Agg
Definition: aggdrawer.h:141
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
vertex array of line and arc segments.
Definition: polyver.h:494
vertex list of line and arc segments.
Definition: polyver.h:600
a2dDrawStyle
Define the manner in which a2dCanvasView draws to the device.
Definition: artglob.h:280
classes for initializing the artbase modules, and set paths to be used for fonts etc.
the antigrain based drawing context derived from a2dDrawer2D
Drawing context abstraction.
Definition: drawer2d.h:177
agg::renderer_base< PixFormatA > RendererBaseA
base rendering Agg
Definition: aggdrawer.h:138
the wxGraphicContext based drawing context
agg::pixfmt_rgba32 PixFormatA
color format in a2dAggDrawer
Definition: aggdrawer.h:132
Contains image with RGBA per pixel.
a2dStrokeStyle
stroke styles for a2dStroke
Definition: stylebase.h:298
graphicagg.h Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation