]> Dogcows Code - chaz/openbox/commitdiff
make methods for Rect that use Point
authorDana Jansens <danakj@orodu.net>
Sun, 10 Nov 2002 11:25:40 +0000 (11:25 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 10 Nov 2002 11:25:40 +0000 (11:25 +0000)
otk/rect.cc
otk/rect.hh

index db53b37e1a2f53a799e3d1c4dbb3119e93ce6147..f5068efe3e9fe61057bc53061626c72e1d9f123c 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace otk {
 
-void Rect::setX(int x) {
+void Rect::setX(int x)
+{
   _x2 += x - _x1;
   _x1 = x;
 }
@@ -15,7 +16,17 @@ void Rect::setY(int y)
 }
 
 
-void Rect::setPos(int x, int y) {
+void Rect::setPos(const Point &location)
+{
+  _x2 += location.x() - _x1;
+  _x1 = location.x();
+  _y2 += location.y() - _y1;
+  _y1 = loaction.y();
+}
+
+
+void Rect::setPos(int x, int y)
+{
   _x2 += x - _x1;
   _x1 = x;
   _y2 += y - _y1;
@@ -23,28 +34,46 @@ void Rect::setPos(int x, int y) {
 }
 
 
-void Rect::setWidth(unsigned int w) {
+void Rect::setWidth(unsigned int w)
+{
   _x2 = w + _x1 - 1;
 }
 
 
-void Rect::setHeight(unsigned int h) {
+void Rect::setHeight(unsigned int h)
+{
   _y2 = h + _y1 - 1;
 }
 
 
-void Rect::setSize(unsigned int w, unsigned int h) {
+void Rect::setSize(unsigned int w, unsigned int h)
+{
   _x2 = w + _x1 - 1;
   _y2 = h + _y1 - 1;
 }
 
 
-void Rect::setRect(int x, int y, unsigned int w, unsigned int h) {
+void Rect::setSize(const Point &size)
+{
+  _x2 = size.x() + _x1 - 1;
+  _y2 = size.y() + _y1 - 1;
+}
+
+
+void Rect::setRect(int x, int y, unsigned int w, unsigned int h)
+{
   *this = Rect(x, y, w, h);
 }
 
 
-void Rect::setCoords(int l, int t, int r, int b) {
+void setRect(const Point &location, const Point &size)
+{
+  *this = Rect(location, size);
+}
+
+
+void Rect::setCoords(int l, int t, int r, int b)
+{
   _x1 = l;
   _y1 = t;
   _x2 = r;
@@ -52,7 +81,17 @@ void Rect::setCoords(int l, int t, int r, int b) {
 }
 
 
-Rect Rect::operator|(const Rect &a) const {
+void setCoords(const Point &tl, const Point &br)
+{
+  _x1 = tl.x();
+  _y1 = tl.y();
+  _x2 = br.x();
+  _y2 = br.y();
+}
+
+
+Rect Rect::operator|(const Rect &a) const
+{
   Rect b;
 
   b._x1 = std::min(_x1, a._x1);
@@ -64,7 +103,8 @@ Rect Rect::operator|(const Rect &a) const {
 }
 
 
-Rect Rect::operator&(const Rect &a) const {
+Rect Rect::operator&(const Rect &a) const
+{
   Rect b;
 
   b._x1 = std::max(_x1, a._x1);
@@ -76,19 +116,22 @@ Rect Rect::operator&(const Rect &a) const {
 }
 
 
-bool Rect::intersects(const Rect &a) const {
+bool Rect::intersects(const Rect &a) const
+{
   return std::max(_x1, a._x1) <= std::min(_x2, a._x2) &&
          std::max(_y1, a._y1) <= std::min(_y2, a._y2);
 }
 
 
-bool Rect::contains(int x, int y) const {
+bool Rect::contains(int x, int y) const
+{
   return x >= _x1 && x <= _x2 &&
          y >= _y1 && y <= _y2;
 }
 
 
-bool Rect::contains(const Rect& a) const {
+bool Rect::contains(const Rect& a) const
+{
   return a._x1 >= _x1 && a._x2 <= _x2 &&
          a._y1 >= _y1 && a._y2 <= _y2;
 }
index 925456a196711acf6d13b7197df73601cd7c4375..dc3d05d658b41008cd880d5684b36dc4a94784ae 100644 (file)
@@ -26,6 +26,14 @@ public:
   */
   inline Rect(int x, int y, unsigned int w, unsigned 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 an XRectangle
   inline explicit Rect(const XRectangle& xrect)
     : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
@@ -44,6 +52,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,11 +75,19 @@ 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; }
   //! The height of the Rect
   inline unsigned 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
@@ -79,12 +98,17 @@ public:
     @param h The new height of the rectangle
   */
   void setHeight(unsigned int h);
-  //! Sets the width of the Rect.
+  //! 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);
+  //! 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
   /*!
@@ -96,6 +120,12 @@ public:
     @param h The new height of the rectangle
    */
   void setRect(int x, int y, unsigned int w, unsigned 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 +135,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
   /*!
This page took 0.033112 seconds and 4 git commands to generate.