KHTML
IntRect.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 QT_BEGIN_NAMESPACE
00048 class QRect;
00049 QT_END_NAMESPACE
00050 #elif PLATFORM(GTK)
00051 typedef struct _GdkRectangle GdkRectangle;
00052 #endif
00053 #if PLATFORM(SYMBIAN)
00054 class TRect;
00055 #endif
00056
00057 #if PLATFORM(WX)
00058 class wxRect;
00059 #endif
00060
00061 namespace WebCore {
00062
00063 class FloatRect;
00064
00065 class IntRect {
00066 public:
00067 IntRect() { }
00068 IntRect(const IntPoint& location, const IntSize& size)
00069 : m_location(location), m_size(size) { }
00070 IntRect(int x, int y, int width, int height)
00071 : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
00072
00073 explicit IntRect(const FloatRect& rect);
00074
00075 IntPoint location() const { return m_location; }
00076 IntSize size() const { return m_size; }
00077
00078 void setLocation(const IntPoint& location) { m_location = location; }
00079 void setSize(const IntSize& size) { m_size = size; }
00080
00081 int x() const { return m_location.x(); }
00082 int y() const { return m_location.y(); }
00083 int width() const { return m_size.width(); }
00084 int height() const { return m_size.height(); }
00085
00086 void setX(int x) { m_location.setX(x); }
00087 void setY(int y) { m_location.setY(y); }
00088 void setWidth(int width) { m_size.setWidth(width); }
00089 void setHeight(int height) { m_size.setHeight(height); }
00090
00091
00092
00093 IntPoint topLeft() const { return m_location; }
00094 IntPoint topRight() const { return IntPoint(right() - 1, y()); }
00095 IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
00096 IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
00097
00098 bool isEmpty() const { return m_size.isEmpty(); }
00099
00100 int right() const { return x() + width(); }
00101 int bottom() const { return y() + height(); }
00102
00103 void move(const IntSize& s) { m_location += s; }
00104 void move(int dx, int dy) { m_location.move(dx, dy); }
00105
00106 bool intersects(const IntRect&) const;
00107 bool contains(const IntRect&) const;
00108
00109
00110
00111 bool contains(int px, int py) const
00112 { return px >= x() && px < right() && py >= y() && py < bottom(); }
00113 bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
00114
00115 void intersect(const IntRect&);
00116 void unite(const IntRect&);
00117
00118 void inflateX(int dx)
00119 {
00120 m_location.setX(m_location.x() - dx);
00121 m_size.setWidth(m_size.width() + dx + dx);
00122 }
00123 void inflateY(int dy)
00124 {
00125 m_location.setY(m_location.y() - dy);
00126 m_size.setHeight(m_size.height() + dy + dy);
00127 }
00128 void inflate(int d) { inflateX(d); inflateY(d); }
00129 void scale(float s);
00130
00131 #if PLATFORM(WX)
00132 IntRect(const wxRect&);
00133 operator wxRect() const;
00134 #endif
00135
00136 #if PLATFORM(WIN)
00137 IntRect(const RECT&);
00138 operator RECT() const;
00139 #elif PLATFORM(QT)
00140 IntRect(const QRect&);
00141 operator QRect() const;
00142 #elif PLATFORM(GTK)
00143 IntRect(const GdkRectangle&);
00144 operator GdkRectangle() const;
00145 #endif
00146 #if PLATFORM(SYMBIAN)
00147 IntRect(const TRect&);
00148 operator TRect() const;
00149 TRect Rect() const;
00150 #endif
00151
00152 #if PLATFORM(CG)
00153 operator CGRect() const;
00154 #endif
00155
00156 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00157 operator NSRect() const;
00158 #endif
00159
00160 private:
00161 IntPoint m_location;
00162 IntSize m_size;
00163 };
00164
00165 inline IntRect intersection(const IntRect& a, const IntRect& b)
00166 {
00167 IntRect c = a;
00168 c.intersect(b);
00169 return c;
00170 }
00171
00172 inline IntRect unionRect(const IntRect& a, const IntRect& b)
00173 {
00174 IntRect c = a;
00175 c.unite(b);
00176 return c;
00177 }
00178
00179 inline bool operator==(const IntRect& a, const IntRect& b)
00180 {
00181 return a.location() == b.location() && a.size() == b.size();
00182 }
00183
00184 inline bool operator!=(const IntRect& a, const IntRect& b)
00185 {
00186 return a.location() != b.location() || a.size() != b.size();
00187 }
00188
00189 #if PLATFORM(CG)
00190 IntRect enclosingIntRect(const CGRect&);
00191 #endif
00192
00193 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00194 IntRect enclosingIntRect(const NSRect&);
00195 #endif
00196
00197 }
00198
00199 #endif // IntRect_h