wxArt2D
dcdrawer.h
Go to the documentation of this file.
1 /*! \file wx/artbase/dcdrawer.h
2 
3  \brief Contains graphical drawing context specific classes.
4  a2dDcDrawer and derived classes are used for drawing primitives.
5 
6  \author Klaas Holwerda
7 
8  Copyright: 2000-2004 (c) Klaas Holwerda
9 
10  Licence: wxWidgets Licence
11 
12  RCS-ID: $Id: dcdrawer.h,v 1.22 2009/10/06 18:40:31 titato Exp $
13 */
14 
15 #ifndef __WXDCDRAWER_H__
16 #define __WXDCDRAWER_H__
17 
18 #ifndef WX_PRECOMP
19 #include "wx/wx.h"
20 #endif
21 
22 //#include "wx/image.h"
23 //#include "wx/prntbase.h"
24 //#include <wx/module.h>
25 #include <wx/dcclient.h>
26 #include <wx/dcmemory.h>
27 
28 #include "wx/artbase/drawer2d.h"
29 
30 
31 
32 //!This class implements drawing functions for wxDC based drawing.
33 /*!
34 This class implements drawing functions for wxDC based drawing.
35 See a2dCanvasView class for documentation.
36 You must set the DC to use to draw to the device.
37 In case of a buffer you must select the bitmap into the DC yourself.
38 \sa class: a2dCanvas
39 \sa class: a2dRenderImage
40 
41  \ingroup drawer
42 */
43 class A2DARTBASEDLLEXP a2dDcDrawer : public a2dDrawer2D
44 {
45 public:
46 
47  //! Drawer having a buffer of w pixel wide and h pixels heigh
48  a2dDcDrawer( int width = 0, int height = 0 );
49 
50  //! Drawer having a buffer of w pixel wide and h pixels height given by size
51  a2dDcDrawer( const wxSize& size );
52 
53  //!set buffer size to w pixel wide and h pixels heigh
54  /*!
55  \remark
56  SetMappingDeviceRect() is NOT reset.
57  */
58  void SetBufferSize( int w, int h );
59 
60  wxBitmap GetBuffer() const { return wxBitmap( 0, 0 ); }
61 
62  //!get part of the buffer given a rect
63  wxBitmap GetSubBitmap( wxRect sub_rect ) const;
64 
65  //!destructor
66  virtual ~a2dDcDrawer();
67 
68  //!copy constructor
69  a2dDcDrawer( const a2dDcDrawer& other );
70 
71  a2dDcDrawer( const a2dDrawer2D& other );
72 
73  virtual void BlitBuffer( wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
74 
75  virtual void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
76 
77  void ResetStyle();
78 
79  //!start to draw on this context (used to initialize a specific drawer)
80  virtual void BeginDraw();
81 
82  //!end drawing on this context (used to reset a specific drawer)
83  virtual void EndDraw();
84 
85  //!get the DC that is used for rendering
86  virtual wxDC* GetRenderDC() const { return m_renderDC; }
87 
88  //!set the DC that is used for rendering
89  /*!Used for setting an external DC ( e.g for printing )
90  You must set an external before calling BeginDraw()
91  At the end of the printing action, you must call SetRenderDC( NULL ) to
92  Switch back to normal operation, which means the creation of a wxClientDC is handled internal.
93  */
94  void SetRenderDC( wxDC* dc );
95 
96  wxDC* GetDeviceDC() const { return m_deviceDC; }
97 
98  void SetClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
99 
100  virtual void ExtendClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
101 
102  virtual void ExtendAndPushClippingRegion( a2dVertexList* points, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE, a2dBooleanClip clipoperation = a2dCLIP_AND );
103 
104  void PopClippingRegion();
105 
106  void SetClippingRegionDev( wxCoord minx, wxCoord miny, wxCoord width, wxCoord height );
107  void SetClippingRegion( double minx, double miny, double maxx, double maxy );
108  void DestroyClippingRegion();
109 
110  //! Draw a wxImage in world coordinates.
111  /*! Currently this implementation does not handle rotated transformations properly.
112  */
113  void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
114 
115  void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
116 
117  void DrawRoundedRectangle( double x, double y, double width, double height, double radius, bool pixelsize = false );
118 
119  //more speedy then base, by directly converting to device coordinates.
120  void DrawVpath( const a2dVpath* path );
121 
122  void DrawPolyPolygon( a2dListOfa2dVertexList polylist, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
123 
124  // Documented in base class.
125  void DrawCircle( double xc, double yc, double radius );
126 
127  void DrawEllipse( double xc, double yc, double width, double height );
128 
129  void DrawLine( double x1, double y1, double x2, double y2 );
130 
131  //! draw single point
132  void DrawPoint( double xc, double yc );
133 
134  virtual void DeviceDrawAnnotation( const wxString& text, wxCoord x, wxCoord y, const wxFont& font );
135 
136 protected:
137 
138  virtual void DoSetDrawStyle( a2dDrawStyle drawstyle );
139 
140  void DoSetActiveStroke();
141 
142  void DoSetActiveFill();
143 
144  //internal drawing of polygons
145  virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
146 
147  //internal drawing of polylines
148  virtual void DeviceDrawLines( unsigned int n, bool spline );
149 
150  void DeviceDrawLine( double x1, double y1, double x2, double y2 );
151 
152  void DeviceDrawHorizontalLine( int x1, int y1, int x2, bool use_stroke_color );
153 
154  void DeviceDrawVerticalLine( int x1, int y1, int y2, bool use_stroke_color );
155 
156  void DeviceDrawPixel( int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a );
157 
158  //!in pixels
159  void DeviceDrawBitmap( const wxBitmap& bmp, double x, double y,
160  bool useMask = false );
161 
162  void SetLogicalFunction( wxRasterOperationMode function );
163 
164  // Documented in base class
165  virtual void DrawCharDc( wxChar c );
166  // Documented in base class
167  virtual void DrawTextDc( const wxString& text, double x, double y );
168 
169  // Documented in base class
170  virtual void DrawCharFreetype( wxChar c );
171 
172  //!The DC to use to draw to the device or buffer ( depends on type of a2dCanvasView )
173  /*!In case of a m_buffer you must select the bitmap into the DC yourself. */
174  wxDC* m_renderDC;
175 
176  //! wxDc to draw or blit to the device
177  /*! ( either from a blit from the buffer or drawn directly ) */
178  wxClientDC* m_deviceDC;
179 
180  //! when dc is set from the outside, this is true.
182 
183 private:
184  //! clipping region.
185  wxRegion m_clip;
186 
187  DECLARE_DYNAMIC_CLASS( a2dDcDrawer )
188 };
189 
190 
191 //!This class implements drawing functions for wxDC based drawing.
192 /*!
193 It uses a bitmap buffer to do double buffering.
194 See a2dCanvasView class for more documentation.
195 To start drawing you must call BeginDraw at when stopping drawing you must call EndDraw.
196 This will takes care of setting and releasing the wxMemoryDC used internal, and keeps your code
197 "a2dCanvasView type" independent.
198 \sa class: a2dCanvas
199 \sa class: a2dRenderImage
200 
201  \ingroup drawer
202 */
203 class A2DARTBASEDLLEXP a2dMemDcDrawer : public a2dDcDrawer
204 {
205 public:
206 
207  //!constructor ( just some default )
208  a2dMemDcDrawer( int width = 0, int height = 0 );
209 
210  //! Drawer having a buffer of w pixel wide and h pixels height given by size
211  a2dMemDcDrawer( const wxSize& size );
212 
213  //!start to draw on this context (used to initialize a specific drawer)
214  virtual void BeginDraw();
215 
216  //!end drawing on this context (used to reset a specific drawer)
217  virtual void EndDraw();
218 
219  //!return buffer as a bitmap
220  wxBitmap GetBuffer() const {return m_buffer;}
221 
222  //! change the size of the buffer
223  void SetBufferSize( int w, int h );
224 
225  //!return a bitmap representing a rectangular part of the buffer
226  wxBitmap GetSubBitmap( wxRect sub_rect ) const;
227 
228  //!destructor
229  virtual ~a2dMemDcDrawer();
230 
231  //!copy constructor
232  a2dMemDcDrawer( const a2dMemDcDrawer& other );
233 
234  //! Draw a wxImage in world coordinates.
235  /*! Use AggDrawer when available.
236  */
237  void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
238 
239  void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
240 
241  void CopyIntoBuffer( const wxBitmap& bitm );
242 
243  virtual void BlitBuffer( wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
244 
245  virtual void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
246 
247  virtual void ShiftBuffer( int dxy, bool yshift );
248 
249 protected:
250 
251  virtual void DrawTextFreetype( const wxString& text, double x, double y );
252 
253 #if wxART2D_USE_FREETYPE
254  //! draw one character into screen buffer, at the position (x,y).
255  void DrawCharFreetype( wxColour col, wxChar c, int x, int y, FT_Matrix trans_matrix, FT_Vector vec );
256 #endif
257  virtual void DrawCharFreetype( wxChar c );
258 
259  virtual void DrawPolygon( const a2dVertexList* list, bool spline = false, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
260 
261  virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
262 
263  //!the buffer that is used for rendering
264  wxBitmap m_buffer;
265 
266  //!Created at BeginDraw, and destoyed at EndDraw, used to actually draw
267  wxMemoryDC* m_memdc;
268 
269  // internally used in methods. Create/ delete of these is very expensive
270  mutable wxMemoryDC m_mdc1, m_mdc2;
271 #if defined(__WXMSW__)
272  HDC m_hdc1, m_hdc2;
273 #endif
274 
275 private:
276 
277  DECLARE_DYNAMIC_CLASS( a2dMemDcDrawer )
278 };
279 
280 #if wxART2D_USE_GRAPHICS_CONTEXT
281 
282 //! wxGraphicsContext based drawing context derived from a2dDrawer2D
283 /*!
284  Use wxGraphicsContext from wxWidgets to draw.
285 
286  \ingroup drawer
287 */
288 class a2dGcDrawer : public a2dGcBaseDrawer
289 {
290  DECLARE_DYNAMIC_CLASS( a2dGcDrawer )
291 
292 public:
293 
294  //! Drawer having a buffer of w pixel wide and h pixels heigh
295  a2dGcDrawer( int width = 0, int height = 0 );
296 
297  //! Drawer having a buffer of w pixel wide and h pixels height given by size
298  a2dGcDrawer( const wxSize& size );
299 
300  //! bitmap is converted to image on which you can draw.
301  //! Use GetBuffer() to get a bitmap back.
302  a2dGcDrawer( const wxBitmap& bitmap );
303 
304  //!return buffer as a bitmap
305  wxBitmap GetBuffer() const;
306 
307  //! copy constructor
308  a2dGcDrawer( const a2dGcDrawer& other );
309 
310  a2dGcDrawer( const a2dDrawer2D& other );
311 
312  //!set buffer size to w pixel wide and h pixels heigh
313  void SetBufferSize( int w, int h );
314 
315  //!get part of the buffer given a rect
316  wxBitmap GetSubBitmap( wxRect sub_rect ) const;
317 
318  virtual ~a2dGcDrawer();
319 
320  //!start to draw on this context (used to initialize a specific drawer)
321  virtual void BeginDraw();
322 
323  //!end drawing on this context (used to reset a specific drawer)
324  virtual void EndDraw();
325 
326  virtual void SetYaxis( bool up );
327 
328  void InitContext();
329 
330  void BlitBuffer( wxDC* dc, wxRect rect, const wxPoint& bufferpos = wxPoint( 0, 0 ) );
331 
332  void ShiftBuffer( int dxy, bool yshift );
333 
334  void DrawPoint( double xc, double yc );
335 
336  void DrawImage( const wxImage& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
337 
338  void DrawImage( const a2dImageRGBA& image, double x, double y, double width, double height, wxUint8 Opacity = 255 );
339 
340 protected:
341 
342  void DoSetActiveStroke();
343 
344  void DoSetActiveFill();
345 
346  void DoSetActiveFont( const a2dFont& font );
347 
348  //!the buffer that is used for rendering
349  wxBitmap m_buffer;
350 
351  //!Created at BeginDraw, and destoyed at EndDraw, used to actually draw
352  wxMemoryDC m_memdc;
353 
354  //! when dc is set from the outside, this is true.
355  bool m_externalDc;
356 };
357 
358 #endif // wxART2D_USE_GRAPHICS_CONTEXT
359 
360 
361 #endif /* __WXDCDRAWER_H__ */
362 
virtual void ExtendClippingRegion(a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE, a2dBooleanClip clipoperation=a2dCLIP_AND)=0
extend clipping region with a polygon to which everything drawn will be clipped.
virtual void DeviceDrawPixel(int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
draw a single, unstroked pixel in device coordinates with the given color
Definition: drawer2d.cpp:3100
wxBitmap GetBuffer() const
Return the buffer as a bitmap.
Definition: dcdrawer.h:60
virtual void DrawVpath(const a2dVpath *path)
Draw vector path in world coordinates.
Definition: drawer2d.cpp:1568
void SetBufferSize(int w, int h)
set buffer size to w pixel wide and h pixels heigh
Definition: dcdrawer.cpp:216
virtual void DestroyClippingRegion()=0
set clipping region off
virtual void BeginDraw()
start to draw on this context (used to initialize a specific drawer)
Definition: dcdrawer.cpp:160
Defines a font to be set to a2dDrawer2D or stored in a2dCanvsObject etc.
Definition: stylebase.h:779
virtual void DrawPolygon(a2dVertexArray *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
Draw polygon in world coordinates using pointarray.
Definition: drawer2d.cpp:1889
This class implements drawing functions for wxDC based drawing.
Definition: dcdrawer.h:43
This class implements drawing functions for wxDC based drawing.
Definition: dcdrawer.h:203
virtual void DrawCharFreetype(wxChar c)
Draw a freetype character.
Definition: dcdrawer.cpp:2309
wxBitmap GetBuffer() const
return buffer as a bitmap
Definition: dcdrawer.h:220
vertex list of line and arc segments.
Definition: polyver.h:600
virtual void DeviceDrawVerticalLine(int x1, int y1, int y2, bool use_stroke_color)
Draw a pixel-width, unstroked vertical line in device (pixel) coordinates.
Definition: drawer2d.cpp:3095
a2dDrawStyle
Define the manner in which a2dCanvasView draws to the device.
Definition: artglob.h:280
virtual wxBitmap GetSubBitmap(wxRect sub_rect) const =0
A way to get parts form the buffer that is drawn into.
virtual void DrawRoundedRectangle(double x, double y, double width, double height, double radius, bool pixelsize=false)
Draw RoundedRectangle in world coordinates.
Definition: drawer2d.cpp:2048
virtual void ResetStyle()
set a pre-defined style reseting cashed values.
Definition: drawer2d.cpp:545
virtual void DrawCharDc(wxChar c)
Draw a dc character.
Definition: drawer2d.h:981
virtual void DrawPoint(double xc, double yc)=0
draw a single point
wxDC * m_renderDC
The DC to use to draw to the device or buffer ( depends on type of a2dCanvasView ) ...
Definition: dcdrawer.h:174
virtual void DrawPolyPolygon(a2dListOfa2dVertexList polylist, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
draw a list of polygons ( contour clockwise becomes hole )
Definition: drawer2d.cpp:1881
Drawing context abstraction.
Definition: drawer2d.h:177
virtual void DrawImage(const wxImage &image, double x, double y, double width, double height, wxUint8 Opacity=255)=0
Draw wxImage in world coordinates.
wxBitmap GetSubBitmap(wxRect sub_rect) const
get part of the buffer given a rect
Definition: dcdrawer.cpp:222
virtual void ShiftBuffer(int dxy, bool yshift)
quick scroll over small distance
Definition: drawer2d.h:271
virtual void DrawTextFreetype(const wxString &text, double x, double y)
Draw text in world coordinates, based on a freetype font .
Definition: drawer2d.h:972
virtual void DoSetActiveStroke()=0
per drawer implementation
virtual void DrawLine(double x1, double y1, double x2, double y2)
Draw line in world coordinates.
Definition: drawer2d.cpp:2167
virtual void DoSetActiveFill()=0
per drawer implementation
wxDC * GetDeviceDC() const
get the DC that is used for rendering
Definition: dcdrawer.h:96
virtual void DeviceDrawLine(double x1, double y1, double x2, double y2)
draw in pixels
Definition: drawer2d.cpp:3085
virtual void DrawTextDc(const wxString &text, double x, double y)
Draw text in user coordinates, based on a dc font .
Definition: drawer2d.h:987
wxMemoryDC * m_memdc
Created at BeginDraw, and destoyed at EndDraw, used to actually draw.
Definition: dcdrawer.h:267
virtual void ExtendAndPushClippingRegion(a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE, a2dBooleanClip clipoperation=a2dCLIP_AND)=0
push on stack the current clipping region and extend clipping region
virtual void SetClippingRegion(a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)=0
set clipping region from polygon to which everything drawn will be clipped.
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
wxClientDC * m_deviceDC
wxDc to draw or blit to the device
Definition: dcdrawer.h:178
virtual void DrawCharFreetype(wxChar c)
Draw a freetype character.
Definition: drawer2d.h:966
virtual void SetClippingRegionDev(wxCoord minx, wxCoord miny, wxCoord maxx, wxCoord maxy)=0
set clipping region using x y values in device coordinates
virtual wxDC * GetRenderDC() const
get the DC that is used for rendering
Definition: dcdrawer.h:86
virtual void BeginDraw()=0
start to draw on this context (used to initialize a specific drawer)
virtual void DeviceDrawPolygon(unsigned int n, bool spline, wxPolygonFillMode fillStyle)
draw an internal polygon in device coordinates
Definition: drawer2d.cpp:3075
virtual void DeviceDrawAnnotation(const wxString &text, wxCoord x, wxCoord y, const wxFont &font)
text drawn in device coordinates
Definition: drawer2d.h:672
void BlitBuffer()
blit whole buffer to device
Definition: drawer2d.cpp:183
virtual void PopClippingRegion()=0
pop a previously pushed clipping region
bool m_externalDc
when dc is set from the outside, this is true.
Definition: dcdrawer.h:181
wxBitmap m_buffer
the buffer that is used for rendering
Definition: dcdrawer.h:264
virtual void EndDraw()=0
end drawing on this context (used to reset a specific drawer)
virtual void DrawEllipse(double x, double y, double width, double height)
Draw Ellipse in world coordinates.
Definition: drawer2d.cpp:2121
virtual void SetBufferSize(int w, int h)=0
Change the buffer size.
virtual void DrawCircle(double x, double y, double radius)
Draw Circle in world coordinates.
Definition: drawer2d.cpp:2116
void DrawImage(const wxImage &image, double x, double y, double width, double height, wxUint8 Opacity=255)
Draw a wxImage in world coordinates.
Definition: dcdrawer.cpp:840
Vector Path.
Definition: polyver.h:1211
virtual void DeviceDrawPolygon(unsigned int n, bool spline, wxPolygonFillMode fillStyle)
draw an internal polygon in device coordinates
Definition: dcdrawer.cpp:1771
virtual void DeviceDrawHorizontalLine(int x1, int y1, int x2, bool use_stroke_color)
Draw a pixel-width, unstroked horizontal line in device (pixel) coordinates.
Definition: drawer2d.cpp:3090
virtual void EndDraw()
end drawing on this context (used to reset a specific drawer)
Definition: dcdrawer.cpp:192
virtual void DeviceDrawLines(unsigned int n, bool spline)
draw an internal polyline in device coordinates
Definition: drawer2d.cpp:3080
dcdrawer.h Source File -- Sun Oct 12 2014 17:04:15 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation