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 expect...it 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 sensitive...you 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

or

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?
LVL 5
scrapdogAsked:
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...
0
rarigoCommented:
Hi ScrapDog,

   Does your code look like this:

{...}
  private
    OldX, OldY : Integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

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

{...} ?

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

Tchau,
Reginaldo

0
snoop_doggy_doggCommented:
Scrap,

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.

Woof.
0

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:
Reginaldo:

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?



0
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
0
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
Delphi

From novice to tech pro — start learning today.