From 6a145ed63aa48944b8dced0d5a6fbcaffda507e7 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 15 Mar 2018 21:17:16 +0000 Subject: Android: window clipping working fl_rectf. This code is not very beautiful, but the resulting class should be easy to use. A range-based loop can be used to find all relevant clipping rectangles for a drawing call. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12754 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/Android/Fl_Android_Graphics_Driver.cxx | 73 +++++++++++----------- 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'src/drivers/Android/Fl_Android_Graphics_Driver.cxx') diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx index 554d72e84..aa2bcd937 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx @@ -97,15 +97,46 @@ static uint16_t make565(Fl_Color crgba) void Fl_Android_Graphics_Driver::rectf_unscaled(float x, float y, float w, float h) { - // FIXME: r must be a complex region, like pClippingRegion. +#if 1 Fl_Rect_Region r(x, y, w, h); -#if 0 - if (r.intersect_with(pClippingRegion)) { - rectf_unclipped(r.x(), r.y(), r.w(), r.h()); + for (const auto &it: pClippingRegion.overlapping(r)) { +#if 1 + Fl_Rect_Region s(it->clipped_rect()); + rectf_unclipped(s.x(), s.y(), s.w(), s.h()); +#else + if (it->is_simple()) { + Fl_Rect_Region r(x, y, w, h); + if (r.intersect_with(*it)) { + rectf_unclipped(r.x(), r.y(), r.w(), r.h()); + } + } +#endif + } + +#elif 0 + + // This is elegant code, but it is not efficient. It walks the entire tree + // and checks for intersetion, even if the parent region indicated that there + // is no intersection. + // + // Maybe we can add a parameter somewhere so that the iterator runs the tree + // based on a give rectangle. + + for (const auto &it: pClippingRegion) { + // TODO: if region is complex, but doesn't intersect, can we somehow manipulate the iterator? + if (it->is_simple()) { + Fl_Rect_Region r(x, y, w, h); + if (r.intersect_with(*it)) { + rectf_unclipped(r.x(), r.y(), r.w(), r.h()); + } + } } -#else // proof of concept - // FIXME: write iterator over tree + +#else + + // This code is massiv and ugly and has the same problem in that it does not + // optimize the number of tests for intersections. r.print("---- fl_rectf"); pClippingRegion.print("clip to"); @@ -134,36 +165,8 @@ void Fl_Android_Graphics_Driver::rectf_unscaled(float x, float y, float w, float } } } -#endif - - - - - // TODO: create a complex region by intersecting r with the pClippingRegion - // TODO: walk the region and draw all rectangles - - /* - * rectf(x, y, w, h) { - * rectf(complex_window_region, drawing_rect(x, y, w, h)) - * } - * - * rectf( complexRgn, drawRgn) { - * // B: start of iterator - * if (intersect(rect_of_complexRgn, drawRgn) { - * if (complexRgn->is_complex() { - * rectf(complexRgn->subregion, drawRect); - * } else { - * rawRect = intersection(rect_of_complexRgn, drawRgn); - * rawDrawRect(rawRect); - * } - * } - * // A: recursion - * if (complexRgn->next) - * rectf(complexRgn->next, drawRgn); - * // B: end of iterator - * } - */ +#endif } void Fl_Android_Graphics_Driver::rectf_unclipped(float x, float y, float w, float h) -- cgit v1.2.3