Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsRegionQt Class Reference

#include <nsRegionQt.h>

Inheritance diagram for nsRegionQt:
Inheritance graph
[legend]
Collaboration diagram for nsRegionQt:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsRegionQt ()
virtual ~nsRegionQt ()
virtual NS_DECL_ISUPPORTS nsresult Init ()
virtual void SetTo (const nsIRegion &aRegion)
 copy operator equivalent that takes another region
virtual void SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 copy operator equivalent that takes a rect
void SetTo (const nsRegionQt *aRegion)
virtual void Intersect (const nsIRegion &aRegion)
 destructively intersect another region with this one
virtual void Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively intersect a rect with this region
virtual void Union (const nsIRegion &aRegion)
 destructively union another region with this one
virtual void Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively union a rect with this region
virtual void Subtract (const nsIRegion &aRegion)
 destructively subtract another region with this one
virtual void Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively subtract a rect from this region
virtual PRBool IsEmpty (void)
 is this region empty? i.e.
virtual PRBool IsEqual (const nsIRegion &aRegion)
 == operator equivalent i.e.
virtual void GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
 returns the bounding box of the region i.e.
virtual void Offset (PRInt32 aXOffset, PRInt32 aYOffset)
 offsets the region in x and y
virtual PRBool ContainsRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 does the region intersect the rectangle?
NS_IMETHOD GetRects (nsRegionRectSet **aRects)
 get the set of rects which make up this region.
NS_IMETHOD FreeRects (nsRegionRectSet *aRects)
 Free a rect set returned by GetRects.
NS_IMETHOD GetNativeRegion (void *&aRegion) const
 Get the native region that this nsIRegion represents.
NS_IMETHOD GetRegionComplexity (nsRegionComplexity &aComplexity) const
 Get the complexity of the region as defined by the nsRegionComplexity enum.
NS_IMETHOD GetNumRects (PRUint32 *aRects) const
 get the number of rects which make up this region.

Private Member Functions

virtual void SetRegionEmpty ()

Private Attributes

QRegion mRegion

Detailed Description

Definition at line 48 of file nsRegionQt.h.


Constructor & Destructor Documentation

Definition at line 48 of file nsRegionQt.cpp.

                       : mRegion()
{
}
nsRegionQt::~nsRegionQt ( ) [virtual]

Definition at line 52 of file nsRegionQt.cpp.

{
}

Member Function Documentation

PRBool nsRegionQt::ContainsRect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

does the region intersect the rectangle?

Parameters:
rectto check for containment
Returns:
true if the region intersects the rect

Implements nsIRegion.

Definition at line 146 of file nsRegionQt.cpp.

{
    return mRegion.contains(QRect(aX, aY, aWidth, aHeight));
}

Free a rect set returned by GetRects.

Parameters:
aRectsrects to free
Returns:
error status

Implements nsIRegion.

Definition at line 194 of file nsRegionQt.cpp.

{
    if (nsnull != aRects) {
        PR_Free((void*)aRects);
    }
    return NS_OK;
}
void nsRegionQt::GetBoundingBox ( PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight 
) [virtual]

returns the bounding box of the region i.e.

the smallest rectangle that completely contains the region.

Parameters:
aXout parameter for xoffset of bounding rect for region
aYout parameter for yoffset of bounding rect for region
aWidthout parameter for width of bounding rect for region
aHeightout parameter for height of bounding rect for region
Returns:
void

Implements nsIRegion.

Definition at line 130 of file nsRegionQt.cpp.

{
    QRect rect = mRegion.boundingRect();

    *aX = rect.x();
    *aY = rect.y();
    *aWidth = rect.width();
    *aHeight = rect.height();
}
NS_IMETHODIMP nsRegionQt::GetNativeRegion ( void *&  aRegion) const [virtual]

Get the native region that this nsIRegion represents.

Parameters:
aRegionout parameter for native region handle
Returns:
error status

Implements nsIRegion.

Definition at line 202 of file nsRegionQt.cpp.

{
    aRegion = (void*)&mRegion;
    return NS_OK;
}
NS_IMETHODIMP nsRegionQt::GetNumRects ( PRUint32 aRects) const [virtual]

get the number of rects which make up this region.

Parameters:
aRectsout parameter containing the number of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 225 of file nsRegionQt.cpp.

{
  *aRects = mRegion.rects().size();

  return NS_OK;
}

get the set of rects which make up this region.

the aRects parameter must be freed by calling FreeRects before the region is deleted. aRects may be passed in again when requesting the rect list as a recycling method.

Parameters:
aRectsout parameter containing set of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 152 of file nsRegionQt.cpp.

{
    NS_ASSERTION(!(nsnull == aRects), "bad ptr");

    QMemArray<QRect>   array = mRegion.rects();
    PRUint32        size  = array.size();
    nsRegionRect    *rect  = nsnull;
    nsRegionRectSet *rects = *aRects;

    if (nsnull == rects || rects->mRectsLen < (PRUint32)size) {
        void *buf = PR_Realloc(rects,
                               sizeof(nsRegionRectSet)
                               + (sizeof(nsRegionRect) * (size - 1)));

        if (nsnull == buf) {
            if (nsnull != rects)
                rects->mNumRects = 0;
            return NS_OK;
        }
        rects = (nsRegionRectSet*)buf;
        rects->mRectsLen = size;
    }
    rects->mNumRects = size;
    rects->mArea = 0;
    rect = &rects->mRects[0];

    for (PRUint32 i = 0; i < size; i++) {
        const QRect &qRect = array.at(i);

        rect->x = qRect.x();
        rect->y = qRect.y();
        rect->width = qRect.width();
        rect->height = qRect.height();

        rects->mArea += rect->width * rect->height;

        rect++;
    }
    *aRects = rects;
    return NS_OK;
}

Here is the call graph for this function:

Get the complexity of the region as defined by the nsRegionComplexity enum.

Parameters:
aComplexityout parameter for region complexity
Returns:
error status

Implements nsIRegion.

Definition at line 208 of file nsRegionQt.cpp.

{
    // cast to avoid const-ness problems on some compilers
    if (mRegion.isEmpty()) {
        aComplexity = eRegionComplexity_empty;
    }
    else {
        aComplexity = eRegionComplexity_rect;
    }
    return NS_OK;
}
nsresult nsRegionQt::Init ( void  ) [virtual]

Implements nsIRegion.

Definition at line 58 of file nsRegionQt.cpp.

{
    mRegion = QRegion();
    return NS_OK;
}
void nsRegionQt::Intersect ( const nsIRegion aRegion) [virtual]

destructively intersect another region with this one

Parameters:
regionto intersect
Returns:
void

Implements nsIRegion.

Definition at line 81 of file nsRegionQt.cpp.

{
    nsRegionQt *pRegion = (nsRegionQt*)&aRegion;

    mRegion = mRegion.intersect(pRegion->mRegion);
}
void nsRegionQt::Intersect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively intersect a rect with this region

Parameters:
aXxoffset of rect to intersect with region
aYyoffset of rect to intersect with region
aWidthwidth of rect to intersect with region
aHeightheight of rect to intersect with region
Returns:
void

Implements nsIRegion.

Definition at line 88 of file nsRegionQt.cpp.

{
    mRegion = mRegion.intersect(QRect(aX, aY, aWidth, aHeight));
}
PRBool nsRegionQt::IsEmpty ( void  ) [virtual]

is this region empty? i.e.

does it contain any pixels

Parameters:
none
Returns:
returns whether the region is empty

Implements nsIRegion.

Definition at line 118 of file nsRegionQt.cpp.

{
    return mRegion.isEmpty();
}
PRBool nsRegionQt::IsEqual ( const nsIRegion aRegion) [virtual]

== operator equivalent i.e.

do the regions contain exactly the same pixels

Parameters:
regionto compare
Returns:
whether the regions are identical

Implements nsIRegion.

Definition at line 123 of file nsRegionQt.cpp.

{
    nsRegionQt *pRegion = (nsRegionQt*)&aRegion;

    return (mRegion == pRegion->mRegion);
}
void nsRegionQt::Offset ( PRInt32  aXOffset,
PRInt32  aYOffset 
) [virtual]

offsets the region in x and y

Parameters:
xoffsetpixel offset in x
yoffsetpixel offset in y
Returns:
void

Implements nsIRegion.

Definition at line 141 of file nsRegionQt.cpp.

{
    mRegion.translate(aXOffset, aYOffset);
}
void nsRegionQt::SetRegionEmpty ( ) [private, virtual]

Definition at line 220 of file nsRegionQt.cpp.

{
    mRegion = QRegion();
}
void nsRegionQt::SetTo ( const nsIRegion aRegion) [virtual]

copy operator equivalent that takes another region

Parameters:
regionto copy
Returns:
void

Implements nsIRegion.

Definition at line 64 of file nsRegionQt.cpp.

{
    nsRegionQt *pRegion = (nsRegionQt*)&aRegion;

    mRegion = pRegion->mRegion;
}
void nsRegionQt::SetTo ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

copy operator equivalent that takes a rect

Parameters:
aXxoffset of rect to set region to
aYyoffset of rect to set region to
aWidthwidth of rect to set region to
aHeightheight of rect to set region to
Returns:
void

Implements nsIRegion.

Definition at line 76 of file nsRegionQt.cpp.

{
    mRegion = QRegion(aX, aY, aWidth, aHeight);;
}

Definition at line 71 of file nsRegionQt.cpp.

{
    mRegion = aRegion->mRegion;
}
void nsRegionQt::Subtract ( const nsIRegion aRegion) [virtual]

destructively subtract another region with this one

Parameters:
regionto subtract
Returns:
void

Implements nsIRegion.

Definition at line 106 of file nsRegionQt.cpp.

{
    nsRegionQt *pRegion = (nsRegionQt*)&aRegion;

    mRegion = mRegion.subtract(pRegion->mRegion);
}
void nsRegionQt::Subtract ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively subtract a rect from this region

Parameters:
aXxoffset of rect to subtract with region
aYyoffset of rect to subtract with region
aWidthwidth of rect to subtract with region
aHeightheight of rect to subtract with region
Returns:
void

Implements nsIRegion.

Definition at line 113 of file nsRegionQt.cpp.

{
    mRegion = mRegion.subtract(QRect(aX, aY, aWidth, aHeight));
}
void nsRegionQt::Union ( const nsIRegion aRegion) [virtual]

destructively union another region with this one

Parameters:
regionto union
Returns:
void

Implements nsIRegion.

Definition at line 94 of file nsRegionQt.cpp.

{
    nsRegionQt *pRegion = (nsRegionQt*)&aRegion;

    mRegion = mRegion.unite(pRegion->mRegion);
}
void nsRegionQt::Union ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively union a rect with this region

Parameters:
aXxoffset of rect to union with region
aYyoffset of rect to union with region
aWidthwidth of rect to union with region
aHeightheight of rect to union with region
Returns:
void

Implements nsIRegion.

Definition at line 101 of file nsRegionQt.cpp.

{
    mRegion = mRegion.unite(QRect(aX, aY, aWidth, aHeight));
}

Member Data Documentation

QRegion nsRegionQt::mRegion [private]

Definition at line 82 of file nsRegionQt.h.


The documentation for this class was generated from the following files: