tvplanit: Fix TVpClock. Add example. Some refactoring and cosmetic changes.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5041 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2016-07-28 21:22:54 +00:00
parent 6e6d5a064a
commit ba7e8c8e0c
8 changed files with 833 additions and 272 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="laz_visualplanit"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@@ -0,0 +1,21 @@
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1, laz_visualplanit
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,165 @@
object Form1: TForm1
Left = 262
Height = 283
Top = 155
Width = 461
Caption = 'Form1'
ClientHeight = 283
ClientWidth = 461
Font.Color = clWindowText
OnCreate = FormCreate
LCLVersion = '1.7'
object VpLEDLabel1: TVpLEDLabel
Left = 9
Height = 60
Top = 6
Width = 442
Caption = 'Visual PlanIt'
Columns = 13
OffColor = 930866
OnColor = clLime
Size = 3
end
object VpClock1: TVpClock
Left = 11
Height = 200
Top = 72
Width = 200
Active = False
Color = clForm
ClockMode = cmClock
DigitalOptions.MilitaryTime = True
DigitalOptions.OnColor = clLime
DigitalOptions.OffColor = 930866
DigitalOptions.BgColor = clBlack
DigitalOptions.Size = 2
DigitalOptions.ShowSeconds = True
DisplayMode = dmAnalog
AnalogOptions.DrawMarks = True
AnalogOptions.HourHandColor = clBlack
AnalogOptions.HourHandLength = 60
AnalogOptions.HourHandWidth = 4
AnalogOptions.MinuteHandColor = clBlack
AnalogOptions.MinuteHandLength = 80
AnalogOptions.MinuteHandWidth = 3
AnalogOptions.SecondHandColor = clRed
AnalogOptions.SecondHandLength = 90
AnalogOptions.SecondHandWidth = 1
AnalogOptions.ShowSecondHand = True
AnalogOptions.SolidHands = True
MinuteOffset = 0
ParentColor = False
SecondOffset = 0
HourOffset = 0
OnCountdownDone = VpClock1CountdownDone
OnSecondChange = VpClockTimeChange
end
object BtnStartStop: TButton
Left = 351
Height = 51
Top = 80
Width = 99
Caption = 'Start'
OnClick = BtnStartStopClick
TabOrder = 1
end
object RgClockMode: TRadioGroup
Left = 224
Height = 89
Top = 151
Width = 116
AutoFill = True
Caption = 'Clock mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 69
ClientWidth = 112
ItemIndex = 0
Items.Strings = (
'Clock'
'Counter'
'Count-down'
)
OnClick = RgClockModeClick
TabOrder = 2
end
object EdCountDownTime: TTimeEdit
Left = 351
Height = 23
Top = 172
Width = 99
ButtonWidth = 23
NumGlyphs = 1
MaxLength = 0
OnChange = EdCountDownTimeChange
TabOrder = 3
Visible = False
Text = '00:30:00'
end
object LblCountDownTime: TLabel
Left = 351
Height = 15
Top = 152
Width = 98
Caption = 'Count-down time:'
FocusControl = EdCountDownTime
ParentColor = False
Visible = False
end
object CbNewClockFace: TCheckBox
Left = 351
Height = 19
Top = 221
Width = 100
Caption = 'New clock face'
OnChange = CbNewClockFaceChange
TabOrder = 4
end
object LblElapsedTime: TLabel
Left = 224
Height = 15
Top = 256
Width = 49
Caption = 'Elapsed...'
ParentColor = False
end
object RgDisplayMode: TRadioGroup
Left = 224
Height = 63
Top = 72
Width = 115
AutoFill = True
Caption = 'Display mode'
ChildSizing.LeftRightSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 43
ClientWidth = 111
ItemIndex = 0
Items.Strings = (
'Analog'
'Digital'
)
OnClick = RgDisplayModeClick
TabOrder = 5
end
object CbMilitaryTime: TCheckBox
Left = 351
Height = 19
Top = 208
Width = 87
Caption = 'Military time'
OnChange = CbMilitaryTimeChange
TabOrder = 6
Visible = False
end
end

View File

@@ -0,0 +1,179 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, EditBtn, VpLEDLabel, VpClock;
type
{ TForm1 }
TForm1 = class(TForm)
BtnStartStop: TButton;
CbNewClockFace: TCheckBox;
CbMilitaryTime: TCheckBox;
LblCountDownTime: TLabel;
LblElapsedTime: TLabel;
RgDisplayMode: TRadioGroup;
RgClockMode: TRadioGroup;
VpClock1: TVpClock;
EdCountDownTime: TTimeEdit;
VpLEDLabel1: TVpLEDLabel;
procedure AnalogClockCountdownDone(Sender: TObject);
procedure CbMilitaryTimeChange(Sender: TObject);
procedure VpClockTimeChange(Sender: TObject);
procedure BtnStartStopClick(Sender: TObject);
procedure CbNewClockFaceChange(Sender: TObject);
procedure EdCountDownTimeChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure RgClockModeClick(Sender: TObject);
procedure RgDisplayModeClick(Sender: TObject);
procedure VpClock1CountdownDone(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.AnalogClockCountdownDone(Sender: TObject);
begin
ShowMessage('Countdown finished.');
end;
procedure TForm1.VpClockTimeChange(Sender: TObject);
begin
LblElapsedTime.Caption := Format('Elapsed: %d hrs, %d min, %d sec', [
VpClock1.ElapsedHours, VpClock1.ElapsedMinutes, VpClock1.ElapsedSeconds
]);
end;
procedure TForm1.BtnStartStopClick(Sender: TObject);
var
isStarted: Boolean;
willStart: Boolean;
begin
isStarted := VpClock1.Active;
willStart := not isStarted;
if willStart and (RgClockMode.ItemIndex = ord(cmCountdownTimer)) then
RgClockModeClick(nil);
VpClock1.Active := willStart;
if VpClock1.Active then
BtnStartStop.Caption := 'Stop' else
BtnStartStop.Caption := 'Start';
end;
procedure TForm1.CbMilitaryTimeChange(Sender: TObject);
var
t: TDateTime;
begin
t := VpClock1.Time;
VpClock1.DigitalOptions.MilitaryTime := CbMilitaryTime.Checked;
VpClock1.Time := t;
end;
procedure TForm1.CbNewClockFaceChange(Sender: TObject);
begin
if CbNewClockFace.Checked then begin
VpClock1.AnalogOptions.ClockFace.LoadFromFile('clockface.bmp');
VpClock1.AnalogOptions.HourHandWidth := 2;
VpClock1.AnalogOptions.MinuteHandWidth := 2;
VpClock1.AnalogOptions.SecondHandWidth := 1;
VpClock1.Width := 100;
VpClock1.Height := 100;
end else begin
VpClock1.AnalogOptions.ClockFace := nil;
VpClock1.AnalogOptions.HourHandWidth := 4;
VpClock1.AnalogOptions.MinuteHandWidth := 3;
VpClock1.AnalogOptions.SecondHandWidth := 1;
VpClock1.Width := 200;
VpClock1.Height := 200;
end;
VpClock1.AnalogOptions.DrawMarks := not CbNewClockFace.Checked;
if RgDisplayMode.ItemIndex = ord(dmAnalog) then
VpClock1.Invalidate;
end;
procedure TForm1.EdCountDownTimeChange(Sender: TObject);
begin
if VpClock1.ClockMode = cmCountDownTimer then
VpClock1.Time := EdCountDownTime.Time;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EdCountDownTime.Time := StrToTime(EdCountDownTime.Text);
CbMilitaryTime.Top := CbNewClockFace.Top;
end;
procedure TForm1.RgClockModeClick(Sender: TObject);
var
h,m,s,ms: Word;
begin
VpClock1.Active := false;
BtnStartStop.Caption := 'Start';
VpClock1.ClockMode := TVpClockMode(RgClockMode.ItemIndex);
case VpClock1.ClockMode of
cmClock:
begin
VpClock1.Time := now;
VpClock1.Active := true;
BtnStartStop.Caption := 'Stop';
end;
cmTimer:
VpClock1.Time := 0;
cmCountdownTimer:
begin
DecodeTime(EdCountDownTime.Time, h,m,s,ms);
VpClock1.HourOffset := h;
VpClock1.MinuteOffset := m;
VpClock1.SecondOffset := s;
end;
end;
EdCountDownTime.Visible := VpClock1.ClockMode = cmCountDownTimer;
LblCountDownTime.Visible := EdCountDownTime.Visible;
end;
procedure TForm1.RgDisplayModeClick(Sender: TObject);
var
t: TDateTime;
begin
t := VpClock1.Time;
VpClock1.DisplayMode := TVpClockDisplayMode(RgDisplayMode.ItemIndex);
case VpClock1.DisplayMode of
dmAnalog:
CbNewClockFaceChange(nil);
dmDigital:
begin
VpClock1.Width := 136;
VpClock1.Height := 30;
end;
end;
CbMilitaryTime.Visible := VpClock1.DisplayMode = dmDigital;
CbNewClockface.Visible := VpClock1.DisplayMode = dmAnalog;
VpClock1.Time := t;
end;
procedure TForm1.VpClock1CountdownDone(Sender: TObject);
begin
ShowMessage('Countdown completed.');
end;
end.

View File

@@ -1,16 +1,16 @@
object Form1: TForm1 object Form1: TForm1
Left = 262 Left = 262
Height = 400 Height = 406
Top = 155 Top = 155
Width = 588 Width = 567
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 400 ClientHeight = 406
ClientWidth = 588 ClientWidth = 567
OnCreate = FormCreate OnCreate = FormCreate
LCLVersion = '1.7' LCLVersion = '1.7'
object VpNavBar1: TVpNavBar object VpNavBar1: TVpNavBar
Left = 0 Left = 0
Height = 370 Height = 376
Top = 0 Top = 0
Width = 128 Width = 128
ActiveFolder = 0 ActiveFolder = 0
@@ -187,17 +187,17 @@ object Form1: TForm1
object Panel1: TPanel object Panel1: TPanel
Left = 0 Left = 0
Height = 30 Height = 30
Top = 370 Top = 376
Width = 588 Width = 567
Align = alBottom Align = alBottom
ClientHeight = 30 ClientHeight = 30
ClientWidth = 588 ClientWidth = 567
TabOrder = 2 TabOrder = 2
object Bevel1: TBevel object Bevel1: TBevel
Left = 1 Left = 1
Height = 3 Height = 3
Top = 1 Top = 1
Width = 586 Width = 565
Align = alTop Align = alTop
Shape = bsTopLine Shape = bsTopLine
end end

View File

@@ -35,12 +35,12 @@ interface
uses uses
{$IFDEF LCL} {$IFDEF LCL}
LMessages,LCLProc,LCLType,LCLIntf, LMessages, LCLProc, LCLType, LCLIntf, ExtCtrls,
{$ELSE} {$ELSE}
Windows, Messages, Windows, Messages, VpTimerPool,
{$ENDIF} {$ENDIF}
Classes, Controls, Dialogs, Forms, Graphics, Menus,Math, Classes, Controls, Dialogs, Forms, Graphics, Menus,Math,
SysUtils, VpBase, VpLEDLabel, VpTimerPool; SysUtils, VpBase, VpLEDLabel;
type type
TVpPercent = 0..100; TVpPercent = 0..100;
@@ -154,7 +154,11 @@ type
TVpCustomClock = class(TVpCustomControl) TVpCustomClock = class(TVpCustomControl)
protected {private} protected {private}
{$IFDEF DELPHI}
FTimerPool: TVpTimerPool; FTimerPool: TVpTimerPool;
{$ELSE}
FTimer: TTimer;
{$ENDIF}
FActive: Boolean; FActive: Boolean;
FClockMode: TVpClockMode; FClockMode: TVpClockMode;
FDigitalOptions: TVpDigitalOptions; FDigitalOptions: TVpDigitalOptions;
@@ -166,7 +170,7 @@ type
FHandOptions: TVpHandOptions; FHandOptions: TVpHandOptions;
FTime: TDateTime; FTime: TDateTime;
FMilitaryTime: Boolean; FMilitaryTime: Boolean;
FStartTime : TDateTime; FCountdownStartTime: TDateTime;
FHourOffset: Integer; {Hours} FHourOffset: Integer; {Hours}
FMinuteOffset: Integer; {Minutes} FMinuteOffset: Integer; {Minutes}
FSecondOffset: Integer; {Seconds} FSecondOffset: Integer; {Seconds}
@@ -180,7 +184,11 @@ type
ckAnalogWidth: Integer; ckAnalogWidth: Integer;
ckLEDDisplay: TVpLEDClockDisplay; ckLEDDisplay: TVpLEDClockDisplay;
ckDraw: TBitMap; ckDraw: TBitMap;
{$IFDEF DELPHI}
ckClockHandle: Integer; ckClockHandle: Integer;
{$ELSE}
FTimeStarted: TDateTime; {time at which the timer is activated }
{$ENDIF}
ckOldHour: Integer; ckOldHour: Integer;
ckOldMinute: Integer; ckOldMinute: Integer;
ckOldSecond: Integer; ckOldSecond: Integer;
@@ -207,8 +215,12 @@ type
procedure ckHandOptionChange(Sender: TObject); procedure ckHandOptionChange(Sender: TObject);
procedure ckDigitalOptionChange(Sender: TObject); procedure ckDigitalOptionChange(Sender: TObject);
procedure SizeDigitalDisplay; procedure SizeDigitalDisplay;
{$IFDEF DELPHI}
procedure ckTimerEvent(Sender: TObject; Handle: Integer; Interval: Cardinal; procedure ckTimerEvent(Sender: TObject; Handle: Integer; Interval: Cardinal;
ElapsedTime: LongInt); ElapsedTime: LongInt);
{$ELSE}
procedure ckTimerEvent(Sender: TObject);
{$ENDIF}
procedure DoOnHourChange; procedure DoOnHourChange;
procedure DoOnMinuteChange; procedure DoOnMinuteChange;
procedure DoOnSecondChange; procedure DoOnSecondChange;
@@ -241,18 +253,15 @@ type
property SecondOffset: Integer read FSecondOffset write SetSecondOffset; property SecondOffset: Integer read FSecondOffset write SetSecondOffset;
{events} {events}
property OnHourChange: TNotifyEvent read FOnHourChange write FOnHourChange; property OnHourChange: TNotifyEvent read FOnHourChange write FOnHourChange;
property OnMinuteChange : TNotifyEvent property OnMinuteChange: TNotifyEvent read FOnMinuteChange write FOnMinuteChange;
read FOnMinuteChange write FOnMinuteChange; property OnSecondChange: TNotifyEvent read FOnSecondChange write FOnSecondChange;
property OnSecondChange : TNotifyEvent property OnCountdownDone: TNotifyEvent read FOnCountdownDone write FOnCountdownDone;
read FOnSecondChange write FOnSecondChange;
property OnCountdownDone : TNotifyEvent
read FOnCountdownDone write FOnCountdownDone;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override; procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
property DisplayMode: TVpClockDisplayMode property DisplayMode: TVpClockDisplayMode read FDisplayMode write SetDisplayMode;
read FDisplayMode write SetDisplayMode;
property ElapsedDays: Integer read GetElapsedDays; property ElapsedDays: Integer read GetElapsedDays;
property ElapsedHours: Integer read GetElapsedHours; property ElapsedHours: Integer read GetElapsedHours;
property ElapsedMinutes: LongInt read GetElapsedMinutes; property ElapsedMinutes: LongInt read GetElapsedMinutes;
@@ -393,7 +402,6 @@ end;
constructor TVpHandOptions.Create; constructor TVpHandOptions.Create;
begin begin
inherited; inherited;
FClockFace := TBitMap.Create; FClockFace := TBitMap.Create;
FDrawMarks := True; FDrawMarks := True;
end; end;
@@ -403,7 +411,6 @@ destructor TVpHandOptions.Destroy;
begin begin
FClockFace.Free; FClockFace.Free;
FClockFace := nil; FClockFace := nil;
inherited; inherited;
end; end;
{=====} {=====}
@@ -565,7 +572,11 @@ begin
FClockMode := cmClock; FClockMode := cmClock;
{$IFDEF DELPHI}
FTimerPool := TVpTimerPool.Create(self); FTimerPool := TVpTimerPool.Create(self);
{$ELSE}
FTimer := TTimer.Create(self);
{$ENDIF}
FHandOptions := TVpHandOptions.Create; FHandOptions := TVpHandOptions.Create;
FHandOptions.OnChange := ckHandOptionChange; FHandOptions.OnChange := ckHandOptionChange;
@@ -588,7 +599,11 @@ begin
ckDraw.Width := Width; ckDraw.Width := Width;
ckDraw.Height := Height; ckDraw.Height := Height;
{$IFDEF DELPHI}
ckClockHandle := -1; ckClockHandle := -1;
{$ELSE}
FTimer.Enabled := false;
{$ENDIF}
end; end;
{=====} {=====}
@@ -660,6 +675,7 @@ begin
end; end;
{=====} {=====}
{$IFDEF DELPHI}
procedure TVpCustomClock.ckTimerEvent(Sender: TObject; Handle: Integer; procedure TVpCustomClock.ckTimerEvent(Sender: TObject; Handle: Integer;
Interval: Cardinal; ElapsedTime: LongInt); Interval: Cardinal; ElapsedTime: LongInt);
var var
@@ -694,6 +710,35 @@ begin
SetTime(FStartTime - ckConvertMsToDateTime(ElapsedTime)); SetTime(FStartTime - ckConvertMsToDateTime(ElapsedTime));
end; end;
end; end;
{$ELSE}
procedure TVpCustomClock.ckTimerEvent(Sender: TObject);
var
Hour, Minute, Second, MSecond: Word;
C, D: Integer;
elapsed: TDateTime;
begin
elapsed := now - FTimeStarted;
case FClockMode of
cmClock:
begin { Clock }
DecodeTime(Now, Hour, Minute, Second, MSecond);
D := Minute + FMinuteOffset;
Minute := Abs(D mod 60);
C := Hour + FHourOffset + D div 60;
if C > 23 then
Dec(C, 24);
if C < 0 then
Inc(C, 24);
Hour := C;
SetTime(EncodeTime(Hour, Minute, Second, MSecond));
end;
cmTimer: { Count-up timer }
SetTime(elapsed);
cmCountDownTimer: { Count-down timer }
SetTime(FCountdownStartTime - elapsed);
end;
end;
{$ENDIF}
{=====} {=====}
procedure TVpCustomClock.DoOnHourChange; procedure TVpCustomClock.DoOnHourChange;
@@ -728,70 +773,97 @@ function TVpCustomClock.GetElapsedDays: Integer;
var var
ClockDate : TDateTime; ClockDate : TDateTime;
begin begin
{$IFDEF DELPHI}
if ckClockHandle > -1 then begin if ckClockHandle > -1 then begin
ClockDate := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]); ClockDate := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]);
ckDays := Trunc(ClockDate); ckDays := Trunc(ClockDate);
end; end;
{$ELSE}
if FTimer.Enabled then begin
ClockDate := now - FTimeStarted;
ckDays := Trunc(ClockDate);
end;
{$ENDIF}
Result := ckDays; Result := ckDays;
end; end;
{=====} {=====}
function TVpCustomClock.GetElapsedHours: Integer; function TVpCustomClock.GetElapsedHours: Integer;
var var
Hour : Word; Hour, Min, Sec, MSec: Word;
Min : Word;
Sec : Word;
MSec : Word;
TempTime : TDateTime; TempTime : TDateTime;
begin begin
Result := 0;
{$IFDEF DELPHI}
if ckClockHandle > -1 then begin if ckClockHandle > -1 then begin
TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]); TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]);
DecodeTime(TempTime, Hour, Min, Sec, MSec); DecodeTime(TempTime, Hour, Min, Sec, MSec);
ckHours := Hour Result := Hour;
end; end;
Result := ckHours; {$ELSE}
if FTimer.Enabled then begin
Temptime := now - FTimeStarted;
DecodeTime(TempTime, Hour, Min, Sec, MSec);
Result := Hour;
end;
{$ENDIF}
end; end;
{=====} {=====}
function TVpCustomClock.GetElapsedMinutes: LongInt; function TVpCustomClock.GetElapsedMinutes: LongInt;
var var
Hour : Word; Hour, Min, Sec, MSec: Word;
Min : Word;
Sec : Word;
MSec : Word;
TempTime : TDateTime; TempTime : TDateTime;
begin begin
Result := 0;
{$IFDEF DELPHI}
if ckClockHandle > -1 then begin if ckClockHandle > -1 then begin
TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]); TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]);
DecodeTime(TempTime, Hour, Min, Sec, MSec); DecodeTime(TempTime, Hour, Min, Sec, MSec);
ckMinutes := Min; Result := Min;
end; end;
Result := ckMinutes; {$ELSE}
if FTimer.Enabled then begin
TempTime := now - FTimeStarted;
DecodeTime(TempTime, Hour, Min, Sec, MSec);
Result := Min;
end;
{$ENDIF}
end; end;
{=====} {=====}
function TVpCustomClock.GetElapsedSeconds : LongInt; function TVpCustomClock.GetElapsedSeconds : LongInt;
var var
Hour : Word; Hour, Min, Sec, MSec: Word;
Min : Word;
Sec : Word;
MSec : Word;
TempTime : TDateTime; TempTime : TDateTime;
begin begin
Result := 0;
{$IFDEF DELPHI}
if ckClockHandle > -1 then begin if ckClockHandle > -1 then begin
TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]); TempTime := ckConvertMsToDateTime(FTimerPool.ElapsedTime[ckClockHandle]);
DecodeTime(TempTime, Hour, Min, Sec, MSec); DecodeTime(TempTime, Hour, Min, Sec, MSec);
ckSeconds := Sec; Result := Sec;
end; end;
Result := ckSeconds; {$ELSE}
if FTimer.Enabled then begin
TempTime := now - FTimeStarted;
DecodeTime(TempTime, Hour, Min, Sec, MSec);
Result := Sec;
end;
{$ENDIF}
end; end;
{=====} {=====}
function TVpCustomClock.GetElapsedSecondsTotal : LongInt; function TVpCustomClock.GetElapsedSecondsTotal : LongInt;
begin begin
Result := 0;
{$IFDEF DELPHI}
if ckClockHandle > -1 then if ckClockHandle > -1 then
ckTotalSeconds := FTimerPool.ElapsedTime[ckClockHandle] div 1000; Result := FTimerPool.ElapsedTime[ckClockHandle] div 1000;
Result := ckTotalSeconds; {$ELSE}
if FTimer.Enabled then
Result := Round((now - FTimeStarted) * SecondsInDay);
{$ENDIF}
end; end;
{=====} {=====}
@@ -836,8 +908,7 @@ var
ElRgn : HRgn; ElRgn : HRgn;
R : TRect; R : TRect;
procedure DrawTickMark(MarkX, MarkY : Integer; procedure DrawTickMark(MarkX, MarkY: Integer; LColor, MColor, RColor: TColor;
LColor, MColor, RColor : TColor;
FiveMinute: Boolean); FiveMinute: Boolean);
begin begin
with ckDraw.Canvas do begin with ckDraw.Canvas do begin
@@ -940,10 +1011,8 @@ var
NewPoint.Y := NewPoint.Y + HalfHeight; NewPoint.Y := NewPoint.Y + HalfHeight;
end; end;
procedure DrawNewHand(PenColor : TColor; procedure DrawNewHand(PenColor: TColor; Hand: HandType;
Hand : HandType; HandLength, HipWidth: Integer);
HandLength : Integer;
HipWidth : Integer);
const const
MaxPoints = 7; MaxPoints = 7;
var var
@@ -967,71 +1036,78 @@ var
begin begin
ACanvas.Brush.Color := clWhite; ACanvas.Brush.Color := clWhite;
case Hand of case Hand of
HourHand : begin HourHand:
case Hour of case Hour of
0..3, 0..3, 12..15:
12..15 : begin begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(1,2,4); LoadPoints(1,2,4);
end; end;
4..5, 4..5, 16..17:
16..17 : begin begin
LoadPoints(1,2,4); LoadPoints(1,2,4);
LoadPoints(1,2,6); LoadPoints(1,2,6);
end; end;
6..9, 6..9, 18..21:
18..21 : begin begin
LoadPoints(1,2,6); LoadPoints(1,2,6);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
10..11, 10..11, 22..23:
22..23 : begin begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
end; end;
end;
MinuteHand: begin MinuteHand:
case Minute of case Minute of
0..15 : begin 0..15:
begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(1,2,4); LoadPoints(1,2,4);
end; end;
16..25: begin 16..25:
begin
LoadPoints(1,2,4); LoadPoints(1,2,4);
LoadPoints(1,2,6); LoadPoints(1,2,6);
end; end;
26..50: begin 26..50:
begin
LoadPoints(1,2,6); LoadPoints(1,2,6);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
51..59: begin 51..59:
begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
end; end;
end;
SecondHand: begin SecondHand:
case Second of case Second of
0..15 : begin 0..15:
begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(1,2,4); LoadPoints(1,2,4);
end; end;
16..25: begin 16..25:
begin
LoadPoints(1,2,4); LoadPoints(1,2,4);
LoadPoints(1,2,6); LoadPoints(1,2,6);
end; end;
26..50: begin 26..50:
begin
LoadPoints(1,2,6); LoadPoints(1,2,6);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
51..59: begin 51..59:
begin
LoadPoints(2,3,4); LoadPoints(2,3,4);
LoadPoints(2,3,6); LoadPoints(2,3,6);
end; end;
end; end;
end; end; // case Hand of...
end;
ACanvas.Brush.Color := Color; ACanvas.Brush.Color := Color;
end; end;
@@ -1136,20 +1212,34 @@ begin
if FActive then begin if FActive then begin
if FDisplayMode = dmDigital then if FDisplayMode = dmDigital then
FMilitaryTime := DigitalOptions.MilitaryTime; FMilitaryTime := DigitalOptions.MilitaryTime;
{$IFDEF DELPHI}
if ckClockHandle = -1 then if ckClockHandle = -1 then
ckClockHandle := FTimerPool.Add(ckTimerEvent, ckInterval); ckClockHandle := FTimerPool.Add(ckTimerEvent, ckInterval);
if FClockMode = cmClock then {$ELSE}
FTime := Now FTimeStarted := now;
else if FClockMode = cmCountdownTimer then FTimer.Interval := ckInterval;
FStartTime := EncodeTime(FHourOffset, FMinuteOffset, FTimer.Enabled := FActive;
FSecondOffset, 0) FTimer.OnTimer := ckTimerEvent;
else {$ENDIF}
case FClockMode of
cmClock:
FTime := Now;
cmTimer:
FTime := 0; FTime := 0;
end else if ckClockHandle > -1 then begin cmCountdownTimer:
FCountdownStartTime := EncodeTime(FHourOffset, FMinuteOffset, FSecondOffset, 0);
end;
end
else
{$IFDEF DELPHI}
if ckClockHandle > -1 then begin
FTimerPool.Remove(ckClockHandle); FTimerPool.Remove(ckClockHandle);
ckClockHandle := -1; ckClockHandle := -1;
end; end;
{$ELSE}
if FTimer.Enabled then
FTimer.Enabled := false;
{$ENDIF}
Invalidate; Invalidate;
end; end;
end; end;
@@ -1222,22 +1312,34 @@ begin
{Initialize the LED display} {Initialize the LED display}
if FActive then begin if FActive then begin
if FClockMode = cmClock then case FClockMode of
{Clock} cmClock:
SetTime(Now) SetTime(Now);
else if FClockMode = cmTimer then cmTimer:
{Timer} {$IFDEF DELPHI}
SetTime(ckConvertMsToDateTime(FElapsedSeconds * 1000)) SetTime(ckConvertMsToDateTime(FElapsedSeconds * 1000));
else {$ELSE}
{Countdown Timer} SetTime(Now - FTimeStarted);
if (FStartTime - ckConvertMsToDateTime( {$ENDIF}
FElapsedSeconds * 1000) <= 0) then cmCountdownTimer:
{$IFDEF DELPHI}
if (FStartTime - ckConvertMsToDateTime(FElapsedSeconds * 1000) <= 0) then
begin begin
SetTime(0); SetTime(0);
Active := false; Active := false;
DoOnCountdownDone; DoOnCountdownDone;
end else end else
SetTime(FStartTime - ckConvertMsToDateTime(FElapsedSeconds * 1000)); SetTime(FStartTime - ckConvertMsToDateTime(FElapsedSeconds * 1000));
{$ELSE}
if (FCountdownStartTime - (now - FTimeStarted) <= 0) then
begin
SetTime(0);
Active := false;
DoOnCountdownDone;
end else
SetTime(FCountdownStartTime - (now - FTimeStarted));
{$ENDIF}
end;
end; end;
end; end;
@@ -1284,6 +1386,7 @@ var
begin begin
DecodeTime(Value, Hour1, Minute1, Second1, MSecond); DecodeTime(Value, Hour1, Minute1, Second1, MSecond);
DecodeTime(FTime, Hour2, Minute2, Second2, MSecond); DecodeTime(FTime, Hour2, Minute2, Second2, MSecond);
if (Hour1 <> Hour2) or (Minute1 <> Minute2) or (Second1 <> Second2) then begin if (Hour1 <> Hour2) or (Minute1 <> Minute2) or (Second1 <> Second2) then begin
FTime := Value; FTime := Value;
@@ -1300,11 +1403,14 @@ begin
if DisplayMode = dmDigital then begin if DisplayMode = dmDigital then begin
if FDigitalOptions.ShowSeconds and FMilitaryTime then if FDigitalOptions.ShowSeconds and FMilitaryTime then
TimeStr := FormatDateTime('hh:nn:ss', FTime) TimeStr := FormatDateTime('hh:nn:ss', FTime)
else if FDigitalOptions.ShowSeconds and not FMilitaryTime then else
if FDigitalOptions.ShowSeconds and not FMilitaryTime then
TimeStr := FormatDateTime('hh:nn:ss am/pm', FTime) TimeStr := FormatDateTime('hh:nn:ss am/pm', FTime)
else if not FDigitalOptions.ShowSeconds and FMilitaryTime then else
if not FDigitalOptions.ShowSeconds and FMilitaryTime then
TimeStr := FormatDateTime('hh:nn', FTime) TimeStr := FormatDateTime('hh:nn', FTime)
else if not FDigitalOptions.ShowSeconds and not FMilitaryTime then else
if not FDigitalOptions.ShowSeconds and not FMilitaryTime then
TimeStr := FormatDateTime('hh:nn am/pm', FTime); TimeStr := FormatDateTime('hh:nn am/pm', FTime);
ckLEDDisplay.Caption := TimeStr; ckLEDDisplay.Caption := TimeStr;
end; end;

View File

@@ -169,7 +169,11 @@ begin
tpList := TList.Create; tpList := TList.Create;
{allocate a window handle for the timer} {allocate a window handle for the timer}
//TODO: tpHandle := {$IFDEF VERSION6}Classes.{$ENDIF}AllocateHWnd(tpTimerWndProc); {$IFDEF DELPHI}
tpHandle := {$IFDEF VERSION6}Classes.{$ENDIF}AllocateHWnd(tpTimerWndProc);
{$ELSE}
// ToDo: tpHandle := AllocateHWnd(tpTimerWndProc);
{$ENDIF}
end; end;
destructor TVpTimerPool.Destroy; destructor TVpTimerPool.Destroy;
@@ -189,7 +193,11 @@ begin
tpList := nil; tpList := nil;
{deallocate our window handle} {deallocate our window handle}
//TODO: {$IFDEF VERSION6}Classes.{$ENDIF}DeallocateHWnd(tpHandle); {$IFDEF DELPHI}
{$IFDEF VERSION6}Classes.{$ENDIF}DeallocateHWnd(tpHandle);
{$ELSE}
// ToDo: DeallocateHWnd(tpHandle);
{$ENDIF}
inherited Destroy; inherited Destroy;
end; end;