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 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 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. 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 w := DisplayWidth@"b" / 2 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. |