/*
        rect.h (rectangle)

        V1.00 - 181096  Kimmo Teräväinen
        -----   ------  ----------------
        V0.01   181096  Started
        V0.05   201096  Most methods written & tested.
        V0.06   211096  cPiste & cSize are inherited from cAlkioR2
                        (item R²)
        V0.07   031196  cPiste -> cPoint, caKuvio -> caImage
        V0.08   031196  Transfered cPoint ja cSize to point.h.
        V0.10   141196  Transfered out from cImage.
        V0.11   271196  BUG FIXED: Inside() & OverLap were always FALSE

*/
#ifndef DC1_POKER_RECTANGLE
#define DC1_POKER_RECTANGLE

#include "point.h"
#include "IDCMP.h"

class cRectangle {
protected:
  cPoint pos;
  cSize  size;
public:
  cRectangle(int a=0,int b=0,int c=0,int d=0): pos(a,b), size(c,d) {}
  cRectangle(const cRectangle &rect): pos(rect.pos), size(rect.size) {}

  virtual cRectangle &operator=(const cRectangle &rect) {
    pos=rect.pos;
    size=rect.size;
    return *this;
  }

  int Left() const { return pos.X();}
  int Top() const  { return pos.Y();}
  int Width() const { return size.X();}
  int Height() const  { return size.Y();}
  int Right() const { return pos.X()+size.X()-1;}
  int Bottom() const  { return pos.Y()+size.Y()-1;}

  cPoint &MoveTo(const cPoint &p) { pos=p; return pos; }
  cPoint &Move(const cPoint &p) {  pos+=p; return pos; }

  int Inside(int x,int y) const {
    if((pos.X()-x)>0) return FALSE;
    if((pos.Y()-y)>0) return FALSE;
    if((pos.X()+size.X()-x)<=0) return FALSE;
    if((pos.Y()+size.Y()-y)<=0) return FALSE;
    return TRUE;
  }
  int Inside(const cPoint &p) const { return Inside(p.X(),p.Y()); }

  int OverLap(int left,int top,int right,int bottom) const {
    if((pos.X()-right)>0) return FALSE;
    if((pos.Y()-bottom)>0) return FALSE;
    if((pos.X()+size.X()-left)<=0) return FALSE;
    if((pos.Y()+size.Y()-top)<=0) return FALSE;
    return TRUE;
  }
  int OverLap(const cRectangle &r) const  {
    return OverLap(r.Left(),r.Top(),r.Right(),r.Bottom());
  }
};


class cMsgRectangle : public cRectangle , public cIDCMP {
public:
  cMsgRectangle(int a=0,int b=0,int c=0,int d=0): cRectangle(a,b,c,d) {}
};

#endif