Einzelnen Beitrag anzeigen

Benutzerbild von Harry Stahl
Harry Stahl

Registriert seit: 2. Apr 2004
Ort: Bonn
2.479 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Text um Kreis schreiben in FMX

  Alt 31. Mai 2015, 18:45
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).
Miniaturansicht angehängter Grafiken
drawcircle-prog.jpg   tt.png  
Angehängte Dateien
Dateityp: zip CircleTextDraw.zip (7,1 KB, 6x aufgerufen)

Geändert von Harry Stahl (31. Mai 2015 um 18:52 Uhr)
  Mit Zitat antworten Zitat