C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[1124] 향상된 TRect 구조체 : CRect
김태선 [cppbuilder] 34123 읽음    2013-02-12 20:00
기존 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);
	}
};


//---------------------------------------------------------------------------

+ -

관련 글 리스트
1124 향상된 TRect 구조체 : CRect 김태선 34123 2013/02/12
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.