//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Clock.h"
#include <math.h>
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
void __fastcall TCenter::SetX(int value)
{
if( value != FX )
{
FX = value;
UpdateParent();
}
}
void __fastcall TCenter::SetY(int value)
{
if( value != FY )
{
FY = value;
UpdateParent();
}
}
void __fastcall TCenter::UpdateParent(void)
{
FParent->Repaint();
}
TCenter::TCenter() : TPersistent()
{
FX = 50;
FY = 50;
}
//class THand--------------------------------------------------------
void __fastcall THand::SetRadius(int value)
{
if( value != FRadius )
{
FRadius = value;
UpdateParent();
}
}
void __fastcall THand::SetBackRadius(int value)
{
if( value != FBackRadius )
{
FBackRadius = value;
UpdateParent();
}
}
void __fastcall THand::SetWidth(int value)
{
if( value != FWidth )
{
FWidth = value;
UpdateParent();
}
}
void __fastcall THand::SetColor(TColor value)
{
if( value != FColor )
{
FColor = value;
UpdateParent();
}
}
void __fastcall THand::UpdateParent(void)
{
FParent->Repaint();
}
THand::THand() : TPersistent()
{
}
//class TCenterPoint------------------------------------------------------------
void __fastcall TCenterPoint::SetPointSize(int value)
{
if( value != FPointSize )
{
FPointSize = value;
UpdateParent();
}
}
void __fastcall TCenterPoint::SetPenSize(int value)
{
if( value != FPenSize )
{
FPenSize = value;
UpdateParent();
}
}
void __fastcall TCenterPoint::SetPenColor(TColor value)
{
if( value != FPenColor )
{
FPenColor = value;
UpdateParent();
}
}
void __fastcall TCenterPoint::SetFillColor(TColor value)
{
if( value != FFillColor )
{
FFillColor = value;
UpdateParent();
}
}
void __fastcall TCenterPoint::UpdateParent(void)
{
FParent->Repaint();
}
TCenterPoint::TCenterPoint() : TPersistent()
{
}
//class TClock------------------------------------------------------------------
__fastcall TClock::TClock(TComponent* AOwner) : TCustomControl(AOwner)
{
Width = 100;
Height = 100;
FOldWidth = Width;
FOldHeight = Height;
FTransparentColor = clFuchsia;
FTransparent = false;
DisImage = new Graphics::TBitmap();
WorkImage = new Graphics::TBitmap();
FPicture = new Graphics::TPicture();
FStepTimer = new TTimer(this); //建立时钟发生器
FInterval = 1000;
FInterActive = true;
FStepTimer->Enabled = FInterActive;
FStepTimer->Interval = FInterval;
FStepTimer->OnTimer = UpdateClock;
FVerInfo = "sundiy's super Clock";
FColorOrBmp = bgPicture;
FAutoCenter = true;
FHourHandEnabled = true;
FMinuteHandEnabled = true;
FSecondHandEnabled = true;
FPictureStyle = psNone;
FThemeStyle = tsNone;
FRoundX = 25;
FRoundY = 25;
FHoleRound = false;
FCenter = new TCenter;
FCenter->Parent = this;
FCenter->X = 50;
FCenter->Y = 50;
FHourHand = new THand;
FHourHand->Parent = this;
FHourHand->BackRadius = 6;
FHourHand->Color = clGreen;
FHourHand->Radius = 25;
FHourHand->Width = 2;
FMinuteHand = new THand;
FMinuteHand->Parent = this;
FMinuteHand->BackRadius = 6;
FMinuteHand->Color = clBlue;
FMinuteHand->Radius = 30;
FMinuteHand->Width = 2;
FSecondHand = new THand;
FSecondHand->Parent = this;
FSecondHand->BackRadius = 11;
FSecondHand->Color = clRed;
FSecondHand->Radius = 38;
FSecondHand->Width = 1;
FDrawCenterPoint = new TCenterPoint;
FDrawCenterPoint->Parent = this;
FDrawCenterPoint->PointSize = 4;
FDrawCenterPoint->PenSize = 1;
FDrawCenterPoint->FillColor = clBlack;
FDrawCenterPoint->PenColor = clWhite;
}
__fastcall TClock::~TClock(void)
{
delete FStepTimer;
delete WorkImage;
delete DisImage;
delete FPicture;
}
void __fastcall TClock::SetPicture(TPicture* value)
{
if( !(value->Graphic->Empty) )
{
FPicture->Assign(value);
Width = FPicture->Width;
Height = FPicture->Height;
Repaint();
}
}
void __fastcall TClock::SetTransparent(bool value)
{
if( value != FTransparent )
{
FTransparent = value;
Repaint();
}
}
void __fastcall TClock::SetTransparentColor(TColor Value)
{
if( Value != FTransparentColor )
{
FTransparentColor = Value;
Repaint();
}
}
void __fastcall TClock::SetInterval(int Value)
{
if( Value != FInterval )
{
FInterval = Value;
FStepTimer->Interval = FInterval;
Repaint();
}
}
void __fastcall TClock::SetActive(bool Value)
{
if( Value != Active )
{
FInterActive = Value;
FStepTimer->Enabled = FInterActive;
Repaint();
}
}
void __fastcall TClock::VersionMark(String value)
{
}
void __fastcall TClock::SetBgColor(TColor Value)
{
if( Value != FBgUseColor )
{
FBgUseColor = Value;
Repaint();
}
}
void __fastcall TClock::SetBgStyle(TClockBgStyle Value)
{
if( Value != FColorOrBmp )
{
FColorOrBmp = Value;
Repaint();
}
}
void __fastcall TClock::SetCenterPoint(bool Value)
{
if( Value != FCenterPoint )
{
FCenterPoint = Value;
Repaint();
}
}
void __fastcall TClock::SetAutoCenter(bool Value)
{
if( Value != FAutoCenter )
{
if( Value )
{
FCenter->X = Width / 2;
FCenter->Y = Height / 2;
}
FAutoCenter = Value;
Repaint();
}
}
void __fastcall TClock::SetHourHandEnabled(bool value)
{
if( value != FHourHandEnabled )
{
FHourHandEnabled = value;
Repaint();
}
}
void __fastcall TClock::SetMinuteHandEnabled(bool value)
{
if( value != FMinuteHandEnabled )
{
FMinuteHandEnabled = value;
Repaint();
}
}
void __fastcall TClock::SetSecondHandEnabled(bool value)
{
if( value != FSecondHandEnabled )
{
FSecondHandEnabled = value;
Repaint();
}
}
void __fastcall TClock::SetPictureStyle(TClockPictureStyle Value)
{
if( Value != FPictureStyle )
{
FPictureStyle = Value;
Repaint();
}
}
void __fastcall TClock::SetThemeStyle(TClockThemeStyle value)
{
if( value != FThemeStyle )
{
FThemeStyle = value;
StyleChanged();
}
}
void __fastcall TClock::SetRoundX(int Value)
{
if( Value != FRoundX )
{
FRoundX = Value;
StyleChanged();
}
}
void __fastcall TClock::SetRoundY(int Value)
{
if( Value != FRoundY )
{
FRoundY = Value;
StyleChanged();
}
}
void __fastcall TClock::SetHoleRound(bool Value)
{
if( Value != FHoleRound )
{
FHoleRound = Value;
Repaint();
}
}
void __fastcall TClock::UpdateClock(TObject* Sender)
{
Word H,M,S,MS;
TDateTime dt = Now();
dt.DecodeTime(&H, &M, &S, &MS);
Paint();
if( s != OldSecond)
{
if( NULL != FSecond )
FSecond(this, s);
OldSecond = s;
}
if( m != OldMinute)
{
if( NULL != FMinute )
FMinute(this, m);
OldMinute = m;
}
if( h != OldHour )
{
if( NULL != FHo