00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __WXGDIPLUSDRAWER_H__
00010 #define __WXGDIPLUSDRAWER_H__
00011
00012 #ifndef WX_PRECOMP
00013 #include "wx/wx.h"
00014 #endif
00015
00016
00017 #include "a2dprivate.h"
00018
00019 #if wxART2D_USE_GDIPLUSDRAWER
00020
00021 #include <gdiplus.h>
00022
00023 #include "wx/artbase/drawer2d.h"
00024 #include "wx/artbase/stylebase.h"
00025 #include "wx/image.h"
00026 #include "wx/geometry.h"
00027
00028
00029
00030 using namespace Gdiplus;
00031
00032
00033
00034 WX_DECLARE_LIST( Region, RegionList );
00035
00036 class a2dGDIPlusDrawer : public a2dDrawer2D
00037 {
00038 public:
00039 a2dGDIPlusDrawer( int width = 100, int height = 100 );
00040 a2dGDIPlusDrawer( const wxSize &size );
00041
00042 a2dGDIPlusDrawer( const a2dGDIPlusDrawer& other );
00043
00044 virtual ~a2dGDIPlusDrawer( );
00045
00046 void Init();
00047
00048 public:
00049
00050
00051 wxBitmap GetBuffer() const { return m_buffer; }
00052
00053
00054 void SetBufferSize( int w, int h );
00055
00056
00057 wxBitmap GetSubBitmap( wxRect sub_rect ) const;
00058
00059 void CopyIntoBuffer( const wxBitmap& bitm );
00060
00061 virtual void SetTransform( const a2dAffineMatrix& userToWorld );
00062 virtual void PushTransform();
00063 virtual void PushIdentityTransform();
00064 virtual void PushTransform( const a2dAffineMatrix& affine );
00065 virtual void PopTransform( void );
00066
00067
00068 virtual void BeginDraw();
00069
00070
00071 virtual void EndDraw();
00072
00073
00074
00075
00076
00077
00078
00079 void SetRenderDC( wxDC* dc );
00080
00081 wxDC* GetDeviceDC() const { return m_deviceDC; }
00082
00083 void BlitBuffer( wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
00084
00085
00086 virtual void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
00087
00088 void ShiftBuffer( int dxy, bool yshift );
00089
00090 void ResetStyle( );
00091
00092 void SetClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
00093
00094 virtual void ExtendClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
00095
00096 virtual void ExtendAndPushClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
00097
00098 void PopClippingRegion( );
00099
00100 void SetClippingRegionDev( wxCoord minx, wxCoord miny, wxCoord width, wxCoord height );
00101
00102 void SetClippingRegion( double minx, double miny, double maxx, double maxy );
00103
00104 void DestroyClippingRegion( );
00105
00106 virtual void DrawRoundedRectangle( double x, double y, double width, double height, double radius, bool pixelsize = false );
00107
00108 virtual void DrawCircle( double x, double y, double radius );
00109
00110
00111 void DrawPoint( double xc, double yc );
00112
00113 virtual void DrawEllipse( double x, double y, double width, double height);
00114
00115 void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
00116
00117 void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
00118
00119 void SetTextBackgroundMode( int mode );
00120
00121 protected:
00122
00123 virtual void DoSetDrawStyle( a2dDrawStyle drawstyle );
00124
00125 void DoSetActiveStroke();
00126
00127 void DoSetActiveFill();
00128
00129 virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
00130
00131 virtual void DeviceDrawLines( unsigned int n, bool spline );
00132
00133 void DeviceDrawLine( double x1, double y1, double x2, double y2 );
00134
00135 void DeviceDrawHorizontalLine( int x1, int y1, int x2, bool use_stroke_color);
00136
00137 void DeviceDrawVerticalLine( int x1, int y1, int y2, bool use_stroke_color);
00138
00139 void DeviceDrawPixel( int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 );
00140
00141 virtual void DrawTextDc( const wxString& text, double x, double y );
00142
00143
00144 virtual void DrawCharStroke( wxChar c );
00145
00146 virtual void DrawCharFreetype( wxChar c );
00147
00148 virtual void DrawCharDc( wxChar c );
00149
00150 Matrix* _get_gdiplus_user_to_device_transform();
00151
00152 GdiplusStartupInput m_gdiplus_startup_input;
00153 ULONG_PTR m_gdiplus_token;
00154 Graphics *m_context;
00155
00156
00157 wxBitmap m_buffer;
00158
00159 wxMemoryDC* m_dc;
00160 RegionList m_clipping_region_stack;
00161
00162 Pen *m_current_pen;
00163 Brush *m_current_brush;
00164 Image* m_penImage;
00165 Brush* m_penBrush;
00166 Image* m_brushImage;
00167 Matrix* m_matrix;
00168 GraphicsPath* m_brushPath;
00169
00170
00171
00172 wxClientDC* m_deviceDC;
00173
00174
00175 bool m_externalDc;
00176
00177
00178 wxRegion m_clip;
00179
00180
00181
00182 GraphicsPath *createGraphicsPath( a2dVertexList *list, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
00183 };
00184
00185
00186 #endif // wxART2D_USE_GDIPLUS_DRAWER
00187
00188 #endif // __WXGDIPLUSDRAWER_H__