> sorry, a line was copied to the wrong position - here's a 
> corrected version.

I think the problem is that you are always setting the damage, or
calling redraw(), from within the draw context.

That will not work reliably, since at the end of the draw context the
damage will be cleared - you can not safely assume that any *new* damage
that you set (e.g. by calling redraw or otherwise) will be recursively
processed within the draw sequence.

You probably need to set up a "deferred" damage context using a timeout
or similar to get the desired effect... Something like this might work:


/* nested scroll group redraw problem */

#include <stdio.h>
#include <string.h>

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

#define _menuFile (menu__menubar+0)

static int g_cnt = 0;
static int g_x = 0;
static int deferred_timeout_active = 0;

class Bar;

static Fl_Double_Window *_mainwin = NULL;
static Bar * _bar = NULL;
static int _colwidth = 100;

static void linedrawn( int x );
static void request_deffered_update(void);

////////////////////////////////////////////////////////////////////////
/

class status_box : public Fl_Box {
private:
        char _buf[12];
public:
    status_box( int X, int Y, int W, int H ) : Fl_Box( X, Y, W, H) {
        box( FL_DOWN_BOX );
    }

protected:
    void draw() {
        sprintf( _buf, "%d", g_x );
        Fl_Box::draw();
        fl_font(FL_TIMES, 14);
        fl_color( FL_BLACK );
        fl_draw( _buf, x()+10, y()+20 );
    }
};

static status_box *sb = 0;

////////////////////////////////////////////////////////////////////////
/

class Canvas : public Fl_Group {
public:
    Canvas( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H,
"canvas" ) {
        box(FL_FLAT_BOX);
        color( (Fl_Color)197 );
    }

protected:
    void draw() {
        //fprintf( stderr, "%d) Canvas::draw(): x=%d, y=%d\n", ++g_cnt,
x(), y() );fflush(stderr);
        Fl_Group::draw();
        drawLines();
    }
private:
    void drawLines() {
        int xx = x();
        int yy = y();
        int ww = w();
        int hh = h();

        int endY = yy + hh;
        fl_color( FL_BLACK );
        for( int dx = 0; dx <= ww; dx += _colwidth ) {
            int x = xx + dx;
            fl_line( x, yy, x, endY );
            linedrawn( x );
        }
    }
};

////////////////////////////////////////////////////////////////////////
/

class Scroll : public Fl_Scroll {
public:
    Scroll( int X, int Y, int W, int H ) : Fl_Scroll( X, Y, W, H,
"scroll" ) {
        box(FL_FLAT_BOX);
        color((Fl_Color)196);
        align(Fl_Align(FL_ALIGN_CENTER));
    }
protected:
    void draw() {
        //fprintf( stderr, "%d) Scroll::draw(): x=%d, y=%d\n", ++g_cnt,
x(), y() );fflush(stderr);
        Fl_Scroll::draw();
    }
};

////////////////////////////////////////////////////////////////////////
/

class Bar : public Fl_Box {
private:
        char _buf[12];
public:
    Bar( int X, int Y, int W, int H ) : Fl_Box( X, Y, W, H, "bar" ) {
        color( (Fl_Color)187 );
        box( FL_FLAT_BOX );
        _bar = this;
        _buf[0] = 0;
    }

    void drawLine( int x ) {
        //fprintf( stderr, "%d) Bar::drawLine(): x=%d\n", ++g_cnt, x
);fflush(stderr);
        sprintf( _buf, "%d", x );
        g_x = x;
        draw();
    }

protected:
    void draw() {
        //fprintf( stderr, "%d) Bar::draw()\n", ++g_cnt );
fflush(stderr);
        Fl_Box::draw();
        fl_font(FL_TIMES, 14);
        fl_color( FL_BLACK );
        fl_draw( _buf, 50, y()+20 );
        request_deffered_update();
    }
};

////////////////////////////////////////////////////////////////////////
/

class Group : public Fl_Group {
private:
    Bar * _pBar;
    Scroll * _pScroll;
    Canvas * _pCanvas;
public:
    Group( int X, int Y, int W, int H ) : Fl_Group( X, Y, W, H, "group"
) {
        align(Fl_Align(FL_ALIGN_CENTER));
        begin();
        _pBar = new Bar( X, Y, W, 40 );

        _pScroll = new Scroll( X, Y+50, W, H-50 );
        _pCanvas = new Canvas( X, Y+50, 800, 800 );
        _pCanvas->end();
        _pScroll->end();

        resizable( _pScroll );
        end();
    }

protected:
    void draw() {
        //fprintf( stderr, "%d) Group::draw()\n", ++g_cnt
);fflush(stderr);
        Fl_Group::draw();
    }
};

static void linedrawn( int x ) {
    _bar->drawLine( x );
}

/***** deferred update timeout callback ***********/
static void deferred_update(void*) {
    static int old_x = 0;
    if(old_x != g_x)
    {
        old_x = g_x;
        sb->redraw();
        _bar->redraw();
    }
    deferred_timeout_active = 0;
} // deferred_update

static void request_deffered_update(void) {
    if(!deferred_timeout_active) { // guard against multiple invocations
        deferred_timeout_active = -1;
        Fl::add_timeout(0.1, deferred_update);
    }
} // request_deffered_update

//----------------------------------------------------//

Fl_Menu_Bar *_menubar=(Fl_Menu_Bar *)0;

Fl_Menu_Item menu__menubar[] = {
 {"File", 0,  0, 0, 0, FL_NORMAL_LABEL, 0, 14, 0},
 {0,0,0,0,0,0,0,0,0}
};

//----------------------------------------------------//

int main(int argc, char **argv) {
    _mainwin = new Fl_Double_Window(500, 600);
    _mainwin->begin();
    sb = new status_box(50, 550, 80, 30);

    _menubar = new Fl_Menu_Bar(0, 0, 500, 20, "menubar");
    _menubar->menu(menu__menubar);

    Group * group = new Group(0, 20, 500, 380 );
    Fl_Group::current()->resizable( group );
    group->end();

    _mainwin->end();
    _mainwin->show(argc, argv);

    return Fl::run();
}

/* end of file */



SELEX Galileo Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 
3EL
A company registered in England & Wales.  Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

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

Reply via email to