#include #include #include #include #include // // Show how to make a scrollable table of thumbnail images - erco 10/10/06 // #define THUMB_IMAGE_W 50 // thumb image width #define THUMB_IMAGE_H 50 // thumb image height #define THUMB_IMAGE_MARGIN 5 // margin around image #define THUMB_LABEL_SIZE 12 // label size in pixels // EXAMPLE 50x50 XPM IMAGE static char *cartman_xpm[] = { "50 50 9 1", " c None", ". c #0000FF", "+ c #EAFF86", "@ c #71A6CB", "# c #FFEAEA", "$ c #000000", "% c #B14E50", "& c #FFFFFF", "* c #FF9797", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".....................++++++++.....................", "...................++++++++++++...................", "..................++++++++++++++..................", "................@@++@@++++++@@++@@................", "..............@@@@@@@@@@@@@@@@@@@@@@..............", "............@@@@@@@@@@@@@@@@@@@@@@@@@@............", "...........@@@@@@@@@@@@@@@@@@@@@@@@@@@@...........", "..........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..........", "........@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@........", ".......@@@@@@++++++++++++++++++++++++@@@@@@.......", "......@@@++++++++++++++++++++++++++++++++@@@......", "......++++++++######################++++++++......", "......++++++++######################++++++++......", "......++++######$$$$$########$$$$$######++++......", "......##########$$#$$########$$#$$##########......", "......##########$###$########$###$##########......", "......#########$#####$######$#####$#########......", ".....%#########$#####$######$#####$#########%.....", "..%%%%######################################%%%%..", "%%%%%%######################################%%%%%%", "%%%%%%######################################%%%%%%", "%%%%%%%####################################%%%%%%%", "%%%%%%%########$$$$$$$$$$$$$$$$$$$$########%%%%%%%", "%%%%%%%#########$$&&&&&&&&&&&&&&$$#########%%%%%%%", "%%%%%%%%#########$$&&&&&&&&&&&&$$#########%%%%%%%%", "%%%%%%%%%%########$************$########%%%%%%%%%%", "%%%%%%%%%%%########************########%%%%%%%%%%%", "%%%%%%%%%%%%%#######**********#######%%%%%%%%%%%%%", "%%%%%%%%%%%%%%########******########%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%########**########%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%########%%%%%%%%%%%%%%%%%%%%%", "%%%$%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%$%%%", "%%$%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%$%%", "%$%%%%%%%%%%%%%%%%%%%%%%$%$%%%%%%%%%%%%%%%%%%%%%$%", "$%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%$", "%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%%%%%%$%%%%%%%%%%%%%%%%%%%%%%%" }; class Thumbnail : public Fl_Box { Fl_Pixmap *img; public: Thumbnail(int X,int Y,const char*L=0): Fl_Box(X,Y, THUMB_IMAGE_W+THUMB_IMAGE_MARGIN*2, THUMB_IMAGE_H+THUMB_IMAGE_MARGIN*2+THUMB_LABEL_SIZE+4,L) { img = 0; box(FL_UP_BOX); color(48); align(FL_ALIGN_CENTER|FL_ALIGN_TOP|FL_ALIGN_INSIDE); labelsize(THUMB_LABEL_SIZE); } void image(Fl_Pixmap *val) { img = val; } void draw() { // Draw box, label, border, etc. Fl_Box::draw(); // Draw image over box if ( img ) img->draw(x()+THUMB_IMAGE_MARGIN, y()+labelsize()+THUMB_IMAGE_MARGIN+2); } }; int main() { // Create the XPM image Fl_Pixmap cartman(cartman_xpm); // Create the windows and widgets Fl_Double_Window win(Fl::w()/4, Fl::h()/4); Fl_Scroll scroll(10,10,win.w()-20,win.h()-20); scroll.begin(); { int by = scroll.y(); Thumbnail *thumb = 0; // Create thumbnails along X for ( int x=0; x<100; x++ ) { int bx = scroll.x(); // Create thumbnails along Y for ( int y=0; y<100; y++ ) { thumb = new Thumbnail(bx, by, "Testing"); thumb->image(&cartman); // assign image to thumbnail bx += thumb->w(); } by += thumb->h(); } } scroll.end(); win.end(); win.resizable(win); win.show(); return(Fl::run()); }