home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - GDISPLAY.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_dsp.hpp"
-
- int UI_REGION_ELEMENT::Overlap(const UI_REGION &a_region)
- {
- return (Max(a_region.left, region.left) <= Min(a_region.right, region.right) &&
- Max(a_region.top, region.top) <= Min(a_region.bottom, region.bottom));
- }
-
- int UI_REGION_ELEMENT::Overlap(const UI_REGION &sRegion, UI_REGION &tRegion)
- {
- // Use a comparison formula to see if the regions overlap.
- tRegion.left = Max(region.left, sRegion.left);
- tRegion.top = Max(region.top, sRegion.top);
- tRegion.right = Min(region.right, sRegion.right);
- tRegion.bottom = Min(region.bottom, sRegion.bottom);
- if (tRegion.left > tRegion.right || tRegion.top > tRegion.bottom)
- return(FALSE);
-
- // Make sure the region is on the screen.
- if (tRegion.left < 0)
- tRegion.left = 0;
- if (tRegion.top < 0)
- tRegion.top = 0;
- return(TRUE);
- }
-
- void UI_REGION_LIST::Split(int screenID, const UI_REGION ®ion)
- {
- UI_REGION tRegion, sRegion;
- UI_REGION_ELEMENT *dRegion, *t_dRegion;
-
- // Split any overlapping regions.
- for (dRegion = First(); dRegion; dRegion = t_dRegion)
- {
- // Preset the previous region element.
- t_dRegion = dRegion->Next();
-
- // Object encompasses the whole region.
- if (dRegion->Encompassed(region))
- {
- UI_LIST::Subtract(dRegion);
- delete dRegion;
- }
-
- // Object overlaps the region.
- else if (dRegion->Overlap(region, tRegion))
- {
- screenID = dRegion->screenID;
- tRegion = dRegion->region;
- sRegion = region;
-
- // Region is split at a maximum shown by the following set
- // of regions:
- // ┌─────────┐ 1
- // ├──┬───┬──┤ 2,3,4
- // ├──┴───┴──┤ 5
- // └─────────┘
- //
-
- // Check for a top region (region 1 above).
- if (region.top > tRegion.top)
- UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
- tRegion.top, tRegion.right, region.top - 1));
- else
- sRegion.top = tRegion.top;
-
- // Check for a bottom region (region 5 above).
- if (region.bottom < tRegion.bottom)
- UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
- region.bottom + 1, tRegion.right, tRegion.bottom));
- else
- sRegion.bottom = tRegion.bottom;
-
- // Check for a left region (region 2 above).
- if (region.left > tRegion.left)
- UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, tRegion.left,
- sRegion.top, region.left - 1, sRegion.bottom));
-
- // Check for a right region (region 4 above).
- if (region.right < tRegion.right)
- UI_LIST::Add(0, new UI_REGION_ELEMENT(screenID, region.right + 1,
- sRegion.top, tRegion.right, sRegion.bottom));
-
- // Region 3 is the object's region.
- UI_LIST::Subtract(dRegion);
- delete dRegion;
- }
- }
- }
-
-
-