1
0
mirror of https://bitbucket.org/Dennis07/lina-components.git synced 2024-11-24 08:02:12 +02:00
lina-components/Source/uFrmCtrls.pas
Dennis07 93182ccbbc Version 1.0 DEV 1.02
Signed-off-by: Dennis07 <den.goehlert@t-online.de>
2014-09-05 01:16:55 +02:00

592 lines
18 KiB
ObjectPascal

unit uFrmCtrls;
//////////////////////////////////////
/// Lina Form Controls Unit ///
/// **************************** ///
/// (c) 2014 Dennis Göhlert a.o. ///
//////////////////////////////////////
interface
uses
{ Standard-Units }
SysUtils, Classes, Controls, Forms, ComCtrls, ExtCtrls, Graphics,
{ Andere Package-Units }
uBase;
type
{ Hilfsklassen }
TSplashScreenMode = (ssmDefault,ssmModal);
TSplashScreenAnimation = (ssaNone,ssaShallow);
type
{ Ereignisse }
TSplashCreateEvent = procedure(Sender: TObject) of object;
TSplashDestroyEvent = procedure(Sender: TObject) of object;
TSplashShowEvent = procedure(Sender: TObject) of object;
TSplashHideEvent = procedure(Sender: TObject) of object;
TSplashChangeEvent = procedure(Sender: TObject) of object;
TSplashTimerEvent = procedure(Sender: TObject) of object;
type
{ Hauptklassen }
TSplashForm = class
private
{ Private-Deklarationen }
FBorderStyle: TFormBorderStyle;
FBorderIcons: TBorderIcons;
FLeft: Integer;
FTop: Integer;
FWidth: Integer;
FHeight: Integer;
FAlign: TAlign;
FAlphaBlend: Boolean;
FAlphaBlendValue: Byte;
FCaption: TCaption;
FColor: TColor;
FEnabled: Boolean;
FWindowState: TWindowState;
FPosition: TPosition;
FCursor: TCursor;
public
{ Public-Deklarationen }
constructor Create;
destructor Destroy; override;
published
{ Published-Deklarationen }
property BorderStyle: TFormBorderStyle read FBorderStyle write FBorderStyle default bsNone;
property BorderIcons: TBorderIcons read FBorderIcons write FBorderIcons default [];
property Left: Integer read FLeft write FLeft default 0;
property Top: Integer read FTop write FTop default 0;
property Width: Integer read FWidth write FWidth default 600;
property Height: Integer read FHeight write FHeight default 400;
property Align: TAlign read FAlign write FAlign default alNone;
property AlphaBlend: Boolean read FAlphaBlend write FAlphaBlend default False;
property AlphaBlendValue: Byte read FAlphaBlendValue write FAlphaBlendValue default 255;
property Caption: TCaption read FCaption write FCaption;
property Color: TColor read FColor write FColor default clBtnFace;
property Enabled: Boolean read FEnabled write FEnabled default True;
property WindowState: TWindowState read FWindowState write FWindowState default wsNormal;
property Position: TPosition read FPosition write FPosition default poScreenCenter;
property Cursor: TCursor read FCursor write FCursor default crHourGlass;
end;
TSplashProgressBar = class
private
{ Private-Deklarationen }
FLeft: Integer;
FTop: Integer;
FWidth: Integer;
FHeight: Integer;
FVisible: Boolean;
FPosition: Integer;
FMin: Integer;
FMax: Integer;
FAlign: TAlign;
FBackgroundColor: TColor;
FBarColor: TColor;
FState: TProgressBarState;
FStyle: TProgressBarStyle;
FSmooth: Boolean;
FSmoothReverse: Boolean;
FMarqueeInterval: Integer;
FStep: Integer;
public
{ Public-Deklarationen }
constructor Create;
destructor Destroy; override;
published
{ Published-Deklarationen }
property Left: Integer read FLeft write FLeft default 250;
property Top: Integer read FTop write FTop default 250;
property Width: Integer read FWidth write FWidth default 100;
property Height: Integer read FHeight write FHeight default 50;
property Visible: Boolean read FVisible write FVisible default True;
property Position: Integer read FPosition write FPosition default 0;
property Max: Integer read FMax write FMax default 100;
property Min: Integer read FMin write FMin default 0;
property Align: TAlign read FAlign write FAlign default alNone;
property BackgroundColor: TColor read FBackgroundColor write FBackgroundColor default clDefault;
property BarColor: TColor read FBarColor write FBarColor default clDefault;
property State: TProgressBarState read FState write FState default pbsNormal;
property Style: TProgressBarStyle read FStyle write FStyle default pbstNormal;
property Smooth: Boolean read FSmooth write FSmooth default False;
property SmoothReverse: Boolean read FSmoothReverse write FSmoothReverse default False;
property MarqueeInterval: Integer read FMarqueeInterval write FMarqueeInterval default 10;
property Step: Integer read FStep write FStep default 10;
end;
TSplashImage = class
private
{ Private-Deklarationen }
FVisible: Boolean;
FTransparent: Boolean;
FPicture: TPicture;
public
{ Public-Deklarationen }
constructor Create;
destructor Destroy; override;
published
{ Published-Deklarationen }
property Visible: Boolean read FVisible write FVisible default True;
property Transparent: Boolean read FTransparent write FTransparent default False;
property Picture: TPicture read FPicture write FPicture;
end;
TSplashTimer = class
private
{ Private-Deklarationen }
FEnabled: Boolean;
FInterval: Cardinal;
public
{ Public-Deklarationen }
constructor Create;
destructor Destroy;
published
{ Published-Deklarationen }
property Enabled: Boolean read FEnabled write FEnabled default False;
property Interval: Cardinal read FInterval write FInterval default 1000;
end;
TSplashScreen = class(TComponent)
private
{ Private-Deklarationen }
FormObject: TForm;
ProgressBarObject: TProgressBar;
ImageObject: TImage;
TimerObject: TTimer;
AnimationTimerShow: TTimer;
AnimationTimerHide: TTimer;
FAbout: TComponentAbout;
FSplashForm: TSplashForm;
FSplashProgressBar: TSplashProgressBar;
FSplashImage: TSplashImage;
FSplashTimer: TSplashTimer;
FDisplayTime: Cardinal;
FAutoShow: Boolean;
FMode: TSplashScreenMode;
FAnimation: TSplashScreenAnimation;
FAnimationSpeed: Byte;
FVisible: Boolean;
{ Ereignisse }
FCreateEvent: TSplashCreateEvent;
FDestroyEvent: TSplashDestroyEvent;
FShowEvent: TSplashShowEvent;
FHideEvent: TSplashHideEvent;
FChangeEvent: TSplashChangeEvent;
FTimerEvent: TSplashTimerEvent;
{ Methoden }
procedure SetVisible(Value: Boolean);
procedure FormObjectShow(Sender: TObject);
procedure FormObjectHide(Sender: TObject);
procedure TimerObjectTimer(Sender: TObject);
procedure AnimationTimerShowTimer(Sender: TObject);
procedure AnimationTimerHideTimer(Sender: TObject);
protected
{ Protected-Deklarationen }
procedure Refresh; //Vorberaitung (benutzerdefinierte Werte)
procedure Reset; //Vorbereitung (standardmäßige Werte)
public
{ Public-Deklarationen }
property Visible: Boolean read FVisible write SetVisible;
constructor Create(AOwnder: TComponent); override;
destructor Destroy; override;
procedure ApplyChanges; //Änderungen übernehmen
procedure Show; //Anzeigen
procedure Hide; //Verstecken (schließen)
published
{ Published-Deklarationen }
{ Ereignisse }
property OnCreate: TSplashCreateEvent read FCreateEvent write FCreateEvent;
property OnDestroy: TSplashDestroyEvent read FDestroyEvent write FDestroyEvent;
property OnShow: TSplashShowEvent read FShowEvent write FShowEvent;
property OnHide: TSplashHideEvent read FHideEvent write FHideEvent;
property OnChange: TSplashChangeEvent read FChangeEvent write FChangeEvent;
property OnTimer: TSplashTimerEvent read FTimerEvent write FTimerEvent;
{ Eigenschaften }
property About: TComponentAbout read FAbout;
property SplashForm: TSplashForm read FSplashForm write FSplashForm;
property SplashProgressBar: TSplashProgressBar read FSplashProgressBar write FSplashProgressBar;
property SplashImage: TSplashImage read FSplashImage write FSplashImage;
property SplashTimer: TSplashTimer read FSplashTimer write FSplashTimer;
property DisplayTime: Cardinal read FDisplayTime write FDisplayTime default 2000;
property AutoShow: Boolean read FAutoShow write FAutoShow default False;
property Mode: TSplashScreenMode read FMode write FMode default ssmDefault;
property Animation: TSplashScreenAnimation read FAnimation write FAnimation default ssaNone;
property AnimationSpeed: Byte read FAnimationSpeed write FAnimationSpeed default 10;
end;
procedure Register;
const
{ Meta-Daten }
SplashComponent_Name = 'SplashScreen';
SplashComponent_Version = 1.0;
SplashComponent_Copyright = 'Copyright © 2014';
SplashComponent_Author = 'Dennis Göhlert a.o.';
implementation
procedure Register;
begin
RegisterComponents(ComponentsPage,[TSplashScreen]);
end;
{ ----------------------------------------------------------------------------
TSplashForm
---------------------------------------------------------------------------- }
constructor TSplashForm.Create;
begin
//...
end;
destructor TSplashForm.Destroy;
begin
//...
inherited;
end;
{ ----------------------------------------------------------------------------
TSplashProgressBar
---------------------------------------------------------------------------- }
constructor TSplashProgressBar.Create;
begin
//...
end;
destructor TSplashProgressBar.Destroy;
begin
//...
inherited;
end;
{ ----------------------------------------------------------------------------
TSplashImage
---------------------------------------------------------------------------- }
constructor TSplashImage.Create;
begin
FPicture := TPicture.Create;
end;
destructor TSplashImage.Destroy;
begin
FPicture.Free;
inherited;
end;
{ ----------------------------------------------------------------------------
TSplashTimer
---------------------------------------------------------------------------- }
constructor TSplashTimer.Create;
begin
//...
end;
destructor TSplashTimer.Destroy;
begin
//...
inherited;
end;
{ ----------------------------------------------------------------------------
TSplashScreen
---------------------------------------------------------------------------- }
constructor TSplashScreen.Create(AOwnder: TComponent);
begin
inherited;
FDisplayTime := 2000;
FAutoShow := False;
FMode := ssmDefault;
FAnimation := ssaNone;
FAnimationSpeed := 10;
FVisible := False;
FAbout := TComponentAbout.Create(SplashComponent_Name,SplashComponent_Version,SplashComponent_Copyright,SplashComponent_Author);
FSplashForm := TSplashForm.Create;
FSplashProgressBar := TSplashProgressBar.Create;
FSplashImage := TSplashImage.Create;
FSplashTimer := TSplashTimer.Create;
FormObject := TForm.Create(Self);
FormObject.OnShow := FormObjectShow;
FormObject.OnHide := FormObjectHide;
ProgressBarObject := TProgressBar.Create(Self);
ProgressBarObject.Parent := FormObject;
ImageObject := TImage.Create(Self);
ImageObject.Parent := FormObject;
TimerObject := TTimer.Create(Self);
TimerObject.OnTimer := TimerObjectTimer;
TimerObject.Enabled := False;
AnimationTimerShow := TTimer.Create(Self);
AnimationTimerShow.OnTimer := AnimationTimerShowTimer;
AnimationTimerShow.Enabled := False;
AnimationTimerShow.Interval := 50;
AnimationTimerHide := TTimer.Create(Self);
AnimationTimerHide.OnTimer := AnimationTimerHideTimer;
AnimationTimerHide.Enabled := False;
AnimationTimerHide.Interval := 50;
Reset;
if Assigned(OnCreate) then
begin
OnCreate(Self);
end;
{ Erst NACHDEM fertig erstellt wurde und OnCreate-Event ausgeführt wurde... }
if AutoShow = True then
begin
Show;
end;
end;
destructor TSplashScreen.Destroy;
begin
if Assigned(OnDestroy) then
begin
OnDestroy(Self);
end;
FAbout.Free;
FSplashForm.Free;
FSplashProgressBar.Free;
FSplashImage.Free;
FSplashTimer.Free;
FormObject.Close;
FormObject.Free;
//ProgressBarObject.Free; _
//ImageObject.Free; |
//TimerObject.Free; |____\ Automatisch
//AnimationTimerShow.Free; | / freigegeben
//AnimationTimerHide.Free; _|
inherited;
end;
procedure TSplashScreen.Show;
begin
ApplyChanges;
if Mode = ssmModal then
begin
FormObject.ShowModal;
end else
begin
FormObject.Show;
end;
if Animation = ssaShallow then
begin
FormObject.AlphaBlend := True;
FormObject.AlphaBlendValue := 0;
AnimationTimerHide.Enabled := False;
AnimationTimerShow.Enabled := True;
end;
FVisible := True;
FormObject.BringToFront;
if Assigned(OnShow) then
begin
OnShow(Self);
end;
end;
procedure TSplashScreen.Hide;
begin
TimerObject.Enabled := False;
if Animation = ssaNone then
begin
FormObject.Hide;
end else
begin
if Animation = ssaShallow then
begin
FormObject.AlphaBlend := True;
AnimationTimerShow.Enabled := False;
AnimationTimerHide.Enabled := True;
end;
end;
FVisible := False;
if Assigned(OnHide) then
begin
OnHide(Self);
end;
end;
procedure TSplashScreen.ApplyChanges;
begin
{ "Refresh;" ist nicht public, deswegen hier eine Referenz.
Falls beim übernehmen der Änderungen noch sonstige Dinge getan werden
müssen, können diese hier definiert werden. }
Refresh;
end;
procedure TSplashScreen.Refresh;
begin
{ TSplashForm -> TForm }
FormObject.BorderStyle := SplashForm.BorderStyle;
FormObject.BorderIcons := SplashForm.BorderIcons;
FormObject.Left := SplashForm.Left;
FormObject.Top := SplashForm.Top;
FormObject.Width := SplashForm.Width;
FormObject.Height := SplashForm.Height;
FormObject.Align := SplashForm.Align;
FormObject.AlphaBlend := SplashForm.AlphaBlend;
FormObject.AlphaBlendValue := SplashForm.AlphaBlendValue;
FormObject.Caption := SplashForm.Caption;
FormObject.Color := SplashForm.Color;
FormObject.Enabled := SplashForm.Enabled;
FormObject.WindowState := SplashForm.WindowState;
FormObject.Position := SplashForm.Position;
FormObject.Cursor := SplashForm.Cursor;
{ TSplashProgressBar -> TProgressBar }
ProgressBarObject.Left := SplashProgressBar.Left;
ProgressBarObject.Top := SplashProgressBar.Top;
ProgressBarObject.Width := SplashProgressBar.Width;
ProgressBarObject.Height := SplashProgressBar.Height;
ProgressBarObject.Visible := SplashProgressBar.Visible;
ProgressBarObject.Position := SplashProgressBar.Position;
ProgressBarObject.Max := SplashProgressBar.Max;
ProgressBarObject.Min := SplashProgressBar.Min;
ProgressBarObject.Cursor := FormObject.Cursor;
ProgressBarObject.Align := SplashProgressBar.Align;
ProgressBarObject.BackgroundColor := SplashProgressBar.BackgroundColor;
ProgressBarObject.BarColor := SplashProgressBar.BarColor;
ProgressBarObject.State := SplashProgressBar.State;
ProgressBarObject.Style := SplashProgressBar.Style;
ProgressBarObject.Smooth := SplashProgressBar.Smooth;
ProgressBarObject.SmoothReverse := SplashProgressBar.SmoothReverse;
ProgressBarObject.MarqueeInterval := SplashProgressBar.MarqueeInterval;
ProgressBarObject.Step := SplashProgressBar.Step;
{ TSplashImage -> TImage }
ImageObject.Visible := SplashImage.Visible;
ImageObject.Transparent := SplashImage.Transparent;
ImageObject.Picture := SplashImage.Picture;
{ TSplashTimer -> TTimer }
TimerObject.Enabled := SplashTimer.Enabled;
TimerObject.Interval := SplashTimer.Interval;
if Assigned(OnChange) then
begin
OnChange(Self);
end;
end;
procedure TSplashScreen.Reset;
begin
{ TSplashForm }
SplashForm.BorderStyle := bsNone;
SplashForm.BorderIcons := [];
SplashForm.Left := 0;
SplashForm.Top := 0;
SplashForm.Width := 600;
SplashForm.Height := 400;
SplashForm.Align := alNone;
SplashForm.AlphaBlend := False;
SplashForm.AlphaBlendValue := 255;
SplashForm.Color := clBtnFace;
SplashForm.Enabled := True;
SplashForm.WindowState := wsNormal;
SplashForm.Position := poScreenCenter;
SplashForm.Cursor := crHourGlass;
{ TSplashProgressBar }
SplashProgressBar.Left := 250;
SplashProgressBar.Top := 250;
SplashProgressBar.Width := 100;
SplashProgressBar.Height := 50;
SplashProgressBar.Visible := True;
SplashProgressBar.Position := 0;
SplashProgressBar.Max := 100;
SplashProgressBar.Min := 0;
SplashProgressBar.Align := alNone;
SplashProgressBar.BackgroundColor := clDefault;
SplashProgressBar.BarColor := clDefault;
SplashProgressBar.State := pbsNormal;
SplashProgressBar.Style := pbstNormal;
SplashProgressBar.Smooth := False;
SplashProgressBar.SmoothReverse := False;
SplashProgressBar.MarqueeInterval := 10;
SplashProgressBar.Step := 10;
{ TSplashImage }
SplashImage.Visible := True;
SplashImage.Transparent := False;
{ TSplashTimer }
SplashTimer.Enabled := False;
SplashTimer.Interval := 1000;
if Assigned(OnChange) then
begin
OnChange(Self);
end;
end;
procedure TSplashScreen.SetVisible(Value: Boolean);
begin
if Value = True then
begin
Show;
end else
begin
Hide;
end;
end;
procedure TSplashScreen.FormObjectShow(Sender: TObject);
begin
//...
end;
procedure TSplashScreen.FormObjectHide(Sender: TObject);
begin
//...
end;
procedure TSplashScreen.TimerObjectTimer(Sender: TObject);
begin
if Assigned(OnTimer) then
begin
OnTimer(Self);
end;
end;
procedure TSplashScreen.AnimationTimerShowTimer(Sender: TObject);
begin
if Animation = ssaShallow then
begin
if FormObject.AlphaBlendValue < SplashForm.AlphaBlendValue then
begin
if SplashForm.AlphaBlendValue - FormObject.AlphaBlendValue < AnimationSpeed then
begin
FormObject.AlphaBlendValue := FormObject.AlphaBlendValue + (SplashForm.AlphaBlendValue - FormObject.AlphaBlendValue);
end else
begin
FormObject.AlphaBlendValue := FormObject.AlphaBlendValue + AnimationSpeed;
end;
end else
begin
AnimationTimerShow.Enabled := False;
FormObject.AlphaBlend := SplashForm.AlphaBlend;
end;
end;
end;
procedure TSplashScreen.AnimationTimerHideTimer(Sender: TObject);
begin
if Animation = ssaShallow then
begin
if FormObject.AlphaBlendValue > 0 then
begin
if FormObject.AlphaBlendValue < AnimationSpeed then
begin
FormObject.AlphaBlendValue := FormObject.AlphaBlendValue - FormObject.AlphaBlendValue;
end else
begin
FormObject.AlphaBlendValue := FormObject.AlphaBlendValue - AnimationSpeed;
end;
end else
begin
AnimationTimerHide.Enabled := False;
FormObject.AlphaBlend := SplashForm.AlphaBlend;
FormObject.Hide;
end;
end;
end;
end.