+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++;
+ }
+}
+