diff --git a/lib/kwineffects.cpp b/lib/kwineffects.cpp index 81b6ca34e3..678ef76a57 100644 --- a/lib/kwineffects.cpp +++ b/lib/kwineffects.cpp @@ -614,6 +614,52 @@ WindowQuadList WindowQuadList::makeGrid( int maxquadsize ) const return ret; } +WindowQuadList WindowQuadList::makeRegularGrid( int xSubdivisions, int ySubdivisions ) const + { + if( empty()) + return *this; + // find the bounding rectangle + double left = first().left(); + double right = first().right(); + double top = first().top(); + double bottom = first().bottom(); + foreach( WindowQuad quad, *this ) + { +#ifndef NDEBUG + if( quad.isTransformed()) + kFatal( 1212 ) << "Splitting quads is allowed only in pre-paint calls!" ; +#endif + left = qMin( left, quad.left()); + right = qMax( right, quad.right()); + top = qMin( top, quad.top()); + bottom = qMax( bottom, quad.bottom()); + } + + double xincrement = (right - left) / xSubdivisions; + double yincrement = (bottom - top) / ySubdivisions; + WindowQuadList ret; + for( double y = top; + y < bottom; + y += yincrement ) + { + for( double x = left; + x < right; + x += xincrement) + { + foreach( WindowQuad quad, *this ) + { + if( QRectF( QPointF( quad.left(), quad.top()), QPointF( quad.right(), quad.bottom())) + .intersects( QRectF( x, y, xincrement, yincrement ))) + { + ret.append( quad.makeSubQuad( qMax( x, quad.left()), qMax( y, quad.top()), + qMin( quad.right(), x + xincrement ), qMin( quad.bottom(), y + yincrement ))); + } + } + } + } + return ret; + } + void WindowQuadList::makeArrays( float** vertices, float** texcoords ) const { *vertices = new float[ count() * 4 * 2 ]; diff --git a/lib/kwineffects.h b/lib/kwineffects.h index b7321ff741..4806e5e4c5 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -759,6 +759,7 @@ class KWIN_EXPORT WindowQuadList WindowQuadList splitAtX( double x ) const; WindowQuadList splitAtY( double y ) const; WindowQuadList makeGrid( int maxquadsize ) const; + WindowQuadList makeRegularGrid( int xSubdivisions, int ySubdivisions ) const; WindowQuadList select( WindowQuadType type ) const; WindowQuadList filterOut( WindowQuadType type ) const; bool smoothNeeded() const;