X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Frect.hh;h=65a679c74240440864df691885145a95f5e907ca;hb=6c3aec9e0996d2957855c188b5ff60bf4bc628fa;hp=1ffefcba2edcdd54160e280cdfea698931b9f1b9;hpb=e9085c3a45be749fb5bda969552be52a0d60afe0;p=chaz%2Fopenbox diff --git a/otk/rect.hh b/otk/rect.hh index 1ffefcba..65a679c7 100644 --- a/otk/rect.hh +++ b/otk/rect.hh @@ -6,6 +6,7 @@ extern "C" { #include } +#include "point.hh" #include namespace otk { @@ -24,8 +25,22 @@ public: @param w The width of the rectangle @param h The height of the rectangle */ - inline Rect(int x, int y, unsigned int w, unsigned int h) + inline Rect(int x, int y, int w, int h) : _x1(x), _y1(y), _x2(w + x - 1), _y2(h + y - 1) { } + //! Constructs a Rect from 2 Point objects + /*! + @param location The point defining the top left corner of the rectangle + @param size The width and height of the rectangle + */ + inline Rect(const Point &location, const Point &size) + : _x1(location.x()), _y1(location.y()), + _x2(size.x() + location.x() - 1), _y2(size.y() + location.y() - 1) { } + //! Constructs a Rect from another Rect + /*! + @param rect The rectangle from which to construct this new one + */ + inline Rect(const Rect &rect) + : _x1(rect._x1), _y1(rect._y1), _x2(rect._x2), _y2(rect._y2) { } //! Constructs a Rect from an XRectangle inline explicit Rect(const XRectangle& xrect) : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1), @@ -44,6 +59,9 @@ public: inline int x(void) const { return _x1; } //! The y component of the point defining the top left corner of the Rect inline int y(void) const { return _y1; } + //! Returns the Point that defines the top left corner of the rectangle + inline Point location() const { return Point(_x1, _y1); } + //! Sets the x coordinate of the Rect. /*! @param x The new x component of the point defining the top left corner of @@ -64,27 +82,40 @@ public: the rectangle */ void setPos(int x, int y); + //! Sets the x and y coordinates of the Rect. + /*! + @param location The point defining the top left corner of the rectangle. + */ + void setPos(const Point &location); //! The width of the Rect - inline unsigned int width(void) const { return _x2 - _x1 + 1; } + inline int width(void) const { return _x2 - _x1 + 1; } //! The height of the Rect - inline unsigned int height(void) const { return _y2 - _y1 + 1; } + inline int height(void) const { return _y2 - _y1 + 1; } + //! Returns the size of the Rect + inline Point size() const { return Point(_x2 - _x1 + 1, _y2 - _y1 + 1); } + //! Sets the width of the Rect /*! @param w The new width of the rectangle */ - void setWidth(unsigned int w); + void setWidth(int w); //! Sets the height of the Rect /*! @param h The new height of the rectangle */ - void setHeight(unsigned int h); - //! Sets the width of the Rect. + void setHeight(int h); + //! Sets the size of the Rect. /*! @param w The new width of the rectangle @param h The new height of the rectangle */ - void setSize(unsigned int w, unsigned int h); + void setSize(int w, int h); + //! Sets the size of the Rect. + /*! + @param size The new size of the rectangle + */ + void setSize(const Point &size); //! Sets the position and size of the Rect /*! @@ -95,7 +126,13 @@ public: @param w The new width of the rectangle @param h The new height of the rectangle */ - void setRect(int x, int y, unsigned int w, unsigned int h); + void setRect(int x, int y, int w, int h); + //! Sets the position and size of the Rect + /*! + @param location The new point defining the top left corner of the rectangle + @param size The new size of the rectangle + */ + void setRect(const Point &location, const Point &size); //! Sets the position of all 4 sides of the Rect /*! @@ -105,6 +142,12 @@ public: @param b The new bottom coordinate of the rectangle */ void setCoords(int l, int t, int r, int b); + //! Sets the position of all 4 sides of the Rect + /*! + @param tl The new point at the top left of the rectangle + @param br The new point at the bottom right of the rectangle + */ + void setCoords(const Point &tl, const Point &br); //! Determines if two Rect objects are equal /*! @@ -130,7 +173,7 @@ public: /*! The intersection of the rectangles will consist of just the area where the two rectangles overlap. - @param A second Rect object to form an intersection with. + @param a A second Rect object to form an intersection with. @return The intersection between this Rect and the one passed to the function */ @@ -147,7 +190,7 @@ public: /*! The intersection of the rectangles will consist of just the area where the two rectangles overlap. - @param A second Rect object to form an intersection with. + @param a A second Rect object to form an intersection with. */ inline Rect &operator&=(const Rect &a) { *this = *this & a; return *this; } @@ -176,6 +219,14 @@ public: @return true if the point is contained within this Rect; otherwise, false */ bool contains(int x, int y) const; + //! Determines if this Rect contains a point + /*! + The rectangle contains the point if it falls within the rectangle's + boundaries. + @param p The point to operate on + @return true if the point is contained within this Rect; otherwise, false + */ + bool contains(const Point &p) const; //! Determines if this Rect contains another Rect entirely /*! This rectangle contains the second rectangle if it is entirely within this