BRegion: add ScaleBy method.

* Is there a reason to not have it?
This commit is contained in:
Adrien Destugues
2014-06-19 18:05:14 +02:00
parent 3fc9fd5624
commit 669ac9d6f5
3 changed files with 28 additions and 0 deletions
+1
View File
@@ -59,6 +59,7 @@ public:
void OffsetBy(const BPoint& point);
void OffsetBy(int32 x, int32 y);
void ScaleBy(float x, float y);
void MakeEmpty();
+10
View File
@@ -81,6 +81,16 @@ offset_rect(clipping_rect &rect, int32 x, int32 y)
}
static inline void
scale_rect(clipping_rect& rect, float x, float y)
{
rect.left = (int)(rect.left * x);
rect.top = (int)(rect.top * y);
rect.right = (int)(rect.right * x);
rect.bottom = (int)(rect.bottom * y);
}
// Converts the given clipping_rect to a BRect
static inline BRect
to_BRect(const clipping_rect &rect)
+17
View File
@@ -306,6 +306,23 @@ BRegion::OffsetBy(int32 x, int32 y)
}
void
BRegion::ScaleBy(float x, float y)
{
if (x == 1.0 && y == 1.0)
return;
if (fCount > 0) {
if (fData != &fBounds) {
for (int32 i = 0; i < fCount; i++)
scale_rect(fData[i], x, y);
}
scale_rect(fBounds, x, y);
}
}
// Empties the region, so that it doesn't include any rect, and invalidates
// its bounds.
void