pleyo.com

/src/trunk2/BAL/Interfaces/graphics/IntRect.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2006 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #ifndef IntRect_h
00027 #define IntRect_h
00028 
00029 #include "IntPoint.h"
00030 #include <wtf/Platform.h>
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGRect CGRect;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGRect NSRect;
00039 #else
00040 typedef struct _NSRect NSRect;
00041 #endif
00042 #endif
00043 
00044 #if PLATFORM(WIN)
00045 typedef struct tagRECT RECT;
00046 #elif PLATFORM(QT)
00047 class QRect;
00048 #endif
00049 #if PLATFORM(SYMBIAN)
00050 class TRect;
00051 #endif
00052 
00053 namespace WebCore {
00054 
00055 class FloatRect;
00056 
00057 class IntRect {
00058 public:
00059     IntRect() { }
00060     IntRect(const IntPoint& location, const IntSize& size)
00061         : m_location(location), m_size(size) { }
00062     IntRect(int x, int y, int width, int height)
00063         : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
00064 
00065     explicit IntRect(const FloatRect& rect); // don't do this implicitly since it's lossy
00066         
00067     IntPoint location() const { return m_location; }
00068     IntSize size() const { return m_size; }
00069 
00070     void setLocation(const IntPoint& location) { m_location = location; }
00071     void setSize(const IntSize& size) { m_size = size; }
00072 
00073     int x() const { return m_location.x(); }
00074     int y() const { return m_location.y(); }
00075     int width() const { return m_size.width(); }
00076     int height() const { return m_size.height(); }
00077 
00078     void setX(int x) { m_location.setX(x); }
00079     void setY(int y) { m_location.setY(y); }
00080     void setWidth(int width) { m_size.setWidth(width); }
00081     void setHeight(int height) { m_size.setHeight(height); }
00082 
00083     // Be careful with these functions.  The point is considered to be to the right and below.  These are not
00084     // substitutes for right() and bottom().
00085     IntPoint topLeft() const { return m_location; }
00086     IntPoint topRight() const { return IntPoint(right() - 1, y()); }
00087     IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
00088     IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
00089 
00090     bool isEmpty() const { return m_size.isEmpty(); }
00091 
00092     int right() const { return x() + width(); }
00093     int bottom() const { return y() + height(); }
00094 
00095     void move(const IntSize& s) { m_location += s; } 
00096     void move(int dx, int dy) { m_location.move(dx, dy); } 
00097 
00098     bool intersects(const IntRect&) const;
00099     bool contains(const IntRect&) const;
00100 
00101     // This checks to see if the rect contains x,y in the traditional sense.
00102     // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
00103     bool contains(int px, int py) const
00104         { return px >= x() && px < right() && py >= y() && py < bottom(); }
00105     bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
00106 
00107     void intersect(const IntRect&);
00108     void unite(const IntRect&);
00109 
00110     void inflateX(int dx)
00111     {
00112         m_location.setX(m_location.x() - dx);
00113         m_size.setWidth(m_size.width() + dx + dx);
00114     }
00115     void inflateY(int dy)
00116     {
00117         m_location.setY(m_location.y() - dy);
00118         m_size.setHeight(m_size.height() + dy + dy);
00119     }
00120     void inflate(int d) { inflateX(d); inflateY(d); }
00121     void scale(float s);
00122 
00123 #if PLATFORM(WIN)
00124     IntRect(const RECT&);
00125     operator RECT() const;
00126 #elif PLATFORM(QT)
00127     IntRect(const QRect&);
00128     operator QRect() const;
00129 #endif
00130 #if PLATFORM(SYMBIAN)
00131     IntRect(const TRect&);
00132     operator TRect() const;
00133     TRect Rect() const;
00134 #endif
00135 
00136 #if PLATFORM(CG)
00137     operator CGRect() const;
00138 #endif
00139 
00140 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00141     operator NSRect() const;
00142 #endif
00143 
00144 private:
00145     IntPoint m_location;
00146     IntSize m_size;
00147 };
00148 
00149 inline IntRect intersection(const IntRect& a, const IntRect& b)
00150 {
00151     IntRect c = a;
00152     c.intersect(b);
00153     return c;
00154 }
00155 
00156 inline IntRect unionRect(const IntRect& a, const IntRect& b)
00157 {
00158     IntRect c = a;
00159     c.unite(b);
00160     return c;
00161 }
00162 
00163 inline bool operator==(const IntRect& a, const IntRect& b)
00164 {
00165     return a.location() == b.location() && a.size() == b.size();
00166 }
00167 
00168 inline bool operator!=(const IntRect& a, const IntRect& b)
00169 {
00170     return a.location() != b.location() || a.size() != b.size();
00171 }
00172 
00173 #if PLATFORM(CG)
00174 IntRect enclosingIntRect(const CGRect&);
00175 #endif
00176 
00177 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00178 IntRect enclosingIntRect(const NSRect&);
00179 #endif
00180 
00181 } // namespace WebCore
00182 
00183 #endif // IntRect_h

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com