1 | // |
---|
2 | // "$Id: pixmap_browser.cxx 8344 2011-01-31 17:46:55Z manolo $" |
---|
3 | // |
---|
4 | // A shared image test program for the Fast Light Tool Kit (FLTK). |
---|
5 | // |
---|
6 | // Copyright 1998-2010 by Bill Spitzak and others. |
---|
7 | // |
---|
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. |
---|
12 | // |
---|
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. |
---|
17 | // |
---|
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 |
---|
21 | // USA. |
---|
22 | // |
---|
23 | // Please report all bugs and problems on the following page: |
---|
24 | // |
---|
25 | // http://www.fltk.org/str.php |
---|
26 | // |
---|
27 | |
---|
28 | #include <FL/Fl.H> |
---|
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> |
---|
33 | #include <string.h> |
---|
34 | #include <errno.h> |
---|
35 | #include <FL/Fl_File_Chooser.H> |
---|
36 | #include <FL/fl_message.H> |
---|
37 | |
---|
38 | Fl_Box *b; |
---|
39 | Fl_Double_Window *w; |
---|
40 | Fl_Shared_Image *img; |
---|
41 | |
---|
42 | |
---|
43 | static char name[1024]; |
---|
44 | |
---|
45 | void load_file(const char *n) { |
---|
46 | if (img) { |
---|
47 | img->release(); |
---|
48 | img = 0L; |
---|
49 | } |
---|
50 | if (fl_filename_isdir(n)) { |
---|
51 | b->label("@fileopen"); // show a generic folder |
---|
52 | b->labelsize(64); |
---|
53 | b->labelcolor(FL_LIGHT2); |
---|
54 | b->image(0); |
---|
55 | b->redraw(); |
---|
56 | return; |
---|
57 | } |
---|
58 | img = Fl_Shared_Image::get(n); |
---|
59 | if (!img) { |
---|
60 | b->label("@filenew"); // show an empty document |
---|
61 | b->labelsize(64); |
---|
62 | b->labelcolor(FL_LIGHT2); |
---|
63 | b->image(0); |
---|
64 | b->redraw(); |
---|
65 | return; |
---|
66 | } |
---|
67 | if (img->w() > b->w() || img->h() > b->h()) { |
---|
68 | Fl_Image *temp; |
---|
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()); |
---|
71 | |
---|
72 | img->release(); |
---|
73 | img = (Fl_Shared_Image *)temp; |
---|
74 | } |
---|
75 | b->label(name); |
---|
76 | b->labelsize(14); |
---|
77 | b->labelcolor(FL_FOREGROUND_COLOR); |
---|
78 | b->image(img); |
---|
79 | b->redraw(); |
---|
80 | } |
---|
81 | |
---|
82 | void file_cb(const char *n) { |
---|
83 | if (!strcmp(name,n)) return; |
---|
84 | load_file(n); |
---|
85 | strcpy(name,n); |
---|
86 | w->label(name); |
---|
87 | } |
---|
88 | |
---|
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); |
---|
94 | } |
---|
95 | |
---|
96 | int dvisual = 0; |
---|
97 | int arg(int, char **argv, int &i) { |
---|
98 | if (argv[i][1] == '8') {dvisual = 1; i++; return 1;} |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | int main(int argc, char **argv) { |
---|
103 | int i = 1; |
---|
104 | |
---|
105 | fl_register_images(); |
---|
106 | |
---|
107 | Fl::args(argc,argv,i,arg); |
---|
108 | |
---|
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); |
---|
119 | return Fl::run(); |
---|
120 | } |
---|
121 | |
---|
122 | // |
---|
123 | // End of "$Id: pixmap_browser.cxx 8344 2011-01-31 17:46:55Z manolo $". |
---|
124 | // |
---|