ste wrote:
> how to show text on an image .jpeg??..
> (click the button to show text over jpeg image)
The following works for sure; we make our own widget 'MyImage'
and handle the drawing ourself, so we control drawing the image,
then the text over it.
It's a little more code than the last example, but still pretty simple.
This is a bit more flexible too, cause you can completely control the
drawing of the widget, ie. you can draw graphics over the image as well.
In this case it's assumed /tmp/foo.jpg exists, and is an image
that is 640x480 or smaller.
Should build with 'fltk-config --use-images --compile test.cxx'
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/fl_draw.h>
class MyImage : public Fl_Widget { // Create a custom
widget
Fl_JPEG_Image *jpg; // will contain the
jpeg image
void draw() { // Take full control of
drawing our widget
fl_color(FL_RED); fl_rectf(x(),y(),w(),h()); // draw red filled
rectangle as background
jpg->draw(x(), y(), w(), h()); // draw image over
background
if ( label() ) { // any label assigned?
fl_font(labelfont(), labelsize()); // set font/size
fl_color(labelcolor()); // set color
fl_draw(label(), x(),y(),w(),h(), align()); // draw text over image
and background
}
}
public:
MyImage(int X,int Y,int W,int H) : Fl_Widget(X,Y,W,H) { // ctor
jpg = new Fl_JPEG_Image("/tmp/foo.jpg"); // load jpeg
image (change filename as needed)
}
};
// Globals
Fl_Window *win = 0;
Fl_Button *but = 0;
MyImage *img = 0;
void ButtonCallback(Fl_Widget*,void*) { // callback invoked
when button pressed
img->label("Your text goes here."); // label to show text
img->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); // label draws 'center'
and 'inside' the widget
img->labelcolor(FL_WHITE); // label color
img->labelsize(30); // label size
}
int main(int argc, char **argv) {
win = new Fl_Window(700, 600); // create window
img = new MyImage(10,10,640,480); // create our custom
widget
but = new Fl_Button(300,500,120,25,"Push"); // create 'Push' button
but->callback(ButtonCallback); // assign callback to
button
win->end();
win->show(argc,argv);
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk