1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dccg.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/graphics.h"
17 #include "wx/dcclient.h"
18 #include "wx/dcmemory.h"
20 #include "wx/region.h"
25 #include "wx/mac/uma.h"
30 // in case our functions were defined outside std, we make it known all the same
36 #include "wx/mac/private.h"
38 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
39 typedef float CGFloat
;
43 #define wxMAC_USE_CORE_TEXT 1
45 #define wxMAC_USE_ATSU_TEXT 1
47 #undef wxMAC_USE_CG_TEXT
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
54 const double M_PI
= 3.14159265358979;
58 static const double RAD2DEG
= 180.0 / M_PI
;
61 // Pen, Brushes and Fonts
65 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
67 OSStatus
wxMacDrawCGImage(
68 CGContextRef inContext
,
69 const HIRect
* inBounds
,
74 CGContextDrawImage(inContext
, *inBounds
, inImage
);
77 return HIViewDrawCGImage( inContext
, inBounds
, inImage
);
81 // CGPattern wrapper class: always allocate on heap, never call destructor
83 class wxMacCoreGraphicsPattern
86 wxMacCoreGraphicsPattern() {}
88 // is guaranteed to be called only with a non-Null CGContextRef
89 virtual void Render( CGContextRef ctxRef
) = 0;
91 operator CGPatternRef() const { return m_patternRef
; }
94 virtual ~wxMacCoreGraphicsPattern()
96 // as this is called only when the m_patternRef is been released;
97 // don't release it again
100 static void _Render( void *info
, CGContextRef ctxRef
)
102 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
103 if ( self
&& ctxRef
)
104 self
->Render( ctxRef
);
107 static void _Dispose( void *info
)
109 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
113 CGPatternRef m_patternRef
;
115 static const CGPatternCallbacks ms_Callbacks
;
118 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
120 class ImagePattern
: public wxMacCoreGraphicsPattern
123 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
125 wxASSERT( bmp
&& bmp
->Ok() );
127 Init( (CGImageRef
) bmp
->CreateCGImage() , transform
);
130 // ImagePattern takes ownership of CGImageRef passed in
131 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
136 Init( image
, transform
);
139 virtual void Render( CGContextRef ctxRef
)
142 wxMacDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
146 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
151 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
152 m_patternRef
= CGPatternCreate(
153 this , m_imageBounds
, transform
,
154 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
155 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
159 virtual ~ImagePattern()
162 CGImageRelease( m_image
);
166 CGRect m_imageBounds
;
169 class HatchPattern
: public wxMacCoreGraphicsPattern
172 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
174 m_hatch
= hatchstyle
;
175 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
176 m_patternRef
= CGPatternCreate(
177 this , m_imageBounds
, transform
,
178 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
179 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
182 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
184 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
187 virtual void Render( CGContextRef ctxRef
)
191 case wxBDIAGONAL_HATCH
:
195 { 8.0 , 0.0 } , { 0.0 , 8.0 }
197 StrokeLineSegments( ctxRef
, pts
, 2 );
201 case wxCROSSDIAG_HATCH
:
205 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
206 { 8.0 , 0.0 } , { 0.0 , 8.0 }
208 StrokeLineSegments( ctxRef
, pts
, 4 );
212 case wxFDIAGONAL_HATCH
:
216 { 0.0 , 0.0 } , { 8.0 , 8.0 }
218 StrokeLineSegments( ctxRef
, pts
, 2 );
226 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
227 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
229 StrokeLineSegments( ctxRef
, pts
, 4 );
233 case wxHORIZONTAL_HATCH
:
237 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
239 StrokeLineSegments( ctxRef
, pts
, 2 );
243 case wxVERTICAL_HATCH
:
247 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
249 StrokeLineSegments( ctxRef
, pts
, 2 );
259 virtual ~HatchPattern() {}
261 CGRect m_imageBounds
;
265 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
268 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
269 ~wxMacCoreGraphicsPenData();
272 virtual void Apply( wxGraphicsContext
* context
);
273 virtual wxDouble
GetWidth() { return m_width
; }
277 wxMacCFRefHolder
<CGColorRef
> m_color
;
278 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
284 const CGFloat
*m_lengths
;
285 CGFloat
*m_userLengths
;
289 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
290 CGFloat
* m_patternColorComponents
;
293 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
294 wxGraphicsObjectRefData( renderer
)
298 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
299 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
300 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
302 // TODO: * m_dc->m_scaleX
303 m_width
= pen
.GetWidth();
307 switch ( pen
.GetCap() )
310 m_cap
= kCGLineCapRound
;
313 case wxCAP_PROJECTING
:
314 m_cap
= kCGLineCapSquare
;
318 m_cap
= kCGLineCapButt
;
322 m_cap
= kCGLineCapButt
;
326 switch ( pen
.GetJoin() )
329 m_join
= kCGLineJoinBevel
;
333 m_join
= kCGLineJoinMiter
;
337 m_join
= kCGLineJoinRound
;
341 m_join
= kCGLineJoinMiter
;
345 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
347 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
348 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
349 static const CGFloat dashed
[] = { 19.0 , 9.0 };
350 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
352 switch ( pen
.GetStyle() )
358 m_count
= WXSIZEOF(dotted
);
359 m_userLengths
= new CGFloat
[ m_count
] ;
360 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
361 m_lengths
= m_userLengths
;
365 m_count
= WXSIZEOF(dashed
);
370 m_count
= WXSIZEOF(short_dashed
);
371 m_lengths
= short_dashed
;
375 m_count
= WXSIZEOF(dotted_dashed
);
376 m_lengths
= dotted_dashed
;
381 m_count
= pen
.GetDashes( &dashes
);
382 if ((dashes
!= NULL
) && (m_count
> 0))
384 m_userLengths
= new CGFloat
[m_count
];
385 for ( int i
= 0; i
< m_count
; ++i
)
387 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
389 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
390 m_userLengths
[i
] = dashUnit
+ 2.0;
391 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
392 m_userLengths
[i
] = dashUnit
;
395 m_lengths
= m_userLengths
;
400 wxBitmap
* bmp
= pen
.GetStipple();
401 if ( bmp
&& bmp
->Ok() )
403 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
404 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
405 m_patternColorComponents
= new CGFloat
[1] ;
406 m_patternColorComponents
[0] = 1.0;
415 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
416 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
417 m_patternColorComponents
= new CGFloat
[4] ;
418 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
419 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
420 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
421 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
425 if ((m_lengths
!= NULL
) && (m_count
> 0))
427 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
428 m_cap
= kCGLineCapButt
;
432 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
434 delete[] m_userLengths
;
435 delete[] m_patternColorComponents
;
438 void wxMacCoreGraphicsPenData::Init()
441 m_userLengths
= NULL
;
444 m_patternColorComponents
= NULL
;
448 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
450 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
451 CGContextSetLineWidth( cg
, m_width
);
452 CGContextSetLineJoin( cg
, m_join
);
454 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
455 CGContextSetLineCap( cg
, m_cap
);
459 CGAffineTransform matrix
= CGContextGetCTM( cg
);
460 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
461 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
462 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
466 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
468 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
471 CGContextSetStrokeColorWithColor( cg
, m_color
);
479 static const char *gs_stripedback_xpm
[] = {
480 /* columns rows colors chars-per-pixel */
491 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
493 // make sure we all use one class for all conversions from wx to native colour
495 class wxMacCoreGraphicsColour
498 wxMacCoreGraphicsColour();
499 wxMacCoreGraphicsColour(const wxBrush
&brush
);
500 ~wxMacCoreGraphicsColour();
502 void Apply( CGContextRef cgContext
);
505 wxMacCFRefHolder
<CGColorRef
> m_color
;
506 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
509 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
510 CGFloat
* m_patternColorComponents
;
513 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
515 delete[] m_patternColorComponents
;
518 void wxMacCoreGraphicsColour::Init()
521 m_patternColorComponents
= NULL
;
524 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
528 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
529 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
530 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
531 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
535 CGContextSetFillColorWithColor( cgContext
, m_color
);
539 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
544 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
547 if ( brush
.GetStyle() == wxSOLID
)
549 m_color
.Set( brush
.GetColour().CreateCGColor() );
551 else if ( brush
.IsHatch() )
554 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
555 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
557 m_patternColorComponents
= new CGFloat
[4] ;
558 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
559 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
560 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
561 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
565 // now brush is a bitmap
566 wxBitmap
* bmp
= brush
.GetStipple();
567 if ( bmp
&& bmp
->Ok() )
570 m_patternColorComponents
= new CGFloat
[1] ;
571 m_patternColorComponents
[0] = 1.0;
572 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
573 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
578 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
581 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
582 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
583 ~wxMacCoreGraphicsBrushData ();
585 virtual void Apply( wxGraphicsContext
* context
);
586 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
587 const wxColour
&c1
, const wxColour
&c2
);
588 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
589 const wxColour
&oColor
, const wxColour
&cColor
);
591 virtual bool IsShading() { return m_isShading
; }
592 CGShadingRef
GetShading() { return m_shading
; }
594 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
595 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
598 wxMacCoreGraphicsColour m_cgColor
;
601 CGFunctionRef m_gradientFunction
;
602 CGShadingRef m_shading
;
603 CGFloat
*m_gradientComponents
;
606 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
611 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
612 const wxColour
&c1
, const wxColour
&c2
)
614 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
615 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
619 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
620 const wxColour
&oColor
, const wxColour
&cColor
)
622 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
623 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
627 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
634 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
637 CGShadingRelease(m_shading
);
639 if( m_gradientFunction
)
640 CGFunctionRelease(m_gradientFunction
);
642 delete[] m_gradientComponents
;
645 void wxMacCoreGraphicsBrushData::Init()
647 m_gradientFunction
= NULL
;
649 m_gradientComponents
= NULL
;
653 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
655 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
659 // nothing to set as shades are processed by clipping using the path and filling
663 m_cgColor
.Apply( cg
);
667 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
669 CGFloat
* colors
= (CGFloat
*) info
;
671 for( int i
= 0 ; i
< 4 ; ++i
)
673 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
677 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
679 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
680 static const CGFloat input_value_range
[2] = { 0, 1 };
681 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
682 m_gradientComponents
= new CGFloat
[8] ;
683 m_gradientComponents
[0] = c1
.Red() / 255.0;
684 m_gradientComponents
[1] = c1
.Green() / 255.0;
685 m_gradientComponents
[2] = c1
.Blue() / 255.0;
686 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
687 m_gradientComponents
[4] = c2
.Red() / 255.0;
688 m_gradientComponents
[5] = c2
.Green() / 255.0;
689 m_gradientComponents
[6] = c2
.Blue() / 255.0;
690 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
692 return CGFunctionCreate ( m_gradientComponents
, 1,
703 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
706 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
707 ~wxMacCoreGraphicsFontData();
709 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
711 ATSUStyle m_macATSUIStyle
;
714 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
716 m_macATSUIStyle
= NULL
;
718 #ifdef wxMAC_USE_CORE_TEXT
719 #elif defined(wxMAC_USE_ATSU_TEXT)
722 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
724 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
726 // we need the scale here ...
728 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
730 col
.GetRGBColor( &atsuColor
);
731 ATSUAttributeTag atsuTags
[] =
736 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
741 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
747 status
= ::ATSUSetAttributes(
748 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
749 atsuTags
, atsuSizes
, atsuValues
);
751 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
752 #elif defined(WXMAC_USE_CG_TEXT)
756 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
758 #ifdef wxMAC_USE_CORE_TEXT
759 #elif defined(wxMAC_USE_ATSU_TEXT)
760 if ( m_macATSUIStyle
)
762 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
763 m_macATSUIStyle
= NULL
;
765 #elif defined(WXMAC_USE_CG_TEXT)
773 //-----------------------------------------------------------------------------
774 // wxMacCoreGraphicsMatrix declaration
775 //-----------------------------------------------------------------------------
777 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
780 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
782 virtual ~wxMacCoreGraphicsMatrixData() ;
784 virtual wxGraphicsObjectRefData
*Clone() const ;
786 // concatenates the matrix
787 virtual void Concat( const wxGraphicsMatrixData
*t
);
789 // sets the matrix to the respective values
790 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
791 wxDouble tx
=0.0, wxDouble ty
=0.0);
793 // gets the component valuess of the matrix
794 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
795 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
797 // makes this the inverse matrix
798 virtual void Invert();
800 // returns true if the elements of the transformation matrix are equal ?
801 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
803 // return true if this is the identity matrix
804 virtual bool IsIdentity() const;
810 // add the translation to this matrix
811 virtual void Translate( wxDouble dx
, wxDouble dy
);
813 // add the scale to this matrix
814 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
816 // add the rotation to this matrix (radians)
817 virtual void Rotate( wxDouble angle
);
820 // apply the transforms
823 // applies that matrix to the point
824 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
826 // applies the matrix except for translations
827 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
829 // returns the native representation
830 virtual void * GetNativeMatrix() const;
833 CGAffineTransform m_matrix
;
836 //-----------------------------------------------------------------------------
837 // wxMacCoreGraphicsMatrix implementation
838 //-----------------------------------------------------------------------------
840 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
844 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
848 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
850 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
851 m
->m_matrix
= m_matrix
;
855 // concatenates the matrix
856 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
858 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
861 // sets the matrix to the respective values
862 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
863 wxDouble tx
, wxDouble ty
)
865 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
868 // gets the component valuess of the matrix
869 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
870 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
872 if (a
) *a
= m_matrix
.a
;
873 if (b
) *b
= m_matrix
.b
;
874 if (c
) *c
= m_matrix
.c
;
875 if (d
) *d
= m_matrix
.d
;
876 if (tx
) *tx
= m_matrix
.tx
;
877 if (ty
) *ty
= m_matrix
.ty
;
880 // makes this the inverse matrix
881 void wxMacCoreGraphicsMatrixData::Invert()
883 m_matrix
= CGAffineTransformInvert( m_matrix
);
886 // returns true if the elements of the transformation matrix are equal ?
887 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
889 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
892 // return true if this is the identity matrix
893 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
895 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
896 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
903 // add the translation to this matrix
904 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
906 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
909 // add the scale to this matrix
910 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
912 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
915 // add the rotation to this matrix (radians)
916 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
918 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
922 // apply the transforms
925 // applies that matrix to the point
926 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
928 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
934 // applies the matrix except for translations
935 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
937 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
942 // returns the native representation
943 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
945 return (void*) &m_matrix
;
952 //-----------------------------------------------------------------------------
953 // wxMacCoreGraphicsPath declaration
954 //-----------------------------------------------------------------------------
956 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
959 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
961 ~wxMacCoreGraphicsPathData();
963 virtual wxGraphicsObjectRefData
*Clone() const;
965 // begins a new subpath at (x,y)
966 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
968 // adds a straight line from the current point to (x,y)
969 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
971 // adds a cubic Bezier curve from the current point, using two control points and an end point
972 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
974 // closes the current sub-path
975 virtual void CloseSubpath();
977 // gets the last point of the current path, (0,0) if not yet set
978 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
980 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
981 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
984 // These are convenience functions which - if not available natively will be assembled
985 // using the primitives from above
988 // adds a quadratic Bezier curve from the current point, using a control point and an end point
989 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
991 // appends a rectangle as a new closed subpath
992 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
994 // appends an ellipsis as a new closed subpath fitting the passed rectangle
995 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
997 // 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)
998 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
1000 // adds another path
1001 virtual void AddPath( const wxGraphicsPathData
* path
);
1003 // returns the native path
1004 virtual void * GetNativePath() const { return m_path
; }
1006 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
1007 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
1009 // transforms each point of this path by the matrix
1010 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
1012 // gets the bounding box enclosing all points (possibly including control points)
1013 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
1015 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
1017 CGMutablePathRef m_path
;
1020 //-----------------------------------------------------------------------------
1021 // wxMacCoreGraphicsPath implementation
1022 //-----------------------------------------------------------------------------
1024 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1029 m_path
= CGPathCreateMutable();
1032 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1034 CGPathRelease( m_path
);
1037 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1039 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1044 // opens (starts) a new subpath
1045 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1047 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1050 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1052 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1055 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1057 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1060 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1062 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1065 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1067 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1068 CGPathAddRect( m_path
, NULL
, cgRect
);
1071 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1073 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1076 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1077 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1079 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1080 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1083 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1085 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1088 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1090 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1093 // closes the current subpath
1094 void wxMacCoreGraphicsPathData::CloseSubpath()
1096 CGPathCloseSubpath( m_path
);
1099 // gets the last point of the current path, (0,0) if not yet set
1100 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1102 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1107 // transforms each point of this path by the matrix
1108 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1110 CGMutablePathRef p
= CGPathCreateMutable() ;
1111 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1112 CGPathRelease( m_path
);
1116 // gets the bounding box enclosing all points (possibly including control points)
1117 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1119 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1120 *x
= bounds
.origin
.x
;
1121 *y
= bounds
.origin
.y
;
1122 *w
= bounds
.size
.width
;
1123 *h
= bounds
.size
.height
;
1126 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1128 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1135 //-----------------------------------------------------------------------------
1136 // wxMacCoreGraphicsContext declaration
1137 //-----------------------------------------------------------------------------
1139 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1142 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1144 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1146 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1148 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1150 wxMacCoreGraphicsContext();
1152 ~wxMacCoreGraphicsContext();
1156 // returns the size of the graphics context in device coordinates
1157 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1159 virtual void StartPage( wxDouble width
, wxDouble height
);
1161 virtual void EndPage();
1163 virtual void Flush();
1165 // push the current state of the context, ie the transformation matrix on a stack
1166 virtual void PushState();
1168 // pops a stored state from the stack
1169 virtual void PopState();
1171 // clips drawings to the region
1172 virtual void Clip( const wxRegion
®ion
);
1174 // clips drawings to the rect
1175 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1177 // resets the clipping to original extent
1178 virtual void ResetClip();
1180 virtual void * GetNativeContext();
1182 bool SetLogicalFunction( int function
);
1188 virtual void Translate( wxDouble dx
, wxDouble dy
);
1191 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1194 virtual void Rotate( wxDouble angle
);
1196 // concatenates this transform with the current transform of this context
1197 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1199 // sets the transform of this context
1200 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1202 // gets the matrix of this context
1203 virtual wxGraphicsMatrix
GetTransform() const;
1205 // setting the paint
1208 // strokes along a path with the current pen
1209 virtual void StrokePath( const wxGraphicsPath
&path
);
1211 // fills a path with the current brush
1212 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1214 // draws a path by first filling and then stroking
1215 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1217 virtual bool ShouldOffset() const
1220 if ( !m_pen
.IsNull() )
1222 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1223 if ( penwidth
== 0 )
1226 return ( penwidth
% 2 ) == 1;
1232 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1234 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1236 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1237 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1239 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1245 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1247 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1249 void SetNativeContext( CGContextRef cg
);
1251 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1252 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1255 void EnsureIsValid();
1257 CGContextRef m_cgContext
;
1258 WindowRef m_windowRef
;
1259 bool m_releaseContext
;
1260 CGAffineTransform m_windowTransform
;
1264 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1267 //-----------------------------------------------------------------------------
1268 // device context implementation
1270 // more and more of the dc functionality should be implemented by calling
1271 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1272 // also coordinate conversions should be moved to native matrix ops
1273 //-----------------------------------------------------------------------------
1275 // we always stock two context states, one at entry, to be able to preserve the
1276 // state we were called with, the other one after changing to HI Graphics orientation
1277 // (this one is used for getting back clippings etc)
1279 //-----------------------------------------------------------------------------
1280 // wxMacCoreGraphicsContext implementation
1281 //-----------------------------------------------------------------------------
1283 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1285 class wxQuartzOffsetHelper
1288 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1293 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1295 ~wxQuartzOffsetHelper( )
1298 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1305 void wxMacCoreGraphicsContext::Init()
1308 m_releaseContext
= false;
1313 HIRect r
= CGRectMake(0,0,0,0);
1314 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1317 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1320 SetNativeContext(cgcontext
);
1325 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1328 m_windowRef
= window
;
1331 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1334 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1335 int originX
, originY
;
1336 originX
= originY
= 0;
1337 window
->MacWindowToRootWindow( &originX
, &originY
);
1339 Rect bounds
= { 0,0,0,0 };
1342 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1344 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1345 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1346 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1349 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1354 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1357 wxLogDebug(wxT("Illegal Constructor called"));
1360 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1362 SetNativeContext(NULL
);
1365 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1372 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1375 if ( width
!= 0 && height
!= 0)
1376 r
= CGRectMake( 0 , 0 , width
, height
);
1378 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1380 CGContextBeginPage(m_cgContext
, &r
);
1381 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1382 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1385 void wxMacCoreGraphicsContext::EndPage()
1387 CGContextEndPage(m_cgContext
);
1390 void wxMacCoreGraphicsContext::Flush()
1392 CGContextFlush(m_cgContext
);
1395 void wxMacCoreGraphicsContext::EnsureIsValid()
1401 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1405 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1407 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1408 CGContextSaveGState( m_cgContext
);
1409 m_releaseContext
= true;
1410 if ( !HIShapeIsEmpty(m_clipRgn
) )
1412 // the clip region is in device coordinates, so we convert this again to user coordinates
1413 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1414 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1415 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1416 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1417 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1418 CGContextClip( m_cgContext
);
1420 CGContextSaveGState( m_cgContext
);
1424 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1426 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1428 if (m_logicalFunction
== function
)
1433 bool retval
= false;
1435 if ( function
== wxCOPY
)
1438 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1440 else if ( function
== wxINVERT
|| function
== wxXOR
)
1442 // change color to white
1443 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1444 CGContextSetShouldAntialias( m_cgContext
, false );
1449 m_logicalFunction
= function
;
1453 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1457 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1458 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1459 CGContextClip( m_cgContext
);
1464 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1465 // to regions we try at least to have correct translations
1466 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1467 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1468 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1470 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1471 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1472 m_clipRgn
.Set(mutableShape
);
1476 // clips drawings to the rect
1477 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1479 HIRect r
= CGRectMake( x
, y
, w
, h
);
1482 CGContextClipToRect( m_cgContext
, r
);
1486 // the clipping itself must be stored as device coordinates, otherwise
1487 // we cannot apply it back correctly
1488 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1489 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1493 // resets the clipping to original extent
1494 void wxMacCoreGraphicsContext::ResetClip()
1498 // there is no way for clearing the clip, we can only revert to the stored
1499 // state, but then we have to make sure everything else is NOT restored
1500 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1501 CGContextRestoreGState( m_cgContext
);
1502 CGContextSaveGState( m_cgContext
);
1503 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1504 transformNew
= CGAffineTransformInvert( transformNew
) ;
1505 CGContextConcatCTM( m_cgContext
, transformNew
);
1506 CGContextConcatCTM( m_cgContext
, transform
);
1510 HIRect r
= CGRectMake(0,0,0,0);
1511 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1515 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1517 if ( m_pen
.IsNull() )
1522 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1524 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1525 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1526 CGContextStrokePath( m_cgContext
);
1529 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1531 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1533 // when using shading, we cannot draw pen and brush at the same time
1534 // revert to the base implementation of first filling and then stroking
1535 wxGraphicsContext::DrawPath( path
, fillStyle
);
1539 CGPathDrawingMode mode
= kCGPathFill
;
1540 if ( m_brush
.IsNull() )
1542 if ( m_pen
.IsNull() )
1545 mode
= kCGPathStroke
;
1549 if ( m_pen
.IsNull() )
1551 if ( fillStyle
== wxODDEVEN_RULE
)
1552 mode
= kCGPathEOFill
;
1558 if ( fillStyle
== wxODDEVEN_RULE
)
1559 mode
= kCGPathEOFillStroke
;
1561 mode
= kCGPathFillStroke
;
1567 if ( !m_brush
.IsNull() )
1568 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1569 if ( !m_pen
.IsNull() )
1570 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1572 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1574 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1575 CGContextDrawPath( m_cgContext
, mode
);
1578 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1580 if ( m_brush
.IsNull() )
1585 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1587 CGContextSaveGState( m_cgContext
);
1588 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1589 CGContextClip( m_cgContext
);
1590 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1591 CGContextRestoreGState( m_cgContext
);
1595 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1596 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1597 if ( fillStyle
== wxODDEVEN_RULE
)
1598 CGContextEOFillPath( m_cgContext
);
1600 CGContextFillPath( m_cgContext
);
1604 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1606 // we allow either setting or clearing but not replacing
1607 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1611 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1612 CGContextRestoreGState( m_cgContext
);
1613 CGContextRestoreGState( m_cgContext
);
1614 if ( m_releaseContext
)
1617 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1621 CGContextRelease(m_cgContext
);
1627 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1628 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1629 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1630 // for this one operation.
1632 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1636 CGContextRetain(m_cgContext
);
1637 CGContextSaveGState( m_cgContext
);
1638 CGContextSaveGState( m_cgContext
);
1639 m_releaseContext
= false;
1643 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1646 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1648 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1651 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1654 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1656 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1659 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1662 CGContextRotateCTM( m_cgContext
, angle
);
1664 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1667 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1671 CGImageRef image
= (CGImageRef
)( bmp
.CreateCGImage() );
1672 HIRect r
= CGRectMake( x
, y
, w
, h
);
1673 if ( bmp
.GetDepth() == 1 )
1675 // is is a mask, the '1' in the mask tell where to draw the current brush
1676 if ( !m_brush
.IsNull() )
1678 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1680 // TODO clip to mask
1682 CGContextSaveGState( m_cgContext );
1683 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1684 CGContextClip( m_cgContext );
1685 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1686 CGContextRestoreGState( m_cgContext);
1691 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1692 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1698 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1700 CGImageRelease( image
);
1703 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1707 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1708 CGContextSaveGState( m_cgContext
);
1709 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1710 CGContextScaleCTM( m_cgContext
, 1, -1 );
1711 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1712 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1713 CGContextRestoreGState( m_cgContext
);
1716 void wxMacCoreGraphicsContext::PushState()
1720 CGContextSaveGState( m_cgContext
);
1723 void wxMacCoreGraphicsContext::PopState()
1727 CGContextRestoreGState( m_cgContext
);
1730 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1732 if ( m_font
.IsNull() )
1736 #ifdef wxMAC_USE_CORE_TEXT
1737 // TODO core text implementation here
1738 #elif defined(wxMAC_USE_ATSU_TEXT)
1739 DrawText(str
, x
, y
, 0.0);
1740 #elif defined(WXMAC_USE_CG_TEXT)
1741 // TODO core graphics text implementation here
1745 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1747 if ( m_font
.IsNull() )
1751 #ifdef wxMAC_USE_CORE_TEXT
1752 // default implementation takes care of rotation and calls non rotated DrawText afterwards
1753 wxGraphicsContext::DrawText( str
, x
, y
, angle
);
1754 #elif defined(wxMAC_USE_ATSU_TEXT)
1755 OSStatus status
= noErr
;
1756 ATSUTextLayout atsuLayout
;
1757 UniCharCount chars
= str
.length();
1758 UniChar
* ubuf
= NULL
;
1760 #if SIZEOF_WCHAR_T == 4
1761 wxMBConvUTF16 converter
;
1763 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1764 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1765 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1767 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1768 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1769 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1770 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1772 chars
= unicharlen
/ 2;
1775 ubuf
= (UniChar
*) str
.wc_str();
1777 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1778 chars
= wxWcslen( wchar
.data() );
1779 ubuf
= (UniChar
*) wchar
.data();
1783 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1784 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1785 &chars
, &style
, &atsuLayout
);
1787 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1789 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1790 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1792 int iAngle
= int( angle
* RAD2DEG
);
1793 if ( abs(iAngle
) > 0 )
1795 Fixed atsuAngle
= IntToFixed( iAngle
);
1796 ATSUAttributeTag atsuTags
[] =
1798 kATSULineRotationTag
,
1800 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1804 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1808 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1809 atsuTags
, atsuSizes
, atsuValues
);
1813 ATSUAttributeTag atsuTags
[] =
1817 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1819 sizeof( CGContextRef
) ,
1821 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1825 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1826 atsuTags
, atsuSizes
, atsuValues
);
1829 ATSUTextMeasurement textBefore
, textAfter
;
1830 ATSUTextMeasurement ascent
, descent
;
1832 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1833 &textBefore
, &textAfter
, &ascent
, &descent
);
1835 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1838 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1839 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1841 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1842 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1843 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1845 CGContextSaveGState(m_cgContext
);
1846 CGContextTranslateCTM(m_cgContext
, x
, y
);
1847 CGContextScaleCTM(m_cgContext
, 1, -1);
1848 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1849 IntToFixed(0) , IntToFixed(0) );
1851 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1853 CGContextRestoreGState(m_cgContext
);
1855 ::ATSUDisposeTextLayout(atsuLayout
);
1857 #if SIZEOF_WCHAR_T == 4
1860 #elif defined(WXMAC_USE_CG_TEXT)
1861 // default implementation takes care of rotation and calls non rotated DrawText afterwards
1862 wxGraphicsContext::DrawText( str
, x
, y
, angle
);
1866 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1867 wxDouble
*descent
, wxDouble
*externalLeading
) const
1869 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1877 if ( externalLeading
)
1878 *externalLeading
= 0;
1883 #ifdef wxMAC_USE_CORE_TEXT
1884 // TODO core text implementation here
1885 #elif defined(wxMAC_USE_ATSU_TEXT)
1886 OSStatus status
= noErr
;
1888 ATSUTextLayout atsuLayout
;
1889 UniCharCount chars
= str
.length();
1890 UniChar
* ubuf
= NULL
;
1892 #if SIZEOF_WCHAR_T == 4
1893 wxMBConvUTF16 converter
;
1895 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1896 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1897 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1899 const wxWCharBuffer wchar
= str
.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
*) str
.wc_str();
1909 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1910 chars
= wxWcslen( wchar
.data() );
1911 ubuf
= (UniChar
*) wchar
.data();
1915 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1916 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1917 &chars
, &style
, &atsuLayout
);
1919 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1921 ATSUTextMeasurement textBefore
, textAfter
;
1922 ATSUTextMeasurement textAscent
, textDescent
;
1924 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1925 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1928 *height
= FixedToInt(textAscent
+ textDescent
);
1930 *descent
= FixedToInt(textDescent
);
1931 if ( externalLeading
)
1932 *externalLeading
= 0;
1934 *width
= FixedToInt(textAfter
- textBefore
);
1936 ::ATSUDisposeTextLayout(atsuLayout
);
1937 #if SIZEOF_WCHAR_T == 4
1940 #elif defined(WXMAC_USE_CG_TEXT)
1941 // TODO core graphics text implementation here
1945 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1948 widths
.Add(0, text
.length());
1953 #ifdef wxMAC_USE_CORE_TEXT
1954 // TODO core text implementation here
1955 #elif defined(wxMAC_USE_ATSU_TEXT)
1956 ATSUTextLayout atsuLayout
;
1957 UniCharCount chars
= text
.length();
1958 UniChar
* ubuf
= NULL
;
1960 #if SIZEOF_WCHAR_T == 4
1961 wxMBConvUTF16 converter
;
1963 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1964 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1965 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1967 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1968 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1969 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1970 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1972 chars
= unicharlen
/ 2;
1975 ubuf
= (UniChar
*) text
.wc_str();
1977 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1978 chars
= wxWcslen( wchar
.data() );
1979 ubuf
= (UniChar
*) wchar
.data();
1983 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1984 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1985 &chars
, &style
, &atsuLayout
);
1987 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1989 unsigned long actualNumberOfBounds
= 0;
1990 ATSTrapezoid glyphBounds
;
1992 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1994 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1995 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1996 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1999 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
2000 //unsigned char uch = s[i];
2003 ::ATSUDisposeTextLayout(atsuLayout
);
2004 #if SIZEOF_WCHAR_T == 4
2007 #elif defined(WXMAC_USE_CG_TEXT)
2008 // TODO core graphics text implementation here
2012 void * wxMacCoreGraphicsContext::GetNativeContext()
2017 // concatenates this transform with the current transform of this context
2018 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
2021 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2023 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2026 // sets the transform of this context
2027 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
2031 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
2032 transform
= CGAffineTransformInvert( transform
) ;
2033 CGContextConcatCTM( m_cgContext
, transform
);
2034 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2038 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
2042 // gets the matrix of this context
2043 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
2045 wxGraphicsMatrix m
= CreateMatrix();
2046 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
2047 CGContextGetCTM( m_cgContext
));
2055 //-----------------------------------------------------------------------------
2056 // wxMacCoreGraphicsRenderer declaration
2057 //-----------------------------------------------------------------------------
2059 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2062 wxMacCoreGraphicsRenderer() {}
2064 virtual ~wxMacCoreGraphicsRenderer() {}
2068 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2070 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2072 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2074 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2076 virtual wxGraphicsContext
* CreateMeasuringContext();
2080 virtual wxGraphicsPath
CreatePath();
2084 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2085 wxDouble tx
=0.0, wxDouble ty
=0.0);
2088 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2090 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2092 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2093 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2094 const wxColour
&c1
, const wxColour
&c2
) ;
2096 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2097 // with radius r and color cColor
2098 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2099 const wxColour
&oColor
, const wxColour
&cColor
) ;
2102 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2108 //-----------------------------------------------------------------------------
2109 // wxMacCoreGraphicsRenderer implementation
2110 //-----------------------------------------------------------------------------
2112 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2114 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2116 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2118 return &gs_MacCoreGraphicsRenderer
;
2121 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2123 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2126 return new wxMacCoreGraphicsContext(this,
2127 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2131 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2135 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2137 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2141 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2143 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2146 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2148 return new wxMacCoreGraphicsContext(this, window
);
2151 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2153 return new wxMacCoreGraphicsContext(this);
2158 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2161 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2168 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2169 wxDouble tx
, wxDouble ty
)
2172 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2173 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2178 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2180 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2181 return wxNullGraphicsPen
;
2185 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2190 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2192 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2193 return wxNullGraphicsBrush
;
2197 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2202 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2203 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2204 const wxColour
&c1
, const wxColour
&c2
)
2207 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2208 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2213 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2214 // with radius r and color cColor
2215 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2216 const wxColour
&oColor
, const wxColour
&cColor
)
2219 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2220 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2226 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2231 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2235 return wxNullGraphicsFont
;