new graphics context implementation

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2006-10-20 11:46:28 +00:00
parent 4130e41449
commit f7862d3e49
4 changed files with 41 additions and 20 deletions

View File

@@ -52,7 +52,7 @@ wxMemoryDC::~wxMemoryDC()
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
m_selected.EndRawAccess() ; m_selected.EndRawAccess() ;
CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
delete m_graphicContext ; delete m_graphicContext ;
m_graphicContext = NULL ; m_graphicContext = NULL ;
CGContextRelease( bmCtx ) ; CGContextRelease( bmCtx ) ;
@@ -68,7 +68,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
m_selected.EndRawAccess() ; m_selected.EndRawAccess() ;
CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
delete m_graphicContext ; delete m_graphicContext ;
m_graphicContext = NULL ; m_graphicContext = NULL ;
CGContextRelease( bmCtx ) ; CGContextRelease( bmCtx ) ;
@@ -89,6 +89,8 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
int bytesPerPixel = 4 ; int bytesPerPixel = 4 ;
int w = bitmap.GetWidth() ; int w = bitmap.GetWidth() ;
int h = bitmap.GetHeight() ; int h = bitmap.GetHeight() ;
m_width = w;
m_height = h;
// TODO: should this be kCGImageAlphaPremultiplied[First,Last] ? // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ; CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ;
@@ -105,7 +107,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ; CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ;
CGContextScaleCTM( bmCtx , 1 , -1 ) ; CGContextScaleCTM( bmCtx , 1 , -1 ) ;
m_graphicContext = new wxMacCGContext( bmCtx ) ; SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
m_graphicContext->SetPen( m_pen ) ; m_graphicContext->SetPen( m_pen ) ;
m_graphicContext->SetBrush( m_brush ) ; m_graphicContext->SetBrush( m_brush ) ;
m_graphicContext->SetFont( m_font ) ; m_graphicContext->SetFont( m_font ) ;

View File

@@ -94,8 +94,8 @@ wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
PMPrinterGetOutputResolution( printer, native->m_macPrintSettings, &res) ; PMPrinterGetOutputResolution( printer, native->m_macPrintSettings, &res) ;
#else #else
m_err = PMGetResolution((PMPageFormat) (native->m_macPageFormat), &res); m_err = PMGetResolution((PMPageFormat) (native->m_macPageFormat), &res);
m_ppi = wxSize(int(res.hRes), int(res.vRes));
#endif #endif
m_ppi = wxSize(int(res.hRes), int(res.vRes));
} }
wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC() wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
@@ -286,8 +286,10 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
m_mm_to_pix_y = mm2inches * sz.y; m_mm_to_pix_y = mm2inches * sz.y;
} }
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
/*
// the cgContext will only be handed over page by page // the cgContext will only be handed over page by page
m_graphicContext = new wxMacCGContext() ; m_graphicContext = new wxMacCGContext() ;
*/
#endif #endif
} }
} }
@@ -300,8 +302,10 @@ wxSize wxPrinterDC::GetPPI() const
wxPrinterDC::~wxPrinterDC(void) wxPrinterDC::~wxPrinterDC(void)
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
/*
// this context was borrowed // this context was borrowed
((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ; ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ;
*/
#endif #endif
delete m_nativePrinterDC ; delete m_nativePrinterDC ;
} }
@@ -309,7 +313,7 @@ wxPrinterDC::~wxPrinterDC(void)
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
void wxPrinterDC::MacSetCGContext( void * cg ) void wxPrinterDC::MacSetCGContext( void * cg )
{ {
((wxMacCGContext*)(m_graphicContext))->SetNativeContext( (CGContextRef) cg ) ; SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
m_graphicContext->SetPen( m_pen ) ; m_graphicContext->SetPen( m_pen ) ;
m_graphicContext->SetBrush( m_brush ) ; m_graphicContext->SetBrush( m_brush ) ;
} }

View File

@@ -20,7 +20,28 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
// Create a DC representing the whole screen // Create a DC representing the whole screen
wxScreenDC::wxScreenDC() wxScreenDC::wxScreenDC()
{ {
#ifndef __LP64__ #if wxMAC_USE_CORE_GRAPHICS
CGDirectDisplayID display = CGMainDisplayID();
m_displayId = (UInt32) display;
CGError err = CGDisplayCaptureWithOptions(display,kCGCaptureNoFill);
wxASSERT( err == kCGErrorSuccess );
CGContextRef cg = CGDisplayGetDrawingContext(display);
CGRect bounds ;
bounds = CGDisplayBounds(display);
/*
m_macLocalOrigin.x = 0;
m_macLocalOrigin.y = 0;
*/ // TODO
SInt16 height;
GetThemeMenuBarHeight( &height );
m_minY = height;
m_minX = 0;
m_maxX = bounds.size.width;
m_maxY = bounds.size.height - height;
SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
m_width = bounds.size.width;
m_height = bounds.size.height - height;
#else
m_macPort = CreateNewPort() ; m_macPort = CreateNewPort() ;
GrafPtr port ; GrafPtr port ;
GetPort( &port ) ; GetPort( &port ) ;
@@ -30,9 +51,7 @@ wxScreenDC::wxScreenDC()
SetPort( port ) ; SetPort( port ) ;
m_macLocalOrigin.x = -pt.h ; m_macLocalOrigin.x = -pt.h ;
m_macLocalOrigin.y = -pt.v ; m_macLocalOrigin.y = -pt.v ;
#if wxMAC_USE_CORE_GRAPHICS
m_macLocalOriginInPort = m_macLocalOrigin ;
#endif
BitMap screenBits; BitMap screenBits;
GetQDGlobalsScreenBits( &screenBits ); GetQDGlobalsScreenBits( &screenBits );
m_minX = screenBits.bounds.left ; m_minX = screenBits.bounds.left ;
@@ -44,25 +63,21 @@ wxScreenDC::wxScreenDC()
m_maxX = screenBits.bounds.right ; m_maxX = screenBits.bounds.right ;
m_maxY = screenBits.bounds.bottom ; m_maxY = screenBits.bounds.bottom ;
#if wxMAC_USE_CORE_GRAPHICS
m_graphicContext = new wxMacCGContext( port ) ;
#else
MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ; MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
#endif #endif
m_ok = true ; m_ok = true ;
#endif
} }
wxScreenDC::~wxScreenDC() wxScreenDC::~wxScreenDC()
{ {
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
delete m_graphicContext ; delete m_graphicContext;
m_graphicContext = NULL ; m_graphicContext = NULL;
#endif CGDirectDisplayID display = (CGDirectDisplayID) m_displayId;
CGDisplayRelease( display );
#ifndef __LP64__ #else
if ( m_macPort ) if ( m_macPort )
DisposePort( (CGrafPtr) m_macPort ) ; DisposePort( (CGrafPtr) m_macPort ) ;
#endif #endif

View File

@@ -166,7 +166,7 @@ bool wxMetaFile::Play(wxDC *dc)
#if wxMAC_USE_CORE_GRAPHICS #if wxMAC_USE_CORE_GRAPHICS
#ifndef __LP64__ #ifndef __LP64__
QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef; QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef;
CGContextRef cg = ((wxMacCGContext*)(dc->GetGraphicContext()))->GetNativeContext(); CGContextRef cg = (CGContextRef) dc->GetGraphicContext()->GetNativeContext();
CGRect bounds = QDPictGetBounds( cgPictRef ); CGRect bounds = QDPictGetBounds( cgPictRef );
CGContextSaveGState( cg ); CGContextSaveGState( cg );