기존 TRect보다 향상된 구조체인 CRect입니다.
기존 TRect와 상위 하위 호환을 다 가지고 있고,
선언하면 바로 0으로 초기화 되는 등 몇가지 메소드가 추가 되었습니다.
또 소스 형태이므로 필요하면 메소드를 더 추가해서 사용하는 것도 자유롭습니다.
CRect r = TRect(0, 1, 2, 3);
TRect r2 = r;
CRect r3 = r2;
TCanvas *C = ImageMan->Canvas;
CRect rs = CRect(0, 0, 100, 100);
CRect rz = TRect(0, 0, 100, 100);
C->Rectangle(rs);
이런 식으로 자유롭게 사용 가능합니다.
안드로이드 코딩할 때 있는 메소드가 없어서,
코딩을 조금이라도 편하게 해 보고자 살짝 개량 했습니다.
그냥 기존 TRect 쓰듯이 쓰시면 됩니다.
//---------------------------------------------------------------------------
// 향상된 TRect 구조체
// Written by KTS
struct CRect : public TRect
{
CRect()
{
Clear();
}
CRect(const TPoint& TL, const TPoint& BR)
{
left=TL.x; top=TL.y; right=BR.x; bottom=BR.y;
}
CRect(int l, int t, int r, int b)
{
left=l; top=t; right=r; bottom=b;
}
CRect(RECT& r)
{
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
CRect(const TRect& r)
{
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
void Clear()
{
ZeroMemory(this, sizeof * this);
}
void Set(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
void SetWH(int left, int top, int width, int height)
{
Set(left, top, left + width, top + height);
}
CRect& operator =(const TRect& rc)
{
Left = rc.left;
Top = rc.top;
Right = rc.right;
Bottom = rc.bottom;
return *this;
}
bool operator ==(const CRect& rc) const
{
return left == rc.left && top==rc.top &&
right == rc.right && bottom==rc.bottom;
}
bool operator !=(const CRect& rc) const
{
return !(rc==*this);
}
bool operator ==(const TRect& rc) const
{
return left == rc.left && top==rc.top &&
right == rc.right && bottom==rc.bottom;
}
bool operator !=(const TRect& rc) const
{
return !(rc==*this);
}
};
//---------------------------------------------------------------------------
|