media/omx-plugin/include/ics/ui/Rect.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Copyright (C) 2006 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef ANDROID_UI_RECT
michael@0 18 #define ANDROID_UI_RECT
michael@0 19
michael@0 20 #include <utils/TypeHelpers.h>
michael@0 21 #include <ui/Point.h>
michael@0 22
michael@0 23 #include <android/rect.h>
michael@0 24
michael@0 25 namespace android {
michael@0 26
michael@0 27 class Rect : public ARect
michael@0 28 {
michael@0 29 public:
michael@0 30 typedef ARect::value_type value_type;
michael@0 31
michael@0 32 // we don't provide copy-ctor and operator= on purpose
michael@0 33 // because we want the compiler generated versions
michael@0 34
michael@0 35 inline Rect() {
michael@0 36 }
michael@0 37 inline Rect(int32_t w, int32_t h) {
michael@0 38 left = top = 0; right = w; bottom = h;
michael@0 39 }
michael@0 40 inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) {
michael@0 41 left = l; top = t; right = r; bottom = b;
michael@0 42 }
michael@0 43 inline Rect(const Point& lt, const Point& rb) {
michael@0 44 left = lt.x; top = lt.y; right = rb.x; bottom = rb.y;
michael@0 45 }
michael@0 46
michael@0 47 void makeInvalid();
michael@0 48
michael@0 49 inline void clear() {
michael@0 50 left = top = right = bottom = 0;
michael@0 51 }
michael@0 52
michael@0 53 // a valid rectangle has a non negative width and height
michael@0 54 inline bool isValid() const {
michael@0 55 return (width()>=0) && (height()>=0);
michael@0 56 }
michael@0 57
michael@0 58 // an empty rect has a zero width or height, or is invalid
michael@0 59 inline bool isEmpty() const {
michael@0 60 return (width()<=0) || (height()<=0);
michael@0 61 }
michael@0 62
michael@0 63 inline void set(const Rect& rhs) {
michael@0 64 operator = (rhs);
michael@0 65 }
michael@0 66
michael@0 67 // rectangle's width
michael@0 68 inline int32_t width() const {
michael@0 69 return right-left;
michael@0 70 }
michael@0 71
michael@0 72 // rectangle's height
michael@0 73 inline int32_t height() const {
michael@0 74 return bottom-top;
michael@0 75 }
michael@0 76
michael@0 77 void setLeftTop(const Point& lt) {
michael@0 78 left = lt.x;
michael@0 79 top = lt.y;
michael@0 80 }
michael@0 81
michael@0 82 void setRightBottom(const Point& rb) {
michael@0 83 right = rb.x;
michael@0 84 bottom = rb.y;
michael@0 85 }
michael@0 86
michael@0 87 // the following 4 functions return the 4 corners of the rect as Point
michael@0 88 Point leftTop() const {
michael@0 89 return Point(left, top);
michael@0 90 }
michael@0 91 Point rightBottom() const {
michael@0 92 return Point(right, bottom);
michael@0 93 }
michael@0 94 Point rightTop() const {
michael@0 95 return Point(right, top);
michael@0 96 }
michael@0 97 Point leftBottom() const {
michael@0 98 return Point(left, bottom);
michael@0 99 }
michael@0 100
michael@0 101 // comparisons
michael@0 102 inline bool operator == (const Rect& rhs) const {
michael@0 103 return (left == rhs.left) && (top == rhs.top) &&
michael@0 104 (right == rhs.right) && (bottom == rhs.bottom);
michael@0 105 }
michael@0 106
michael@0 107 inline bool operator != (const Rect& rhs) const {
michael@0 108 return !operator == (rhs);
michael@0 109 }
michael@0 110
michael@0 111 // operator < defines an order which allows to use rectangles in sorted
michael@0 112 // vectors.
michael@0 113 bool operator < (const Rect& rhs) const;
michael@0 114
michael@0 115 Rect& offsetToOrigin() {
michael@0 116 right -= left;
michael@0 117 bottom -= top;
michael@0 118 left = top = 0;
michael@0 119 return *this;
michael@0 120 }
michael@0 121 Rect& offsetTo(const Point& p) {
michael@0 122 return offsetTo(p.x, p.y);
michael@0 123 }
michael@0 124 Rect& offsetBy(const Point& dp) {
michael@0 125 return offsetBy(dp.x, dp.y);
michael@0 126 }
michael@0 127 Rect& operator += (const Point& rhs) {
michael@0 128 return offsetBy(rhs.x, rhs.y);
michael@0 129 }
michael@0 130 Rect& operator -= (const Point& rhs) {
michael@0 131 return offsetBy(-rhs.x, -rhs.y);
michael@0 132 }
michael@0 133 const Rect operator + (const Point& rhs) const;
michael@0 134 const Rect operator - (const Point& rhs) const;
michael@0 135
michael@0 136 void translate(int32_t dx, int32_t dy) { // legacy, don't use.
michael@0 137 offsetBy(dx, dy);
michael@0 138 }
michael@0 139
michael@0 140 Rect& offsetTo(int32_t x, int32_t y);
michael@0 141 Rect& offsetBy(int32_t x, int32_t y);
michael@0 142 bool intersect(const Rect& with, Rect* result) const;
michael@0 143 };
michael@0 144
michael@0 145 ANDROID_BASIC_TYPES_TRAITS(Rect)
michael@0 146
michael@0 147 }; // namespace android
michael@0 148
michael@0 149 #endif // ANDROID_UI_RECT

mercurial