00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __WXAGGGRAPHICS_H__
00018 #define __WXAGGGRAPHICS_H__
00019
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023
00024
00025 #include "a2dprivate.h"
00026
00027 #if wxART2D_USE_GRAPHICS_CONTEXT
00028 #if wxART2D_USE_AGGDRAWER
00029
00030 #include "wx/artbase/artglob.h"
00031 #include "wx/artbase/stylebase.h"
00032 #include "wx/genart/imagergba.h"
00033 #include "wx/artbase/graphica.h"
00034
00035 #include "wx/aggdrawer/aggdrawer.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class a2dAggContext : public a2dContext
00047 {
00048 DECLARE_NO_COPY_CLASS(a2dAggContext)
00049
00050 public:
00051 a2dAggContext( wxGraphicsRenderer* renderer, const wxImage& drawable );
00052 a2dAggContext( wxGraphicsRenderer* renderer, a2dImageRGBA *drawable );
00053 virtual ~a2dAggContext();
00054
00055 virtual void Clip( const wxRegion ®ion );
00056
00057
00058 virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
00059
00060
00061 virtual void ResetClip();
00062
00063 virtual void Translate( wxDouble dx , wxDouble dy );
00064 virtual void Scale( wxDouble xScale , wxDouble yScale );
00065 virtual void Rotate( wxDouble angle );
00066
00067
00068 virtual void ConcatTransform( const wxGraphicsMatrix& matrix );
00069
00070
00071 virtual void SetTransform( const wxGraphicsMatrix& matrix );
00072
00073
00074 virtual wxGraphicsMatrix GetTransform() const;
00075
00076 virtual void SetDrawStyle( a2dDrawStyle drawstyle );
00077
00078 #if wxCHECK_VERSION(2,9,0)
00079 virtual void DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
00080 #else
00081 virtual void DrawGraphicsBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
00082 #endif
00083
00084 virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height,
00085 wxDouble *descent, wxDouble *externalLeading ) const;
00086 virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;
00087
00088 #if wxCHECK_VERSION(2,9,0)
00089 bool SetCompositionMode(wxCompositionMode op);
00090 #endif
00091
00092
00093 virtual bool SetLogicalFunction(int function) ;
00094
00095 virtual void DrawCharDc( wxChar c );
00096 virtual void DrawTextDc( const wxString& text, double x, double y );
00097 virtual void DrawCharStroke( wxChar c );
00098 virtual void DrawCharFreetype( wxChar c );
00099
00100 void DrawRoundedRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h, wxDouble radius);
00101 void DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h);
00102
00103 void SetPreStroke( bool preStroke ) { m_preStroke = preStroke; }
00104
00105 bool GetPreStroke() { return m_preStroke; }
00106
00107 private:
00108
00109 void Render( bool fillColor );
00110 virtual void RenderGradient( bool radial );
00111 virtual void RenderBitmapFill();
00112
00113 int ToAggPath( a2dVertexArray* points, bool transform );
00114 int ToAggPath( const a2dVertexList *list, bool transform );
00115
00116 void DrawPolygon( const a2dVertexList *list, wxPolygonFillMode fillStyle );
00117 void DrawLines( const a2dVertexList* list );
00118
00119 agg::trans_affine _get_agg_user_to_device_transform() const
00120 {
00121 return agg::trans_affine(
00122 m_usertodevice(0,0), m_usertodevice(0,1),
00123 m_usertodevice(1,0), m_usertodevice(1,1),
00124 m_usertodevice(2,0), m_usertodevice(2,1));
00125 }
00126
00127
00128 virtual void DoSetActiveStroke();
00129
00130
00131 virtual void DoSetActiveFill();
00132
00133 void DeviceDrawBitmap( const wxBitmap &bmp, double x, double y, bool useMask );
00134
00135 a2dImageRGBA* m_buffer;
00136
00137 bool m_needbufferupdate;
00138
00139 wxClientDC* m_deviceDC;
00140
00141 PixFormatA m_pixFormat;
00142 PixFormatComp m_pixFormatComp;
00143 RendererBaseA m_renBase;
00144 RendererBaseComp m_renBaseComp;
00145 RendererSolidComp m_renSolidComp;
00146 RendererSolidAaA m_renderer;
00147 agg::rasterizer_scanline_aa<> m_rasterizer;
00148 agg::comp_op_e m_blendMode;
00149
00150 template <class PathT>
00151 void _ras_add_stroked_path_xform(PathT &path, const agg::trans_affine &mtx);
00152
00153 unsigned char* m_pdata;
00154
00155 agg::rendering_buffer m_rendering_buffer;
00156
00157 double m_strokewidth;
00158 double m_strokewidthDev;
00159
00160 bool m_preStroke;
00161
00162 a2dStrokeStyle m_style;
00163
00164 agg::line_join_e m_join;
00165
00166 agg::line_cap_e m_cap;
00167
00168 wxImage m_pattern;
00169 agg::rendering_buffer m_pattern_rbuf;
00170
00171 agg::scanline_u8 m_sl;
00172
00173 void _stipple_render_scanlines( agg::rasterizer_scanline_aa<>& ras,
00174 agg::scanline_u8& sl,
00175 RendererBaseA &renb,
00176 agg::rendering_buffer pat,
00177 double alpha);
00178
00179 agg::path_storage m_path;
00180 double m_fillGradientD1;
00181 double m_lineGradientD1;
00182 double m_fillGradientD2;
00183 double m_lineGradientD2;
00184 GradientArray m_fillGradient;
00185 GradientArray m_lineGradient;
00186 agg::trans_affine m_fillGradientMatrix;
00187 agg::trans_affine m_lineGradientMatrix;
00188 agg::span_interpolator_linear<> m_fillGradientInterpolator;
00189 agg::span_interpolator_linear<> m_lineGradientInterpolator;
00190
00191 agg::gradient_x m_linearGradientFunction;
00192 agg::gradient_circle m_radialGradientFunction;
00193 };
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 class a2dGcAggDrawer : public a2dGcBaseDrawer
00204 {
00205 DECLARE_DYNAMIC_CLASS(a2dGcAggDrawer)
00206
00207 public:
00208
00209
00210 a2dGcAggDrawer( int width = 0, int height = 0 );
00211
00212
00213 a2dGcAggDrawer( const wxSize& size );
00214
00215
00216
00217 a2dGcAggDrawer( const wxBitmap& bitmap );
00218
00219 bool HasAlpha() { return true; }
00220
00221
00222 wxBitmap GetBuffer() const;
00223
00224
00225 a2dGcAggDrawer( const a2dGcAggDrawer& other );
00226
00227 a2dGcAggDrawer( const a2dDrawer2D& other );
00228
00229
00230 void SetBufferSize( int w, int h );
00231
00232
00233 wxBitmap GetSubBitmap( wxRect sub_rect ) const;
00234
00235 void CopyIntoBuffer( const wxBitmap& bitm );
00236
00237 virtual ~a2dGcAggDrawer();
00238
00239 virtual void SetYaxis( bool up );
00240
00241 void InitContext();
00242
00243 void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint(0,0) );
00244
00245 void ShiftBuffer( int dxy, bool yshift );
00246
00247 void DrawPoint( double xc, double yc );
00248
00249 void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
00250
00251 void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
00252
00253 protected:
00254
00255 void DoSetActiveStroke();
00256
00257 void DoSetActiveFill();
00258
00259 void DoSetActiveFont( const a2dFont& font );
00260
00261
00262 a2dImageRGBA m_buffer;
00263
00264 unsigned char* m_pdata;
00265 };
00266
00267 #endif
00268
00269 #endif //wxART2D_USE_GRAPHICS_CONTEXT
00270
00271 #endif