Fix wxGCDC::Clear

If underlying graphics context is rotated then drawing a rectangle with origin at (0,0) doesn't cover all the drawing area. To draw over entire area we need to get extents of the actual clipping region (with applied all transformations) and use it as coordinates of the drawn rectangle.

See #17636.
This commit is contained in:
Artur Wieczorek 2016-08-21 21:03:16 +02:00
parent 78f00da98a
commit 12eaa61930
2 changed files with 15 additions and 1 deletions

View File

@ -98,6 +98,7 @@ All (GUI):
- Fix displaying validation errors for numeric wxPropertyGrid properties. - Fix displaying validation errors for numeric wxPropertyGrid properties.
- Add wxSYS_CARET_{ON,OFF,TIMEOUT}_MSEC system settings (brawer). - Add wxSYS_CARET_{ON,OFF,TIMEOUT}_MSEC system settings (brawer).
- Add wxGraphicsContext::GetClipBox(). - Add wxGraphicsContext::GetClipBox().
- Fix wxGCDC::Clear() for rotated graphics context.
wxGTK: wxGTK:

View File

@ -1189,17 +1189,30 @@ wxCoord wxGCDCImpl::GetCharHeight(void) const
void wxGCDCImpl::Clear(void) void wxGCDCImpl::Clear(void)
{ {
wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") ); wxCHECK_RET( IsOk(), wxT("wxGCDC(cg)::Clear - invalid DC") );
// TODO better implementation / incorporate size info into wxGCDC or context
m_graphicContext->SetBrush( m_backgroundBrush ); m_graphicContext->SetBrush( m_backgroundBrush );
wxPen p = *wxTRANSPARENT_PEN; wxPen p = *wxTRANSPARENT_PEN;
m_graphicContext->SetPen( p ); m_graphicContext->SetPen( p );
wxCompositionMode formerMode = m_graphicContext->GetCompositionMode(); wxCompositionMode formerMode = m_graphicContext->GetCompositionMode();
m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE); m_graphicContext->SetCompositionMode(wxCOMPOSITION_SOURCE);
#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.
// Note: Legacy implmentation might not work work properly
// if graphics context is rotated
// TODO: Do the tests of wxMacCoreGraphicsContext::GetClipBox
// and switch to the implmenentation used by other renderers (code below).
//
// maximum positive coordinate Cairo can handle is 2^23 - 1 // maximum positive coordinate Cairo can handle is 2^23 - 1
// Use a value slightly less than this to be sure we avoid the limit // Use a value slightly less than this to be sure we avoid the limit
DoDrawRectangle( DoDrawRectangle(
DeviceToLogicalX(0), DeviceToLogicalY(0), DeviceToLogicalX(0), DeviceToLogicalY(0),
DeviceToLogicalXRel(0x800000 - 64), DeviceToLogicalYRel(0x800000 - 64)); DeviceToLogicalXRel(0x800000 - 64), DeviceToLogicalYRel(0x800000 - 64));
#else
double x, y, w, h;
m_graphicContext->GetClipBox(&x, &y, &w, &h);
m_graphicContext->DrawRectangle(x, y, w, h);
#endif // __WXOSX__ / !__WXOSX__
m_graphicContext->SetCompositionMode(formerMode); m_graphicContext->SetCompositionMode(formerMode);
m_graphicContext->SetPen( m_pen ); m_graphicContext->SetPen( m_pen );
m_graphicContext->SetBrush( m_brush ); m_graphicContext->SetBrush( m_brush );