KHtml

IntRect.h
1 /*
2  * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef IntRect_h
27 #define IntRect_h
28 
29 #include "IntPoint.h"
30 #include <wtf/Platform.h>
31 
32 #if PLATFORM(CG)
33 typedef struct CGRect CGRect;
34 #endif
35 
36 #if PLATFORM(MAC)
37 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
38 typedef struct CGRect NSRect;
39 #else
40 typedef struct _NSRect NSRect;
41 #endif
42 #endif
43 
44 #if PLATFORM(WIN)
45 typedef struct tagRECT RECT;
46 #elif PLATFORM(QT)
47 QT_BEGIN_NAMESPACE
48 class QRect;
49 QT_END_NAMESPACE
50 #elif PLATFORM(GTK)
51 typedef struct _GdkRectangle GdkRectangle;
52 #endif
53 #if PLATFORM(SYMBIAN)
54 class TRect;
55 #endif
56 
57 #if PLATFORM(WX)
58 class wxRect;
59 #endif
60 
61 namespace WebCore
62 {
63 
64 class FloatRect;
65 
66 class IntRect
67 {
68 public:
69  IntRect() { }
70  IntRect(const IntPoint &location, const IntSize &size)
71  : m_location(location), m_size(size) { }
72  IntRect(int x, int y, int width, int height)
73  : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
74 
75  explicit IntRect(const FloatRect &rect); // don't do this implicitly since it's lossy
76 
77  IntPoint location() const
78  {
79  return m_location;
80  }
81  IntSize size() const
82  {
83  return m_size;
84  }
85 
86  void setLocation(const IntPoint &location)
87  {
88  m_location = location;
89  }
90  void setSize(const IntSize &size)
91  {
92  m_size = size;
93  }
94 
95  int x() const
96  {
97  return m_location.x();
98  }
99  int y() const
100  {
101  return m_location.y();
102  }
103  int width() const
104  {
105  return m_size.width();
106  }
107  int height() const
108  {
109  return m_size.height();
110  }
111 
112  void setX(int x)
113  {
114  m_location.setX(x);
115  }
116  void setY(int y)
117  {
118  m_location.setY(y);
119  }
120  void setWidth(int width)
121  {
122  m_size.setWidth(width);
123  }
124  void setHeight(int height)
125  {
126  m_size.setHeight(height);
127  }
128 
129  // Be careful with these functions. The point is considered to be to the right and below. These are not
130  // substitutes for right() and bottom().
131  IntPoint topLeft() const
132  {
133  return m_location;
134  }
135  IntPoint topRight() const
136  {
137  return IntPoint(right() - 1, y());
138  }
139  IntPoint bottomLeft() const
140  {
141  return IntPoint(x(), bottom() - 1);
142  }
143  IntPoint bottomRight() const
144  {
145  return IntPoint(right() - 1, bottom() - 1);
146  }
147 
148  bool isEmpty() const
149  {
150  return m_size.isEmpty();
151  }
152 
153  int right() const
154  {
155  return x() + width();
156  }
157  int bottom() const
158  {
159  return y() + height();
160  }
161 
162  void move(const IntSize &s)
163  {
164  m_location += s;
165  }
166  void move(int dx, int dy)
167  {
168  m_location.move(dx, dy);
169  }
170 
171  bool intersects(const IntRect &) const;
172  bool contains(const IntRect &) const;
173 
174  // This checks to see if the rect contains x,y in the traditional sense.
175  // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
176  bool contains(int px, int py) const
177  {
178  return px >= x() && px < right() && py >= y() && py < bottom();
179  }
180  bool contains(const IntPoint &point) const
181  {
182  return contains(point.x(), point.y());
183  }
184 
185  void intersect(const IntRect &);
186  void unite(const IntRect &);
187 
188  void inflateX(int dx)
189  {
190  m_location.setX(m_location.x() - dx);
191  m_size.setWidth(m_size.width() + dx + dx);
192  }
193  void inflateY(int dy)
194  {
195  m_location.setY(m_location.y() - dy);
196  m_size.setHeight(m_size.height() + dy + dy);
197  }
198  void inflate(int d)
199  {
200  inflateX(d);
201  inflateY(d);
202  }
203  void scale(float s);
204 
205 #if PLATFORM(WX)
206  IntRect(const wxRect &);
207  operator wxRect() const;
208 #endif
209 
210 #if PLATFORM(WIN)
211  IntRect(const RECT &);
212  operator RECT() const;
213 #elif PLATFORM(QT)
214  IntRect(const QRect &);
215  operator QRect() const;
216 #elif PLATFORM(GTK)
217  IntRect(const GdkRectangle &);
218  operator GdkRectangle() const;
219 #endif
220 #if PLATFORM(SYMBIAN)
221  IntRect(const TRect &);
222  operator TRect() const;
223  TRect Rect() const;
224 #endif
225 
226 #if PLATFORM(CG)
227  operator CGRect() const;
228 #endif
229 
230 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
231  operator NSRect() const;
232 #endif
233 
234 private:
235  IntPoint m_location;
236  IntSize m_size;
237 };
238 
239 inline IntRect intersection(const IntRect &a, const IntRect &b)
240 {
241  IntRect c = a;
242  c.intersect(b);
243  return c;
244 }
245 
246 inline IntRect unionRect(const IntRect &a, const IntRect &b)
247 {
248  IntRect c = a;
249  c.unite(b);
250  return c;
251 }
252 
253 inline bool operator==(const IntRect &a, const IntRect &b)
254 {
255  return a.location() == b.location() && a.size() == b.size();
256 }
257 
258 inline bool operator!=(const IntRect &a, const IntRect &b)
259 {
260  return a.location() != b.location() || a.size() != b.size();
261 }
262 
263 #if PLATFORM(CG)
264 IntRect enclosingIntRect(const CGRect &);
265 #endif
266 
267 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
268 IntRect enclosingIntRect(const NSRect &);
269 #endif
270 
271 } // namespace WebCore
272 
273 #endif // IntRect_h
QTextStream & right(QTextStream &stream)
QVariant location(const QVariant &res)
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
KIOCORE_EXPORT CopyJob * move(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.