?? bmpclock.pas
字號:
if FMinuteHandEnabled then begin
DrawHand(MinuteHand.Radius, MinuteHand.BackRadius, MinuteHand.Width, MinuteHand.Color, FCurAngle);
end;
{---------畫出秒針-----------}
FCurAngle := 2 * Pi * S / 60;
if FSecondHandEnabled then begin
DrawHand(SecondHand.Radius, SecondHand.BackRadius, SecondHand.Width, SecondHand.Color, FCurAngle);
end;
{---------畫中心點-----------}
if FCenterPoint then begin
Drawponit(CenterMark.FPointSize, CenterMark.FPenSize, CenterMark.FFillColor, CenterMark.FPenColor);
end;
end; {with}
Self.Canvas.Draw(0, 0, WorkImage); //將結果畫到前臺
if (FoldWidth <> Width) or (FoldHeight <> Height) then begin //大小改變時,重畫形狀;
FoldWidth := Width;
FoldHeight := Height;
StyleChanged;
end;
end;
{===================自定義背景位圖======================}
procedure TBmpClock.SetPicture(Value: TPicture);
begin
if not (Value.Graphic.Empty) then begin
FPicture.Assign(value);
Width := FPicture.Width;
Height := FPicture.Height;
Repaint;
end;
end;
{====================設置背景透明=======================}
procedure TBmpClock.SetTransParent(Value: Boolean);
begin
if Value <> FTransparent then begin
FTransparent := Value;
Repaint;
end;
end;
{====================設置背景透明的顏色=================}
procedure TBmpClock.SetTransParentColor(Value: TColor);
begin
if Value <> FTransParentColor then begin
FTransParentColor := Value;
Repaint;
end;
end;
{=====================設置時鐘計時周期==================}
procedure TBmpClock.SetInterval(Value: Word);
begin
if Value <> FInterval then begin
FInterval := Value;
FStepTime.Interval := FInterval;
Repaint;
end;
end;
{======================啟動時鐘計時=====================}
procedure TBmpClock.SetActive(Value: Boolean);
begin
if Value <> Active then begin
FInterActive := Value;
FStepTime.Enabled := FInterActive;
Repaint;
end;
end;
{======================更改啟用屬性=====================}
procedure TBmpClock.CmEnabledChanged(var message: TWMNoParams);
begin
inherited;
FStepTime.Enabled := Self.Enabled;
FInterActive := Self.Enabled;
Repaint;
end;
{=======================版本信息(唯讀屬性)============}
procedure TBmpClock.VersionMark(Value: string);
var
s: string;
begin
s := 'BmpClock V3.0 版權所有(C) 2003-2005 小帆工作室';
if Value <> FVerInfo then begin
MessageBox(HANDLE, PChar(s),
'關于 BmpClock V3.0', MB_OK + MB_ICONINFORMATION);
FVerInfo := s;
end;
end;
{===================設置自動中心========================}
procedure TBmpClock.SetAutoCenter(Value: Boolean);
begin
if Value <> FAutoCenter then
begin
if Value then
begin
with FCenter do
begin
X := Width div 2;
Y := Height div 2;
end;
end;
FAutoCenter := Value;
Repaint;
end;
end;
{========================使用純顏色背景=================}
procedure TBmpClock.SetBgStyle(Value: TBgStyle);
begin
if Value <> FColorOrBmp then begin
FColorOrBmp := Value;
Repaint;
end;
end;
{=====================設置背景顏色======================}
procedure TBmpClock.SetBgColor(Value: TColor);
begin
if Value <> FBgUseColor then begin
FBgUseColor := Value;
Repaint;
end;
end;
{======================設置中心點=======================}
procedure TBmpClock.SetCenterPoint(Value: Boolean);
begin
if Value <> FCenterPoint then begin
FCenterPoint := Value;
Repaint;
end;
end;
{================指針算法 (核心代碼 I )================}
procedure TBmpClock.DrawHand(Radius, BackRadius, HandWidth: Integer; HandColor: TColor; Angle: Real);
var
X, Y, Xh, Yh, Xb, Yb, FXCenter, FYCenter: Integer;
begin
{---------定義中心-----------}
if FAutoCenter then begin
FXCenter := Width div 2;
FYCenter := Height div 2
end
else begin
FXCenter := FCenter.FX;
FYCenter := FCenter.FY;
end;
with WorkImage.Canvas do begin
Pen.Width := HandWidth;
Pen.Color := HandColor;
Angle := FCurAngle; //取得當前指針角度
Y := Round(FYCenter - Radius * cos(Angle));
X := Round(FXCenter + Radius * sin(Angle));
Yb := Round(FYCenter + BackRadius * cos(Angle));
Xb := Round(FXCenter - BackRadius * sin(Angle));
Yh := Round(FYCenter - BackRadius * cos(Angle));
Xh := Round(FXCenter + BackRadius * sin(Angle));
if FHoleRound then begin
MoveTo(Xh, Yh);
LineTo(X, Y);
end
else begin
MoveTo(Xb, Yb);
LineTo(X, Y); //畫時鐘指針;
end;
end;
end;
procedure TBmpClock.SetHoleRound(Value: Boolean);
begin
if Value <> FHoleRound then
begin
FHoleRound := Value;
Repaint;
end;
end;
{====================畫中心點過程=======================}
procedure TBmpClock.DrawPonit(PointSize, PenSize: Integer; FillColor, PenColor: TColor);
var
FXCenter, FYCenter: Integer;
begin
if FAutoCenter then begin
FXCenter := Width div 2;
FYCenter := Height div 2
end
else begin
FXCenter := FCenter.FX;
FYCenter := FCenter.FY;
end;
with WorkImage.Canvas do begin
Pen.Width := PenSize;
Pen.Color := PenColor;
Brush.Color := FillColor;
RoundRect((FXCenter) - PointSize, (FYCenter) - PointSize, (FXCenter) + PointSize, (FYCenter) + PointSize, Width, Height);
end;
end;
{====================是否啟用時針=======================}
procedure TBmpClock.SetHourHandEnabled(Value: Boolean);
begin
if Value <> FHourHandEnabled then begin
FHourHandEnabled := Value;
Repaint;
end;
end;
{=====================是否啟用分針======================}
procedure TBmpClock.SetMinuteHandEnabled(Value: Boolean);
begin
if Value <> FMinuteHandEnabled then begin
FMinuteHandEnabled := Value;
Repaint;
end;
end;
{====================是否啟用秒針=======================}
procedure TBmpClock.SetSecondHandEnabled(Value: Boolean);
begin
if Value <> FSecondHandEnabled then begin
FSecondHandEnabled := Value;
Repaint;
end;
end;
{====================設置背景圖效果=====================}
procedure TBmpClock.SetPictureStyle(Value: TPictureStyle);
begin
if Value <> FPictureStyle then begin
FPictureStyle := Value;
Repaint;
end;
end;
{====================設置控件外形=======================}
procedure TBmpClock.SetThemeStyle(Value: TThemeStyle);
begin
if value <> FThemeStyle then
begin
FThemeStyle := Value;
StyleChanged;
end;
end;
{=================設置圓角 X============================}
procedure TBmpClock.SetRoundX(Value: Integer);
begin
if Value <> FRoundX then
begin
FRoundX := Value;
StyleChanged;
end;
end;
{===================設置圓角 Y==========================}
procedure TBmpClock.SetRoundY(Value: Integer);
begin
if Value <> FRoundY then
begin
FRoundY := Value;
StyleChanged;
end;
end;
{=================設置形狀過程==========================}
procedure TBmpClock.StyleChanged;
var
HT: THandle;
begin
HT := CreateRectRgn(0, 0, Width, Height);
case FThemeStyle of
tsNone:
begin
HT := CreateRectRgn(0, 0, Width, Height);
end;
tsCircle:
begin
HT := CreateEllipticRgn(0, 0, Width, Height);
end;
tsRoundRect:
begin
HT := CreateRoundRectRgn(0, 0, Width, Height, FRoundX, FRoundY);
end;
end;
SetWindowRgn(Handle, HT, True);
Repaint;
end;
//***********************************開始 TCenter*******************************
{=======================構造 中心=======================}
constructor TCenter.Create;
begin
inherited Create;
FX := 50;
FY := 50;
end;
{===================設置中心的 X 坐標===================}
procedure TCenter.SetX(Value: Integer);
begin
if Value <> FX then
begin
FX := Value;
UpdateParent;
end;
end;
{===================設置中心的 Y 坐標===================}
procedure TCenter.SetY(Value: Integer);
begin
if Value <> FY then
begin
FY := Value;
UpdateParent;
end;
end;
{======================刷新父控件=======================}
procedure TCenter.UpdateParent;
begin
Parent.Repaint;
end;
//*******************************開始 THand ************************************
{======================建立指針==========================}
constructor THand.Create;
begin
inherited Create;
end;
{====================更改屬性后,刷新父控件==============}
procedure THand.UpdateParent;
begin
Parent.RePaint;
end;
{===================設置指針正向長度=====================}
procedure THand.SetRadius(Value: integer);
begin
if Value <> FRadius then
begin
FRadius := Value;
UpdateParent;
end;
end;
{===================設置指針反向長度=====================}
procedure THand.SetBackRadius(Value: integer);
begin
if Value <> FBackRadius then
begin
FBackRadius := Value;
UpdateParent;
end;
end;
{===================設置指針寬度=========================}
procedure THand.SetWidth(Value: integer);
begin
if Value <> FWidth then
begin
FWidth := Value;
UpdateParent;
end;
end;
{===================設置指針顏色=========================}
procedure THand.SetColor(Value: TColor);
begin
if Value <> FColor then
begin
FColor := Value;
UpdateParent;
end;
end;
//*****************************開始 TCenterPoint *******************************
{======================建立中心點========================}
constructor TCenterPoint.Create;
begin
inherited Create;
FPointSize := 4;
FPenSize := 1;
FFillColor := clBlack;
FPenColor := clWhite;
end;
{========================中心點大小======================}
procedure TCenterPoint.SetPonitSize(Value: Integer);
begin
if Value <> FPointSize then
begin
FPointSize := Value;
UpdateParent;
end;
end;
{=======================邊緣圓圈大小=====================}
procedure TCenterPoint.SetPenSize(Value: Integer);
begin
if Value <> FPenSize then
begin
FPenSize := Value;
UpdateParent;
end;
end;
{=====================設置邊緣圓圈顏色===================}
procedure TCenterPoint.SetPenColor(Value: TColor);
begin
if Value <> FPenColor then
begin
FPenColor := Value;
UpdateParent;
end;
end;
{=======================設置填充顏色=====================}
procedure TCenterPoint.SetFillColor(Value: TColor);
begin
if Value <> FFillColor then
begin
FFillColor := Value;
UpdateParent;
end;
end;
{==================設置中心屬性后刷新父控件==============}
procedure TCenterPoint.UpdateParent;
begin
Parent.Repaint;
end;
{=====================注冊組件===========================}
procedure Register;
begin
RegisterComponents('Samples', [TBmpClock]);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -