## foxgui-users

 Re: [Foxgui-users] FOX contributions: "gauge" widget From: Daniel Stine - 2008-04-18 18:48:08 ```Stephen, I agree with Georg that AA will make the arbitrarily slanted lines smoother and scale down better. As a side effect it will also make them a little thicker overall so you may not be able to fit as many minor divisions into the scale. As you guessed antialiasing is simple to implement in OpenGL because it's built into the library. However, OpenGL would make your widget much heavier than required. Since I do most of my FOX development on Windows I've been through the M/S help documents extensively. The Windows GDI library does not have built-in support for AA that I have found. It's not that hard to find line antialiasing code in various places online and roll your own function. Here's a function that I've used. I lifted it from either Paul Bourke, Anti-Grain Geometry, or Dr. Kotowski http://www.mini.pw.edu.pl/~kotowski/Grafika/RasterDrawing/Index.html, I can't remember, but it's not entirely my own work. This is the Gupta-Sproull algorithm. The other one to search for is called Bresenham. Regards, Dan // // Gupta-Sproull antialias // #define SWAP(Aa,Bb) { n = Aa; Aa = Bb; Bb = n; } void antialias(FXDCWindow *dcp, FXint x1, FXint y1, FXint x2, FXint y2, PixFunc_f pfunc) { FXint n; FXint u,u1,u2; FXint v,v1,v2; FXbool transpose = (abs(y2 - y1) > abs(x2 - x1)); if (transpose) { u1 = y1; u2 = y2; v1 = x1; v2 = x2; } else { u1 = x1; u2 = x2; v1 = y1; v2 = y2; } if (u1 > u2) { SWAP(u1, u2) SWAP(v1, v2) } FXint du = u2 - u1; FXint dv = abs(v2 - v1); FXint incrE = 2*dv; FXint incrNE = 2*(dv - du); FXint error = 2*dv - du; FXint vstep = (v1 < v2) ? 1 : -1; FXint numer = 0; // numerator, v=0 for start pixel FXdouble denom = 2.0*sqrt((FXdouble)du*du + dv*dv); // precomputed denominator FXdouble two_du_over_denom = 2*du/denom; // precomputed constant v = v1; for (u=u1; u<=u2; u++) { color_pixel(dcp, u,v, fabs(numer/denom), pfunc, transpose); for (n=1; color_pixel(dcp, u, v - vstep*n, fabs(n*two_du_over_denom + numer/denom), pfunc, transpose); n++); for (n=1; color_pixel(dcp, u, v + vstep*n, fabs(n*two_du_over_denom - numer/denom), pfunc, transpose); n++); if (error > 0) { numer = error - du; error += incrNE; v += vstep; } else { numer = error + du; error += incrE; } } return; } FXbool color_pixel(FXDCWindow *dcp, FXint u, FXint v, FXdouble distance, PixFunc_f pfunc, FXbool reflect) { FXdouble factor; if (distance < lineWidth/2.0) { factor = 1.0 - 2.0*distance/lineWidth; (this->*pfunc)(dcp, u,v, factor*255, reflect); return true; } return false; } > If anyone knows of a cheesy trick that might work for FXGauge then I'm > all ears... ```
 Re: [Foxgui-users] FOX contributions: "gauge" widget From: Daniel Stine - 2008-04-21 11:04:55 ```Stephen, The PixFunc is just a class member function that I was using to render each pixel of the AA line. I was passing different functions to render the line at the normal scale and also a magnified version so I could see the details. It can be a simple as a dc.setForeground() followed by a dc.drawPoint(x,y) call. I completely agree that we like FOX's blazing speed so rendering the entire scale antialiased may not be appropriate for your design goals. Maybe to split the difference between speed and visual quality I'd render a nice AA backing image of the correct size at SEL_CONFIGURE time, draw the entire background and pointer at SEL_PAINT time, and quickly move the pointer(s) for each update by erasing the previous one using dc.drawArea() to draw the smaller background rectangle over the pointer then rendering it AA at the new position. You've already suggested something along this line. This technique may still flash annoyingly depending on the update rate. The other way to to double buffer the complete gauge image. ie. draw the background and new pointer in another offscreen image and keep overlaying that one in the visible drawable. Just offering some different design options... Cheers, Dan > at), but what is the PixFunc_f function supposed to do? ```
 Re: [Foxgui-users] FOX contributions: "gauge" widget From: Hardy, Stephen - 2008-04-18 19:41:12 ```Dan, forgive me if it's in the reference (which I haven't had time to look at), but what is the PixFunc_f function supposed to do? Maybe AA would not be *too* CPU-intensive for this simple widget, but realistically I think it would require a backing image for the "scale", which would then be practically constant unless resized. Only the pointers would need to be alpha-blended using some client-side tricks like your code shows. Another cheesy trick would be to render into a client-side image of 2 or 3 times the required size in both directions, then average (or maybe convolve) into a smaller image. This would be more like OpenGL style texture mapping, but much simpler of course. Regards, SJH PS: This is all very well, but actually the thing I like about FOX is the blazing speed, and I don't want to give that up lightly just because the widgets are a bit ugly. A lot of the stuff I do really benefits from having the CPU mostly available for the app logic and hardly bothered by the user interface. > -----Original Message----- > From: foxgui-users-bounces@... [mailto:foxgui-users- > bounces@...] On Behalf Of Daniel Stine > Sent: Friday, April 18, 2008 11:48 AM > To: foxgui-users@... > Subject: Re: [Foxgui-users] FOX contributions: "gauge" widget > > Stephen, > > I agree with Georg that AA will make the arbitrarily slanted lines > smoother and scale down better. As a side effect it will also make > them a little thicker overall so you may not be able to fit as many > minor divisions into the scale. > > As you guessed antialiasing is simple to implement in OpenGL because > it's built into the library. However, OpenGL would make your widget > much heavier than required. > > Since I do most of my FOX development on Windows I've been through the > M/S help documents extensively. > The Windows GDI library does not have built-in support for AA that I > have found. It's not that hard to find line antialiasing code in > various places online and roll your own function. > > Here's a function that I've used. I lifted it from either Paul > Bourke, Anti-Grain Geometry, or Dr. Kotowski > http://www.mini.pw.edu.pl/~kotowski/Grafika/RasterDrawing/Index.html, > I can't remember, but it's not entirely my own work. > > This is the Gupta-Sproull algorithm. The other one to search for is > called Bresenham. > > Regards, > Dan > > > // > // Gupta-Sproull antialias > // > #define SWAP(Aa,Bb) { n = Aa; Aa = Bb; Bb = n; } > void antialias(FXDCWindow *dcp, FXint x1, FXint y1, FXint x2, FXint > y2, PixFunc_f pfunc) > { > FXint n; > FXint u,u1,u2; > FXint v,v1,v2; > FXbool transpose = (abs(y2 - y1) > abs(x2 - x1)); > if (transpose) { > u1 = y1; u2 = y2; > v1 = x1; v2 = x2; > } > else { > u1 = x1; u2 = x2; > v1 = y1; v2 = y2; > } > if (u1 > u2) { > SWAP(u1, u2) > SWAP(v1, v2) > } > FXint du = u2 - u1; > FXint dv = abs(v2 - v1); > FXint incrE = 2*dv; > FXint incrNE = 2*(dv - du); > FXint error = 2*dv - du; > FXint vstep = (v1 < v2) ? 1 : -1; > > FXint numer = 0; // numerator, v=0 for start pixel > FXdouble denom = 2.0*sqrt((FXdouble)du*du + dv*dv); // precomputed > denominator > FXdouble two_du_over_denom = 2*du/denom; // precomputed constant > > v = v1; > for (u=u1; u<=u2; u++) { > color_pixel(dcp, u,v, fabs(numer/denom), pfunc, transpose); > for (n=1; color_pixel(dcp, u, v - vstep*n, fabs(n*two_du_over_denom + > numer/denom), pfunc, transpose); n++); > for (n=1; color_pixel(dcp, u, v + vstep*n, fabs(n*two_du_over_denom - > numer/denom), pfunc, transpose); n++); > if (error > 0) { > numer = error - du; > error += incrNE; > v += vstep; > } > else { > numer = error + du; > error += incrE; > } > } > > return; > } > > > FXbool color_pixel(FXDCWindow *dcp, FXint u, FXint v, FXdouble > distance, PixFunc_f pfunc, FXbool reflect) > { > FXdouble factor; > > if (distance < lineWidth/2.0) { > factor = 1.0 - 2.0*distance/lineWidth; > (this->*pfunc)(dcp, u,v, factor*255, reflect); > return true; > } > > return false; > } > > > > > If anyone knows of a cheesy trick that might work for FXGauge then > I'm > > all ears... > > ----------------------------------------------------------------------- > -- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save \$100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/ > javaone > _______________________________________________ > Foxgui-users mailing list > Foxgui-users@... > https://lists.sourceforge.net/lists/listinfo/foxgui-users ```