On 5 Jun 2009, at 13:09, Michel Schmid wrote:
> I want to show a image over another image (is this the correct way
> to describe this? sorry, but my mothertongue ist not english.. :-) )
> In other words, I have a image and its backgroud is also a image...
>
> The picture in front is a battery (which shows the battery-state of
> an embedded-system, so i need several pictures to show the various
> battery-states). In background there ist a bar which goes smoothly
> from black to grey... So it is a tedious to design those battery-
> pictures with a background that fits to its image behind...
Below is a very untidy (and poorly commented) example of some of the
things you are asking for - perhaps this will show you how to get
started?
Compile as:
fltk-config --use-images --compile alpha-test.cxx
Note that I tested this with fltk-1.3.x on a Mac, so whilst I expect
it to be OK on other platforms, YMMV!
Oh - Also, I posted this via gmail, which has a nasty habit of
munging my posts up, so here's hoping!
------------
// alpha blend image test
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <FL/Fl_RGB_Image.H>
#include <stdlib.h>
#include <stdio.h>
static int level = 0;
class ImageTest : public Fl_Box {
public:
static ImageTest *create() {
int x, y;
uchar *drgba = img_rgba = (uchar*)malloc(128*128*4);
for (y=0; y<128; y++) {
for (x=0; x<128; x++) {
*drgba++ = y<<1;
*drgba++ = x<<1;
*drgba++ = (127-x)<<1;
*drgba++ = x+y;
}
}
i_rgba = new Fl_RGB_Image (img_rgba,128,128,4);
return new ImageTest(8, 8, 240, 240);
}
static uchar *img_rgba;
static Fl_RGB_Image *i_rgba;
ImageTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
box(FL_BORDER_BOX);
}
void draw() {
char txt[64];
Fl_Box::draw(); // draw the base widget
int xx, yy;
xx = x()+10; yy = y()+10;
fl_color(FL_BLACK); fl_rectf(xx, yy, 130, 130);
fl_color(FL_WHITE); fl_rectf(xx, yy, 130, 130 - level);
// fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4);
i_rgba->draw(xx+1,yy+1);
// set font and draw some text
fl_font(FL_HELVETICA | FL_BOLD, 16);
sprintf(txt, "%3d", level);
fl_color(FL_WHITE); fl_draw(txt, xx+50, yy+64);
fl_color(FL_BLACK); fl_draw("Test Level", xx+134, yy+64);
}
};
uchar *ImageTest::img_rgba = 0;
Fl_RGB_Image *ImageTest::i_rgba = 0;
ImageTest *img = 0;
// do_anim code start
void do_anim(void *) {
static int dir = 2;
level += dir;
if(level < 0) {
level = 0; dir *= -1;
}
else if (level > 130) {
level = 130; dir *= -1;
}
img->redraw();
Fl::repeat_timeout(0.1, do_anim);
} // do_anim code end
int main (int argc, char**argv) {
Fl_Double_Window *main_win = new Fl_Double_Window(256, 256, "Test");
main_win->begin();
img = ImageTest::create();
main_win->end();
main_win->show(argc, argv);
// animate the scene
Fl::add_timeout(0.1, do_anim);
return Fl::run();
}
/* end of file */
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk