[comp.sys.mac.programmer] dragging icons

franco@bbn.com (Frank A. Lonigro) (02/20/88)

[[[[[ Line eaters unite ]]]]]

To all LSC users:
	I'm new to programming the MAC and have a request.  Could some
of you send me your favorite piece of code for choosing and dragging
ICONs with the mouse(not the whole program, just that section of code).

	I have this great book on programming the MAC in "C", "Using the
Macintosh ToolBox with C".  It's a good book and I'm learning alot, but
it doesn't explain how to code the most used aspect of the Mac desktop,
namely, choosing an ICON and have it become its mask and then dragging it
to another spot on the desktop(be it in a window or the desktop itself).
I have this idea that I need to define a rectangle, stick the image of the
ICON in it and then detect a mouseDown event and determine if the Event.where
point is enclosed by that rectangle.  This is all well and good except
how do you have it change to its mask?  I also could use OffsetRect() to
move it, but there must be an easier way to find out the "dh, dv" parameters.
Is there such a function called DragRect() synonymous to DragWindow()??

	Any and all help you can give would be greatly appreciated.

Thanks in advance,
-franco

franco@bbn.com
franco%bbn.com@relay.cs.net
...!harvard!bbn!franco

borscht@eleazar.Dartmouth.EDU (Andy J. Williams) (02/21/88)

In article <21013@bbn.COM> franco@bbn.com (Frank A. Lonigro) writes:

>To all LSC users:
>	I'm new to programming the MAC and have a request.  Could some
>of you send me your favorite piece of code for choosing and dragging
>ICONs with the mouse(not the whole program, just that section of code).


I need similar routines in LSP.  I need to implement a system which looks
very much like the finder except it uses ICONs instead of ICN#s.  Any little
piece of code to drag, mask, zoom open, or scroll would be very helpful.

>	Any and all help you can give would be greatly appreciated.
>
>Thanks in advance,
>-franco
>

Thanks from me too!
-Andy

-- 
Andy J. Williams    |_   /| |BITNET: borscht@eleazar.dartmouth.edu
HB 509 Dartmouth Clg|\`o_O' |UUCP: {ihnp4,decvax,linus}!dartvax!eleazar!borscht
Hanover, NH 03775   |  ( )  |_ DISCLAIMER: You better like my opinions,
603-643-7727        |   U ACK!|            my mother can beat up your mother...

drc@dbase.UUCP (Dennis Cohen) (02/21/88)

In article <21013@bbn.COM>, franco@bbn.com (Frank A. Lonigro) writes:
> 
...
> 	I have this great book on programming the MAC in "C", "Using the
> Macintosh ToolBox with C".  It's a good book and I'm learning alot, but
> it doesn't explain how to code the most used aspect of the Mac desktop,
> namely, choosing an ICON and have it become its mask and then dragging it
> to another spot on the desktop(be it in a window or the desktop itself).
> I have this idea that I need to define a rectangle, stick the image of the
> ICON in it and then detect a mouseDown event and determine if the Event.where
> point is enclosed by that rectangle.  This is all well and good except
> how do you have it change to its mask?  I also could use OffsetRect() to
> move it, but there must be an easier way to find out the "dh, dv" parameters.
> Is there such a function called DragRect() synonymous to DragWindow()??
> 
> 	Any and all help you can give would be greatly appreciated.
> 
This isn't a code fragment, just some hints.  First of all, you should be
using a ICN# rather than an ICON, since an ICON doesn't have a mask, but the
mask for the icon in an ICN# is the second 128 bytes.  You should be creating
a 32x32 pixel rectangle into which you place the icon with a call to DrawIcon.
When you want the mask, get the mask from the ICN# and call DrawIcon again.
For dragging it, you can call DragGrayRgn which is what DragWindow and
DragControl call to move their outlines around.  When it finally gets to its
destination, redraw it in the new location and erase it from the old.  This
is all pretty easy once you've done it once or twice.


Dennis Cohen
Ashton-Tate Macintosh Division
dBASE Mac Development Team

neil@dsl.cis.upenn.edu (Neil Radisch) (03/04/88)

What's the cleanest way to drag an icon if you know its location and have
its bitmap. I tried to use Draggrayrgn() but I could not find a way to
incorporate the bit image of the icon into a region.

thanks


|----------------------------------------------------------------------------|
| "Better to remain quiet and be thought a fool than to speak out and remove |
|  all doubt" --- Abraham Lincoln                                            |
|                                                                            |
|  neil@dsl.cis.upenn.edu.UUCP                                               |
|----------------------------------------------------------------------------|