Greg Ercolano wrote:
> This might be the fl_line_sytle(FL_SOLID, 2) call causing a
> floating point antialiased rectangle to be drawn, where the pixel
> centers might be off by 0.5 or something. Macs are pretty smart
> about antialiased lines and stuff.

        ..and by that I mean, might be a bug in fltk's handling
        of pixel positioning when the line style is changed,
        and not a bug in your app.

        However, one bug in your app: you're not leaving the line style
        at zero; see the docs on fl_line_style() for comments about this:
        http://fltk.org/documentation.php/doc-1.1/drawing.html#fl_line_style
        "If you change this it is your responsibility to set it back
        to the default with fl_line_style(0)."

        Fixing that probably does not change the problem though.
        Just something to keep in mind if you use line styles.


        Below is an interesting variation that just draws a black
        rectangle with a 2 pixel white border, but every second
        it alternates drawing the border:

                1) using fl_line_style(FL_SOLID,2) + fl_rect()

                2) using fl_line_style(FL_SOLID,0) + two fl_rect()s,
                   one single pixel rect inside the other.

        Theoretically, both should look the same (though I guess it depends
        which side of the dimensions the extra pixel thickness should go for
        a two pixel thick line), but on all platforms you can see there's
        flashing going on.

        On linux, with the line style set to 2, it looks like only the
        right and bottom edges are drawn with two pixel thickness,
        and the top and left edges are drawn with one.

        On windows, there's a pretty horrible thing going on at
        the lower right corner, apparently dropping pixels.

        So it seems like the only way to get pixel accurate
        results is to leave the line style alone, and draw two
        separate rectangles.

        Here's the program described above:

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Box.H>

class Foo: public Fl_Box {
    int count;
    void draw() {
        fl_color(FL_BLACK);
        fl_rectf(x(),y(),w(),h());
        fl_color(FL_WHITE);
        if ( count & 1 ) {
            // use 2 pixel thick lines
            fl_line_style(FL_SOLID, 1);
            fl_rect(x(),y(),w(),h());
            fl_line_style(FL_SOLID, 0);         // docs say we must leave it at 
zero
        } else {
            // use 1 pixel thick lines, but draw two rects, one inside the other
            fl_line_style(FL_SOLID, 0);
            fl_rect(x(),y(),w(),h());
            fl_rect(x()+1,y()+1,w()-2,h()-2);
        }
    }
    static void Count_CB(void *userdata) {
        Foo *o = (Foo*)userdata;
        o->count++;
        o->redraw();
        Fl::repeat_timeout(1.0, Count_CB, userdata);
    }
public:
    Foo(int X, int Y, int W, int H, const char *L = 0) : Fl_Box(X,Y,W,H,L) {
        count = 0;
        Fl::add_timeout(1.0, Count_CB, (void*)this);
    }
};

int main(int argc, char *argv[]) {
    Fl_Double_Window win(400, 240);
    Foo foo(10,10,400-20,240-20);
    win.show();
    return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to