Author Topic: Can I change the psDot pen spacing?  (Read 2129 times)


  • Jr. Member
  • **
  • Posts: 57
Can I change the psDot pen spacing?
« on: August 02, 2013, 08:12:13 pm »
So I've made a simple program where the pen follows the mouse around the screen. When I move the mouse quickly, the pen spacing is fine, however when I move the mouse slowly, the dots are so close together than it just becomes a line. It seems the spacing is on a timer. Is there any way of setting it so that a dot is created after (eg) 100px?

Also, on a side note, can I prevent the pen looking jagged or would I have to use another library like BGRABitmap?

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}


  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;


  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    { private declarations }
    { public declarations }

  Form1: TForm1;
  x1, x2, y1, y2, count : integer;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
  x1 := 0;
  x2 := 0;
  y1 := 0;
  y2 := 0;
  count := 0;
  Canvas.Pen.Color := clRed;
  Canvas.Pen.Width := 5;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
  x1 := x;
  y1 := y;
  if (Count > 0) then
  Canvas.Line(x1, y1, x2, y2);
  Count := count + 1;
  x2 := x1;
  y2 := y1;


Thanks guys :)


  • Hero Member
  • *****
  • Posts: 5365
Re: Can I change the psDot pen spacing?
« Reply #1 on: August 02, 2013, 08:19:12 pm »
no the dashes are not dependent on a timer, to put it simple you are painting multiple lines so when the mouse moves slowly the difference between x1,y1 and x2,y2 is so small that it seems as a continues line but it is not they are multiple lines one next to the other. Try to minimize and restore your form after you have painted the lines and see what happens.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64


  • Hero Member
  • *****
  • Posts: 3405
    • Personal webpage
Re: Can I change the psDot pen spacing?
« Reply #2 on: August 02, 2013, 08:46:29 pm »
You can draw progressively a line with dots using BGRABitmap, more precisely:
Code: [Select]
     procedure DrawLineAntialias(x1, y1, x2, y2: integer; c1, c2: TBGRAPixel; dashLen: integer; DrawLastPixel: boolean; var DashPos: integer);

First initialize DashPos variable to zero and pass it as a parameter. Its value will change in order to continue the line properly. If you want a simple dash, set c1 to the color of the dashes and c2 to BGRAPixelTransparent.
Conscience is the debugger of the mind


TinyPortal © 2005-2018