Add a method to subdivide the window into regular grid.

Will be used by wobbly windows effect.

svn path=/trunk/KDE/kdebase/workspace/; revision=781469
This commit is contained in:
Rivo Laks 2008-03-02 22:28:50 +00:00
parent 23ff1daaaa
commit 3f581b4d0c
2 changed files with 47 additions and 0 deletions

View file

@ -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 ];

View file

@ -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;