Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Text um Kreis schreiben in FMX (https://www.delphipraxis.net/185317-text-um-kreis-schreiben-fmx.html)

zeras 30. Mai 2015 10:59


Text um Kreis schreiben in FMX
 
Gibt es eine Komponente in XE5, einen Text um einen Kreis zu schreiben?

mensch72 30. Mai 2015 11:05

AW: Text um Kreis schreiben
 
damit geht auch ein Kreis(abschnitt)

https://www.tmssoftware.com/site/advfancylabel.asp

zeras 30. Mai 2015 11:10

AW: Text um Kreis schreiben
 
Zitat:

Zitat von mensch72 (Beitrag 1303643)
damit geht auch ein Kreis(abschnitt)

https://www.tmssoftware.com/site/advfancylabel.asp

Danke für die Info.
Ich hatte leider vergessen, dass ich das für FMX brauche. Ich habe zwar das Componentpack, aber das angefragte gibt es nur unter VCL. Jedenfalls habe ich das nur unter VCL gefunden, wobei ich nicht die letzte Version von TMS habe.

Harry Stahl 31. Mai 2015 18:45

AW: Text um Kreis schreiben in FMX
 
Liste der Anhänge anzeigen (Anzahl: 3)
Mir ist da leider keine Funktion bekannt, die das direkt anbietet (wie etwa DrawTextOnPath in anderen Entwicklungsumgebungen, dann hätte man das mit einer TPath-Komponente (Formen) lösen können).

Unter FMX ist das aber letztlich gar kein Problem, da man ja alle Textelemente rotieren und somit diese einfach ausrichten kann.

Für die von Dir benötigte Problemlösung habe ich mal quick and dirty etwas zusammengebastelt, wie man die Aufgabe lösen könnte. Hier erzeuge ich einfach für jeden einzelnen Buchstaben ein TLabel, das ich dann abhängig von der Position am Rand im entsprechenden Rotationswinkel anordne.

Du kannst mit den Werten für Winkel und (Text) Abstand ein wenig spielen, um zu sehen, wie sich das Ergebnis auswirkt. Wenn Du das ganze als Bitmap benötigen solltest, erhältst Du das mit der MakeScreenshot-Funktion. Hier der kurze Quelltext:

Delphi-Quellcode:
procedure TForm14.Button1Click(Sender: TObject);
var
  L: Integer;
  s: string;
  tl: TLabel;
  x, y, lh, centerx, centery: Extended;
  radians: extended;
  MyRotationAngle, textw: Extended;

  bm: TBitmap;
begin
  // Labels entfernen, falls da
  if Circle1.Children <> NIL then begin
    for L := Circle1.Children.Count-1 downto 0 do
      Circle1.Children[L].free;
  end;

  centerx := circle1.Width /2;
  centery := circle1.Height / 2;
  MyRotationAngle := Winkel.Value;

  for L := 1 to length (edit1.Text) do begin
    s := copy (edit1.Text, L, 1);

    textw := canvas.TextWidth(s) + Abstand.Value; // Textbreite Buchstabe

    lh := (circle1.Height / 2) + canvas.TextHeight(s);

    tl := tLabel.Create(Circle1);
    tl.Parent := Circle1;
    tl.Visible := True;
    tl.Text := s;
    tl.AutoSize := True;

    tl.RotationCenter.x := 0;
    tl.RotationCenter.y := 0;

    // Punkt auf Kreisrand berechnen
    radians := (MyRotationAngle - 90) * pi / 180;
    x := lh + lh * cos(radians);
    y := lh + lh * sin(radians);

    tl.Position.X := x + CenterX - lh;// - tl.Height;
    tl.Position.Y := y + CenterY - lh;// - tl.Height;

    tl.RotationAngle := MyRotationAngle;

    MyRotationAngle := MyRotationAngle + textw;
  end;

  (* Falls als Bitmap benötigt:
  bm := TBitmap.Create;
  bm := LayoutCopy.MakeScreenshot;
  //bm.SaveToFile('D:\TT.png');
  *)
end;
Anliegend der Source-Code (mit XE8 entwickelt, ist aber auch für frühere Versionen nutzbar) und 2 Screenshots (Hinweis: 2. Bild ist ein PNG mit Alphakanal, wird evtl. nicht in jedem Browser in der Vorschau richtig angezeigt).

Der schöne Günther 31. Mai 2015 19:04

AW: Text um Kreis schreiben in FMX
 
Ist das nicht genau was auf der Seite FireMonkey Layouts Strategies steht?
Zitat:

For example, an easy way to obtain a circular distribution of controls is to set the initial location for a TLayout with the controls inside, and then copy and paste the positioned layouts, keeping the same location and changing the RotationAngle.

Harry Stahl 31. Mai 2015 19:57

AW: Text um Kreis schreiben in FMX
 
Zitat:

Zitat von Der schöne Günther (Beitrag 1303734)
Ist das nicht genau was auf der Seite FireMonkey Layouts Strategies steht?
Zitat:

For example, an easy way to obtain a circular distribution of controls is to set the initial location for a TLayout with the controls inside, and then copy and paste the positioned layouts, keeping the same location and changing the RotationAngle.

Nein, "genau was da steht" ist es nicht (wobei es nicht schaden kann, sich das und die weiterführenden Seiten einmal durchzulesen). Dort geht es in erster Linie darum, wie man zur Design-Zeit Controls anordnen kann. Ich bin davon ausgegangen, dass die Aufgabe "Text" um Kreis schreiben" sich auf eine Runtime-Problematik bezog.

zeras 31. Mai 2015 21:11

AW: Text um Kreis schreiben in FMX
 
Danke für die Quelle.
Ich werde mal sehen, wie ich das in mein Projekt einbauen kann.
Aber bezahlen kann ich die "Sonntagsarbeit" nicht.


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:22 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