1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dccg.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/graphics.h"
17 #include "wx/dcclient.h"
18 #include "wx/dcmemory.h"
20 #include "wx/region.h"
25 #include "wx/mac/uma.h"
30 // in case our functions were defined outside std, we make it known all the same
36 #include "wx/mac/private.h"
38 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
39 typedef float CGFloat
;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
48 const double M_PI
= 3.14159265358979;
52 static const double RAD2DEG
= 180.0 / M_PI
;
55 // Pen, Brushes and Fonts
59 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
61 OSStatus
wxMacDrawCGImage(
62 CGContextRef inContext
,
63 const HIRect
* inBounds
,
68 CGContextDrawImage(inContext
, *inBounds
, inImage
);
70 HIViewDrawCGImage( inContext
, inBounds
, inImage
);
74 // CGPattern wrapper class: always allocate on heap, never call destructor
76 class wxMacCoreGraphicsPattern
79 wxMacCoreGraphicsPattern() {}
81 // is guaranteed to be called only with a non-Null CGContextRef
82 virtual void Render( CGContextRef ctxRef
) = 0;
84 operator CGPatternRef() const { return m_patternRef
; }
87 virtual ~wxMacCoreGraphicsPattern()
89 // as this is called only when the m_patternRef is been released;
90 // don't release it again
93 static void _Render( void *info
, CGContextRef ctxRef
)
95 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
97 self
->Render( ctxRef
);
100 static void _Dispose( void *info
)
102 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
106 CGPatternRef m_patternRef
;
108 static const CGPatternCallbacks ms_Callbacks
;
111 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
113 class ImagePattern
: public wxMacCoreGraphicsPattern
116 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
118 wxASSERT( bmp
&& bmp
->Ok() );
120 Init( (CGImageRef
) bmp
->CreateCGImage() , transform
);
123 // ImagePattern takes ownership of CGImageRef passed in
124 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
129 Init( image
, transform
);
132 virtual void Render( CGContextRef ctxRef
)
135 wxMacDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
139 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
144 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
145 m_patternRef
= CGPatternCreate(
146 this , m_imageBounds
, transform
,
147 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
148 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
152 virtual ~ImagePattern()
155 CGImageRelease( m_image
);
159 CGRect m_imageBounds
;
162 class HatchPattern
: public wxMacCoreGraphicsPattern
165 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
167 m_hatch
= hatchstyle
;
168 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
169 m_patternRef
= CGPatternCreate(
170 this , m_imageBounds
, transform
,
171 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
172 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
175 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
177 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
180 virtual void Render( CGContextRef ctxRef
)
184 case wxBDIAGONAL_HATCH
:
188 { 8.0 , 0.0 } , { 0.0 , 8.0 }
190 StrokeLineSegments( ctxRef
, pts
, 2 );
194 case wxCROSSDIAG_HATCH
:
198 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
199 { 8.0 , 0.0 } , { 0.0 , 8.0 }
201 StrokeLineSegments( ctxRef
, pts
, 4 );
205 case wxFDIAGONAL_HATCH
:
209 { 0.0 , 0.0 } , { 8.0 , 8.0 }
211 StrokeLineSegments( ctxRef
, pts
, 2 );
219 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
220 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
222 StrokeLineSegments( ctxRef
, pts
, 4 );
226 case wxHORIZONTAL_HATCH
:
230 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
232 StrokeLineSegments( ctxRef
, pts
, 2 );
236 case wxVERTICAL_HATCH
:
240 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
242 StrokeLineSegments( ctxRef
, pts
, 2 );
252 virtual ~HatchPattern() {}
254 CGRect m_imageBounds
;
258 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
261 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
262 ~wxMacCoreGraphicsPenData();
265 virtual void Apply( wxGraphicsContext
* context
);
266 virtual wxDouble
GetWidth() { return m_width
; }
270 wxMacCFRefHolder
<CGColorRef
> m_color
;
271 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
277 const CGFloat
*m_lengths
;
278 CGFloat
*m_userLengths
;
282 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
283 CGFloat
* m_patternColorComponents
;
286 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
287 wxGraphicsObjectRefData( renderer
)
291 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
292 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
293 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
295 // TODO: * m_dc->m_scaleX
296 m_width
= pen
.GetWidth();
300 switch ( pen
.GetCap() )
303 m_cap
= kCGLineCapRound
;
306 case wxCAP_PROJECTING
:
307 m_cap
= kCGLineCapSquare
;
311 m_cap
= kCGLineCapButt
;
315 m_cap
= kCGLineCapButt
;
319 switch ( pen
.GetJoin() )
322 m_join
= kCGLineJoinBevel
;
326 m_join
= kCGLineJoinMiter
;
330 m_join
= kCGLineJoinRound
;
334 m_join
= kCGLineJoinMiter
;
338 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
340 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
341 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
342 static const CGFloat dashed
[] = { 19.0 , 9.0 };
343 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
345 switch ( pen
.GetStyle() )
351 m_count
= WXSIZEOF(dotted
);
352 m_userLengths
= new CGFloat
[ m_count
] ;
353 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
354 m_lengths
= m_userLengths
;
358 m_count
= WXSIZEOF(dashed
);
363 m_count
= WXSIZEOF(short_dashed
);
364 m_lengths
= short_dashed
;
368 m_count
= WXSIZEOF(dotted_dashed
);
369 m_lengths
= dotted_dashed
;
374 m_count
= pen
.GetDashes( &dashes
);
375 if ((dashes
!= NULL
) && (m_count
> 0))
377 m_userLengths
= new CGFloat
[m_count
];
378 for ( int i
= 0; i
< m_count
; ++i
)
380 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
382 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
383 m_userLengths
[i
] = dashUnit
+ 2.0;
384 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
385 m_userLengths
[i
] = dashUnit
;
388 m_lengths
= m_userLengths
;
393 wxBitmap
* bmp
= pen
.GetStipple();
394 if ( bmp
&& bmp
->Ok() )
396 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
397 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
398 m_patternColorComponents
= new CGFloat
[1] ;
399 m_patternColorComponents
[0] = 1.0;
408 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
409 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
410 m_patternColorComponents
= new CGFloat
[4] ;
411 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
412 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
413 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
414 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
418 if ((m_lengths
!= NULL
) && (m_count
> 0))
420 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
421 m_cap
= kCGLineCapButt
;
425 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
427 delete[] m_userLengths
;
428 delete[] m_patternColorComponents
;
431 void wxMacCoreGraphicsPenData::Init()
434 m_userLengths
= NULL
;
437 m_patternColorComponents
= NULL
;
441 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
443 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
444 CGContextSetLineWidth( cg
, m_width
);
445 CGContextSetLineJoin( cg
, m_join
);
447 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
448 CGContextSetLineCap( cg
, m_cap
);
452 CGAffineTransform matrix
= CGContextGetCTM( cg
);
453 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
454 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
455 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
459 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
461 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
464 CGContextSetStrokeColorWithColor( cg
, m_color
);
472 static const char *gs_stripedback_xpm
[] = {
473 /* columns rows colors chars-per-pixel */
484 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
486 // make sure we all use one class for all conversions from wx to native colour
488 class wxMacCoreGraphicsColour
491 wxMacCoreGraphicsColour();
492 wxMacCoreGraphicsColour(const wxBrush
&brush
);
493 ~wxMacCoreGraphicsColour();
495 void Apply( CGContextRef cgContext
);
498 wxMacCFRefHolder
<CGColorRef
> m_color
;
499 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
502 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
503 CGFloat
* m_patternColorComponents
;
506 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
508 delete[] m_patternColorComponents
;
511 void wxMacCoreGraphicsColour::Init()
514 m_patternColorComponents
= NULL
;
517 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
521 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
522 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
523 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
524 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
528 CGContextSetFillColorWithColor( cgContext
, m_color
);
532 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
537 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
540 if ( brush
.GetStyle() == wxSOLID
)
542 m_color
.Set( brush
.GetColour().CreateCGColor() );
544 else if ( brush
.IsHatch() )
547 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
548 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
550 m_patternColorComponents
= new CGFloat
[4] ;
551 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
552 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
553 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
554 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
558 // now brush is a bitmap
559 wxBitmap
* bmp
= brush
.GetStipple();
560 if ( bmp
&& bmp
->Ok() )
563 m_patternColorComponents
= new CGFloat
[1] ;
564 m_patternColorComponents
[0] = 1.0;
565 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
566 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
571 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
574 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
575 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
576 ~wxMacCoreGraphicsBrushData ();
578 virtual void Apply( wxGraphicsContext
* context
);
579 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
580 const wxColour
&c1
, const wxColour
&c2
);
581 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
582 const wxColour
&oColor
, const wxColour
&cColor
);
584 virtual bool IsShading() { return m_isShading
; }
585 CGShadingRef
GetShading() { return m_shading
; }
587 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
588 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
591 wxMacCoreGraphicsColour m_cgColor
;
594 CGFunctionRef m_gradientFunction
;
595 CGShadingRef m_shading
;
596 CGFloat
*m_gradientComponents
;
599 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
604 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
605 const wxColour
&c1
, const wxColour
&c2
)
607 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
608 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
612 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
613 const wxColour
&oColor
, const wxColour
&cColor
)
615 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
616 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
620 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
627 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
630 CGShadingRelease(m_shading
);
632 if( m_gradientFunction
)
633 CGFunctionRelease(m_gradientFunction
);
635 delete[] m_gradientComponents
;
638 void wxMacCoreGraphicsBrushData::Init()
640 m_gradientFunction
= NULL
;
642 m_gradientComponents
= NULL
;
646 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
648 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
652 // nothing to set as shades are processed by clipping using the path and filling
656 m_cgColor
.Apply( cg
);
660 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
662 CGFloat
* colors
= (CGFloat
*) info
;
664 for( int i
= 0 ; i
< 4 ; ++i
)
666 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
670 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
672 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
673 static const CGFloat input_value_range
[2] = { 0, 1 };
674 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
675 m_gradientComponents
= new CGFloat
[8] ;
676 m_gradientComponents
[0] = c1
.Red() / 255.0;
677 m_gradientComponents
[1] = c1
.Green() / 255.0;
678 m_gradientComponents
[2] = c1
.Blue() / 255.0;
679 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
680 m_gradientComponents
[4] = c2
.Red() / 255.0;
681 m_gradientComponents
[5] = c2
.Green() / 255.0;
682 m_gradientComponents
[6] = c2
.Blue() / 255.0;
683 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
685 return CGFunctionCreate ( m_gradientComponents
, 1,
696 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
699 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
700 ~wxMacCoreGraphicsFontData();
702 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
704 ATSUStyle m_macATSUIStyle
;
707 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
709 m_macATSUIStyle
= NULL
;
713 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
715 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
717 // we need the scale here ...
719 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
721 col
.GetRGBColor( &atsuColor
);
722 ATSUAttributeTag atsuTags
[] =
727 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
732 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
738 status
= ::ATSUSetAttributes(
739 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
740 atsuTags
, atsuSizes
, atsuValues
);
742 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
745 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
747 if ( m_macATSUIStyle
)
749 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
750 m_macATSUIStyle
= NULL
;
758 //-----------------------------------------------------------------------------
759 // wxMacCoreGraphicsMatrix declaration
760 //-----------------------------------------------------------------------------
762 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
765 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
767 virtual ~wxMacCoreGraphicsMatrixData() ;
769 virtual wxGraphicsObjectRefData
*Clone() const ;
771 // concatenates the matrix
772 virtual void Concat( const wxGraphicsMatrixData
*t
);
774 // sets the matrix to the respective values
775 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
776 wxDouble tx
=0.0, wxDouble ty
=0.0);
778 // gets the component valuess of the matrix
779 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
780 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
782 // makes this the inverse matrix
783 virtual void Invert();
785 // returns true if the elements of the transformation matrix are equal ?
786 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
788 // return true if this is the identity matrix
789 virtual bool IsIdentity() const;
795 // add the translation to this matrix
796 virtual void Translate( wxDouble dx
, wxDouble dy
);
798 // add the scale to this matrix
799 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
801 // add the rotation to this matrix (radians)
802 virtual void Rotate( wxDouble angle
);
805 // apply the transforms
808 // applies that matrix to the point
809 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
811 // applies the matrix except for translations
812 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
814 // returns the native representation
815 virtual void * GetNativeMatrix() const;
818 CGAffineTransform m_matrix
;
821 //-----------------------------------------------------------------------------
822 // wxMacCoreGraphicsMatrix implementation
823 //-----------------------------------------------------------------------------
825 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
829 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
833 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
835 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
836 m
->m_matrix
= m_matrix
;
840 // concatenates the matrix
841 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
843 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
846 // sets the matrix to the respective values
847 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
848 wxDouble tx
, wxDouble ty
)
850 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
853 // gets the component valuess of the matrix
854 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
855 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
857 if (a
) *a
= m_matrix
.a
;
858 if (b
) *b
= m_matrix
.b
;
859 if (c
) *c
= m_matrix
.c
;
860 if (d
) *d
= m_matrix
.d
;
861 if (tx
) *tx
= m_matrix
.tx
;
862 if (ty
) *ty
= m_matrix
.ty
;
865 // makes this the inverse matrix
866 void wxMacCoreGraphicsMatrixData::Invert()
868 m_matrix
= CGAffineTransformInvert( m_matrix
);
871 // returns true if the elements of the transformation matrix are equal ?
872 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
874 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
877 // return true if this is the identity matrix
878 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
880 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
881 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
888 // add the translation to this matrix
889 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
891 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
894 // add the scale to this matrix
895 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
897 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
900 // add the rotation to this matrix (radians)
901 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
903 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
907 // apply the transforms
910 // applies that matrix to the point
911 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
913 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
919 // applies the matrix except for translations
920 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
922 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
927 // returns the native representation
928 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
930 return (void*) &m_matrix
;
937 //-----------------------------------------------------------------------------
938 // wxMacCoreGraphicsPath declaration
939 //-----------------------------------------------------------------------------
941 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
944 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
946 ~wxMacCoreGraphicsPathData();
948 virtual wxGraphicsObjectRefData
*Clone() const;
950 // begins a new subpath at (x,y)
951 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
953 // adds a straight line from the current point to (x,y)
954 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
956 // adds a cubic Bezier curve from the current point, using two control points and an end point
957 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
959 // closes the current sub-path
960 virtual void CloseSubpath();
962 // gets the last point of the current path, (0,0) if not yet set
963 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
965 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
966 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
969 // These are convenience functions which - if not available natively will be assembled
970 // using the primitives from above
973 // adds a quadratic Bezier curve from the current point, using a control point and an end point
974 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
976 // appends a rectangle as a new closed subpath
977 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
979 // appends an ellipsis as a new closed subpath fitting the passed rectangle
980 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
982 // 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)
983 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
986 virtual void AddPath( const wxGraphicsPathData
* path
);
988 // returns the native path
989 virtual void * GetNativePath() const { return m_path
; }
991 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
992 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
994 // transforms each point of this path by the matrix
995 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
997 // gets the bounding box enclosing all points (possibly including control points)
998 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
1000 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
1002 CGMutablePathRef m_path
;
1005 //-----------------------------------------------------------------------------
1006 // wxMacCoreGraphicsPath implementation
1007 //-----------------------------------------------------------------------------
1009 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1014 m_path
= CGPathCreateMutable();
1017 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1019 CGPathRelease( m_path
);
1022 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1024 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1029 // opens (starts) a new subpath
1030 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1032 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1035 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1037 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1040 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1042 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1045 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1047 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1050 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1052 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1053 CGPathAddRect( m_path
, NULL
, cgRect
);
1056 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1058 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1061 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1062 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1064 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1065 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1068 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1070 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1073 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1075 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1078 // closes the current subpath
1079 void wxMacCoreGraphicsPathData::CloseSubpath()
1081 CGPathCloseSubpath( m_path
);
1084 // gets the last point of the current path, (0,0) if not yet set
1085 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1087 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1092 // transforms each point of this path by the matrix
1093 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1095 CGMutablePathRef p
= CGPathCreateMutable() ;
1096 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1097 CGPathRelease( m_path
);
1101 // gets the bounding box enclosing all points (possibly including control points)
1102 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1104 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1105 *x
= bounds
.origin
.x
;
1106 *y
= bounds
.origin
.y
;
1107 *w
= bounds
.size
.width
;
1108 *h
= bounds
.size
.height
;
1111 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1113 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1120 //-----------------------------------------------------------------------------
1121 // wxMacCoreGraphicsContext declaration
1122 //-----------------------------------------------------------------------------
1124 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1127 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1129 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1131 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1133 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1135 wxMacCoreGraphicsContext();
1137 ~wxMacCoreGraphicsContext();
1141 // returns the size of the graphics context in device coordinates
1142 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1144 virtual void StartPage( wxDouble width
, wxDouble height
);
1146 virtual void EndPage();
1148 virtual void Flush();
1150 // push the current state of the context, ie the transformation matrix on a stack
1151 virtual void PushState();
1153 // pops a stored state from the stack
1154 virtual void PopState();
1156 // clips drawings to the region
1157 virtual void Clip( const wxRegion
®ion
);
1159 // clips drawings to the rect
1160 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1162 // resets the clipping to original extent
1163 virtual void ResetClip();
1165 virtual void * GetNativeContext();
1167 bool SetLogicalFunction( int function
);
1173 virtual void Translate( wxDouble dx
, wxDouble dy
);
1176 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1179 virtual void Rotate( wxDouble angle
);
1181 // concatenates this transform with the current transform of this context
1182 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1184 // sets the transform of this context
1185 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1187 // gets the matrix of this context
1188 virtual wxGraphicsMatrix
GetTransform() const;
1190 // setting the paint
1193 // strokes along a path with the current pen
1194 virtual void StrokePath( const wxGraphicsPath
&path
);
1196 // fills a path with the current brush
1197 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1199 // draws a path by first filling and then stroking
1200 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1202 virtual bool ShouldOffset() const
1205 if ( !m_pen
.IsNull() )
1207 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1208 if ( penwidth
== 0 )
1211 return ( penwidth
% 2 ) == 1;
1217 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1219 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1221 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1222 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1224 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1230 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1232 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1234 void SetNativeContext( CGContextRef cg
);
1236 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1237 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1240 void EnsureIsValid();
1242 CGContextRef m_cgContext
;
1243 WindowRef m_windowRef
;
1244 bool m_releaseContext
;
1245 CGAffineTransform m_windowTransform
;
1249 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1252 //-----------------------------------------------------------------------------
1253 // device context implementation
1255 // more and more of the dc functionality should be implemented by calling
1256 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1257 // also coordinate conversions should be moved to native matrix ops
1258 //-----------------------------------------------------------------------------
1260 // we always stock two context states, one at entry, to be able to preserve the
1261 // state we were called with, the other one after changing to HI Graphics orientation
1262 // (this one is used for getting back clippings etc)
1264 //-----------------------------------------------------------------------------
1265 // wxMacCoreGraphicsContext implementation
1266 //-----------------------------------------------------------------------------
1268 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1270 class wxQuartzOffsetHelper
1273 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1278 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1280 ~wxQuartzOffsetHelper( )
1283 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1290 void wxMacCoreGraphicsContext::Init()
1293 m_releaseContext
= false;
1298 HIRect r
= CGRectMake(0,0,0,0);
1299 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1302 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1305 SetNativeContext(cgcontext
);
1310 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1313 m_windowRef
= window
;
1316 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1319 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1320 int originX
, originY
;
1321 originX
= originY
= 0;
1322 window
->MacWindowToRootWindow( &originX
, &originY
);
1324 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1326 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1327 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1328 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1331 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1336 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1339 wxLogDebug(wxT("Illegal Constructor called"));
1342 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1344 SetNativeContext(NULL
);
1347 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1354 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1357 if ( width
!= 0 && height
!= 0)
1358 r
= CGRectMake( 0 , 0 , width
, height
);
1360 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1362 CGContextBeginPage(m_cgContext
, &r
);
1363 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1364 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1367 void wxMacCoreGraphicsContext::EndPage()
1369 CGContextEndPage(m_cgContext
);
1372 void wxMacCoreGraphicsContext::Flush()
1374 CGContextFlush(m_cgContext
);
1377 void wxMacCoreGraphicsContext::EnsureIsValid()
1383 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1387 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1389 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1390 CGContextSaveGState( m_cgContext
);
1391 m_releaseContext
= true;
1392 if ( !HIShapeIsEmpty(m_clipRgn
) )
1394 // the clip region is in device coordinates, so we convert this again to user coordinates
1395 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1396 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1397 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1398 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1399 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1400 CGContextClip( m_cgContext
);
1402 CGContextSaveGState( m_cgContext
);
1406 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1408 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1410 if (m_logicalFunction
== function
)
1415 bool retval
= false;
1417 if ( function
== wxCOPY
)
1420 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1422 else if ( function
== wxINVERT
|| function
== wxXOR
)
1424 // change color to white
1425 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1426 CGContextSetShouldAntialias( m_cgContext
, false );
1431 m_logicalFunction
= function
;
1435 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1439 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1440 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1441 CGContextClip( m_cgContext
);
1446 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1447 // to regions we try at least to have correct translations
1448 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1449 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1450 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1452 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1453 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1454 m_clipRgn
.Set(mutableShape
);
1458 // clips drawings to the rect
1459 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1461 HIRect r
= CGRectMake( x
, y
, w
, h
);
1464 CGContextClipToRect( m_cgContext
, r
);
1468 // the clipping itself must be stored as device coordinates, otherwise
1469 // we cannot apply it back correctly
1470 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1471 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1475 // resets the clipping to original extent
1476 void wxMacCoreGraphicsContext::ResetClip()
1480 // there is no way for clearing the clip, we can only revert to the stored
1481 // state, but then we have to make sure everything else is NOT restored
1482 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1483 CGContextRestoreGState( m_cgContext
);
1484 CGContextSaveGState( m_cgContext
);
1485 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1486 transformNew
= CGAffineTransformInvert( transformNew
) ;
1487 CGContextConcatCTM( m_cgContext
, transformNew
);
1488 CGContextConcatCTM( m_cgContext
, transform
);
1492 HIRect r
= CGRectMake(0,0,0,0);
1493 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1497 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1499 if ( m_pen
.IsNull() )
1504 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1506 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1507 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1508 CGContextStrokePath( m_cgContext
);
1511 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1513 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1515 // when using shading, we cannot draw pen and brush at the same time
1516 // revert to the base implementation of first filling and then stroking
1517 wxGraphicsContext::DrawPath( path
, fillStyle
);
1521 CGPathDrawingMode mode
= kCGPathFill
;
1522 if ( m_brush
.IsNull() )
1524 if ( m_pen
.IsNull() )
1527 mode
= kCGPathStroke
;
1531 if ( m_pen
.IsNull() )
1533 if ( fillStyle
== wxODDEVEN_RULE
)
1534 mode
= kCGPathEOFill
;
1540 if ( fillStyle
== wxODDEVEN_RULE
)
1541 mode
= kCGPathEOFillStroke
;
1543 mode
= kCGPathFillStroke
;
1549 if ( !m_brush
.IsNull() )
1550 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1551 if ( !m_pen
.IsNull() )
1552 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1554 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1556 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1557 CGContextDrawPath( m_cgContext
, mode
);
1560 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1562 if ( m_brush
.IsNull() )
1567 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1569 CGContextSaveGState( m_cgContext
);
1570 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1571 CGContextClip( m_cgContext
);
1572 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1573 CGContextRestoreGState( m_cgContext
);
1577 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1578 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1579 if ( fillStyle
== wxODDEVEN_RULE
)
1580 CGContextEOFillPath( m_cgContext
);
1582 CGContextFillPath( m_cgContext
);
1586 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1588 // we allow either setting or clearing but not replacing
1589 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1593 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1594 CGContextRestoreGState( m_cgContext
);
1595 CGContextRestoreGState( m_cgContext
);
1596 if ( m_releaseContext
)
1599 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1603 CGContextRelease(m_cgContext
);
1609 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1610 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1611 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1612 // for this one operation.
1614 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1618 CGContextRetain(m_cgContext
);
1619 CGContextSaveGState( m_cgContext
);
1620 CGContextSaveGState( m_cgContext
);
1621 m_releaseContext
= false;
1625 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1628 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1630 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1633 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1636 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1638 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1641 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1644 CGContextRotateCTM( m_cgContext
, angle
);
1646 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1649 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1653 CGImageRef image
= (CGImageRef
)( bmp
.CreateCGImage() );
1654 HIRect r
= CGRectMake( x
, y
, w
, h
);
1655 if ( bmp
.GetDepth() == 1 )
1657 // is is a mask, the '1' in the mask tell where to draw the current brush
1658 if ( !m_brush
.IsNull() )
1660 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1662 // TODO clip to mask
1664 CGContextSaveGState( m_cgContext );
1665 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1666 CGContextClip( m_cgContext );
1667 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1668 CGContextRestoreGState( m_cgContext);
1673 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1674 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1680 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1682 CGImageRelease( image
);
1685 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1689 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1690 CGContextSaveGState( m_cgContext
);
1691 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1692 CGContextScaleCTM( m_cgContext
, 1, -1 );
1693 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1694 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1695 CGContextRestoreGState( m_cgContext
);
1698 void wxMacCoreGraphicsContext::PushState()
1702 CGContextSaveGState( m_cgContext
);
1705 void wxMacCoreGraphicsContext::PopState()
1709 CGContextRestoreGState( m_cgContext
);
1712 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1714 DrawText(str
, x
, y
, 0.0);
1717 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1719 if ( m_font
.IsNull() )
1724 OSStatus status
= noErr
;
1725 ATSUTextLayout atsuLayout
;
1726 UniCharCount chars
= str
.length();
1727 UniChar
* ubuf
= NULL
;
1729 #if SIZEOF_WCHAR_T == 4
1730 wxMBConvUTF16 converter
;
1732 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1733 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1734 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1736 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1737 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1738 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1739 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1741 chars
= unicharlen
/ 2;
1744 ubuf
= (UniChar
*) str
.wc_str();
1746 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1747 chars
= wxWcslen( wchar
.data() );
1748 ubuf
= (UniChar
*) wchar
.data();
1752 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1753 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1754 &chars
, &style
, &atsuLayout
);
1756 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1758 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1759 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1761 int iAngle
= int( angle
* RAD2DEG
);
1762 if ( abs(iAngle
) > 0 )
1764 Fixed atsuAngle
= IntToFixed( iAngle
);
1765 ATSUAttributeTag atsuTags
[] =
1767 kATSULineRotationTag
,
1769 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1773 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1777 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1778 atsuTags
, atsuSizes
, atsuValues
);
1782 ATSUAttributeTag atsuTags
[] =
1786 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1788 sizeof( CGContextRef
) ,
1790 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1794 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1795 atsuTags
, atsuSizes
, atsuValues
);
1798 ATSUTextMeasurement textBefore
, textAfter
;
1799 ATSUTextMeasurement ascent
, descent
;
1801 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1802 &textBefore
, &textAfter
, &ascent
, &descent
);
1804 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1807 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1808 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1810 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1811 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1812 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1814 CGContextSaveGState(m_cgContext
);
1815 CGContextTranslateCTM(m_cgContext
, x
, y
);
1816 CGContextScaleCTM(m_cgContext
, 1, -1);
1817 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1818 IntToFixed(0) , IntToFixed(0) );
1820 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1822 CGContextRestoreGState(m_cgContext
);
1824 ::ATSUDisposeTextLayout(atsuLayout
);
1826 #if SIZEOF_WCHAR_T == 4
1831 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1832 wxDouble
*descent
, wxDouble
*externalLeading
) const
1834 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1842 if ( externalLeading
)
1843 *externalLeading
= 0;
1848 OSStatus status
= noErr
;
1850 ATSUTextLayout atsuLayout
;
1851 UniCharCount chars
= str
.length();
1852 UniChar
* ubuf
= NULL
;
1854 #if SIZEOF_WCHAR_T == 4
1855 wxMBConvUTF16 converter
;
1857 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1858 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1859 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1861 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1862 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1863 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1864 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1866 chars
= unicharlen
/ 2;
1869 ubuf
= (UniChar
*) str
.wc_str();
1871 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1872 chars
= wxWcslen( wchar
.data() );
1873 ubuf
= (UniChar
*) wchar
.data();
1877 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1878 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1879 &chars
, &style
, &atsuLayout
);
1881 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1883 ATSUTextMeasurement textBefore
, textAfter
;
1884 ATSUTextMeasurement textAscent
, textDescent
;
1886 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1887 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1890 *height
= FixedToInt(textAscent
+ textDescent
);
1892 *descent
= FixedToInt(textDescent
);
1893 if ( externalLeading
)
1894 *externalLeading
= 0;
1896 *width
= FixedToInt(textAfter
- textBefore
);
1898 ::ATSUDisposeTextLayout(atsuLayout
);
1899 #if SIZEOF_WCHAR_T == 4
1904 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1907 widths
.Add(0, text
.length());
1912 ATSUTextLayout atsuLayout
;
1913 UniCharCount chars
= text
.length();
1914 UniChar
* ubuf
= NULL
;
1916 #if SIZEOF_WCHAR_T == 4
1917 wxMBConvUTF16 converter
;
1919 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1920 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1921 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1923 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1924 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1925 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1926 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1928 chars
= unicharlen
/ 2;
1931 ubuf
= (UniChar
*) text
.wc_str();
1933 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1934 chars
= wxWcslen( wchar
.data() );
1935 ubuf
= (UniChar
*) wchar
.data();
1939 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1940 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1941 &chars
, &style
, &atsuLayout
);
1943 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1945 unsigned long actualNumberOfBounds
= 0;
1946 ATSTrapezoid glyphBounds
;
1948 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1950 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1951 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1952 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1955 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1956 //unsigned char uch = s[i];
1959 ::ATSUDisposeTextLayout(atsuLayout
);
1960 #if SIZEOF_WCHAR_T == 4
1965 void * wxMacCoreGraphicsContext::GetNativeContext()
1970 // concatenates this transform with the current transform of this context
1971 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1974 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1976 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1979 // sets the transform of this context
1980 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1984 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1985 transform
= CGAffineTransformInvert( transform
) ;
1986 CGContextConcatCTM( m_cgContext
, transform
);
1987 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1991 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
1995 // gets the matrix of this context
1996 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
1998 wxGraphicsMatrix m
= CreateMatrix();
1999 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
2000 CGContextGetCTM( m_cgContext
));
2008 //-----------------------------------------------------------------------------
2009 // wxMacCoreGraphicsRenderer declaration
2010 //-----------------------------------------------------------------------------
2012 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2015 wxMacCoreGraphicsRenderer() {}
2017 virtual ~wxMacCoreGraphicsRenderer() {}
2021 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2023 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2025 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2027 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2029 virtual wxGraphicsContext
* CreateMeasuringContext();
2033 virtual wxGraphicsPath
CreatePath();
2037 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2038 wxDouble tx
=0.0, wxDouble ty
=0.0);
2041 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2043 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2045 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2046 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2047 const wxColour
&c1
, const wxColour
&c2
) ;
2049 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2050 // with radius r and color cColor
2051 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2052 const wxColour
&oColor
, const wxColour
&cColor
) ;
2055 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2058 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2061 //-----------------------------------------------------------------------------
2062 // wxMacCoreGraphicsRenderer implementation
2063 //-----------------------------------------------------------------------------
2065 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2067 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2069 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2071 return &gs_MacCoreGraphicsRenderer
;
2074 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2076 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2079 return new wxMacCoreGraphicsContext(this,
2080 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2084 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2088 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2090 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2094 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2096 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2099 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2101 return new wxMacCoreGraphicsContext(this, window
);
2104 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2106 return new wxMacCoreGraphicsContext(this);
2111 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2114 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2121 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2122 wxDouble tx
, wxDouble ty
)
2125 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2126 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2131 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2133 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2134 return wxNullGraphicsPen
;
2138 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2143 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2145 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2146 return wxNullGraphicsBrush
;
2150 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2155 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2156 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2157 const wxColour
&c1
, const wxColour
&c2
)
2160 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2161 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2166 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2167 // with radius r and color cColor
2168 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2169 const wxColour
&oColor
, const wxColour
&cColor
)
2172 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2173 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2179 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2184 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2188 return wxNullGraphicsFont
;