• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

FloatRect.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003, 2006, 2007 Apple Inc.  All rights reserved.
00003  * Copyright (C) 2005 Nokia.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  *
00014  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00015  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00018  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 
00027 #ifndef FloatRect_h
00028 #define FloatRect_h
00029 
00030 #include "FloatPoint.h"
00031 
00032 #if PLATFORM(CG)
00033 typedef struct CGRect CGRect;
00034 #endif
00035 
00036 #if PLATFORM(MAC)
00037 #ifdef NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES
00038 typedef struct CGRect NSRect;
00039 #else
00040 typedef struct _NSRect NSRect;
00041 #endif
00042 #endif
00043 
00044 #if PLATFORM(QT)
00045 QT_BEGIN_NAMESPACE
00046 class QRectF;
00047 QT_END_NAMESPACE
00048 #endif
00049 
00050 #if PLATFORM(WX) && USE(WXGC)
00051 class wxRect2DDouble;
00052 #endif
00053 
00054 namespace WebCore {
00055 
00056 class IntRect;
00057 
00058 class FloatRect {
00059 public:
00060     FloatRect() { }
00061     FloatRect(const FloatPoint& location, const FloatSize& size)
00062         : m_location(location), m_size(size) { }
00063     FloatRect(float x, float y, float width, float height)
00064         : m_location(FloatPoint(x, y)), m_size(FloatSize(width, height)) { }
00065     FloatRect(const IntRect&);
00066 
00067     static FloatRect narrowPrecision(double x, double y, double width, double height);
00068 
00069     FloatPoint location() const { return m_location; }
00070     FloatSize size() const { return m_size; }
00071 
00072     void setLocation(const FloatPoint& location) { m_location = location; }
00073     void setSize(const FloatSize& size) { m_size = size; }
00074 
00075     float x() const { return m_location.x(); }
00076     float y() const { return m_location.y(); }
00077     float width() const { return m_size.width(); }
00078     float height() const { return m_size.height(); }
00079 
00080     void setX(float x) { m_location.setX(x); }
00081     void setY(float y) { m_location.setY(y); }
00082     void setWidth(float width) { m_size.setWidth(width); }
00083     void setHeight(float height) { m_size.setHeight(height); }
00084 
00085     bool isEmpty() const { return m_size.isEmpty(); }
00086 
00087     float right() const { return x() + width(); }
00088     float bottom() const { return y() + height(); }
00089 
00090     void move(const FloatSize& delta) { m_location += delta; } 
00091     void move(float dx, float dy) { m_location.move(dx, dy); } 
00092 
00093     bool intersects(const FloatRect&) const;
00094     bool contains(const FloatRect&) const;
00095 
00096     void intersect(const FloatRect&);
00097     void unite(const FloatRect&);
00098 
00099     // Note, this doesn't match what IntRect::contains(IntPoint&) does; the int version
00100     // is really checking for containment of 1x1 rect, but that doesn't make sense with floats.
00101     bool contains(float px, float py) const
00102         { return px >= x() && px <= right() && py >= y() && py <= bottom(); }
00103     bool contains(const FloatPoint& point) const { return contains(point.x(), point.y()); }
00104 
00105 
00106     void inflateX(float dx) {
00107         m_location.setX(m_location.x() - dx);
00108         m_size.setWidth(m_size.width() + dx + dx);
00109     }
00110     void inflateY(float dy) {
00111         m_location.setY(m_location.y() - dy);
00112         m_size.setHeight(m_size.height() + dy + dy);
00113     }
00114     void inflate(float d) { inflateX(d); inflateY(d); }
00115     void scale(float s);
00116 
00117 #if PLATFORM(CG)
00118     FloatRect(const CGRect&);
00119     operator CGRect() const;
00120 #endif
00121 
00122 #if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
00123     FloatRect(const NSRect&);
00124     operator NSRect() const;
00125 #endif
00126 
00127 #if PLATFORM(QT)
00128     FloatRect(const QRectF&);
00129     operator QRectF() const;
00130 #endif
00131 #if PLATFORM(SYMBIAN)
00132     FloatRect(const TRect&);
00133     operator TRect() const;
00134     TRect rect() const;
00135 #endif
00136 
00137 #if PLATFORM(WX) && USE(WXGC)
00138     FloatRect(const wxRect2DDouble&);
00139     operator wxRect2DDouble() const;
00140 #endif
00141 
00142 private:
00143     FloatPoint m_location;
00144     FloatSize m_size;
00145 };
00146 
00147 inline FloatRect intersection(const FloatRect& a, const FloatRect& b)
00148 {
00149     FloatRect c = a;
00150     c.intersect(b);
00151     return c;
00152 }
00153 
00154 inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
00155 {
00156     FloatRect c = a;
00157     c.unite(b);
00158     return c;
00159 }
00160 
00161 inline bool operator==(const FloatRect& a, const FloatRect& b)
00162 {
00163     return a.location() == b.location() && a.size() == b.size();
00164 }
00165 
00166 inline bool operator!=(const FloatRect& a, const FloatRect& b)
00167 {
00168     return a.location() != b.location() || a.size() != b.size();
00169 }
00170 
00171 IntRect enclosingIntRect(const FloatRect&);
00172 
00173 }
00174 
00175 #endif

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal