Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting a paint program à la MS Paint - how to interpolate between mouse move events?
    primarykey
    data
    text
    <p>I want to write a paint program in the style of MS Paint.</p> <p>For painting things on screen when the user moves the mouse, I have to wait for mouse move events and draw on the screen whenever I receive one. Apparently, mose move events are not sent very often, so I have to interpolate the mouse movement by drawing a line between the current mouse position and the previous one. In pseudocode, this looks something like this:</p> <pre><code>var positionOld = null def handleMouseMove(positionNew): if mouse.button.down: if positionOld == null: positionOld = positionNew screen.draw.line(positionOld,positionNew) positionOld = positionNew </code></pre> <p>Now my <strong>question</strong>: interpolating with straight line segments looks too jagged for my taste, can you recommend a better interpolation method? What method do GIMP or Adobe Photoshop implement?</p> <p>Alternatively, is there a way to increase the frequency of the mouse move events that I receive? The GUI framework I'm using is <a href="http://www.wxwidgets.org/" rel="noreferrer">wxWidgets</a>.</p> <p>GUI framework: wxWidgets.<br> (Programming language: Haskell, but that's irrelevant here)</p> <p><strong>EDIT:</strong> Clarification: I want something that looks smoother than straight line segments, see the picture (original size):</p> <p><a href="http://i26.tinypic.com/hwa42h.jpg" rel="noreferrer">jagged lines drawn between mouse positions http://i26.tinypic.com/hwa42h.jpg</a></p> <p><strong>EDIT2:</strong> The code I'm using looks like this:</p> <pre><code>-- create bitmap and derive drawing context im &lt;- imageCreateSized (sy 800 600) bitmap &lt;- bitmapCreateFromImage im (-1) -- wxBitmap dc &lt;- memoryDCCreate -- wxMemoryDC memoryDCSelectObject dc bitmap ... -- handle mouse move onMouse ... sw (MouseLeftDrag posNew _) = do ... line dc posOld posNew [color := white , penJoin := JoinRound , penWidth := 2] repaint sw -- a wxScrolledWindow -- handle paint event onPaint ... = do ... -- draw bitmap on the wxScrolledWindow drawBitmap dc_sw bitmap pointZero False [] </code></pre> <p>which might make a difference. Maybe my choices of wx-classes is why I'm getting a rather low frequency of mouse move events.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload