unit CEProgressbar;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs;
  
Type TCpStyle = (CpProgressbar, CpGauge);

type
  TCEProgressbar = class(TCustomControl)
  private
  FBitmap           : TBitmap;
  FValue            : integer;
  FMax              : integer;
  FMin              : integer;
  FStyle            : TCpStyle;
  FCoreColor        : TColor;
  FBoarderCOlor     : TColor;
  procedure SetValue(Value : integer);
  procedure SetMax(Value : integer);
  procedure SetMin(Value : integer);
  procedure SetStyle(Value : TCpStyle);
  procedure SetCoreColor(value : TColor);
  procedure SetBoarderColor(value : TColor);
  procedure Erstellen;
  procedure Paint; override;
    { Private declarations }
  protected
    { Protected declarations }
  public
  constructor Create(AOwner : TComponent); override;
  destructor Destroy;override;
    { Public declarations }
  published
  property Value : integer  read FValue write SetValue;
  property Max   : integer  read FMax write SetMax;
  property Min   : integer  read FMin write SetMin;
  property Style : TCpStyle read FStyle write SetStyle;
  property CoreColor : TColor read FCoreColor write SetCoreColor;
  property BoarderColor : TColor read FBoarderColor write SetBoarderColor;
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('WinCe',[TCEProgressbar]);
end;

//------------------------------------------------------------------------------

constructor TCEProgressbar.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
Width              :=80;
Height             :=20;
Min                :=0;
Max                :=100;
CoreColor          :=clNavy;
Style              :=CpProgressbar;
FBitmap            := TBitmap.create;
FBitmap.pixelformat:= pf16bit;
Erstellen;
end;

//------------------------------------------------------------------------------

destructor TCEProgressbar.Destroy;
begin
FBitmap.free;
inherited Destroy;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.Paint;
begin
if (FBitmap <> Nil) then begin
   if (FBitmap.Width <> Width) or (Fbitmap.Height <> Height) then Erstellen;
   canvas.Draw(0,0,FBitmap);
   end;

   //Erstellen;
   {if FBitmap <> Nil then }//canvas.Draw(0,0,FBitmap);
   //canvas.Pen.Color:=clred;
   //canvas.Ellipse(0,0,width,height);
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.Erstellen;
begin
if FBitmap <> Nil then begin
   Case FStyle of
   CpProgressbar : begin
                 if FBitmap.Height <> Height then FBitmap.Height:=Height;
                 if FBitmap.Width <> Width then Fbitmap.Width:=Width;
                 With Fbitmap.Canvas do begin
                     Pen.Color:=FBoarderColor;
                     Brush.Color:=clwhite;
                     ellipse(0,0,width,Height);
                     end;
                 end;
   Cpgauge       : begin
                 if FBitmap.Height <> Height then FBitmap.Height:=Height;
                 if FBitmap.Width <> Width then Fbitmap.Width:=Width;
                 FBitmap.Canvas.TextOut(0,0,'test');
                   end;
   end;
end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetValue(Value : integer);
begin
if Value <> FValue then begin
   FValue:=Value;
   end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetMax(Value : integer);
begin
if Value <> FMax then begin
   FMax:=Value;
   end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetMin(Value : integer);
begin
if Value <> FMin then begin
     FMin:=Value;
     end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetStyle(Value : TCpStyle);
begin
if Value <> FStyle then begin
   FStyle:=Value;
   end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetCoreColor(value : TColor);
begin
if Value <> FCoreColor then begin
   FCoreColor:=Value;
   Erstellen;
   Paint;
   end;
end;

//------------------------------------------------------------------------------

procedure TCEProgressbar.SetBoarderColor(value : TColor);
begin
if Value <> FBoarderColor then begin
   FBoarderColor:=Value;
   Erstellen;
   Paint;
   end;
end;

//------------------------------------------------------------------------------

initialization
{$I CeProgressbar.lrs}


end.
