On 06/10/11 11:04, Greg Ercolano wrote:
>> However, most write-your-own-widget examples put the widget in (0,0)
>> of the top window,
> [..]
>       This distinction of widgets vs. windows should certainly be
>       pointed out in the "drawing" section of the docs, and this
>       section referenced from other parts of the docs where we talk
>       about deriving custom widgets.
> 
>       If I can, I'll see if I can add that.

   I've submitted STR#2662 to schedule this be updated in the docs:
   http://fltk.org/str.php?L2662

   BTW, you can derive widgets from Fl_Window if you want your
   coordinate space to be relative to 0,0.

   Fl_Windows can be children of windows, just like an Fl_Group,
   and unless I'm forgetting something (I don't usually use this
   technique myself), you can probably get what you want this way
   if you prefer your widget to work relative to 0,0.

   I recall there once was a time putting windows in windows
   didn't work well.. I think this was fixed in recent versions,
   but I can't remember the details.

   Here's a small example I just whipped up in 1.3.x which
   shows deriving a custom window class, and using it to create
   a window, and a window-in-a-window.

   It's draw() method prints the x() and y() values for the window,
   which shows the x() y() value for the actual window to be the
   window's position on the desktop, and the x()/y() values for
   the window-in-a-window to be its position on the parent window.


#include <FL/Fl.H>
#include <FL/Fl_Window.H>
// Demonstrate a window's x()/y() values in draw() of a window vs. a 
window-in-a-window -erco 6/10/11
class MyWindow : public Fl_Window {
public:
    MyWindow(int X, int Y, const char*L=0) : Fl_Window(X,Y,L) { }
    MyWindow(int X, int Y, int W, int H, const char*L=0) : Fl_Window(X,Y,W,H,L) 
{ }
    void draw() {
        Fl_Window::draw();
        printf("[%s] MyWindow::draw(): x/y = %d/%d\n",          // show 
window's x()/y() values at draw() time
            label(), x(), y());
    }
};
int main(int argc, char **argv) {
    MyWindow win(300, 300, "MAINWIN");                          // make a main 
window
        MyWindow subwin(50,50,300-100,300-100, "SUB-WIN");      // make a 
window inside the main window at 50,50
        subwin.color(FL_RED);                                   // (make it red 
so we can see it)
    win.end();
    win.resizable(win);
    win.show(argc,argv);
    return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to