Alvin wrote:
>
> Now I am trying to implement a mouse selection tool. I thought about adding
> the selection capability in the Fl_Image_Box widget but I cannot determine
> how I can have the child (Fl_Image_Box) scroll the Fl_Canvas when the mouse
> is at the bounds of the Fl_Canvas's viewable area (the area minus the
> scrollbars (if they are visible that is)).
>
> So, what I have done is implement the mouse selection tool inside Fl_Canvas.
> This allows me to implement the auto scrolling (when the mouse reaches the
> bounds). To do this, my initial instinct was to implement the the selection
> code in Fl_Canvas::handle(). And update the viewable area when
> Fl_Canvas::resize() is called. The purpose of known the viewable area is so
> that the selection rectangle isn't drawn ontop of the scrollbars at to be
> able to automagically scroll as it is being define, resized and moved.
>
> The first thing that Fl_Canvas::resize() does is call Fl_Scroll::resize().
> Before I looked at the code for Fl_Scroll, I expected that the scrollbars
> would be updated (value, min and max bounds and visible) when
> Fl_Scroll::resize() returned. This is wrong.
> The only way to truly know the viewable area is after Fl_Scroll::draw() has
> been called. This is because Fl_Scroll manages its scrollbars in
> Fl_Scroll::draw()
Yes, that's bad behavior, IMHO.
> Currently, I implement the selection rectangle as a drawable element as in:
If it's for _drawing_ the selection area, then everything should be fine,
the draw() method would be the correct way to do it.
> void Fl_Canvas::draw()
> {
> Fl_Touch_Scroll::draw();
>
> recalc_dimensions(); // <-- this was missing before my OP
Here, you might have a look at Fl_Scroll::bbox() - a somewhat new
method, maybe not (yet) documented.
> if(do_selection)
> {
> fl_push_clip(vx, vy, vw, vh);
> {
> fl_line_style(FL_DASH | FL_JOIN_ROUND, 2);
>
> fl_rect(sx, sy, sw, sh, FL_RED);
>
> fl_line_style(FL_SOLID);
> }
> fl_pop_clip();
> }
> }
>
> As you can see, I have added a fix so that I recalculate the viewable area
> everytime Fl_Canvas::draw() is called. This seems to fix my problems.
Fine.
> However, that means that the only way for a derived class to know the
> viewable area as well as the true state the of scrollbars is to override
> the draw(). My initial instinct was to do all the calculations in handle()
> and simple leave draw() for rendering.
I think, you're right, IMHO Fl_Scroll should update the scrollbars in its
resize() method. Maybe an STR for the next release ?
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk