news
About Elegant Chaos
info
About me and my friends
people
Software from Elegant Chaos
software
Other stuff...
stuff

DragRgn

This XFCN allows you to drag gray regions around the screen. Neat features include the ability to define the region shape from a graphic on the card.

DragRgn XFCN. Version 2.2d2, by Sam Deane. Copyright ©1994 ULTRALAB. Compiled 14:37:10, 14/12/94. Debugging code included.


[last exit to hypercard] [externals index] [download DragRgn]

Description

This XFCN allows you to drag gray outlines around. This makes it easy to create "draggable" buttons, which behave a bit like Finder icons.

The XFCN returns a pair of numbers, which give the horizontal and vertical distances that the outline was dragged.

Optional Parameters

The optional <limit> and <slop> parameters allow you to constrain the dragging to a rectangular area. When the mouse is within the limit rectangle, the region's outline follows it normally. When the mouse is outside the limit rectangle but inside the slop rectangle, the region is "pinned" so that the point on the region that was clicked is kept within the limit rectangle. When the mouse is outside the slop rectangle, the outline dissapears. If the mouse button is relased when the outline has dissapeared, the XFCN will behave as though the outline had not been moved at all.

The <limit> and <slop> parameters can either be passed a rectangle, or as one of the pre-defined constants desktop (the default value) or card (which limits the dragging to the card window).

The optional <mode> parameter allows you to constrain the outline so that it only moves vertically, or only moves horizontally. A value of 1 constrains horizontally, a value of 2 vertically, and a value of 0 means no constraints.


Commands

rect

This command allows you to drag a rectangular outline.

The syntax is:

  get DragRgn("rect",<rect>,<click> {,<limit> {,<slop> {,<mode>}}})

The <rect> parameter gives starting position of the rectangle that you wish to drag around.

The <click> parameter defines the relative positions of the grey outline and the cursor whilst the outline is being dragged. Normally you should pass the clickLoc here.

See "Optional Parameters" for an explanation of the <limit>, <slop> and <mode> parameters.

Example script for rect

on mouseDown
  put the rect of me into path
  put the screenrect into limit
  put the clickLoc into click
  put 0 into mode
  
  if the shiftKey is down then
    wait until the mouseLoc ­ click
    if the mouseH <> item 1 of click then
      put 1 into mode
      
    else if the mouseV <> item 2 of click then
      put 2 into mode
    end if
  end if
  
  put DragRgn(rect,path,click,,,mode)
end mouseDown

region

This command allows you to drag round a shape made from an artibtrary path of lines. The syntax is:

  get DragRgn("region",<path>,<click> {,<limit> {,<slop> {,<mode>}}})

The <path> parameter gives a list of points in the form x1,y1,x2,y2,x3,y3,.... These points define a path, starting at the top left hand corner of the button and progressing from there to point 1, point 2, etc.

The <click> parameter defines the relative positions of the grey outline and the cursor whilst the outline is being dragged. Normally you should pass the clickLoc here.

See "Optional Parameters" for an explanation of the <limit>, <slop> and <mode> parameters.

Example script for region

on mouseDown
  put the left of me into item 1 of path
  put the top of me into item 2 of path
  put "0,30,60,30,30,-30,-30,-30" into item 3 of path
  
  put the screenrect into limit
  put the clickLoc into click
  put 0 into mode
  
  put DragRgn(region,path,click,limit,limit,mode)
end mouseDown

oval

This command allows you to drag round an oval outline. The syntax is:

  get DragRgn("oval",<rect>,<click> {,<limit> {,<slop> {,<mode>}}})

The <rect> parameter gives starting position of the outline that you wish to drag around.

The <click> parameter defines the relative positions of the grey outline and the cursor whilst the outline is being dragged. Normally you should pass the clickLoc here.

See "Optional Parameters" for an explanation of the <limit>, <slop> and <mode> parameters.

Example script for oval

on mouseDown
  put the rect of me into path
  put the screenrect into limit
  put the clickLoc into click
  
  put DragRgn(oval,path,click)
end mouseDown

roundrect

The commands allows you to drag an outline shaped like a rectangle with rounded corners. The syntax is:

get DragRgn("roundRect",<rect>,<click> {,<limit> {,<slop> {,<mode>}}})

The <rect> parameter gives starting position of the rectangle that you wish to drag around.

The <click> parameter defines the relative positions of the grey outline and the cursor whilst the outline is being dragged. Normally you should pass the clickLoc here.

See "Optional Parameters" for an explanation of the <limit>, <slop> and <mode> parameters.

Example script for roundrect

on mouseDown
  put "10,10," into path
  put the rect of me after path
  put the screenrect into limit
  put the clickLoc into click
  put 0 into mode
  
  if the shiftKey is down then
    wait until the mouseLoc ­ click
    if the mouseH <> item 1 of click then
      put 1 into mode
      
    else if the mouseV <> item 2 of click then
      put 2 into mode
    end if
  end if
  
  put DragRgn(roundrect,path,click,,,mode)
end mouseDown

bitmap

With this command, the exact shape of the region that you drag is determined by graphics on that region (try the example button below to see what I mean!).

The syntax is:

  get DragRgn("bitmap",<rect>,<click> {,<limit> {,<slop> {,<mode>}}})

The <rect> parameter gives starting position of the outline that you wish to drag around.

The <click> parameter defines the relative positions of the grey outline and the cursor whilst the outline is being dragged. Normally you should pass the clickLoc here.

See "Optional Parameters" for an explanation of the <limit>, <slop> and <mode> parameters.

Example script for bitmap

on mouseDown
  put the rect of me into path
  put the screenrect into limit
  put the clickLoc into click
  
  put DragRgn(bitmap,path,click)
end mouseDown

[last exit to hypercard] [externals index] [download DragRgn]

This page was created automatically, on 25/03/1999 from version 3.0d4 of Last Exit To Hypercard.