scrapdog
asked on
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?
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?
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(Sende r: 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
Does your code look like this:
{...}
private
OldX, OldY : Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormMouseMove(Sende
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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
~scrap doggy dog
ASKER