#include #include #include void Normalize(Rect *p) { ShortInt t; if (p->bottom < p-> top) { t = p->top; p->top = p->bottom; p->bottom = t; } if (p->left > p-> right) { t = p->left; p->left = p->right; p->right = t; } } /* Renvoie un point r tel que p,r definissent un carre */ Point NormCarre(Point p,Point q) { Point r; int cote; if (abs(q.h-p.h) > abs(q.v-p.v)) { cote = abs(q.h-p.h); r.h = q.h; if (q.v > p.v) { r.v = p.v+cote; } else { r.v = p.v - cote; } } else { cote = abs(q.v-p.v); r.v = q.v; if (q.h > p.h) { r.h = p.h+cote; } else { r.h = p.h - cote; } } return r; } void main(void) { Rect r; Point p,q,qq; InitQuickDraw(); PenSize(2,2); for (;;) { WaitClickDown(); GetMouse(&p); SetRect(&r,p.h,p.v,p.h,p.v); PenMode(patXor); PenPat(gray); do { GetMouse(&q); q = NormCarre(p,q); SetRect(&r,p.h,p.v,q.h,q.v); Normalize(&r); FrameRect(&r); do { GetMouse(&qq); qq = NormCarre(p,qq); } while (qq.h == q.h && qq.v == q.v && Button()); FrameRect(&r); } while (Button()); PenMode(patCopy); PenPat(black); FrameRect(&r); } }