月別アーカイブ: 2013年11月

TFont の色、サイズがコードから変更できない件

self.FTitleLabel.StyledSettings := [] で解決

 

  self.FTitleLabel.StyledSettings := [];
  self.FTitleLabel.Font.Size   := Self.FBGImage.Height * 0.1;
  self.FTitleLabel.FontColor   := claWhite;
  self.FTitleLabel.TextAlign   := TTextAlign.taCenter;
  self.FTitleLabel.Height      := Self.FBGImage.Height * 0.2;
  self.FTitleLabel.Align       := TAlignLayout.alTop;
  self.FContentsText.Align     := TAlignLayout.alClient;

アニメーション サンプル


unit untImageEffect;

interface

uses
  untImageManager,

  System.Classes,
  System.Types,
  System.UIConsts,
  FMX.Filter.Effects,
  FMX.Types,
  FMX.Controls,
  FMX.Objects;

type
  TCueMark = class(TObject)
private
  FParent: TImage;
  FCueImage: TImage;
  FPathAnimation: TPathAnimation;
  FRoughTimer: TTimer;
  FMSec: Integer;

  procedure OnRoughTimer(Sender: TObject);

  function getScreenHeight: Single;
  function getScreenWidth: Single;
  function getOrginHeight: Single;
  function getOrginWidth: Single;
  procedure OnPathAnimation1Finish(Sender: TObject);

  property ScreenWidth:  Single read getScreenWidth;
  property ScreenHeight: Single read getScreenHeight;
  property OrginWidth:   Single read getOrginWidth;
  property OrginHeight:  Single read getOrginHeight;

public
  constructor Create(aParent: TImage);
  destructor Destroy; override;

  procedure Start(aMSec: Integer);

end;

type
  TFloatingStars = class(TObject)
private
  FParent: TImage;
  FStarImage: Array of TImage;
  FPathAnimation: Array of TPathAnimation;
  FFillRGBEffect: Array of TFillRGBEffect;
//  FMSec: Integer;

  procedure setCount(const Value: Integer);

  procedure FreeAllImageAndPathAnimation();
    function getCount: Integer;
    function getScreenHeight: Single;
    function getScreenWidth: Single;
    function getOrginHeight: Single;
    function getOrginWidth: Single;
public
  constructor Create(aParent: TImage);
  destructor Destroy; override;

  procedure Start(aMSec: Integer);

  property ScreenWidth:  Single read getScreenWidth;
  property ScreenHeight: Single read getScreenHeight;
  property OrginWidth:   Single read getOrginWidth;
  property OrginHeight:  Single read getOrginHeight;

  property Count: Integer       read getCount        write setCount;

end;

var
  FloatingStars: TFloatingStars;
  CueMark: TCueMark;

implementation

uses
  untMainForm;

{ TFloatingStars }

constructor TFloatingStars.Create(aParent: TImage);
begin
//  inherited;
  FParent := aParent;
  Count  := 10;
end;

destructor TFloatingStars.Destroy;
begin
  FreeAllImageAndPathAnimation();
  inherited;
end;

procedure TFloatingStars.FreeAllImageAndPathAnimation;
var
  i: Integer;
begin
  //
  for i := 0 to Length(FStarImage) - 1 do
    FStarImage[i].Free;
  SetLength(FStarImage, 0);

  //
  for i := 0 to Length(FPathAnimation) - 1 do
//    if FPathAnimation[i] <> nil then FPathAnimation[i].Free;
  SetLength(FPathAnimation, 0);

  for i := 0 to Length(FFillRGBEffect) - 1 do
//    if FPathAnimation[i] <> nil then FPathAnimation[i].Free;
  SetLength(FFillRGBEffect, 0);

end;

function TFloatingStars.getCount: Integer;
begin
  Result := Length(FStarImage);
end;

function TFloatingStars.getOrginHeight: Single;
begin
  Result := FStarImage[0].Bitmap.Height;
end;

function TFloatingStars.getOrginWidth: Single;
begin
  Result := FStarImage[0].Bitmap.Width;
end;

function TFloatingStars.getScreenHeight: Single;
begin
  Result := FParent.Height;
end;

function TFloatingStars.getScreenWidth: Single;
begin
  Result := FParent.Width;
end;

procedure TFloatingStars.setCount(const Value: Integer);
var
  i: Integer;
begin

  FreeAllImageAndPathAnimation();

  SetLength(FStarImage,     Value);
  SetLength(FPathAnimation, Value);
  SetLength(FFillRGBEffect, Value);

  for i := 0 to Value - 1 do
  begin
    FStarImage[i] := TImage.Create(FParent);
    FStarImage[i].Parent := TFmxObject(FParent);
    FStarImage[i].Width  := 45;
    FStarImage[i].Height := 45;
//    FStarImage[i].Bitmap.SetSize(45,45);

    FStarImage[i].Bitmap.Assign(ImageManager.Item('star.png'));
    FStarImage[i].Position.X :=-100;
    FStarImage[i].Position.Y :=-100;
    FStarImage[i].Enabled := True;
    FStarImage[i].WrapMode := TImageWrapMode.iwFit;

    FStarImage[i].Visible := False;

    //
    FPathAnimation[i] := TPathAnimation.Create(FStarImage[i]);
    FPathAnimation[i].Parent := FStarImage[i];

    //
    FFillRGBEffect[i] := TFillRGBEffect.Create(FStarImage[i]);
    FFillRGBEffect[i].Parent := FStarImage[i];

    //    FPathAnimation[i].Parent := TFmxObject(FStarImage[i]);

  end;

end;

procedure TFloatingStars.Start(aMSec: Integer);
var
  i: Integer;
  tmpSize: Single;
  tmpDiff: Single;
  tmpDelay: Single;
  tmpDuration: Single;
  tmpStartPos: TPointF;
  tmpEndPos: TPointF;
begin

  for i := 0 to Count - 1 do
  begin

    tmpSize     := OrginWidth  * (Random + 0.5);
    tmpDiff     := Random * ScreenWidth * 0.5 + ScreenWidth/2;
    tmpDelay    := Random * (aMSec/1000) * 0.4;
    tmpDuration := Random * (aMSec/1000) * 0.6;

    tmpStartPos := PointF(tmpDiff,          -1 * tmpSize);
    tmpEndPos   := PointF( - ScreenWidth/2, ScreenHeight + tmpSize + 10);

    FStarImage[i].Width      := tmpSize;
    FStarImage[i].Height     := tmpSize;
    FStarImage[i].Position.X := tmpStartPos.X - FParent.Position.X;
    FStarImage[i].Position.Y := tmpStartPos.Y - FParent.Position.Y;

    FPathAnimation[i].Path.Clear;
    FPathAnimation[i].Path.MoveTo(PointF(0, 0));
    FPathAnimation[i].Path.LineTo(tmpEndPos);
//    FPathAnimation[i].Path.ClosePath;

    FPathAnimation[i].Loop := False;
    FPathAnimation[i].Duration := tmpDuration;
    FPathAnimation[i].Delay := tmpDelay;
    FPathAnimation[i].Interpolation := TInterpolationType.itQuadratic;

    case random(5) of
      0: FFillRGBEffect[i].Color := clapink;
      1: FFillRGBEffect[i].Color := claYellow;
      2: FFillRGBEffect[i].Color := claCyan;
      3: FFillRGBEffect[i].Color := claGreen;
      4: FFillRGBEffect[i].Color := claBlue;
    end;

    FStarImage[i].Visible := true;
    FPathAnimation[i].Start;

  end;

end;

{ TCueMark }

constructor TCueMark.Create(aParent: TImage);
begin

  FParent := aParent;

  FRoughTimer := TTimer.Create(nil);
  FRoughTimer.OnTimer  := OnRoughTimer;
  FRoughTimer.Enabled  := False;

  FCueImage := TImage.Create(FParent);
  FCueImage.Parent := TFmxObject(FParent);

  FCueImage.Bitmap.Assign(ImageManager.Item('cuemark.png'));
  FCueImage.Width      := FCueImage.Bitmap.Width;
  FCueImage.Height     := FCueImage.Bitmap.Height;
  FCueImage.Position.X := -100;
  FCueImage.Position.Y := -100;
  FCueImage.WrapMode := TImageWrapMode.iwFit;

  FCueImage.Visible := False;

  //
  FPathAnimation := TPathAnimation.Create(FCueImage);
  FPathAnimation.Parent := FCueImage;
  FPathAnimation.OnFinish  := OnPathAnimation1Finish;

end;

destructor TCueMark.Destroy;
begin
  FCueImage.Free;
//  FPathAnimation.Free;
  inherited;
end;

procedure TCueMark.OnPathAnimation1Finish(Sender: TObject);
begin
  FRoughTimer.Enabled := True;
end;

procedure TCueMark.OnRoughTimer(Sender: TObject);
begin
  FRoughTimer.Interval := FMsec div 2;
  FCueImage.Visible := False;
  FRoughTimer.Enabled := false;
end;

function TCueMark.getOrginHeight: Single;
begin
  Result := FCueImage.Bitmap.Height;
end;

function TCueMark.getOrginWidth: Single;
begin
  Result := FCueImage.Bitmap.Width;
end;

function TCueMark.getScreenHeight: Single;
begin
  Result := FParent.Height;
end;

function TCueMark.getScreenWidth: Single;
begin
  Result := FParent.Width;
end;

procedure TCueMark.Start(aMSec: Integer);
begin
    FMSec   := aMSec;

    FCueImage.Width      := OrginWidth;
    FCueImage.Height     := OrginHeight;

    FCueImage.Position.X := (ScreenWidth - OrginWidth) / 2;
    FCueImage.Position.Y := -1 * OrginHeight;

    FPathAnimation.Path.Clear;
    FPathAnimation.Path.MoveTo(PointF(0, 0));
    //
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight+40));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight-40));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight+20));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight-20));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight+5));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight-5));
    FPathAnimation.Path.LineTo(PointF(0,
                                      (ScreenHeight - OrginHeight) / 2 + OrginHeight));
    FPathAnimation.Loop := False;
    FPathAnimation.Duration := FMsec / 2000;
    FPathAnimation.Delay := 0;
    FPathAnimation.Interpolation := TInterpolationType.itQuadratic;

    FCueImage.Visible := true;
    FPathAnimation.Start;

    end;

end.

生成した TImage への描画がうまくいかない件

StarImage.Parent := self;

が大切。

https://forums.embarcadero.com/thread.jspa?threadID=97048&tstart=0
で教えてもらいました。





procedure TForm3.FormCreate(Sender: TObject);
begin
 StarImage := TImage.Create(Self);
 StarImage.Parent := self;
end;

procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 StarImage.Free;
end;

procedure TForm3.Button1Click(Sender: TObject);
var
 p1, p2: TPointF;
begin

 p1.Create(20, 2);
 p2.Create(400, 400);

 StarImage.Width := 400;
 StarImage.Height := 400;
 StarImage.Position.X :=40;
 StarImage.Position.Y :=40;
 StarImage.Visible := True;
 StarImage.Enabled := True;
 StarImage.WrapMode := TImageWrapMode.iwFit;

 StarImage.Bitmap.SetSize(400,400);
 StarImage.Bitmap.Canvas.BeginScene;
 StarImage.Bitmap.Canvas.DrawLine(p1, p2, 100);
 StarImage.Bitmap.Canvas.EndScene;
end;