{==============================================================================

  Controls
  Copyright (C) 2000-2001 by Evgeny Kryukov
  All rights reserved

  All contents of this file and all other files included in this archive
  are Copyright (C) 2001 Evgeny Kryukov. Use and/or distribution of
  them requires acceptance of the License Agreement.

  See License.txt for licence information

===============================================================================}

unit EpIIProgress;

{$I EpIIVer.inc}
{$T-,W-,X+,P+}

interface

uses
  Windows, Classes, Graphics, Forms, KsBitmap, KsUtils, KsControls, KsProgress,
  EpIIStyles, EpIIVersion;

type

{ TEpProgressBar class }

  TEpProgressBar = class(TKsCustomProgressBar)
  private
    FBevelWidth: integer;
    FBackground: TEpBackground;
    FBorder: TepBorder;
    FProgressBackground: TEpBackground;
    FProgressBorder: TepBorder;
    procedure DoBackgroundChange(Sender: TObject);
    procedure DoBorderChange(Sender: TObject);

    function GetVersion: TEpVersion;
    procedure SetVersion(const Value: TEpVersion);
    procedure SetBackground(const Value: TEpBackground);
    procedure SetBorder(const Value: TepBorder);
    procedure SetProgressBackground(const Value: TEpBackground);
    procedure SetProgressBorder(const Value: TepBorder);
  protected
    procedure PaintBar; override;
    procedure PaintFrame; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
  published
    { It's possible to draw the background for control. Based on TEpBackground class.
      See Also:
        TEpBackground
    }
    property Background: TEpBackground read FBackground write SetBackground;
    property Blend;
    property BlendValue;
    { It's possible to draw the border for control. Based on TEpBorder class.
      See Also:
        TEpBorder
    }
    property Border: TepBorder read FBorder write SetBorder;
    property Max;
    property Min;
    property Position;
    { It's possible to draw the progress bar background for control. Based on TEpBackground class.
      See Also:
        TEpBackground
    }
    property ProgressBackground: TEpBackground read FProgressBackground write SetProgressBackground;
    { It's possible to draw the progress bar border for control. Based on TEpBorder class.
      See Also:
        TEpBorder
    }
    property ProgressBorder: TepBorder read FProgressBorder write SetProgressBorder;
    property Orientation;
    property ShowBorder;
    property Smooth;
    property Version: TEpVersion read GetVersion write SetVersion
      stored false;
  end;

implementation {===============================================================}

{ TEpProgressBar }

constructor TEpProgressBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FBackground := TEpBackground.Create;
  FBackground.OnChange := DoBackgroundChange;
  FBorder := TEpBorder.Create;
  FBorder.OnChange := DoBorderChange;

  FProgressBackground := TEpBackground.Create;
  FProgressBackground.OnChange := DoBackgroundChange;
  FProgressBorder := TEpBorder.Create;
  FProgressBorder.OnChange := DoBackgroundChange;
end;

destructor TEpProgressBar.Destroy;
begin
  FProgressBackground.Free;
  FProgressBorder.Free;
  FBackground.Free;
  FBorder.Free;
  inherited Destroy;
end;

procedure TEpProgressBar.Loaded;
begin
  inherited;
  BorderWidth := FBorder.Width;
end;

{ Painting }

procedure TEpProgressBar.PaintBar;
var
  FillR, R: TRect;
  W, Pos: integer;
begin
  if FProgressBorder = nil then Exit;
   
  R := GetBarRect;
  if Orientation = kboHorizontal then
    W := RectWidth(R)
  else
    W := RectHeight(R);
  { Calc Pos }
  Pos := Round(W * GetPercent(Position));
  { Set FillR }
  FillR := R;
  if Orientation = kboHorizontal then
    FillR.Right := FillR.Left + Pos
  else
    FillR.Top := FillR.Bottom - Pos;

  FProgressBackground.Draw(Buffer, FillR);
  FProgressBorder.Draw(Buffer, FillR, 0);
end;

procedure TEpProgressBar.PaintFrame;
var
  R: TRect;
begin
  if FBorder = nil then Exit;

  R := Rect(0, 0, FWidth, FHeight);

  FBackground.Draw(Buffer, R);
  FBorder.Draw(Buffer, R, 0);
end;

procedure TEpProgressBar.DoBackgroundChange(Sender: TObject);
begin
  Invalidate;
end;

procedure TEpProgressBar.DoBorderChange(Sender: TObject);
begin
  BorderWidth := FBorder.Width;
end;

{ Properties }

function TEpProgressBar.GetVersion: TEpVersion;
begin
  Result := EpVersion;
end;

procedure TEpProgressBar.SetVersion(const Value: TEpVersion);
begin

end;

procedure TEpProgressBar.SetBackground(const Value: TEpBackground);
begin
  FBackground.Assign(Value);
end;

procedure TEpProgressBar.SetBorder(const Value: TepBorder);
begin
  FBorder := Value;
end;

procedure TEpProgressBar.SetProgressBackground(const Value: TEpBackground);
begin
  FProgressBackground.Assign(Value);
end;

procedure TEpProgressBar.SetProgressBorder(const Value: TepBorder);
begin
  FProgressBorder.Assign(Value);
end;

end.
