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
->CGImageCreate() , 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 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
488 delete[] m_patternColorComponents
;
491 void wxMacCoreGraphicsColour::Init()
494 m_patternColorComponents
= NULL
;
497 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
501 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
502 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
503 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
504 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
508 CGContextSetFillColorWithColor( cgContext
, m_color
);
512 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
517 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
520 if ( brush
.GetStyle() == wxSOLID
)
522 if ( brush
.MacGetBrushKind() == kwxMacBrushTheme
)
525 HIThemeBrushCreateCGColor( brush
.MacGetTheme(), &color
);
526 m_color
.Set( color
) ;
530 CGFloat components
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
531 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
532 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
535 else if ( brush
.IsHatch() )
538 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
539 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
541 m_patternColorComponents
= new CGFloat
[4] ;
542 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
543 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
544 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
545 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
549 // now brush is a bitmap
550 wxBitmap
* bmp
= brush
.GetStipple();
551 if ( bmp
&& bmp
->Ok() )
554 m_patternColorComponents
= new CGFloat
[1] ;
555 m_patternColorComponents
[0] = 1.0;
556 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
557 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
562 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
565 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
566 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
567 ~wxMacCoreGraphicsBrushData ();
569 virtual void Apply( wxGraphicsContext
* context
);
570 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
571 const wxColour
&c1
, const wxColour
&c2
);
572 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
573 const wxColour
&oColor
, const wxColour
&cColor
);
575 virtual bool IsShading() { return m_isShading
; }
576 CGShadingRef
GetShading() { return m_shading
; }
578 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
579 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
582 wxMacCoreGraphicsColour m_cgColor
;
585 CGFunctionRef m_gradientFunction
;
586 CGShadingRef m_shading
;
587 CGFloat
*m_gradientComponents
;
590 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
595 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
596 const wxColour
&c1
, const wxColour
&c2
)
598 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
599 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
603 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
604 const wxColour
&oColor
, const wxColour
&cColor
)
606 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
607 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
611 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
618 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
621 CGShadingRelease(m_shading
);
623 if( m_gradientFunction
)
624 CGFunctionRelease(m_gradientFunction
);
626 delete[] m_gradientComponents
;
629 void wxMacCoreGraphicsBrushData::Init()
631 m_gradientFunction
= NULL
;
633 m_gradientComponents
= NULL
;
637 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
639 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
643 // nothing to set as shades are processed by clipping using the path and filling
647 m_cgColor
.Apply( cg
);
651 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
653 CGFloat
* colors
= (CGFloat
*) info
;
655 for( int i
= 0 ; i
< 4 ; ++i
)
657 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
661 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
663 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
664 static const CGFloat input_value_range
[2] = { 0, 1 };
665 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
666 m_gradientComponents
= new CGFloat
[8] ;
667 m_gradientComponents
[0] = c1
.Red() / 255.0;
668 m_gradientComponents
[1] = c1
.Green() / 255.0;
669 m_gradientComponents
[2] = c1
.Blue() / 255.0;
670 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
671 m_gradientComponents
[4] = c2
.Red() / 255.0;
672 m_gradientComponents
[5] = c2
.Green() / 255.0;
673 m_gradientComponents
[6] = c2
.Blue() / 255.0;
674 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
676 return CGFunctionCreate ( m_gradientComponents
, 1,
687 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
690 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
691 ~wxMacCoreGraphicsFontData();
693 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
695 ATSUStyle m_macATSUIStyle
;
698 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
700 m_macATSUIStyle
= NULL
;
704 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
706 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
708 // we need the scale here ...
710 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
712 col
.GetRGBColor( &atsuColor
);
713 ATSUAttributeTag atsuTags
[] =
718 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
723 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
729 status
= ::ATSUSetAttributes(
730 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
731 atsuTags
, atsuSizes
, atsuValues
);
733 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
736 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
738 if ( m_macATSUIStyle
)
740 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
741 m_macATSUIStyle
= NULL
;
749 //-----------------------------------------------------------------------------
750 // wxMacCoreGraphicsMatrix declaration
751 //-----------------------------------------------------------------------------
753 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
756 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
758 virtual ~wxMacCoreGraphicsMatrixData() ;
760 virtual wxGraphicsObjectRefData
*Clone() const ;
762 // concatenates the matrix
763 virtual void Concat( const wxGraphicsMatrixData
*t
);
765 // sets the matrix to the respective values
766 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
767 wxDouble tx
=0.0, wxDouble ty
=0.0);
769 // gets the component valuess of the matrix
770 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
771 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
773 // makes this the inverse matrix
774 virtual void Invert();
776 // returns true if the elements of the transformation matrix are equal ?
777 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
779 // return true if this is the identity matrix
780 virtual bool IsIdentity() const;
786 // add the translation to this matrix
787 virtual void Translate( wxDouble dx
, wxDouble dy
);
789 // add the scale to this matrix
790 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
792 // add the rotation to this matrix (radians)
793 virtual void Rotate( wxDouble angle
);
796 // apply the transforms
799 // applies that matrix to the point
800 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
802 // applies the matrix except for translations
803 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
805 // returns the native representation
806 virtual void * GetNativeMatrix() const;
809 CGAffineTransform m_matrix
;
812 //-----------------------------------------------------------------------------
813 // wxMacCoreGraphicsMatrix implementation
814 //-----------------------------------------------------------------------------
816 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
820 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
824 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
826 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
827 m
->m_matrix
= m_matrix
;
831 // concatenates the matrix
832 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
834 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
837 // sets the matrix to the respective values
838 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
839 wxDouble tx
, wxDouble ty
)
841 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
844 // gets the component valuess of the matrix
845 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
846 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
848 if (a
) *a
= m_matrix
.a
;
849 if (b
) *b
= m_matrix
.b
;
850 if (c
) *c
= m_matrix
.c
;
851 if (d
) *d
= m_matrix
.d
;
852 if (tx
) *tx
= m_matrix
.tx
;
853 if (ty
) *ty
= m_matrix
.ty
;
856 // makes this the inverse matrix
857 void wxMacCoreGraphicsMatrixData::Invert()
859 m_matrix
= CGAffineTransformInvert( m_matrix
);
862 // returns true if the elements of the transformation matrix are equal ?
863 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
865 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
868 // return true if this is the identity matrix
869 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
871 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
872 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
879 // add the translation to this matrix
880 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
882 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
885 // add the scale to this matrix
886 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
888 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
891 // add the rotation to this matrix (radians)
892 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
894 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
898 // apply the transforms
901 // applies that matrix to the point
902 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
904 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
910 // applies the matrix except for translations
911 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
913 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
918 // returns the native representation
919 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
921 return (void*) &m_matrix
;
928 //-----------------------------------------------------------------------------
929 // wxMacCoreGraphicsPath declaration
930 //-----------------------------------------------------------------------------
932 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
935 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
937 ~wxMacCoreGraphicsPathData();
939 virtual wxGraphicsObjectRefData
*Clone() const;
941 // begins a new subpath at (x,y)
942 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
944 // adds a straight line from the current point to (x,y)
945 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
947 // adds a cubic Bezier curve from the current point, using two control points and an end point
948 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
950 // closes the current sub-path
951 virtual void CloseSubpath();
953 // gets the last point of the current path, (0,0) if not yet set
954 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
956 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
957 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
960 // These are convenience functions which - if not available natively will be assembled
961 // using the primitives from above
964 // adds a quadratic Bezier curve from the current point, using a control point and an end point
965 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
967 // appends a rectangle as a new closed subpath
968 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
970 // appends an ellipsis as a new closed subpath fitting the passed rectangle
971 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
973 // 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)
974 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
977 virtual void AddPath( const wxGraphicsPathData
* path
);
979 // returns the native path
980 virtual void * GetNativePath() const { return m_path
; }
982 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
983 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
985 // transforms each point of this path by the matrix
986 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
988 // gets the bounding box enclosing all points (possibly including control points)
989 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
991 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
993 CGMutablePathRef m_path
;
996 //-----------------------------------------------------------------------------
997 // wxMacCoreGraphicsPath implementation
998 //-----------------------------------------------------------------------------
1000 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1005 m_path
= CGPathCreateMutable();
1008 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1010 CGPathRelease( m_path
);
1013 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1015 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1020 // opens (starts) a new subpath
1021 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1023 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1026 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1028 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1031 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1033 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1036 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1038 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1041 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1043 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1044 CGPathAddRect( m_path
, NULL
, cgRect
);
1047 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1049 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1052 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1053 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1055 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1056 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1059 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1061 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1064 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1066 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1069 // closes the current subpath
1070 void wxMacCoreGraphicsPathData::CloseSubpath()
1072 CGPathCloseSubpath( m_path
);
1075 // gets the last point of the current path, (0,0) if not yet set
1076 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1078 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1083 // transforms each point of this path by the matrix
1084 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1086 CGMutablePathRef p
= CGPathCreateMutable() ;
1087 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1088 CGPathRelease( m_path
);
1092 // gets the bounding box enclosing all points (possibly including control points)
1093 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1095 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1096 *x
= bounds
.origin
.x
;
1097 *y
= bounds
.origin
.y
;
1098 *w
= bounds
.size
.width
;
1099 *h
= bounds
.size
.height
;
1102 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1104 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1111 //-----------------------------------------------------------------------------
1112 // wxMacCoreGraphicsContext declaration
1113 //-----------------------------------------------------------------------------
1115 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1118 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1120 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1122 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1124 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1126 wxMacCoreGraphicsContext();
1128 ~wxMacCoreGraphicsContext();
1132 // returns the size of the graphics context in device coordinates
1133 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1135 virtual void StartPage( wxDouble width
, wxDouble height
);
1137 virtual void EndPage();
1139 virtual void Flush();
1141 // push the current state of the context, ie the transformation matrix on a stack
1142 virtual void PushState();
1144 // pops a stored state from the stack
1145 virtual void PopState();
1147 // clips drawings to the region
1148 virtual void Clip( const wxRegion
®ion
);
1150 // clips drawings to the rect
1151 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1153 // resets the clipping to original extent
1154 virtual void ResetClip();
1156 virtual void * GetNativeContext();
1158 bool SetLogicalFunction( int function
);
1164 virtual void Translate( wxDouble dx
, wxDouble dy
);
1167 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1170 virtual void Rotate( wxDouble angle
);
1172 // concatenates this transform with the current transform of this context
1173 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1175 // sets the transform of this context
1176 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1178 // gets the matrix of this context
1179 virtual wxGraphicsMatrix
GetTransform() const;
1181 // setting the paint
1184 // strokes along a path with the current pen
1185 virtual void StrokePath( const wxGraphicsPath
&path
);
1187 // fills a path with the current brush
1188 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1190 // draws a path by first filling and then stroking
1191 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1193 virtual bool ShouldOffset() const
1196 if ( !m_pen
.IsNull() )
1198 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1199 if ( penwidth
== 0 )
1202 return ( penwidth
% 2 ) == 1;
1208 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1210 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1212 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1213 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1215 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1221 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1223 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1225 void SetNativeContext( CGContextRef cg
);
1227 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1228 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1231 void EnsureIsValid();
1233 CGContextRef m_cgContext
;
1234 WindowRef m_windowRef
;
1235 bool m_releaseContext
;
1236 CGAffineTransform m_windowTransform
;
1240 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1243 //-----------------------------------------------------------------------------
1244 // device context implementation
1246 // more and more of the dc functionality should be implemented by calling
1247 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1248 // also coordinate conversions should be moved to native matrix ops
1249 //-----------------------------------------------------------------------------
1251 // we always stock two context states, one at entry, to be able to preserve the
1252 // state we were called with, the other one after changing to HI Graphics orientation
1253 // (this one is used for getting back clippings etc)
1255 //-----------------------------------------------------------------------------
1256 // wxMacCoreGraphicsContext implementation
1257 //-----------------------------------------------------------------------------
1259 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1261 class wxQuartzOffsetHelper
1264 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1269 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1271 ~wxQuartzOffsetHelper( )
1274 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1281 void wxMacCoreGraphicsContext::Init()
1284 m_releaseContext
= false;
1289 HIRect r
= CGRectMake(0,0,0,0);
1290 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1293 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1296 SetNativeContext(cgcontext
);
1301 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1304 m_windowRef
= window
;
1307 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1310 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1311 int originX
, originY
;
1312 originX
= originY
= 0;
1313 window
->MacWindowToRootWindow( &originX
, &originY
);
1315 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1317 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1318 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1319 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1322 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1327 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1330 wxLogDebug(wxT("Illegal Constructor called"));
1333 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1335 SetNativeContext(NULL
);
1338 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1345 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1348 if ( width
!= 0 && height
!= 0)
1349 r
= CGRectMake( 0 , 0 , width
, height
);
1351 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1353 CGContextBeginPage(m_cgContext
, &r
);
1354 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1355 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1358 void wxMacCoreGraphicsContext::EndPage()
1360 CGContextEndPage(m_cgContext
);
1363 void wxMacCoreGraphicsContext::Flush()
1365 CGContextFlush(m_cgContext
);
1368 void wxMacCoreGraphicsContext::EnsureIsValid()
1374 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1378 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1380 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1381 CGContextSaveGState( m_cgContext
);
1382 m_releaseContext
= true;
1383 if ( !HIShapeIsEmpty(m_clipRgn
) )
1385 // the clip region is in device coordinates, so we convert this again to user coordinates
1386 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1387 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1388 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1389 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1390 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1391 CGContextClip( m_cgContext
);
1393 CGContextSaveGState( m_cgContext
);
1397 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1399 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1401 if (m_logicalFunction
== function
)
1406 bool retval
= false;
1408 if ( function
== wxCOPY
)
1411 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1413 else if ( function
== wxINVERT
|| function
== wxXOR
)
1415 // change color to white
1416 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1417 CGContextSetShouldAntialias( m_cgContext
, false );
1422 m_logicalFunction
= function
;
1426 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1430 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1431 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1432 CGContextClip( m_cgContext
);
1437 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1438 // to regions we try at least to have correct translations
1439 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1440 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1441 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1443 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1444 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1445 m_clipRgn
.Set(mutableShape
);
1449 // clips drawings to the rect
1450 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1452 HIRect r
= CGRectMake( x
, y
, w
, h
);
1455 CGContextClipToRect( m_cgContext
, r
);
1459 // the clipping itself must be stored as device coordinates, otherwise
1460 // we cannot apply it back correctly
1461 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1462 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1466 // resets the clipping to original extent
1467 void wxMacCoreGraphicsContext::ResetClip()
1471 // there is no way for clearing the clip, we can only revert to the stored
1472 // state, but then we have to make sure everything else is NOT restored
1473 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1474 CGContextRestoreGState( m_cgContext
);
1475 CGContextSaveGState( m_cgContext
);
1476 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1477 transformNew
= CGAffineTransformInvert( transformNew
) ;
1478 CGContextConcatCTM( m_cgContext
, transformNew
);
1479 CGContextConcatCTM( m_cgContext
, transform
);
1483 HIRect r
= CGRectMake(0,0,0,0);
1484 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1488 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1490 if ( m_pen
.IsNull() )
1495 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1497 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1498 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1499 CGContextStrokePath( m_cgContext
);
1502 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1504 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1506 // when using shading, we cannot draw pen and brush at the same time
1507 // revert to the base implementation of first filling and then stroking
1508 wxGraphicsContext::DrawPath( path
, fillStyle
);
1512 CGPathDrawingMode mode
= kCGPathFill
;
1513 if ( m_brush
.IsNull() )
1515 if ( m_pen
.IsNull() )
1518 mode
= kCGPathStroke
;
1522 if ( m_pen
.IsNull() )
1524 if ( fillStyle
== wxODDEVEN_RULE
)
1525 mode
= kCGPathEOFill
;
1531 if ( fillStyle
== wxODDEVEN_RULE
)
1532 mode
= kCGPathEOFillStroke
;
1534 mode
= kCGPathFillStroke
;
1540 if ( !m_brush
.IsNull() )
1541 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1542 if ( !m_pen
.IsNull() )
1543 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1545 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1547 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1548 CGContextDrawPath( m_cgContext
, mode
);
1551 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1553 if ( m_brush
.IsNull() )
1558 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1560 CGContextSaveGState( m_cgContext
);
1561 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1562 CGContextClip( m_cgContext
);
1563 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1564 CGContextRestoreGState( m_cgContext
);
1568 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1569 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1570 if ( fillStyle
== wxODDEVEN_RULE
)
1571 CGContextEOFillPath( m_cgContext
);
1573 CGContextFillPath( m_cgContext
);
1577 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1579 // we allow either setting or clearing but not replacing
1580 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1584 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1585 CGContextRestoreGState( m_cgContext
);
1586 CGContextRestoreGState( m_cgContext
);
1587 if ( m_releaseContext
)
1590 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1594 CGContextRelease(m_cgContext
);
1600 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1601 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1602 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1603 // for this one operation.
1605 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1609 CGContextRetain(m_cgContext
);
1610 CGContextSaveGState( m_cgContext
);
1611 CGContextSaveGState( m_cgContext
);
1612 m_releaseContext
= false;
1616 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1619 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1621 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1624 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1627 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1629 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1632 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1635 CGContextRotateCTM( m_cgContext
, angle
);
1637 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1640 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1644 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() );
1645 HIRect r
= CGRectMake( x
, y
, w
, h
);
1646 if ( bmp
.GetDepth() == 1 )
1648 // is is a mask, the '1' in the mask tell where to draw the current brush
1649 if ( !m_brush
.IsNull() )
1651 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1653 // TODO clip to mask
1655 CGContextSaveGState( m_cgContext );
1656 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1657 CGContextClip( m_cgContext );
1658 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1659 CGContextRestoreGState( m_cgContext);
1664 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1665 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1671 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1673 CGImageRelease( image
);
1676 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1680 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1681 CGContextSaveGState( m_cgContext
);
1682 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1683 CGContextScaleCTM( m_cgContext
, 1, -1 );
1684 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1685 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1686 CGContextRestoreGState( m_cgContext
);
1689 void wxMacCoreGraphicsContext::PushState()
1693 CGContextSaveGState( m_cgContext
);
1696 void wxMacCoreGraphicsContext::PopState()
1700 CGContextRestoreGState( m_cgContext
);
1703 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1705 DrawText(str
, x
, y
, 0.0);
1708 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1710 if ( m_font
.IsNull() )
1715 OSStatus status
= noErr
;
1716 ATSUTextLayout atsuLayout
;
1717 UniCharCount chars
= str
.length();
1718 UniChar
* ubuf
= NULL
;
1720 #if SIZEOF_WCHAR_T == 4
1721 wxMBConvUTF16 converter
;
1723 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1724 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1725 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1727 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1728 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1729 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1730 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1732 chars
= unicharlen
/ 2;
1735 ubuf
= (UniChar
*) str
.wc_str();
1737 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1738 chars
= wxWcslen( wchar
.data() );
1739 ubuf
= (UniChar
*) wchar
.data();
1743 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1744 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1745 &chars
, &style
, &atsuLayout
);
1747 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1749 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1750 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1752 int iAngle
= int( angle
* RAD2DEG
);
1753 if ( abs(iAngle
) > 0 )
1755 Fixed atsuAngle
= IntToFixed( iAngle
);
1756 ATSUAttributeTag atsuTags
[] =
1758 kATSULineRotationTag
,
1760 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1764 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1768 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1769 atsuTags
, atsuSizes
, atsuValues
);
1773 ATSUAttributeTag atsuTags
[] =
1777 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1779 sizeof( CGContextRef
) ,
1781 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1785 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1786 atsuTags
, atsuSizes
, atsuValues
);
1789 ATSUTextMeasurement textBefore
, textAfter
;
1790 ATSUTextMeasurement ascent
, descent
;
1792 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1793 &textBefore
, &textAfter
, &ascent
, &descent
);
1795 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1798 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1799 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1801 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1802 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1803 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1805 CGContextSaveGState(m_cgContext
);
1806 CGContextTranslateCTM(m_cgContext
, x
, y
);
1807 CGContextScaleCTM(m_cgContext
, 1, -1);
1808 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1809 IntToFixed(0) , IntToFixed(0) );
1811 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1813 CGContextRestoreGState(m_cgContext
);
1815 ::ATSUDisposeTextLayout(atsuLayout
);
1817 #if SIZEOF_WCHAR_T == 4
1822 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1823 wxDouble
*descent
, wxDouble
*externalLeading
) const
1825 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1833 if ( externalLeading
)
1834 *externalLeading
= 0;
1839 OSStatus status
= noErr
;
1841 ATSUTextLayout atsuLayout
;
1842 UniCharCount chars
= str
.length();
1843 UniChar
* ubuf
= NULL
;
1845 #if SIZEOF_WCHAR_T == 4
1846 wxMBConvUTF16 converter
;
1848 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1849 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1850 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1852 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1853 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1854 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1855 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1857 chars
= unicharlen
/ 2;
1860 ubuf
= (UniChar
*) str
.wc_str();
1862 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1863 chars
= wxWcslen( wchar
.data() );
1864 ubuf
= (UniChar
*) wchar
.data();
1868 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1869 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1870 &chars
, &style
, &atsuLayout
);
1872 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1874 ATSUTextMeasurement textBefore
, textAfter
;
1875 ATSUTextMeasurement textAscent
, textDescent
;
1877 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1878 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1881 *height
= FixedToInt(textAscent
+ textDescent
);
1883 *descent
= FixedToInt(textDescent
);
1884 if ( externalLeading
)
1885 *externalLeading
= 0;
1887 *width
= FixedToInt(textAfter
- textBefore
);
1889 ::ATSUDisposeTextLayout(atsuLayout
);
1890 #if SIZEOF_WCHAR_T == 4
1895 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1898 widths
.Add(0, text
.length());
1903 ATSUTextLayout atsuLayout
;
1904 UniCharCount chars
= text
.length();
1905 UniChar
* ubuf
= NULL
;
1907 #if SIZEOF_WCHAR_T == 4
1908 wxMBConvUTF16 converter
;
1910 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1911 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1912 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1914 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1915 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1916 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1917 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1919 chars
= unicharlen
/ 2;
1922 ubuf
= (UniChar
*) text
.wc_str();
1924 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1925 chars
= wxWcslen( wchar
.data() );
1926 ubuf
= (UniChar
*) wchar
.data();
1930 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1931 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1932 &chars
, &style
, &atsuLayout
);
1934 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1936 unsigned long actualNumberOfBounds
= 0;
1937 ATSTrapezoid glyphBounds
;
1939 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1941 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1942 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1943 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1946 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1947 //unsigned char uch = s[i];
1950 ::ATSUDisposeTextLayout(atsuLayout
);
1951 #if SIZEOF_WCHAR_T == 4
1956 void * wxMacCoreGraphicsContext::GetNativeContext()
1961 // concatenates this transform with the current transform of this context
1962 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1965 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1967 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1970 // sets the transform of this context
1971 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1975 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1976 transform
= CGAffineTransformInvert( transform
) ;
1977 CGContextConcatCTM( m_cgContext
, transform
);
1978 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1982 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
1986 // gets the matrix of this context
1987 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
1989 wxGraphicsMatrix m
= CreateMatrix();
1990 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
1991 CGContextGetCTM( m_cgContext
));
1999 //-----------------------------------------------------------------------------
2000 // wxMacCoreGraphicsRenderer declaration
2001 //-----------------------------------------------------------------------------
2003 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2006 wxMacCoreGraphicsRenderer() {}
2008 virtual ~wxMacCoreGraphicsRenderer() {}
2012 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2014 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2016 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2018 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2020 virtual wxGraphicsContext
* CreateMeasuringContext();
2024 virtual wxGraphicsPath
CreatePath();
2028 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2029 wxDouble tx
=0.0, wxDouble ty
=0.0);
2032 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2034 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2036 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2037 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2038 const wxColour
&c1
, const wxColour
&c2
) ;
2040 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2041 // with radius r and color cColor
2042 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2043 const wxColour
&oColor
, const wxColour
&cColor
) ;
2046 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2049 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2052 //-----------------------------------------------------------------------------
2053 // wxMacCoreGraphicsRenderer implementation
2054 //-----------------------------------------------------------------------------
2056 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2058 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2060 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2062 return &gs_MacCoreGraphicsRenderer
;
2065 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2067 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2070 return new wxMacCoreGraphicsContext(this,
2071 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2075 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2079 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2081 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2085 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2087 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2090 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2092 return new wxMacCoreGraphicsContext(this, window
);
2095 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2097 return new wxMacCoreGraphicsContext(this);
2102 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2105 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2112 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2113 wxDouble tx
, wxDouble ty
)
2116 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2117 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2122 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2124 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2125 return wxNullGraphicsPen
;
2129 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2134 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2136 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2137 return wxNullGraphicsBrush
;
2141 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2146 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2147 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2148 const wxColour
&c1
, const wxColour
&c2
)
2151 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2152 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2157 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2158 // with radius r and color cColor
2159 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2160 const wxColour
&oColor
, const wxColour
&cColor
)
2163 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2164 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2170 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2175 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2179 return wxNullGraphicsFont
;