Sensitivity of OnMouseMove

I am writing a paint program (like Paint Shop Pro, Windows Paint, etc.)

Say the user wants to draw freely on the canvas with the mouse.  Currently I use an OnMouseMove event, and draw a line on the canvas between the current event and the previous OnMouseMove event.

While this works fine when the user is moving the mouse relatively slow, if the user happens to scribble really fast, the result is not what you would resembles what the user intended to draw, but it looks like a bunch of cheaply connected lines.

While experimenting with Paint Shop Pro, I look closely noticed that it uses the same method as I...but it seems that PSP seems to be a lot more can scribble really fast and the lines still look like curve.

I have come to the conclusion that, either

1.  The OnMouseMove event is not generated often enough


2.  The event is generated often enough, but my event handler is too slow

Is it faster to use Windows messages directly, than to use the OnMouseMove event?  Or is there even some better way than that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

scrapdogAuthor Commented:
P.S.  The OnPaint method of the same component has quite a bit of overhead (it has to do a lot of conversions)...I don't know if this affects OnMouseMove at all...
Hi ScrapDog,

   Does your code look like this:

    OldX, OldY : Integer;
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
    if ( OldX <> 0 ) and ( OldY <> 0 ) then
       Canvas.MoveTo( OldX, OldY );
       Canvas.LineTo( X, Y );
    OldX := X;
    OldY := Y;

{...} ?

And are these the results you're not happy with?



There is a lot of overhead drawing on that canvas.  Why don't you store the coordinates sent via MouseMove in an array, then perhaps in a lower priority thread, draw the lines whenever the system has time.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scrapdogAuthor Commented:

Similar in theory, but not in practice...I draw the line on the canvas of a bitmap.

That is not what constitutes the majority of the overhead, however...the component I am writing take this bitmap and displays it in a different aspect ratio.  The converted bitmap is blitted to the component's canvas.

Would using a separate thread speed this up?

scrapdogAuthor Commented:
Ah yes, snoop doggy dog, after thinking about it a bit, that sounds like a very good idea.  I will leave the Q open a little while longer, though, just in case.

~scrap doggy dog
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.