pleyo.com

/src/trunk2/BAL/Interfaces/graphics/IntPoint.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #ifndef IntPoint_h
00027 #define IntPoint_h
00028 
00029 #include "IntSize.h"
00030 #include <wtf/Platform.h>
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGPoint CGPoint;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGPoint NSPoint;
00039 #else
00040 typedef struct _NSPoint NSPoint;
00041 #endif
00042 #endif
00043 
00044 #if PLATFORM(WIN)
00045 typedef struct tagPOINT POINT;
00046 typedef struct tagPOINTS POINTS;
00047 #elif PLATFORM(QT)
00048 class QPoint;
00049 #endif
00050 #if PLATFORM(SYMBIAN)
00051 class TPoint;
00052 #endif
00053 
00054 namespace WebCore {
00055 
00056 class IntPoint {
00057 public:
00058     IntPoint() : m_x(0), m_y(0) { }
00059     IntPoint(int x, int y) : m_x(x), m_y(y) { }
00060 
00061     int x() const { return m_x; }
00062     int y() const { return m_y; }
00063 
00064     void setX(int x) { m_x = x; }
00065     void setY(int y) { m_y = y; }
00066 
00067     void move(int dx, int dy) { m_x += dx; m_y += dy; }
00068     
00069 #if PLATFORM(CG)
00070     explicit IntPoint(const CGPoint&); // don't do this implicitly since it's lossy
00071     operator CGPoint() const;
00072 #endif
00073 
00074 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00075     explicit IntPoint(const NSPoint&); // don't do this implicitly since it's lossy
00076     operator NSPoint() const;
00077 #endif
00078 
00079 #if PLATFORM(WIN)
00080     IntPoint(const POINT&);
00081     operator POINT() const;
00082     IntPoint(const POINTS&);
00083     operator POINTS() const;
00084 #elif PLATFORM(QT)
00085     IntPoint(const QPoint&);
00086     operator QPoint() const;
00087 #endif
00088 #if PLATFORM(SYMBIAN)
00089     IntPoint(const TPoint&);
00090     operator TPoint() const;
00091 #endif
00092 
00093 private:
00094     int m_x, m_y;
00095 };
00096 
00097 inline IntPoint& operator+=(IntPoint& a, const IntSize& b)
00098 {
00099     a.move(b.width(), b.height());
00100     return a;
00101 }
00102 
00103 inline IntPoint& operator-=(IntPoint& a, const IntSize& b)
00104 {
00105     a.move(-b.width(), -b.height());
00106     return a;
00107 }
00108 #ifdef __OWB__
00109 inline IntPoint operator+(const IntPoint& a, const IntPoint& b)
00110 {
00111     return IntPoint(a.x() + b.x(), a.y() + b.y());
00112 }
00113 #endif
00114 inline IntPoint operator+(const IntPoint& a, const IntSize& b)
00115 {
00116     return IntPoint(a.x() + b.width(), a.y() + b.height());
00117 }
00118 
00119 inline IntSize operator-(const IntPoint& a, const IntPoint& b)
00120 {
00121     return IntSize(a.x() - b.x(), a.y() - b.y());
00122 }
00123 
00124 inline IntPoint operator-(const IntPoint& a, const IntSize& b)
00125 {
00126     return IntPoint(a.x() - b.width(), a.y() - b.height());
00127 }
00128 
00129 inline bool operator==(const IntPoint& a, const IntPoint& b)
00130 {
00131     return a.x() == b.x() && a.y() == b.y();
00132 }
00133 
00134 inline bool operator!=(const IntPoint& a, const IntPoint& b)
00135 {
00136     return a.x() != b.x() || a.y() != b.y();
00137 }
00138 
00139 } // namespace WebCore
00140 
00141 #endif // IntPoint_h

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com