• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • platform
  • graphics
IntRect.h
Go to the documentation of this file.
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)
33typedef struct CGRect CGRect;
34#endif
35
36#if PLATFORM(MAC)
37#ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
38typedef struct CGRect NSRect;
39#else
40typedef struct _NSRect NSRect;
41#endif
42#endif
43
44#if PLATFORM(WIN)
45typedef struct tagRECT RECT;
46#elif PLATFORM(QT)
47QT_BEGIN_NAMESPACE
48class QRect;
49QT_END_NAMESPACE
50#elif PLATFORM(GTK)
51typedef struct _GdkRectangle GdkRectangle;
52#endif
53#if PLATFORM(SYMBIAN)
54class TRect;
55#endif
56
57#if PLATFORM(WX)
58class wxRect;
59#endif
60
61namespace WebCore {
62
63class FloatRect;
64
65class IntRect {
66public:
67 IntRect() { }
68 IntRect(const IntPoint& location, const IntSize& size)
69 : m_location(location), m_size(size) { }
70 IntRect(int x, int y, int width, int height)
71 : m_location(IntPoint(x, y)), m_size(IntSize(width, height)) { }
72
73 explicit IntRect(const FloatRect& rect); // don't do this implicitly since it's lossy
74
75 IntPoint location() const { return m_location; }
76 IntSize size() const { return m_size; }
77
78 void setLocation(const IntPoint& location) { m_location = location; }
79 void setSize(const IntSize& size) { m_size = size; }
80
81 int x() const { return m_location.x(); }
82 int y() const { return m_location.y(); }
83 int width() const { return m_size.width(); }
84 int height() const { return m_size.height(); }
85
86 void setX(int x) { m_location.setX(x); }
87 void setY(int y) { m_location.setY(y); }
88 void setWidth(int width) { m_size.setWidth(width); }
89 void setHeight(int height) { m_size.setHeight(height); }
90
91 // Be careful with these functions. The point is considered to be to the right and below. These are not
92 // substitutes for right() and bottom().
93 IntPoint topLeft() const { return m_location; }
94 IntPoint topRight() const { return IntPoint(right() - 1, y()); }
95 IntPoint bottomLeft() const { return IntPoint(x(), bottom() - 1); }
96 IntPoint bottomRight() const { return IntPoint(right() - 1, bottom() - 1); }
97
98 bool isEmpty() const { return m_size.isEmpty(); }
99
100 int right() const { return x() + width(); }
101 int bottom() const { return y() + height(); }
102
103 void move(const IntSize& s) { m_location += s; }
104 void move(int dx, int dy) { m_location.move(dx, dy); }
105
106 bool intersects(const IntRect&) const;
107 bool contains(const IntRect&) const;
108
109 // This checks to see if the rect contains x,y in the traditional sense.
110 // Equivalent to checking if the rect contains a 1x1 rect below and to the right of (px,py).
111 bool contains(int px, int py) const
112 { return px >= x() && px < right() && py >= y() && py < bottom(); }
113 bool contains(const IntPoint& point) const { return contains(point.x(), point.y()); }
114
115 void intersect(const IntRect&);
116 void unite(const IntRect&);
117
118 void inflateX(int dx)
119 {
120 m_location.setX(m_location.x() - dx);
121 m_size.setWidth(m_size.width() + dx + dx);
122 }
123 void inflateY(int dy)
124 {
125 m_location.setY(m_location.y() - dy);
126 m_size.setHeight(m_size.height() + dy + dy);
127 }
128 void inflate(int d) { inflateX(d); inflateY(d); }
129 void scale(float s);
130
131#if PLATFORM(WX)
132 IntRect(const wxRect&);
133 operator wxRect() const;
134#endif
135
136#if PLATFORM(WIN)
137 IntRect(const RECT&);
138 operator RECT() const;
139#elif PLATFORM(QT)
140 IntRect(const QRect&);
141 operator QRect() const;
142#elif PLATFORM(GTK)
143 IntRect(const GdkRectangle&);
144 operator GdkRectangle() const;
145#endif
146#if PLATFORM(SYMBIAN)
147 IntRect(const TRect&);
148 operator TRect() const;
149 TRect Rect() const;
150#endif
151
152#if PLATFORM(CG)
153 operator CGRect() const;
154#endif
155
156#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
157 operator NSRect() const;
158#endif
159
160private:
161 IntPoint m_location;
162 IntSize m_size;
163};
164
165inline IntRect intersection(const IntRect& a, const IntRect& b)
166{
167 IntRect c = a;
168 c.intersect(b);
169 return c;
170}
171
172inline IntRect unionRect(const IntRect& a, const IntRect& b)
173{
174 IntRect c = a;
175 c.unite(b);
176 return c;
177}
178
179inline bool operator==(const IntRect& a, const IntRect& b)
180{
181 return a.location() == b.location() && a.size() == b.size();
182}
183
184inline bool operator!=(const IntRect& a, const IntRect& b)
185{
186 return a.location() != b.location() || a.size() != b.size();
187}
188
189#if PLATFORM(CG)
190IntRect enclosingIntRect(const CGRect&);
191#endif
192
193#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
194IntRect enclosingIntRect(const NSRect&);
195#endif
196
197} // namespace WebCore
198
199#endif // IntRect_h
IntPoint.h
WebCore::FloatRect
Definition: FloatRect.h:59
WebCore::IntPoint
Definition: IntPoint.h:64
WebCore::IntPoint::x
int x() const
Definition: IntPoint.h:69
WebCore::IntPoint::y
int y() const
Definition: IntPoint.h:70
WebCore::IntPoint::setX
void setX(int x)
Definition: IntPoint.h:72
WebCore::IntPoint::setY
void setY(int y)
Definition: IntPoint.h:73
WebCore::IntPoint::move
void move(int dx, int dy)
Definition: IntPoint.h:75
WebCore::IntRect
Definition: IntRect.h:65
WebCore::IntRect::setWidth
void setWidth(int width)
Definition: IntRect.h:88
WebCore::IntRect::IntRect
IntRect()
Definition: IntRect.h:67
WebCore::IntRect::setSize
void setSize(const IntSize &size)
Definition: IntRect.h:79
WebCore::IntRect::topLeft
IntPoint topLeft() const
Definition: IntRect.h:93
WebCore::IntRect::setX
void setX(int x)
Definition: IntRect.h:86
WebCore::IntRect::bottomLeft
IntPoint bottomLeft() const
Definition: IntRect.h:95
WebCore::IntRect::unite
void unite(const IntRect &)
Definition: IntRect.cpp:78
WebCore::IntRect::intersects
bool intersects(const IntRect &) const
Definition: IntRect.cpp:43
WebCore::IntRect::location
IntPoint location() const
Definition: IntRect.h:75
WebCore::IntRect::x
int x() const
Definition: IntRect.h:81
WebCore::IntRect::setLocation
void setLocation(const IntPoint &location)
Definition: IntRect.h:78
WebCore::IntRect::move
void move(int dx, int dy)
Definition: IntRect.h:104
WebCore::IntRect::inflateY
void inflateY(int dy)
Definition: IntRect.h:123
WebCore::IntRect::intersect
void intersect(const IntRect &)
Definition: IntRect.cpp:57
WebCore::IntRect::contains
bool contains(const IntPoint &point) const
Definition: IntRect.h:113
WebCore::IntRect::setHeight
void setHeight(int height)
Definition: IntRect.h:89
WebCore::IntRect::inflateX
void inflateX(int dx)
Definition: IntRect.h:118
WebCore::IntRect::setY
void setY(int y)
Definition: IntRect.h:87
WebCore::IntRect::isEmpty
bool isEmpty() const
Definition: IntRect.h:98
WebCore::IntRect::move
void move(const IntSize &s)
Definition: IntRect.h:103
WebCore::IntRect::scale
void scale(float s)
Definition: IntRect.cpp:99
WebCore::IntRect::IntRect
IntRect(int x, int y, int width, int height)
Definition: IntRect.h:70
WebCore::IntRect::topRight
IntPoint topRight() const
Definition: IntRect.h:94
WebCore::IntRect::contains
bool contains(int px, int py) const
Definition: IntRect.h:111
WebCore::IntRect::bottomRight
IntPoint bottomRight() const
Definition: IntRect.h:96
WebCore::IntRect::size
IntSize size() const
Definition: IntRect.h:76
WebCore::IntRect::y
int y() const
Definition: IntRect.h:82
WebCore::IntRect::height
int height() const
Definition: IntRect.h:84
WebCore::IntRect::contains
bool contains(const IntRect &) const
Definition: IntRect.cpp:51
WebCore::IntRect::inflate
void inflate(int d)
Definition: IntRect.h:128
WebCore::IntRect::IntRect
IntRect(const IntPoint &location, const IntSize &size)
Definition: IntRect.h:68
WebCore::IntRect::bottom
int bottom() const
Definition: IntRect.h:101
WebCore::IntRect::right
int right() const
Definition: IntRect.h:100
WebCore::IntRect::width
int width() const
Definition: IntRect.h:83
WebCore::IntSize
Definition: IntSize.h:57
WebCore::IntSize::width
int width() const
Definition: IntSize.h:62
WebCore::IntSize::setHeight
void setHeight(int height)
Definition: IntSize.h:66
WebCore::IntSize::height
int height() const
Definition: IntSize.h:63
WebCore::IntSize::setWidth
void setWidth(int width)
Definition: IntSize.h:65
WebCore::IntSize::isEmpty
bool isEmpty() const
Definition: IntSize.h:68
d
#define d
Definition: khtmlfind.cpp:42
WebCore
Definition: CSSHelper.h:7
WebCore::operator!=
bool operator!=(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:135
WebCore::unionRect
FloatRect unionRect(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:155
WebCore::operator==
bool operator==(const FloatPoint &a, const FloatPoint &b)
Definition: FloatPoint.h:130
WebCore::intersection
FloatRect intersection(const FloatRect &a, const FloatRect &b)
Definition: FloatRect.h:148
WebCore::enclosingIntRect
IntRect enclosingIntRect(const FloatRect &rect)
Definition: FloatRect.cpp:112
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal