[comp.sys.mac.programmer] How can I ensure a Rect is visible on screen?

np@doc.ic.ac.uk (Nigel Perry) (11/14/90)

I'm centering dialogs over windows (from an XCMD in HC 2). My current
strategy is to first centre the dialog Rect over the window and
then check that the Rect is not outside the RgnBBox of the grayRgn -
this copes with the window I'm centering over being part of the screen.
This works fine for a single screen, but it is possible for
a multi-screen setup to have a rectangular hole WITHIN the
RgnBBox (i.e. the area above/below a small screen when paired with
a large one). Is there a method for ensuring a Rect is within
a region and if not moving it so that it is?

Thanks in advance


---
Nigel Perry                                  Department of Computing
                                             Imperial College
Janet: np@uk.ac.ic.doc                       London
ARPA:  np%uk.ac.ic.doc@ucl-cs                SW7
Uucp:  np@icdoc.UUCP, ukc!icdoc!np           England

dorner@pequod.cso.uiuc.edu (Steve Dorner) (11/15/90)

In article <2472@gould.doc.ic.ac.uk> np@doc.ic.ac.uk (Nigel Perry) writes:
>a large one). Is there a method for ensuring a Rect is within
>a region

RectInRgn will tell you if part of the rectangle is in the region.
Once you know that, use RectRgn to make a region of the rectangle.
SectRgn this with the region you're interested in.  Use EqualRgn
to see if the intersection is the same as the rectangle's region.

>and if not moving it so that it is?

Now there's an interesting problem.

I'm not convinced that centering a dialog on a window is a good idea if
it results in the dialog being split over multiple screens, but you probably
aren't interested in my opinion.
--
Steve Dorner, U of Illinois Computing Services Office
Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner