pleyo.com

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

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 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 IntSize_h
00027 #define IntSize_h
00028 
00029 #include <wtf/Platform.h>
00030 
00031 #if PLATFORM(CG)
00032 typedef struct CGSize CGSize;
00033 #endif
00034 
00035 #if PLATFORM(MAC)
00036 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00037 typedef struct CGSize NSSize;
00038 #else
00039 typedef struct _NSSize NSSize;
00040 #endif
00041 #endif
00042 
00043 #if PLATFORM(WIN)
00044 typedef struct tagSIZE SIZE;
00045 #elif PLATFORM(QT)
00046 class QSize;
00047 #endif
00048 #if PLATFORM(SYMBIAN)
00049 class TSize;
00050 #endif
00051 
00052 namespace WebCore {
00053 
00054 class IntSize {
00055 public:
00056     IntSize() : m_width(0), m_height(0) { }
00057     IntSize(int width, int height) : m_width(width), m_height(height) { }
00058     
00059     int width() const { return m_width; }
00060     int height() const { return m_height; }
00061 
00062     void setWidth(int width) { m_width = width; }
00063     void setHeight(int height) { m_height = height; }
00064 
00065     bool isEmpty() const { return m_width <= 0 || m_height <= 0; }
00066 
00067     IntSize expandedTo(const IntSize& other) const
00068     {
00069         return IntSize(m_width > other.m_width ? m_width : other.m_width,
00070             m_height > other.m_height ? m_height : other.m_height);
00071     }
00072 
00073     IntSize shrunkTo(const IntSize& other) const
00074     {
00075         return IntSize(m_width < other.m_width ? m_width : other.m_width,
00076             m_height < other.m_height ? m_height : other.m_height);
00077     }
00078 
00079     void clampNegativeToZero()
00080     {
00081         *this = expandedTo(IntSize());
00082     }
00083 
00084 #if PLATFORM(CG)
00085     explicit IntSize(const CGSize&); // don't do this implicitly since it's lossy
00086     operator CGSize() const;
00087 #endif
00088 
00089 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00090     explicit IntSize(const NSSize &); // don't do this implicitly since it's lossy
00091     operator NSSize() const;
00092 #endif
00093 
00094 #if PLATFORM(WIN)
00095     IntSize(const SIZE&);
00096     operator SIZE() const;
00097 #endif
00098 
00099 #if PLATFORM(QT)
00100     IntSize(const QSize&);
00101     operator QSize() const;
00102 #endif
00103 #if PLATFORM(SYMBIAN)
00104     IntSize(const TSize&);
00105     operator TSize() const;
00106 #endif
00107 
00108 
00109 private:
00110     int m_width, m_height;
00111 };
00112 
00113 inline IntSize& operator+=(IntSize& a, const IntSize& b)
00114 {
00115     a.setWidth(a.width() + b.width());
00116     a.setHeight(a.height() + b.height());
00117     return a;
00118 }
00119 
00120 inline IntSize& operator-=(IntSize& a, const IntSize& b)
00121 {
00122     a.setWidth(a.width() - b.width());
00123     a.setHeight(a.height() - b.height());
00124     return a;
00125 }
00126 
00127 inline IntSize operator+(const IntSize& a, const IntSize& b)
00128 {
00129     return IntSize(a.width() + b.width(), a.height() + b.height());
00130 }
00131 
00132 inline IntSize operator-(const IntSize& a, const IntSize& b)
00133 {
00134     return IntSize(a.width() - b.width(), a.height() - b.height());
00135 }
00136 
00137 inline IntSize operator-(const IntSize& size)
00138 {
00139     return IntSize(-size.width(), -size.height());
00140 }
00141 
00142 inline bool operator==(const IntSize& a, const IntSize& b)
00143 {
00144     return a.width() == b.width() && a.height() == b.height();
00145 }
00146 
00147 inline bool operator!=(const IntSize& a, const IntSize& b)
00148 {
00149     return a.width() != b.width() || a.height() != b.height();
00150 }
00151 
00152 } // namespace WebCore
00153 
00154 #endif // IntSize_h

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

pleyo.com
pleyo.com