diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-03-16 17:39:16 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-03-16 17:39:16 +0000 |
| commit | b6858cef5694f3c2aa9a9899d2516ef07ea7d85c (patch) | |
| tree | be2300053715979611f9289908b7d96b125738e6 /src/drivers/Android/Fl_Android_Graphics_Clipping.cxx | |
| parent | e0a15603dd92d4a6965a5ccc59f5485824f81038 (diff) | |
Android: added function to optimize complex regions
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12760 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Android/Fl_Android_Graphics_Clipping.cxx')
| -rw-r--r-- | src/drivers/Android/Fl_Android_Graphics_Clipping.cxx | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/drivers/Android/Fl_Android_Graphics_Clipping.cxx b/src/drivers/Android/Fl_Android_Graphics_Clipping.cxx index 000ef929f..022acea86 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Clipping.cxx +++ b/src/drivers/Android/Fl_Android_Graphics_Clipping.cxx @@ -168,6 +168,17 @@ int Fl_Rect_Region::intersect_with(const Fl_Rect_Region &r) } /** + * Use rectangle as a bounding box and add the outline of another rect. + */ +void Fl_Rect_Region::add_to_bbox(const Fl_Rect_Region &r) +{ + if (r.pLeft<pLeft) pLeft = r.pLeft; + if (r.pTop<pTop) pTop = r.pTop; + if (r.pRight>pRight) pRight = r.pRight; + if (r.pBottom>pBottom) pBottom = r.pBottom; +} + +/** * Print the coordinates of the rect to the log. * @param label some text that is logged with this message. */ @@ -237,8 +248,8 @@ void Fl_Complex_Region::print_data(int indent) const */ void Fl_Complex_Region::set(const Fl_Rect_Region &r) { - delete pSubregion; pSubregion = 0; Fl_Rect_Region::set(r); + delete pSubregion; pSubregion = 0; } /** @@ -307,10 +318,49 @@ int Fl_Complex_Region::subtract(const Fl_Rect_Region &r) pNext->subtract(r); } } + compress(); return 0; } /** + * Compress the subregion of this region if possible and update the bounding + * box of this region. + * + * Does not recurse down the tree! + */ +void Fl_Complex_Region::compress() +{ + // Can't compress anything that does not have a subregion + if (!pSubregion) return; + + // remove all empty regions, because the really don't add anything (literally) + Fl_Complex_Region *rgn = pSubregion, **rgnPtr = &pSubregion; + while (rgn) { + if (rgn->is_empty()) { + *rgnPtr = rgn->pNext; + delete rgn; + } + rgnPtr = &rgn->pNext; + rgn = *rgnPtr; + } + if (!pSubregion) return; + + // find rectangles that can be merged into a single new rectangle + + // if there is only a single subregion left, merge it into this region + if (pSubregion->pNext==nullptr) { + set((Fl_Rect_Region&)*pSubregion); // deletes subregion for us + } + if (!pSubregion) return; + + // finally, update the boudning box + Fl_Rect_Region::set((Fl_Rect_Region&)*pSubregion); + for (rgn=pSubregion->pNext; rgn; rgn=rgn->pNext) { + add_to_bbox(*rgn); + } +} + +/** * Subtract a rect from another rect, potentially creating four new rectangles. * This assumes that the calling region is NOT complex. * @param r subtract the area of this rectangle. |
