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 #if PLATFORM(MAC)
37 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
38 typedef struct CGPoint NSPoint;
39 #else
40 typedef struct _NSPoint NSPoint;
41 #endif
42 #endif
43 
44 #if PLATFORM(WIN)
45 typedef struct tagPOINT POINT;
46 typedef struct tagPOINTS POINTS;
47 #elif PLATFORM(QT)
48 QT_BEGIN_NAMESPACE
49 class QPoint;
50 QT_END_NAMESPACE
51 #elif PLATFORM(GTK)
52 typedef struct _GdkPoint GdkPoint;
53 #endif
54 #if PLATFORM(SYMBIAN)
55 class TPoint;
56 #endif
57 
58 #if PLATFORM(WX)
59 class wxPoint;
60 #endif
61 
62 namespace WebCore
63 {
64 
65 class IntPoint
66 {
67 public:
IntPoint()68     IntPoint() : m_x(0), m_y(0) { }
IntPoint(int x,int y)69     IntPoint(int x, int y) : m_x(x), m_y(y) { }
70 
x()71     int x() const
72     {
73         return m_x;
74     }
y()75     int y() const
76     {
77         return m_y;
78     }
79 
setX(int x)80     void setX(int x)
81     {
82         m_x = x;
83     }
setY(int y)84     void setY(int y)
85     {
86         m_y = y;
87     }
88 
move(int dx,int dy)89     void move(int dx, int dy)
90     {
91         m_x += dx;
92         m_y += dy;
93     }
94 
95 #if PLATFORM(CG)
96     explicit IntPoint(const CGPoint &); // don't do this implicitly since it's lossy
97     operator CGPoint() const;
98 #endif
99 
100 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
101     explicit IntPoint(const NSPoint &); // don't do this implicitly since it's lossy
102     operator NSPoint() const;
103 #endif
104 
105 #if PLATFORM(WIN)
106     IntPoint(const POINT &);
107     operator POINT() const;
108     IntPoint(const POINTS &);
109     operator POINTS() const;
110 #elif PLATFORM(QT)
111     IntPoint(const QPoint &);
112     operator QPoint() const;
113 #elif PLATFORM(GTK)
114     IntPoint(const GdkPoint &);
115     operator GdkPoint() const;
116 #endif
117 #if PLATFORM(SYMBIAN)
118     IntPoint(const TPoint &);
119     operator TPoint() const;
120 #endif
121 
122 #if PLATFORM(WX)
123     IntPoint(const wxPoint &);
124     operator wxPoint() const;
125 #endif
126 
127 private:
128     int m_x, m_y;
129 };
130 
131 inline IntPoint &operator+=(IntPoint &a, const IntSize &b)
132 {
133     a.move(b.width(), b.height());
134     return a;
135 }
136 
137 inline IntPoint &operator-=(IntPoint &a, const IntSize &b)
138 {
139     a.move(-b.width(), -b.height());
140     return a;
141 }
142 
143 inline IntPoint operator+(const IntPoint &a, const IntSize &b)
144 {
145     return IntPoint(a.x() + b.width(), a.y() + b.height());
146 }
147 
148 inline IntSize operator-(const IntPoint &a, const IntPoint &b)
149 {
150     return IntSize(a.x() - b.x(), a.y() - b.y());
151 }
152 
153 inline IntPoint operator-(const IntPoint &a, const IntSize &b)
154 {
155     return IntPoint(a.x() - b.width(), a.y() - b.height());
156 }
157 
158 inline bool operator==(const IntPoint &a, const IntPoint &b)
159 {
160     return a.x() == b.x() && a.y() == b.y();
161 }
162 
163 inline bool operator!=(const IntPoint &a, const IntPoint &b)
164 {
165     return a.x() != b.x() || a.y() != b.y();
166 }
167 
168 } // namespace WebCore
169 
170 #endif // IntPoint_h
171