//Shapes.cpp
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Shapes.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//static inline void ValidCtrCheck(TSampleShape *)
{
new TSampleShape(NULL);
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::TSampleShape(TComponent* Owner)
: TGraphicControl(Owner)
{
Height=65;
Width=65;
FBrush=new TBrush();
FBrush->OnChange=StyleChanged;
FPen=new TPen();
FPen->OnChange=StyleChanged;
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::~TSampleShape()
{
delete FBrush;
delete FPen;
}
//------------------------------------------------------------------------
void __fastcall TSampleShape::Paint()
{
int X,Y,W,H,S;
Canvas->Pen=FPen;
Canvas->Brush=FBrush;
W=Width;
H=Height;
X=Y=0;
if(W<H)
S=W;
else
S=H;
switch(FShape)
{
case sstRectangle:
case sstSquare:
Canvas->Rectangle(X,Y,X+W,Y+H);
break;
case sstRoundRect:
case sstRoundSquare:
Canvas->RoundRect(X,Y,X+W,Y+H,S/4,S/4);
break;
case sstCircle:
case sstEllipse:
Canvas->Ellipse(X,Y,X+W,Y+H);
break;
default:
break;
}
}
//------------------------------------------------------------------
namespace Shapes
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TSampleShape)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetShape(TSampleShapeType Value)
{
if(FShape!=Value)
FShape=Value;
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetPen(TPen* Value)
{
FPen->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::SetBrush(TBrush* Value)
{
FBrush->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::StyleChanged(TObject* Owner)
{
Invalidate();
}
//-----------------------------------------------------------------------
//Shapes.h
//---------------------------------------------------------------------------#ifndef ShapesH
#define ShapesH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
enum TSampleShapeType {sstRectangle,sstSquare,sstRoundRect,sstRoundSquare,
sstEllipse,sstCircle};class PACKAGE TSampleShape : public TGraphicControl
{
private:
TSampleShapeType FShape;
void __fastcall SetShape(TSampleShapeType Value);
TPen *FPen;
TBrush *FBrush;
void __fastcall SetPen(TPen* Value);
void __fastcall SetBrush(TBrush* Value);
protected:
virtual void __fastcall Paint();
public:
virtual __fastcall TSampleShape(TComponent* Owner);
__fastcall ~TSampleShape();
void __fastcall StyleChanged(TObject* Owner);
__published:
__property DragCursor;
__property DragMode;
__property OnDragOver;
__property OnDragDrop;
__property OnEndDrag;
__property OnMouseDown;
__property OnMouseMove;
__property OnMouseUp;
__property TSampleShapeType Shape={read=FShape,write=SetShape,nodefault};
__property Height;
__property Width;
__property TBrush* Brush={read=FBrush,write=SetBrush,nodefault};
__property TPen* Pen={read=FPen,write=SetPen,nodefault};
};
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop#include "Shapes.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//static inline void ValidCtrCheck(TSampleShape *)
{
new TSampleShape(NULL);
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::TSampleShape(TComponent* Owner)
: TGraphicControl(Owner)
{
Height=65;
Width=65;
FBrush=new TBrush();
FBrush->OnChange=StyleChanged;
FPen=new TPen();
FPen->OnChange=StyleChanged;
}
//---------------------------------------------------------------------------
__fastcall TSampleShape::~TSampleShape()
{
delete FBrush;
delete FPen;
}
//------------------------------------------------------------------------
void __fastcall TSampleShape::Paint()
{
int X,Y,W,H,S;
Canvas->Pen=FPen;
Canvas->Brush=FBrush;
W=Width;
H=Height;
X=Y=0;
if(W<H)
S=W;
else
S=H;
switch(FShape)
{
case sstRectangle:
case sstSquare:
Canvas->Rectangle(X,Y,X+W,Y+H);
break;
case sstRoundRect:
case sstRoundSquare:
Canvas->RoundRect(X,Y,X+W,Y+H,S/4,S/4);
break;
case sstCircle:
case sstEllipse:
Canvas->Ellipse(X,Y,X+W,Y+H);
break;
default:
break;
}
}
//------------------------------------------------------------------
namespace Shapes
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TSampleShape)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetShape(TSampleShapeType Value)
{
if(FShape!=Value)
FShape=Value;
Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TSampleShape::SetPen(TPen* Value)
{
FPen->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::SetBrush(TBrush* Value)
{
FBrush->Assign(Value);
}
//-----------------------------------------------------------------------
void __fastcall TSampleShape::StyleChanged(TObject* Owner)
{
Invalidate();
}
//-----------------------------------------------------------------------
//Shapes.h
//---------------------------------------------------------------------------#ifndef ShapesH
#define ShapesH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
enum TSampleShapeType {sstRectangle,sstSquare,sstRoundRect,sstRoundSquare,
sstEllipse,sstCircle};class PACKAGE TSampleShape : public TGraphicControl
{
private:
TSampleShapeType FShape;
void __fastcall SetShape(TSampleShapeType Value);
TPen *FPen;
TBrush *FBrush;
void __fastcall SetPen(TPen* Value);
void __fastcall SetBrush(TBrush* Value);
protected:
virtual void __fastcall Paint();
public:
virtual __fastcall TSampleShape(TComponent* Owner);
__fastcall ~TSampleShape();
void __fastcall StyleChanged(TObject* Owner);
__published:
__property DragCursor;
__property DragMode;
__property OnDragOver;
__property OnDragDrop;
__property OnEndDrag;
__property OnMouseDown;
__property OnMouseMove;
__property OnMouseUp;
__property TSampleShapeType Shape={read=FShape,write=SetShape,nodefault};
__property Height;
__property Width;
__property TBrush* Brush={read=FBrush,write=SetBrush,nodefault};
__property TPen* Pen={read=FPen,write=SetPen,nodefault};
};
//---------------------------------------------------------------------------
#endif
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货