2 // "$Id: pixmap_browser.cxx 8344 2011-01-31 17:46:55Z manolo $"
4 // A shared image test program for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
29 #include <FL/Fl_Box.H>
30 #include <FL/Fl_Double_Window.H>
31 #include <FL/Fl_Button.H>
32 #include <FL/Fl_Shared_Image.H>
35 #include <FL/Fl_File_Chooser.H>
36 #include <FL/fl_message.H>
43 static char name
[1024];
45 void load_file(const char *n
) {
50 if (fl_filename_isdir(n
)) {
51 b
->label("@fileopen"); // show a generic folder
53 b
->labelcolor(FL_LIGHT2
);
58 img
= Fl_Shared_Image::get(n
);
60 b
->label("@filenew"); // show an empty document
62 b
->labelcolor(FL_LIGHT2
);
67 if (img
->w() > b
->w() || img
->h() > b
->h()) {
69 if (img
->w() > img
->h()) temp
= img
->copy(b
->w(), b
->h() * img
->h() / img
->w());
70 else temp
= img
->copy(b
->w() * img
->w() / img
->h(), b
->h());
73 img
= (Fl_Shared_Image
*)temp
;
77 b
->labelcolor(FL_FOREGROUND_COLOR
);
82 void file_cb(const char *n
) {
83 if (!strcmp(name
,n
)) return;
89 void button_cb(Fl_Widget
*,void *) {
90 fl_file_chooser_callback(file_cb
);
91 const char *fname
= fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name
);
92 puts(fname
? fname
: "(null)"); fflush(stdout
);
93 fl_file_chooser_callback(0);
97 int arg(int, char **argv
, int &i
) {
98 if (argv
[i
][1] == '8') {dvisual
= 1; i
++; return 1;}
102 int main(int argc
, char **argv
) {
105 fl_register_images();
107 Fl::args(argc
,argv
,i
,arg
);
109 Fl_Double_Window
window(400,435); ::w
= &window
;
110 Fl_Box
b(10,45,380,380); ::b
= &b
;
111 b
.box(FL_THIN_DOWN_BOX
);
112 b
.align(FL_ALIGN_INSIDE
|FL_ALIGN_CENTER
);
113 Fl_Button
button(150,5,100,30,"load");
114 button
.callback(button_cb
);
115 if (!dvisual
) Fl::visual(FL_RGB
);
116 if (argv
[1]) load_file(argv
[1]);
117 window
.resizable(window
);
118 window
.show(argc
,argv
);
123 // End of "$Id: pixmap_browser.cxx 8344 2011-01-31 17:46:55Z manolo $".