wxArt2D
graphica.h
Go to the documentation of this file.
1 /*! \file wx/artbase/graphica.h
2 
3  \brief the wxGraphicContext based drawing context
4 
5  Vector path drawing the wx way.
6 
7  \author Klaas Holwerda
8 
9  Copyright: 2000-2004 (c) Klaas Holwerda
10 
11  Licence: wxWidgets Licence
12 
13  RCS-ID: $Id: graphica.h,v 1.10 2009/10/06 18:40:31 titato Exp $
14 */
15 
16 #ifndef __WXGRAPHICSA_H__
17 #define __WXGRAPHICSA_H__
18 
19 // where we keep all our configuration symbol (wxART2D_USE_*)
20 #include "a2dprivate.h"
21 
22 #if wxART2D_USE_GRAPHICS_CONTEXT
23 
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif
27 
28 #include "wx/dcprint.h"
29 
30 #include "wx/graphics.h"
31 #if wxCHECK_VERSION(2, 9, 0)
32 #include "graphics.h"
33 #endif
34 
35 #include "wx/artbase/artglob.h"
36 #include "wx/artbase/stylebase.h"
37 #include "wx/genart/imagergba.h"
38 #include "wx/artbase/polyver.h"
39 
40 #include <vector>
41 
42 class a2dStrokeData : public wxGraphicsObjectRefData
43 {
44 public:
45  a2dStrokeData( wxGraphicsRenderer* renderer = 0, const wxPen& pen = wxNullPen );
46  a2dStrokeData( wxGraphicsRenderer* renderer, const a2dStroke& stroke );
47  ~a2dStrokeData();
48 
49  void Init();
50 
51  virtual void Apply( wxGraphicsContext* context );
52  virtual wxDouble GetWidth() { return m_stroke.GetWidth(); }
53 
54 private :
55 
56  a2dStroke m_stroke;
57 };
58 
59 class a2dFillData : public wxGraphicsObjectRefData
60 {
61 public:
62  a2dFillData( wxGraphicsRenderer* renderer = 0 );
63  a2dFillData( wxGraphicsRenderer* renderer, const wxBrush& brush );
64  a2dFillData( wxGraphicsRenderer* renderer, const a2dFill& fill );
65  ~a2dFillData ();
66 
67  virtual void Apply( wxGraphicsContext* context );
68 
69 
70 #if wxCHECK_VERSION(2, 9, 1)
71  void CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
72  const wxGraphicsGradientStops& stops );
73  void CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
74  const wxGraphicsGradientStops& stops );
75 #else
76  void CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
77  const wxColour& c1, const wxColour& c2 );
78  void CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
79  const wxColour& oColor, const wxColour& cColor );
80 #endif
81 
82 
83 protected:
84  virtual void Init();
85 
86 private :
87 
88  a2dFill m_fill;
89 
90 };
91 
92 class a2dFontData : public wxGraphicsObjectRefData
93 {
94 public:
95  a2dFontData( wxGraphicsRenderer* renderer, const wxFont& font, const wxColour& col );
96  a2dFontData( wxGraphicsRenderer* renderer, const a2dFont& font );
97  ~a2dFontData();
98 
99  virtual void Apply( wxGraphicsContext* context );
100 private :
101 
102  a2dFont m_font;
103 };
104 
105 class a2dBitmapData : public wxGraphicsObjectRefData
106 {
107 public:
108  a2dBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp );
109  a2dBitmapData( wxGraphicsRenderer* renderer, const wxImage& image );
110  a2dBitmapData( wxGraphicsRenderer* renderer, const wxGraphicsBitmap& a2dbitmap );
111  ~a2dBitmapData();
112 
113  virtual wxImage GetImage() const { return m_image; }
114  virtual wxSize GetSize() const { return wxSize( m_width, m_height ); }
115 private :
116 
117  wxImage m_image;
118  int m_width;
119  int m_height;
120 };
121 
122 class a2dMatrixData : public wxGraphicsMatrixData
123 {
124 public :
125  a2dMatrixData( wxGraphicsRenderer* renderer, const a2dAffineMatrix* matrix = NULL ) ;
126  virtual ~a2dMatrixData() ;
127 
128  virtual wxGraphicsObjectRefData* Clone() const ;
129 
130  // concatenates the matrix
131  virtual void Concat( const wxGraphicsMatrixData* t );
132 
133  // sets the matrix to the respective values
134  virtual void Set( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
135  wxDouble tx = 0.0, wxDouble ty = 0.0 );
136 
137  // gets the component valuess of the matrix
138  virtual void Get( wxDouble* a = NULL, wxDouble* b = NULL, wxDouble* c = NULL,
139  wxDouble* d = NULL, wxDouble* tx = NULL, wxDouble* ty = NULL ) const;
140 
141  // makes this the inverse matrix
142  virtual void Invert();
143 
144  // returns true if the elements of the transformation matrix are equal ?
145  virtual bool IsEqual( const wxGraphicsMatrixData* t ) const ;
146 
147  // return true if this is the identity matrix
148  virtual bool IsIdentity() const;
149 
150  //
151  // transformation
152  //
153 
154  // add the translation to this matrix
155  virtual void Translate( wxDouble dx , wxDouble dy );
156 
157  // add the scale to this matrix
158  virtual void Scale( wxDouble xScale , wxDouble yScale );
159 
160  // add the rotation to this matrix (radians)
161  virtual void Rotate( wxDouble angle );
162 
163  //
164  // apply the transforms
165  //
166 
167  // applies that matrix to the point
168  virtual void TransformPoint( wxDouble* x, wxDouble* y ) const;
169 
170  // applies the matrix except for translations
171  virtual void TransformDistance( wxDouble* dx, wxDouble* dy ) const;
172 
173  // returns the native representation
174  virtual void* GetNativeMatrix() const;
175 private:
176  a2dAffineMatrix m_matrix ;
177 } ;
178 
179 class a2dPathData : public wxGraphicsPathData
180 {
181 public :
182  a2dPathData( wxGraphicsRenderer* renderer, a2dVpath* path = NULL );
183  ~a2dPathData();
184 
185  virtual wxGraphicsObjectRefData* Clone() const;
186 
187  //
188  // These are the path primitives from which everything else can be constructed
189  //
190 
191  // begins a new subpath at (x,y)
192  virtual void MoveToPoint( wxDouble x, wxDouble y );
193 
194  // adds a straight line from the current point to (x,y)
195  virtual void AddLineToPoint( wxDouble x, wxDouble y );
196 
197  // adds a cubic Bezier curve from the current point, using two control points and an end point
198  virtual void AddCurveToPoint( wxDouble cx1, wxDouble cy1, wxDouble cx2, wxDouble cy2, wxDouble x, wxDouble y );
199 
200 
201  // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
202  virtual void AddArc( wxDouble x, wxDouble y, wxDouble r, wxDouble startAngle, wxDouble endAngle, bool clockwise ) ;
203 
204  // gets the last point of the current path, (0,0) if not yet set
205  virtual void GetCurrentPoint( wxDouble* x, wxDouble* y ) const;
206 
207  // adds another path
208  virtual void AddPath( const wxGraphicsPathData* path );
209 
210  // closes the current sub-path
211  virtual void CloseSubpath();
212 
213  //
214  // These are convenience functions which - if not available natively will be assembled
215  // using the primitives from above
216  //
217 
218  /*
219 
220  // appends a rectangle as a new closed subpath
221  virtual void AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) ;
222  // appends an ellipsis as a new closed subpath fitting the passed rectangle
223  virtual void AddEllipsis( wxDouble x, wxDouble y, wxDouble w , wxDouble h ) ;
224 
225  // draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
226  virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ;
227  */
228 
229  // returns the native path
230  virtual void* GetNativePath() const ;
231 
232  // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
233  virtual void UnGetNativePath( void* p ) const;
234 
235  // transforms each point of this path by the matrix
236  virtual void Transform( const wxGraphicsMatrixData* matrix ) ;
237 
238  // gets the bounding box enclosing all points (possibly including control points)
239  virtual void GetBox( wxDouble* x, wxDouble* y, wxDouble* w, wxDouble* h ) const;
240 
241  virtual bool Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle = wxWINDING_RULE ) const;
242 
243 private :
244  a2dVpath m_path;
245 };
246 
247 class a2dContext : public wxGraphicsContext
248 {
249  DECLARE_NO_COPY_CLASS( a2dContext )
250 
251 public:
252 
253  a2dContext( wxGraphicsRenderer* renderer, int width, int height );
254  a2dContext( wxGraphicsRenderer* renderer );
255  a2dContext( wxGraphicsRenderer* renderer, a2dContext* context );
256  //a2dContext( wxGraphicsRenderer* renderer, const wxImage& image );
257  //a2dContext( wxGraphicsRenderer* renderer, const a2dImage* drawable );
258  //a2dContext( wxGraphicsRenderer* renderer, wxWindow *window);
259  a2dContext();
260  virtual ~a2dContext();
261 
262 #if wxCHECK_VERSION(2,9,0)
263  // sets the antialiasing mode, returns true if it supported
264  virtual bool SetAntialiasMode( wxAntialiasMode antialias ) { return false; }
265 
266  // sets the compositing operator, returns true if it supported
267  virtual bool SetCompositionMode( wxCompositionMode op ) { return false; }
268 #endif
269 
270  virtual void Clip( const wxRegion& region );
271 
272  // clips drawings to the rect in user coordinates
273  virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
274 
275  // resets the clipping to original extent
276  virtual void ResetClip();
277 
278  virtual void* GetNativeContext();
279 
280  virtual void StrokePath( const wxGraphicsPath& p );
281  virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxWINDING_RULE );
282 
283  void DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxWINDING_RULE );
284 
285  virtual void Translate( wxDouble dx , wxDouble dy );
286  virtual void Scale( wxDouble xScale , wxDouble yScale );
287  virtual void Rotate( wxDouble angle );
288 
289  // concatenates this transform with the current transform of this context
290  virtual void ConcatTransform( const wxGraphicsMatrix& matrix );
291 
292  // sets the pen
293  virtual void SetPen( const wxGraphicsPen& pen );
294 
295  // sets the brush for filling
296  virtual void SetBrush( const wxGraphicsBrush& brush );
297 
298  // sets the font
299  virtual void SetFont( const wxGraphicsFont& font );
300 
301  void SetStroke( const a2dStroke& stroke );
302 
303  void SetFill( const a2dFill& fill );
304 
305  void SetFont( const a2dFont& font );
306 
307  //! set drawstyle to use for drawing,
308  /*!
309  The draw style is used for drawing in a certain fashion.
310 
311  The current fill, stroke are preserved. So when switching back to a drawing style
312  where the last set fill and stroke are used, they still will be intact.
313  New settings for fill, stroke may or may not have effect, but do change the current fill are stroke,
314  independent of the drawing style.
315  This depends if it makes sense to have a different style when the drawstyle is in action.
316  When drawstyle is set, the last set fill, stroke are made active when needed.
317 
318  \param drawstyle one of the draw styles
319  */
320  virtual void SetDrawStyle( a2dDrawStyle drawstyle ) = 0;
321 
322  //!get drawstyle used for drawing.
323  a2dDrawStyle GetDrawStyle() {return m_drawstyle;}
324 
325  // all rendering is done into a fully transparent temporary context
326  void BeginLayer( wxDouble opacity ) {};
327 
328  // composites back the drawings into the context with the opacity given at
329  // the BeginLayer call
330  void EndLayer() {};
331 
332  // sets the transform of this context
333  virtual void SetTransform( const wxGraphicsMatrix& matrix );
334 
335  // gets the matrix of this context
336  virtual wxGraphicsMatrix GetTransform() const;
337 
338 #if wxCHECK_VERSION(2,9,0)
339  virtual void DrawBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
340 #else
341  virtual void DrawGraphicsBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
342 #endif
343 
344  virtual void DrawBitmap( const wxBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
345  virtual void DrawIcon( const wxIcon& icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
346  virtual void PushState();
347  virtual void PopState();
348 
349 #if wxCHECK_VERSION(2,9,0)
350  void DoDrawText( const wxString& str, wxDouble x, wxDouble y );
351 #else
352  void DrawText( const wxString& str, wxDouble x, wxDouble y );
353 #endif
354  virtual void GetTextExtent( const wxString& str, wxDouble* width, wxDouble* height,
355  wxDouble* descent, wxDouble* externalLeading ) const;
356  virtual void GetPartialTextExtents( const wxString& text, wxArrayDouble& widths ) const;
357 
358  //! Set the display aberration of curved shapes
359  /*!
360  The drawing of curved shapes will not deviate more than this from the ideal curve.
361  \remark the smaller the number the longer the drawing takes.
362 
363  \param aber maximum deviation in device coordinates
364  */
365  void SetDisplayAberration( double aber ) { m_displayaberration = aber; }
366 
367  //! Returns the display aberration of curved shapes
368  /*!,
369  The drawing of curved shapes will not deviate more than this from the ideal curve.
370  */
371  double GetDisplayAberration() { return m_displayaberration; }
372 
373  //!set at what size to stop drawing
374  inline void SetPrimitiveThreshold( wxUint16 pixels ) { m_drawingthreshold = pixels; }
375 
376  //!get drawing threshold \sa SetDrawingThreshold
377  inline wxUint16 GetPrimitiveThreshold() { return m_drawingthreshold; }
378 
379  //! when enabling m_useOpacityFactor, this is how transparent
380  /*!
381  \param OpacityFactor Real opacity is set opacity * m_OpacityFactor/255
382  */
383  void SetOpacityFactor( wxUint8 OpacityFactor ) { m_OpacityFactor = OpacityFactor; }
384 
385  //! see SetOpacityFactor()
386  wxUint8 GetOpacityFactor() { return m_OpacityFactor; }
387 
388  //!get y axis orientation
389  inline bool GetYaxis() const { return m_yaxis; }
390 
391  //!set if the Yaxis goes up or down
392  virtual void SetYaxis( bool up );
393 
394 protected:
395 
396  void Init();
397 
398  //! return true if the drawstyle in combination with the active stroke and fill,
399  //! does not require filling
400  inline bool IsStrokeOnly()
401  {
402  return ( m_drawstyle == a2dWIREFRAME ||
403  m_drawstyle == a2dWIREFRAME_ZERO_WIDTH ||
404  m_drawstyle == a2dWIREFRAME_INVERT ||
405  m_drawstyle == a2dWIREFRAME_INVERT_ZERO_WIDTH ||
406  m_activefill.IsNoFill() ||
407  m_activefill.GetStyle() == a2dFILL_TRANSPARENT
408  );
409  }
410 
411  //! return true if the the drawstyle in combination with the active stroke,
412  //! does not require stroking
413  inline bool IsStroked()
414  {
415  return !m_activestroke.IsNoStroke() && !m_activestroke.GetStyle() == a2dSTROKE_TRANSPARENT;
416  }
417 
418  //! per drawer implementation
419  virtual void DoSetActiveStroke() = 0;
420 
421  //! per drawer implementation
422  virtual void DoSetActiveFill() = 0;
423 
424  //!Draw polygon in world coordinates using pointlist
425  virtual void DrawPolygon( const a2dVertexList* list, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
426 
427  //!Draw polyline in world coordinates using pointlist
428  virtual void DrawLines( const a2dVertexList* list );
429 
430  //!Draw line in world coordinates
431  virtual void DrawLine( double x1, double y1, double x2, double y2 );
432 
433  virtual void DrawVpath( const a2dVpath* path );
434 
435  //! convert vertex array containing line and arc segments in user coordinates to device coordinate lines.
436  int ToDeviceLines( a2dVertexArray* points, a2dBoundingBox& devbbox, bool& smallPoly, bool replaceByRectangle = false );
437 
438  //! convert vertex list containing line and arc segments in user coordinates to device coordinate lines.
439  int ToDeviceLines( const a2dVertexList* list, a2dBoundingBox& devbbox, bool& smallPoly, bool replaceByRectangle = false );
440 
441  //!Given the rectangle in world coordinate to be displayed, update the mappingmatrix.
442  /*!
443  To display all of a drawing, set this to the bounding box of the root object
444  of the canvas.
445 
446  So vx1 and vx2 to the minimum x and y of the bounding box.
447  Calculate xpp and ypp in such a manner that it will show the whole drawing.
448 
449  The buffer size or SetMappingDeviceRect() are not used when setting the mapping with this function.
450  In fact all other mapping functions in a2dContext use this function to set the mapping for the a2dContext in the end.
451 
452  \remark when a relative world matrix SetTransform() is set, the m_usertodevice
453  is recalculated to take the new mapping matrix and the already set
454  user matrix into account.
455 
456  \param x: map to device x (non zero if canvas window is smaller than drawer)
457  \param y: map to device y (non zero if canvas window is smaller than drawer)
458  \param wx: map to device of this size in x, normally same as width of buffer bitmap
459  \param wy: map to device of this size in y, normally same as height of buffer bitmap
460  \param vx1: minimum x coordinate of display area
461  \param vy1: minimum y coordinate of display area
462  \param xpp: Number of world units per pixel in x
463  \param ypp: Number of world units per pixel in y
464  */
465  void SetMappingUpp( double x, double y, double wx, double wy, double vx1, double vy1, double xpp, double ypp );
466 
467  //!Used for filling with Gradient fill style.
468  void FillPolygon( int n, wxRealPoint points[] );
469 
470  //!Used for filling with Gradient fill style.
471  bool MoveUp( int n, wxRealPoint points[] , double horline, int& index, int direction );
472 
473  //!Used for filling with Gradient fill style.
474  void DetectCriticalPoints( int n, wxRealPoint points[] );
475 
476  // Core text drawing function.
477  /*! This function will draw each character separately using the function drawchar.
478  It will also advance and kern the characters, by adjusting the affine matrices.
479  The character will also be checked against the clipbox.
480  This function assumes (0,0) is the lowerleft bbox corner.
481  This function will not draw the background fill.
482  \param text The text to be drawn.
483  \param x x-Position of the text.
484  \param y y-Position of the text.
485  \param drawchar A function which will draw a given character.
486  */
487  void DrawTextGeneric( const wxString& text, double x, double y, void ( a2dContext::*drawchar )( wxChar ) );
488 
489  //! Draw a cross instead of a character.
490  virtual void DrawCharUnknown( wxChar c );
491 
492  //! Draw a cross, indicating an unsupported font type for this drawer.
493  /*! Draws text at the given position in user coordinates.
494  Adding rotation etc. to that matrix makes it possible to draw rotated text.
495  \param text draw unknown text
496  \param x x position
497  \param y y position
498  \param words If false, draw a boxed cross for the whole line.
499  If true, draw a piece of line for each word.
500  */
501  virtual void DrawTextUnknown( const wxString& text, double x, double y, bool words = false );
502 
503  //! Draw a stroke character
504  /*! This is an internal function, used by DrawTextStroke.
505  This function assumes that the affine matrix has been set up by the calling function
506  in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner
507  of the character. Also mirroring should be performed by the calling function.
508  */
509  virtual void DrawCharStroke( wxChar c );
510 
511  //! Wrapper for DrawCharStroke
512  /*!
513  ISO C++ seems(?) to forbid directly calling the address of virtual member functions.
514  Calling &a2dContext::DrawCharStroke refers to the actual function in a2dContext and
515  does not refer to the virtual function.
516  Calling &(this->DrawCharStroke) should refer to the virtual function and is accepted by
517  some compilers (MSVC, gcc <3.3), but according to gcc 3.4 this is not allowed by ISO C++.
518  Therefore the virtual function is called through this intermediate function
519  */
520  void DrawCharStrokeCb( wxChar c ) { DrawCharStroke( c ); }
521 
522  //! Draw text in user coordinates, based on a stroke font.
523  /* The text will be drawn with (0,0) being the lowerleft bbox corner.
524  The background fill and alignment positioning are handled by DrawText.
525  */
526  virtual void DrawTextStroke( const wxString& text, double x, double y )
527  { DrawTextGeneric( text, x, y, &a2dContext::DrawCharStrokeCb ); }
528 
529  //! Draw a freetype character
530  /*! This is an internal function, used by DrawTextFreetype
531  This function assumes that the affine matrix has been set up by the calling function
532  in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner
533  of the character. Also mirroring should be performed by the calling function.
534  */
535  virtual void DrawCharFreetype( wxChar c ) { DrawCharUnknown( c ); }
536 
537  //! Wrapper for DrawCharFreetype
538  /*! \sa DrawCharStrokeCb */
539  void DrawCharFreetypeCb( wxChar c ) { DrawCharFreetype( c ); }
540 
541  //! Draw text in world coordinates, based on a freetype font .
542  /* The text will be drawn with (0,0) being the lowerleft bbox corner.
543  The background fill and alignment positioning are handled by DrawText.
544  */
545  virtual void DrawTextFreetype( const wxString& text, double x, double y )
546  { DrawTextGeneric( text, x, y, &a2dContext::DrawCharFreetypeCb ); }
547 
548  //! Draw a dc character
549  /*! This is an internal function, used by DrawTextDc
550  This function assumes that the affine matrix has been set up by the calling function
551  in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner
552  of the character. Also mirroring should be performed by the calling function.
553  */
554  virtual void DrawCharDc( wxChar c ) { DrawCharUnknown( c ); }
555 
556  //! Wrapper for DrawCharDc
557  /*! \sa DrawCharStrokeCb */
558  void DrawCharDcCb( wxChar c ) { DrawCharDc( c ); }
559 
560  //! Draw text in user coordinates, based on a dc font .
561  /* The text will be drawn with (0,0) being the lowerleft bbox corner.
562  The background fill and alignment positioning are handled by DrawText.
563  */
564  virtual void DrawTextDc( const wxString& text, double x, double y )
565  { DrawTextGeneric( text, x, y, &a2dContext::DrawCharDcCb ); }
566 
567  //! Convert double points to integer coords in the point cache and return pointer.
568  wxPoint* _convertToIntPointCache( int n, wxRealPoint* pts );
569 
570  //! draw an internal polygon in device coordinates
571  virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
572 
573  //! draw an internal polyline in device coordinates
574  virtual void DeviceDrawLines( unsigned int n, bool spline );
575 
576  //!draw in pixels
577  virtual void DeviceDrawLine( double x1, double y1, double x2, double y2 );
578 
579  //! Draw a pixel-width, unstroked horizontal line in device (pixel) coordinates
580  /*! This method is useful for implementing low level fill routines.
581 
582  \param x1 x start of line
583  \param x2 x end of line
584  \param y1 y of line
585  \param use_stroke_color If true, then use the current stroke color
586  If false, then use the current fill color.
587  */
588  virtual void DeviceDrawHorizontalLine( int x1, int y1, int x2, bool use_stroke_color );
589 
590  //! Draw a pixel-width, unstroked vertical line in device (pixel) coordinates
591  /*! This method is useful for implementing low level fill routines.
592 
593  \param x1 x of line
594  \param y1 y start of line
595  \param y2 y end of line
596  \param use_stroke_color If true, then use the current stroke color
597  If false, then use the current fill color.
598  */
599  virtual void DeviceDrawVerticalLine( int x1, int y1, int y2, bool use_stroke_color );
600 
601  //!draw a single, unstroked pixel in device coordinates with the given color
602  virtual void DeviceDrawPixel( int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 );
603 
604  //! active stroke alpha
605  wxUint8 m_StrokeOpacityCol1;
606  //! active stroke alpha
607  wxUint8 m_StrokeOpacityCol2;
608  //! active fill alpha
609  wxUint8 m_FillOpacityCol1;
610  //! active fill alpha
611  wxUint8 m_FillOpacityCol2;
612 
613  //! active stroke colours
614  unsigned char m_colour1redStroke;
615  //! active stroke colours
616  unsigned char m_colour1greenStroke;
617  //! active stroke colours
618  unsigned char m_colour1blueStroke;
619 
620  //! active fill colours
621  unsigned char m_colour1redFill;
622  //! active fill colours
623  unsigned char m_colour1greenFill;
624  //! active fill colours
625  unsigned char m_colour1blueFill;
626 
627  //! active fill colours
628  unsigned char m_colour2redFill;
629  //! active fill colours
630  unsigned char m_colour2greenFill;
631  //! active fill colours
632  unsigned char m_colour2blueFill;
633 
634  //!used while rendering
635  a2dStroke m_activestroke;
636 
637  //!used while rendering
638  a2dFill m_activefill;
639 
640  //!current font set
641  a2dFont m_a2dfont;
642 
643  //!drawstyle (like invert mode)
644  a2dDrawStyle m_drawstyle;
645 
646  a2dAffineMatrix m_usertodevice;
647 
648  int m_width;
649 
650  int m_height;
651 
652  //! up or down
653  bool m_yaxis;
654 
655  //! current clipping area in device coordinates
656  wxRect m_clipboxdev;
657 
658  //! critical point list for polygon
659  a2dCriticalPointList m_CRlist;
660 
661  //! scanline list of intersections with polygon
662  a2dAETList m_AETlist;
663 
664  //!cached array for containing transformed device coordinates (integer)
665  std::vector<wxPoint> m_cpointsInt;
666 
667  //!cached array for containing transformed device coordinates (double)
668  std::vector<wxRealPoint> m_cpointsDouble;
669 
670  //!accuracy of arc segment calculation etc. in device coordinates
671  double m_displayaberration;
672 
673  //! object smaller than this value will not be rendered
674  wxUint16 m_drawingthreshold;
675 
676  //! opacity will be the one set, derived by this
677  wxUint8 m_OpacityFactor;
678 
679 private:
680 
681  void ColourXYLinear( int x1, int x2, int y );
682  void ColourXYRadial( int x1, int x2, int y );
683 
684  //! gradient start stop
685  double m_dx1, m_dy1, m_dx2, m_dy2, m_radiusd, m_length, m_max_x, m_min_x, m_max_y, m_min_y;
686  a2dLine m_line;
687 
688 };
689 
690 class a2dDcContext : public a2dContext
691 {
692  DECLARE_NO_COPY_CLASS( a2dDcContext )
693 
694 public:
695 
696  a2dDcContext( wxGraphicsRenderer* renderer, wxMemoryDC* dc, wxBitmap* drawable );
697  a2dDcContext( wxGraphicsRenderer* renderer, wxBitmap* drawable );
698  virtual ~a2dDcContext();
699 
700  // clips drawings to the rect
701  virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
702 
703  // resets the clipping to original extent
704  virtual void ResetClip();
705 
706  //! set drawstyle to use for drawing,
707  /*!
708  The draw style is used for drawing in a certain fashion.
709 
710  The current fill, stroke are preserved. So when switching back to a drawing style
711  where the last set fill and stroke are used, they still will be intact.
712  New settings for fill, stroke may or may not have effect, but do change the current fill are stroke,
713  independent of the drawing style.
714  This depends if it makes sense to have a different style when the drawstyle is in action.
715  When drawstyle is set, the last set fill, stroke are made active when needed.
716 
717  \param drawstyle one of the draw styles
718  */
719  virtual void SetDrawStyle( a2dDrawStyle drawstyle );
720 
721  // sets the current logical function, returns true if it supported
722  virtual bool SetLogicalFunction( wxRasterOperationMode function ) ;
723 
724 #if wxCHECK_VERSION(2,9,0)
725  virtual void DrawBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
726 #else
727  virtual void DrawGraphicsBitmap( const wxGraphicsBitmap& bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
728 #endif
729 
730  virtual void DrawCharDc( wxChar c );
731  virtual void DrawTextDc( const wxString& text, double x, double y );
732  virtual void DrawCharFreetype( wxChar c );
733 
734 protected:
735 
736  //! per drawer implementation
737  virtual void DoSetActiveStroke();
738 
739  //! per drawer implementation
740  virtual void DoSetActiveFill();
741 
742  virtual void DrawVpath( const a2dVpath* path );
743 
744  void DeviceDrawBitmap( const wxBitmap& bmp, double x, double y, bool useMask );
745 
746  //! draw an internal polygon in device coordinates
747  virtual void DeviceDrawPolygon( unsigned int n, bool spline , wxPolygonFillMode fillStyle );
748  virtual void DeviceDrawLines( unsigned int n, bool spline );
749  virtual void DeviceDrawLine( double x1, double y1, double x2, double y2 );
750  virtual void DeviceDrawHorizontalLine( int x1, int y1, int x2, bool use_stroke_color );
751  virtual void DeviceDrawVerticalLine( int x1, int y1, int y2, bool use_stroke_color );
752  virtual void DeviceDrawPixel( int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255 );
753 
754  //!the buffer that is used for rendering
755  wxBitmap* m_buffer;
756 
757  //!The DC to use to draw to the device or buffer ( depends on type of a2dCanvasView )
758  /*!In case of a m_buffer you must select the bitmap into the DC yourself. */
759  wxDC* m_renderDC;
760 };
761 
762 //-----------------------------------------------------------------------------
763 // a2dRenderer declaration
764 //-----------------------------------------------------------------------------
765 
766 class a2dRenderer : public wxGraphicsRenderer
767 {
768 public :
769  a2dRenderer() {}
770 
771  virtual ~a2dRenderer() {}
772 
773  // Context
774 
775  virtual wxGraphicsContext* CreateContext( const wxWindowDC& dc );
776 
777  virtual wxGraphicsContext* CreateContext( const wxMemoryDC& dc );
778 
779  virtual wxGraphicsContext* CreateContext( wxMemoryDC* dc, wxBitmap* drawable );
780 
781  virtual wxGraphicsContext* CreateContextFromNativeContext( void* context );
782 
783  virtual wxGraphicsContext* CreateContextFromNativeWindow( void* window );
784 
785  virtual wxGraphicsContext* CreateContext( wxWindow* window );
786 
787  virtual wxGraphicsContext* CreateMeasuringContext();
788 
789 #if wxCHECK_VERSION(2, 9, 0)
790 #if wxUSE_PRINTING_ARCHITECTURE
791  virtual wxGraphicsContext* CreateContext( const wxPrinterDC& dc );
792 #ifdef __WXMSW__
793  virtual wxGraphicsContext* CreateContext( const wxEnhMetaFileDC& dc );
794 #endif
795 
796 #endif // wxUSE_PRINTING_ARCHITECTURE
797 #endif //wxCHECK_VERSION(2, 9, 0)
798 
799 
800  // Path
801  virtual wxGraphicsPath CreatePath();
802 
803  // Matrix
804  virtual wxGraphicsMatrix CreateMatrix( wxDouble a = 1.0, wxDouble b = 0.0, wxDouble c = 0.0, wxDouble d = 1.0,
805  wxDouble tx = 0.0, wxDouble ty = 0.0 );
806 
807  virtual wxGraphicsPen CreatePen( const wxPen& pen ) ;
808 
809  virtual wxGraphicsBrush CreateBrush( const wxBrush& brush ) ;
810 
811  virtual wxGraphicsPen CreateStroke( const a2dStroke& stroke ) ;
812 
813  virtual wxGraphicsBrush CreateFill( const a2dFill& fill ) ;
814 
815 #if wxCHECK_VERSION(2, 9, 1)
816  virtual wxGraphicsBrush
817  CreateLinearGradientBrush( wxDouble x1, wxDouble y1,
818  wxDouble x2, wxDouble y2,
819  const wxGraphicsGradientStops& stops );
820 
821  virtual wxGraphicsBrush
822  CreateRadialGradientBrush( wxDouble xo, wxDouble yo,
823  wxDouble xc, wxDouble yc,
824  wxDouble radius,
825  const wxGraphicsGradientStops& stops );
826 
827  // create a graphics bitmap from a native bitmap
828  virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap );
829 
830 #else
831  // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
832  virtual wxGraphicsBrush CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
833  const wxColour& c1, const wxColour& c2 ) ;
834 
835  // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
836  // with radius r and color cColor
837  virtual wxGraphicsBrush CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
838  const wxColour& oColor, const wxColour& cColor ) ;
839 #endif
840 
841 
842 
843  // sets the font
844  virtual wxGraphicsFont CreateFont( const wxFont& font , const wxColour& col = *wxBLACK ) ;
845 
846  virtual wxGraphicsFont CreateFont( const a2dFont& font ) ;
847 
848  wxGraphicsBitmap CreateBitmap( const wxBitmap& bitmap ) ;
849 
850  wxGraphicsBitmap CreateBitmap( const wxImage& image ) ;
851 
852  virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap& bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h );
853 
854 
855 private :
856  DECLARE_DYNAMIC_CLASS_NO_COPY( a2dRenderer )
857 } ;
858 
859 
860 
861 #endif //wxART2D_USE_GRAPHICS_CONTEXT
862 
863 
864 #endif
Base class for all types of strokes, understood by a2dDrawer2D classes.
Definition: stylebase.h:378
Stroke and fill base classes.
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
general vertexlist and array and vector path functions and classes.
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.
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
Line calculations.
Definition: liner.h:36
Contains image with RGBA per pixel.
The a2dBoundingBox class stores one a2dBoundingBox of a a2dCanvasObject.
Definition: bbox.h:39
Vector Path.
Definition: polyver.h:1211
graphica.h Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation