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"
24 #include "wx/mac/uma.h"
29 // in case our functions were defined outside std, we make it known all the same
35 #include "wx/mac/private.h"
37 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
38 typedef float CGFloat
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
47 const double M_PI
= 3.14159265358979;
51 static const double RAD2DEG
= 180.0 / M_PI
;
54 // Pen, Brushes and Fonts
58 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
60 // CGPattern wrapper class: always allocate on heap, never call destructor
62 class wxMacCoreGraphicsPattern
65 wxMacCoreGraphicsPattern() {}
67 // is guaranteed to be called only with a non-Null CGContextRef
68 virtual void Render( CGContextRef ctxRef
) = 0;
70 operator CGPatternRef() const { return m_patternRef
; }
73 virtual ~wxMacCoreGraphicsPattern()
75 // as this is called only when the m_patternRef is been released;
76 // don't release it again
79 static void _Render( void *info
, CGContextRef ctxRef
)
81 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
83 self
->Render( ctxRef
);
86 static void _Dispose( void *info
)
88 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
92 CGPatternRef m_patternRef
;
94 static const CGPatternCallbacks ms_Callbacks
;
97 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
99 class ImagePattern
: public wxMacCoreGraphicsPattern
102 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
104 wxASSERT( bmp
&& bmp
->Ok() );
106 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
);
109 // ImagePattern takes ownership of CGImageRef passed in
110 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
115 Init( image
, transform
);
118 virtual void Render( CGContextRef ctxRef
)
121 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
125 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
130 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
131 m_patternRef
= CGPatternCreate(
132 this , m_imageBounds
, transform
,
133 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
134 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
138 virtual ~ImagePattern()
141 CGImageRelease( m_image
);
145 CGRect m_imageBounds
;
148 class HatchPattern
: public wxMacCoreGraphicsPattern
151 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
153 m_hatch
= hatchstyle
;
154 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
155 m_patternRef
= CGPatternCreate(
156 this , m_imageBounds
, transform
,
157 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
158 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
161 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
163 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
166 virtual void Render( CGContextRef ctxRef
)
170 case wxBDIAGONAL_HATCH
:
174 { 8.0 , 0.0 } , { 0.0 , 8.0 }
176 StrokeLineSegments( ctxRef
, pts
, 2 );
180 case wxCROSSDIAG_HATCH
:
184 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
185 { 8.0 , 0.0 } , { 0.0 , 8.0 }
187 StrokeLineSegments( ctxRef
, pts
, 4 );
191 case wxFDIAGONAL_HATCH
:
195 { 0.0 , 0.0 } , { 8.0 , 8.0 }
197 StrokeLineSegments( ctxRef
, pts
, 2 );
205 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
206 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
208 StrokeLineSegments( ctxRef
, pts
, 4 );
212 case wxHORIZONTAL_HATCH
:
216 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
218 StrokeLineSegments( ctxRef
, pts
, 2 );
222 case wxVERTICAL_HATCH
:
226 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
228 StrokeLineSegments( ctxRef
, pts
, 2 );
238 virtual ~HatchPattern() {}
240 CGRect m_imageBounds
;
244 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
247 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
248 ~wxMacCoreGraphicsPenData();
251 virtual void Apply( wxGraphicsContext
* context
);
252 virtual wxDouble
GetWidth() { return m_width
; }
256 wxMacCFRefHolder
<CGColorRef
> m_color
;
257 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
263 const CGFloat
*m_lengths
;
264 CGFloat
*m_userLengths
;
268 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
269 CGFloat
* m_patternColorComponents
;
272 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
273 wxGraphicsObjectRefData( renderer
)
277 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
278 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
279 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
281 // TODO: * m_dc->m_scaleX
282 m_width
= pen
.GetWidth();
286 switch ( pen
.GetCap() )
289 m_cap
= kCGLineCapRound
;
292 case wxCAP_PROJECTING
:
293 m_cap
= kCGLineCapSquare
;
297 m_cap
= kCGLineCapButt
;
301 m_cap
= kCGLineCapButt
;
305 switch ( pen
.GetJoin() )
308 m_join
= kCGLineJoinBevel
;
312 m_join
= kCGLineJoinMiter
;
316 m_join
= kCGLineJoinRound
;
320 m_join
= kCGLineJoinMiter
;
324 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
326 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
327 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
328 static const CGFloat dashed
[] = { 19.0 , 9.0 };
329 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
331 switch ( pen
.GetStyle() )
337 m_count
= WXSIZEOF(dotted
);
338 m_userLengths
= new CGFloat
[ m_count
] ;
339 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
340 m_lengths
= m_userLengths
;
344 m_count
= WXSIZEOF(dashed
);
349 m_count
= WXSIZEOF(short_dashed
);
350 m_lengths
= short_dashed
;
354 m_count
= WXSIZEOF(dotted_dashed
);
355 m_lengths
= dotted_dashed
;
360 m_count
= pen
.GetDashes( &dashes
);
361 if ((dashes
!= NULL
) && (m_count
> 0))
363 m_userLengths
= new CGFloat
[m_count
];
364 for ( int i
= 0; i
< m_count
; ++i
)
366 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
368 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
369 m_userLengths
[i
] = dashUnit
+ 2.0;
370 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
371 m_userLengths
[i
] = dashUnit
;
374 m_lengths
= m_userLengths
;
379 wxBitmap
* bmp
= pen
.GetStipple();
380 if ( bmp
&& bmp
->Ok() )
382 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
383 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
384 m_patternColorComponents
= new CGFloat
[1] ;
385 m_patternColorComponents
[0] = 1.0;
394 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
395 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
396 m_patternColorComponents
= new CGFloat
[4] ;
397 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
398 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
399 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
400 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
404 if ((m_lengths
!= NULL
) && (m_count
> 0))
406 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
407 m_cap
= kCGLineCapButt
;
411 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
413 delete[] m_userLengths
;
414 delete[] m_patternColorComponents
;
417 void wxMacCoreGraphicsPenData::Init()
420 m_userLengths
= NULL
;
423 m_patternColorComponents
= NULL
;
427 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
429 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
430 CGContextSetLineWidth( cg
, m_width
);
431 CGContextSetLineJoin( cg
, m_join
);
433 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
434 CGContextSetLineCap( cg
, m_cap
);
438 CGAffineTransform matrix
= CGContextGetCTM( cg
);
439 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
440 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
441 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
445 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
447 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
450 CGContextSetStrokeColorWithColor( cg
, m_color
);
458 static const char *gs_stripedback_xpm
[] = {
459 /* columns rows colors chars-per-pixel */
470 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
472 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
474 delete[] m_patternColorComponents
;
477 void wxMacCoreGraphicsColour::Init()
480 m_patternColorComponents
= NULL
;
483 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
487 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
488 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
489 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
490 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
494 CGContextSetFillColorWithColor( cgContext
, m_color
);
498 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
503 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
506 if ( brush
.GetStyle() == wxSOLID
)
508 if ( brush
.MacGetBrushKind() == kwxMacBrushTheme
)
511 HIThemeBrushCreateCGColor( brush
.MacGetTheme(), &color
);
512 m_color
.Set( color
) ;
516 CGFloat components
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
517 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
518 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
521 else if ( brush
.IsHatch() )
524 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
525 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
527 m_patternColorComponents
= new CGFloat
[4] ;
528 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
529 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
530 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
531 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
535 // now brush is a bitmap
536 wxBitmap
* bmp
= brush
.GetStipple();
537 if ( bmp
&& bmp
->Ok() )
540 m_patternColorComponents
= new CGFloat
[1] ;
541 m_patternColorComponents
[0] = 1.0;
542 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
543 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
548 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
551 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
552 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
553 ~wxMacCoreGraphicsBrushData ();
555 virtual void Apply( wxGraphicsContext
* context
);
556 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
557 const wxColour
&c1
, const wxColour
&c2
);
558 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
559 const wxColour
&oColor
, const wxColour
&cColor
);
561 virtual bool IsShading() { return m_isShading
; }
562 CGShadingRef
GetShading() { return m_shading
; }
564 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
565 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
568 wxMacCoreGraphicsColour m_cgColor
;
571 CGFunctionRef m_gradientFunction
;
572 CGShadingRef m_shading
;
573 CGFloat
*m_gradientComponents
;
576 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
581 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
582 const wxColour
&c1
, const wxColour
&c2
)
584 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
585 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
589 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
590 const wxColour
&oColor
, const wxColour
&cColor
)
592 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
593 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
597 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
604 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
607 CGShadingRelease(m_shading
);
609 if( m_gradientFunction
)
610 CGFunctionRelease(m_gradientFunction
);
612 delete[] m_gradientComponents
;
615 void wxMacCoreGraphicsBrushData::Init()
617 m_gradientFunction
= NULL
;
619 m_gradientComponents
= NULL
;
623 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
625 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
629 // nothing to set as shades are processed by clipping using the path and filling
633 m_cgColor
.Apply( cg
);
637 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
639 CGFloat
* colors
= (CGFloat
*) info
;
641 for( int i
= 0 ; i
< 4 ; ++i
)
643 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
647 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
649 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
650 static const CGFloat input_value_range
[2] = { 0, 1 };
651 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
652 m_gradientComponents
= new CGFloat
[8] ;
653 m_gradientComponents
[0] = c1
.Red() / 255.0;
654 m_gradientComponents
[1] = c1
.Green() / 255.0;
655 m_gradientComponents
[2] = c1
.Blue() / 255.0;
656 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
657 m_gradientComponents
[4] = c2
.Red() / 255.0;
658 m_gradientComponents
[5] = c2
.Green() / 255.0;
659 m_gradientComponents
[6] = c2
.Blue() / 255.0;
660 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
662 return CGFunctionCreate ( m_gradientComponents
, 1,
673 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
676 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
677 ~wxMacCoreGraphicsFontData();
679 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
681 ATSUStyle m_macATSUIStyle
;
684 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
686 m_macATSUIStyle
= NULL
;
690 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
692 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
694 // we need the scale here ...
696 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
697 RGBColor atsuColor
= MAC_WXCOLORREF( col
.GetPixel() );
698 ATSUAttributeTag atsuTags
[] =
703 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
708 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
714 status
= ::ATSUSetAttributes(
715 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
716 atsuTags
, atsuSizes
, atsuValues
);
718 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
721 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
723 if ( m_macATSUIStyle
)
725 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
726 m_macATSUIStyle
= NULL
;
734 //-----------------------------------------------------------------------------
735 // wxMacCoreGraphicsMatrix declaration
736 //-----------------------------------------------------------------------------
738 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
741 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
743 virtual ~wxMacCoreGraphicsMatrixData() ;
745 virtual wxGraphicsObjectRefData
*Clone() const ;
747 // concatenates the matrix
748 virtual void Concat( const wxGraphicsMatrixData
*t
);
750 // sets the matrix to the respective values
751 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
752 wxDouble tx
=0.0, wxDouble ty
=0.0);
754 // gets the component valuess of the matrix
755 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
756 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
758 // makes this the inverse matrix
759 virtual void Invert();
761 // returns true if the elements of the transformation matrix are equal ?
762 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
764 // return true if this is the identity matrix
765 virtual bool IsIdentity() const;
771 // add the translation to this matrix
772 virtual void Translate( wxDouble dx
, wxDouble dy
);
774 // add the scale to this matrix
775 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
777 // add the rotation to this matrix (radians)
778 virtual void Rotate( wxDouble angle
);
781 // apply the transforms
784 // applies that matrix to the point
785 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
787 // applies the matrix except for translations
788 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
790 // returns the native representation
791 virtual void * GetNativeMatrix() const;
794 CGAffineTransform m_matrix
;
797 //-----------------------------------------------------------------------------
798 // wxMacCoreGraphicsMatrix implementation
799 //-----------------------------------------------------------------------------
801 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
805 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
809 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
811 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
812 m
->m_matrix
= m_matrix
;
816 // concatenates the matrix
817 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
819 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
822 // sets the matrix to the respective values
823 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
824 wxDouble tx
, wxDouble ty
)
826 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
829 // gets the component valuess of the matrix
830 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
831 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
833 if (a
) *a
= m_matrix
.a
;
834 if (b
) *b
= m_matrix
.b
;
835 if (c
) *c
= m_matrix
.c
;
836 if (d
) *d
= m_matrix
.d
;
837 if (tx
) *tx
= m_matrix
.tx
;
838 if (ty
) *ty
= m_matrix
.ty
;
841 // makes this the inverse matrix
842 void wxMacCoreGraphicsMatrixData::Invert()
844 m_matrix
= CGAffineTransformInvert( m_matrix
);
847 // returns true if the elements of the transformation matrix are equal ?
848 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
850 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
853 // return true if this is the identity matrix
854 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
856 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
857 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
864 // add the translation to this matrix
865 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
867 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
870 // add the scale to this matrix
871 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
873 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
876 // add the rotation to this matrix (radians)
877 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
879 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
883 // apply the transforms
886 // applies that matrix to the point
887 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
889 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
895 // applies the matrix except for translations
896 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
898 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
903 // returns the native representation
904 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
906 return (void*) &m_matrix
;
913 //-----------------------------------------------------------------------------
914 // wxMacCoreGraphicsPath declaration
915 //-----------------------------------------------------------------------------
917 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
920 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
922 ~wxMacCoreGraphicsPathData();
924 virtual wxGraphicsObjectRefData
*Clone() const;
926 // begins a new subpath at (x,y)
927 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
929 // adds a straight line from the current point to (x,y)
930 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
932 // adds a cubic Bezier curve from the current point, using two control points and an end point
933 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
935 // closes the current sub-path
936 virtual void CloseSubpath();
938 // gets the last point of the current path, (0,0) if not yet set
939 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
941 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
942 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
945 // These are convenience functions which - if not available natively will be assembled
946 // using the primitives from above
949 // adds a quadratic Bezier curve from the current point, using a control point and an end point
950 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
952 // appends a rectangle as a new closed subpath
953 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
955 // appends an ellipsis as a new closed subpath fitting the passed rectangle
956 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
958 // 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)
959 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
962 virtual void AddPath( const wxGraphicsPathData
* path
);
964 // returns the native path
965 virtual void * GetNativePath() const { return m_path
; }
967 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
968 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
970 // transforms each point of this path by the matrix
971 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
973 // gets the bounding box enclosing all points (possibly including control points)
974 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
976 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
978 CGMutablePathRef m_path
;
981 //-----------------------------------------------------------------------------
982 // wxMacCoreGraphicsPath implementation
983 //-----------------------------------------------------------------------------
985 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
990 m_path
= CGPathCreateMutable();
993 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
995 CGPathRelease( m_path
);
998 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1000 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1005 // opens (starts) a new subpath
1006 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1008 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1011 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1013 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1016 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1018 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1021 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1023 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1026 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1028 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1029 CGPathAddRect( m_path
, NULL
, cgRect
);
1032 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1034 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1037 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1038 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1040 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1041 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1044 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1046 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1049 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1051 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1054 // closes the current subpath
1055 void wxMacCoreGraphicsPathData::CloseSubpath()
1057 CGPathCloseSubpath( m_path
);
1060 // gets the last point of the current path, (0,0) if not yet set
1061 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1063 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1068 // transforms each point of this path by the matrix
1069 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1071 CGMutablePathRef p
= CGPathCreateMutable() ;
1072 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1073 CGPathRelease( m_path
);
1077 // gets the bounding box enclosing all points (possibly including control points)
1078 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1080 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1081 *x
= bounds
.origin
.x
;
1082 *y
= bounds
.origin
.y
;
1083 *w
= bounds
.size
.width
;
1084 *h
= bounds
.size
.height
;
1087 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1089 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1096 //-----------------------------------------------------------------------------
1097 // wxMacCoreGraphicsContext declaration
1098 //-----------------------------------------------------------------------------
1100 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1103 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1105 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1107 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1109 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1111 wxMacCoreGraphicsContext();
1113 ~wxMacCoreGraphicsContext();
1117 // returns the size of the graphics context in device coordinates
1118 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1120 virtual void StartPage( wxDouble width
, wxDouble height
);
1122 virtual void EndPage();
1124 virtual void Flush();
1126 // push the current state of the context, ie the transformation matrix on a stack
1127 virtual void PushState();
1129 // pops a stored state from the stack
1130 virtual void PopState();
1132 // clips drawings to the region
1133 virtual void Clip( const wxRegion
®ion
);
1135 // clips drawings to the rect
1136 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1138 // resets the clipping to original extent
1139 virtual void ResetClip();
1141 virtual void * GetNativeContext();
1143 bool SetLogicalFunction( int function
);
1149 virtual void Translate( wxDouble dx
, wxDouble dy
);
1152 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1155 virtual void Rotate( wxDouble angle
);
1157 // concatenates this transform with the current transform of this context
1158 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1160 // sets the transform of this context
1161 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1163 // gets the matrix of this context
1164 virtual wxGraphicsMatrix
GetTransform() const;
1166 // setting the paint
1169 // strokes along a path with the current pen
1170 virtual void StrokePath( const wxGraphicsPath
&path
);
1172 // fills a path with the current brush
1173 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1175 // draws a path by first filling and then stroking
1176 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1178 virtual bool ShouldOffset() const
1181 if ( !m_pen
.IsNull() )
1183 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1184 if ( penwidth
== 0 )
1187 return ( penwidth
% 2 ) == 1;
1193 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1195 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1197 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1198 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1200 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1206 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1208 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1210 void SetNativeContext( CGContextRef cg
);
1212 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1213 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1216 void EnsureIsValid();
1218 CGContextRef m_cgContext
;
1219 WindowRef m_windowRef
;
1220 bool m_releaseContext
;
1221 CGAffineTransform m_windowTransform
;
1225 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1228 //-----------------------------------------------------------------------------
1229 // device context implementation
1231 // more and more of the dc functionality should be implemented by calling
1232 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1233 // also coordinate conversions should be moved to native matrix ops
1234 //-----------------------------------------------------------------------------
1236 // we always stock two context states, one at entry, to be able to preserve the
1237 // state we were called with, the other one after changing to HI Graphics orientation
1238 // (this one is used for getting back clippings etc)
1240 //-----------------------------------------------------------------------------
1241 // wxMacCoreGraphicsContext implementation
1242 //-----------------------------------------------------------------------------
1244 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1246 class wxQuartzOffsetHelper
1249 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1254 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1256 ~wxQuartzOffsetHelper( )
1259 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1266 void wxMacCoreGraphicsContext::Init()
1269 m_releaseContext
= false;
1274 HIRect r
= CGRectMake(0,0,0,0);
1275 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1278 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1281 SetNativeContext(cgcontext
);
1286 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1289 m_windowRef
= window
;
1292 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1295 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1296 int originX
, originY
;
1297 originX
= originY
= 0;
1298 window
->MacWindowToRootWindow( &originX
, &originY
);
1300 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1302 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1303 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1304 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1307 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1312 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1315 wxLogDebug(wxT("Illegal Constructor called"));
1318 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1320 SetNativeContext(NULL
);
1323 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1330 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1333 if ( width
!= 0 && height
!= 0)
1334 r
= CGRectMake( 0 , 0 , width
, height
);
1336 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1338 CGContextBeginPage(m_cgContext
, &r
);
1339 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1340 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1343 void wxMacCoreGraphicsContext::EndPage()
1345 CGContextEndPage(m_cgContext
);
1348 void wxMacCoreGraphicsContext::Flush()
1350 CGContextFlush(m_cgContext
);
1353 void wxMacCoreGraphicsContext::EnsureIsValid()
1359 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1363 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1365 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1366 CGContextSaveGState( m_cgContext
);
1367 m_releaseContext
= true;
1368 if ( !HIShapeIsEmpty(m_clipRgn
) )
1370 // the clip region is in device coordinates, so we convert this again to user coordinates
1371 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1372 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1373 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1374 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1375 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1376 CGContextClip( m_cgContext
);
1378 CGContextSaveGState( m_cgContext
);
1382 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1384 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1386 if (m_logicalFunction
== function
)
1391 bool retval
= false;
1393 if ( function
== wxCOPY
)
1396 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1398 else if ( function
== wxINVERT
|| function
== wxXOR
)
1400 // change color to white
1401 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1402 CGContextSetShouldAntialias( m_cgContext
, false );
1407 m_logicalFunction
= function
;
1411 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1415 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1416 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1417 CGContextClip( m_cgContext
);
1422 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1423 // to regions we try at least to have correct translations
1424 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1425 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1426 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1428 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1429 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1430 m_clipRgn
.Set(mutableShape
);
1434 // clips drawings to the rect
1435 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1437 HIRect r
= CGRectMake( x
, y
, w
, h
);
1440 CGContextClipToRect( m_cgContext
, r
);
1444 // the clipping itself must be stored as device coordinates, otherwise
1445 // we cannot apply it back correctly
1446 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1447 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1451 // resets the clipping to original extent
1452 void wxMacCoreGraphicsContext::ResetClip()
1456 // there is no way for clearing the clip, we can only revert to the stored
1457 // state, but then we have to make sure everything else is NOT restored
1458 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1459 CGContextRestoreGState( m_cgContext
);
1460 CGContextSaveGState( m_cgContext
);
1461 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1462 transformNew
= CGAffineTransformInvert( transformNew
) ;
1463 CGContextConcatCTM( m_cgContext
, transformNew
);
1464 CGContextConcatCTM( m_cgContext
, transform
);
1468 HIRect r
= CGRectMake(0,0,0,0);
1469 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1473 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1475 if ( m_pen
.IsNull() )
1480 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1482 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1483 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1484 CGContextStrokePath( m_cgContext
);
1487 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1489 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1491 // when using shading, we cannot draw pen and brush at the same time
1492 // revert to the base implementation of first filling and then stroking
1493 wxGraphicsContext::DrawPath( path
, fillStyle
);
1497 CGPathDrawingMode mode
= kCGPathFill
;
1498 if ( m_brush
.IsNull() )
1500 if ( m_pen
.IsNull() )
1503 mode
= kCGPathStroke
;
1507 if ( m_pen
.IsNull() )
1509 if ( fillStyle
== wxODDEVEN_RULE
)
1510 mode
= kCGPathEOFill
;
1516 if ( fillStyle
== wxODDEVEN_RULE
)
1517 mode
= kCGPathEOFillStroke
;
1519 mode
= kCGPathFillStroke
;
1525 if ( !m_brush
.IsNull() )
1526 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1527 if ( !m_pen
.IsNull() )
1528 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1530 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1532 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1533 CGContextDrawPath( m_cgContext
, mode
);
1536 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1538 if ( m_brush
.IsNull() )
1543 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1545 CGContextSaveGState( m_cgContext
);
1546 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1547 CGContextClip( m_cgContext
);
1548 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1549 CGContextRestoreGState( m_cgContext
);
1553 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1554 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1555 if ( fillStyle
== wxODDEVEN_RULE
)
1556 CGContextEOFillPath( m_cgContext
);
1558 CGContextFillPath( m_cgContext
);
1562 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1564 // we allow either setting or clearing but not replacing
1565 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1569 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1570 CGContextRestoreGState( m_cgContext
);
1571 CGContextRestoreGState( m_cgContext
);
1572 if ( m_releaseContext
)
1575 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1579 CGContextRelease(m_cgContext
);
1585 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1586 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1587 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1588 // for this one operation.
1590 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1594 CGContextRetain(m_cgContext
);
1595 CGContextSaveGState( m_cgContext
);
1596 CGContextSaveGState( m_cgContext
);
1597 m_releaseContext
= false;
1601 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1604 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1606 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1609 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1612 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1614 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1617 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1620 CGContextRotateCTM( m_cgContext
, angle
);
1622 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1625 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1629 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() );
1630 HIRect r
= CGRectMake( x
, y
, w
, h
);
1631 if ( bmp
.GetDepth() == 1 )
1633 // is is a mask, the '1' in the mask tell where to draw the current brush
1634 if ( !m_brush
.IsNull() )
1636 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1638 // TODO clip to mask
1640 CGContextSaveGState( m_cgContext );
1641 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1642 CGContextClip( m_cgContext );
1643 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1644 CGContextRestoreGState( m_cgContext);
1649 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1650 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1656 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1658 CGImageRelease( image
);
1661 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1665 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1666 CGContextSaveGState( m_cgContext
);
1667 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1668 CGContextScaleCTM( m_cgContext
, 1, -1 );
1669 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1670 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1671 CGContextRestoreGState( m_cgContext
);
1674 void wxMacCoreGraphicsContext::PushState()
1678 CGContextSaveGState( m_cgContext
);
1681 void wxMacCoreGraphicsContext::PopState()
1685 CGContextRestoreGState( m_cgContext
);
1688 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1690 DrawText(str
, x
, y
, 0.0);
1693 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1695 if ( m_font
.IsNull() )
1700 OSStatus status
= noErr
;
1701 ATSUTextLayout atsuLayout
;
1702 UniCharCount chars
= str
.length();
1703 UniChar
* ubuf
= NULL
;
1705 #if SIZEOF_WCHAR_T == 4
1706 wxMBConvUTF16 converter
;
1708 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1709 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1710 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1712 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1713 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1714 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1715 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1717 chars
= unicharlen
/ 2;
1720 ubuf
= (UniChar
*) str
.wc_str();
1722 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1723 chars
= wxWcslen( wchar
.data() );
1724 ubuf
= (UniChar
*) wchar
.data();
1728 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1729 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1730 &chars
, &style
, &atsuLayout
);
1732 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1734 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1735 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1737 int iAngle
= int( angle
* RAD2DEG
);
1738 if ( abs(iAngle
) > 0 )
1740 Fixed atsuAngle
= IntToFixed( iAngle
);
1741 ATSUAttributeTag atsuTags
[] =
1743 kATSULineRotationTag
,
1745 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1749 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1753 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1754 atsuTags
, atsuSizes
, atsuValues
);
1758 ATSUAttributeTag atsuTags
[] =
1762 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1764 sizeof( CGContextRef
) ,
1766 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1770 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1771 atsuTags
, atsuSizes
, atsuValues
);
1774 ATSUTextMeasurement textBefore
, textAfter
;
1775 ATSUTextMeasurement ascent
, descent
;
1777 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1778 &textBefore
, &textAfter
, &ascent
, &descent
);
1780 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1783 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1784 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1786 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1787 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1788 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1790 CGContextSaveGState(m_cgContext
);
1791 CGContextTranslateCTM(m_cgContext
, x
, y
);
1792 CGContextScaleCTM(m_cgContext
, 1, -1);
1793 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1794 IntToFixed(0) , IntToFixed(0) );
1796 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1798 CGContextRestoreGState(m_cgContext
);
1800 ::ATSUDisposeTextLayout(atsuLayout
);
1802 #if SIZEOF_WCHAR_T == 4
1807 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1808 wxDouble
*descent
, wxDouble
*externalLeading
) const
1810 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1818 if ( externalLeading
)
1819 *externalLeading
= 0;
1824 OSStatus status
= noErr
;
1826 ATSUTextLayout atsuLayout
;
1827 UniCharCount chars
= str
.length();
1828 UniChar
* ubuf
= NULL
;
1830 #if SIZEOF_WCHAR_T == 4
1831 wxMBConvUTF16 converter
;
1833 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1834 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1835 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1837 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1838 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1839 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1840 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1842 chars
= unicharlen
/ 2;
1845 ubuf
= (UniChar
*) str
.wc_str();
1847 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1848 chars
= wxWcslen( wchar
.data() );
1849 ubuf
= (UniChar
*) wchar
.data();
1853 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1854 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1855 &chars
, &style
, &atsuLayout
);
1857 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1859 ATSUTextMeasurement textBefore
, textAfter
;
1860 ATSUTextMeasurement textAscent
, textDescent
;
1862 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1863 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1866 *height
= FixedToInt(textAscent
+ textDescent
);
1868 *descent
= FixedToInt(textDescent
);
1869 if ( externalLeading
)
1870 *externalLeading
= 0;
1872 *width
= FixedToInt(textAfter
- textBefore
);
1874 ::ATSUDisposeTextLayout(atsuLayout
);
1875 #if SIZEOF_WCHAR_T == 4
1880 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1883 widths
.Add(0, text
.length());
1888 ATSUTextLayout atsuLayout
;
1889 UniCharCount chars
= text
.length();
1890 UniChar
* ubuf
= NULL
;
1892 #if SIZEOF_WCHAR_T == 4
1893 wxMBConvUTF16 converter
;
1895 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1896 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1897 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1899 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1900 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1901 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1902 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1904 chars
= unicharlen
/ 2;
1907 ubuf
= (UniChar
*) text
.wc_str();
1909 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1910 chars
= wxWcslen( wchar
.data() );
1911 ubuf
= (UniChar
*) wchar
.data();
1915 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1916 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1917 &chars
, &style
, &atsuLayout
);
1919 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1921 unsigned long actualNumberOfBounds
= 0;
1922 ATSTrapezoid glyphBounds
;
1924 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1926 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1927 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1928 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1931 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1932 //unsigned char uch = s[i];
1935 ::ATSUDisposeTextLayout(atsuLayout
);
1936 #if SIZEOF_WCHAR_T == 4
1941 void * wxMacCoreGraphicsContext::GetNativeContext()
1946 // concatenates this transform with the current transform of this context
1947 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
1950 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1952 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1955 // sets the transform of this context
1956 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
1960 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1961 transform
= CGAffineTransformInvert( transform
) ;
1962 CGContextConcatCTM( m_cgContext
, transform
);
1963 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
1967 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
1971 // gets the matrix of this context
1972 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
1974 wxGraphicsMatrix m
= CreateMatrix();
1975 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
1976 CGContextGetCTM( m_cgContext
));
1984 //-----------------------------------------------------------------------------
1985 // wxMacCoreGraphicsRenderer declaration
1986 //-----------------------------------------------------------------------------
1988 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
1991 wxMacCoreGraphicsRenderer() {}
1993 virtual ~wxMacCoreGraphicsRenderer() {}
1997 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
1999 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2001 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2003 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2005 virtual wxGraphicsContext
* CreateMeasuringContext();
2009 virtual wxGraphicsPath
CreatePath();
2013 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2014 wxDouble tx
=0.0, wxDouble ty
=0.0);
2017 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2019 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2021 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2022 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2023 const wxColour
&c1
, const wxColour
&c2
) ;
2025 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2026 // with radius r and color cColor
2027 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2028 const wxColour
&oColor
, const wxColour
&cColor
) ;
2031 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2034 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2037 //-----------------------------------------------------------------------------
2038 // wxMacCoreGraphicsRenderer implementation
2039 //-----------------------------------------------------------------------------
2041 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2043 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2045 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2047 return &gs_MacCoreGraphicsRenderer
;
2050 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2052 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2055 return new wxMacCoreGraphicsContext(this,
2056 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2060 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2064 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2066 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2070 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2072 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2075 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2077 return new wxMacCoreGraphicsContext(this, window
);
2080 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2082 return new wxMacCoreGraphicsContext(this);
2087 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2090 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2097 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2098 wxDouble tx
, wxDouble ty
)
2101 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2102 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2107 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2109 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2110 return wxNullGraphicsPen
;
2114 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2119 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2121 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2122 return wxNullGraphicsBrush
;
2126 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2131 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2132 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2133 const wxColour
&c1
, const wxColour
&c2
)
2136 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2137 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2142 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2143 // with radius r and color cColor
2144 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2145 const wxColour
&oColor
, const wxColour
&cColor
)
2148 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2149 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2155 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2160 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2164 return wxNullGraphicsFont
;