Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   FMX bunte Polygone zeichnen (https://www.delphipraxis.net/205249-fmx-bunte-polygone-zeichnen.html)

bernhard_LA 18. Aug 2020 08:23


FMX bunte Polygone zeichnen
 
Liste der Anhänge anzeigen (Anzahl: 1)
scheitere aktuell dabei jetzt bunte Polygone zu zeichnen


hier der Demo code :


Delphi-Quellcode:
procedure TForm1.btn_draw_PolygonClick(Sender: TObject);
var
  p1, p2, p3, p4, p5: TPointF;
  MyPolygon: TPolygon;
  I: Integer;
  Brush: TStrokeBrush;
begin


  for I :=1 to 10  do
  begin
  Brush := TStrokeBrush.Create(TBrushKind.Solid, randomColor);
  Brush.Thickness := 2;
  // sets the points that define the polygon
  p1 := TPointF.Create(200+ Random(50), 220 + Random(50) );
  p2 := TPointF.Create(250+ Random(50), 360+ Random(50));
  p3 := TPointF.Create(280+ Random(50), 260+ Random(50));
  p4 := TPointF.Create(200+ Random(50), 180+ Random(50));
  p5 := TPointF.Create(100+ Random(50), 160+ Random(50));
  // creates the polygon
  SetLength(MyPolygon, 5);
  MyPolygon[0] := p1;
  MyPolygon[1] := p2;
  MyPolygon[2] := p3;
  MyPolygon[3] := p4;
  MyPolygon[4] := p5;

  // localBMP.Canvas.Stroke := Brush; geht nicht weil read only property ......

  localBMP.Canvas.BeginScene;
  // draws the polygon on the canvas
  localBMP.Canvas.DrawPolygon(MyPolygon, 50) ;
  localBMP.Canvas.EndScene;
  // updates the bitmap
  // Image1.Bitmap.BitmapChanged;

  LoadBMP2GUI(nil);

  Brush.Free;
  end;
end;

ich kann den Brush nicht an meine Bitmap übergeben , und einen Aufruf incl. Brush gibt es für Canvas.DrawPolygon nicht :-(

Sherlock 18. Aug 2020 09:01

AW: FMX bunte Polygone zeichnen
 
FMX.TCanvas.Stroke.Kind muss auch gesetzt werden, meine ich.

Sherlock

Rollo62 18. Aug 2020 10:02

AW: FMX bunte Polygone zeichnen
 
DocWiki ist gerade down (mal wieder).
https://www.ideasawakened.com/post/s...i-applications
http://delphi.org/2019/02/delphis-bi...ittle-svg-fun/

Probier das doch mal mit TPath, in PathData da kann man direkt beliebige SVG-ähnliche Pfade eingeben.

philipp.hofmann 18. Aug 2020 13:52

AW: FMX bunte Polygone zeichnen
 
Ich mache es mit folgendem Code (ist aber eine Vereinfachung, da meine Polygon-Form relativ fix ist):

Delphi-Quellcode:
unit SimplePolygon;

interface

uses
  System.Classes, System.Types, FMX.Objects, System.Math.Vectors;

type
  TSimplePolygon = class(TShape)
  private
    FPoints: TPolygon;
  protected
    procedure Paint; override;
  public
    heightEnd:single;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
  end;

procedure Register;

implementation

uses MyLog;

procedure Register;
begin
  RegisterComponents('Shapes', [TSimplePolygon]);
end;

{ TSimpleTriangle }

constructor TSimplePolygon.Create(AOwner: TComponent);
begin
  inherited;
  SetLength(FPoints, 5);
end;

destructor TSimplePolygon.Destroy;
begin
  Finalize(FPoints);
  inherited;
end;

procedure TSimplePolygon.Paint;
var
  R: TRectF;
begin
  R := GetShapeRect;
  FPoints[0] := PointF(R.Left, R.Bottom);
  FPoints[1] := PointF(R.Left, R.Top);
  FPoints[2] := PointF(R.Right, R.Top-(heightEnd-height));
  FPoints[3] := PointF(R.Right, R.Bottom);
  FPoints[4] := PointF(R.Left, R.Bottom);
  Canvas.Fill.Assign(Self.Fill);
  Canvas.FillPolygon(FPoints, AbsoluteOpacity);
  Canvas.DrawPolygon(FPoints, AbsoluteOpacity);
end;

end.
Delphi-Quellcode:
            polygon:=TSimplePolygon.Create(self);
            polygon.Parent:=myRExercise;
            polygon.beginUpdate;
            polygon.Name:='RECT_'+IntToStr(i)+'_'+IntToStr(j)+'_'+IntToStr(k);
            polygon.OnClick:=btRectClick;
            polygon.Fill.Color:=myExercise.sequenceList[i].legList[k].getLegLevelColor();
            polygon.Stroke.Dash:=TStrokeDash.Solid;
            polygon.Stroke.Color:=TAlphaColors.Black;
            polygon.Stroke.Thickness:=1;
            polygon.Width:=width;
            polygon.Height:=height;
            polygon.HeightEnd:=heightEnd;
            polygon.Position.X:=lastX;
            polygon.Position.Y:=myRExercise.Height-polygon.Height;
            polygon.EndUpdate;


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:01 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz