]> git.saurik.com Git - iphone-api.git/blob - WebCore/IntPoint.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / IntPoint.h
1 /*
2 * Copyright (C) 2004, 2005, 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 IntPoint_h
27 #define IntPoint_h
28
29 #include "IntSize.h"
30 #include <wtf/Platform.h>
31
32 #if PLATFORM(CG)
33 typedef struct CGPoint CGPoint;
34 #endif
35
36
37 #if PLATFORM(WIN)
38 typedef struct tagPOINT POINT;
39 typedef struct tagPOINTS POINTS;
40 #elif PLATFORM(QT)
41 QT_BEGIN_NAMESPACE
42 class QPoint;
43 QT_END_NAMESPACE
44 #elif PLATFORM(GTK)
45 typedef struct _GdkPoint GdkPoint;
46 #endif
47 #if PLATFORM(SYMBIAN)
48 class TPoint;
49 #endif
50
51 #if PLATFORM(WX)
52 class wxPoint;
53 #endif
54
55 #if PLATFORM(SKIA)
56 struct SkPoint;
57 struct SkIPoint;
58 #endif
59
60 namespace WebCore {
61
62 class IntPoint {
63 public:
64 IntPoint() : m_x(0), m_y(0) { }
65 IntPoint(int x, int y) : m_x(x), m_y(y) { }
66
67 int x() const { return m_x; }
68 int y() const { return m_y; }
69
70 void setX(int x) { m_x = x; }
71 void setY(int y) { m_y = y; }
72
73 void move(int dx, int dy) { m_x += dx; m_y += dy; }
74
75 IntPoint expandedTo(const IntPoint& other) const
76 {
77 return IntPoint(m_x > other.m_x ? m_x : other.m_x,
78 m_y > other.m_y ? m_y : other.m_y);
79 }
80
81 IntPoint shrunkTo(const IntPoint& other) const
82 {
83 return IntPoint(m_x < other.m_x ? m_x : other.m_x,
84 m_y < other.m_y ? m_y : other.m_y);
85 }
86
87 void clampNegativeToZero()
88 {
89 *this = expandedTo(IntPoint());
90 }
91
92 #if PLATFORM(CG)
93 explicit IntPoint(const CGPoint&); // don't do this implicitly since it's lossy
94 operator CGPoint() const;
95 #endif
96
97
98 #if PLATFORM(WIN)
99 IntPoint(const POINT&);
100 operator POINT() const;
101 IntPoint(const POINTS&);
102 operator POINTS() const;
103 #elif PLATFORM(QT)
104 IntPoint(const QPoint&);
105 operator QPoint() const;
106 #elif PLATFORM(GTK)
107 IntPoint(const GdkPoint&);
108 operator GdkPoint() const;
109 #endif
110 #if PLATFORM(SYMBIAN)
111 IntPoint(const TPoint&);
112 operator TPoint() const;
113 #endif
114
115 #if PLATFORM(WX)
116 IntPoint(const wxPoint&);
117 operator wxPoint() const;
118 #endif
119
120 #if PLATFORM(SKIA)
121 IntPoint(const SkIPoint&);
122 operator SkIPoint() const;
123 operator SkPoint() const;
124 #endif
125
126 private:
127 int m_x, m_y;
128 };
129
130 inline IntPoint& operator+=(IntPoint& a, const IntSize& b)
131 {
132 a.move(b.width(), b.height());
133 return a;
134 }
135
136 inline IntPoint& operator-=(IntPoint& a, const IntSize& b)
137 {
138 a.move(-b.width(), -b.height());
139 return a;
140 }
141
142 inline IntPoint operator+(const IntPoint& a, const IntSize& b)
143 {
144 return IntPoint(a.x() + b.width(), a.y() + b.height());
145 }
146
147 inline IntSize operator-(const IntPoint& a, const IntPoint& b)
148 {
149 return IntSize(a.x() - b.x(), a.y() - b.y());
150 }
151
152 inline IntPoint operator-(const IntPoint& a, const IntSize& b)
153 {
154 return IntPoint(a.x() - b.width(), a.y() - b.height());
155 }
156
157 inline bool operator==(const IntPoint& a, const IntPoint& b)
158 {
159 return a.x() == b.x() && a.y() == b.y();
160 }
161
162 inline bool operator!=(const IntPoint& a, const IntPoint& b)
163 {
164 return a.x() != b.x() || a.y() != b.y();
165 }
166
167 } // namespace WebCore
168
169 #endif // IntPoint_h