wxArt2D
gdiplusdrawer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gdiplusdrawer.h
3 // Author: Tsolakos Stavros
4 // Created: 04/30/04
5 // Copyright: 2004 (c) Tsolakos Stavros
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef __WXGDIPLUSDRAWER_H__
10 #define __WXGDIPLUSDRAWER_H__
11 
12 #ifndef WX_PRECOMP
13 #include "wx/wx.h"
14 #endif
15 
16 // where we keep all our configuration symbol (wxART2D_USE_*)
17 #include "a2dprivate.h"
18 
19 #if wxART2D_USE_GDIPLUSDRAWER
20 
21 #include <gdiplus.h>
22 
23 #include "wx/artbase/drawer2d.h"
24 #include "wx/artbase/stylebase.h"
25 #include "wx/image.h"
26 #include "wx/geometry.h"
27 
28 // We do not want to have a Gdiplus:: prefix in front
29 // of every GDI+ specific symbol.
30 using namespace Gdiplus;
31 
32 // Declare a Gdiplus::Region list. It will act as a
33 // stack that keeps clipping regions.
34 WX_DECLARE_LIST( Region, RegionList );
35 
36 class a2dGDIPlusDrawer : public a2dDrawer2D
37 {
38 public:
39  a2dGDIPlusDrawer( int width = 100, int height = 100 );
40  a2dGDIPlusDrawer( const wxSize& size );
41 
42  a2dGDIPlusDrawer( const a2dGDIPlusDrawer& other );
43 
44  virtual ~a2dGDIPlusDrawer( );
45 
46  void Init();
47 
48 public:
49 
50  //!get buffer as bitmap pointer
51  wxBitmap GetBuffer() const { return m_buffer; }
52 
53  //!set buffer size to w pixel wide and h pixels heigh
54  void SetBufferSize( int w, int h );
55 
56  //!get part of the buffer given a rect
57  wxBitmap GetSubBitmap( wxRect sub_rect ) const;
58 
59  void CopyIntoBuffer( const wxBitmap& bitm );
60 
61  virtual void SetTransform( const a2dAffineMatrix& userToWorld );
62  virtual void PushTransform();
63  virtual void PushIdentityTransform();
64  virtual void PushTransform( const a2dAffineMatrix& affine );
65  virtual void PopTransform( void );
66 
67  //!start to draw on this context (used to initialize a specific drawer)
68  virtual void BeginDraw();
69 
70  //!end drawing on this context (used to reset a specific drawer)
71  virtual void EndDraw();
72 
73  //!set the DC that is used for rendering
74  /*!Used for setting an external DC ( e.g for printing )
75  You must set an external before calling BeginDraw()
76  At the end of the printing action, you must call SetRenderDC( NULL ) to
77  Switch back to normal operation, which means the creation of a wxClientDC is handled internal.
78  */
79  void SetRenderDC( wxDC* dc );
80 
81  wxDC* GetDeviceDC() const { return m_deviceDC; }
82 
83  void BlitBuffer( wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
84 
85  //! used for blitting to a wxDC.
86  virtual void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
87 
88  void ShiftBuffer( int dxy, bool yshift );
89 
90  void ResetStyle( );
91 
92  void SetClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
93 
94  virtual void ExtendClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
95 
96  virtual void ExtendAndPushClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
97 
98  void PopClippingRegion( );
99 
100  void SetClippingRegionDev( wxCoord minx, wxCoord miny, wxCoord width, wxCoord height );
101 
102  void SetClippingRegion( double minx, double miny, double maxx, double maxy );
103 
104  void DestroyClippingRegion( );
105 
106  virtual void DrawRoundedRectangle( double x, double y, double width, double height, double radius, bool pixelsize = false );
107 
108  virtual void DrawCircle( double x, double y, double radius );
109 
110  //! draw single point
111  void DrawPoint( double xc, double yc );
112 
113  virtual void DrawEllipse( double x, double y, double width, double height );
114 
115  void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
116 
117  void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
118 
119  void SetTextBackgroundMode( int mode );
120 
121 protected:
122 
123  virtual void DoSetDrawStyle( a2dDrawStyle drawstyle );
124 
125  void DoSetActiveStroke();
126 
127  void DoSetActiveFill();
128 
129  virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
130 
131  virtual void DeviceDrawLines( unsigned int n, bool spline );
132 
133  void DeviceDrawLine( double x1, double y1, double x2, double y2 );
134 
135  void DeviceDrawHorizontalLine( int x1, int y1, int x2, bool use_stroke_color );
136 
137  void DeviceDrawVerticalLine( int x1, int y1, int y2, bool use_stroke_color );
138 
139  void DeviceDrawPixel( int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 );
140 
141  virtual void DrawTextDc( const wxString& text, double x, double y );
142 
143  // Documented in base class
144  virtual void DrawCharStroke( wxChar c );
145  // Documented in base class
146  virtual void DrawCharFreetype( wxChar c );
147  // Documented in base class
148  virtual void DrawCharDc( wxChar c );
149 
150  Matrix* _get_gdiplus_user_to_device_transform();
151 
152  GdiplusStartupInput m_gdiplus_startup_input;
153  ULONG_PTR m_gdiplus_token;
154  Graphics* m_context;
155 
156  //!the buffer that is used for rendering
157  wxBitmap m_buffer;
158  //!Created at BeginDraw, and destoyed at EndDraw, used to actually draw
159  wxMemoryDC* m_dc;
160  RegionList m_clipping_region_stack;
161 
162  Pen* m_current_pen;
163  Brush* m_current_brush;
164  Image* m_penImage;
165  Brush* m_penBrush;
166  Image* m_brushImage;
167  Matrix* m_matrix;
168  GraphicsPath* m_brushPath;
169 
170  //! wxDc to draw or blit to the device
171  /*! ( either from a blit from the buffer or drawn directly ) */
172  wxClientDC* m_deviceDC;
173 
174  //! when dc is set from the outside, this is true.
175  bool m_externalDc;
176 
177  //! clipping region.
178  wxRegion m_clip;
179 
180  // Assistant functions that perform several conversions
181  // between wxArt2d and GDI+ similar data types.
182  GraphicsPath* createGraphicsPath( a2dVertexList* list, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
183 };
184 
185 
186 #endif // wxART2D_USE_GDIPLUS_DRAWER
187 
188 #endif // __WXGDIPLUSDRAWER_H__
Stroke and fill base classes.
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
Drawing context abstraction.
Definition: drawer2d.h:177
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
Contains graphical drawing context specific classes. a2dDrawer2D and derived classes are used for dra...
a2dBooleanClip
Used for defining how a ClippingRegion defined as a polygon is combined with.
Definition: drawer2d.h:54
gdiplusdrawer.h Source File -- Sun Oct 12 2014 17:04:20 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation