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

thanks & bye
testalucida


#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)

int g_cnt = 0;

class Bar;

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

void linedrawn( int x );

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

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() );
                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() );
                Fl_Scroll::draw();
        }
};

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

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

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

                damage( FL_DAMAGE_ALL );
                draw();
        }

protected:
        void draw() {
                fprintf( stderr, "%d) Bar::draw()\n", ++g_cnt );
                color( FL_BLACK );
                fl_draw( _buf, 50, y()+20 );
        }

};

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

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));

                _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 );

                Fl_Group::draw();
                _pBar->damage( FL_DAMAGE_ALL );
                _pBar->redraw();
        }
};

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

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


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, 400);
    { _menubar = new Fl_Menu_Bar(0, 0, 500, 20, "menubar");
      _menubar->menu(menu__menubar);
    } // Fl_Menu_Bar* _menubar
    { Group * group = new Group(0, 20, 500, 380 );
      Fl_Group::current()->resizable( group );
    } // Fl_Group* _group
    _mainwin->end();
  } // Fl_Double_Window* _mainwin
  _mainwin->show(argc, argv);
  return Fl::run();
}




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

Reply via email to