Saturday, October 21, 2006

TRect type

TRect defines a rectangle.
Unit
Types

struct TRect
 {
 TRect() {}
 TRect(const TPoint& TL, const TPoint& BR)
  { left=TL.x; top=TL.y; right=BR.x; bottom=BR.y; }
 TRect(int l, int t, int r, int b)
  { left=l; top=t; right=r; bottom=b; }
 TRect(RECT& r)
  {
  left = r.left;
  top = r.top;
  right = r.right;
  bottom = r.bottom;
  }

int Width() const { return right - left; }
int Height() const { return bottom - top ; }
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); }
 __property LONG Left = { read=left, write=left };
 __property LONG Top = { read=top, write=top };
 __property LONG Right = { read=right, write=right };
 __property LONG Bottom = { read=bottom, write=bottom };
 };

Description
TRect represents the dimensions of a rectangle. The coordinates are specified as either four separate integers representing the left, top, right, and bottom sides, or as two points representing the locations of the top left and bottom right corners.

Typically, TRect values represent pixel locations, where the origin of the pixel coordinate system is in the top left corner of the screen (screen coordinates) or the top left corner of a control client area (client coordinates). When a TRect value represents a rectangle on the screen, by convention the top and left edges are considered inside the rectangle and the bottom and right edges are considered outside the rectangle. This convention allows the width of the rectangle to be Right - Left and the height to be Bottom - Top.
要特別注意的一點是 TRect 這個長方塊中所指明的區域並不包含 the bottom and right edges, 這是為了讓 rectangle 的長寬值剛好符合座標相減的緣故。
 

No comments:

Post a Comment