KHTML
FloatRect.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
00027 #ifndef FloatRect_h
00028 #define FloatRect_h
00029
00030 #include "FloatPoint.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(QT)
00045 QT_BEGIN_NAMESPACE
00046 class QRectF;
00047 QT_END_NAMESPACE
00048 #endif
00049
00050 #if PLATFORM(WX) && USE(WXGC)
00051 class wxRect2DDouble;
00052 #endif
00053
00054 namespace WebCore {
00055
00056 class IntRect;
00057
00058 class FloatRect {
00059 public:
00060 FloatRect() { }
00061 FloatRect(const FloatPoint& location, const FloatSize& size)
00062 : m_location(location), m_size(size) { }
00063 FloatRect(float x, float y, float width, float height)
00064 : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
00065 FloatRect(const IntRect&);
00066
00067 static FloatRect narrowPrecision(double x, double y, double width, double height);
00068
00069 FloatPoint location() const { return m_location; }
00070 FloatSize size() const { return m_size; }
00071
00072 void setLocation(const FloatPoint& location) { m_location = location; }
00073 void setSize(const FloatSize& size) { m_size = size; }
00074
00075 float x() const { return m_location.x(); }
00076 float y() const { return m_location.y(); }
00077 float width() const { return m_size.width(); }
00078 float height() const { return m_size.height(); }
00079
00080 void setX(float x) { m_location.setX(x); }
00081 void setY(float y) { m_location.setY(y); }
00082 void setWidth(float width) { m_size.setWidth(width); }
00083 void setHeight(float height) { m_size.setHeight(height); }
00084
00085 bool isEmpty() const { return m_size.isEmpty(); }
00086
00087 float right() const { return x() + width(); }
00088 float bottom() const { return y() + height(); }
00089
00090 void move(const FloatSize& delta) { m_location += delta; }
00091 void move(float dx, float dy) { m_location.move(dx, dy); }
00092
00093 bool intersects(const FloatRect&) const;
00094 bool contains(const FloatRect&) const;
00095
00096 void intersect(const FloatRect&);
00097 void unite(const FloatRect&);
00098
00099
00100
00101 bool contains(float px, float py) const
00102 { return px >= x() && px <= right() && py >= y() && py <= bottom(); }
00103 bool contains(const FloatPoint& point) const { return contains(point.x(), point.y()); }
00104
00105
00106 void inflateX(float dx) {
00107 m_location.setX(m_location.x() - dx);
00108 m_size.setWidth(m_size.width() + dx + dx);
00109 }
00110 void inflateY(float dy) {
00111 m_location.setY(m_location.y() - dy);
00112 m_size.setHeight(m_size.height() + dy + dy);
00113 }
00114 void inflate(float d) { inflateX(d); inflateY(d); }
00115 void scale(float s);
00116
00117 #if PLATFORM(CG)
00118 FloatRect(const CGRect&);
00119 operator CGRect() const;
00120 #endif
00121
00122 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00123 FloatRect(const NSRect&);
00124 operator NSRect() const;
00125 #endif
00126
00127 #if PLATFORM(QT)
00128 FloatRect(const QRectF&);
00129 operator QRectF() const;
00130 #endif
00131 #if PLATFORM(SYMBIAN)
00132 FloatRect(const TRect&);
00133 operator TRect() const;
00134 TRect rect() const;
00135 #endif
00136
00137 #if PLATFORM(WX) && USE(WXGC)
00138 FloatRect(const wxRect2DDouble&);
00139 operator wxRect2DDouble() const;
00140 #endif
00141
00142 private:
00143 FloatPoint m_location;
00144 FloatSize m_size;
00145 };
00146
00147 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
00148 {
00149 FloatRect c = a;
00150 c.intersect(b);
00151 return c;
00152 }
00153
00154 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
00155 {
00156 FloatRect c = a;
00157 c.unite(b);
00158 return c;
00159 }
00160
00161 inline bool operator==(const FloatRect& a, const FloatRect& b)
00162 {
00163 return a.location() == b.location() && a.size() == b.size();
00164 }
00165
00166 inline bool operator!=(const FloatRect& a, const FloatRect& b)
00167 {
00168 return a.location() != b.location() || a.size() != b.size();
00169 }
00170
00171 IntRect enclosingIntRect(const FloatRect&);
00172
00173 }
00174
00175 #endif