1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/ics/ui/Rect.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* 1.5 + * Copyright (C) 2006 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef ANDROID_UI_RECT 1.21 +#define ANDROID_UI_RECT 1.22 + 1.23 +#include <utils/TypeHelpers.h> 1.24 +#include <ui/Point.h> 1.25 + 1.26 +#include <android/rect.h> 1.27 + 1.28 +namespace android { 1.29 + 1.30 +class Rect : public ARect 1.31 +{ 1.32 +public: 1.33 + typedef ARect::value_type value_type; 1.34 + 1.35 + // we don't provide copy-ctor and operator= on purpose 1.36 + // because we want the compiler generated versions 1.37 + 1.38 + inline Rect() { 1.39 + } 1.40 + inline Rect(int32_t w, int32_t h) { 1.41 + left = top = 0; right = w; bottom = h; 1.42 + } 1.43 + inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) { 1.44 + left = l; top = t; right = r; bottom = b; 1.45 + } 1.46 + inline Rect(const Point& lt, const Point& rb) { 1.47 + left = lt.x; top = lt.y; right = rb.x; bottom = rb.y; 1.48 + } 1.49 + 1.50 + void makeInvalid(); 1.51 + 1.52 + inline void clear() { 1.53 + left = top = right = bottom = 0; 1.54 + } 1.55 + 1.56 + // a valid rectangle has a non negative width and height 1.57 + inline bool isValid() const { 1.58 + return (width()>=0) && (height()>=0); 1.59 + } 1.60 + 1.61 + // an empty rect has a zero width or height, or is invalid 1.62 + inline bool isEmpty() const { 1.63 + return (width()<=0) || (height()<=0); 1.64 + } 1.65 + 1.66 + inline void set(const Rect& rhs) { 1.67 + operator = (rhs); 1.68 + } 1.69 + 1.70 + // rectangle's width 1.71 + inline int32_t width() const { 1.72 + return right-left; 1.73 + } 1.74 + 1.75 + // rectangle's height 1.76 + inline int32_t height() const { 1.77 + return bottom-top; 1.78 + } 1.79 + 1.80 + void setLeftTop(const Point& lt) { 1.81 + left = lt.x; 1.82 + top = lt.y; 1.83 + } 1.84 + 1.85 + void setRightBottom(const Point& rb) { 1.86 + right = rb.x; 1.87 + bottom = rb.y; 1.88 + } 1.89 + 1.90 + // the following 4 functions return the 4 corners of the rect as Point 1.91 + Point leftTop() const { 1.92 + return Point(left, top); 1.93 + } 1.94 + Point rightBottom() const { 1.95 + return Point(right, bottom); 1.96 + } 1.97 + Point rightTop() const { 1.98 + return Point(right, top); 1.99 + } 1.100 + Point leftBottom() const { 1.101 + return Point(left, bottom); 1.102 + } 1.103 + 1.104 + // comparisons 1.105 + inline bool operator == (const Rect& rhs) const { 1.106 + return (left == rhs.left) && (top == rhs.top) && 1.107 + (right == rhs.right) && (bottom == rhs.bottom); 1.108 + } 1.109 + 1.110 + inline bool operator != (const Rect& rhs) const { 1.111 + return !operator == (rhs); 1.112 + } 1.113 + 1.114 + // operator < defines an order which allows to use rectangles in sorted 1.115 + // vectors. 1.116 + bool operator < (const Rect& rhs) const; 1.117 + 1.118 + Rect& offsetToOrigin() { 1.119 + right -= left; 1.120 + bottom -= top; 1.121 + left = top = 0; 1.122 + return *this; 1.123 + } 1.124 + Rect& offsetTo(const Point& p) { 1.125 + return offsetTo(p.x, p.y); 1.126 + } 1.127 + Rect& offsetBy(const Point& dp) { 1.128 + return offsetBy(dp.x, dp.y); 1.129 + } 1.130 + Rect& operator += (const Point& rhs) { 1.131 + return offsetBy(rhs.x, rhs.y); 1.132 + } 1.133 + Rect& operator -= (const Point& rhs) { 1.134 + return offsetBy(-rhs.x, -rhs.y); 1.135 + } 1.136 + const Rect operator + (const Point& rhs) const; 1.137 + const Rect operator - (const Point& rhs) const; 1.138 + 1.139 + void translate(int32_t dx, int32_t dy) { // legacy, don't use. 1.140 + offsetBy(dx, dy); 1.141 + } 1.142 + 1.143 + Rect& offsetTo(int32_t x, int32_t y); 1.144 + Rect& offsetBy(int32_t x, int32_t y); 1.145 + bool intersect(const Rect& with, Rect* result) const; 1.146 +}; 1.147 + 1.148 +ANDROID_BASIC_TYPES_TRAITS(Rect) 1.149 + 1.150 +}; // namespace android 1.151 + 1.152 +#endif // ANDROID_UI_RECT