Ok - here's a crude worked example of what I was trying to describe.
Builds and runs just fine on this Mac. Should work anywhere but YMMV...
The do_anim() bit with the timer is just to simulate incoming data,
but it is just random dots at present. Your own input data would go
in there, obviously.
Check the code, see if it makes sense to you. Is that the sort of
thing you were trying to do?
/
************************************************************************
/
// compile as:
// fltk-config --compile laser-plot.cxx
//
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Button.H>
#include <Fl/fl_draw.H>
static Fl_Double_Window *main_win;
// defines for the image window sizes
#define WW 256 // width
#define HH 256 // height
#define DD 3 // depth
/
************************************************************************
/
class vw_box : public Fl_Box {
protected:
void draw(void);
int iw, ih, id;
uchar *data;
public:
vw_box(int X, int Y, int W, int H) : Fl_Box(X,Y,W,H) { data =
NULL;}
void set_data(uchar *newdat, int W, int H, int D);
};
/
************************************************************************
/
void vw_box::set_data(uchar *newdat, int W, int H, int D) {
iw = W; ih = H; id = D;
if (data) delete [] data;
data = newdat;
}
/
************************************************************************
/
void vw_box::draw(void) {
if (!data) return;
/* Ensure that the full window is redrawn */
fl_push_no_clip();
/* Redraw the whole image */
fl_draw_image((const uchar *)data, x(), y(), iw, ih, id);
fl_pop_clip();
}
/
************************************************************************
/
static vw_box *box_2; // image box
static uchar *da; // image array
/
************************************************************************
/
void quit_cb(Fl_Button *, void *)
{
main_win->hide();
}
/
************************************************************************
/
void do_anim(void *) {
static int iter = 20; // only refresh the display every so often...
// make up random x, y, range values to plot
float xf = (float)WW * rand() / (float)RAND_MAX;
float yf = (float)HH * rand() / (float)RAND_MAX;
// random cell colours
float rf = 255.0 * rand() / (float)RAND_MAX;
float gf = 255.0 * rand() / (float)RAND_MAX;
float bf = 255.0 * rand() / (float)RAND_MAX;
// cell x,y position as integers
int xo = (int)xf & (WW-1);
int yo = (int)yf & (HH-1);
// simulate colour settings
int rr = (int)rf & 0xFF; // R colour value 0 - 255
int gg = (int)gf & 0xFF; // G colour value 0 - 255
int bb = (int)bf & 0xFF; // B colour value 0 - 255
// now fill in the plot cells
int cell = (xo * WW * DD) + (yo * DD);
da[cell] = rr; // R
da[cell+1] = gg; // G
da[cell+2] = bb; // B
iter --;
if (iter <= 0) {
box_2->redraw(); // redisplay the data
iter = 100;
}
Fl::repeat_timeout(0.001, do_anim);
}
/
************************************************************************
/
int main(int argc, char **argv)
{
main_win = new Fl_Double_Window(WW + 100, HH + 20);
main_win->begin();
box_2 = new vw_box(10, 10, WW, HH);
Fl_Button *quit = new Fl_Button(WW + 20, 10, 60, 30);
quit->label("Quit");
quit->callback((Fl_Callback *)quit_cb);
main_win->end();
// make the range/colour mapping table
// something...
// make the data array
da = new uchar[WW * HH * DD];
int xo, yo, idx;
for(yo = 0; yo < HH; yo++) {
for(xo = 0; xo < WW; xo++) {
for(idx = 0; idx < 3; idx++) {
int cell = (xo * WW * DD) + (yo * DD) + idx;
da[cell] = (cell & 0xFF);
}
}
}
// set the data array as the box image
box_2->set_data(da, WW, HH, DD);
// initilaise the random sequence
srand(time(0));
// add some animation - simulate input data
Fl::add_timeout(0.01, do_anim);
// run the main loop
main_win->show(argc, argv);
return Fl::run();
}
/* End of File */
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk