unit uRajzolo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, Buttons;

type

  TDrawingTool = (dtLine,dtFreehand);

  TfRajzolo = class(TForm)
    Panel1: TPanel;
    sbSzabadkezi: TSpeedButton;
    sbVonal: TSpeedButton;
    Kep: TImage;
    procedure FormCreate(Sender: TObject);
    procedure sbVonalClick(Sender: TObject);
    procedure sbSzabadkeziClick(Sender: TObject);
    procedure KepMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure KepMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure KepMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
  dt : TDrawingTool;
  InDraw : Boolean;
  StartPont : TPoint;
  RegiPont : TPoint;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fRajzolo: TfRajzolo;

implementation

{$R *.DFM}

procedure TfRajzolo.FormCreate(Sender: TObject);
Var B:TBitmap;
begin
     B:=TBitMap.Create;
     B.Width := ClientWidth;
     B.Height := ClientHeight;
     Kep.Picture.Graphic := B;
     dt := dtFreehand;
     InDraw := False;
end;

procedure TfRajzolo.sbVonalClick(Sender: TObject);
begin
dt := dtLine;
end;

procedure TfRajzolo.sbSzabadkeziClick(Sender: TObject);
begin
dt := dtFreehand;
end;

procedure TfRajzolo.KepMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if Button=mbLeft Then
   Begin
   InDraw := True;
   Case dt Of
        dtLine:
            Begin
            Startpont := Point(X,Y);
            Regipont := Point(X,Y);
            Kep.Canvas.Pen.Mode := pmNotXor;
            End;
        dtFreehand:
             Kep.Canvas.MoveTo(X,Y);
        End;
     End;
end;

procedure TfRajzolo.KepMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if InDraw Then
   Case dt Of
        dtLine:
            Begin
            With Kep.Canvas Do
               Begin
               MoveTo(StartPont.X,StartPont.Y);
               LineTo(RegiPont.X,RegiPont.Y);
               MoveTo(StartPont.X,StartPont.Y);
               LineTo(X,Y);
               RegiPont := Point(X,Y);
               End;

            End;
        dtFreehand:
             Kep.Canvas.LineTo(X,Y);
        End;
end;

procedure TfRajzolo.KepMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if InDraw Then
   Begin
   InDraw := False;
   Case dt Of
        dtLine:
            Begin
            With Kep.Canvas Do
               Begin
               Pen.Mode := pmCopy;
               MoveTo(StartPont.X,StartPont.Y);
               LineTo(X,Y);
               End;
            End;
        dtFreehand:
             Kep.Canvas.LineTo(X,Y);
        End;
     End;
end;

end.
