On 07.12.2012 12:42, zfrdh wrote:
> I try to get a group inside a scroll and inside the group I have for smaller 
> groups. All have their own drawing routines.
>
> If I resize the outer window and scroll, the drawing is totally corrupted, a 
> lot of pixels are missing.
>
> Can someone explain how to handle scroll/draw in a correct way?

Yes, I can. Now, after a little testing, I found out that my
previous posting was not complete. Setting a boxtype in Fl_Scroll
is recommended anyway, but it's not necessary to "repair" your
program. See the full source code with comments:

#include <iostream>
using namespace std;

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl.H>
#include <FL/Fl_Scroll.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Menu_Bar.H>

static const unsigned int MENU_HEIGHT= 25;

class MyBox: public Fl_Group
{
     private:
         string name;

     public:
         MyBox( int x, int y, int w, int h, string _name):
             Fl_Group( x,y,w,h ),
             name(_name)
     { end();           // end group *added*

/* you derived class MyBox from Fl_Group, but didn't  end() the
group(s) below in your code. I did it here in the c'tor, but
that's probably not what you want in a regular program.
*/
       box(FL_FLAT_BOX); // set background *added*
/* boxtype not absolutely necessary, but better for testing.
Consider using FL_UP_BOX or FL_DOWN_BOX to see the boundaries.
*/
     }


         void draw()
         {
             cout << "Draw name " << name << endl;
             cout << "Position " << x() << " " << y() << endl;
             cout << "Size " << w() << " " << h() << endl;

             Fl_Group::draw(); // draw group/background !
/* You must (better: *should*) draw the parent, i.e. the background
and box *before* your other contents, otherwise it will be hidden.
*/

             fl_color(fl_rgb_color(0,0,0));
             fl_line(x()   ,y(), x()+w(), y()+h() );
             fl_line(x()   ,y()+h(), x()+w(), y() );

             // Fl_Group::draw(); // moved before line drawing
/* see above */
             cout << "End draw" << endl;
         }

         void resize(int x, int y, int w, int h)
         {
             cout << "resize called for " << name << "  " << x << " " << 
y << " " << w << " " << h << endl;
             Fl_Group::resize(x,y,w,h);
         }
};

void Do(Fl_Widget*, void* obj) {  } // dummy only

int main()
{
     Fl_Double_Window win(400,400, "Test1");
     Fl_Menu_Bar menubar(0,0, 400, MENU_HEIGHT);
     Fl_Scroll scroll(0,MENU_HEIGHT,400,400-MENU_HEIGHT);
     menubar.add( "Hallo",0, Do,(void*)&win);

     MyBox box(0, MENU_HEIGHT, 400, 400-MENU_HEIGHT, "master");
     MyBox littleBox00( 0, MENU_HEIGHT, 50,50, "sub00");
     MyBox littleBox01( 0, MENU_HEIGHT+50, 50,50, "sub01");
     MyBox littleBox10( 50, MENU_HEIGHT, 50,50, "sub10");
     MyBox littleBox11( 50, MENU_HEIGHT+50, 50,50, "sub11");

     scroll.end();
     win.end();

     win.resizable(box);
     win.show();
     return Fl::run();
}
/* end of code */

IMHO it's questionable if you really wanted to derive class MyBox
from Fl_Group, maybe you wanted Fl_Box. However, if Fl_Group was
intended, you MUST end() the group in your code, usually after
adding other widgets. I did it in the c'tor, because it was easier
in this special case (no children).

WRT drawing the parent, in your case Fl_Group: it depends on the
contents and boxtype, whether it is necessary to draw it (at all)
or the drawing order. Usually you will call the parent's draw
method before adding more (own) contents, but again YMMV.

HTH

-- 

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

Reply via email to