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
[1021] Bitmap 그림을 표시할 수 있는 TShape 컴포넌트.
김태선 [cppbuilder] 8648 읽음    2010-11-29 14:26
컴포넌트 교체식으로 구현된 Bitmap 그림을 넣을 수 있는 TShape 컴포넌트 입니다.
화면을 이쁘게 만들때 가끔, TShape의 단순한 모양이 아닌 그림을 표시하고 싶을때가 있습니다.
물론 이럴때는 TImage를 사용하면 됩니다.
그러나 이미 코딩되었는 많은 루틴을 건드리지 않고, 살짝 Bitmap 표시 기능만 덧붙이고자 할때 유용합니다.

기존 컴포넌트에서 기능 일부만 살짝 바꿀때는 컴포넌트 교체식이 짱입니다.

기존 Shape 대신 Bitmap을 표시할 수도 있고,
Shape을 유지한 위에 덧그릴 수도 있습니다.
비트맵의 투명화는 지원하지 않으니, 이를 가능하게 하고 싶다면 조금 연구를 해야 합니다.


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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
// Bitmap 그림을 표시할 수 있는 TShape 컴포넌트.
// Written by KTS.

class TShape : public Extctrls::TShape
{
	typedef Extctrls::TShape inherited;

public:
	Graphics::TBitmap *Bmp;
	int		BmpX, BmpY;
	bool	bStretch;
	bool	bKeepShape;

	__fastcall virtual TShape(TComponent* Owner) : inherited(Owner)
	{
		Bmp = NULL;
		BmpX = BmpY = 0;
		bStretch = true;
		bKeepShape = false;
	}

	void __fastcall Paint()
	{
		if (Bmp == NULL)
			inherited::Paint();
		else
		{
			if (bKeepShape)
				inherited::Paint();
			if (bStretch)
				Canvas->StretchDraw(ClientRect, Bmp);
			else
				Canvas->Draw(BmpX, BmpY, Bmp);
		}
	}

	void	SetBitmap(Graphics::TBitmap *bmp)
	{
		Bmp = bmp;
		Invalidate();
	}
};
#define TShape        ::TShape

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


class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TShape *Shape1;
    TBitBtn *BitBtn1;
    TBitBtn *BitBtn2;
    TImage *Image1;
    void __fastcall BitBtn1Click(TObject *Sender);
    void __fastcall BitBtn2Click(TObject *Sender);
private:    // User declarations
public:        // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif







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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
// set bitmap

void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
    Shape1->BmpX = 100;
    Shape1->BmpY = 100;
    Shape1->bKeepShape = true;
    Shape1->bStretch = false;

    Shape1->SetBitmap(여기에 그릴 비트맵을 지정하면 됩니다);
}
//---------------------------------------------------------------------------
// clear bitmap

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
    Shape1->SetBitmap(NULL);
}
//---------------------------------------------------------------------------


그럼.

+ -

관련 글 리스트
1021 Bitmap 그림을 표시할 수 있는 TShape 컴포넌트. 김태선 8648 2010/11/29
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.