diff options
author | 2012-05-07 13:49:17 -0700 | |
---|---|---|
committer | 2012-05-07 15:25:52 -0700 | |
commit | 59332804306c054082a39e9b004146bd03ae1d30 (patch) | |
tree | 1f6f9489a157b30a586467663e8ce4648bfdc457 | |
parent | 3410a85b15a4d2579b5e77144f275a30ad880a65 (diff) |
libui: add the Rect::transform method
This change adds a method to Rect to transform a rectangle by a graphics HAL
transform.
Change-Id: Ic0d0988e731bdb5662faee41a5927b1242891658
Bug: 6299171
-rw-r--r-- | include/ui/Rect.h | 10 | ||||
-rw-r--r-- | libs/ui/Rect.cpp | 21 |
2 files changed, 30 insertions, 1 deletions
diff --git a/include/ui/Rect.h b/include/ui/Rect.h index 9e98bc5620..bd820618f3 100644 --- a/include/ui/Rect.h +++ b/include/ui/Rect.h @@ -136,10 +136,18 @@ public: void translate(int32_t dx, int32_t dy) { // legacy, don't use. offsetBy(dx, dy); } - + Rect& offsetTo(int32_t x, int32_t y); Rect& offsetBy(int32_t x, int32_t y); bool intersect(const Rect& with, Rect* result) const; + + // Create a new Rect by transforming this one using a graphics HAL + // transform. This rectangle is defined in a coordinate space starting at + // the origin and extending to (width, height). If the transform includes + // a ROT90 then the output rectangle is defined in a space extending to + // (height, width). Otherwise the output rectangle is in the same space as + // the input. + Rect transform(uint32_t xform, int32_t width, int32_t height); }; ANDROID_BASIC_TYPES_TRAITS(Rect) diff --git a/libs/ui/Rect.cpp b/libs/ui/Rect.cpp index 5694e00002..65fe5f9da8 100644 --- a/libs/ui/Rect.cpp +++ b/libs/ui/Rect.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <system/graphics.h> #include <ui/Rect.h> namespace android { @@ -92,4 +93,24 @@ bool Rect::intersect(const Rect& with, Rect* result) const return !(result->isEmpty()); } +Rect Rect::transform(uint32_t xform, int32_t width, int32_t height) { + Rect result(*this); + if (xform & HAL_TRANSFORM_FLIP_H) { + result = Rect(width - result.right, result.top, + width - result.left, result.bottom); + } + if (xform & HAL_TRANSFORM_FLIP_V) { + result = Rect(result.left, height - result.bottom, + result.right, height - result.top); + } + if (xform & HAL_TRANSFORM_ROT_90) { + int left = height - result.bottom; + int top = result.left; + int right = height - result.top; + int bottom = result.right; + result = Rect(left, top, right, bottom); + } + return result; +} + }; // namespace android |