Skip to content

Commit

Permalink
AnyiQuack works now also with FMX, at least FMX on Windows. New Slidi…
Browse files Browse the repository at this point in the history
…ngButtonFMX example to demonstrate the ability.
  • Loading branch information
WladiD committed Jun 14, 2019
1 parent 6b799a6 commit def2341
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 5 deletions.
36 changes: 36 additions & 0 deletions AQPSystemTypesAnimations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ TAQPSystemTypesAnimations = class(TAQPlugin)
const Setter: TRefSystemTypeSetterProcedure<Integer>; Duration: Integer; ID: Integer = 0;
const EaseFunction: TEaseFunction = nil; const OnComplete: TAnonymNotifyEvent = nil): TAQ;

function SingleAnimation(TargetValue: Single;
const Getter: TRefSystemTypeGetterFunction<Single>;
const Setter: TRefSystemTypeSetterProcedure<Single>; Duration: Integer; ID: Integer = 0;
const EaseFunction: TEaseFunction = nil; const OnComplete: TAnonymNotifyEvent = nil): TAQ;

function ColorAnimation(const TargetColor: TColor;
const Getter: TRefSystemTypeGetterFunction<TColor>;
const Setter: TRefSystemTypeSetterProcedure<TColor>; Duration: Integer; ID: Integer = 0;
Expand Down Expand Up @@ -103,6 +108,37 @@ function TAQPSystemTypesAnimations.IntegerAnimation(TargetValue: Integer;
end);
end;

function TAQPSystemTypesAnimations.SingleAnimation(TargetValue: Single;
const Getter: TRefSystemTypeGetterFunction<Single>;
const Setter: TRefSystemTypeSetterProcedure<Single>; Duration: Integer; ID: Integer = 0;
const EaseFunction: TEaseFunction = nil; const OnComplete: TAnonymNotifyEvent = nil): TAQ;
begin
Result := Each(
function(AQ: TAQ; O: TObject): Boolean
var
FromValue: Single;
begin
Result := True;

FromValue := Getter(O);

Take(O).EachAnimation(Duration,
function(AQ: TAQ; O: TObject): Boolean
var
Progress, AniValue: Real;
begin
Result := True;
Progress := AQ.CurrentInterval.Progress;
AniValue := TAQ.EaseReal(FromValue, TargetValue, Progress, EaseFunction);

Setter(O, AniValue);

if Progress = 1 then
FireCompleteEvent(O, OnComplete{$IFDEF OutputDebugAnimation}, 'IntegerAnimation'{$ENDIF});
end, nil, ID);
end);
end;

function TAQPSystemTypesAnimations.ColorAnimation(const TargetColor: TColor;
const Getter: TRefSystemTypeGetterFunction<TColor>;
const Setter: TRefSystemTypeSetterProcedure<TColor>; Duration, ID: Integer;
Expand Down
9 changes: 4 additions & 5 deletions AnyiQuack.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ interface
System.Diagnostics,
System.SyncObjs,
System.UITypes,
Generics.Collections,
Vcl.Forms;
Generics.Collections;

{$INCLUDE Compile.inc}

Expand Down Expand Up @@ -2810,10 +2809,10 @@ procedure TTimerThread.WndProc(var Msg: TMessage);
try
FTimerProc;
except
Application.HandleException(Self);
System.Classes.ApplicationHandleException(Self);
end
else
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
else
Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
end;

procedure TTimerThread.Execute;
Expand Down
80 changes: 80 additions & 0 deletions Examples/SlidingButtonFMX/Main.fmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
object MainForm: TMainForm
Left = 0
Top = 0
ActiveControl = Button1
Caption = 'Click to slide the button'
ClientHeight = 480
ClientWidth = 640
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Label1: TLabel
Anchors = [akRight, akBottom]
Position.X = 232.000000000000000000
Position.Y = 416.000000000000000000
Size.Width = 401.000000000000000000
Size.Height = 65.000000000000000000
Size.PlatformDefault = False
TextSettings.HorzAlign = Trailing
Text =
'The X and Y properties of the Position are animated independentl' +
'y. '#13#10'Try to hit the space key rapidly.'
TabOrder = 2
end
object XTrackBar: TTrackBar
Anchors = [akRight, akBottom]
CanParentFocus = True
Max = 2000.000000000000000000
Min = 100.000000000000000000
Orientation = Horizontal
Position.X = 352.000000000000000000
Position.Y = 368.000000000000000000
Size.Width = 281.000000000000000000
Size.Height = 19.000000000000000000
Size.PlatformDefault = False
TabOrder = 5
Value = 500.000000000000000000
end
object YTrackBar: TTrackBar
Anchors = [akRight, akBottom]
CanParentFocus = True
Max = 2000.000000000000000000
Min = 100.000000000000000000
Orientation = Horizontal
Position.X = 351.000000000000000000
Position.Y = 400.000000000000000000
Size.Width = 281.000000000000000000
Size.Height = 19.000000000000000000
Size.PlatformDefault = False
TabOrder = 4
Value = 750.000000000000000000
end
object Label2: TLabel
Anchors = [akRight, akBottom]
Position.X = 224.000000000000000000
Position.Y = 368.000000000000000000
TextSettings.HorzAlign = Trailing
Text = 'X duration'
TabOrder = 7
end
object Label3: TLabel
Anchors = [akRight, akBottom]
Position.X = 224.000000000000000000
Position.Y = 400.000000000000000000
TextSettings.HorzAlign = Trailing
Text = 'Y duration'
TabOrder = 6
end
object Button1: TButton
Position.X = 240.000000000000000000
Position.Y = 200.000000000000000000
Size.Width = 137.000000000000000000
Size.Height = 73.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Text = 'Slide'
OnClick = Button1Click
end
end
74 changes: 74 additions & 0 deletions Examples/SlidingButtonFMX/Main.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
unit Main;

interface

uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Variants,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Graphics,
FMX.Dialogs,
FMX.Controls.Presentation,
FMX.StdCtrls,

AnyiQuack,
AQPSystemTypesAnimations;

type
TMainForm = class(TForm)
Button1: TButton;
Label1: TLabel;
XTrackBar: TTrackBar;
YTrackBar: TTrackBar;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
end;

var
MainForm: TMainForm;

implementation

{$R *.fmx}

procedure TMainForm.Button1Click(Sender: TObject);
var
TypesAniPlugin: TAQPSystemTypesAnimations;
NewLeft, NewTop: Single;
ButtonSender: TButton absolute Sender;
begin
TypesAniPlugin := Take(Sender)
.CancelAnimations
.Plugin<TAQPSystemTypesAnimations>;

NewLeft := Random(Trunc(ClientWidth - ButtonSender.Width));
NewTop := Random(Trunc(ClientHeight - ButtonSender.Height));

TypesAniPlugin.SingleAnimation(NewLeft,
function(RefObject: TObject): Single
begin
Result := TButton(RefObject).Position.X;
end,
procedure(RefObject: TObject; const NewLeft: Single)
begin
TButton(RefObject).Position.X := NewLeft;
end, Trunc(XTrackBar.Value), 0, TAQ.Ease(etBack));

TypesAniPlugin.SingleAnimation(NewTop,
function(RefObject: TObject): Single
begin
Result := TButton(RefObject).Position.Y;
end,
procedure(RefObject: TObject; const NewLeft: Single)
begin
TButton(RefObject).Position.Y := NewLeft;
end, Trunc(YTrackBar.Value), 0, TAQ.Ease(etElastic));
end;

end.
16 changes: 16 additions & 0 deletions Examples/SlidingButtonFMX/SlidingButton.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
program SlidingButton;

uses
System.StartUpCopy,
FMX.Forms,
Main in 'Main.pas' {MainForm},
AnyiQuack in '..\..\AnyiQuack.pas',
AQPSystemTypesAnimations in '..\..\AQPSystemTypesAnimations.pas';

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
end.
Loading

0 comments on commit def2341

Please sign in to comment.