Einzelnen Beitrag anzeigen

Benutzerbild von uligerhardt
uligerhardt

Registriert seit: 19. Aug 2004
Ort: Hof/Saale
1.735 Beiträge
 
Delphi 2007 Professional
 
#17

AW: Zeichnen auf Canvas und ZOrder bzw. Übermalen

  Alt 2. Apr 2015, 10:56
Zitat:
Freilich geht das.
Nö! nicht mit Canvas.
Ich hab deinen Code mal in eine lauffähige Form gebracht und sehe Kreise über Strichen:
Delphi-Quellcode:
procedure DrawEllipseFromCenter(Canvas: TCanvas; XOffset: integer; YOffset: integer; RadiusOfCircle: Integer);
var
  R: TRect;
begin
  R.Top := YOffset - RadiusOfCircle;
  R.Left := XOffset - RadiusOfCircle;
  R.Bottom := YOffset + RadiusOfCircle;
  R.Right := XOffset + RadiusOfCircle;
  Canvas.Ellipse(R);
end;

procedure TForm2.PaintFramePaint(Sender: TObject);
var
  Bitmap: TBitmap;
const
  Physics_x0 = 100;
  Physics_x1 = 200;
  Physics_y0 = 100;
  Physics_y1 = 200;
  Physics_r0 = 30;
  Physics_r1 = 40;
  xFact = 1;

  function xxc(x: Integer): Integer;
  begin
    Result := x;
  end;

  function yyc(y: Integer): Integer;
  begin
    Result := y;
  end;

begin
  Bitmap := TBitmap.Create;
  try
    Bitmap.SetSize(PaintFrame.ClientWidth, PaintFrame.ClientHeight);

    Bitmap.Canvas.Font.Color := clblack;
    Bitmap.Canvas.Pen.Width := 1;
    //PrepareScale;

    // Linie an der das Pendel (Ball) hängt
    Bitmap.Canvas.Pen.Color := clblack;
    Bitmap.Canvas.MoveTo(xxc(Physics_x0), yyc(Physics_y0));
    Bitmap.Canvas.LineTo(xxc(Physics_x1), yyc(Physics_y1));

    Bitmap.Canvas.Brush.Style := bsSolid;
    Bitmap.Canvas.brush.Color := clblack;
    Bitmap.Canvas.Pen.Width := 5;
    // Center Punkt
    DrawEllipseFromCenter(Bitmap.Canvas, xxc(Physics_x0), yyc(Physics_y0), round(Physics_r0 * xFact));

    // Ball
    Bitmap.Canvas.brush.Color := clred;
    Bitmap.Canvas.Pen.Width := 2;
    DrawEllipseFromCenter(Bitmap.Canvas, xxc(Physics_x1), yyc(Physics_y1), round(Physics_r1 * xFact));

    // vom Bitmap auf das Canvas kopieren
    BitBlt(PaintFrame.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height, Bitmap.Canvas.Handle, 0, 0, srccopy);
  finally
    Bitmap.Free;
  end;
end;
(PaintFrame ist dabei eine TPaintBox) Also irgendwie zeigst du uns nicht das Relevante.
Uli Gerhardt
  Mit Zitat antworten Zitat