PTINRECT(3R)

NAME
ptinrect - check for Point inclusion in a Rectangle

SYNOPSIS
# include <dmd.h>

int ptinrect (p, r)
Point p;
Rectangle r;

DESCRIPTION
The ptinrect function returns 1 if p is a Point within Rectangle r ; and 0, otherwise.

EXAMPLE
The following routine will draw a box in the middle of a window. Then when button 1 is depressed within the box, the bell will ring. The routine returns when a key is typed.

    #include <dmd.h>
    Point add();
    Point sub();
    Point div();
    ringbox()
    {
       Point center, offset;
       Rectangle midbox;
       offset = div (sub (Drect.corner,
                    Drect.origin), 2);
       center = add (Drect.origin, offset);
       midbox.origin = sub (center, Pt (16, 16));
       midbox.corner = add (center, Pt (16, 16));
       box (&display, midbox, F_XOR);
       request (MOUSE|KBD);
       while (kbdchar () == -1){
       	wait (MOUSE);
       	if (ptinrect (mouse.xy, midbox) &&
                 button1()) ringbell();
       }
    }