Fix calculating the extent of clipping box (wxDC, GTK).

While setting a clipping region there is necessary to intersect it either with current clipping region location if such region exists or with wxDC surface extents if no clipping region is set. This way effective clipping box will be always inside the wxDC surface. Effective clipping box can be an empty region.
Clipping box parameters are calculated and stored in logical coordinates.
This commit is contained in:
Artur Wieczorek
2016-07-17 00:09:33 +02:00
parent c845b953a2
commit 902b9a5c56
3 changed files with 41 additions and 7 deletions

View File

@@ -74,7 +74,6 @@ All:
- Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi).
- Handle strings with embedded NULs in wxDataStream (Nitch).
- Don't crash in wxTextFile::GetLastLine() if the file is empty (crohr).
- Many fixes and improvements in Direct2D, Cairo, and GDI+ graphics renderers.
All (GUI):
@@ -92,6 +91,8 @@ All (GUI):
- Implement auto complete in generic wxSearchCtrl (Eric Jensen).
- Fix preserving selection when changing selection mode in wxGrid (jonkraber).
- Fix wxTextEntry::SetHint() with wxTE_PASSWORD in generic implementation.
- Many fixes and improvements in Direct2D, Cairo, and GDI+ graphics renderers.
- Fix and unify clipping region support for MSW and GTK+.
wxGTK:

View File

@@ -398,11 +398,43 @@ wxGTKDCImpl::~wxGTKDCImpl()
void wxGTKDCImpl::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
{
m_clipping = TRUE;
m_clipX1 = x;
m_clipY1 = y;
m_clipX2 = x + width;
m_clipY2 = y + height;
wxASSERT_MSG( width >= 0 && height >= 0,
"Clipping box size values cannot be negative" );
wxRect newRegion(x, y, width, height);
wxRect clipRegion;
if ( m_clipping )
{
// New clipping box is an intersection
// of required clipping box and the current one.
wxRect curRegion(m_clipX1, m_clipY1, m_clipX2 - m_clipX1, m_clipY2 - m_clipY1);
clipRegion = curRegion.Intersect(newRegion);
}
else
{
// Effective clipping box is an intersection
// of required clipping box and DC surface.
int dcWidth, dcHeight;
DoGetSize(&dcWidth, &dcHeight);
wxRect dcRect(DeviceToLogicalX(0), DeviceToLogicalY(0),
DeviceToLogicalXRel(dcWidth), DeviceToLogicalYRel(dcHeight));
clipRegion = dcRect.Intersect(newRegion);
m_clipping = true;
}
if ( clipRegion.IsEmpty() )
{
m_clipX1 = m_clipY1 = m_clipX2 = m_clipY2 = 0;
}
else
{
m_clipX1 = clipRegion.GetLeftTop().x;
m_clipY1 = clipRegion.GetLeftTop().y;
m_clipX2 = clipRegion.GetBottomRight().x + 1;
m_clipY2 = clipRegion.GetBottomRight().y + 1;
}
}
// ---------------------------------------------------------------------------

View File

@@ -1918,7 +1918,8 @@ void wxWindowDCImpl::DoSetDeviceClippingRegion( const wxRegion &region )
wxCoord xx, yy, ww, hh;
m_currentClippingRegion.GetBox( xx, yy, ww, hh );
wxGTKDCImpl::DoSetClippingRegion( xx, yy, ww, hh );
wxGTKDCImpl::DoSetClippingRegion(DeviceToLogicalX(xx), DeviceToLogicalY(yy),
DeviceToLogicalXRel(ww), DeviceToLogicalYRel(hh));
GdkRegion* gdkRegion = m_currentClippingRegion.GetRegion();
gdk_gc_set_clip_region(m_penGC, gdkRegion);