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 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 #if !defined( __DARWIN__ ) || defined(__MWERKS__)
44 const double M_PI
= 3.14159265358979;
48 static const double RAD2DEG
= 180.0 / M_PI
;
51 // Pen, Brushes and Fonts
55 #pragma mark wxMacCoreGraphicsPattern, ImagePattern, HatchPattern classes
57 OSStatus
wxMacDrawCGImage(
58 CGContextRef inContext
,
59 const HIRect
* inBounds
,
64 CGContextDrawImage(inContext
, *inBounds
, inImage
);
67 return HIViewDrawCGImage( inContext
, inBounds
, inImage
);
71 // CGPattern wrapper class: always allocate on heap, never call destructor
73 class wxMacCoreGraphicsPattern
76 wxMacCoreGraphicsPattern() {}
78 // is guaranteed to be called only with a non-Null CGContextRef
79 virtual void Render( CGContextRef ctxRef
) = 0;
81 operator CGPatternRef() const { return m_patternRef
; }
84 virtual ~wxMacCoreGraphicsPattern()
86 // as this is called only when the m_patternRef is been released;
87 // don't release it again
90 static void _Render( void *info
, CGContextRef ctxRef
)
92 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
94 self
->Render( ctxRef
);
97 static void _Dispose( void *info
)
99 wxMacCoreGraphicsPattern
* self
= (wxMacCoreGraphicsPattern
*) info
;
103 CGPatternRef m_patternRef
;
105 static const CGPatternCallbacks ms_Callbacks
;
108 const CGPatternCallbacks
wxMacCoreGraphicsPattern::ms_Callbacks
= { 0, &wxMacCoreGraphicsPattern::_Render
, &wxMacCoreGraphicsPattern::_Dispose
};
110 class ImagePattern
: public wxMacCoreGraphicsPattern
113 ImagePattern( const wxBitmap
* bmp
, const CGAffineTransform
& transform
)
115 wxASSERT( bmp
&& bmp
->Ok() );
117 Init( (CGImageRef
) bmp
->CreateCGImage() , transform
);
120 // ImagePattern takes ownership of CGImageRef passed in
121 ImagePattern( CGImageRef image
, const CGAffineTransform
& transform
)
126 Init( image
, transform
);
129 virtual void Render( CGContextRef ctxRef
)
132 wxMacDrawCGImage( ctxRef
, &m_imageBounds
, m_image
);
136 void Init( CGImageRef image
, const CGAffineTransform
& transform
)
141 m_imageBounds
= CGRectMake( 0.0, 0.0, (CGFloat
)CGImageGetWidth( m_image
), (CGFloat
)CGImageGetHeight( m_image
) );
142 m_patternRef
= CGPatternCreate(
143 this , m_imageBounds
, transform
,
144 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
145 kCGPatternTilingNoDistortion
, true , &wxMacCoreGraphicsPattern::ms_Callbacks
);
149 virtual ~ImagePattern()
152 CGImageRelease( m_image
);
156 CGRect m_imageBounds
;
159 class HatchPattern
: public wxMacCoreGraphicsPattern
162 HatchPattern( int hatchstyle
, const CGAffineTransform
& transform
)
164 m_hatch
= hatchstyle
;
165 m_imageBounds
= CGRectMake( 0.0, 0.0, 8.0 , 8.0 );
166 m_patternRef
= CGPatternCreate(
167 this , m_imageBounds
, transform
,
168 m_imageBounds
.size
.width
, m_imageBounds
.size
.height
,
169 kCGPatternTilingNoDistortion
, false , &wxMacCoreGraphicsPattern::ms_Callbacks
);
172 void StrokeLineSegments( CGContextRef ctxRef
, const CGPoint pts
[] , size_t count
)
174 CGContextStrokeLineSegments( ctxRef
, pts
, count
);
177 virtual void Render( CGContextRef ctxRef
)
181 case wxBDIAGONAL_HATCH
:
185 { 8.0 , 0.0 } , { 0.0 , 8.0 }
187 StrokeLineSegments( ctxRef
, pts
, 2 );
191 case wxCROSSDIAG_HATCH
:
195 { 0.0 , 0.0 } , { 8.0 , 8.0 } ,
196 { 8.0 , 0.0 } , { 0.0 , 8.0 }
198 StrokeLineSegments( ctxRef
, pts
, 4 );
202 case wxFDIAGONAL_HATCH
:
206 { 0.0 , 0.0 } , { 8.0 , 8.0 }
208 StrokeLineSegments( ctxRef
, pts
, 2 );
216 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
217 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
219 StrokeLineSegments( ctxRef
, pts
, 4 );
223 case wxHORIZONTAL_HATCH
:
227 { 0.0 , 4.0 } , { 8.0 , 4.0 } ,
229 StrokeLineSegments( ctxRef
, pts
, 2 );
233 case wxVERTICAL_HATCH
:
237 { 4.0 , 0.0 } , { 4.0 , 8.0 } ,
239 StrokeLineSegments( ctxRef
, pts
, 2 );
249 virtual ~HatchPattern() {}
251 CGRect m_imageBounds
;
255 class wxMacCoreGraphicsPenData
: public wxGraphicsObjectRefData
258 wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
);
259 ~wxMacCoreGraphicsPenData();
262 virtual void Apply( wxGraphicsContext
* context
);
263 virtual wxDouble
GetWidth() { return m_width
; }
267 wxMacCFRefHolder
<CGColorRef
> m_color
;
268 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
274 const CGFloat
*m_lengths
;
275 CGFloat
*m_userLengths
;
279 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
280 CGFloat
* m_patternColorComponents
;
283 wxMacCoreGraphicsPenData::wxMacCoreGraphicsPenData( wxGraphicsRenderer
* renderer
, const wxPen
&pen
) :
284 wxGraphicsObjectRefData( renderer
)
288 CGFloat components
[4] = { pen
.GetColour().Red() / 255.0 , pen
.GetColour().Green() / 255.0 ,
289 pen
.GetColour().Blue() / 255.0 , pen
.GetColour().Alpha() / 255.0 } ;
290 m_color
.Set( CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ) ;
292 // TODO: * m_dc->m_scaleX
293 m_width
= pen
.GetWidth();
297 switch ( pen
.GetCap() )
300 m_cap
= kCGLineCapRound
;
303 case wxCAP_PROJECTING
:
304 m_cap
= kCGLineCapSquare
;
308 m_cap
= kCGLineCapButt
;
312 m_cap
= kCGLineCapButt
;
316 switch ( pen
.GetJoin() )
319 m_join
= kCGLineJoinBevel
;
323 m_join
= kCGLineJoinMiter
;
327 m_join
= kCGLineJoinRound
;
331 m_join
= kCGLineJoinMiter
;
335 const CGFloat dashUnit
= m_width
< 1.0 ? 1.0 : m_width
;
337 const CGFloat dotted
[] = { dashUnit
, dashUnit
+ 2.0 };
338 static const CGFloat short_dashed
[] = { 9.0 , 6.0 };
339 static const CGFloat dashed
[] = { 19.0 , 9.0 };
340 static const CGFloat dotted_dashed
[] = { 9.0 , 6.0 , 3.0 , 3.0 };
342 switch ( pen
.GetStyle() )
348 m_count
= WXSIZEOF(dotted
);
349 m_userLengths
= new CGFloat
[ m_count
] ;
350 memcpy( m_userLengths
, dotted
, sizeof(dotted
) );
351 m_lengths
= m_userLengths
;
355 m_count
= WXSIZEOF(dashed
);
360 m_count
= WXSIZEOF(short_dashed
);
361 m_lengths
= short_dashed
;
365 m_count
= WXSIZEOF(dotted_dashed
);
366 m_lengths
= dotted_dashed
;
371 m_count
= pen
.GetDashes( &dashes
);
372 if ((dashes
!= NULL
) && (m_count
> 0))
374 m_userLengths
= new CGFloat
[m_count
];
375 for ( int i
= 0; i
< m_count
; ++i
)
377 m_userLengths
[i
] = dashes
[i
] * dashUnit
;
379 if ( i
% 2 == 1 && m_userLengths
[i
] < dashUnit
+ 2.0 )
380 m_userLengths
[i
] = dashUnit
+ 2.0;
381 else if ( i
% 2 == 0 && m_userLengths
[i
] < dashUnit
)
382 m_userLengths
[i
] = dashUnit
;
385 m_lengths
= m_userLengths
;
390 wxBitmap
* bmp
= pen
.GetStipple();
391 if ( bmp
&& bmp
->Ok() )
393 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
394 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
395 m_patternColorComponents
= new CGFloat
[1] ;
396 m_patternColorComponents
[0] = 1.0;
405 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
406 m_pattern
.Set( *( new HatchPattern( pen
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
407 m_patternColorComponents
= new CGFloat
[4] ;
408 m_patternColorComponents
[0] = pen
.GetColour().Red() / 255.0;
409 m_patternColorComponents
[1] = pen
.GetColour().Green() / 255.0;
410 m_patternColorComponents
[2] = pen
.GetColour().Blue() / 255.0;
411 m_patternColorComponents
[3] = pen
.GetColour().Alpha() / 255.0;
415 if ((m_lengths
!= NULL
) && (m_count
> 0))
417 // force the line cap, otherwise we get artifacts (overlaps) and just solid lines
418 m_cap
= kCGLineCapButt
;
422 wxMacCoreGraphicsPenData::~wxMacCoreGraphicsPenData()
424 delete[] m_userLengths
;
425 delete[] m_patternColorComponents
;
428 void wxMacCoreGraphicsPenData::Init()
431 m_userLengths
= NULL
;
434 m_patternColorComponents
= NULL
;
438 void wxMacCoreGraphicsPenData::Apply( wxGraphicsContext
* context
)
440 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
441 CGContextSetLineWidth( cg
, m_width
);
442 CGContextSetLineJoin( cg
, m_join
);
444 CGContextSetLineDash( cg
, 0 , m_lengths
, m_count
);
445 CGContextSetLineCap( cg
, m_cap
);
449 CGAffineTransform matrix
= CGContextGetCTM( cg
);
450 CGContextSetPatternPhase( cg
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
451 CGContextSetStrokeColorSpace( cg
, m_colorSpace
);
452 CGContextSetStrokePattern( cg
, m_pattern
, m_patternColorComponents
);
456 if ( context
->GetLogicalFunction() == wxINVERT
|| context
->GetLogicalFunction() == wxXOR
)
458 CGContextSetRGBStrokeColor( cg
, 1.0, 1.0 , 1.0, 1.0 );
461 CGContextSetStrokeColorWithColor( cg
, m_color
);
469 static const char *gs_stripedback_xpm
[] = {
470 /* columns rows colors chars-per-pixel */
481 wxBitmap
gs_stripedback_bmp( wxImage( (const char* const* ) gs_stripedback_xpm
), -1 ) ;
483 // make sure we all use one class for all conversions from wx to native colour
485 class wxMacCoreGraphicsColour
488 wxMacCoreGraphicsColour();
489 wxMacCoreGraphicsColour(const wxBrush
&brush
);
490 ~wxMacCoreGraphicsColour();
492 void Apply( CGContextRef cgContext
);
495 wxMacCFRefHolder
<CGColorRef
> m_color
;
496 wxMacCFRefHolder
<CGColorSpaceRef
> m_colorSpace
;
499 wxMacCFRefHolder
<CGPatternRef
> m_pattern
;
500 CGFloat
* m_patternColorComponents
;
503 wxMacCoreGraphicsColour::~wxMacCoreGraphicsColour()
505 delete[] m_patternColorComponents
;
508 void wxMacCoreGraphicsColour::Init()
511 m_patternColorComponents
= NULL
;
514 void wxMacCoreGraphicsColour::Apply( CGContextRef cgContext
)
518 CGAffineTransform matrix
= CGContextGetCTM( cgContext
);
519 CGContextSetPatternPhase( cgContext
, CGSizeMake(matrix
.tx
, matrix
.ty
) );
520 CGContextSetFillColorSpace( cgContext
, m_colorSpace
);
521 CGContextSetFillPattern( cgContext
, m_pattern
, m_patternColorComponents
);
525 CGContextSetFillColorWithColor( cgContext
, m_color
);
529 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour()
534 wxMacCoreGraphicsColour::wxMacCoreGraphicsColour( const wxBrush
&brush
)
537 if ( brush
.GetStyle() == wxSOLID
)
539 m_color
.Set( brush
.GetColour().CreateCGColor() );
541 else if ( brush
.IsHatch() )
544 m_colorSpace
.Set( CGColorSpaceCreatePattern( wxMacGetGenericRGBColorSpace() ) );
545 m_pattern
.Set( *( new HatchPattern( brush
.GetStyle() , CGAffineTransformMakeScale( 1,-1 ) ) ) );
547 m_patternColorComponents
= new CGFloat
[4] ;
548 m_patternColorComponents
[0] = brush
.GetColour().Red() / 255.0;
549 m_patternColorComponents
[1] = brush
.GetColour().Green() / 255.0;
550 m_patternColorComponents
[2] = brush
.GetColour().Blue() / 255.0;
551 m_patternColorComponents
[3] = brush
.GetColour().Alpha() / 255.0;
555 // now brush is a bitmap
556 wxBitmap
* bmp
= brush
.GetStipple();
557 if ( bmp
&& bmp
->Ok() )
560 m_patternColorComponents
= new CGFloat
[1] ;
561 m_patternColorComponents
[0] = 1.0;
562 m_colorSpace
.Set( CGColorSpaceCreatePattern( NULL
) );
563 m_pattern
.Set( *( new ImagePattern( bmp
, CGAffineTransformMakeScale( 1,-1 ) ) ) );
568 class wxMacCoreGraphicsBrushData
: public wxGraphicsObjectRefData
571 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
);
572 wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
, const wxBrush
&brush
);
573 ~wxMacCoreGraphicsBrushData ();
575 virtual void Apply( wxGraphicsContext
* context
);
576 void CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
577 const wxColour
&c1
, const wxColour
&c2
);
578 void CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
579 const wxColour
&oColor
, const wxColour
&cColor
);
581 virtual bool IsShading() { return m_isShading
; }
582 CGShadingRef
GetShading() { return m_shading
; }
584 CGFunctionRef
CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
);
585 static void CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
);
588 wxMacCoreGraphicsColour m_cgColor
;
591 CGFunctionRef m_gradientFunction
;
592 CGShadingRef m_shading
;
593 CGFloat
*m_gradientComponents
;
596 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData( wxGraphicsRenderer
* renderer
) : wxGraphicsObjectRefData( renderer
)
601 void wxMacCoreGraphicsBrushData::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
602 const wxColour
&c1
, const wxColour
&c2
)
604 m_gradientFunction
= CreateGradientFunction( c1
, c2
);
605 m_shading
= CGShadingCreateAxial( wxMacGetGenericRGBColorSpace(), CGPointMake(x1
,y1
), CGPointMake(x2
,y2
), m_gradientFunction
, true, true ) ;
609 void wxMacCoreGraphicsBrushData::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
610 const wxColour
&oColor
, const wxColour
&cColor
)
612 m_gradientFunction
= CreateGradientFunction( oColor
, cColor
);
613 m_shading
= CGShadingCreateRadial( wxMacGetGenericRGBColorSpace(), CGPointMake(xo
,yo
), 0, CGPointMake(xc
,yc
), radius
, m_gradientFunction
, true, true ) ;
617 wxMacCoreGraphicsBrushData::wxMacCoreGraphicsBrushData(wxGraphicsRenderer
* renderer
, const wxBrush
&brush
) : wxGraphicsObjectRefData( renderer
),
624 wxMacCoreGraphicsBrushData::~wxMacCoreGraphicsBrushData()
627 CGShadingRelease(m_shading
);
629 if( m_gradientFunction
)
630 CGFunctionRelease(m_gradientFunction
);
632 delete[] m_gradientComponents
;
635 void wxMacCoreGraphicsBrushData::Init()
637 m_gradientFunction
= NULL
;
639 m_gradientComponents
= NULL
;
643 void wxMacCoreGraphicsBrushData::Apply( wxGraphicsContext
* context
)
645 CGContextRef cg
= (CGContextRef
) context
->GetNativeContext();
649 // nothing to set as shades are processed by clipping using the path and filling
653 m_cgColor
.Apply( cg
);
657 void wxMacCoreGraphicsBrushData::CalculateShadingValues (void *info
, const CGFloat
*in
, CGFloat
*out
)
659 CGFloat
* colors
= (CGFloat
*) info
;
661 for( int i
= 0 ; i
< 4 ; ++i
)
663 out
[i
] = colors
[i
] + ( colors
[4+i
] - colors
[i
] ) * f
;
667 CGFunctionRef
wxMacCoreGraphicsBrushData::CreateGradientFunction( const wxColour
& c1
, const wxColour
& c2
)
669 static const CGFunctionCallbacks callbacks
= { 0, &CalculateShadingValues
, NULL
};
670 static const CGFloat input_value_range
[2] = { 0, 1 };
671 static const CGFloat output_value_ranges
[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };
672 m_gradientComponents
= new CGFloat
[8] ;
673 m_gradientComponents
[0] = c1
.Red() / 255.0;
674 m_gradientComponents
[1] = c1
.Green() / 255.0;
675 m_gradientComponents
[2] = c1
.Blue() / 255.0;
676 m_gradientComponents
[3] = c1
.Alpha() / 255.0;
677 m_gradientComponents
[4] = c2
.Red() / 255.0;
678 m_gradientComponents
[5] = c2
.Green() / 255.0;
679 m_gradientComponents
[6] = c2
.Blue() / 255.0;
680 m_gradientComponents
[7] = c2
.Alpha() / 255.0;
682 return CGFunctionCreate ( m_gradientComponents
, 1,
693 class wxMacCoreGraphicsFontData
: public wxGraphicsObjectRefData
696 wxMacCoreGraphicsFontData( wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
);
697 ~wxMacCoreGraphicsFontData();
699 virtual ATSUStyle
GetATSUStyle() { return m_macATSUIStyle
; }
701 ATSUStyle m_macATSUIStyle
;
704 wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer
* renderer
, const wxFont
&font
, const wxColour
& col
) : wxGraphicsObjectRefData( renderer
)
706 m_macATSUIStyle
= NULL
;
708 #ifdef wxMAC_USE_CORE_TEXT
709 #elif defined(wxMAC_USE_ATSU_TEXT)
712 status
= ATSUCreateAndCopyStyle( (ATSUStyle
) font
.MacGetATSUStyle() , &m_macATSUIStyle
);
714 wxASSERT_MSG( status
== noErr
, wxT("couldn't create ATSU style") );
716 // we need the scale here ...
718 Fixed atsuSize
= IntToFixed( int( 1 * font
.MacGetFontSize()) );
720 col
.GetRGBColor( &atsuColor
);
721 ATSUAttributeTag atsuTags
[] =
726 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
731 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
737 status
= ::ATSUSetAttributes(
738 m_macATSUIStyle
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
) ,
739 atsuTags
, atsuSizes
, atsuValues
);
741 wxASSERT_MSG( status
== noErr
, wxT("couldn't modify ATSU style") );
742 #elif defined(WXMAC_USE_CG_TEXT)
746 wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData()
748 #ifdef wxMAC_USE_CORE_TEXT
749 #elif defined(wxMAC_USE_ATSU_TEXT)
750 if ( m_macATSUIStyle
)
752 ::ATSUDisposeStyle((ATSUStyle
)m_macATSUIStyle
);
753 m_macATSUIStyle
= NULL
;
755 #elif defined(WXMAC_USE_CG_TEXT)
763 //-----------------------------------------------------------------------------
764 // wxMacCoreGraphicsMatrix declaration
765 //-----------------------------------------------------------------------------
767 class WXDLLIMPEXP_CORE wxMacCoreGraphicsMatrixData
: public wxGraphicsMatrixData
770 wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) ;
772 virtual ~wxMacCoreGraphicsMatrixData() ;
774 virtual wxGraphicsObjectRefData
*Clone() const ;
776 // concatenates the matrix
777 virtual void Concat( const wxGraphicsMatrixData
*t
);
779 // sets the matrix to the respective values
780 virtual void Set(wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
781 wxDouble tx
=0.0, wxDouble ty
=0.0);
783 // gets the component valuess of the matrix
784 virtual void Get(wxDouble
* a
=NULL
, wxDouble
* b
=NULL
, wxDouble
* c
=NULL
,
785 wxDouble
* d
=NULL
, wxDouble
* tx
=NULL
, wxDouble
* ty
=NULL
) const;
787 // makes this the inverse matrix
788 virtual void Invert();
790 // returns true if the elements of the transformation matrix are equal ?
791 virtual bool IsEqual( const wxGraphicsMatrixData
* t
) const ;
793 // return true if this is the identity matrix
794 virtual bool IsIdentity() const;
800 // add the translation to this matrix
801 virtual void Translate( wxDouble dx
, wxDouble dy
);
803 // add the scale to this matrix
804 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
806 // add the rotation to this matrix (radians)
807 virtual void Rotate( wxDouble angle
);
810 // apply the transforms
813 // applies that matrix to the point
814 virtual void TransformPoint( wxDouble
*x
, wxDouble
*y
) const;
816 // applies the matrix except for translations
817 virtual void TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const;
819 // returns the native representation
820 virtual void * GetNativeMatrix() const;
823 CGAffineTransform m_matrix
;
826 //-----------------------------------------------------------------------------
827 // wxMacCoreGraphicsMatrix implementation
828 //-----------------------------------------------------------------------------
830 wxMacCoreGraphicsMatrixData::wxMacCoreGraphicsMatrixData(wxGraphicsRenderer
* renderer
) : wxGraphicsMatrixData(renderer
)
834 wxMacCoreGraphicsMatrixData::~wxMacCoreGraphicsMatrixData()
838 wxGraphicsObjectRefData
*wxMacCoreGraphicsMatrixData::Clone() const
840 wxMacCoreGraphicsMatrixData
* m
= new wxMacCoreGraphicsMatrixData(GetRenderer()) ;
841 m
->m_matrix
= m_matrix
;
845 // concatenates the matrix
846 void wxMacCoreGraphicsMatrixData::Concat( const wxGraphicsMatrixData
*t
)
848 m_matrix
= CGAffineTransformConcat(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()) );
851 // sets the matrix to the respective values
852 void wxMacCoreGraphicsMatrixData::Set(wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
853 wxDouble tx
, wxDouble ty
)
855 m_matrix
= CGAffineTransformMake(a
,b
,c
,d
,tx
,ty
);
858 // gets the component valuess of the matrix
859 void wxMacCoreGraphicsMatrixData::Get(wxDouble
* a
, wxDouble
* b
, wxDouble
* c
,
860 wxDouble
* d
, wxDouble
* tx
, wxDouble
* ty
) const
862 if (a
) *a
= m_matrix
.a
;
863 if (b
) *b
= m_matrix
.b
;
864 if (c
) *c
= m_matrix
.c
;
865 if (d
) *d
= m_matrix
.d
;
866 if (tx
) *tx
= m_matrix
.tx
;
867 if (ty
) *ty
= m_matrix
.ty
;
870 // makes this the inverse matrix
871 void wxMacCoreGraphicsMatrixData::Invert()
873 m_matrix
= CGAffineTransformInvert( m_matrix
);
876 // returns true if the elements of the transformation matrix are equal ?
877 bool wxMacCoreGraphicsMatrixData::IsEqual( const wxGraphicsMatrixData
* t
) const
879 return CGAffineTransformEqualToTransform(m_matrix
, *((CGAffineTransform
*) t
->GetNativeMatrix()));
882 // return true if this is the identity matrix
883 bool wxMacCoreGraphicsMatrixData::IsIdentity() const
885 return ( m_matrix
.a
== 1 && m_matrix
.d
== 1 &&
886 m_matrix
.b
== 0 && m_matrix
.d
== 0 && m_matrix
.tx
== 0 && m_matrix
.ty
== 0);
893 // add the translation to this matrix
894 void wxMacCoreGraphicsMatrixData::Translate( wxDouble dx
, wxDouble dy
)
896 m_matrix
= CGAffineTransformTranslate( m_matrix
, dx
, dy
);
899 // add the scale to this matrix
900 void wxMacCoreGraphicsMatrixData::Scale( wxDouble xScale
, wxDouble yScale
)
902 m_matrix
= CGAffineTransformScale( m_matrix
, xScale
, yScale
);
905 // add the rotation to this matrix (radians)
906 void wxMacCoreGraphicsMatrixData::Rotate( wxDouble angle
)
908 m_matrix
= CGAffineTransformRotate( m_matrix
, angle
);
912 // apply the transforms
915 // applies that matrix to the point
916 void wxMacCoreGraphicsMatrixData::TransformPoint( wxDouble
*x
, wxDouble
*y
) const
918 CGPoint pt
= CGPointApplyAffineTransform( CGPointMake(*x
,*y
), m_matrix
);
924 // applies the matrix except for translations
925 void wxMacCoreGraphicsMatrixData::TransformDistance( wxDouble
*dx
, wxDouble
*dy
) const
927 CGSize sz
= CGSizeApplyAffineTransform( CGSizeMake(*dx
,*dy
) , m_matrix
);
932 // returns the native representation
933 void * wxMacCoreGraphicsMatrixData::GetNativeMatrix() const
935 return (void*) &m_matrix
;
942 //-----------------------------------------------------------------------------
943 // wxMacCoreGraphicsPath declaration
944 //-----------------------------------------------------------------------------
946 class WXDLLEXPORT wxMacCoreGraphicsPathData
: public wxGraphicsPathData
949 wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
= NULL
);
951 ~wxMacCoreGraphicsPathData();
953 virtual wxGraphicsObjectRefData
*Clone() const;
955 // begins a new subpath at (x,y)
956 virtual void MoveToPoint( wxDouble x
, wxDouble y
);
958 // adds a straight line from the current point to (x,y)
959 virtual void AddLineToPoint( wxDouble x
, wxDouble y
);
961 // adds a cubic Bezier curve from the current point, using two control points and an end point
962 virtual void AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
);
964 // closes the current sub-path
965 virtual void CloseSubpath();
967 // gets the last point of the current path, (0,0) if not yet set
968 virtual void GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const;
970 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
971 virtual void AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
);
974 // These are convenience functions which - if not available natively will be assembled
975 // using the primitives from above
978 // adds a quadratic Bezier curve from the current point, using a control point and an end point
979 virtual void AddQuadCurveToPoint( wxDouble cx
, wxDouble cy
, wxDouble x
, wxDouble y
);
981 // appends a rectangle as a new closed subpath
982 virtual void AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
984 // appends an ellipsis as a new closed subpath fitting the passed rectangle
985 virtual void AddCircle( wxDouble x
, wxDouble y
, wxDouble r
);
987 // 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)
988 virtual void AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
);
991 virtual void AddPath( const wxGraphicsPathData
* path
);
993 // returns the native path
994 virtual void * GetNativePath() const { return m_path
; }
996 // give the native path returned by GetNativePath() back (there might be some deallocations necessary)
997 virtual void UnGetNativePath(void *WXUNUSED(p
)) const {}
999 // transforms each point of this path by the matrix
1000 virtual void Transform( const wxGraphicsMatrixData
* matrix
);
1002 // gets the bounding box enclosing all points (possibly including control points)
1003 virtual void GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*y
) const;
1005 virtual bool Contains( wxDouble x
, wxDouble y
, int fillStyle
= wxODDEVEN_RULE
) const;
1007 CGMutablePathRef m_path
;
1010 //-----------------------------------------------------------------------------
1011 // wxMacCoreGraphicsPath implementation
1012 //-----------------------------------------------------------------------------
1014 wxMacCoreGraphicsPathData::wxMacCoreGraphicsPathData( wxGraphicsRenderer
* renderer
, CGMutablePathRef path
) : wxGraphicsPathData(renderer
)
1019 m_path
= CGPathCreateMutable();
1022 wxMacCoreGraphicsPathData::~wxMacCoreGraphicsPathData()
1024 CGPathRelease( m_path
);
1027 wxGraphicsObjectRefData
* wxMacCoreGraphicsPathData::Clone() const
1029 wxMacCoreGraphicsPathData
* clone
= new wxMacCoreGraphicsPathData(GetRenderer(),CGPathCreateMutableCopy(m_path
));
1034 // opens (starts) a new subpath
1035 void wxMacCoreGraphicsPathData::MoveToPoint( wxDouble x1
, wxDouble y1
)
1037 CGPathMoveToPoint( m_path
, NULL
, x1
, y1
);
1040 void wxMacCoreGraphicsPathData::AddLineToPoint( wxDouble x1
, wxDouble y1
)
1042 CGPathAddLineToPoint( m_path
, NULL
, x1
, y1
);
1045 void wxMacCoreGraphicsPathData::AddCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble cx2
, wxDouble cy2
, wxDouble x
, wxDouble y
)
1047 CGPathAddCurveToPoint( m_path
, NULL
, cx1
, cy1
, cx2
, cy2
, x
, y
);
1050 void wxMacCoreGraphicsPathData::AddQuadCurveToPoint( wxDouble cx1
, wxDouble cy1
, wxDouble x
, wxDouble y
)
1052 CGPathAddQuadCurveToPoint( m_path
, NULL
, cx1
, cy1
, x
, y
);
1055 void wxMacCoreGraphicsPathData::AddRectangle( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1057 CGRect cgRect
= { { x
, y
} , { w
, h
} };
1058 CGPathAddRect( m_path
, NULL
, cgRect
);
1061 void wxMacCoreGraphicsPathData::AddCircle( wxDouble x
, wxDouble y
, wxDouble r
)
1063 CGPathAddArc( m_path
, NULL
, x
, y
, r
, 0.0 , 2 * M_PI
, true );
1066 // adds an arc of a circle centering at (x,y) with radius (r) from startAngle to endAngle
1067 void wxMacCoreGraphicsPathData::AddArc( wxDouble x
, wxDouble y
, wxDouble r
, wxDouble startAngle
, wxDouble endAngle
, bool clockwise
)
1069 // inverse direction as we the 'normal' state is a y axis pointing down, ie mirrored to the standard core graphics setup
1070 CGPathAddArc( m_path
, NULL
, x
, y
, r
, startAngle
, endAngle
, !clockwise
);
1073 void wxMacCoreGraphicsPathData::AddArcToPoint( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
, wxDouble r
)
1075 CGPathAddArcToPoint( m_path
, NULL
, x1
, y1
, x2
, y2
, r
);
1078 void wxMacCoreGraphicsPathData::AddPath( const wxGraphicsPathData
* path
)
1080 CGPathAddPath( m_path
, NULL
, (CGPathRef
) path
->GetNativePath() );
1083 // closes the current subpath
1084 void wxMacCoreGraphicsPathData::CloseSubpath()
1086 CGPathCloseSubpath( m_path
);
1089 // gets the last point of the current path, (0,0) if not yet set
1090 void wxMacCoreGraphicsPathData::GetCurrentPoint( wxDouble
* x
, wxDouble
* y
) const
1092 CGPoint p
= CGPathGetCurrentPoint( m_path
);
1097 // transforms each point of this path by the matrix
1098 void wxMacCoreGraphicsPathData::Transform( const wxGraphicsMatrixData
* matrix
)
1100 CGMutablePathRef p
= CGPathCreateMutable() ;
1101 CGPathAddPath( p
, (CGAffineTransform
*) matrix
->GetNativeMatrix() , m_path
);
1102 CGPathRelease( m_path
);
1106 // gets the bounding box enclosing all points (possibly including control points)
1107 void wxMacCoreGraphicsPathData::GetBox(wxDouble
*x
, wxDouble
*y
, wxDouble
*w
, wxDouble
*h
) const
1109 CGRect bounds
= CGPathGetBoundingBox( m_path
) ;
1110 *x
= bounds
.origin
.x
;
1111 *y
= bounds
.origin
.y
;
1112 *w
= bounds
.size
.width
;
1113 *h
= bounds
.size
.height
;
1116 bool wxMacCoreGraphicsPathData::Contains( wxDouble x
, wxDouble y
, int fillStyle
) const
1118 return CGPathContainsPoint( m_path
, NULL
, CGPointMake(x
,y
), fillStyle
== wxODDEVEN_RULE
);
1125 //-----------------------------------------------------------------------------
1126 // wxMacCoreGraphicsContext declaration
1127 //-----------------------------------------------------------------------------
1129 class WXDLLEXPORT wxMacCoreGraphicsContext
: public wxGraphicsContext
1132 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
= 0, wxDouble height
= 0 );
1134 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
);
1136 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
);
1138 wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
);
1140 wxMacCoreGraphicsContext();
1142 ~wxMacCoreGraphicsContext();
1146 // returns the size of the graphics context in device coordinates
1147 virtual void GetSize( wxDouble
* width
, wxDouble
* height
);
1149 virtual void StartPage( wxDouble width
, wxDouble height
);
1151 virtual void EndPage();
1153 virtual void Flush();
1155 // push the current state of the context, ie the transformation matrix on a stack
1156 virtual void PushState();
1158 // pops a stored state from the stack
1159 virtual void PopState();
1161 // clips drawings to the region
1162 virtual void Clip( const wxRegion
®ion
);
1164 // clips drawings to the rect
1165 virtual void Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1167 // resets the clipping to original extent
1168 virtual void ResetClip();
1170 virtual void * GetNativeContext();
1172 bool SetLogicalFunction( int function
);
1178 virtual void Translate( wxDouble dx
, wxDouble dy
);
1181 virtual void Scale( wxDouble xScale
, wxDouble yScale
);
1184 virtual void Rotate( wxDouble angle
);
1186 // concatenates this transform with the current transform of this context
1187 virtual void ConcatTransform( const wxGraphicsMatrix
& matrix
);
1189 // sets the transform of this context
1190 virtual void SetTransform( const wxGraphicsMatrix
& matrix
);
1192 // gets the matrix of this context
1193 virtual wxGraphicsMatrix
GetTransform() const;
1195 // setting the paint
1198 // strokes along a path with the current pen
1199 virtual void StrokePath( const wxGraphicsPath
&path
);
1201 // fills a path with the current brush
1202 virtual void FillPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1204 // draws a path by first filling and then stroking
1205 virtual void DrawPath( const wxGraphicsPath
&path
, int fillStyle
= wxODDEVEN_RULE
);
1207 virtual bool ShouldOffset() const
1210 if ( !m_pen
.IsNull() )
1212 penwidth
= (int)((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->GetWidth();
1213 if ( penwidth
== 0 )
1216 return ( penwidth
% 2 ) == 1;
1222 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
);
1224 virtual void DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
);
1226 virtual void GetTextExtent( const wxString
&text
, wxDouble
*width
, wxDouble
*height
,
1227 wxDouble
*descent
, wxDouble
*externalLeading
) const;
1229 virtual void GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const;
1235 virtual void DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1237 virtual void DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
);
1239 void SetNativeContext( CGContextRef cg
);
1241 DECLARE_NO_COPY_CLASS(wxMacCoreGraphicsContext
)
1242 DECLARE_DYNAMIC_CLASS(wxMacCoreGraphicsContext
)
1245 void EnsureIsValid();
1247 CGContextRef m_cgContext
;
1248 WindowRef m_windowRef
;
1249 bool m_releaseContext
;
1250 CGAffineTransform m_windowTransform
;
1254 wxMacCFRefHolder
<HIShapeRef
> m_clipRgn
;
1257 //-----------------------------------------------------------------------------
1258 // device context implementation
1260 // more and more of the dc functionality should be implemented by calling
1261 // the appropricate wxMacCoreGraphicsContext, but we will have to do that step by step
1262 // also coordinate conversions should be moved to native matrix ops
1263 //-----------------------------------------------------------------------------
1265 // we always stock two context states, one at entry, to be able to preserve the
1266 // state we were called with, the other one after changing to HI Graphics orientation
1267 // (this one is used for getting back clippings etc)
1269 //-----------------------------------------------------------------------------
1270 // wxMacCoreGraphicsContext implementation
1271 //-----------------------------------------------------------------------------
1273 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsContext
, wxGraphicsContext
)
1275 class wxQuartzOffsetHelper
1278 wxQuartzOffsetHelper( CGContextRef cg
, bool offset
)
1283 CGContextTranslateCTM( m_cg
, 0.5, 0.5 );
1285 ~wxQuartzOffsetHelper( )
1288 CGContextTranslateCTM( m_cg
, -0.5, -0.5 );
1295 void wxMacCoreGraphicsContext::Init()
1298 m_releaseContext
= false;
1303 HIRect r
= CGRectMake(0,0,0,0);
1304 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1307 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, CGContextRef cgcontext
, wxDouble width
, wxDouble height
) : wxGraphicsContext(renderer
)
1310 SetNativeContext(cgcontext
);
1315 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, WindowRef window
): wxGraphicsContext(renderer
)
1318 m_windowRef
= window
;
1321 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer
* renderer
, wxWindow
* window
): wxGraphicsContext(renderer
)
1324 m_windowRef
= (WindowRef
) window
->MacGetTopLevelWindowRef();
1325 int originX
, originY
;
1326 originX
= originY
= 0;
1327 window
->MacWindowToRootWindow( &originX
, &originY
);
1329 Rect bounds
= { 0,0,0,0 };
1332 GetWindowBounds( m_windowRef
, kWindowContentRgn
, &bounds
);
1334 m_windowTransform
= CGAffineTransformMakeTranslation( 0 , bounds
.bottom
- bounds
.top
);
1335 m_windowTransform
= CGAffineTransformScale( m_windowTransform
, 1 , -1 );
1336 m_windowTransform
= CGAffineTransformTranslate( m_windowTransform
, originX
, originY
) ;
1339 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext(wxGraphicsRenderer
* renderer
) : wxGraphicsContext(renderer
)
1344 wxMacCoreGraphicsContext::wxMacCoreGraphicsContext() : wxGraphicsContext(NULL
)
1347 wxLogDebug(wxT("Illegal Constructor called"));
1350 wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext()
1352 SetNativeContext(NULL
);
1355 void wxMacCoreGraphicsContext::GetSize( wxDouble
* width
, wxDouble
* height
)
1362 void wxMacCoreGraphicsContext::StartPage( wxDouble width
, wxDouble height
)
1365 if ( width
!= 0 && height
!= 0)
1366 r
= CGRectMake( 0 , 0 , width
, height
);
1368 r
= CGRectMake( 0 , 0 , m_width
, m_height
);
1370 CGContextBeginPage(m_cgContext
, &r
);
1371 // CGContextTranslateCTM( m_cgContext , 0 , height == 0 ? m_height : height );
1372 // CGContextScaleCTM( m_cgContext , 1 , -1 );
1375 void wxMacCoreGraphicsContext::EndPage()
1377 CGContextEndPage(m_cgContext
);
1380 void wxMacCoreGraphicsContext::Flush()
1382 CGContextFlush(m_cgContext
);
1385 void wxMacCoreGraphicsContext::EnsureIsValid()
1391 QDBeginCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1395 wxASSERT_MSG( status
== noErr
, wxT("Cannot nest wxDCs on the same window") );
1397 CGContextConcatCTM( m_cgContext
, m_windowTransform
);
1398 CGContextSaveGState( m_cgContext
);
1399 m_releaseContext
= true;
1400 if ( !HIShapeIsEmpty(m_clipRgn
) )
1402 // the clip region is in device coordinates, so we convert this again to user coordinates
1403 wxMacCFRefHolder
<HIMutableShapeRef
> hishape
;
1404 hishape
.Set( HIShapeCreateMutableCopy( m_clipRgn
) );
1405 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
,m_windowTransform
);
1406 HIShapeOffset( hishape
, -transformedOrigin
.x
, -transformedOrigin
.y
);
1407 HIShapeReplacePathInCGContext( hishape
, m_cgContext
);
1408 CGContextClip( m_cgContext
);
1410 CGContextSaveGState( m_cgContext
);
1414 // TODO test whether the private CGContextSetCompositeOperation works under 10.3 (using NSCompositingModes)
1416 bool wxMacCoreGraphicsContext::SetLogicalFunction( int function
)
1418 if (m_logicalFunction
== function
)
1423 bool retval
= false;
1425 if ( function
== wxCOPY
)
1428 CGContextSetBlendMode( m_cgContext
, kCGBlendModeNormal
);
1430 else if ( function
== wxINVERT
|| function
== wxXOR
)
1432 // change color to white
1433 CGContextSetBlendMode( m_cgContext
, kCGBlendModeExclusion
);
1434 CGContextSetShouldAntialias( m_cgContext
, false );
1439 m_logicalFunction
= function
;
1443 void wxMacCoreGraphicsContext::Clip( const wxRegion
®ion
)
1447 HIShapeRef shape
= HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() );
1448 HIShapeReplacePathInCGContext( shape
, m_cgContext
);
1449 CGContextClip( m_cgContext
);
1454 // this offsetting to device coords is not really correct, but since we cannot apply affine transforms
1455 // to regions we try at least to have correct translations
1456 wxMacCFRefHolder
<HIShapeRef
> hishape
;
1457 hishape
.Set( HIShapeCreateWithQDRgn( (RgnHandle
) region
.GetWXHRGN() ));
1458 HIMutableShapeRef mutableShape
= HIShapeCreateMutableCopy( hishape
);
1460 CGPoint transformedOrigin
= CGPointApplyAffineTransform( CGPointZero
, m_windowTransform
);
1461 HIShapeOffset( mutableShape
, transformedOrigin
.x
, transformedOrigin
.y
);
1462 m_clipRgn
.Set(mutableShape
);
1466 // clips drawings to the rect
1467 void wxMacCoreGraphicsContext::Clip( wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1469 HIRect r
= CGRectMake( x
, y
, w
, h
);
1472 CGContextClipToRect( m_cgContext
, r
);
1476 // the clipping itself must be stored as device coordinates, otherwise
1477 // we cannot apply it back correctly
1478 r
.origin
= CGPointApplyAffineTransform( r
.origin
, m_windowTransform
);
1479 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1483 // resets the clipping to original extent
1484 void wxMacCoreGraphicsContext::ResetClip()
1488 // there is no way for clearing the clip, we can only revert to the stored
1489 // state, but then we have to make sure everything else is NOT restored
1490 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
1491 CGContextRestoreGState( m_cgContext
);
1492 CGContextSaveGState( m_cgContext
);
1493 CGAffineTransform transformNew
= CGContextGetCTM( m_cgContext
);
1494 transformNew
= CGAffineTransformInvert( transformNew
) ;
1495 CGContextConcatCTM( m_cgContext
, transformNew
);
1496 CGContextConcatCTM( m_cgContext
, transform
);
1500 HIRect r
= CGRectMake(0,0,0,0);
1501 m_clipRgn
.Set(HIShapeCreateWithRect(&r
));
1505 void wxMacCoreGraphicsContext::StrokePath( const wxGraphicsPath
&path
)
1507 if ( m_pen
.IsNull() )
1512 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1514 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1515 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1516 CGContextStrokePath( m_cgContext
);
1519 void wxMacCoreGraphicsContext::DrawPath( const wxGraphicsPath
&path
, int fillStyle
)
1521 if ( !m_brush
.IsNull() && ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1523 // when using shading, we cannot draw pen and brush at the same time
1524 // revert to the base implementation of first filling and then stroking
1525 wxGraphicsContext::DrawPath( path
, fillStyle
);
1529 CGPathDrawingMode mode
= kCGPathFill
;
1530 if ( m_brush
.IsNull() )
1532 if ( m_pen
.IsNull() )
1535 mode
= kCGPathStroke
;
1539 if ( m_pen
.IsNull() )
1541 if ( fillStyle
== wxODDEVEN_RULE
)
1542 mode
= kCGPathEOFill
;
1548 if ( fillStyle
== wxODDEVEN_RULE
)
1549 mode
= kCGPathEOFillStroke
;
1551 mode
= kCGPathFillStroke
;
1557 if ( !m_brush
.IsNull() )
1558 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1559 if ( !m_pen
.IsNull() )
1560 ((wxMacCoreGraphicsPenData
*)m_pen
.GetRefData())->Apply(this);
1562 wxQuartzOffsetHelper
helper( m_cgContext
, ShouldOffset() );
1564 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1565 CGContextDrawPath( m_cgContext
, mode
);
1568 void wxMacCoreGraphicsContext::FillPath( const wxGraphicsPath
&path
, int fillStyle
)
1570 if ( m_brush
.IsNull() )
1575 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1577 CGContextSaveGState( m_cgContext
);
1578 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1579 CGContextClip( m_cgContext
);
1580 CGContextDrawShading( m_cgContext
, ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->GetShading() );
1581 CGContextRestoreGState( m_cgContext
);
1585 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1586 CGContextAddPath( m_cgContext
, (CGPathRef
) path
.GetNativePath() );
1587 if ( fillStyle
== wxODDEVEN_RULE
)
1588 CGContextEOFillPath( m_cgContext
);
1590 CGContextFillPath( m_cgContext
);
1594 void wxMacCoreGraphicsContext::SetNativeContext( CGContextRef cg
)
1596 // we allow either setting or clearing but not replacing
1597 wxASSERT( m_cgContext
== NULL
|| cg
== NULL
);
1601 // TODO : when is this necessary - should we add a Flush() method ? CGContextSynchronize( m_cgContext );
1602 CGContextRestoreGState( m_cgContext
);
1603 CGContextRestoreGState( m_cgContext
);
1604 if ( m_releaseContext
)
1607 QDEndCGContext( GetWindowPort( m_windowRef
) , &m_cgContext
);
1611 CGContextRelease(m_cgContext
);
1617 // FIXME: This check is needed because currently we need to use a DC/GraphicsContext
1618 // in order to get font properties, like wxFont::GetPixelSize, but since we don't have
1619 // a native window attached to use, I create a wxGraphicsContext with a NULL CGContextRef
1620 // for this one operation.
1622 // When wxFont::GetPixelSize on Mac no longer needs a graphics context, this check
1626 CGContextRetain(m_cgContext
);
1627 CGContextSaveGState( m_cgContext
);
1628 CGContextSaveGState( m_cgContext
);
1629 m_releaseContext
= false;
1633 void wxMacCoreGraphicsContext::Translate( wxDouble dx
, wxDouble dy
)
1636 CGContextTranslateCTM( m_cgContext
, dx
, dy
);
1638 m_windowTransform
= CGAffineTransformTranslate(m_windowTransform
,dx
,dy
);
1641 void wxMacCoreGraphicsContext::Scale( wxDouble xScale
, wxDouble yScale
)
1644 CGContextScaleCTM( m_cgContext
, xScale
, yScale
);
1646 m_windowTransform
= CGAffineTransformScale(m_windowTransform
,xScale
,yScale
);
1649 void wxMacCoreGraphicsContext::Rotate( wxDouble angle
)
1652 CGContextRotateCTM( m_cgContext
, angle
);
1654 m_windowTransform
= CGAffineTransformRotate(m_windowTransform
,angle
);
1657 void wxMacCoreGraphicsContext::DrawBitmap( const wxBitmap
&bmp
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1661 CGImageRef image
= (CGImageRef
)( bmp
.CreateCGImage() );
1662 HIRect r
= CGRectMake( x
, y
, w
, h
);
1663 if ( bmp
.GetDepth() == 1 )
1665 // is is a mask, the '1' in the mask tell where to draw the current brush
1666 if ( !m_brush
.IsNull() )
1668 if ( ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->IsShading() )
1670 // TODO clip to mask
1672 CGContextSaveGState( m_cgContext );
1673 CGContextAddPath( m_cgContext , (CGPathRef) path.GetNativePath() );
1674 CGContextClip( m_cgContext );
1675 CGContextDrawShading( m_cgContext, ((wxMacCoreGraphicsBrushData*)m_brush.GetRefData())->GetShading() );
1676 CGContextRestoreGState( m_cgContext);
1681 ((wxMacCoreGraphicsBrushData
*)m_brush
.GetRefData())->Apply(this);
1682 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1688 wxMacDrawCGImage( m_cgContext
, &r
, image
);
1690 CGImageRelease( image
);
1693 void wxMacCoreGraphicsContext::DrawIcon( const wxIcon
&icon
, wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
1697 CGRect r
= CGRectMake( 00 , 00 , w
, h
);
1698 CGContextSaveGState( m_cgContext
);
1699 CGContextTranslateCTM( m_cgContext
, x
, y
+ h
);
1700 CGContextScaleCTM( m_cgContext
, 1, -1 );
1701 PlotIconRefInContext( m_cgContext
, &r
, kAlignNone
, kTransformNone
,
1702 NULL
, kPlotIconRefNormalFlags
, MAC_WXHICON( icon
.GetHICON() ) );
1703 CGContextRestoreGState( m_cgContext
);
1706 void wxMacCoreGraphicsContext::PushState()
1710 CGContextSaveGState( m_cgContext
);
1713 void wxMacCoreGraphicsContext::PopState()
1717 CGContextRestoreGState( m_cgContext
);
1720 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
)
1722 if ( m_font
.IsNull() )
1726 #ifdef wxMAC_USE_CORE_TEXT
1727 // TODO core text implementation here
1728 #elif defined(wxMAC_USE_ATSU_TEXT)
1729 DrawText(str
, x
, y
, 0.0);
1730 #elif defined(WXMAC_USE_CG_TEXT)
1731 // TODO core graphics text implementation here
1735 void wxMacCoreGraphicsContext::DrawText( const wxString
&str
, wxDouble x
, wxDouble y
, wxDouble angle
)
1737 if ( m_font
.IsNull() )
1741 #ifdef wxMAC_USE_CORE_TEXT
1742 // default implementation takes care of rotation and calls non rotated DrawText afterwards
1743 wxGraphicsContext::DrawText( str
, x
, y
, angle
);
1744 #elif defined(wxMAC_USE_ATSU_TEXT)
1745 OSStatus status
= noErr
;
1746 ATSUTextLayout atsuLayout
;
1747 UniCharCount chars
= str
.length();
1748 UniChar
* ubuf
= NULL
;
1750 #if SIZEOF_WCHAR_T == 4
1751 wxMBConvUTF16 converter
;
1753 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1754 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1755 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1757 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1758 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1759 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1760 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1762 chars
= unicharlen
/ 2;
1765 ubuf
= (UniChar
*) str
.wc_str();
1767 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1768 chars
= wxWcslen( wchar
.data() );
1769 ubuf
= (UniChar
*) wchar
.data();
1773 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1774 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1775 &chars
, &style
, &atsuLayout
);
1777 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the rotated text") );
1779 status
= ::ATSUSetTransientFontMatching( atsuLayout
, true );
1780 wxASSERT_MSG( status
== noErr
, wxT("couldn't setup transient font matching") );
1782 int iAngle
= int( angle
* RAD2DEG
);
1783 if ( abs(iAngle
) > 0 )
1785 Fixed atsuAngle
= IntToFixed( iAngle
);
1786 ATSUAttributeTag atsuTags
[] =
1788 kATSULineRotationTag
,
1790 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1794 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1798 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1799 atsuTags
, atsuSizes
, atsuValues
);
1803 ATSUAttributeTag atsuTags
[] =
1807 ByteCount atsuSizes
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1809 sizeof( CGContextRef
) ,
1811 ATSUAttributeValuePtr atsuValues
[sizeof(atsuTags
) / sizeof(ATSUAttributeTag
)] =
1815 status
= ::ATSUSetLayoutControls(atsuLayout
, sizeof(atsuTags
) / sizeof(ATSUAttributeTag
),
1816 atsuTags
, atsuSizes
, atsuValues
);
1819 ATSUTextMeasurement textBefore
, textAfter
;
1820 ATSUTextMeasurement ascent
, descent
;
1822 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1823 &textBefore
, &textAfter
, &ascent
, &descent
);
1825 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1828 x
+= (int)(sin(angle
) * FixedToInt(ascent
));
1829 y
+= (int)(cos(angle
) * FixedToInt(ascent
));
1831 status
= ::ATSUMeasureTextImage( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1832 IntToFixed(x
) , IntToFixed(y
) , &rect
);
1833 wxASSERT_MSG( status
== noErr
, wxT("couldn't measure the rotated text") );
1835 CGContextSaveGState(m_cgContext
);
1836 CGContextTranslateCTM(m_cgContext
, x
, y
);
1837 CGContextScaleCTM(m_cgContext
, 1, -1);
1838 status
= ::ATSUDrawText( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1839 IntToFixed(0) , IntToFixed(0) );
1841 wxASSERT_MSG( status
== noErr
, wxT("couldn't draw the rotated text") );
1843 CGContextRestoreGState(m_cgContext
);
1845 ::ATSUDisposeTextLayout(atsuLayout
);
1847 #if SIZEOF_WCHAR_T == 4
1850 #elif defined(WXMAC_USE_CG_TEXT)
1851 // default implementation takes care of rotation and calls non rotated DrawText afterwards
1852 wxGraphicsContext::DrawText( str
, x
, y
, angle
);
1856 void wxMacCoreGraphicsContext::GetTextExtent( const wxString
&str
, wxDouble
*width
, wxDouble
*height
,
1857 wxDouble
*descent
, wxDouble
*externalLeading
) const
1859 wxCHECK_RET( !m_font
.IsNull(), wxT("wxDC(cg)::DoGetTextExtent - no valid font set") );
1867 if ( externalLeading
)
1868 *externalLeading
= 0;
1873 #ifdef wxMAC_USE_CORE_TEXT
1874 // TODO core text implementation here
1875 #elif defined(wxMAC_USE_ATSU_TEXT)
1876 OSStatus status
= noErr
;
1878 ATSUTextLayout atsuLayout
;
1879 UniCharCount chars
= str
.length();
1880 UniChar
* ubuf
= NULL
;
1882 #if SIZEOF_WCHAR_T == 4
1883 wxMBConvUTF16 converter
;
1885 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 );
1886 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1887 converter
.WC2MB( (char*) ubuf
, str
.wc_str(), unicharlen
+ 2 );
1889 const wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1890 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1891 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1892 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1894 chars
= unicharlen
/ 2;
1897 ubuf
= (UniChar
*) str
.wc_str();
1899 wxWCharBuffer wchar
= str
.wc_str( wxConvLocal
);
1900 chars
= wxWcslen( wchar
.data() );
1901 ubuf
= (UniChar
*) wchar
.data();
1905 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1906 status
= ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1907 &chars
, &style
, &atsuLayout
);
1909 wxASSERT_MSG( status
== noErr
, wxT("couldn't create the layout of the text") );
1911 ATSUTextMeasurement textBefore
, textAfter
;
1912 ATSUTextMeasurement textAscent
, textDescent
;
1914 status
= ::ATSUGetUnjustifiedBounds( atsuLayout
, kATSUFromTextBeginning
, kATSUToTextEnd
,
1915 &textBefore
, &textAfter
, &textAscent
, &textDescent
);
1918 *height
= FixedToInt(textAscent
+ textDescent
);
1920 *descent
= FixedToInt(textDescent
);
1921 if ( externalLeading
)
1922 *externalLeading
= 0;
1924 *width
= FixedToInt(textAfter
- textBefore
);
1926 ::ATSUDisposeTextLayout(atsuLayout
);
1927 #if SIZEOF_WCHAR_T == 4
1930 #elif defined(WXMAC_USE_CG_TEXT)
1931 // TODO core graphics text implementation here
1935 void wxMacCoreGraphicsContext::GetPartialTextExtents(const wxString
& text
, wxArrayDouble
& widths
) const
1938 widths
.Add(0, text
.length());
1943 #ifdef wxMAC_USE_CORE_TEXT
1944 // TODO core text implementation here
1945 #elif defined(wxMAC_USE_ATSU_TEXT)
1946 ATSUTextLayout atsuLayout
;
1947 UniCharCount chars
= text
.length();
1948 UniChar
* ubuf
= NULL
;
1950 #if SIZEOF_WCHAR_T == 4
1951 wxMBConvUTF16 converter
;
1953 size_t unicharlen
= converter
.WC2MB( NULL
, text
.wc_str() , 0 );
1954 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1955 converter
.WC2MB( (char*) ubuf
, text
.wc_str(), unicharlen
+ 2 );
1957 const wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1958 size_t unicharlen
= converter
.WC2MB( NULL
, wchar
.data() , 0 );
1959 ubuf
= (UniChar
*) malloc( unicharlen
+ 2 );
1960 converter
.WC2MB( (char*) ubuf
, wchar
.data() , unicharlen
+ 2 );
1962 chars
= unicharlen
/ 2;
1965 ubuf
= (UniChar
*) text
.wc_str();
1967 wxWCharBuffer wchar
= text
.wc_str( wxConvLocal
);
1968 chars
= wxWcslen( wchar
.data() );
1969 ubuf
= (UniChar
*) wchar
.data();
1973 ATSUStyle style
= (((wxMacCoreGraphicsFontData
*)m_font
.GetRefData())->GetATSUStyle());
1974 ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr
) ubuf
, 0 , chars
, chars
, 1 ,
1975 &chars
, &style
, &atsuLayout
);
1977 for ( int pos
= 0; pos
< (int)chars
; pos
++ )
1979 unsigned long actualNumberOfBounds
= 0;
1980 ATSTrapezoid glyphBounds
;
1982 // We get a single bound, since the text should only require one. If it requires more, there is an issue
1984 result
= ATSUGetGlyphBounds( atsuLayout
, 0, 0, kATSUFromTextBeginning
, pos
+ 1,
1985 kATSUseDeviceOrigins
, 1, &glyphBounds
, &actualNumberOfBounds
);
1986 if (result
!= noErr
|| actualNumberOfBounds
!= 1 )
1989 widths
[pos
] = FixedToInt( glyphBounds
.upperRight
.x
- glyphBounds
.upperLeft
.x
);
1990 //unsigned char uch = s[i];
1993 ::ATSUDisposeTextLayout(atsuLayout
);
1994 #if SIZEOF_WCHAR_T == 4
1997 #elif defined(WXMAC_USE_CG_TEXT)
1998 // TODO core graphics text implementation here
2002 void * wxMacCoreGraphicsContext::GetNativeContext()
2007 // concatenates this transform with the current transform of this context
2008 void wxMacCoreGraphicsContext::ConcatTransform( const wxGraphicsMatrix
& matrix
)
2011 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2013 m_windowTransform
= CGAffineTransformConcat(m_windowTransform
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2016 // sets the transform of this context
2017 void wxMacCoreGraphicsContext::SetTransform( const wxGraphicsMatrix
& matrix
)
2021 CGAffineTransform transform
= CGContextGetCTM( m_cgContext
);
2022 transform
= CGAffineTransformInvert( transform
) ;
2023 CGContextConcatCTM( m_cgContext
, transform
);
2024 CGContextConcatCTM( m_cgContext
, *(CGAffineTransform
*) matrix
.GetNativeMatrix());
2028 m_windowTransform
= *(CGAffineTransform
*) matrix
.GetNativeMatrix();
2032 // gets the matrix of this context
2033 wxGraphicsMatrix
wxMacCoreGraphicsContext::GetTransform() const
2035 wxGraphicsMatrix m
= CreateMatrix();
2036 *((CGAffineTransform
*) m
.GetNativeMatrix()) = ( m_cgContext
== NULL
? m_windowTransform
:
2037 CGContextGetCTM( m_cgContext
));
2045 //-----------------------------------------------------------------------------
2046 // wxMacCoreGraphicsRenderer declaration
2047 //-----------------------------------------------------------------------------
2049 class WXDLLIMPEXP_CORE wxMacCoreGraphicsRenderer
: public wxGraphicsRenderer
2052 wxMacCoreGraphicsRenderer() {}
2054 virtual ~wxMacCoreGraphicsRenderer() {}
2058 virtual wxGraphicsContext
* CreateContext( const wxWindowDC
& dc
);
2060 virtual wxGraphicsContext
* CreateContextFromNativeContext( void * context
);
2062 virtual wxGraphicsContext
* CreateContextFromNativeWindow( void * window
);
2064 virtual wxGraphicsContext
* CreateContext( wxWindow
* window
);
2066 virtual wxGraphicsContext
* CreateMeasuringContext();
2070 virtual wxGraphicsPath
CreatePath();
2074 virtual wxGraphicsMatrix
CreateMatrix( wxDouble a
=1.0, wxDouble b
=0.0, wxDouble c
=0.0, wxDouble d
=1.0,
2075 wxDouble tx
=0.0, wxDouble ty
=0.0);
2078 virtual wxGraphicsPen
CreatePen(const wxPen
& pen
) ;
2080 virtual wxGraphicsBrush
CreateBrush(const wxBrush
& brush
) ;
2082 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2083 virtual wxGraphicsBrush
CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2084 const wxColour
&c1
, const wxColour
&c2
) ;
2086 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2087 // with radius r and color cColor
2088 virtual wxGraphicsBrush
CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2089 const wxColour
&oColor
, const wxColour
&cColor
) ;
2092 virtual wxGraphicsFont
CreateFont( const wxFont
&font
, const wxColour
&col
= *wxBLACK
) ;
2095 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacCoreGraphicsRenderer
)
2098 //-----------------------------------------------------------------------------
2099 // wxMacCoreGraphicsRenderer implementation
2100 //-----------------------------------------------------------------------------
2102 IMPLEMENT_DYNAMIC_CLASS(wxMacCoreGraphicsRenderer
,wxGraphicsRenderer
)
2104 static wxMacCoreGraphicsRenderer gs_MacCoreGraphicsRenderer
;
2106 wxGraphicsRenderer
* wxGraphicsRenderer::GetDefaultRenderer()
2108 return &gs_MacCoreGraphicsRenderer
;
2111 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( const wxWindowDC
& dc
)
2113 wxMemoryDC
* mdc
= wxDynamicCast(&dc
, wxMemoryDC
);
2116 return new wxMacCoreGraphicsContext(this,
2117 (CGContextRef
)mdc
->GetGraphicsContext()->GetNativeContext());
2121 return new wxMacCoreGraphicsContext(this,(CGContextRef
)dc
.GetWindow()->MacGetCGContextRef() );
2125 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context
)
2127 return new wxMacCoreGraphicsContext(this,(CGContextRef
)context
);
2131 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContextFromNativeWindow( void * window
)
2133 return new wxMacCoreGraphicsContext(this,(WindowRef
)window
);
2136 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateContext( wxWindow
* window
)
2138 return new wxMacCoreGraphicsContext(this, window
);
2141 wxGraphicsContext
* wxMacCoreGraphicsRenderer::CreateMeasuringContext()
2143 return new wxMacCoreGraphicsContext(this);
2148 wxGraphicsPath
wxMacCoreGraphicsRenderer::CreatePath()
2151 m
.SetRefData( new wxMacCoreGraphicsPathData(this));
2158 wxGraphicsMatrix
wxMacCoreGraphicsRenderer::CreateMatrix( wxDouble a
, wxDouble b
, wxDouble c
, wxDouble d
,
2159 wxDouble tx
, wxDouble ty
)
2162 wxMacCoreGraphicsMatrixData
* data
= new wxMacCoreGraphicsMatrixData( this );
2163 data
->Set( a
,b
,c
,d
,tx
,ty
) ;
2168 wxGraphicsPen
wxMacCoreGraphicsRenderer::CreatePen(const wxPen
& pen
)
2170 if ( !pen
.Ok() || pen
.GetStyle() == wxTRANSPARENT
)
2171 return wxNullGraphicsPen
;
2175 p
.SetRefData(new wxMacCoreGraphicsPenData( this, pen
));
2180 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateBrush(const wxBrush
& brush
)
2182 if ( !brush
.Ok() || brush
.GetStyle() == wxTRANSPARENT
)
2183 return wxNullGraphicsBrush
;
2187 p
.SetRefData(new wxMacCoreGraphicsBrushData( this, brush
));
2192 // sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
2193 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateLinearGradientBrush( wxDouble x1
, wxDouble y1
, wxDouble x2
, wxDouble y2
,
2194 const wxColour
&c1
, const wxColour
&c2
)
2197 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2198 d
->CreateLinearGradientBrush(x1
, y1
, x2
, y2
, c1
, c2
);
2203 // sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
2204 // with radius r and color cColor
2205 wxGraphicsBrush
wxMacCoreGraphicsRenderer::CreateRadialGradientBrush( wxDouble xo
, wxDouble yo
, wxDouble xc
, wxDouble yc
, wxDouble radius
,
2206 const wxColour
&oColor
, const wxColour
&cColor
)
2209 wxMacCoreGraphicsBrushData
* d
= new wxMacCoreGraphicsBrushData( this );
2210 d
->CreateRadialGradientBrush(xo
,yo
,xc
,yc
,radius
,oColor
,cColor
);
2216 wxGraphicsFont
wxMacCoreGraphicsRenderer::CreateFont( const wxFont
&font
, const wxColour
&col
)
2221 p
.SetRefData(new wxMacCoreGraphicsFontData( this , font
, col
));
2225 return wxNullGraphicsFont
;