Tuesday, February 14, 2006

Drawing with different line types


    Windows allows to draw lines where each pixel is another shape or drawing with LineDDa function. It needs a callback function that is called when each pixel must be drawn. There you can put the drawing routines. This routine draws a rectangle every 4 pixels:


      TForm1 = class(TForm)

        procedure FormCreate(Sender: TObject);

        procedure FormPaint(Sender: TObject);

      public

        DrawNow : Integer;

      end;



      var

        Form1: TForm1;



      procedure DrawPoint(x,y : Integer;lpData : LParam); stdcall;



      implementation



      {$R *.DFM}



      procedure DrawPoint(x,y : Integer;lpData : LParam);

      begin

        with TObject(lpData) as TForm1 do begin

          if DrawNow mod 4 = 0 then

            Canvas.Rectangle(x-2,y-2,x+3,y+3);

          Inc(DrawNow);

        end;

      end;



      procedure TForm1.FormCreate(Sender: TObject);

      begin

        DrawNow := 0;

      end;



      procedure TForm1.FormPaint(Sender: TObject);

      begin

        LineDDA(0,0,Width,Height,@DrawPoint,Integer(Self));

      end;

0 Comments:

Post a Comment

<< Home