From f5a571fc83921005c21eff1383cd30ac4afadd2c Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 2 Jan 2006 20:18:23 +0000 Subject: Fixed "Pixmap" demo to not pop up a dialog if an image (or other file or even directory) is not readable. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4735 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- test/pixmap_browser.cxx | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/test/pixmap_browser.cxx b/test/pixmap_browser.cxx index 16e064259..a2cb1ff25 100644 --- a/test/pixmap_browser.cxx +++ b/test/pixmap_browser.cxx @@ -43,11 +43,25 @@ Fl_Shared_Image *img; static char name[1024]; void load_file(const char *n) { - if (img) img->release(); - + if (img) { + img->release(); + img = 0L; + } + if (fl_filename_isdir(n)) { + b->label("@fileopen"); // show a generic folder + b->labelsize(64); + b->labelcolor(FL_LIGHT2); + b->image(0); + b->redraw(); + return; + } img = Fl_Shared_Image::get(n); if (!img) { - fl_alert("Image file format not recognized!"); + b->label("@filenew"); // show an empty document + b->labelsize(64); + b->labelcolor(FL_LIGHT2); + b->image(0); + b->redraw(); return; } if (img->w() > b->w() || img->h() > b->h()) { @@ -58,8 +72,9 @@ void load_file(const char *n) { img->release(); img = (Fl_Shared_Image *)temp; } - b->label(name); + b->labelsize(14); + b->labelcolor(FL_FOREGROUND_COLOR); b->image(img); b->redraw(); } @@ -90,10 +105,11 @@ int main(int argc, char **argv) { Fl::args(argc,argv,i,arg); - Fl_Window window(400,400); ::w = &window; - Fl_Box b(0,0,window.w(),window.h()); ::b = &b; - b.box(FL_FLAT_BOX); - Fl_Button button(5,5,100,35,"load"); + Fl_Window window(400,435); ::w = &window; + Fl_Box b(10,45,380,380); ::b = &b; + b.box(FL_THIN_DOWN_BOX); + b.align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER); + Fl_Button button(150,5,100,30,"load"); button.callback(button_cb); if (!dvisual) Fl::visual(FL_RGB); if (argv[1]) load_file(argv[1]); -- cgit v1.2.3