#include #pragma hdrstop //--------------------------------------------------------------------------- #include "KShape.h" #include "TClrUtil.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(TKShape *) { new TKShape(NULL); } //--------------------------------------------------------------------------- __fastcall TKShape::TKShape(Classes::TComponent *AOwner) : TGraphicControl(AOwner) { ControlStyle = ControlStyle << csReplicatable; Width = 50; Height = 20; FPen = new Graphics::TPen; FPen->OnChange = RepaintRequest; FBrush = new Graphics::TBrush; FBrush->OnChange = RepaintRequest; FFont = new Graphics::TFont; FFont->OnChange = RepaintRequest; FText = ""; FTextX = 1; FTextY = 1; } //--------------------------------------------------------------------------- __fastcall TKShape::~TKShape() { if (FFont) { delete FFont; FFont = NULL; } if (FBrush) { delete FBrush; FBrush = NULL; } if (FPen) { delete FPen; FPen = NULL; } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetPen(Graphics::TPen *Value) { FPen->Assign(Value); Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TKShape::SetBrush(Graphics::TBrush *Value) { FBrush->Assign(Value); Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TKShape::SetFont(Graphics::TFont *Value) { FFont->Assign(Value); Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TKShape::SetText(AnsiString Value) { if (Canvas->TextWidth(Value) < Width && Canvas->TextHeight(Value) < Height) { FText = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetTextX(int Value) { if ((Width-1) > Value && Value > 0) { FTextX = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetTextY(int Value) { if ((Height-1) > Value && Value > 0) { FTextY = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetText1(AnsiString Value) { if (Canvas->TextWidth(Value) < Width && Canvas->TextHeight(Value) < Height) { FText1 = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetTextX1(int Value) { if ((Width-1) > Value && Value > 0) { FTextX1 = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::SetTextY1(int Value) { if ((Height-1) > Value && Value > 0) { FTextY1 = Value; Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TKShape::RepaintRequest(System::TObject *Sender) { Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TKShape::Paint() { int X, Y, W, H, tw, tx; Canvas->Pen = FPen; Canvas->Brush = FBrush; Canvas->Font = FFont; Canvas->Font->Color = TColorToBW(Canvas->Brush->Color); X = Canvas->Pen->Width / 2; Y = X; W = Width - Canvas->Pen->Width + 1; H = Height - Canvas->Pen->Width + 1; if (Canvas->Pen->Width == 0) { W--; H--; } Canvas->Rectangle(X, Y, X + W, Y + H); tw = Canvas->TextWidth(FText); tx = (Width - 1) - tw; if (FTextX > tx) Canvas->TextOut(tx, FTextY, FText); else Canvas->TextOut(FTextX, FTextY, FText); tw = Canvas->TextWidth(FText1); tx = (Width - 1) - tw; if (FTextX1 > tx) Canvas->TextOut(tx, FTextY1, FText1); else Canvas->TextOut(FTextX1, FTextY1, FText1); } //--------------------------------------------------------------------------- namespace Kshape { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TKShape)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------