Einzelnen Beitrag anzeigen

Satty67

Registriert seit: 24. Feb 2007
Ort: Baden
1.566 Beiträge
 
Delphi 2007 Professional
 
#7

AW: "Kreisberechnung" - Hülfe gesucht...

  Alt 27. Okt 2010, 11:40
Deine Antwort bezieht sich nicht auf meinen Post?

Bei mir funktioniert es:
Delphi-Quellcode:
procedure TForm1.FormPaint(Sender: TObject);
const
  txt = '012346789 - Hello@World!';
var
  Rect1, Rect2, Rect3, RectTotal : TRect;
  fh,fw: integer;
  p1, p2: TPoint;
  ts: TSize;
begin
  SetFontDirection(Canvas.Font, 0);
  canvas.Brush.Style := bsClear;
  DrawCoordSys(canvas);

  // normal TextOut
  canvas.Font.Color := clGray;
  canvas.TextOut(150,150, txt);

  // get fontdim.
  fh := canvas.TextHeight(txt);
  fw := canvas.TextWidth(txt);

  canvas.Pen.Color := clBlue;
  canvas.Rectangle(150,150,150+fw, 150+fh);

  canvas.Pen.Color := clGray;
  canvas.Ellipse(150-fw, 150-fw,150+fw, 150+fw);


  // rotierter Text
  SetFontDirection(Canvas.Font, Winkel);
  canvas.Font.Color := clBlack;
  canvas.TextOut(150,150, txt);


  // Corner
  p1 := POINT(150, 150);
  DrawCross(canvas, p1.x, p1.Y, clYellow); // Nullpos


  p2 := POINT(150 + fw, 150);
  p2 := PointRotate(p1, p2, Winkel);
  DrawCross(canvas, p2.x, p2.Y, clRed);

  Rect1.Top := Math.Min(p1.y, p2.y);
  Rect1.Left := Math.Min(p1.x, p2.x);
  Rect1.Bottom := Math.Max(p1.y, p2.y);
  Rect1.Right := Math.Max(p1.x, p2.x);

  p2 := POINT(150 + fw, 150 + fh);
  p2 := PointRotate(p1, p2, Winkel);
  DrawCross(canvas, p2.x, p2.Y, clGreen);

  Rect2.Top := Math.Min(p1.y, p2.y);
  Rect2.Left := Math.Min(p1.x, p2.x);
  Rect2.Bottom := Math.Max(p1.y, p2.y);
  Rect2.Right := Math.Max(p1.x, p2.x);

  p2 := POINT(150, 150 + fh);
  p2 := PointRotate(p1, p2, Winkel);
  DrawCross(canvas, p2.x, p2.Y, clBlue);

  Rect3.Top := Math.Min(p1.y, p2.y);
  Rect3.Left := Math.Min(p1.x, p2.x);
  Rect3.Bottom := Math.Max(p1.y, p2.y);
  Rect3.Right := Math.Max(p1.x, p2.x);

  RectTotal.Top := Math.Min( Rect1.Top, Math.Min(Rect2.Top, Rect3.Top));
  RectTotal.Left := Math.Min( Rect1.Left, Math.Min(Rect2.Left, Rect3.Left));
  RectTotal.Bottom := Math.Max( Rect1.Bottom, Math.Max(Rect2.Bottom, Rect3.Bottom));
  RectTotal.Right := Math.Max( Rect1.Right, Math.Max(Rect2.Right, Rect3.Right));

  canvas.Rectangle(Rect1);
  canvas.Rectangle(Rect2);
  canvas.Rectangle(Rect3);

  canvas.Pen.Color := clRed;
  canvas.Pen.Width := 2;
  canvas.Rectangle(RectTotal);

  ts := Canvas.TextExtent(txt);
  Label1.Caption := format('Winkel: %d°'#13'Textlänge: %d, Texthöhe: %d (in Pixel)', [Winkel, ts.cx, ts.cy]);

end;
Miniaturansicht angehängter Grafiken
rechteckrotattion.jpg  

Geändert von Satty67 (27. Okt 2010 um 11:42 Uhr)
  Mit Zitat antworten Zitat