

Ich wollte fragen, ob es eine möglichkeit gibt ein Strich, mit Canvas zu zeichnen und diesen dann nachträglich zu bewegen.
Wenn ich dann zwei zeichne, möchte ich beide einzelnd bewegen können.
Danke im voraus für die Hilfe.
lg Dragomir
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormPaint(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
Pt:TPoint;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Pt:=Point(X,Y);
Invalidate;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.MoveTo(10,10);
Canvas.LineTo(Pt);
end;
end.
Canvas merkt sich nur die Pixel, nicht wie sie entstanden sind.Dragomir hat geschrieben:jetz muss ich halt nur schauen, dass wenn ich 2 striche habe er nur den einen bewegt
Ich will dir ja den Spaß nicht verderben, aber kennst du LazPaint (https://sourceforge.net/projects/lazpaint/)? Das ist mit Lazarus geschrieben, und da kannst du schon mal sehen, was auf dich zukommt.Dragomir hat geschrieben:Es ist eine Bildbearbeitungsanwendung.
Ich habe mal einem Bekannten geholfen, der eine (sehr spezielle) Bildbearbeitungs-Software gemacht hat.Dragomir hat geschrieben: Es ist eine Bildbearbeitungsanwendung.
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, contnrs;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
PaintBox1: TPaintBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
private
FMyShapes: TObjectList;
{ private declarations }
public
{ public declarations }
end;
TMyShape = class(TObject)
private
FPosition: TPoint;
public
procedure Draw(C: TCanvas); virtual; abstract;
property Position: TPoint read FPosition write FPosition;
end;
TMyRect = class(TMyShape)
private
FWidth, FHeight: integer;
public
procedure Draw(C: TCanvas); override;
property Width: integer read FWidth write FWidth;
property Height: integer read FHeight write FHeight;
end;
TMyLine = class(TMyShape)
private
FStartPoint, FEndPoint: TPoint;
public
procedure Draw(C: TCanvas); override;
property StartPoint: TPoint read FStartPoint write FStartPoint;
property EndPoint: TPoint read FEndPoint write FEndPoint;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TMyRect.Draw(C: TCanvas);
begin
C.Rectangle(Position.X, Position.Y, Position.X + Width, Position.Y + Height);
end;
procedure TMyLine.Draw(C: TCanvas);
begin
c.MoveTo(Position.X + StartPoint.X, Position.Y + StartPoint.Y);
c.LineTo(Position.X + EndPoint.X, Position.Y + EndPoint.Y);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
FMyShapes := TObjectList.Create(True);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
// Adding an Object
with FMyShapes[FMyShapes.Add(TMyLine.Create)] as TMyLine do
begin
Position := Point(0, 0);
StartPoint := Point(Random(PaintBox1.Width), Random(PaintBox1.Height));
EndPoint := Point(Random(PaintBox1.Width), Random(PaintBox1.Height));
end;
// Redraw everything
PaintBox1.Invalidate;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
// Reposition all Objects
for i := 0 to FMyShapes.Count - 1 do
(FMyShapes[i] as TMyShape).Position :=
Point(Random(PaintBox1.Width), Random(PaintBox1.Height));
// Redraw everything
PaintBox1.Invalidate;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FMyShapes.Free;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
i: integer;
begin
//Clear
PaintBox1.Canvas.Clear;
for i := FMyShapes.Count - 1 downto 0 do // FMyShapes[0] oberste Ebene
(FMyShapes[i] as TMyShape).Draw(Canvas);
end;
end.
Es ist immer die Frage, was "Simpel" ist. Ein paar Stzriche auf große Pixel-Fläche zu malen und davon Teilbereiche anzuzeigen ist eigentlich simpel, aber flüssiges Zoom und Pan braucht trotzdem Hardware-Unterstützung.Warf hat geschrieben:Also für ein simples Grafik Programm sollte die CPU schnell genug sein.