From 669ac9d6f57c4535f10c5e4eaf90cc3354d9dbc7 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 19 Jun 2014 18:03:17 +0200 Subject: [PATCH] BRegion: add ScaleBy method. * Is there a reason to not have it? --- headers/os/interface/Region.h | 1 + headers/private/interface/clipping.h | 10 ++++++++++ src/kits/interface/Region.cpp | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/headers/os/interface/Region.h b/headers/os/interface/Region.h index 9c1e1b0b86..07ad81e348 100644 --- a/headers/os/interface/Region.h +++ b/headers/os/interface/Region.h @@ -59,6 +59,7 @@ public: void OffsetBy(const BPoint& point); void OffsetBy(int32 x, int32 y); + void ScaleBy(float x, float y); void MakeEmpty(); diff --git a/headers/private/interface/clipping.h b/headers/private/interface/clipping.h index cbbeaab024..1d53c420d5 100644 --- a/headers/private/interface/clipping.h +++ b/headers/private/interface/clipping.h @@ -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) diff --git a/src/kits/interface/Region.cpp b/src/kits/interface/Region.cpp index 678d34bc6c..1ce133c8e9 100644 --- a/src/kits/interface/Region.cpp +++ b/src/kits/interface/Region.cpp @@ -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