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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/omx-plugin/include/froyo/ui/Rect.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     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 +namespace android {
    1.27 +
    1.28 +class Rect
    1.29 +{
    1.30 +public:
    1.31 +    int left;
    1.32 +    int top;
    1.33 +    int right;
    1.34 +    int bottom;
    1.35 +
    1.36 +    typedef int value_type;
    1.37 +
    1.38 +    // we don't provide copy-ctor and operator= on purpose
    1.39 +    // because we want the compiler generated versions
    1.40 +
    1.41 +    inline Rect() {
    1.42 +    }
    1.43 +    inline Rect(int w, int h)
    1.44 +        : left(0), top(0), right(w), bottom(h) {
    1.45 +    }
    1.46 +    inline Rect(int l, int t, int r, int b)
    1.47 +        : left(l), top(t), right(r), bottom(b) {
    1.48 +    }
    1.49 +    inline Rect(const Point& lt, const Point& rb) 
    1.50 +        : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y) {
    1.51 +    }
    1.52 +
    1.53 +    void makeInvalid();
    1.54 +
    1.55 +    inline void clear() {
    1.56 +        left = top = right = bottom = 0;
    1.57 +    }
    1.58 +
    1.59 +    // a valid rectangle has a non negative width and height
    1.60 +    inline bool isValid() const {
    1.61 +        return (width()>=0) && (height()>=0);
    1.62 +    }
    1.63 +
    1.64 +    // an empty rect has a zero width or height, or is invalid
    1.65 +    inline bool isEmpty() const {
    1.66 +        return (width()<=0) || (height()<=0);
    1.67 +    }
    1.68 +
    1.69 +    inline void set(const Rect& rhs) {
    1.70 +        operator = (rhs);
    1.71 +    }
    1.72 +
    1.73 +    // rectangle's width
    1.74 +    inline int width() const {
    1.75 +        return right-left;
    1.76 +    }
    1.77 +    
    1.78 +    // rectangle's height
    1.79 +    inline int height() const {
    1.80 +        return bottom-top;
    1.81 +    }
    1.82 +
    1.83 +    void setLeftTop(const Point& lt) {
    1.84 +        left = lt.x;
    1.85 +        top  = lt.y;
    1.86 +    }
    1.87 +
    1.88 +    void setRightBottom(const Point& rb) {
    1.89 +        right = rb.x;
    1.90 +        bottom  = rb.y;
    1.91 +    }
    1.92 +    
    1.93 +    // the following 4 functions return the 4 corners of the rect as Point
    1.94 +    Point leftTop() const {
    1.95 +        return Point(left, top);
    1.96 +    }
    1.97 +    Point rightBottom() const {
    1.98 +        return Point(right, bottom);
    1.99 +    }
   1.100 +    Point rightTop() const {
   1.101 +        return Point(right, top);
   1.102 +    }
   1.103 +    Point leftBottom() const {
   1.104 +        return Point(left, bottom);
   1.105 +    }
   1.106 +
   1.107 +    // comparisons
   1.108 +    inline bool operator == (const Rect& rhs) const {
   1.109 +        return (left == rhs.left) && (top == rhs.top) &&
   1.110 +               (right == rhs.right) && (bottom == rhs.bottom);
   1.111 +    }
   1.112 +
   1.113 +    inline bool operator != (const Rect& rhs) const {
   1.114 +        return !operator == (rhs);
   1.115 +    }
   1.116 +
   1.117 +    // operator < defines an order which allows to use rectangles in sorted
   1.118 +    // vectors.
   1.119 +    bool operator < (const Rect& rhs) const;
   1.120 +
   1.121 +    Rect& offsetToOrigin() {
   1.122 +        right -= left;
   1.123 +        bottom -= top;
   1.124 +        left = top = 0;
   1.125 +        return *this;
   1.126 +    }
   1.127 +    Rect& offsetTo(const Point& p) {
   1.128 +        return offsetTo(p.x, p.y);
   1.129 +    }
   1.130 +    Rect& offsetBy(const Point& dp) {
   1.131 +        return offsetBy(dp.x, dp.y);
   1.132 +    }
   1.133 +    Rect& operator += (const Point& rhs) {
   1.134 +        return offsetBy(rhs.x, rhs.y);
   1.135 +    }
   1.136 +    Rect& operator -= (const Point& rhs) {
   1.137 +        return offsetBy(-rhs.x, -rhs.y);
   1.138 +    }
   1.139 +    const Rect operator + (const Point& rhs) const;
   1.140 +    const Rect operator - (const Point& rhs) const;
   1.141 +
   1.142 +    void translate(int dx, int dy) { // legacy, don't use.
   1.143 +        offsetBy(dx, dy);
   1.144 +    }
   1.145 + 
   1.146 +    Rect&   offsetTo(int x, int y);
   1.147 +    Rect&   offsetBy(int x, int y);
   1.148 +    bool    intersect(const Rect& with, Rect* result) const;
   1.149 +};
   1.150 +
   1.151 +ANDROID_BASIC_TYPES_TRAITS(Rect)
   1.152 +
   1.153 +}; // namespace android
   1.154 +
   1.155 +#endif // ANDROID_UI_RECT

mercurial