Albrecht Schlosser wrote:
> You may try to implement the (virtual) resize() method for a widget
> that lives in your scroll area, something like
I'll go into more detail of what I'm trying to accomplish.
I have a Fl_Canvas widget that inherits Fl_Scroll. The Fl_Canvas will only
contains Fl_Image_Box widgets. The Fl_Image_Box widget is simple a widget
that draws its image at its x() and y(). Like this:
void Fl_Image_Box::draw()
{
// draw the image (if necessary)
fl_push_clip(x(), y(), w(), h());
if(image())
image()->draw(x(), y());
fl_pop_clip();
}
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()
Currently, I implement the selection rectangle as a drawable element as in:
void Fl_Canvas::draw()
{
Fl_Touch_Scroll::draw();
recalc_dimensions(); // <-- this was missing before my OP
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.
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.
--
Alvin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk