From 514782864ed7680901e7bd7a4b8044fc887c71b9 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Fri, 23 Mar 2018 21:41:36 +0000 Subject: [PATCH] Android: Posting well behaved pie drawing method. Needs refactoring. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12787 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- .../app/src/main/cpp/HelloAndroid.cxx | 80 +++++- .../Android/Fl_Android_Graphics_Driver.cxx | 235 +++++++++++++++--- 2 files changed, 276 insertions(+), 39 deletions(-) diff --git a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx index d68dcd4e2..c8abb1512 100644 --- a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx +++ b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx @@ -15,6 +15,79 @@ * */ +#if 0 + + +#include +#include +#include +#include +#include + +class MyBox : public Fl_Box +{ +public: + MyBox(int x, int y, int w, int h) : + Fl_Box(x, y, w, h) + { + box(FL_DOWN_BOX); + } + void draw() + { + Fl_Box::draw(); + fl_color(FL_BLUE); + fl_pie(x()+20, y()+20, w()-40, h()-40, a1, a2); + } + double a1 = 0.0; + double a2 = 240.0; +}; + +Fl_Window *win; +MyBox *box = 0L; +char s1Label[80] = { 0 }; +char s2Label[80] = { 0 }; + +int main(int argc, char **argv) +{ + win = new Fl_Window(0, 0, 600, 800); + + box = new MyBox(10, 10, 580, 580); + + auto s1 = new Fl_Hor_Slider(210, 600, 380, 45, s1Label); + s1->range(-360, 360); + s1->value(0.0); + s1->labelsize(35); + s1->align(FL_ALIGN_LEFT); + s1->increment(1, 0); + s1->callback( + [](Fl_Widget *w, void*) { + auto s = (Fl_Slider*)w; + box->a1 = s->value(); + sprintf(s1Label, "%g", s->value()); + win->redraw(); + } + ); + + auto s2 = new Fl_Hor_Slider(210, 660, 380, 45, s2Label); + s2->range(-360, 360); + s2->value(240.0); + s2->labelsize(35); + s2->align(FL_ALIGN_LEFT); + s2->callback( + [](Fl_Widget *w, void*) { + auto s = (Fl_Slider*)w; + box->a2 = s->value(); + sprintf(s2Label, "%g", s->value()); + win->redraw(); + } + ); + + win->show(argc, argv); + Fl::run(); + return 0; +} + +#elif 1 #include #include @@ -182,8 +255,7 @@ int main(int argc, char ** argv) { - -#if 0 +#else #include #include @@ -310,6 +382,8 @@ int xmain(int argc, char **argv) * drawing call must scale at some point (line width!) * rotating the screen must call the app handler and(?) window resize * proportions: pixels should be square + Need Work: + - Fl_Android_Graphics_Driver::pie(int) needs refactoring test/CubeMain.cxx test/line_style.cxx test/CubeView.cxx test/list_visuals.cxx @@ -320,7 +394,7 @@ test/animated.cxx test/menubar.cxx test/ask.cxx test/minimum.cxx test/bitmap.cxx test/native-filechooser.cxx test/blocks.cxx test/navigation.cxx - * test/boxtype.cxx : !! testing + * test/boxtype.cxx : !! 'boxtype': must fix diamond box, plastic up frame, see fourth column test/offscreen.cxx test/browser.cxx test/output.cxx test/button.cxx test/overlay.cxx diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx index 26a3aa5bd..9d8242958 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx @@ -623,54 +623,217 @@ void Fl_Android_Graphics_Driver::arc_unscaled(float xi, float yi, float w, float */ void Fl_Android_Graphics_Driver::pie_unscaled(float xi, float yi, float w, float h, double b1, double b2) { -// Fl_Android_Application::log_e("------ PIE: %g %g (%g, %g)", b1, b2, b1-90, b2-90); -// Fl_Color c = fl_color(); -// fl_color(FL_YELLOW); - - if (b1>=b2) return; - - double rx = w/2.0; - double ry = h/2.0; + // quick access to bounding box size + double rx = w / 2.0; + double ry = h / 2.0; double x = xi + rx; double y = yi + ry; -// double a1 = b1/180*M_PI; -// double a2 = b2/180*M_PI; -// double incr = (a2-a1)/20; -// for (int i=0; i<20; i++) { -// double dx = cos(a1), dy = -sin(a1); -// line_unscaled(x+rx*dx, y+ry*dy, x+2*rx*dx, y+2*ry*dy); -// a1 += incr; -// } -// -// fl_color(FL_RED); - double at1 = (b1-90)/180*M_PI; // radians, 0 is top, CCW - double at2 = (b2-90)/180*M_PI; // radians, 0 is top, CCW - if (at2<0) { at1+=2*M_PI; at2+=2*M_PI; } - if (at2>2*M_PI) { at1-=2*M_PI; at2-=2*M_PI; } + double a1 = b1 / 180 * M_PI; + double a2 = b2 / 180 * M_PI; - for (double iy=y-ry; iy<=y+ry; iy++) { - double a = acos((iy-y)/ry); - double aL = M_PI-a; // 0..PI - double aR = a+M_PI; // 2PI..PI -// Fl_Android_Application::log_e("%g %g (%g) - %g %g", aL, aR, aR-2*M_PI, at1, at2); + // invert to make b1 always the smaller value + if (b1 > b2) { + b1 -= 360.0; + } + if (b1 == b2) return; - if ( ((at1<0) && ((at1<=aL-2*M_PI) && (at2>aL-2*M_PI) || (at1<=aL) && (at2>aL))) - || ((at1>=0) && (at1<=aL) && (at2>aL))) - xyline_unscaled(x-sin(aL)*rx, iy, x); + // make the top the zero degree origin, turning CCW + b1 -= 90.0; + b2 -= 90.0; - if ( ((at1<0) && ((at1<=aR-2*M_PI) && (at2>aR-2*M_PI) || (at1<=aR) && (at2>aR))) - || ((at1>=0) && (at1<=aR) && (at2>aR))) - xyline_unscaled(x, iy, x-sin(aR)*rx); + // find the delta between angles + double delta = b2 - b1; + if (delta >= 360.0) { + b1 = 0.0; + b2 = 360.0; + delta = 360.0; } + // make sure that b2 is always in the range [0.0..360.0] + if (b2 > 360.0) b2 -= 360.0; // FIXME: fmod(...) + if (b2 < 0.0) b2 += 360.0; + b1 = b2 - delta; + // now b1 is [-360...360] and b2 is [0..360] and b1= 0 && b1 < 90) { + loInside = true; + loLeft = -sinALrx; + loRight = a1Slope * (iy - y); + } + if (b2 >= 0 && b2 < 90) { + hiInside = true; + if (aL < a2) + hiLeft = -sinALrx; + else + hiLeft = a2Slope * (iy - y); + } + if (loInside && hiInside && !flipped) { +// fl_color(FL_GREEN); + if (a1 < aL) + xyline_unscaled(x + hiLeft, iy, x + loRight); + } else { + if ((!loInside) && (!hiInside)) { +// fl_color(FL_MAGENTA); + if ( (b1o<=0.0 && b2>=90.0) || (b1o<=(0.0-360.0) && b2>=(90.0-360.0)) ) + xyline_unscaled(x - sinALrx, iy, x); + } else { + if (loInside) { +// fl_color(FL_BLUE); + if (a1 < aL) + xyline_unscaled(x + loLeft, iy, x + loRight); + } + if (hiInside) { +// fl_color(FL_YELLOW); + xyline_unscaled(x + hiLeft, iy, x); + } + } + } + } else { + // rasterize bottom left quadrant + bool loInside = false, hiInside = false; + double loLeft = 0.0, loRight = 0.0; + double hiLeft = 0.0, hiRight = 0.0; + if (b1 >= 90 && b1 < 180) { + loInside = true; + if (aL>=a1) + loLeft = -sinALrx; + else + loLeft = a1Slope * (iy - y); + } + if (b2 >= 90 && b2 < 180) { + hiInside = true; + hiLeft = -sinALrx; + hiRight = a2Slope * (iy - y); + } + if (loInside && hiInside && !flipped) { +// fl_color(FL_GREEN); + if (a2 > aL) + xyline_unscaled(x + loLeft, iy, x + hiRight); + } else { + if ((!loInside) && (!hiInside)) { +// fl_color(FL_MAGENTA); + if ( (b1o<=90.0 && b2>=180.0) || (b1o<=(90.0-360.0) && b2>=(180.0-360.0)) ) + xyline_unscaled(x - sinALrx, iy, x); + } else { + if (loInside) { +// fl_color(FL_BLUE); + xyline_unscaled(x + loLeft, iy, x); + } + if (hiInside) { +// fl_color(FL_YELLOW); + if (a2 > aL) + xyline_unscaled(x + hiLeft, iy, x + hiRight); + } + } + } + } + if (aR<1.5*M_PI) { + // rasterize bottom right quadrant + bool loInside = false, hiInside = false; + double loLeft = 0.0, loRight = 0.0; + double hiLeft = 0.0, hiRight = 0.0; + if (b1 >= 180 && b1 < 270) { + loInside = true; + loLeft = sinALrx; + loRight = a1Slope * (iy - y); + } + if (b2 >= 180 && b2 < 270) { + hiInside = true; + if (aR < a2) + hiLeft = sinALrx; + else + hiLeft = a2Slope * (iy - y); + } + if (loInside && hiInside && !flipped) { +// fl_color(FL_GREEN); + if (a1 < aR) + xyline_unscaled(x + hiLeft, iy, x + loRight); + } else { + if ((!loInside) && (!hiInside)) { +// fl_color(FL_MAGENTA); + if ( (b1o<=180.0 && b2>=270.0) || (b1o<=(180.0-360.0) && b2>=(270.0-360.0)) ) + xyline_unscaled(x + sinALrx, iy, x); + } else { + if (loInside) { +// fl_color(FL_BLUE); + if (a1 < aR) + xyline_unscaled(x + loLeft, iy, x + loRight); + } + if (hiInside) { +// fl_color(FL_YELLOW); + xyline_unscaled(x + hiLeft, iy, x); + } + } + } + } else { + // rasterize top right quadrant + bool loInside = false, hiInside = false; + double loLeft = 0.0, loRight = 0.0; + double hiLeft = 0.0, hiRight = 0.0; + if (b1 >= 270 && b1 < 360) { + loInside = true; + if (aR>=a1) + loLeft = sinALrx; + else + loLeft = a1Slope * (iy - y); + } + if (b2 >= 270 && b2 < 360) { + hiInside = true; + hiLeft = sinALrx; + hiRight = a2Slope * (iy - y); + } + if (loInside && hiInside && !flipped) { +// fl_color(FL_GREEN); + if (a2 > aR) + xyline_unscaled(x + loLeft, iy, x + hiRight); + } else { + if ((!loInside) && (!hiInside)) { +// fl_color(FL_MAGENTA); + if ( (b1o<=270.0 && b2>=360.0) || (b1o<=(270.0-360.0) && b2>=(360.0-360.0)) ) + xyline_unscaled(x + sinALrx, iy, x); + } else { + if (loInside) { +// fl_color(FL_BLUE); + xyline_unscaled(x + loLeft, iy, x); + } + if (hiInside) { +// fl_color(FL_YELLOW); + if (a2 > aR) + xyline_unscaled(x + hiLeft, iy, x + hiRight); + } + } + } + } + } } - - #if 0 // Code used to switch output to an off-screen window. See macros in