⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qisevensegmentclock.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  Sec  : Word;
  MSec : Word;
begin
  if (Value < 0) or (Value > 99) then raise Exception.Create('Hours must be in the range of 0-99');
  DecodeTime(FTime, Hour, Min, Sec, MSec);
  if Value <> Hour then
    begin
      FTime         := EncodeTime(Value mod 24, Min, Sec, MSec) + Int(FTime);
      FOriginalTime := FTime;
      FStartTime    := Now;
      InvalidateChange;
      if Assigned(OnValueChange) then OnValueChange(Self)
    end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetMinutes(const Value: Integer);
var
  Hour : Word;
  Min  : Word;
  Sec  : Word;
  MSec : Word;
begin
  if (Value < 0) or (Value > 59) then raise Exception.Create('Minutes must be in the range of 0-59');
  DecodeTime(FTime, Hour, Min, Sec, MSec);
  if Value <> Min then
    begin
      FTime         := Trunc(FTime) + EncodeTime(Hour , Value, Sec, MSec) + Int(FTime);
      FOriginalTime := FTime;
      FStartTime    := Now;
      InvalidateChange;
      if Assigned(OnValueChange) then OnValueChange(Self)
    end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetSeconds(const Value: Integer);
var
  Hour : Word;
  Min  : Word;
  Sec  : Word;
  MSec : Word;
begin
  if (Value < 0) or (Value > 59) then raise Exception.Create('Seconds must be in the range of 0-59');
  DecodeTime(FTime, Hour, Min, Sec, MSec);
  if Value <> Sec then
    begin
      FTime         := Trunc(FTime) + EncodeTime(Hour, Min, Value, MSec) + Int(FTime);
      FOriginalTime := FTime;
      FStartTime    := Now;
      InvalidateChange;
      if Assigned(OnValueChange) then OnValueChange(Self)
    end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetTimeInSeconds(Value: Integer);
var
  TotalLeft : Integer;
  Hour      : Word;
  Min       : Word;
  Sec       : Word;
  MSec      : Word;
begin
  MSec      := 0; 
  TotalLeft := Value;
  Hour      := TotalLeft div (60*60);
  TotalLeft := TotalLeft - Hour*(60*60);
  Min       := TotalLeft div 60;
  Sec       := TotalLeft - Min*60;
  FTime     := EncodeTime(Hour mod 24, Min, Sec, MSec);
  InvalidateChange;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.ResetToZero;
begin
  FTime := 0;
  CountTimerEnabled := False;
end;
//****************************************************************************************************************************************************
function TiSevenSegmentClock.GetCountTimerEnabled: Boolean;
begin
  Result := GetTimerRunning;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetCountDirection(const Value: TiCountDirection);
begin
  if FCountDirection <> Value then
    begin
      FCountDirection := Value;
      FOriginalTime   := FTime;
      FStartTime      := Now;
    end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.SetCountTimerEnabled(const Value: Boolean);
begin
  case Value of
    False : TimerStop;
    True  : begin
              TimerStart(0, 100);
              FOriginalTime := FTime;
              FStartTime    := Now;
            end;  
  end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.TimerEvent(Sender : TObject);
var
  Done : Boolean;
begin
  InvalidateChange;
  case FCountDirection of
    icdDown : FTime := FOriginalTime - (Now - FStartTime);
    icdUp   : FTime := FOriginalTime + (Now - FStartTime);
  end;

  if FCountDirection = icdDown then
    begin
      Done := FTime <= 0;

      if Done then
        begin
          FTime := 0;
          CountTimerEnabled := False;
          if Assigned(OnCountDownComplete) then OnCountDownComplete(Self);
        end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiSevenSegmentClock.iPaintTo(Canvas: TCanvas);
var
  OffsetPoint         : TPoint;
  Hour                : Word;
  Min                 : Word;
  Sec                 : Word;
  MSec                : Word;
  DigitWidth          : Integer;
  ColonWidth          : Integer;
  DigitCount          : Integer;
  ColonCount          : Integer;
  CenterOffset        : Integer;
  CharacterTotalWidth : Integer;
  AHeight             : Integer;
  Character           : TSevenSegmentCharacter;
begin
  SetupCharacter;
  DrawBackGround(Canvas, BackGroundColor);

  DigitCount := 2;
  ColonCount := 0;
  if FShowHours then
    begin
      DigitCount := DigitCount + 2;
      ColonCount := ColonCount + 1;
    end;
  if FShowSeconds then
    begin
      DigitCount := DigitCount + 2;
      ColonCount := ColonCount + 1;
    end;

  CharacterTotalWidth := Width - 2*SegmentMargin;

  DigitWidth := Trunc( (5*CharacterTotalWidth - 5*DigitSpacing*(DigitCount + ColonCount - 1))/(5*DigitCount + ColonCount));
  ColonWidth := DigitWidth div 5;
  AHeight    := Height - 2*SegmentMargin;

  CenterOffset := (Width - DigitCount*(DigitWidth + DigitSpacing) - ColonCount*(ColonWidth + DigitSpacing)+ DigitSpacing) div 2;

  OffsetPoint.x := CenterOffset;
  OffsetPoint.y := SegmentMargin;

  DecodeTime(FTime, Hour, Min, Sec, MSec);

  if FTime <= 99 then Hour := Hour + Trunc(FTime)*24;

  if FHourStyle = ichs12 then if Hour > 12 then Hour := Hour - 12;

  if FShowHours then
    begin
      if Hour > 9 then Character := TSevenSegmentCharacter(Hour div 10) else Character := ssc0;
      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, Character);
      OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;

      if Hour <> 0 then Hour := Hour - (Hour div 10)*10 else Hour := 0;
      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, TSevenSegmentCharacter(Hour));
      OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;

      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, ColonWidth, AHeight, sscColon);
      OffsetPoint.x := OffsetPoint.x + ColonWidth + DigitSpacing;

    end;

    if Min > 9 then Character := TSevenSegmentCharacter(Min div 10) else Character := ssc0;
    SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, Character);
    OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;

    if Min <> 0 then Min := Min - (Min div 10)*10 else Min := 0;
    SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, TSevenSegmentCharacter(Min));
    OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;

  if FShowSeconds then
    begin
      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, ColonWidth, AHeight, sscColon);
      OffsetPoint.x := OffsetPoint.x + ColonWidth + DigitSpacing;

      if Sec > 9 then Character := TSevenSegmentCharacter(Sec div 10) else Character := ssc0;
      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, Character);
      OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;

      if Sec <> 0 then Sec := Sec - (Sec div 10)*10 else Sec := 0;
      SevenSegmentCharacter.Draw(Canvas, OffsetPoint, DigitWidth, AHeight, TSevenSegmentCharacter(Sec));
      OffsetPoint.x := OffsetPoint.x + DigitWidth + DigitSpacing;
    end;
end;
//****************************************************************************************************************************************************
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -