unit untMoveLabel10; interface uses System.UIConsts, System.UITypes, System.Types, FMX.StdCtrls, FMX.Objects, FMX.Filter.Effects, FMX.Ani, FMX.Controls, SysUtils, FMX.Types; type TCaptionEffect = class private FParentImage: TImage; FLabel: TLabel; FPathAnimation: TPathAnimation; FDuration: Single; FDelay: Single; function getText: String; procedure setColor(const Value: TAlphaColor); procedure setFontSize(const Value: Integer); procedure setText(const Value: String); function getScreenHeight: Single; function getScreenWidth: Single; function getHeight: Single; function getWidth: Single; procedure setDuration(const Value: Single); procedure setDelay(const Value: Single); property ScreenWidth: Single read getScreenWidth; property ScreenHeight: Single read getScreenHeight; property Width: Single read getWidth; property Height: Single read getHeight; public constructor Create(aParenImaget: TImage); destructor Destroy; override; procedure MoveIn(); procedure Erase(); property Text: String read getText write setText; property FontSize: Integer write setFontSize; property Color: TAlphaColor write setColor; property Duration: Single write setDuration; property Delay: Single write setDelay; end; const LABEL_HEIGHT = 200; DEFAULT_FontSize = 24; DEFAULT_Color = 0; DEFAULT_DURATION = 1; DEFAULT_DELAY = 0; DEFAULT_TEXT = ''; implementation { TCaptionEffect } constructor TCaptionEffect.Create(aParenImaget: TImage); begin FParentImage := aParenImaget; FLabel := TLabel.Create(FParentImage); FLabel.Parent := TFmxObject(FParentImage); FLabel.AutoSize := False; FLabel.Visible := False; FLabel.TextAlign := TTextAlign.taCenter; FLabel.Height := LABEL_HEIGHT; FLabel.Width := ScreenWidth; FLabel.StyledSettings := []; FLabel.ClipChildren := True; FPathAnimation := TPathAnimation.Create(FLabel); FPathAnimation.Parent := TFmxObject(FLabel); Self.FontSize := DEFAULT_FontSize; Self.Color := DEFAULT_Color; Self.Duration := DEFAULT_DURATION; Self.Delay := DEFAULT_DELAY; Self.Text := DEFAULT_TEXT; end; destructor TCaptionEffect.Destroy; begin FLabel.Free; inherited; end; procedure TCaptionEffect.Erase; begin FLabel.Visible := False; end; function TCaptionEffect.getHeight: Single; begin Result := FLabel.Height; end; function TCaptionEffect.getScreenHeight: Single; begin Result := FParentImage.Height; end; function TCaptionEffect.getScreenWidth: Single; begin Result := FParentImage.Width; end; function TCaptionEffect.getText: String; begin Result := FLabel.Text; end; function TCaptionEffect.getWidth: Single; begin Result := FLabel.Width; end; procedure TCaptionEffect.MoveIn; var tmpVCenter: Single; begin FLabel.Font.Size := FLabel.Font.Size; Self.Text := Self.Text; FLabel.Position.X := (ScreenWidth - Width) / 2; FLabel.Position.Y := -1 * Height; tmpVCenter := (ScreenHeight - Height) / 2; FPathAnimation.Path.Clear; FPathAnimation.Path.MoveTo(PointF(0, 0)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height + 40)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height - 40)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height + 20)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height - 20)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height + 5)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height - 5)); FPathAnimation.Path.LineTo(PointF(0, tmpVCenter + Height)); FPathAnimation.Loop := False; FPathAnimation.Duration := FDuration; FPathAnimation.Delay := 0; FPathAnimation.Interpolation := TInterpolationType.itQuadratic; FLabel.Visible := true; FPathAnimation.Start; end; procedure TCaptionEffect.setColor(const Value: TAlphaColor); begin FLabel.FontColor := Value; end; procedure TCaptionEffect.setDelay(const Value: Single); begin FDelay := Value; end; procedure TCaptionEffect.setDuration(const Value: Single); begin FDuration := Value; end; procedure TCaptionEffect.setFontSize(const Value: Integer); begin FLabel.Font.Size := Value; end; procedure TCaptionEffect.setText(const Value: String); begin FLabel.Text := Value; end; end.
動くラベル
コメントをどうぞ