home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / dflat.zip / RECT.C < prev    next >
Text File  |  1991-02-18  |  2KB  |  100 lines

  1. /* ------------- rect.c --------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. /*
  6.  * Produce the intersection of two vectors
  7.  */
  8. static void subVector(int *v1, int *v2, int t1, int t2, int o1, int o2)
  9. {
  10.     *v1 = *v2 = -1;
  11.     if (within(o1, t1, t2))    {
  12.         *v1 = o1;
  13.         if (within(o2, t1, t2))
  14.             *v2 = o2;
  15.         else
  16.             *v2 = t2;
  17.     }
  18.     else if (within(o2, t1, t2))    {
  19.         *v2 = o2;
  20.         if (within(o1, t1, t2))
  21.             *v1 = o1;
  22.         else
  23.             *v1 = t1;
  24.     }
  25.     else if (within(t1, o1, o2))    {
  26.         *v1 = t1;
  27.         if (within(t2, o1, o2))
  28.             *v2 = t2;
  29.         else
  30.             *v2 = t2;
  31.     }
  32.     else if (within(t2, o1, o2))    {
  33.         *v2 = t2;
  34.         if (within(t1, o1, o2))
  35.             *v1 = t1;
  36.         else
  37.             *v1 = o1;
  38.     }
  39. }
  40.  
  41. /*
  42.  * Return the rectangle that is the intersection of the two arguments
  43.  */
  44. RECT subRectangle(RECT r1, RECT r2)
  45. {
  46.     RECT r = {0,0,0,0};
  47.     subVector((int *) &RectLeft(r), (int *) &RectRight(r),
  48.             RectLeft(r1), RectRight(r1), RectLeft(r2), RectRight(r2));
  49.     subVector((int *) &RectTop(r), (int *) &RectBottom(r),
  50.             RectTop(r1), RectBottom(r1), RectTop(r2), RectBottom(r2));
  51.     if (RectRight(r) == -1 || RectTop(r) == -1)
  52.         RectRight(r) = RectLeft(r) = RectTop(r) = RectBottom(r) = 0;
  53.     return r;
  54. }
  55.  
  56. /*
  57.  * Assumes that r1 is a proper subset of r2
  58.  * Returns a rectangle that is the relative position of r1 within r2
  59.  */
  60. RECT RelativeRectangle(RECT r1, RECT r2)
  61. {
  62.     RECT rc;
  63.     RectLeft(rc) = RectLeft(r1) - RectLeft(r2);
  64.     RectTop(rc) = RectTop(r1) - RectTop(r2);
  65.     RectBottom(rc) = RectTop(rc) + RectHeight(r1) - 1;
  66.     RectRight(rc) = RectLeft(rc) + RectWidth(r1) - 1;
  67.     return rc;
  68. }
  69.  
  70. RECT ClientRect(void *wnd)
  71. {
  72.     RECT rc = ((WINDOW)wnd)->rc;
  73.     if (TestAttribute((WINDOW)wnd, HASBORDER))    {
  74.         RectLeft(rc)++;
  75.         RectRight(rc)--;
  76.     }
  77.     if (WindowHeight((WINDOW)wnd) > 1 && (GetClass((WINDOW)wnd) != EDITBOX ||
  78.             TestAttribute((WINDOW)wnd, MULTILINE)))    {
  79.         RectTop(rc)++;
  80.         RectBottom(rc)--;
  81.         if (TestAttribute((WINDOW)wnd, HASMENUBAR))
  82.             RectTop(rc)++;
  83.     }
  84.     return rc;
  85. }
  86.  
  87. /*
  88.  * Initialize a rectangle
  89.  */
  90. RECT SetRect(int lf, int tp, int rt, int bt)
  91. {
  92.     RECT rc;
  93.     rc.lf = lf;
  94.     rc.tp = tp;
  95.     rc.rt = rt;
  96.     rc.bt = bt;
  97.     return rc;
  98. }
  99.  
  100.