In firemonkey, I am trying to make progress using rectangles with round corners. The simplest case is a rectangle (progress indicator) and a second rectangle inside it (progress so far). A simple example is attached.
Progressbar with corners (paint):
I have tried the following things:
:
, , ?
():
!
Jan
,
. , html/css, Delphi .
, ; , . ( , ), Layout ClipChildren true, Width.
ClipChildren
true
Width
type TRoundProgressBar = class (TLayout) strict private FProgress: Single; FFill: TBrush; FStroke: TStrokeBrush; StrokeRect, FillRect: TRectangle; FillLayout: TLayout; procedure SetFill(const Value: TBrush); procedure SetStroke(const Value: TStrokeBrush); procedure FillChanged(Sender: TObject); procedure StrokeChanged(Sender: TObject); procedure SetProgress(Progress: Single); procedure UpdateWidths; protected procedure Resize; override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property Fill: TBrush read FFill write SetFill; property Stroke: TStrokeBrush read FStroke write SetStroke; property Progress: Single read FProgress write SetProgress; end; implementation constructor TRoundProgressBar.Create(AOwner: TComponent); begin inherited Create(AOwner); FFill := TBrush.Create(TBrushKind.Solid, $FFE0E0E0); FFill.OnChanged := FillChanged; FStroke := TStrokeBrush.Create(TBrushKind.Solid, $FF000000); FStroke.OnChanged := StrokeChanged; FillLayout := TLayout.Create(self); FillLayout.Parent := self; FillLayout.Align := TAlignLayout.Left; FillLayout.ClipChildren := true; FillRect := TRectangle.Create(FillLayout); FillRect.Parent := FillLayout; FillRect.Align := TAlignLayout.Left; FillRect.XRadius := 15; FillRect.YRadius := 15; StrokeRect := TRectangle.Create(self); StrokeRect.Parent := self; StrokeRect.Align := TAlignLayout.Contents; StrokeRect.XRadius := 15; StrokeRect.YRadius := 15; StrokeRect.Fill.Kind := TBrushKind.None; end; destructor TRoundProgressBar.Destroy; begin FFill.Free; FStroke.Free; inherited; end; procedure TRoundProgressBar.SetFill(const Value: TBrush); begin FFill.Assign(Value); end; procedure TRoundProgressBar.SetProgress(Progress: Single); begin FProgress := Min(Max(Progress, 0), 100); UpdateWidths; end; procedure TRoundProgressBar.FillChanged(Sender: TObject); begin FillRect.Fill.Assign(FFill); end; procedure TRoundProgressBar.Resize; begin inherited; UpdateWidths; end; procedure TRoundProgressBar.SetStroke(const Value: TStrokeBrush); begin FStroke.Assign(Value); end; procedure TRoundProgressBar.StrokeChanged(Sender: TObject); begin StrokeRect.Stroke.Assign(FStroke); end; procedure TRoundProgressBar.UpdateWidths; begin FillRect.Width := Width; FillLayout.Width := Width * (FProgress / 100); Repaint; end;
, , ( Rectf). :
1) onpaint trectangle ( )
2) 2 Trectangles ( ), tRectangle (), , ( Sides Trectangle) Trectangle (), ( ). 2 Trectangles Tlayout ( , ), Trectangle () Trectangle () ALleft. , MyOrangeRect.width: = XX, xx -
TRectangle:
TRectangle, , fill TBitmap.
TBitmap ( ) fill.bitmap.bitmap( double bitmap) .
- .
: , Photoshop, / , IOS TRectangle.
(roundrect), :
procedure TForm4.SpinBox1Change(Sender: TObject); begin roundrect2.Width:=strtoint(SpinBox1.Text); end;
, ;
TRectangle , .
The best solution for you would be to create a custom component that contains two TPathData(calling them, for example, PathBackground and PathFill), which are recalculated when the percentage changes and when it changes.
TPathData
In the Paint routine, I would draw this path
Canvas.FillPath(PathBackground, ...); Canvas.FillPath(PathFill, ...); Canvas.DrawPath(PathBackground, ...);
By pulling the edge as the last, you avoid rendering errors.
Source: https://habr.com/ru/post/1670296/More articles:"dataTaskWithRequest" requests NSMutableRequest twice when only one request is needed - iosПроверка валидатора для проверки правильности запроса. вернуть оригинал, если не удалось - phpExcel Solver Password: what is it and where can I buy / buy it? - vbaError using replivemongo 0.12.1 with game 2.5.X - scalaHow to programmatically enable the autorun option for my application on Lenovo devices? - androidTimber & WPML String Translation - wordpressDocker installs memcached - phpdjango rest adds data to serializer when saving - djangoHide text from a TextBox without using PasswordBox - wpfКак использовать /dist файлы папок, созданные командой angular -cli ng build для создания приложения, которое можно запустить самостоятельно? - angularAll Articles