pushparaj muthu wrote:
> for(int i=1;i <=3 ; i++)
> {
> fd = open(name[i], O_RDONLY) ;
> retval = read(fd, buff, sizeof(buff));
> selbox[i]->redraw();
> }
Hmm, you appear to be loading the contents of each file
into 'buff', overwriting its contents for each call, instead
of keeping separate buff's for each image, and leaving them
allocated and filled for the duration of the app.
You really need separate buff's for each image, and those
buffers need to remain allocated for the duration of your
program so that whenever Fl::run() calls Select::draw(),
it knows which image to draw.
(Also, you should be calling close(fd) within your loop
after the read(), so that the fd's don't remain open)
Note that calling redraw() does NOT call Select::draw().
redraw() just sets a 'damage' flag for the widget, and
the drawing calls are actually called later by the
Fl::run() loop, to ensure proper order of widget drawing
and screen updating when windows are obscured.
Keep in mind that while your app runs, Fl::run() may call
your Select::draw() functions many times, ie. when other
windows obscure your window, or when your window is stowed
then revealed again. Select::draw() will be called to
refresh the window each time, so the buff for each image
needs to have contents at all times while the widget is open.
So the buffers for each image must remain in memory.
To keep in the spirit of the techniques you're trying to
use, I'd recommend the following modifications, where
you add a char buff[] to your Select class (so that each
instance of the class has a private copy of it), and
your Select::draw() function references that, then you
fill those buff's separately, eg:
class Select : public Fl_Box
{
public:
char buff[WHATEVER]; // ADD THIS (or better yet, dynamically allocate
it..)
[..]
};
int main(..)
{
[..]
for(int i=1;i <=3 ; i++)
{
int fd = open(name[i], O_RDONLY) ;
if ( fd < 0 ) { perror(name[i]); exit(1); }
if ( read(fd, &(selbox[i]->buff), sizeof(buff)) != sizeof(buff) )
{ perror("read() failed"); exit(1); }
close(fd);
selbox[i]->redraw();
}
[..]
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk