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 #if wxUSE_GRAPHICS_CONTEXT && wxMAC_USE_CORE_GRAPHICS
16 #include "wx/graphics.h"
19 #include "wx/dcclient.h"
20 #include "wx/dcmemory.h"
22 #include "wx/region.h"
26 #include "wx/mac/uma.h"
31 // in case our functions were defined outside std, we make it known all the same
37 #include "wx/mac/private.h"
39 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
40 typedef float CGFloat
;
42 #ifndef wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
43 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
44 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 1
46 #define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
56 const double M_PI
= 3.14159265358979;
60 static const double RAD2DEG
= 180.0 / M_PI
;
63 // Pen, Brushes and Fonts
67 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
69 // CGPattern wrapper class: always allocate on heap, never call destructor
71 class wxMacCoreGraphicsPattern
74 wxMacCoreGraphicsPattern() {}
76 // is guaranteed to be called only with a non-Null CGContextRef
77 virtual void Render( CGContextRef ctxRef
) = 0;
79 operator CGPatternRef() const { return m_patternRef
; }
82 virtual ~wxMacCoreGraphicsPattern()
84 // as this is called only when the m_patternRef is been released;
85 // don't release it again
88 static void _Render( void *info
, CGContextRef ctxRef
)
90 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
92 self
->Render( ctxRef
);
95 static void _Dispose( void *info
)
97 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
101 CGPatternRef m_patternRef
;
103 static const CGPatternCallbacks ms_Callbacks
;
106 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
108 class ImagePattern
: public wxMacCoreGraphicsPattern
111 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
113 wxASSERT( bmp
&& bmp
->Ok() );
115 Init( (CGImageRef
) bmp
->CGImageCreate() , transform
);
118 // ImagePattern takes ownership of CGImageRef passed in
119 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
124 Init( image
, transform
);
127 virtual void Render( CGContextRef ctxRef
)
130 HIViewDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
134 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
139 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
140 m_patternRef
= CGPatternCreate(
141 this , m_imageBounds
, transform
,
142 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
143 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
147 virtual ~ImagePattern()
150 CGImageRelease( m_image
);
154 CGRect m_imageBounds
;
157 class HatchPattern
: public wxMacCoreGraphicsPattern
160 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
162 m_hatch
= hatchstyle
;
163 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
164 m_patternRef
= CGPatternCreate(
165 this , m_imageBounds
, transform
,
166 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
167 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
170 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
172 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
173 if ( CGContextStrokeLineSegments
!=NULL
)
175 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
180 CGContextBeginPath( ctxRef
);
181 for (size_t i
= 0; i
< count
; i
+= 2)
183 CGContextMoveToPoint(ctxRef
, pts
[i
].x
, pts
[i
].y
);
184 CGContextAddLineToPoint(ctxRef
, pts
[i
+1].x
, pts
[i
+1].y
);
186 CGContextStrokePath(ctxRef
);
190 virtual void Render( CGContextRef ctxRef
)
194 case wxBDIAGONAL_HATCH
:
198 { 8.0 , 0.0 } , { 0.0 , 8.0 }
200 StrokeLineSegments( ctxRef
, pts
, 2 );
204 case wxCROSSDIAG_HATCH
:
208 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
209 { 8.0 , 0.0 } , { 0.0 , 8.0 }
211 StrokeLineSegments( ctxRef
, pts
, 4 );
215 case wxFDIAGONAL_HATCH
:
219 { 0.0 , 0.0 } , { 8.0 , 8.0 }
221 StrokeLineSegments( ctxRef
, pts
, 2 );
229 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
230 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
232 StrokeLineSegments( ctxRef
, pts
, 4 );
236 case wxHORIZONTAL_HATCH
:
240 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
242 StrokeLineSegments( ctxRef
, pts
, 2 );
246 case wxVERTICAL_HATCH
:
250 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
252 StrokeLineSegments( ctxRef
, pts
, 2 );
262 virtual ~HatchPattern() {}
264 CGRect m_imageBounds
;
268 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
271 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
272 ~wxMacCoreGraphicsPenData();
275 virtual void Apply( wxGraphicsContext
* context
);
276 virtual wxDouble
GetWidth() { return m_width
; }
280 wxMacCFRefHolder
<CGColorRef
> m_color
;
281 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
287 const CGFloat
*m_lengths
;
288 CGFloat
*m_userLengths
;
292 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
293 CGFloat
* m_patternColorComponents
;
296 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
297 wxGraphicsObjectRefData( renderer
)
301 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
302 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
303 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
305 // TODO: * m_dc->m_scaleX
306 m_width
= pen
.GetWidth();
310 switch ( pen
.GetCap() )
313 m_cap
= kCGLineCapRound
;
316 case wxCAP_PROJECTING
:
317 m_cap
= kCGLineCapSquare
;
321 m_cap
= kCGLineCapButt
;
325 m_cap
= kCGLineCapButt
;
329 switch ( pen
.GetJoin() )
332 m_join
= kCGLineJoinBevel
;
336 m_join
= kCGLineJoinMiter
;
340 m_join
= kCGLineJoinRound
;
344 m_join
= kCGLineJoinMiter
;
348 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
350 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
351 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
352 static const CGFloat dashed
[] = { 19.0 , 9.0 };
353 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
355 switch ( pen
.GetStyle() )
361 m_count
= WXSIZEOF(dotted
);
362 m_userLengths
= new CGFloat
[ m_count
] ;
363 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
364 m_lengths
= m_userLengths
;
368 m_count
= WXSIZEOF(dashed
);
373 m_count
= WXSIZEOF(short_dashed
);
374 m_lengths
= short_dashed
;
378 m_count
= WXSIZEOF(dotted_dashed
);
379 m_lengths
= dotted_dashed
;
384 m_count
= pen
.GetDashes( &dashes
);
385 if ((dashes
!= NULL
) && (m_count
> 0))
387 m_userLengths
= new CGFloat
[m_count
];
388 for ( int i
= 0; i
< m_count
; ++i
)
390 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
392 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
393 m_userLengths
[i
] = dashUnit
+ 2.0;
394 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
395 m_userLengths
[i
] = dashUnit
;
398 m_lengths
= m_userLengths
;
403 wxBitmap
* bmp
= pen
.GetStipple();
404 if ( bmp
&& bmp
->Ok() )
406 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
407 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
408 m_patternColorComponents
= new CGFloat
[1] ;
409 m_patternColorComponents
[0] = 1.0;
418 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
419 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
420 m_patternColorComponents
= new CGFloat
[4] ;
421 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
422 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
423 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
424 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
428 if ((m_lengths
!= NULL
) && (m_count
> 0))
430 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
431 m_cap
= kCGLineCapButt
;
435 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
437 delete[] m_userLengths
;
438 delete[] m_patternColorComponents
;
441 void wxMacCoreGraphicsPenData::Init()
444 m_userLengths
= NULL
;
447 m_patternColorComponents
= NULL
;
451 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
453 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
454 CGContextSetLineWidth( cg
, m_width
);
455 CGContextSetLineJoin( cg
, m_join
);
457 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
458 CGContextSetLineCap( cg
, m_cap
);
462 CGAffineTransform matrix
= CGContextGetCTM( cg
);
463 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
464 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
465 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
469 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
471 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
474 CGContextSetStrokeColorWithColor( cg
, m_color
);
482 static const char *gs_stripedback_xpm
[] = {
483 /* columns rows colors chars-per-pixel */
494 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
496 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
498 delete[] m_patternColorComponents
;
501 void wxMacCoreGraphicsColour::Init()
504 m_patternColorComponents
= NULL
;
507 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
511 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
512 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
513 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
514 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
518 CGContextSetFillColorWithColor( cgContext
, m_color
);
522 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
527 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
530 if ( brush
.GetStyle() == wxSOLID
)
532 if ( brush
.MacGetBrushKind() == kwxMacBrushTheme
)
534 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
535 if ( UMAGetSystemVersion() >= 0x1040 )
538 HIThemeBrushCreateCGColor( brush
.MacGetTheme(), &color
);
539 m_color
.Set( color
) ;
544 if( brush
.MacGetTheme() == kThemeBrushDialogBackgroundActive
)
546 // striped background is a pattern, we have to emulate it
549 m_patternColorComponents
= new CGFloat
[1] ;
550 m_patternColorComponents
[0] = 1.0;
551 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
552 m_pattern
.Set( *( new ImagePattern( &gs_stripedback_bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
556 // as close as we can get, unfortunately < 10.4 things get difficult
558 GetThemeBrushAsColor( brush
.MacGetTheme(), 32, true, &color
);
559 CGFloat components
[4] = { (CGFloat
) color
.red
/ 65536,
560 (CGFloat
) color
.green
/ 65536, (CGFloat
) color
.blue
/ 65536, 1 } ;
561 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
567 CGFloat components
[4] = { brush
.GetColour().Red() / 255.0 , brush
.GetColour().Green() / 255.0 ,
568 brush
.GetColour().Blue() / 255.0 , brush
.GetColour().Alpha() / 255.0 } ;
569 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
572 else if ( brush
.IsHatch() )
575 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
576 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
578 m_patternColorComponents
= new CGFloat
[4] ;
579 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
580 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
581 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
582 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
586 // now brush is a bitmap
587 wxBitmap
* bmp
= brush
.GetStipple();
588 if ( bmp
&& bmp
->Ok() )
591 m_patternColorComponents
= new CGFloat
[1] ;
592 m_patternColorComponents
[0] = 1.0;
593 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
594 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
599 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
602 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
603 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
604 ~wxMacCoreGraphicsBrushData ();
606 virtual void Apply( wxGraphicsContext
* context
);
607 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
608 const wxColour
&c1
, const wxColour
&c2
);
609 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
610 const wxColour
&oColor
, const wxColour
&cColor
);
612 virtual bool IsShading() { return m_isShading
; }
613 CGShadingRef
GetShading() { return m_shading
; }
615 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
616 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
619 wxMacCoreGraphicsColour m_cgColor
;
622 CGFunctionRef m_gradientFunction
;
623 CGShadingRef m_shading
;
624 CGFloat
*m_gradientComponents
;
627 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
632 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
633 const wxColour
&c1
, const wxColour
&c2
)
635 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
636 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
640 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
641 const wxColour
&oColor
, const wxColour
&cColor
)
643 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
644 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
648 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
655 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
658 CGShadingRelease(m_shading
);
660 if( m_gradientFunction
)
661 CGFunctionRelease(m_gradientFunction
);
663 delete[] m_gradientComponents
;
666 void wxMacCoreGraphicsBrushData::Init()
668 m_gradientFunction
= NULL
;
670 m_gradientComponents
= NULL
;
674 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
676 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
680 // nothing to set as shades are processed by clipping using the path and filling
684 m_cgColor
.Apply( cg
);
688 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
690 CGFloat
* colors
= (CGFloat
*) info
;
692 for( int i
= 0 ; i
< 4 ; ++i
)
694 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
698 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
700 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
701 static const CGFloat input_value_range
[2] = { 0, 1 };
702 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
703 m_gradientComponents
= new CGFloat
[8] ;
704 m_gradientComponents
[0] = c1
.Red() / 255.0;
705 m_gradientComponents
[1] = c1
.Green() / 255.0;
706 m_gradientComponents
[2] = c1
.Blue() / 255.0;
707 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
708 m_gradientComponents
[4] = c2
.Red() / 255.0;
709 m_gradientComponents
[5] = c2
.Green() / 255.0;
710 m_gradientComponents
[6] = c2
.Blue() / 255.0;
711 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
713 return CGFunctionCreate ( m_gradientComponents
, 1,
724 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
727 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
728 ~wxMacCoreGraphicsFontData();
730 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
732 ATSUStyle m_macATSUIStyle
;
735 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
737 m_macATSUIStyle
= NULL
;
741 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
743 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
745 // we need the scale here ...
747 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
748 RGBColor atsuColor
= MAC_WXCOLORREF( col
.GetPixel() );
749 ATSUAttributeTag atsuTags
[] =
754 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
759 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
765 status
= ::ATSUSetAttributes(
766 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
767 atsuTags
, atsuSizes
, atsuValues
);
769 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
772 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
774 if ( m_macATSUIStyle
)
776 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
777 m_macATSUIStyle
= NULL
;
785 //-----------------------------------------------------------------------------
786 // wxMacCoreGraphicsMatrix declaration
787 //-----------------------------------------------------------------------------
789 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
792 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
794 virtual ~wxMacCoreGraphicsMatrixData() ;
796 virtual wxGraphicsObjectRefData
*Clone() const ;
798 // concatenates the matrix
799 virtual void Concat( const wxGraphicsMatrixData
*t
);
801 // sets the matrix to the respective values
802 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
803 wxDouble tx
=0.0, wxDouble ty
=0.0);
805 // gets the component valuess of the matrix
806 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
807 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
809 // makes this the inverse matrix
810 virtual void Invert();
812 // returns true if the elements of the transformation matrix are equal ?
813 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
815 // return true if this is the identity matrix
816 virtual bool IsIdentity() const;
822 // add the translation to this matrix
823 virtual void Translate( wxDouble dx
, wxDouble dy
);
825 // add the scale to this matrix
826 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
828 // add the rotation to this matrix (radians)
829 virtual void Rotate( wxDouble angle
);
832 // apply the transforms
835 // applies that matrix to the point
836 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
838 // applies the matrix except for translations
839 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
841 // returns the native representation
842 virtual void * GetNativeMatrix() const;
845 CGAffineTransform m_matrix
;
848 //-----------------------------------------------------------------------------
849 // wxMacCoreGraphicsMatrix implementation
850 //-----------------------------------------------------------------------------
852 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
856 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
860 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
862 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
863 m
->m_matrix
= m_matrix
;
867 // concatenates the matrix
868 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
870 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
873 // sets the matrix to the respective values
874 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
875 wxDouble tx
, wxDouble ty
)
877 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
880 // gets the component valuess of the matrix
881 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
882 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
884 if (a
) *a
= m_matrix
.a
;
885 if (b
) *b
= m_matrix
.b
;
886 if (c
) *c
= m_matrix
.c
;
887 if (d
) *d
= m_matrix
.d
;
888 if (tx
) *tx
= m_matrix
.tx
;
889 if (ty
) *ty
= m_matrix
.ty
;
892 // makes this the inverse matrix
893 void wxMacCoreGraphicsMatrixData::Invert()
895 m_matrix
= CGAffineTransformInvert( m_matrix
);
898 // returns true if the elements of the transformation matrix are equal ?
899 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
901 const CGAffineTransform
* tm
= (CGAffineTransform
*) t
->GetNativeMatrix();
902 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
903 if ( CGAffineTransformEqualToTransform
!=NULL
)
905 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
911 m_matrix
.a
== tm
->a
&&
912 m_matrix
.b
== tm
->b
&&
913 m_matrix
.c
== tm
->c
&&
914 m_matrix
.d
== tm
->d
&&
915 m_matrix
.tx
== tm
->tx
&&
916 m_matrix
.ty
== tm
->ty
) ;
920 // return true if this is the identity matrix
921 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
923 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
924 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
931 // add the translation to this matrix
932 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
934 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
937 // add the scale to this matrix
938 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
940 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
943 // add the rotation to this matrix (radians)
944 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
946 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
950 // apply the transforms
953 // applies that matrix to the point
954 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
956 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
962 // applies the matrix except for translations
963 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
965 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
970 // returns the native representation
971 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
973 return (void*) &m_matrix
;
980 //-----------------------------------------------------------------------------
981 // wxMacCoreGraphicsPath declaration
982 //-----------------------------------------------------------------------------
984 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
987 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
989 ~wxMacCoreGraphicsPathData();
991 virtual wxGraphicsObjectRefData
*Clone() const;
993 // begins a new subpath at (x,y)
994 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
996 // adds a straight line from the current point to (x,y)
997 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
999 // adds a cubic Bezier curve from the current point, using two control points and an end point
1000 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
1002 // closes the current sub-path
1003 virtual void CloseSubpath();
1005 // gets the last point of the current path, (0,0) if not yet set
1006 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
1008 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1009 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
1012 // These are convenience functions which - if not available natively will be assembled
1013 // using the primitives from above
1016 // adds a quadratic Bezier curve from the current point, using a control point and an end point
1017 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
1019 // appends a rectangle as a new closed subpath
1020 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1022 // appends an ellipsis as a new closed subpath fitting the passed rectangle
1023 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
1025 // 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)
1026 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
1028 // adds another path
1029 virtual void AddPath( const wxGraphicsPathData
* path
);
1031 // returns the native path
1032 virtual void * GetNativePath() const { return m_path
; }
1034 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
1035 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
1037 // transforms each point of this path by the matrix
1038 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
1040 // gets the bounding box enclosing all points (possibly including control points)
1041 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
1043 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
1045 CGMutablePathRef m_path
;
1048 //-----------------------------------------------------------------------------
1049 // wxMacCoreGraphicsPath implementation
1050 //-----------------------------------------------------------------------------
1052 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1057 m_path
= CGPathCreateMutable();
1060 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1062 CGPathRelease( m_path
);
1065 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1067 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1072 // opens (starts) a new subpath
1073 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1075 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1078 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1080 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1083 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1085 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1088 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1090 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1093 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1095 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1096 CGPathAddRect( m_path
, NULL
, cgRect
);
1099 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1101 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1104 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1105 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1107 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1108 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1111 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1113 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1116 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1118 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1121 // closes the current subpath
1122 void wxMacCoreGraphicsPathData::CloseSubpath()
1124 CGPathCloseSubpath( m_path
);
1127 // gets the last point of the current path, (0,0) if not yet set
1128 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1130 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1135 // transforms each point of this path by the matrix
1136 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1138 CGMutablePathRef p
= CGPathCreateMutable() ;
1139 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1140 CGPathRelease( m_path
);
1144 // gets the bounding box enclosing all points (possibly including control points)
1145 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1147 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1148 *x
= bounds
.origin
.x
;
1149 *y
= bounds
.origin
.y
;
1150 *w
= bounds
.size
.width
;
1151 *h
= bounds
.size
.height
;
1154 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1156 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1157 if ( CGPathContainsPoint
!=NULL
)
1159 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1164 // TODO : implementation for 10.3
1165 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1166 return CGRectContainsPoint( bounds
, CGPointMake(x
,y
) ) == 1;
1174 //-----------------------------------------------------------------------------
1175 // wxMacCoreGraphicsContext declaration
1176 //-----------------------------------------------------------------------------
1178 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1181 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1183 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1185 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1187 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1189 wxMacCoreGraphicsContext();
1191 ~wxMacCoreGraphicsContext();
1195 // returns the size of the graphics context in device coordinates
1196 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1198 virtual void StartPage( wxDouble width
, wxDouble height
);
1200 virtual void EndPage();
1202 virtual void Flush();
1204 // push the current state of the context, ie the transformation matrix on a stack
1205 virtual void PushState();
1207 // pops a stored state from the stack
1208 virtual void PopState();
1210 // clips drawings to the region
1211 virtual void Clip( const wxRegion
®ion
);
1213 // clips drawings to the rect
1214 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1216 // resets the clipping to original extent
1217 virtual void ResetClip();
1219 virtual void * GetNativeContext();
1221 bool SetLogicalFunction( int function
);
1227 virtual void Translate( wxDouble dx
, wxDouble dy
);
1230 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1233 virtual void Rotate( wxDouble angle
);
1235 // concatenates this transform with the current transform of this context
1236 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1238 // sets the transform of this context
1239 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1241 // gets the matrix of this context
1242 virtual wxGraphicsMatrix
GetTransform() const;
1244 // setting the paint
1247 // strokes along a path with the current pen
1248 virtual void StrokePath( const wxGraphicsPath
&path
);
1250 // fills a path with the current brush
1251 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1253 // draws a path by first filling and then stroking
1254 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1256 virtual bool ShouldOffset() const
1259 if ( !m_pen
.IsNull() )
1261 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1262 if ( penwidth
== 0 )
1265 return ( penwidth
% 2 ) == 1;
1271 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1273 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1275 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1276 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1278 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1284 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1286 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1288 void SetNativeContext( CGContextRef cg
);
1290 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1291 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1294 void EnsureIsValid();
1296 CGContextRef m_cgContext
;
1297 WindowRef m_windowRef
;
1298 bool m_releaseContext
;
1299 CGAffineTransform m_windowTransform
;
1303 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1306 //-----------------------------------------------------------------------------
1307 // device context implementation
1309 // more and more of the dc functionality should be implemented by calling
1310 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1311 // also coordinate conversions should be moved to native matrix ops
1312 //-----------------------------------------------------------------------------
1314 // we always stock two context states, one at entry, to be able to preserve the
1315 // state we were called with, the other one after changing to HI Graphics orientation
1316 // (this one is used for getting back clippings etc)
1318 //-----------------------------------------------------------------------------
1319 // wxMacCoreGraphicsContext implementation
1320 //-----------------------------------------------------------------------------
1322 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1324 class wxQuartzOffsetHelper
1327 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1332 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1334 ~wxQuartzOffsetHelper( )
1337 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1344 void wxMacCoreGraphicsContext::Init()
1347 m_releaseContext
= false;
1352 HIRect r
= CGRectMake(0,0,0,0);
1353 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1356 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1359 SetNativeContext(cgcontext
);
1364 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1367 m_windowRef
= window
;
1370 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1373 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1374 int originX
, originY
;
1375 originX
= originY
= 0;
1376 window
->MacWindowToRootWindow( &originX
, &originY
);
1378 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1380 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1381 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1382 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1385 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1390 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1393 wxLogDebug(wxT("Illegal Constructor called"));
1396 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1398 SetNativeContext(NULL
);
1401 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1408 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1411 if ( width
!= 0 && height
!= 0)
1412 r
= CGRectMake( 0 , 0 , width
, height
);
1414 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1416 CGContextBeginPage(m_cgContext
, &r
);
1417 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1418 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1421 void wxMacCoreGraphicsContext::EndPage()
1423 CGContextEndPage(m_cgContext
);
1426 void wxMacCoreGraphicsContext::Flush()
1428 CGContextFlush(m_cgContext
);
1431 void wxMacCoreGraphicsContext::EnsureIsValid()
1437 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1441 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1443 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1444 CGContextSaveGState( m_cgContext
);
1445 m_releaseContext
= true;
1446 if ( !HIShapeIsEmpty(m_clipRgn
) )
1448 // the clip region is in device coordinates, so we convert this again to user coordinates
1449 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1450 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1451 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1452 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1453 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1454 CGContextClip( m_cgContext
);
1456 CGContextSaveGState( m_cgContext
);
1460 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1462 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1464 if (m_logicalFunction
== function
)
1469 bool retval
= false;
1471 if ( function
== wxCOPY
)
1474 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1475 if ( CGContextSetBlendMode
!= NULL
)
1477 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1478 CGContextSetShouldAntialias( m_cgContext
, true );
1482 else if ( function
== wxINVERT
|| function
== wxXOR
)
1484 #if wxMAC_USE_CORE_GRAPHICS_BLEND_MODES
1485 if ( CGContextSetBlendMode
!= NULL
)
1487 // change color to white
1488 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1489 CGContextSetShouldAntialias( m_cgContext
, false );
1496 m_logicalFunction
= function
;
1500 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1504 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1505 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1506 CGContextClip( m_cgContext
);
1511 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1512 // to regions we try at least to have correct translations
1513 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1514 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1515 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1517 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1518 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1519 m_clipRgn
.Set(mutableShape
);
1523 // clips drawings to the rect
1524 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1526 HIRect r
= CGRectMake( x
, y
, w
, h
);
1529 CGContextClipToRect( m_cgContext
, r
);
1533 // the clipping itself must be stored as device coordinates, otherwise
1534 // we cannot apply it back correctly
1535 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1536 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1540 // resets the clipping to original extent
1541 void wxMacCoreGraphicsContext::ResetClip()
1545 // there is no way for clearing the clip, we can only revert to the stored
1546 // state, but then we have to make sure everything else is NOT restored
1547 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1548 CGContextRestoreGState( m_cgContext
);
1549 CGContextSaveGState( m_cgContext
);
1550 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1551 transformNew
= CGAffineTransformInvert( transformNew
) ;
1552 CGContextConcatCTM( m_cgContext
, transformNew
);
1553 CGContextConcatCTM( m_cgContext
, transform
);
1557 HIRect r
= CGRectMake(0,0,0,0);
1558 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1562 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1564 if ( m_pen
.IsNull() )
1569 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1571 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1572 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1573 CGContextStrokePath( m_cgContext
);
1576 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1578 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1580 // when using shading, we cannot draw pen and brush at the same time
1581 // revert to the base implementation of first filling and then stroking
1582 wxGraphicsContext::DrawPath( path
, fillStyle
);
1586 CGPathDrawingMode mode
= kCGPathFill
;
1587 if ( m_brush
.IsNull() )
1589 if ( m_pen
.IsNull() )
1592 mode
= kCGPathStroke
;
1596 if ( m_pen
.IsNull() )
1598 if ( fillStyle
== wxODDEVEN_RULE
)
1599 mode
= kCGPathEOFill
;
1605 if ( fillStyle
== wxODDEVEN_RULE
)
1606 mode
= kCGPathEOFillStroke
;
1608 mode
= kCGPathFillStroke
;
1614 if ( !m_brush
.IsNull() )
1615 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1616 if ( !m_pen
.IsNull() )
1617 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1619 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1621 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1622 CGContextDrawPath( m_cgContext
, mode
);
1625 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1627 if ( m_brush
.IsNull() )
1632 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1634 CGContextSaveGState( m_cgContext
);
1635 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1636 CGContextClip( m_cgContext
);
1637 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1638 CGContextRestoreGState( m_cgContext
);
1642 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1643 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1644 if ( fillStyle
== wxODDEVEN_RULE
)
1645 CGContextEOFillPath( m_cgContext
);
1647 CGContextFillPath( m_cgContext
);
1651 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1653 // we allow either setting or clearing but not replacing
1654 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1658 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1659 CGContextRestoreGState( m_cgContext
);
1660 CGContextRestoreGState( m_cgContext
);
1661 if ( m_releaseContext
)
1664 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1668 CGContextRelease(m_cgContext
);
1674 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1675 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1676 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1677 // for this one operation.
1679 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1683 CGContextRetain(m_cgContext
);
1684 CGContextSaveGState( m_cgContext
);
1685 CGContextSaveGState( m_cgContext
);
1686 m_releaseContext
= false;
1690 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1693 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1695 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1698 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1701 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1703 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1706 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1709 CGContextRotateCTM( m_cgContext
, angle
);
1711 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1714 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1718 CGImageRef image
= (CGImageRef
)( bmp
.CGImageCreate() );
1719 HIRect r
= CGRectMake( x
, y
, w
, h
);
1720 if ( bmp
.GetDepth() == 1 )
1722 // is is a mask, the '1' in the mask tell where to draw the current brush
1723 if ( !m_brush
.IsNull() )
1725 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1727 // TODO clip to mask
1729 CGContextSaveGState( m_cgContext );
1730 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1731 CGContextClip( m_cgContext );
1732 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1733 CGContextRestoreGState( m_cgContext);
1738 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1739 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1745 HIViewDrawCGImage( m_cgContext
, &r
, image
);
1747 CGImageRelease( image
);
1750 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1754 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1755 CGContextSaveGState( m_cgContext
);
1756 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1757 CGContextScaleCTM( m_cgContext
, 1, -1 );
1758 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1759 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1760 CGContextRestoreGState( m_cgContext
);
1763 void wxMacCoreGraphicsContext::PushState()
1767 CGContextSaveGState( m_cgContext
);
1770 void wxMacCoreGraphicsContext::PopState()
1774 CGContextRestoreGState( m_cgContext
);
1777 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1779 DrawText(str
, x
, y
, 0.0);
1782 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1784 if ( m_font
.IsNull() )
1789 OSStatus status
= noErr
;
1790 ATSUTextLayout atsuLayout
;
1791 UniCharCount chars
= str
.length();
1792 UniChar
* ubuf
= NULL
;
1794 #if SIZEOF_WCHAR_T == 4
1795 wxMBConvUTF16 converter
;
1797 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1798 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1799 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1801 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1802 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1803 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1804 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1806 chars
= unicharlen
/ 2;
1809 ubuf
= (UniChar
*) str
.wc_str();
1811 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1812 chars
= wxWcslen( wchar
.data() );
1813 ubuf
= (UniChar
*) wchar
.data();
1817 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1818 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1819 &chars
, &style
, &atsuLayout
);
1821 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1823 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1824 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1826 int iAngle
= int( angle
* RAD2DEG
);
1827 if ( abs(iAngle
) > 0 )
1829 Fixed atsuAngle
= IntToFixed( iAngle
);
1830 ATSUAttributeTag atsuTags
[] =
1832 kATSULineRotationTag
,
1834 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1838 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1842 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1843 atsuTags
, atsuSizes
, atsuValues
);
1847 ATSUAttributeTag atsuTags
[] =
1851 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1853 sizeof( CGContextRef
) ,
1855 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1859 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1860 atsuTags
, atsuSizes
, atsuValues
);
1863 ATSUTextMeasurement textBefore
, textAfter
;
1864 ATSUTextMeasurement ascent
, descent
;
1866 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1867 &textBefore
, &textAfter
, &ascent
, &descent
);
1869 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1872 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1873 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1875 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1876 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1877 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1879 CGContextSaveGState(m_cgContext
);
1880 CGContextTranslateCTM(m_cgContext
, x
, y
);
1881 CGContextScaleCTM(m_cgContext
, 1, -1);
1882 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1883 IntToFixed(0) , IntToFixed(0) );
1885 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1887 CGContextRestoreGState(m_cgContext
);
1889 ::ATSUDisposeTextLayout(atsuLayout
);
1891 #if SIZEOF_WCHAR_T == 4
1896 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1897 wxDouble
*descent
, wxDouble
*externalLeading
) const
1899 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1907 if ( externalLeading
)
1908 *externalLeading
= 0;
1913 OSStatus status
= noErr
;
1915 ATSUTextLayout atsuLayout
;
1916 UniCharCount chars
= str
.length();
1917 UniChar
* ubuf
= NULL
;
1919 #if SIZEOF_WCHAR_T == 4
1920 wxMBConvUTF16 converter
;
1922 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1923 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1924 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1926 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1927 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1928 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1929 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1931 chars
= unicharlen
/ 2;
1934 ubuf
= (UniChar
*) str
.wc_str();
1936 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1937 chars
= wxWcslen( wchar
.data() );
1938 ubuf
= (UniChar
*) wchar
.data();
1942 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1943 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1944 &chars
, &style
, &atsuLayout
);
1946 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1948 ATSUTextMeasurement textBefore
, textAfter
;
1949 ATSUTextMeasurement textAscent
, textDescent
;
1951 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1952 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1955 *height
= FixedToInt(textAscent
+ textDescent
);
1957 *descent
= FixedToInt(textDescent
);
1958 if ( externalLeading
)
1959 *externalLeading
= 0;
1961 *width
= FixedToInt(textAfter
- textBefore
);
1963 ::ATSUDisposeTextLayout(atsuLayout
);
1964 #if SIZEOF_WCHAR_T == 4
1969 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1972 widths
.Add(0, text
.length());
1977 ATSUTextLayout atsuLayout
;
1978 UniCharCount chars
= text
.length();
1979 UniChar
* ubuf
= NULL
;
1981 #if SIZEOF_WCHAR_T == 4
1982 wxMBConvUTF16 converter
;
1984 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1985 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1986 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1988 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1989 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1990 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1991 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1993 chars
= unicharlen
/ 2;
1996 ubuf
= (UniChar
*) text
.wc_str();
1998 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1999 chars
= wxWcslen( wchar
.data() );
2000 ubuf
= (UniChar
*) wchar
.data();
2004 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
2005 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
2006 &chars
, &style
, &atsuLayout
);
2008 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
2010 unsigned long actualNumberOfBounds
= 0;
2011 ATSTrapezoid glyphBounds
;
2013 // We get a single bound, since the text should only require one. If it requires more, there is an issue
2015 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
2016 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
2017 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
2020 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
2021 //unsigned char uch = s[i];
2024 ::ATSUDisposeTextLayout(atsuLayout
);
2025 #if SIZEOF_WCHAR_T == 4
2030 void * wxMacCoreGraphicsContext::GetNativeContext()
2035 // concatenates this transform with the current transform of this context
2036 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
2039 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2041 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2044 // sets the transform of this context
2045 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
2049 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
2050 transform
= CGAffineTransformInvert( transform
) ;
2051 CGContextConcatCTM( m_cgContext
, transform
);
2052 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2056 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
2060 // gets the matrix of this context
2061 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
2063 wxGraphicsMatrix m
= CreateMatrix();
2064 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
2065 CGContextGetCTM( m_cgContext
));
2073 //-----------------------------------------------------------------------------
2074 // wxMacCoreGraphicsRenderer declaration
2075 //-----------------------------------------------------------------------------
2077 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2080 wxMacCoreGraphicsRenderer() {}
2082 virtual ~wxMacCoreGraphicsRenderer() {}
2086 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2088 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2090 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2092 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2094 virtual wxGraphicsContext
* CreateMeasuringContext();
2098 virtual wxGraphicsPath
CreatePath();
2102 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2103 wxDouble tx
=0.0, wxDouble ty
=0.0);
2106 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2108 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2110 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2111 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2112 const wxColour
&c1
, const wxColour
&c2
) ;
2114 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2115 // with radius r and color cColor
2116 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2117 const wxColour
&oColor
, const wxColour
&cColor
) ;
2120 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2123 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2126 //-----------------------------------------------------------------------------
2127 // wxMacCoreGraphicsRenderer implementation
2128 //-----------------------------------------------------------------------------
2130 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2132 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2134 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2136 return &gs_MacCoreGraphicsRenderer
;
2139 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2141 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2144 return new wxMacCoreGraphicsContext(this,
2145 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2149 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2153 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2155 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2159 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2161 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2164 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2166 return new wxMacCoreGraphicsContext(this, window
);
2169 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2171 return new wxMacCoreGraphicsContext(this);
2176 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2179 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2186 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2187 wxDouble tx
, wxDouble ty
)
2190 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2191 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2196 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2198 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2199 return wxNullGraphicsPen
;
2203 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2208 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2210 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2211 return wxNullGraphicsBrush
;
2215 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2220 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2221 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2222 const wxColour
&c1
, const wxColour
&c2
)
2225 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2226 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2231 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2232 // with radius r and color cColor
2233 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2234 const wxColour
&oColor
, const wxColour
&cColor
)
2237 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2238 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2244 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2249 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2253 return wxNullGraphicsFont
;
2258 #endif // wxMAC_USE_CORE_GRAPHICS