Fixed an allocation bug in BRegion::set_size, started to comment BRegion with Doxygen (just the public methods and some friend functions for now). Added BRegion to the build.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3755 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+179
-11
@@ -4,6 +4,11 @@
|
||||
#include <clipping.h>
|
||||
|
||||
/* friend functions */
|
||||
|
||||
/*! \brief zeroes the given region, setting its rect count to 0,
|
||||
and invalidating its bound rectangle.
|
||||
\param region The region to be zeroed.
|
||||
*/
|
||||
void
|
||||
zero_region(BRegion *region)
|
||||
{
|
||||
@@ -28,14 +33,49 @@ clear_region(BRegion *region)
|
||||
region->bound.bottom = 0xf0000001;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/*! \brief Cleanup the region vertically.
|
||||
\param region The region to be cleaned.
|
||||
*/
|
||||
void
|
||||
cleanup_region_1(BRegion *region)
|
||||
{
|
||||
clipping_rect testRect =
|
||||
{
|
||||
1, 1,
|
||||
-1, -2
|
||||
};
|
||||
|
||||
int32 newCount = -1;
|
||||
|
||||
if (region->count > 0) {
|
||||
for (int32 x = 0; x < region->count; x++) {
|
||||
clipping_rect rect = region->data[x];
|
||||
|
||||
if ((rect.left == testRect.left)
|
||||
&& (rect.right == testRect.right)
|
||||
&& (rect.top == testRect.bottom + 1)) {
|
||||
ASSERT(newCount >= 0);
|
||||
|
||||
region->data[newCount].bottom = rect.bottom;
|
||||
|
||||
} else {
|
||||
newCount++;
|
||||
region->data[newCount] = region->data[x];
|
||||
testRect = region->data[x];
|
||||
}
|
||||
}
|
||||
region->count = newCount + 1;
|
||||
|
||||
cleanup_region_horizontal(region);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*! \brief Cleanup the region, by merging rects that can be merged.
|
||||
\param region The region to be cleaned.
|
||||
*/
|
||||
void
|
||||
cleanup_region(BRegion *region)
|
||||
{
|
||||
@@ -49,7 +89,10 @@ cleanup_region(BRegion *region)
|
||||
}
|
||||
|
||||
|
||||
// Sort the given rects by their top value
|
||||
/*! \brief Sorts the given rects by their top value.
|
||||
\param rects A pointer to an array of clipping_rects.
|
||||
\param count The number of rectangles in the array.
|
||||
*/
|
||||
void
|
||||
sort_rects(clipping_rect *rects, long count)
|
||||
{
|
||||
@@ -84,14 +127,42 @@ sort_trans(long *lptr1, long *lptr2, long count)
|
||||
PRINT(("%s\n", __PRETTY_FUNCTION__));
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
/*! \brief Cleanup the region horizontally.
|
||||
\param region The region to be cleaned.
|
||||
*/
|
||||
void
|
||||
cleanup_region_horizontal(BRegion *region)
|
||||
{
|
||||
clipping_rect testRect =
|
||||
{
|
||||
1, 1,
|
||||
-2, -1
|
||||
};
|
||||
|
||||
int32 newCount = -1;
|
||||
|
||||
for (int x = 0; x < region->count; x++) {
|
||||
clipping_rect rect = region->data[x];
|
||||
if ((rect.top == testRect.top) && (rect.bottom == testRect.bottom)
|
||||
&& (rect.left == testRect.right + 1)) {
|
||||
ASSERT(newCount >= 0);
|
||||
region->data[newCount].right = rect.right;
|
||||
|
||||
} else {
|
||||
newCount++;
|
||||
region->data[newCount] = rect;
|
||||
}
|
||||
testRect = region->data[newCount];
|
||||
}
|
||||
region->count = newCount + 1;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*! \brief Copy a region to another.
|
||||
\param source The region to be copied.
|
||||
\param dest The destination region.
|
||||
*/
|
||||
void
|
||||
copy_region(BRegion *source, BRegion *dest)
|
||||
{
|
||||
@@ -115,6 +186,11 @@ copy_region(BRegion *source, BRegion *dest)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Copy a region to another, allocating some additional memory in the destination region.
|
||||
\param source The region to be copied.
|
||||
\param dest The destination region.
|
||||
\param count Amount of additional memory to be allocated in the destination region.
|
||||
*/
|
||||
void
|
||||
copy_region_n(BRegion *source, BRegion *dest, long count)
|
||||
{
|
||||
@@ -386,6 +462,9 @@ sub_region(BRegion *first, BRegion *second, BRegion *dest)
|
||||
|
||||
|
||||
/* BRegion class */
|
||||
|
||||
/*! \brief Initializes a region. The region will have no rects, and its bound will be invalid.
|
||||
*/
|
||||
BRegion::BRegion()
|
||||
:data(NULL)
|
||||
{
|
||||
@@ -396,6 +475,9 @@ BRegion::BRegion()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Initializes a region to be a copy of another.
|
||||
\param region The region to copy.
|
||||
*/
|
||||
BRegion::BRegion(const BRegion ®ion)
|
||||
:data(NULL)
|
||||
{
|
||||
@@ -414,6 +496,9 @@ BRegion::BRegion(const BRegion ®ion)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Initializes a region to contain a BRect.
|
||||
\param rect The BRect to set the region to.
|
||||
*/
|
||||
BRegion::BRegion(const BRect rect)
|
||||
:data(NULL)
|
||||
{
|
||||
@@ -424,13 +509,17 @@ BRegion::BRegion(const BRect rect)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*! \brief Frees the allocated memory.
|
||||
*/
|
||||
BRegion::~BRegion()
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Returns the bounds of the region.
|
||||
\return A BRect which represents the bounds of the region.
|
||||
*/
|
||||
BRect
|
||||
BRegion::Frame() const
|
||||
{
|
||||
@@ -438,6 +527,9 @@ BRegion::Frame() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Returns the bounds of the region as a clipping_rect (which has integer coordinates).
|
||||
\return A clipping_rect which represents the bounds of the region.
|
||||
*/
|
||||
clipping_rect
|
||||
BRegion::FrameInt() const
|
||||
{
|
||||
@@ -445,6 +537,11 @@ BRegion::FrameInt() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Returns the regions's BRect at the given index.
|
||||
\param index The index (zero based) of the wanted rectangle.
|
||||
\return If the given index is valid, it returns the BRect at that index,
|
||||
otherwise, it returns an invalid BRect.
|
||||
*/
|
||||
BRect
|
||||
BRegion::RectAt(int32 index)
|
||||
{
|
||||
@@ -455,6 +552,11 @@ BRegion::RectAt(int32 index)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Returns the regions's clipping_rect at the given index.
|
||||
\param index The index (zero based) of the wanted rectangle.
|
||||
\return If the given index is valid, it returns the clipping_rect at that index,
|
||||
otherwise, it returns an invalid clipping_rect.
|
||||
*/
|
||||
clipping_rect
|
||||
BRegion::RectAtInt(int32 index)
|
||||
{
|
||||
@@ -467,6 +569,9 @@ BRegion::RectAtInt(int32 index)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Counts the region rects.
|
||||
\return An int32 which is the total number of rects in the region.
|
||||
*/
|
||||
int32
|
||||
BRegion::CountRects()
|
||||
{
|
||||
@@ -474,6 +579,9 @@ BRegion::CountRects()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Set the region to contain just the given BRect.
|
||||
\param newBounds A BRect.
|
||||
*/
|
||||
void
|
||||
BRegion::Set(BRect newBounds)
|
||||
{
|
||||
@@ -481,6 +589,9 @@ BRegion::Set(BRect newBounds)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Set the region to contain just the given clipping_rect.
|
||||
\param newBounds A clipping_rect.
|
||||
*/
|
||||
void
|
||||
BRegion::Set(clipping_rect newBounds)
|
||||
{
|
||||
@@ -489,15 +600,17 @@ BRegion::Set(clipping_rect newBounds)
|
||||
if (valid_rect(newBounds)) {
|
||||
count = 1;
|
||||
data[0] = newBounds;
|
||||
bound = newBounds;
|
||||
}
|
||||
else
|
||||
count = 0;
|
||||
|
||||
// Set bounds anyway.
|
||||
bound = newBounds;
|
||||
zero_region(this);
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Check if the region has any area in common with the given BRect.
|
||||
\param rect The BRect to check the region against to.
|
||||
\return \ctrue if the region has any area in common with the BRect, \cfalse if not.
|
||||
*/
|
||||
bool
|
||||
BRegion::Intersects(BRect rect) const
|
||||
{
|
||||
@@ -505,6 +618,10 @@ BRegion::Intersects(BRect rect) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Check if the region has any area in common with the given clipping_rect.
|
||||
\param rect The clipping_rect to check the region against to.
|
||||
\return \ctrue if the region has any area in common with the clipping_rect, \cfalse if not.
|
||||
*/
|
||||
bool
|
||||
BRegion::Intersects(clipping_rect rect) const
|
||||
{
|
||||
@@ -520,6 +637,10 @@ BRegion::Intersects(clipping_rect rect) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Check if the region contains the given BPoint.
|
||||
\param pt The BPoint to be checked.
|
||||
\return \ctrue if the region contains the BPoint, \cfalse if not.
|
||||
*/
|
||||
bool
|
||||
BRegion::Contains(BPoint pt) const
|
||||
{
|
||||
@@ -536,6 +657,11 @@ BRegion::Contains(BPoint pt) const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Check if the region contains the given coordinates.
|
||||
\param x The \cx coordinate of the point to be checked.
|
||||
\param y The \cy coordinate of the point to be checked.
|
||||
\return \ctrue if the region contains the point, \cfalse if not.
|
||||
*/
|
||||
bool
|
||||
BRegion::Contains(int32 x, int32 y)
|
||||
{
|
||||
@@ -551,6 +677,8 @@ BRegion::Contains(int32 x, int32 y)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Prints the BRegion to stdout.
|
||||
*/
|
||||
void
|
||||
BRegion::PrintToStream() const
|
||||
{
|
||||
@@ -564,6 +692,10 @@ BRegion::PrintToStream() const
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Offses all region's rects, and bounds by the given values.
|
||||
\param dh The horizontal offset.
|
||||
\param dv The vertical offset.
|
||||
*/
|
||||
void
|
||||
BRegion::OffsetBy(int32 dh, int32 dv)
|
||||
{
|
||||
@@ -582,6 +714,8 @@ BRegion::OffsetBy(int32 dh, int32 dv)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Empties the region, so that it doesn't include any rect, and invalidates its bounds.
|
||||
*/
|
||||
void
|
||||
BRegion::MakeEmpty()
|
||||
{
|
||||
@@ -589,6 +723,9 @@ BRegion::MakeEmpty()
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, so that it includes the given BRect.
|
||||
\param rect The BRect to be included by the region.
|
||||
*/
|
||||
void
|
||||
BRegion::Include(BRect rect)
|
||||
{
|
||||
@@ -596,6 +733,9 @@ BRegion::Include(BRect rect)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, so that it includes the given clipping_rect.
|
||||
\param rect The clipping_rect to be included by the region.
|
||||
*/
|
||||
void
|
||||
BRegion::Include(clipping_rect rect)
|
||||
{
|
||||
@@ -609,6 +749,9 @@ BRegion::Include(clipping_rect rect)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, so that it includes the area of the given region.
|
||||
\param region The region to be included.
|
||||
*/
|
||||
void
|
||||
BRegion::Include(const BRegion *region)
|
||||
{
|
||||
@@ -619,6 +762,9 @@ BRegion::Include(const BRegion *region)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, excluding the area represented by the given BRect.
|
||||
\param rect The BRect to be excluded.
|
||||
*/
|
||||
void
|
||||
BRegion::Exclude(BRect rect)
|
||||
{
|
||||
@@ -626,6 +772,9 @@ BRegion::Exclude(BRect rect)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, excluding the area represented by the given clipping_rect.
|
||||
\param rect The clipping_rect to be excluded.
|
||||
*/
|
||||
void
|
||||
BRegion::Exclude(clipping_rect rect)
|
||||
{
|
||||
@@ -638,6 +787,9 @@ BRegion::Exclude(clipping_rect rect)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, excluding the area contained in the given BRegion.
|
||||
\param region The BRegion to be excluded.
|
||||
*/
|
||||
void
|
||||
BRegion::Exclude(const BRegion *region)
|
||||
{
|
||||
@@ -648,6 +800,9 @@ BRegion::Exclude(const BRegion *region)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region, so that it will contain just the area in common with the given BRegion.
|
||||
\param region the BRegion to intersect to.
|
||||
*/
|
||||
void
|
||||
BRegion::IntersectWith(const BRegion *region)
|
||||
{
|
||||
@@ -658,6 +813,10 @@ BRegion::IntersectWith(const BRegion *region)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Modifies the region to be a copy of the given BRegion.
|
||||
\param region the BRegion to copy.
|
||||
\return This function always returns \c *this.
|
||||
*/
|
||||
BRegion &
|
||||
BRegion::operator=(const BRegion ®ion)
|
||||
{
|
||||
@@ -679,6 +838,12 @@ BRegion::operator=(const BRegion ®ion)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Adds a rect to the region.
|
||||
\param rect The clipping_rect to be added.
|
||||
|
||||
Adds the given rect to the region, merging it with another already contained in the region,
|
||||
if possible. Recalculate the region's bounds if needed.
|
||||
*/
|
||||
void
|
||||
BRegion::_AddRect(clipping_rect rect)
|
||||
{
|
||||
@@ -719,7 +884,7 @@ BRegion::_AddRect(clipping_rect rect)
|
||||
// We weren't lucky.... just add the rect as a new one
|
||||
if (add) {
|
||||
if (data_size <= count)
|
||||
set_size(16);
|
||||
set_size(data_size + 16);
|
||||
|
||||
data[count] = rect;
|
||||
|
||||
@@ -741,6 +906,9 @@ BRegion::_AddRect(clipping_rect rect)
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Reallocate the memory in the region.
|
||||
\param new_size The amount of rectangles that the region could contain.
|
||||
*/
|
||||
void
|
||||
BRegion::set_size(long new_size)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ INTERFACE_KIT_SOURCE =
|
||||
Polygon.cpp
|
||||
RadioButton.cpp
|
||||
Rect.cpp
|
||||
Region.cpp
|
||||
ScrollBar.cpp
|
||||
StatusBar.cpp
|
||||
StringView.cpp
|
||||
|
||||
Reference in New Issue
Block a user