Issue with Radial Gradients in FMX

  

I’m trying to reproduce the gradient demo given here
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FMXGradient_(Delphi)
I’ve copied everything exactly and have debugged to confirm that the functions are getting called. The linear gradient works fine. However, the radial gradient doesn’t change when I set RotationCenter.X or RotationCenter.Y as shown on the web page. I get no change. However, I do get a change when I change RotationAngle. I’ve noticed previously that setting RotationCenter in a TTransform appears to do nothing. Looking at the TTransform class in FMX.Types I see that RotationCenter isn’t used at all. I’m using Delphi 10.4 Sydney. Is this a change in the code that’s crept in since the demo on the web page was created?
I’ve tried setting TTransform.Position instead of RotationCenter since I can see that it gets used. However that doesn’t seem to do anything either and I can see in FMX.Types that SetPosition isn’t calling MatrixChanged(). In summary it seems broken to me or at least different from the demo. Can anyone else confirm and suggest how I can get it working?
unit source
unit Unit1;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
FMX.StdCtrls, FMX.Edit, FMX.ListBox, FMX.Colors, FMX.Controls.Presentation;

type
TForm1 = class(TForm)
Rectangle1: TRectangle;
Ellipse1: TEllipse;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
ComboBox1: TComboBox;
ListBoxItem1: TListBoxItem;
ListBoxItem2: TListBoxItem;
ColorComboBox1: TColorComboBox;
ColorComboBox2: TColorComboBox;
procedure ColorComboBox1Change(Sender: TObject);
procedure ColorComboBox2Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
procedure Edit3Change(Sender: TObject);
procedure Edit4Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListBoxItem1Click(Sender: TObject);
procedure ListBoxItem2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.ColorComboBox1Change(Sender: TObject);
begin
if Ellipse1.Visible then
Ellipse1.Fill.Gradient.Color := ColorComboBox1.Color
else
Rectangle1.Fill.Gradient.Color := ColorComboBox1.Color;
end;

procedure TForm1.ColorComboBox2Change(Sender: TObject);
begin
if Ellipse1.Visible then
Ellipse1.Fill.Gradient.Color1 := ColorComboBox2.Color
else
Rectangle1.Fill.Gradient.Color1 := ColorComboBox2.Color;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
if Ellipse1.Visible then
Ellipse1.Fill.Gradient.RadialTransform.RotationAngle :=
StrToFloat(Edit1.Text)
else
Rectangle1.Fill.Gradient.StartPosition.X := StrToFloat(Edit1.Text);
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
if Ellipse1.Visible then
Ellipse1.Fill.Gradient.RadialTransform.RotationCenter.X :=
StrToFloat(Edit2.Text)
else
Rectangle1.Fill.Gradient.StartPosition.Y := StrToFloat(Edit2.Text);
end;

procedure TForm1.Edit3Change(Sender: TObject);
begin
if Ellipse1.Visible then
Ellipse1.Fill.Gradient.RadialTransform.RotationCenter.Y :=
StrToFloat(Edit3.Text)
else
Rectangle1.Fill.Gradient.StopPosition.X := StrToFloat(Edit3.Text);
end;

procedure TForm1.Edit4Change(Sender: TObject);
begin
Rectangle1.Fill.Gradient.StopPosition.Y := StrToFloat(Edit4.Text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Ellipse1.Visible := False;
Rectangle1.Visible := False;

// Fill initialization so Gradient can be applied
Ellipse1.Fill.Kind := TBrushKind.Gradient;
Rectangle1.Fill.Kind := TBrushKind.Gradient;

Ellipse1.Fill.Gradient.Style := TGradientStyle.Radial;
Rectangle1.Fill.Gradient.Style := TGradientStyle.Linear;
Label1.Text := ‘Choose the gradient type’;
ListBoxItem1.Text := ‘Linear’;
ListBoxItem2.Text := ‘Radial’;
Label2.Text := ”;
Label3.Text := ”;
Label4.Text := ”;
Label5.Text := ”;
Edit1.Visible := False;
Edit2.Visible := False;
Edit3.Visible := False;
Edit4.Visible := False;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.Selected.Text = ‘Linear’ then ListBoxItem1Click(Self) else
if ComboBox1.Selected.Text = ‘Radial’ then ListBoxItem2Click(Self);
end;

procedure TForm1.ListBoxItem1Click(Sender: TObject);
begin
Label2.Text := ‘StartPosition.X: ‘;
Label3.Text := ‘StartPosition.Y: ‘;
Label4.Text := ‘StopPosition.X: ‘;
Label5.Text := ‘StopPosition.Y: ‘;
Edit1.Visible := True;
Edit2.Visible := True;
Edit3.Visible := True;
Edit4.Visible := True;
Ellipse1.Visible := False;
Rectangle1.Visible := True;

// Set the Gradient colors
Rectangle1.Fill.Gradient.Color1 := ColorComboBox2.Color;
Rectangle1.Fill.Gradient.Color := ColorComboBox1.Color;
// Populate the Edit Boxes
Edit1.Text := FloatToStr(Rectangle1.Fill.Gradient.StartPosition.X);
Edit2.Text := FloatToStr(Rectangle1.Fill.Gradient.StartPosition.Y);
Edit3.Text := FloatToStr(Rectangle1.Fill.Gradient.StopPosition.X);
Edit4.Text := FloatToStr(Rectangle1.Fill.Gradient.StopPosition.Y);
end;

procedure TForm1.ListBoxItem2Click(Sender: TObject);
begin
Label2.Text := ‘RotationAngle:’;
Label3.Text := ‘RotationCenter.X:’;
Label4.Text := ‘RotationCenter.Y:’;
Label5.Text := ”;
Edit1.Visible := True;
Edit2.Visible := True;
Edit3.Visible := True;
Edit4.Visible := False;
Ellipse1.Visible := True;
Rectangle1.Visible := False;

// Set the Gradient colors
Ellipse1.Fill.Gradient.Color1 := ColorComboBox2.Color;
Ellipse1.Fill.Gradient.Color := ColorComboBox1.Color;

// Populate the edit boxes
Edit1.Text := FloatToStr(Ellipse1.Fill.Gradient.RadialTransform.
RotationAngle);
Edit2.Text := FloatToStr(Ellipse1.Fill.Gradient.RadialTransform.
RotationCenter.X);
Edit3.Text := FloatToStr(Ellipse1.Fill.Gradient.RadialTransform.
RotationCenter.Y);

end;

end.

form source
object Form1: TForm1
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
OnCreate = FormCreate
DesignerMasterStyle = 0
object Rectangle1: TRectangle
Position.X = 184.000000000000000000
Position.Y = 8.000000000000000000
Size.Width = 449.000000000000000000
Size.Height = 465.000000000000000000
Size.PlatformDefault = False
end
object Ellipse1: TEllipse
Position.X = 184.000000000000000000
Position.Y = 8.000000000000000000
Size.Width = 449.000000000000000000
Size.Height = 465.000000000000000000
Size.PlatformDefault = False
end
object Label1: TLabel
Position.X = 24.000000000000000000
Position.Y = 40.000000000000000000
Size.Width = 177.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
Text = ‘Choose the gradient type’
end
object Label2: TLabel
Position.X = 32.000000000000000000
Position.Y = 208.000000000000000000
Text = ‘Label2’
end
object Label3: TLabel
Position.X = 32.000000000000000000
Position.Y = 264.000000000000000000
Text = ‘Label3’
end
object Label4: TLabel
Position.X = 32.000000000000000000
Position.Y = 312.000000000000000000
Text = ‘Label4’
end
object Label5: TLabel
Position.X = 32.000000000000000000
Position.Y = 368.000000000000000000
Text = ‘Label5’
end
object Edit1: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
Position.X = 72.000000000000000000
Position.Y = 224.000000000000000000
OnChange = Edit1Change
end
object Edit2: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
Position.X = 72.000000000000000000
Position.Y = 280.000000000000000000
OnChange = Edit2Change
end
object Edit3: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
Position.X = 72.000000000000000000
Position.Y = 336.000000000000000000
OnChange = Edit3Change
end
object Edit4: TEdit
Touch.InteractiveGestures = [LongTap, DoubleTap]
Position.X = 72.000000000000000000
Position.Y = 392.000000000000000000
OnChange = Edit4Change
end
object ComboBox1: TComboBox
Position.X = 16.000000000000000000
Position.Y = 72.000000000000000000
Size.Width = 161.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChange = ComboBox1Change
object ListBoxItem1: TListBoxItem
Text = ‘ListBoxItem1’
OnClick = ListBoxItem1Click
end
object ListBoxItem2: TListBoxItem
Text = ‘ListBoxItem2’
OnClick = ListBoxItem2Click
end
end
object ColorComboBox1: TColorComboBox
DropDownKind = Custom
Color = claNull
DisableFocusEffect = False
Position.X = 16.000000000000000000
Position.Y = 112.000000000000000000
Size.Width = 161.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChange = ColorComboBox1Change
end
object ColorComboBox2: TColorComboBox
DropDownKind = Custom
Color = claNull
DisableFocusEffect = False
Position.X = 16.000000000000000000
Position.Y = 144.000000000000000000
Size.Width = 161.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
OnChange = ColorComboBox2Change
end
end

Comments are closed.