Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/HemulGM/Components
Browse files Browse the repository at this point in the history
  • Loading branch information
HemulGM committed Nov 29, 2018
2 parents 6c4a921 + cc8176b commit 0bcb429
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 8 deletions.
213 changes: 213 additions & 0 deletions HGM.AutoTextType.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
unit HGM.AutoTextType;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, HGM.Common;

type
TOnTextChange = procedure(Sender:TObject; Text:string) of object;
TAutoTypeText = class(TComponent)
private
FWait:Integer;
FText:string;
i:Integer;
Str:string;
DoErase:Boolean;
DoStop:Boolean;
Value: string;
CurrentW:Integer;
FList:TStringList;
FTimerNextPhrase: TTimer;
FTimerNextStep: TTimer;
FNextPhraseInterval: Cardinal;
FNextCharInteravl: Cardinal;
FOnTextChange: TOnTextChange;
FEditControl: TEdit;
FMemoControl: TMemo;
FLabelControl: TLabel;
procedure TimerNextPhraseTimer(Sender: TObject);
procedure TimerNextStepTimer(Sender: TObject);
procedure SetNextPhraseInterval(const Value: Cardinal);
procedure SetNextCharInteravl(const Value: Cardinal);
procedure AnimatePhrase;
procedure AnimateNextStep;
procedure SetOnTextChange(const Value: TOnTextChange);
procedure SetText(const Value: string);
procedure SetEditControl(const Value: TEdit);
procedure SetLabelControl(const Value: TLabel);
procedure SetMemoControl(const Value: TMemo);
procedure SetList(const Value: TStringList);
public
constructor Create(AOwner: TComponent); override;
procedure Start;
procedure Stop;
published
property NextPhraseInterval:Cardinal read FNextPhraseInterval write SetNextPhraseInterval default 2000;
property NextCharInteravl:Cardinal read FNextCharInteravl write SetNextCharInteravl default 70;
property OnTextChange:TOnTextChange read FOnTextChange write SetOnTextChange;
property Text:string read FText;
property LabelControl:TLabel read FLabelControl write SetLabelControl;
property EditControl:TEdit read FEditControl write SetEditControl;
property MemoControl:TMemo read FMemoControl write SetMemoControl;
property List:TStringList read FList write SetList;
end;

procedure Register;

implementation
uses Math;

{ TAutoTypeText }

procedure Register;
begin
RegisterComponents(PackageName, [TAutoTypeText]);
end;

constructor TAutoTypeText.Create(AOwner: TComponent);
begin
inherited;
FList:=TStringList.Create;
DoStop:=False;
FNextCharInteravl:=70;
FNextPhraseInterval:=2000;
FWait:=FNextCharInteravl;

FTimerNextPhrase:=TTimer.Create(nil);
FTimerNextPhrase.Enabled:=False;
FTimerNextPhrase.Interval:=FNextPhraseInterval;
FTimerNextPhrase.OnTimer:=TimerNextPhraseTimer;

FTimerNextStep:=TTimer.Create(nil);
FTimerNextStep.Enabled:=False;
FTimerNextStep.Interval:=70;
FTimerNextStep.OnTimer:=TimerNextStepTimer;

CurrentW:=-1;
end;

procedure TAutoTypeText.TimerNextPhraseTimer(Sender: TObject);
begin
FTimerNextPhrase.Enabled:=False;
Inc(CurrentW);
if CurrentW > FList.Count-1 then CurrentW:=0;
Value:=FList[CurrentW];
AnimatePhrase;
end;

procedure TAutoTypeText.TimerNextStepTimer(Sender: TObject);
begin
FTimerNextStep.Enabled:=False;
AnimateNextStep;
end;

procedure TAutoTypeText.SetEditControl(const Value: TEdit);
begin
FEditControl := Value;
end;

procedure TAutoTypeText.SetLabelControl(const Value: TLabel);
begin
FLabelControl := Value;
end;

procedure TAutoTypeText.SetList(const Value: TStringList);
begin
FList := Value;
end;

procedure TAutoTypeText.SetMemoControl(const Value: TMemo);
begin
FMemoControl := Value;
end;

procedure TAutoTypeText.SetNextCharInteravl(const Value: Cardinal);
begin
FNextCharInteravl := Value;
FWait:=Value;
end;

procedure TAutoTypeText.SetNextPhraseInterval(const Value: Cardinal);
begin
FNextPhraseInterval:=Value;
FTimerNextPhrase.Interval:=Value;
end;

procedure TAutoTypeText.SetOnTextChange(const Value: TOnTextChange);
begin
FOnTextChange := Value;
end;

procedure TAutoTypeText.SetText(const Value: string);
begin
FText:= Value;
if Assigned(FOnTextChange) then FOnTextChange(Self, FText);
if Assigned(FEditControl) then FEditControl.Text:=FText;
if Assigned(FLabelControl) then FLabelControl.Caption:=FText;
if Assigned(FMemoControl) then FMemoControl.Text:=FText;
end;

procedure TAutoTypeText.Start;
begin
DoStop:=False;
FTimerNextPhrase.Enabled:=True;
end;

procedure TAutoTypeText.Stop;
begin
DoStop:=true;
FTimerNextPhrase.Enabled:=False;
end;

procedure TAutoTypeText.AnimateNextStep;
var C:Char;
begin
if (i <= Value.Length) or DoErase then
begin
if DoErase then
begin
Delete(Str, Str.Length, 1);
DoErase:=False;
Dec(i);
end
else
begin
if Random(10) = 2 then
C:=Chr(RandomRange(97, 122))
else C:=Value[i];
DoErase:=C <> Value[i];
Str:=Str+C;
Inc(i);
end;

SetText(Str+'|');
FTimerNextStep.Interval:=FWait;
if (i > Value.Length) and (not DoErase) then
FTimerNextStep.Interval:=FWait * 12;
FTimerNextStep.Enabled:=True;
Exit;
end;
if Str.Length > 0 then
begin
Delete(Str, Str.Length, 1);
SetText(Str+'|');
FTimerNextStep.Interval:=FWait div 2;
FTimerNextStep.Enabled:=True;
Exit;
end;
if not DoStop then
FTimerNextPhrase.Enabled:=True;
end;

procedure TAutoTypeText.AnimatePhrase;
begin
Str:='';
DoErase:=False;
i:=1;
AnimateNextStep;
end;

end.

3 changes: 2 additions & 1 deletion HGMComponents.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ contains
HGM.Tools.Hint in 'HGM.Tools.Hint.pas',
HGM.WinAPI in 'HGM.WinAPI.pas',
HGM.WinAPI.ShellDlg in 'HGM.WinAPI.ShellDlg.pas',
HGM.BlurGaussian in 'HGM.BlurGaussian.pas';
HGM.BlurGaussian in 'HGM.BlurGaussian.pas',
HGM.AutoTextType in 'HGM.AutoTextType.pas';

end.

31 changes: 24 additions & 7 deletions HGMComponents.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
<DCCReference Include="HGM.WinAPI.pas"/>
<DCCReference Include="HGM.WinAPI.ShellDlg.pas"/>
<DCCReference Include="HGM.BlurGaussian.pas"/>
<DCCReference Include="HGM.AutoTextType.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
Expand Down Expand Up @@ -222,13 +223,7 @@
</Source>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl\HGMComponents.rsm" Configuration="Debug" Class="DebugSymbols">
<Platform Name="Win32">
<RemoteName>HGMComponents.rsm</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl\HGMComponents.bpl" Configuration="Debug" Class="ProjectOutput">
<DeployFile LocalName="C:\Users\Public\Documents\Embarcadero\Studio\18.0\Bpl\HGMComponents.bpl" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>HGMComponents.bpl</RemoteName>
<Overwrite>true</Overwrite>
Expand All @@ -240,6 +235,7 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<<<<<<< HEAD
<DeployClass Name="Android_SplashImage470">
<Platform Name="Android">
<RemoteDir>res\drawable-normal</RemoteDir>
Expand All @@ -265,6 +261,12 @@
</DeployClass>
<DeployClass Name="iPad_Launch2048">
<Platform Name="iOSDevice">
=======
<DeployClass Name="ProjectiOSDeviceResourceRules"/>
<DeployClass Name="ProjectOSXResource">
<Platform Name="OSX32">
<RemoteDir>Contents\Resources</RemoteDir>
>>>>>>> cc8176b9276f27ab405bc8c217ffcdf841b021f0
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
Expand Down Expand Up @@ -554,6 +556,21 @@
<Operation>1</Operation>
</Platform>
</DeployClass>
<<<<<<< HEAD
=======
<DeployClass Name="DependencyModule">
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
</DeployClass>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
>>>>>>> cc8176b9276f27ab405bc8c217ffcdf841b021f0
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="iOSDevice" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
Expand Down

0 comments on commit 0bcb429

Please sign in to comment.