Think of something that you wish Authorware could do but it doesn't?  Let the our good friends at Macromedia know via the wishlist.

Please let us know if you find any of the materials on this site inappropriate or offensive. Please include the url and why the material should be reviewed.

Comments and questions about the site are also welcome. Please no Authorware questions, use the AWARE list.

Back

B7005 - How are the Rect functions used?

by - Joseph Ganci


Can anyone explain to me how the various Rect functions that are in the List category work?  I am discussing Lists with the LA user group on Monday and I realize I'm not sure what those functions are used for.

Rect and Point can be used in a variety of ways, but probably the most common way is to check for checking if the cursor is in a certain area. This is useful when hot spots alone don't do the trick. In one recent application, we had to actually mimic hot spots without using hot spots, the explanation for which would take too long here. In that case, I used Rect to set up the various rectangles.

hotspot1 := rect(10, 100, 30, 130)

sets up a rectangular area with the coordinates specificied in the variable hotspot1. You can check to see if the cursor is in this area with a conditional interaction, using

PointInRect(hotspot1, point(cursorx, cursory))

The above expression will be TRUE if the cursor is within the window coordinates 10, 100, 30, 130. The point function is used to convert the cursorx and cursory variables into a point coordinate.

Note the warnings in the Rect function description about using it in older functions where you might think you could use it. The functions that work together are:

Point - creates a point from an x and a y coordinate
Rect - creates a rectangle from top, left, bottom, and right coordinates
PointinRect - determines if a point is inside a rect
InfateRect - lets you change the size of a rectangle according to an added width and height
Intersect - creates a new rectangle from the intersection of rectangle1 and rectangle2.
OffsetRect - creates a new, separate rectangle as an offset from another rectangle.
UnionRect - takes two rectangles and returns the smallest rectangle that encompasses the other two.

The above functions can also be used when calculating geometric formulae and such. They don't have to be used only for screen manipulation. Hope this helps.

Follow-Up:
Joe, thanks a lot,  I guess these very simple explanations are why your functions variables books were the greatest.  I understood the first parts, but got lost in the last 3

Intersect - creates a new rectangle from the intersection of rectangle1 and rectangle2.
OffsetRect - creates a new, separate rectangle as an offset from another rectangle.
UnionRect - takes two rectangles and returns the smallest rectangle that encompasses the other two.

Not a clue why, when or how you'd use these.  Also can you help me understand why are these included in the list category?  I think they would make more sense in the Graphic or Interaction category.  How does this relate to a list?

Also, both of us are working way too late on Authorware stuff.  Gotta get a life!

The functions you mention I'm sure could be used a variety of ways. One that springs to mind is when you have screen objects that could be animated around the screen. You wish to check for the presence of an object or the cursor within the borders defined by the intersection, the union, or the offset of those screen objects. You can then set up rectangles based on the displayx, displayy, displaywidth and displayheight variables.

Let's say you have two display icons, one called "a", the other called "b". Check the following code:

w := DisplayWidth@"a" / 2
h := DisplayHeight@"a" / 2
x := DisplayX@"a"
y := DisplayY@"a"
rect1 := Rect( x - w , y - h , x + w , y + h)

w := DisplayWidth@"b" / 2
h := DisplayHeight@"b" / 2
x := DisplayX@"b"
y := DisplayY@"b"
rect2 := Rect( x - w , y - h , x + w , y + h)

myrect := UnionRect(rect1, rect2)

If the boundary for display "a" is [198,164,283,226] and the boundary for display "b" is [330,175,415,237], then myrect will contain [198,164,415,237], the smallest rectangular area that will contain both. If we had used

myrect := Intersect(rect1, rect2)

then myrect would contain [330,175,283,226]. Notice the y values overlap and so only the portion that is common to both ends up in the resulting rectangle. The x values in each display do not overlap, so the area *between* the two rectangles is taken.

OffsetRect(rect1, 10, -100)

actually changes the value of rect1 to [208,64,293,126].

The reason they're in the list category is because they are actually lists. You can look at each coordinate as you would any ordinary list element.

a := rect1[1]

would set a to 208, for instance, after the above OffsetRect function were executed.

There are 0 reviews
Add your review
Back