Adding a native implementation for clearing bitmap/window contexts

Filling a bitmap surface is filled with ARGB 0,0,0,0. This way eg buffered transparent layers can be properly cleared.
This commit is contained in:
Stefan Csomor
2017-06-25 22:48:58 +02:00
parent 40d77062b0
commit 6dfa897b4a
5 changed files with 72 additions and 28 deletions

View File

@@ -653,6 +653,9 @@ public:
// draws a path by first filling and then stroking
virtual void DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
// paints a transparent rectangle (only useful for bitmaps or windows)
virtual void ClearRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
//
// text
//

View File

@@ -1249,12 +1249,15 @@ wxCoord wxGCDCImpl::GetCharHeight(void) const
void wxGCDCImpl::Clear(void)
{
wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
if ( m_backgroundBrush.IsOk() )
{
m_graphicContext->SetBrush( m_backgroundBrush );
wxPen p = *wxTRANSPARENT_PEN;
m_graphicContext->SetPen( p );
wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE);
#ifdef __WXOSX__
#ifdef __WXOSX__
// This is a legacy implementation which doesn't take advantage
// of clipping region bounds retrieved by wxMacCoreGraphicsContext::GetClipBox
// because this function is not yet verified.
@@ -1268,14 +1271,27 @@ void wxGCDCImpl::Clear(void)
DoDrawRectangle(
DeviceToLogicalX(0), DeviceToLogicalY(0),
DeviceToLogicalXRel(0x800000 - 64), DeviceToLogicalYRel(0x800000 - 64));
#else
#else
double x, y, w, h;
m_graphicContext->GetClipBox(&x, &y, &w, &h);
m_graphicContext->DrawRectangle(x, y, w, h);
#endif // __WXOSX__ / !__WXOSX__
#endif // __WXOSX__ / !__WXOSX__
m_graphicContext->SetCompositionMode(formerMode);
m_graphicContext->SetPen( m_pen );
m_graphicContext->SetBrush( m_brush );
}
else
{
#ifdef __WXOSX__
// same comment as above applies
m_graphicContext->ClearRectangle(DeviceToLogicalX(0), DeviceToLogicalY(0),
DeviceToLogicalXRel(0x8000 - 64), DeviceToLogicalYRel(0x8000 - 64));
#else
double x, y, w, h;
m_graphicContext->GetClipBox(&x, &y, &w, &h);
m_graphicContext->ClearRectangle(x, y, w, h);
#endif
}
}
void wxGCDCImpl::DoGetSize(int *width, int *height) const

View File

@@ -759,6 +759,11 @@ void wxGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDou
DrawPath( path );
}
void wxGraphicsContext::ClearRectangle( wxDouble WXUNUSED(x), wxDouble WXUNUSED(y), wxDouble WXUNUSED(w), wxDouble WXUNUSED(h))
{
}
void wxGraphicsContext::DrawEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
{
wxGraphicsPath path = CreatePath();

View File

@@ -98,7 +98,6 @@ using namespace std;
#ifdef __WXMAC__
#include "wx/osx/private.h"
#include <cairo-quartz.h>
#include <cairo-atsui.h>
#endif
// Helper functions for dealing with alpha pre-multiplication.
@@ -476,6 +475,7 @@ public:
virtual void StrokePath( const wxGraphicsPath& p ) wxOVERRIDE;
virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxWINDING_RULE ) wxOVERRIDE;
virtual void ClearRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) wxOVERRIDE;
virtual void Translate( wxDouble dx , wxDouble dy ) wxOVERRIDE;
virtual void Scale( wxDouble xScale , wxDouble yScale ) wxOVERRIDE;
@@ -2440,6 +2440,15 @@ void wxCairoContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fi
}
}
void wxCairoContext::ClearRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{
cairo_save(m_context);
cairo_set_operator(m_context, CAIRO_OPERATOR_CLEAR);
cairo_rectangle (m_context, x, y, w, h);
cairo_fill (m_context);
cairo_restore(m_context);
}
void wxCairoContext::Rotate( wxDouble angle )
{
cairo_rotate(m_context,angle);

View File

@@ -1338,6 +1338,9 @@ public:
// draws a path by first filling and then stroking
virtual void DrawPath( const wxGraphicsPath &path, wxPolygonFillMode fillStyle = wxODDEVEN_RULE ) wxOVERRIDE;
// paints a transparent rectangle (only useful for bitmaps or windows)
virtual void ClearRectangle(wxDouble x, wxDouble y, wxDouble w, wxDouble h) wxOVERRIDE;
virtual bool ShouldOffset() const wxOVERRIDE
{
if ( !m_enableOffset )
@@ -2348,6 +2351,14 @@ void * wxMacCoreGraphicsContext::GetNativeContext()
return m_cgContext;
}
void wxMacCoreGraphicsContext::ClearRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{
if (!EnsureIsValid())
return;
CGRect rect = CGRectMake( (CGFloat) x , (CGFloat) y , (CGFloat) w , (CGFloat) h );
CGContextClearRect(m_cgContext, rect);
}
void wxMacCoreGraphicsContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{