unit URecordButton;
interface
uses System.SysUtils, System.Classes, System.Types, System.UITypes,
FMX.Graphics, FMX.Types, FMX.Controls, FMX.Objects;
type
TRecordButton =
class(TShape)
protected
FRecording: Boolean;
FDiameter: single;
procedure Paint;
override;
procedure SetDiameter(
const Value: single);
public
constructor Create(AOwner: TComponent);
override;
published
property Diameter: single
read FDiameter
write SetDiameter;
property Recording: Boolean
read FRecording
write FRecording;
property Align;
property Anchors;
property ClipChildren
default false;
property ClipParent
default false;
property DesignVisible
default True;
property Enabled
default True;
property Locked
default false;
property Height;
property HitTest
default True;
property Padding;
property Opacity;
property Margins;
property PopupMenu;
property position;
property RotationAngle;
property RotationCenter;
property Scale;
property Visible
default True;
property Width;
{ Mouse events }
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseEnter;
property OnMouseLeave;
property OnPainting;
property OnPaint;
property OnResize;
end;
implementation
constructor TRecordButton.Create(AOwner: TComponent);
begin
inherited;
Fill.color := $FFFF0000;
Stroke.color := $FFFFFFFF;
Stroke.Kind := TBrushKind.bkSolid;
Diameter := 32;
end;
procedure TRecordButton.SetDiameter(
const Value: single);
begin
FDiameter := Value;
Stroke.Thickness := FDiameter / 20;
end;
procedure TRecordButton.Paint;
var
perc, w: single;
xp, yp: single;
color: TAlphaColor;
begin
if FRecording
then
perc := 0.4
else
perc := 0.85;
w := perc * FDiameter;
xp := (Width - w) / 2;
yp := (FDiameter - w) / 2;
if FRecording
then
canvas.FillRect(RectF(xp, yp, xp + w, yp + w), 0.2 * w, 0.2 * w,
AllCorners, 1, Fill)
else
canvas.FillEllipse(RectF(xp, yp, xp + w, yp + w), 1, Fill);
xp := (Width - FDiameter) / 2;
yp := 0;
canvas.DrawEllipse(RectF(xp, yp, xp + Diameter, yp + Diameter), 1, Stroke);
end;
end.