From: Stefan Csomor Date: Fri, 20 Oct 2006 11:46:28 +0000 (+0000) Subject: new graphics context implementation X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f7862d3e499501dfc5d6103146cae51f2488c9af new graphics context implementation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/mac/carbon/dcmemory.cpp b/src/mac/carbon/dcmemory.cpp index ee44e18330..393e0a23c2 100644 --- a/src/mac/carbon/dcmemory.cpp +++ b/src/mac/carbon/dcmemory.cpp @@ -52,7 +52,7 @@ wxMemoryDC::~wxMemoryDC() { #if wxMAC_USE_CORE_GRAPHICS m_selected.EndRawAccess() ; - CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; + CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ; delete m_graphicContext ; m_graphicContext = NULL ; CGContextRelease( bmCtx ) ; @@ -68,7 +68,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) { #if wxMAC_USE_CORE_GRAPHICS m_selected.EndRawAccess() ; - CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ; + CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ; delete m_graphicContext ; m_graphicContext = NULL ; CGContextRelease( bmCtx ) ; @@ -89,6 +89,8 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) int bytesPerPixel = 4 ; int w = bitmap.GetWidth() ; int h = bitmap.GetHeight() ; + m_width = w; + m_height = h; // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ? CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ; @@ -105,7 +107,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) CGContextTranslateCTM( bmCtx , 0 , m_selected.GetHeight() ) ; CGContextScaleCTM( bmCtx , 1 , -1 ) ; - m_graphicContext = new wxMacCGContext( bmCtx ) ; + SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) ); m_graphicContext->SetPen( m_pen ) ; m_graphicContext->SetBrush( m_brush ) ; m_graphicContext->SetFont( m_font ) ; diff --git a/src/mac/carbon/dcprint.cpp b/src/mac/carbon/dcprint.cpp index ce17739428..f1d1a2f880 100644 --- a/src/mac/carbon/dcprint.cpp +++ b/src/mac/carbon/dcprint.cpp @@ -94,8 +94,8 @@ wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data ) PMPrinterGetOutputResolution( printer, native->m_macPrintSettings, &res) ; #else m_err = PMGetResolution((PMPageFormat) (native->m_macPageFormat), &res); - m_ppi = wxSize(int(res.hRes), int(res.vRes)); #endif + m_ppi = wxSize(int(res.hRes), int(res.vRes)); } wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC() @@ -286,8 +286,10 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata) m_mm_to_pix_y = mm2inches * sz.y; } #if wxMAC_USE_CORE_GRAPHICS +/* // the cgContext will only be handed over page by page m_graphicContext = new wxMacCGContext() ; + */ #endif } } @@ -300,8 +302,10 @@ wxSize wxPrinterDC::GetPPI() const wxPrinterDC::~wxPrinterDC(void) { #if wxMAC_USE_CORE_GRAPHICS +/* // this context was borrowed ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ; + */ #endif delete m_nativePrinterDC ; } @@ -309,7 +313,7 @@ wxPrinterDC::~wxPrinterDC(void) #if wxMAC_USE_CORE_GRAPHICS void wxPrinterDC::MacSetCGContext( void * cg ) { - ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( (CGContextRef) cg ) ; + SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) ); m_graphicContext->SetPen( m_pen ) ; m_graphicContext->SetBrush( m_brush ) ; } diff --git a/src/mac/carbon/dcscreen.cpp b/src/mac/carbon/dcscreen.cpp index e8ccf9807a..10f209b4b0 100644 --- a/src/mac/carbon/dcscreen.cpp +++ b/src/mac/carbon/dcscreen.cpp @@ -20,7 +20,28 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC) // Create a DC representing the whole screen 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() ; GrafPtr port ; GetPort( &port ) ; @@ -30,9 +51,7 @@ wxScreenDC::wxScreenDC() SetPort( port ) ; m_macLocalOrigin.x = -pt.h ; m_macLocalOrigin.y = -pt.v ; -#if wxMAC_USE_CORE_GRAPHICS - m_macLocalOriginInPort = m_macLocalOrigin ; -#endif + BitMap screenBits; GetQDGlobalsScreenBits( &screenBits ); m_minX = screenBits.bounds.left ; @@ -44,25 +63,21 @@ wxScreenDC::wxScreenDC() m_maxX = screenBits.bounds.right ; 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 ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; #endif - m_ok = true ; -#endif + m_ok = true ; } wxScreenDC::~wxScreenDC() { #if wxMAC_USE_CORE_GRAPHICS - delete m_graphicContext ; - m_graphicContext = NULL ; -#endif - -#ifndef __LP64__ + delete m_graphicContext; + m_graphicContext = NULL; + CGDirectDisplayID display = (CGDirectDisplayID) m_displayId; + CGDisplayRelease( display ); +#else if ( m_macPort ) DisposePort( (CGrafPtr) m_macPort ) ; #endif diff --git a/src/mac/carbon/metafile.cpp b/src/mac/carbon/metafile.cpp index 00a3fdc09a..1ed5081a6b 100644 --- a/src/mac/carbon/metafile.cpp +++ b/src/mac/carbon/metafile.cpp @@ -166,7 +166,7 @@ bool wxMetaFile::Play(wxDC *dc) #if wxMAC_USE_CORE_GRAPHICS #ifndef __LP64__ QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef; - CGContextRef cg = ((wxMacCGContext*)(dc->GetGraphicContext()))->GetNativeContext(); + CGContextRef cg = (CGContextRef) dc->GetGraphicContext()->GetNativeContext(); CGRect bounds = QDPictGetBounds( cgPictRef ); CGContextSaveGState( cg );