Developer Workshop: QuickDrag
By Stephen Beaulieu <hippo@be.com>

In last week's Developer Workshop article, Translator
Panel: The Revenge <http://www-classic.be.com/aboutbe
/benewsletter/volume_III/Issue42.html#Workshop>, Daniel
presented a method for starting a drag and drop session
using a one-shot BMessageRunner. The goal was to ignore
extraneous mouse clicks and inadvertent mouse drags. A
potential disadvantage is that this imposes a delay on the
start of the drag process.

This week's sample code offers an alternate method for
starting a drag process based on the distance the mouse
travels while a button is down.

You can find QuickDrag at

<ftp://ftp.be.com/pub/samples/intro/QuickDrag.zip>

QuickDrag creates a window with a single view that slowly
cycles colors through a very uninteresting algorithm. A
drag is initiated when a user clicks in the window and
drags more than 10 pixels horizontally or vertically from
the click point. When a drag and drop session starts, a
transparent bitmap of the window's current color will be
dragged and the window will stop cycling colors.

The implementation is straightforward. The view caches the
click point when the mouse has moved 10 pixels and initiates
the dragging process. The code is self-explanatory, so I'll
only point out two things here:

1. It's necessary to call SetMouseEventMask() in MouseDown()
   to track the mouse when it leaves the view. Otherwise, a
   click within 10 pixels of an edge only generates a drag
   when the mouse moves into the view. Unset the mask in
   MouseUp().

2. A pixel in a B_RGB32 bitmap is not the same as an rgb_color.
   It's necessary to swap the red and blue colors.



