> OK, I'm hearing 'derive your own custom widget starting with Fl_Box.
> Sounds reasonable to me... can someone point me to a tutorial
> on custom widget construction? And/or examples thereof? Thanks again!
Here's a very rough cut at the basic drawing required - you can of
course make this much nicer and fancier, and add the appropriate get/set
methods for defining upper/lower bounds and values...
// bar-graph-demo.cxx
// fltk-config --compile bar-graph-demo.cxx
//
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <stdio.h>
static int bar_val = 0;
class bar_graph: public Fl_Box
{
void draw();
public:
bar_graph(int x, int y,int w,int h, const char *l=0) : Fl_Box
(x,y,w,h,l) {}
};
void bar_graph::draw()
{
int wd = w(); int ht = h();
int xo = x(); int yo = y();
fl_color(FL_BLACK);
fl_push_clip(xo, yo, wd, ht);
fl_rectf(xo, yo, wd, ht);
fl_color(FL_BLUE);
int bw = (wd * bar_val) / 100;
fl_rectf(xo, yo, bw, ht);
char lbl[8];
snprintf(lbl, 8, "%d", bar_val);
fl_color(FL_WHITE);
fl_draw(lbl, (xo + wd/2), (yo + ht/2));
fl_pop_clip();
} /* end of draw() method */
static bar_graph *bar1 = 0;
void update_bar1(void *)
{
static int bar_step = 1;
bar_val += bar_step;
if(bar_val > 99)
bar_step = -1;
if(bar_val < 1)
bar_step = +1;
Fl::repeat_timeout(0.05, update_bar1);
bar1->redraw();
}
int main(int argc, char **argv)
{
Fl_Double_Window *main_win = new Fl_Double_Window(400, 210, "Bar
Test Window");
main_win->begin();
bar1 = new bar_graph(20, 20, 360, 50);
main_win->end();
main_win->show(argc, argv);
Fl::add_timeout(0.1, update_bar1);
return Fl::run();
}
/* end of file */
--
Ian
SELEX Sensors and Airborne Systems Limited
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