{**********************************************}
{   TeeActivityDonut                           }
{   Activity Donut item                        }
{                                              }
{   Copyright (c) 1999-2020 by Steema Software }
{**********************************************}
unit TeeActivityDonut;
{$I TeeDefs.inc}

interface

Uses {$IFNDEF LINUX}
     {$IFNDEF FMX}
     Windows,
     {$ENDIF}
     {$ENDIF}
     SysUtils, Classes,
     {$IFDEF FMX}
     FMX.Types, System.UITypes,
     {$ELSE}
     Graphics,
     {$ENDIF}

     {$IFDEF FMX}
     FMXTee.Engine, FMXTee.Chart, FMXTee.Canvas, FMXTee.Series, FMXTee.Series.Donut, FMXTee.Tools
     {$ELSE}
     TeEngine, Chart, TeCanvas, Series, TeeDonut, TeeTools
     {$ENDIF};

Type
  TActivityDonut=class(TDonutSeries)
  private
    FBackColor : TColor;
    FColor : TColor;
    FValue : Double;
  protected
    function GetValue: Double;
    procedure SetValue(const Value:Double);
    function GetColor:TColor;
    procedure SetColor(const AColor:TColor);
    function GetBackColor:TColor;
    procedure SetBackColor(const AColor:TColor);
  public
    Constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Value : Double read GetValue write SetValue;
    property Color : TColor read GetColor write SetColor;
    property BackColor : TColor read GetBackColor write SetBackColor default {$IFDEF FMX}TAlphaColors.Silver{$ELSE}clSilver{$ENDIF};
  end;

implementation

Uses
  {$IFDEF FMX}
  FMXTee.Constants, FMXTee.ProConstants, FMXTee.Procs
  {$ELSE}
  TeeConst, TeeProCo, TeeProcs
  {$ENDIF};

{ TActivityDonut }

constructor TActivityDonut.Create(AOwner: TComponent);
begin
  inherited;
  FBackColor:={$IFDEF FMX}TAlphaColors.Silver{$ELSE}clSilver{$ENDIF};
end;

destructor TActivityDonut.Destroy;
begin
  inherited;
end;

function TActivityDonut.GetBackColor: TColor;
begin
  result:=FBackColor;
end;

function TActivityDonut.GetColor: TColor;
begin
  result:=FColor;
end;

function TActivityDonut.GetValue: Double;
begin
  result :=FValue;
end;

procedure TActivityDonut.SetBackColor(const AColor: TColor);
begin
  ValueColor[0]:=AColor;
  SetColorProperty(FBackColor,AColor);
end;

procedure TActivityDonut.SetColor(const AColor: TColor);
begin
  ValueColor[1]:=AColor;
  SetColorProperty(FColor,AColor);
end;

procedure TActivityDonut.SetValue(const Value: Double);
begin
  Self.Clear;
  if Value>100 then
    FValue := 100
  else
    FValue:=Value;
  Add(100-FValue);
  Add(FValue);
  SetBackColor(BackColor);
end;

initialization
  RegisterTeeSeries(TActivityDonut,@TeeMsg_ActivityGauge);
finalization
  UnRegisterTeeSeries([TActivityDonut]);
end.
