Here's a crude demo.
Not quite what the OP wanted, as I am not setting a static image for the
button. Instead, I am animating a bar-graph on the button, then writing
some text over the top of that.
Think it should give enough ideas for a proper implementation of the
OP's query, though!
Beware the mail system munging up my lines, as per usual...
----------------------
// bar-graph-button.cxx
// fltk-config --compile bar-graph-button.cxx
//
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <FL/fl_draw.H>
#include <stdio.h>
static int bar_val = 0;
class bar_graph: public Fl_Button {
void draw();
public:
bar_graph(int x, int y,int w,int h, const char *l=0) : Fl_Button
(x,y,w,h,l) {}
};
void bar_graph::draw() {
Fl_Button::draw();
int wd = w() - 12; int ht = h() - 12;
int xo = x() + 6; int yo = y() + 6;
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_font(FL_HELVETICA, 18);
fl_draw(lbl, (xo + wd/2), (yo + 5 + 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();
}
static void cb_button(Fl_Widget*, void*) {
puts("Hello!"); fflush(stdout);
}
static Fl_Double_Window *main_win;
static void cb_quit(Fl_Widget*, void*) {
main_win->hide();
}
int main(int argc, char **argv) {
main_win = new Fl_Double_Window(400, 210, "Bar Test Window");
main_win->begin();
bar1 = new bar_graph(20, 20, 360, 50);
bar1->callback(cb_button);
Fl_Button *quit_b = new Fl_Button(320, 90, 60, 50, "Quit");
quit_b->callback(cb_quit);
main_win->end();
main_win->show(argc, argv);
Fl::add_timeout(0.1, update_bar1);
return Fl::run();
}
/* end of file */
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