Benjamin Stauffer wrote:
> What I really need is a scrollable area (my_canvas right now) where I can 
> draw lines and bitmaps, so I guess my first question is, am I moving in the 
> right direction as I have it structured now?

        I've put a working example here:
        http://seriss.com/people/erco/fltk/#FltkScrollingCanvas

> My second question is, what do I need to do so that while I'm
> scrolling, the lines on my_canvas get redrawn properly and don't get messed 
> up?

        There's nothing you should have to do specially; fltk handles
        calling your draw() code whenever the scroll bars are moved,
        or the window/scroller size is changed.

        Just be sure to reference all your drawing to the x() and y()
        positions of your widget, because the Fl_Scroll changes those
        values when the scrollers are moved.

        So just draw the line work on the full area of your canvas,
        and the scroller will just show the part that fits in its
        viewable area. FLTK's clipping will handle the rest.

> I know I need to implement my own draw()

        Yes.

> and handle() functions

        The handle() function shouldn't be needed just to make
        a scrollable canvas.

        The only reason for a handle() method is if you want to
        react to raw FLTK events like keyboard/mouse and things
        like focus changes, mouse in/out events, etc.

        Redrawing is automatic, and you can depend on the default
        behavior of FLTK to handle e.g. window resizing. For instance,
        in the above 'cheat page' example, the window is resizable.

>     void draw()
>     {
>       fl_rectf(0, 0, w(), h(), 0, 0, 128);
>       draw_grids();
>     }

        I didn't try your program, but I'm guessing the problem
        is in all your coordinates assuming fixed values (eg.
        your fl_rectf() assuming x=0 and y=0)

        Because your widget is inside Fl_Scroll, it will change
        the widget's x() and y() values to effectively 'pan' around
        your widget. So if you don't use those values in your draw()
        routine, you'll be drawing in the wrong place when the scroll
        bars are changed.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to