home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / REGION.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  2.8 KB  |  96 lines

  1. //    Zinc Interface Library - GDISPLAY.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #include "ui_dsp.hpp"
  6.  
  7. int UI_REGION_ELEMENT::Overlap(const UI_REGION &a_region)
  8. {
  9.     return (Max(a_region.left, region.left) <= Min(a_region.right, region.right) &&
  10.         Max(a_region.top, region.top) <= Min(a_region.bottom, region.bottom));
  11. }
  12.  
  13. int UI_REGION_ELEMENT::Overlap(const UI_REGION &sRegion, UI_REGION &tRegion)
  14. {
  15.     // Use a comparison formula to see if the regions overlap.
  16.     tRegion.left = Max(region.left, sRegion.left);
  17.     tRegion.top = Max(region.top, sRegion.top);
  18.     tRegion.right = Min(region.right, sRegion.right);
  19.     tRegion.bottom = Min(region.bottom, sRegion.bottom);
  20.     if (tRegion.left > tRegion.right || tRegion.top > tRegion.bottom)
  21.         return(FALSE);
  22.  
  23.     // Make sure the region is on the screen.
  24.     if (tRegion.left < 0)
  25.         tRegion.left = 0;
  26.     if (tRegion.top < 0)
  27.         tRegion.top = 0;
  28.     return(TRUE);
  29. }
  30.  
  31. void UI_REGION_LIST::Split(int screenID, const UI_REGION ®ion)
  32. {
  33.     UI_REGION tRegion, sRegion;
  34.     UI_REGION_ELEMENT *dRegion, *t_dRegion;
  35.  
  36.     // Split any overlapping regions.
  37.     for (dRegion = First(); dRegion; dRegion = t_dRegion)
  38.     {
  39.         // Preset the previous region element.
  40.         t_dRegion = dRegion->Next();
  41.  
  42.         // Object encompasses the whole region.
  43.         if (dRegion->Encompassed(region))
  44.         {
  45.             UI_LIST::Subtract(dRegion);
  46.             delete dRegion;
  47.         }
  48.  
  49.         // Object overlaps the region.
  50.         else if (dRegion->Overlap(region, tRegion))
  51.         {
  52.             screenID = dRegion->screenID;
  53.             tRegion = dRegion->region;
  54.             sRegion = region;
  55.  
  56.             // Region is split at a maximum shown by the following set
  57.             // of regions:
  58.             //        ┌─────────┐        1
  59.              //        ├──┬───┬──┤        2,3,4
  60.              //        ├──┴───┴──┤        5
  61.              //        └─────────┘
  62.              //
  63.  
  64.             // Check for a top region (region 1 above).
  65.             if (region.top > tRegion.top)
  66.                 UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
  67.                     tRegion.top, tRegion.right, region.top - 1));
  68.             else
  69.                 sRegion.top = tRegion.top;
  70.  
  71.             // Check for a bottom region (region 5 above).
  72.             if (region.bottom < tRegion.bottom)
  73.                 UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
  74.                     region.bottom + 1, tRegion.right, tRegion.bottom));
  75.             else
  76.                 sRegion.bottom = tRegion.bottom;
  77.  
  78.             // Check for a left region (region 2 above).
  79.             if (region.left > tRegion.left)
  80.                 UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
  81.                     sRegion.top, region.left - 1, sRegion.bottom));
  82.  
  83.             // Check for a right region (region 4 above).
  84.             if (region.right < tRegion.right)
  85.                 UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, region.right + 1,
  86.                     sRegion.top, tRegion.right, sRegion.bottom));
  87.  
  88.             // Region 3 is the object's region.
  89.             UI_LIST::Subtract(dRegion);
  90.             delete dRegion;
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96.