]> Shamusworld >> Repos - apple2/blobdiff - src/gui/element.cpp
Undoing changes (accidentally) committed from r31.
[apple2] / src / gui / element.cpp
index dc73bb9fd33e6592b349eef82fac9add22b52c1a..bbaff3cc757598c1e826b7c1387013b16667a1c0 100755 (executable)
@@ -15,6 +15,7 @@
 //
 
 #include "element.h"
+#include "guimisc.h"                                                           // Various support functions
 
 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
 #define MASK_R 0xFF000000
@@ -46,6 +47,7 @@ Element::Element(uint32 x/*= 0*/, uint32 y/*= 0*/, uint32 w/*= 0*/, uint32 h/*=
        extents.y = y,
        extents.w = w,
        extents.h = h;
+       coverList.push_back(extents);
 }
 
 Element::Element(uint32 x, uint32 y, uint32 w, uint32 h,
@@ -57,6 +59,7 @@ Element::Element(uint32 x, uint32 y, uint32 w, uint32 h,
        extents.y = y,
        extents.w = w,
        extents.h = h;
+       coverList.push_back(extents);
 
        // This *should* allow us to store our colors in an endian safe way... :-/
        uint8 * c = (uint8 *)&fgColor;
@@ -81,7 +84,7 @@ bool Element::Inside(uint32 x, uint32 y)
                && y >= (uint32)extents.y && y < (uint32)(extents.y + extents.h) ? true : false);
 }
 
-//Badly named--!!! FIX !!!
+//Badly named--!!! FIX !!! [DONE]
 //SDL_Rect Element::GetParentCorner(void)
 SDL_Rect Element::GetScreenCoords(void)
 {
@@ -102,7 +105,7 @@ SDL_Rect Element::GetScreenCoords(void)
        return rect;
 }
 
-#if 0
+#if 1
 //May use this in the future...
 SDL_Rect Element::GetParentRect(void)
 {
@@ -124,6 +127,11 @@ SDL_Rect Element::GetParentRect(void)
 }
 #endif
 
+SDL_Rect Element::GetExtents(void)
+{
+       return extents;
+}
+
 void Element::CreateBackstore(void)
 {
        backstore = SDL_CreateRGBSurface(SDL_SWSURFACE, extents.w, extents.h, 32,
@@ -140,6 +148,145 @@ void Element::RestoreScreenFromBackstore(void)
        SDL_BlitSurface(backstore, NULL, screen, &r);
 }
 
+void Element::SaveScreenToBackstore(void)
+{
+       SDL_BlitSurface(screen, &extents, backstore, NULL);
+}
+
+void Element::ResetCoverageList(void)
+{
+       // Setup our coverage list with the entire window area
+       coverList.empty();
+       coverList.push_back(extents);
+}
+
+void Element::AdjustCoverageList(SDL_Rect r)
+{
+//Prolly should have a bool here to set whether or not to do this crap, since it
+//takes a little time...
+
+       // Here's where we do the coverage list voodoo... :-)
+
+/*
+Steps:
+  o Check for intersection. If no intersection, then no need to divide rects.
+  o Loop through current rects. If rect is completely inside passed in rect, remove from list.
+  o Loop through remaining rects. If rect intersects, decompose to four rects and
+    exclude degenerate rects, push rest into the coverage list.
+
+*/
+//     std::list<Element *>::reverse_iterator ri;
+//     std::list<SDL_Rect>::iterator i;
+
+       // Loop through rects and remove those completely covered by passed in rect.
+/*     for(i=coverList.begin(); i!=coverList.end(); i++)
+       {
+//             if (RectanglesIntersect(r, *i))
+               if (RectangleFirstInsideSecond(*i, r))
+               {
+//This is not right--do a while loop instead of a for loop?
+                       // Remove it from the list...
+                       std::list<SDL_Rect>::iterator next = coverList.erase(i);
+               }
+       }
+*/
+       // Loop through rects and remove those completely covered by passed in rect.
+       std::list<SDL_Rect>::iterator i = coverList.begin();
+
+       while (i != coverList.end())
+       {
+               if (RectangleFirstInsideSecond(*i, r))
+                       i = coverList.erase(i);                         // This will also advance i to the next item!
+               else
+                       i++;
+       }
+
+//This may not be needed if nothing follows the loop below...!
+//     if (coverList.empty())
+//             return;
+
+       // Check for intersection. If no intersection, then no need to divide rects.
+       i = coverList.begin();
+
+       while (i != coverList.end())
+       {
+               if (RectanglesIntersect(r, *i))
+               {
+                       // Do the decomposition here. There will always be at least *one* rectangle
+                       // generated by this algorithm, so we know we're OK in removing the original
+                       // from the list. The general pattern looks like this:
+                       //
+                       // +------+
+                       // |1     |
+                       // +-+--+-+
+                       // |2|//|3|  <- Rectangle "r" is in the center
+                       // +-+--+-+
+                       // |4     |
+                       // +------+
+                       //
+                       // Even if r extends beyond the bounds of the rectangle under consideration,
+                       // that's OK because we test to see that the rectangle isn't degenerate
+                       // before adding it to the list.
+
+//Should probably use a separate list here and splice it in when we're done here...
+//Or, could use push_front() to avoid the problem... Neat! Doesn't require a separate list!
+//But, we need to remove the currently referenced rect... Another while loop!
+
+//This approach won't work--if no rect1 then we're screwed! [FIXED]
+//Now *that* will work...
+                       SDL_Rect current = *i;
+                       uint32 bottomOfRect1 = current.y;
+//                     uint32 rightOfRect2 = current.x;
+//                     uint32 leftOfRect3 = current.x + current.w;
+                       uint32 topOfRect4 = current.y + current.h;
+
+                       // Rectangle #1 (top)
+                       if (r.y > current.y)                            // Simple rectangle degeneracy test...
+                       {
+                               bottomOfRect1 = r.y;
+                               SDL_Rect rect = current;
+                               rect.h = r.y - current.y;
+                               coverList.push_front(rect);
+                       }
+
+                       // Rectangle #4 (bottom)
+                       if (r.y + r.h < current.y + current.h)
+                       {
+                               topOfRect4 = r.y + r.h;
+                               SDL_Rect rect = current;
+                               rect.y = r.y + r.h;
+                               rect.h = (current.y + current.h) - (r.y + r.h);
+                               coverList.push_front(rect);
+                       }
+
+                       // Rectangle #2 (left side)
+                       if (r.x > current.x)
+                       {
+                               SDL_Rect rect = current;
+                               rect.w = r.x - current.x;
+                               rect.y = bottomOfRect1;
+                               rect.h = topOfRect4 - bottomOfRect1;
+                               coverList.push_front(rect);
+                       }
+
+                       // Rectangle #3 (right side)
+                       if (r.x + r.w < current.x + current.w)
+                       {
+                               SDL_Rect rect;
+                               rect.x = r.x + r.w;
+                               rect.w = (current.x + current.w) - (r.x + r.w);
+                               rect.y = bottomOfRect1;
+                               rect.h = topOfRect4 - bottomOfRect1;
+                               coverList.push_front(rect);
+                       }
+
+                       i = coverList.erase(i);                         // This will also advance i to the next item!
+               }
+               else
+                       i++;
+       }
+}
+
 //
 // Class methods
 //