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 // CGPattern wrapper class: always allocate on heap, never call destructor
63 class wxMacCoreGraphicsPattern
66 wxMacCoreGraphicsPattern() {}
68 // is guaranteed to be called only with a non-Null CGContextRef
69 virtual void Render( CGContextRef ctxRef
) = 0;
71 operator CGPatternRef() const { return m_patternRef
; }
74 virtual ~wxMacCoreGraphicsPattern()
76 // as this is called only when the m_patternRef is been released;
77 // don't release it again
80 static void _Render( void *info
, CGContextRef ctxRef
)
82 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
84 self
->Render( ctxRef
);
87 static void _Dispose( void *info
)
89 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
93 CGPatternRef m_patternRef
;
95 static const CGPatternCallbacks ms_Callbacks
;
98 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
100 class ImagePattern
: public wxMacCoreGraphicsPattern
103 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
105 wxASSERT( bmp
&& bmp
->Ok() );
107 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
);
110 // ImagePattern takes ownership of CGImageRef passed in
111 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
116 Init( image
, transform
);
119 virtual void Render( CGContextRef ctxRef
)
122 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
126 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
131 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
132 m_patternRef
= CGPatternCreate(
133 this , m_imageBounds
, transform
,
134 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
135 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
139 virtual ~ImagePattern()
142 CGImageRelease( m_image
);
146 CGRect m_imageBounds
;
149 class HatchPattern
: public wxMacCoreGraphicsPattern
152 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
154 m_hatch
= hatchstyle
;
155 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
156 m_patternRef
= CGPatternCreate(
157 this , m_imageBounds
, transform
,
158 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
159 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
162 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
164 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
167 virtual void Render( CGContextRef ctxRef
)
171 case wxBDIAGONAL_HATCH
:
175 { 8.0 , 0.0 } , { 0.0 , 8.0 }
177 StrokeLineSegments( ctxRef
, pts
, 2 );
181 case wxCROSSDIAG_HATCH
:
185 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
186 { 8.0 , 0.0 } , { 0.0 , 8.0 }
188 StrokeLineSegments( ctxRef
, pts
, 4 );
192 case wxFDIAGONAL_HATCH
:
196 { 0.0 , 0.0 } , { 8.0 , 8.0 }
198 StrokeLineSegments( ctxRef
, pts
, 2 );
206 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
207 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
209 StrokeLineSegments( ctxRef
, pts
, 4 );
213 case wxHORIZONTAL_HATCH
:
217 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
219 StrokeLineSegments( ctxRef
, pts
, 2 );
223 case wxVERTICAL_HATCH
:
227 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
229 StrokeLineSegments( ctxRef
, pts
, 2 );
239 virtual ~HatchPattern() {}
241 CGRect m_imageBounds
;
245 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
248 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
249 ~wxMacCoreGraphicsPenData();
252 virtual void Apply( wxGraphicsContext
* context
);
253 virtual wxDouble
GetWidth() { return m_width
; }
257 wxMacCFRefHolder
<CGColorRef
> m_color
;
258 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
264 const CGFloat
*m_lengths
;
265 CGFloat
*m_userLengths
;
269 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
270 CGFloat
* m_patternColorComponents
;
273 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
274 wxGraphicsObjectRefData( renderer
)
278 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
279 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
280 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
282 // TODO: * m_dc->m_scaleX
283 m_width
= pen
.GetWidth();
287 switch ( pen
.GetCap() )
290 m_cap
= kCGLineCapRound
;
293 case wxCAP_PROJECTING
:
294 m_cap
= kCGLineCapSquare
;
298 m_cap
= kCGLineCapButt
;
302 m_cap
= kCGLineCapButt
;
306 switch ( pen
.GetJoin() )
309 m_join
= kCGLineJoinBevel
;
313 m_join
= kCGLineJoinMiter
;
317 m_join
= kCGLineJoinRound
;
321 m_join
= kCGLineJoinMiter
;
325 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
327 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
328 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
329 static const CGFloat dashed
[] = { 19.0 , 9.0 };
330 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
332 switch ( pen
.GetStyle() )
338 m_count
= WXSIZEOF(dotted
);
339 m_userLengths
= new CGFloat
[ m_count
] ;
340 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
341 m_lengths
= m_userLengths
;
345 m_count
= WXSIZEOF(dashed
);
350 m_count
= WXSIZEOF(short_dashed
);
351 m_lengths
= short_dashed
;
355 m_count
= WXSIZEOF(dotted_dashed
);
356 m_lengths
= dotted_dashed
;
361 m_count
= pen
.GetDashes( &dashes
);
362 if ((dashes
!= NULL
) && (m_count
> 0))
364 m_userLengths
= new CGFloat
[m_count
];
365 for ( int i
= 0; i
< m_count
; ++i
)
367 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
369 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
370 m_userLengths
[i
] = dashUnit
+ 2.0;
371 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
372 m_userLengths
[i
] = dashUnit
;
375 m_lengths
= m_userLengths
;
380 wxBitmap
* bmp
= pen
.GetStipple();
381 if ( bmp
&& bmp
->Ok() )
383 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
384 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
385 m_patternColorComponents
= new CGFloat
[1] ;
386 m_patternColorComponents
[0] = 1.0;
395 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
396 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
397 m_patternColorComponents
= new CGFloat
[4] ;
398 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
399 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
400 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
401 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
405 if ((m_lengths
!= NULL
) && (m_count
> 0))
407 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
408 m_cap
= kCGLineCapButt
;
412 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
414 delete[] m_userLengths
;
415 delete[] m_patternColorComponents
;
418 void wxMacCoreGraphicsPenData::Init()
421 m_userLengths
= NULL
;
424 m_patternColorComponents
= NULL
;
428 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
430 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
431 CGContextSetLineWidth( cg
, m_width
);
432 CGContextSetLineJoin( cg
, m_join
);
434 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
435 CGContextSetLineCap( cg
, m_cap
);
439 CGAffineTransform matrix
= CGContextGetCTM( cg
);
440 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
441 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
442 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
446 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
448 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
451 CGContextSetStrokeColorWithColor( cg
, m_color
);
459 static const char *gs_stripedback_xpm
[] = {
460 /* columns rows colors chars-per-pixel */
471 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
473 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
475 delete[] m_patternColorComponents
;
478 void wxMacCoreGraphicsColour::Init()
481 m_patternColorComponents
= NULL
;
484 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
488 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
489 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
490 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
491 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
495 CGContextSetFillColorWithColor( cgContext
, m_color
);
499 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
504 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
507 if ( brush
.GetStyle() == wxSOLID
)
509 if ( brush
.MacGetBrushKind() == kwxMacBrushTheme
)
512 HIThemeBrushCreateCGColor( brush
.MacGetTheme(), &color
);
513 m_color
.Set( color
) ;
517 CGFloat components
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
518 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
519 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
522 else if ( brush
.IsHatch() )
525 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
526 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
528 m_patternColorComponents
= new CGFloat
[4] ;
529 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
530 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
531 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
532 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
536 // now brush is a bitmap
537 wxBitmap
* bmp
= brush
.GetStipple();
538 if ( bmp
&& bmp
->Ok() )
541 m_patternColorComponents
= new CGFloat
[1] ;
542 m_patternColorComponents
[0] = 1.0;
543 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
544 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
549 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
552 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
553 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
554 ~wxMacCoreGraphicsBrushData ();
556 virtual void Apply( wxGraphicsContext
* context
);
557 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
558 const wxColour
&c1
, const wxColour
&c2
);
559 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
560 const wxColour
&oColor
, const wxColour
&cColor
);
562 virtual bool IsShading() { return m_isShading
; }
563 CGShadingRef
GetShading() { return m_shading
; }
565 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
566 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
569 wxMacCoreGraphicsColour m_cgColor
;
572 CGFunctionRef m_gradientFunction
;
573 CGShadingRef m_shading
;
574 CGFloat
*m_gradientComponents
;
577 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
582 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
583 const wxColour
&c1
, const wxColour
&c2
)
585 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
586 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
590 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
591 const wxColour
&oColor
, const wxColour
&cColor
)
593 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
594 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
598 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
605 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
608 CGShadingRelease(m_shading
);
610 if( m_gradientFunction
)
611 CGFunctionRelease(m_gradientFunction
);
613 delete[] m_gradientComponents
;
616 void wxMacCoreGraphicsBrushData::Init()
618 m_gradientFunction
= NULL
;
620 m_gradientComponents
= NULL
;
624 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
626 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
630 // nothing to set as shades are processed by clipping using the path and filling
634 m_cgColor
.Apply( cg
);
638 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
640 CGFloat
* colors
= (CGFloat
*) info
;
642 for( int i
= 0 ; i
< 4 ; ++i
)
644 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
648 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
650 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
651 static const CGFloat input_value_range
[2] = { 0, 1 };
652 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
653 m_gradientComponents
= new CGFloat
[8] ;
654 m_gradientComponents
[0] = c1
.Red() / 255.0;
655 m_gradientComponents
[1] = c1
.Green() / 255.0;
656 m_gradientComponents
[2] = c1
.Blue() / 255.0;
657 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
658 m_gradientComponents
[4] = c2
.Red() / 255.0;
659 m_gradientComponents
[5] = c2
.Green() / 255.0;
660 m_gradientComponents
[6] = c2
.Blue() / 255.0;
661 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
663 return CGFunctionCreate ( m_gradientComponents
, 1,
674 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
677 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
678 ~wxMacCoreGraphicsFontData();
680 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
682 ATSUStyle m_macATSUIStyle
;
685 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
687 m_macATSUIStyle
= NULL
;
691 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
693 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
695 // we need the scale here ...
697 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
698 RGBColor atsuColor
= MAC_WXCOLORREF( col
.GetPixel() );
699 ATSUAttributeTag atsuTags
[] =
704 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
709 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
715 status
= ::ATSUSetAttributes(
716 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
717 atsuTags
, atsuSizes
, atsuValues
);
719 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
722 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
724 if ( m_macATSUIStyle
)
726 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
727 m_macATSUIStyle
= NULL
;
735 //-----------------------------------------------------------------------------
736 // wxMacCoreGraphicsMatrix declaration
737 //-----------------------------------------------------------------------------
739 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
742 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
744 virtual ~wxMacCoreGraphicsMatrixData() ;
746 virtual wxGraphicsObjectRefData
*Clone() const ;
748 // concatenates the matrix
749 virtual void Concat( const wxGraphicsMatrixData
*t
);
751 // sets the matrix to the respective values
752 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
753 wxDouble tx
=0.0, wxDouble ty
=0.0);
755 // gets the component valuess of the matrix
756 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
757 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
759 // makes this the inverse matrix
760 virtual void Invert();
762 // returns true if the elements of the transformation matrix are equal ?
763 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
765 // return true if this is the identity matrix
766 virtual bool IsIdentity() const;
772 // add the translation to this matrix
773 virtual void Translate( wxDouble dx
, wxDouble dy
);
775 // add the scale to this matrix
776 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
778 // add the rotation to this matrix (radians)
779 virtual void Rotate( wxDouble angle
);
782 // apply the transforms
785 // applies that matrix to the point
786 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
788 // applies the matrix except for translations
789 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
791 // returns the native representation
792 virtual void * GetNativeMatrix() const;
795 CGAffineTransform m_matrix
;
798 //-----------------------------------------------------------------------------
799 // wxMacCoreGraphicsMatrix implementation
800 //-----------------------------------------------------------------------------
802 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
806 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
810 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
812 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
813 m
->m_matrix
= m_matrix
;
817 // concatenates the matrix
818 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
820 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
823 // sets the matrix to the respective values
824 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
825 wxDouble tx
, wxDouble ty
)
827 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
830 // gets the component valuess of the matrix
831 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
832 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
834 if (a
) *a
= m_matrix
.a
;
835 if (b
) *b
= m_matrix
.b
;
836 if (c
) *c
= m_matrix
.c
;
837 if (d
) *d
= m_matrix
.d
;
838 if (tx
) *tx
= m_matrix
.tx
;
839 if (ty
) *ty
= m_matrix
.ty
;
842 // makes this the inverse matrix
843 void wxMacCoreGraphicsMatrixData::Invert()
845 m_matrix
= CGAffineTransformInvert( m_matrix
);
848 // returns true if the elements of the transformation matrix are equal ?
849 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
851 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
854 // return true if this is the identity matrix
855 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
857 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
858 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
865 // add the translation to this matrix
866 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
868 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
871 // add the scale to this matrix
872 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
874 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
877 // add the rotation to this matrix (radians)
878 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
880 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
884 // apply the transforms
887 // applies that matrix to the point
888 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
890 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
896 // applies the matrix except for translations
897 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
899 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
904 // returns the native representation
905 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
907 return (void*) &m_matrix
;
914 //-----------------------------------------------------------------------------
915 // wxMacCoreGraphicsPath declaration
916 //-----------------------------------------------------------------------------
918 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
921 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
923 ~wxMacCoreGraphicsPathData();
925 virtual wxGraphicsObjectRefData
*Clone() const;
927 // begins a new subpath at (x,y)
928 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
930 // adds a straight line from the current point to (x,y)
931 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
933 // adds a cubic Bezier curve from the current point, using two control points and an end point
934 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
936 // closes the current sub-path
937 virtual void CloseSubpath();
939 // gets the last point of the current path, (0,0) if not yet set
940 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
942 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
943 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
946 // These are convenience functions which - if not available natively will be assembled
947 // using the primitives from above
950 // adds a quadratic Bezier curve from the current point, using a control point and an end point
951 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
953 // appends a rectangle as a new closed subpath
954 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
956 // appends an ellipsis as a new closed subpath fitting the passed rectangle
957 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
959 // 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)
960 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
963 virtual void AddPath( const wxGraphicsPathData
* path
);
965 // returns the native path
966 virtual void * GetNativePath() const { return m_path
; }
968 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
969 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
971 // transforms each point of this path by the matrix
972 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
974 // gets the bounding box enclosing all points (possibly including control points)
975 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
977 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
979 CGMutablePathRef m_path
;
982 //-----------------------------------------------------------------------------
983 // wxMacCoreGraphicsPath implementation
984 //-----------------------------------------------------------------------------
986 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
991 m_path
= CGPathCreateMutable();
994 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
996 CGPathRelease( m_path
);
999 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1001 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1006 // opens (starts) a new subpath
1007 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1009 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1012 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1014 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1017 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1019 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1022 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1024 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1027 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1029 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1030 CGPathAddRect( m_path
, NULL
, cgRect
);
1033 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1035 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1038 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1039 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1041 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1042 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1045 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1047 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1050 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1052 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1055 // closes the current subpath
1056 void wxMacCoreGraphicsPathData::CloseSubpath()
1058 CGPathCloseSubpath( m_path
);
1061 // gets the last point of the current path, (0,0) if not yet set
1062 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1064 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1069 // transforms each point of this path by the matrix
1070 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1072 CGMutablePathRef p
= CGPathCreateMutable() ;
1073 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1074 CGPathRelease( m_path
);
1078 // gets the bounding box enclosing all points (possibly including control points)
1079 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1081 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1082 *x
= bounds
.origin
.x
;
1083 *y
= bounds
.origin
.y
;
1084 *w
= bounds
.size
.width
;
1085 *h
= bounds
.size
.height
;
1088 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1090 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1097 //-----------------------------------------------------------------------------
1098 // wxMacCoreGraphicsContext declaration
1099 //-----------------------------------------------------------------------------
1101 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1104 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1106 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1108 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1110 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1112 wxMacCoreGraphicsContext();
1114 ~wxMacCoreGraphicsContext();
1118 // returns the size of the graphics context in device coordinates
1119 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1121 virtual void StartPage( wxDouble width
, wxDouble height
);
1123 virtual void EndPage();
1125 virtual void Flush();
1127 // push the current state of the context, ie the transformation matrix on a stack
1128 virtual void PushState();
1130 // pops a stored state from the stack
1131 virtual void PopState();
1133 // clips drawings to the region
1134 virtual void Clip( const wxRegion
®ion
);
1136 // clips drawings to the rect
1137 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1139 // resets the clipping to original extent
1140 virtual void ResetClip();
1142 virtual void * GetNativeContext();
1144 bool SetLogicalFunction( int function
);
1150 virtual void Translate( wxDouble dx
, wxDouble dy
);
1153 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1156 virtual void Rotate( wxDouble angle
);
1158 // concatenates this transform with the current transform of this context
1159 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1161 // sets the transform of this context
1162 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1164 // gets the matrix of this context
1165 virtual wxGraphicsMatrix
GetTransform() const;
1167 // setting the paint
1170 // strokes along a path with the current pen
1171 virtual void StrokePath( const wxGraphicsPath
&path
);
1173 // fills a path with the current brush
1174 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1176 // draws a path by first filling and then stroking
1177 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1179 virtual bool ShouldOffset() const
1182 if ( !m_pen
.IsNull() )
1184 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1185 if ( penwidth
== 0 )
1188 return ( penwidth
% 2 ) == 1;
1194 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1196 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1198 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1199 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1201 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1207 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1209 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1211 void SetNativeContext( CGContextRef cg
);
1213 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1214 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1217 void EnsureIsValid();
1219 CGContextRef m_cgContext
;
1220 WindowRef m_windowRef
;
1221 bool m_releaseContext
;
1222 CGAffineTransform m_windowTransform
;
1226 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1229 //-----------------------------------------------------------------------------
1230 // device context implementation
1232 // more and more of the dc functionality should be implemented by calling
1233 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1234 // also coordinate conversions should be moved to native matrix ops
1235 //-----------------------------------------------------------------------------
1237 // we always stock two context states, one at entry, to be able to preserve the
1238 // state we were called with, the other one after changing to HI Graphics orientation
1239 // (this one is used for getting back clippings etc)
1241 //-----------------------------------------------------------------------------
1242 // wxMacCoreGraphicsContext implementation
1243 //-----------------------------------------------------------------------------
1245 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1247 class wxQuartzOffsetHelper
1250 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1255 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1257 ~wxQuartzOffsetHelper( )
1260 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1267 void wxMacCoreGraphicsContext::Init()
1270 m_releaseContext
= false;
1275 HIRect r
= CGRectMake(0,0,0,0);
1276 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1279 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1282 SetNativeContext(cgcontext
);
1287 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1290 m_windowRef
= window
;
1293 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1296 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1297 int originX
, originY
;
1298 originX
= originY
= 0;
1299 window
->MacWindowToRootWindow( &originX
, &originY
);
1301 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1303 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1304 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1305 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1308 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1313 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1316 wxLogDebug(wxT("Illegal Constructor called"));
1319 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1321 SetNativeContext(NULL
);
1324 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1331 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1334 if ( width
!= 0 && height
!= 0)
1335 r
= CGRectMake( 0 , 0 , width
, height
);
1337 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1339 CGContextBeginPage(m_cgContext
, &r
);
1340 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1341 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1344 void wxMacCoreGraphicsContext::EndPage()
1346 CGContextEndPage(m_cgContext
);
1349 void wxMacCoreGraphicsContext::Flush()
1351 CGContextFlush(m_cgContext
);
1354 void wxMacCoreGraphicsContext::EnsureIsValid()
1360 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1364 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1366 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1367 CGContextSaveGState( m_cgContext
);
1368 m_releaseContext
= true;
1369 if ( !HIShapeIsEmpty(m_clipRgn
) )
1371 // the clip region is in device coordinates, so we convert this again to user coordinates
1372 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1373 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1374 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1375 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1376 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1377 CGContextClip( m_cgContext
);
1379 CGContextSaveGState( m_cgContext
);
1383 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1385 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1387 if (m_logicalFunction
== function
)
1392 bool retval
= false;
1394 if ( function
== wxCOPY
)
1397 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1399 else if ( function
== wxINVERT
|| function
== wxXOR
)
1401 // change color to white
1402 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1403 CGContextSetShouldAntialias( m_cgContext
, false );
1408 m_logicalFunction
= function
;
1412 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1416 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1417 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1418 CGContextClip( m_cgContext
);
1423 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1424 // to regions we try at least to have correct translations
1425 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1426 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1427 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1429 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1430 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1431 m_clipRgn
.Set(mutableShape
);
1435 // clips drawings to the rect
1436 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1438 HIRect r
= CGRectMake( x
, y
, w
, h
);
1441 CGContextClipToRect( m_cgContext
, r
);
1445 // the clipping itself must be stored as device coordinates, otherwise
1446 // we cannot apply it back correctly
1447 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1448 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1452 // resets the clipping to original extent
1453 void wxMacCoreGraphicsContext::ResetClip()
1457 // there is no way for clearing the clip, we can only revert to the stored
1458 // state, but then we have to make sure everything else is NOT restored
1459 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1460 CGContextRestoreGState( m_cgContext
);
1461 CGContextSaveGState( m_cgContext
);
1462 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1463 transformNew
= CGAffineTransformInvert( transformNew
) ;
1464 CGContextConcatCTM( m_cgContext
, transformNew
);
1465 CGContextConcatCTM( m_cgContext
, transform
);
1469 HIRect r
= CGRectMake(0,0,0,0);
1470 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1474 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1476 if ( m_pen
.IsNull() )
1481 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1483 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1484 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1485 CGContextStrokePath( m_cgContext
);
1488 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1490 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1492 // when using shading, we cannot draw pen and brush at the same time
1493 // revert to the base implementation of first filling and then stroking
1494 wxGraphicsContext::DrawPath( path
, fillStyle
);
1498 CGPathDrawingMode mode
= kCGPathFill
;
1499 if ( m_brush
.IsNull() )
1501 if ( m_pen
.IsNull() )
1504 mode
= kCGPathStroke
;
1508 if ( m_pen
.IsNull() )
1510 if ( fillStyle
== wxODDEVEN_RULE
)
1511 mode
= kCGPathEOFill
;
1517 if ( fillStyle
== wxODDEVEN_RULE
)
1518 mode
= kCGPathEOFillStroke
;
1520 mode
= kCGPathFillStroke
;
1526 if ( !m_brush
.IsNull() )
1527 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1528 if ( !m_pen
.IsNull() )
1529 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1531 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1533 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1534 CGContextDrawPath( m_cgContext
, mode
);
1537 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1539 if ( m_brush
.IsNull() )
1544 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1546 CGContextSaveGState( m_cgContext
);
1547 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1548 CGContextClip( m_cgContext
);
1549 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1550 CGContextRestoreGState( m_cgContext
);
1554 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1555 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1556 if ( fillStyle
== wxODDEVEN_RULE
)
1557 CGContextEOFillPath( m_cgContext
);
1559 CGContextFillPath( m_cgContext
);
1563 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1565 // we allow either setting or clearing but not replacing
1566 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1570 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1571 CGContextRestoreGState( m_cgContext
);
1572 CGContextRestoreGState( m_cgContext
);
1573 if ( m_releaseContext
)
1576 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1580 CGContextRelease(m_cgContext
);
1586 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1587 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1588 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1589 // for this one operation.
1591 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1595 CGContextRetain(m_cgContext
);
1596 CGContextSaveGState( m_cgContext
);
1597 CGContextSaveGState( m_cgContext
);
1598 m_releaseContext
= false;
1602 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1605 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1607 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1610 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1613 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1615 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1618 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1621 CGContextRotateCTM( m_cgContext
, angle
);
1623 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1626 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1630 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() );
1631 HIRect r
= CGRectMake( x
, y
, w
, h
);
1632 if ( bmp
.GetDepth() == 1 )
1634 // is is a mask, the '1' in the mask tell where to draw the current brush
1635 if ( !m_brush
.IsNull() )
1637 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1639 // TODO clip to mask
1641 CGContextSaveGState( m_cgContext );
1642 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1643 CGContextClip( m_cgContext );
1644 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1645 CGContextRestoreGState( m_cgContext);
1650 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1651 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1657 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1659 CGImageRelease( image
);
1662 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1666 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1667 CGContextSaveGState( m_cgContext
);
1668 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1669 CGContextScaleCTM( m_cgContext
, 1, -1 );
1670 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1671 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1672 CGContextRestoreGState( m_cgContext
);
1675 void wxMacCoreGraphicsContext::PushState()
1679 CGContextSaveGState( m_cgContext
);
1682 void wxMacCoreGraphicsContext::PopState()
1686 CGContextRestoreGState( m_cgContext
);
1689 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1691 DrawText(str
, x
, y
, 0.0);
1694 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1696 if ( m_font
.IsNull() )
1701 OSStatus status
= noErr
;
1702 ATSUTextLayout atsuLayout
;
1703 UniCharCount chars
= str
.length();
1704 UniChar
* ubuf
= NULL
;
1706 #if SIZEOF_WCHAR_T == 4
1707 wxMBConvUTF16 converter
;
1709 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1710 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1711 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1713 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1714 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1715 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1716 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1718 chars
= unicharlen
/ 2;
1721 ubuf
= (UniChar
*) str
.wc_str();
1723 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1724 chars
= wxWcslen( wchar
.data() );
1725 ubuf
= (UniChar
*) wchar
.data();
1729 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1730 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1731 &chars
, &style
, &atsuLayout
);
1733 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1735 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1736 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1738 int iAngle
= int( angle
* RAD2DEG
);
1739 if ( abs(iAngle
) > 0 )
1741 Fixed atsuAngle
= IntToFixed( iAngle
);
1742 ATSUAttributeTag atsuTags
[] =
1744 kATSULineRotationTag
,
1746 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1750 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1754 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1755 atsuTags
, atsuSizes
, atsuValues
);
1759 ATSUAttributeTag atsuTags
[] =
1763 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1765 sizeof( CGContextRef
) ,
1767 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1771 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1772 atsuTags
, atsuSizes
, atsuValues
);
1775 ATSUTextMeasurement textBefore
, textAfter
;
1776 ATSUTextMeasurement ascent
, descent
;
1778 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1779 &textBefore
, &textAfter
, &ascent
, &descent
);
1781 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1784 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1785 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1787 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1788 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1789 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1791 CGContextSaveGState(m_cgContext
);
1792 CGContextTranslateCTM(m_cgContext
, x
, y
);
1793 CGContextScaleCTM(m_cgContext
, 1, -1);
1794 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1795 IntToFixed(0) , IntToFixed(0) );
1797 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1799 CGContextRestoreGState(m_cgContext
);
1801 ::ATSUDisposeTextLayout(atsuLayout
);
1803 #if SIZEOF_WCHAR_T == 4
1808 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1809 wxDouble
*descent
, wxDouble
*externalLeading
) const
1811 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1819 if ( externalLeading
)
1820 *externalLeading
= 0;
1825 OSStatus status
= noErr
;
1827 ATSUTextLayout atsuLayout
;
1828 UniCharCount chars
= str
.length();
1829 UniChar
* ubuf
= NULL
;
1831 #if SIZEOF_WCHAR_T == 4
1832 wxMBConvUTF16 converter
;
1834 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1835 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1836 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1838 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1839 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1840 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1841 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1843 chars
= unicharlen
/ 2;
1846 ubuf
= (UniChar
*) str
.wc_str();
1848 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1849 chars
= wxWcslen( wchar
.data() );
1850 ubuf
= (UniChar
*) wchar
.data();
1854 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1855 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1856 &chars
, &style
, &atsuLayout
);
1858 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1860 ATSUTextMeasurement textBefore
, textAfter
;
1861 ATSUTextMeasurement textAscent
, textDescent
;
1863 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1864 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1867 *height
= FixedToInt(textAscent
+ textDescent
);
1869 *descent
= FixedToInt(textDescent
);
1870 if ( externalLeading
)
1871 *externalLeading
= 0;
1873 *width
= FixedToInt(textAfter
- textBefore
);
1875 ::ATSUDisposeTextLayout(atsuLayout
);
1876 #if SIZEOF_WCHAR_T == 4
1881 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1884 widths
.Add(0, text
.length());
1889 ATSUTextLayout atsuLayout
;
1890 UniCharCount chars
= text
.length();
1891 UniChar
* ubuf
= NULL
;
1893 #if SIZEOF_WCHAR_T == 4
1894 wxMBConvUTF16 converter
;
1896 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1897 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1898 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1900 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1901 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1902 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1903 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1905 chars
= unicharlen
/ 2;
1908 ubuf
= (UniChar
*) text
.wc_str();
1910 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1911 chars
= wxWcslen( wchar
.data() );
1912 ubuf
= (UniChar
*) wchar
.data();
1916 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1917 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1918 &chars
, &style
, &atsuLayout
);
1920 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1922 unsigned long actualNumberOfBounds
= 0;
1923 ATSTrapezoid glyphBounds
;
1925 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1927 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1928 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1929 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1932 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1933 //unsigned char uch = s[i];
1936 ::ATSUDisposeTextLayout(atsuLayout
);
1937 #if SIZEOF_WCHAR_T == 4
1942 void * wxMacCoreGraphicsContext::GetNativeContext()
1947 // concatenates this transform with the current transform of this context
1948 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1951 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1953 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1956 // sets the transform of this context
1957 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1961 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1962 transform
= CGAffineTransformInvert( transform
) ;
1963 CGContextConcatCTM( m_cgContext
, transform
);
1964 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1968 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
1972 // gets the matrix of this context
1973 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
1975 wxGraphicsMatrix m
= CreateMatrix();
1976 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
1977 CGContextGetCTM( m_cgContext
));
1985 //-----------------------------------------------------------------------------
1986 // wxMacCoreGraphicsRenderer declaration
1987 //-----------------------------------------------------------------------------
1989 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
1992 wxMacCoreGraphicsRenderer() {}
1994 virtual ~wxMacCoreGraphicsRenderer() {}
1998 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2000 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2002 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2004 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2006 virtual wxGraphicsContext
* CreateMeasuringContext();
2010 virtual wxGraphicsPath
CreatePath();
2014 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2015 wxDouble tx
=0.0, wxDouble ty
=0.0);
2018 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2020 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2022 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2023 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2024 const wxColour
&c1
, const wxColour
&c2
) ;
2026 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2027 // with radius r and color cColor
2028 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2029 const wxColour
&oColor
, const wxColour
&cColor
) ;
2032 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2035 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2038 //-----------------------------------------------------------------------------
2039 // wxMacCoreGraphicsRenderer implementation
2040 //-----------------------------------------------------------------------------
2042 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2044 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2046 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2048 return &gs_MacCoreGraphicsRenderer
;
2051 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2053 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2056 return new wxMacCoreGraphicsContext(this,
2057 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2061 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2065 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2067 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2071 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2073 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2076 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2078 return new wxMacCoreGraphicsContext(this, window
);
2081 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2083 return new wxMacCoreGraphicsContext(this);
2088 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2091 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2098 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2099 wxDouble tx
, wxDouble ty
)
2102 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2103 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2108 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2110 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2111 return wxNullGraphicsPen
;
2115 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2120 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2122 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2123 return wxNullGraphicsBrush
;
2127 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2132 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2133 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2134 const wxColour
&c1
, const wxColour
&c2
)
2137 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2138 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2143 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2144 // with radius r and color cColor
2145 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2146 const wxColour
&oColor
, const wxColour
&cColor
)
2149 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2150 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2156 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2161 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2165 return wxNullGraphicsFont
;