Hi, I'm sorry to disturb you with a so basic question.
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.
What am I missing? How can I preserve the changes done during the maximized 
state?

Thanks in advance,
David


#include <stdlib.h>
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/fl_draw.H>

class MyButton: public Fl_Button
        {
        public:
                MyButton (int x, int y, int w, int h) : Fl_Button (x,y,w,h) {};
                virtual int handle (int evt);
        };

int MyButton::handle (int evt)
        {
        static int drag = 0;

   switch (evt)
                {
                case FL_ENTER:
                        fl_cursor (FL_CURSOR_HAND);
                        break;
                case FL_LEAVE:
              fl_cursor (FL_CURSOR_DEFAULT);
                        break;
                case FL_DRAG:
                        drag = 1;
                        fl_cursor (FL_CURSOR_MOVE);
                        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
                                drag = 0;
                                this->parent()->redraw ();
                                }
                        break;
        }
        return 1;
        };

int main(int argc, char **argv) {
  Fl_Window *window = new Fl_Window(0,0, 400,400);
  MyButton *david = new MyButton(10,0,100,40);
  window->resizable(window);
  window->end ();
  window->show(argc, argv);
  return Fl::run();
}



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

Reply via email to