[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

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?
0
scrapdog
Asked:
scrapdog
  • 3
1 Solution
 
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
 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now