Thanks Albrecht for your very detailed explanation and thanks everybody for 
answering.
Calling init_sizes() resolved the problem. The other issues in the code were 
due it was just a draft to expose the resizing problem.

David

> David Lopez wrote:
> > Hi, I'm sorry to disturb you with a so basic question.
>
> This is not a basic question. Understanding FLTK's resizing strategies is not
> trivial.
>
> > The posted source code implements a rough button moving by drag and drop in 
> > a resizable window.
> > If I move the button and then I maximize or resize the window, the buttton 
> > is moved and scaled as expected.
> > But if I first maximize the window and and then I move the button and after 
> > that I restore the window size, the button appears on its original location.
>
> This is not the whole story. Just for understanding what happens, try this 
> after
> you start the program:
>
>   (1) drag the button (optional, try with and without)
>   (2) resize the window only by a small amount
>   (3) drag the button (again)
>   (4) now maximize the window.
>
> Do you see the difference? The button should jump back to the (relative)
> position after the _first_ window resize.
>
> > What am I missing? How can I preserve the changes done during the maximized 
> > state?
>
> As Ian suspected in his reply, you need init_sizes() to *save* the positions 
> of
> your widgets internally after moving them. This can be done in the FL_RELEASE
> case, see below.
>
>  From the docs 
> <http://www.fltk.org/doc-1.1/Fl_Group.html#Fl_Group.init_sizes>:
>
> The Fl_Group widget keeps track of the original widget sizes and positions 
> when
> resizing occurs [...]. If you rearrange the widgets in your group, call this
> method to register the new arrangement with the Fl_Group that contains them.
>
> >             case FL_DRAG:
> >                     drag = 1;
> >                     fl_cursor (FL_CURSOR_MOVE);
>
> Try adding position() and redraw() here too to see the effect *while* 
> dragging.
>
> >                     break;
> >             case FL_RELEASE:
> >                     if (drag) //It's the end of a dragging
> >                             {
> >                   fl_cursor (FL_CURSOR_DEFAULT);
> >                             position (x() + Fl::event_x(), y() + 
> > Fl::event_y()); //Move object
>
> you'd better use:
>                       position (Fl::event_x(), Fl::event_y()); //Move object
>
> And add this here:
>                       parent()->init_sizes(); // *save* positions and sizes
>
> >                             drag = 0;
> >                             this->parent()->redraw ();
> >                             }
> >                     break;
>
> After you've fixed this: your dragging is "suboptimal" (there's always a jump 
> of
> the widget such that the top left corner is at the cursor position). The next
> step would be to make it smooth by saving coordinates and using relative 
> (delta
> x, delta y) movement, but this is just another story.
>
> And, btw, your handle() always returns 1, which is probably not what you would
> want in a real application, and it doesn't call the base class handle() 
> method.
> You should read the docs about event handling in the subclassing chapter, 
> there
> is also a good example how to do it the right way.
>
> http://www.fltk.org/doc-1.1/subclassing.html#handle
>
> If you do it this way, you'll probably see that you must also return 1 on
> FL_PUSH events and maybe some more to make it work again.
>
> HTH
>
> Albrecht

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

Reply via email to