1998-10-20 17:25:25 +04:00
|
|
|
//
|
2002-01-06 20:51:12 +03:00
|
|
|
// "$Id: pixmap_browser.cxx,v 1.5.2.4.2.5 2002/01/06 17:51:12 easysw Exp $"
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2001-11-24 21:07:58 +03:00
|
|
|
// A shared image test program for the Fast Light Tool Kit (FLTK).
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2002-01-01 18:11:33 +03:00
|
|
|
// Copyright 1998-2002 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
2001-11-24 21:07:58 +03:00
|
|
|
#include <FL/Fl_Shared_Image.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2001-09-30 21:37:06 +04:00
|
|
|
#include <FL/Fl_File_Chooser.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/fl_message.H>
|
|
|
|
|
|
|
|
Fl_Box *b;
|
|
|
|
Fl_Window *w;
|
2001-11-24 21:07:58 +03:00
|
|
|
Fl_Shared_Image *img;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
|
2001-11-24 21:07:58 +03:00
|
|
|
static char name[1024];
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-11-24 21:07:58 +03:00
|
|
|
void load_file(const char *n) {
|
|
|
|
if (img) img->release();
|
|
|
|
|
|
|
|
img = Fl_Shared_Image::get(n);
|
|
|
|
if (img->w() > b->w() || img->h() > b->h()) {
|
|
|
|
Fl_Image *temp;
|
|
|
|
if (img->w() > img->h()) temp = img->copy(b->w(), b->h() * img->h() / img->w());
|
|
|
|
else temp = img->copy(b->w() * img->w() / img->h(), b->h());
|
|
|
|
|
|
|
|
img->release();
|
|
|
|
img = (Fl_Shared_Image *)temp;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2001-11-24 21:07:58 +03:00
|
|
|
b->label(name);
|
|
|
|
b->image(img);
|
2001-09-02 15:23:27 +04:00
|
|
|
b->redraw();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void file_cb(const char *n) {
|
|
|
|
if (!strcmp(name,n)) return;
|
2001-11-24 21:07:58 +03:00
|
|
|
load_file(n);
|
1998-10-06 22:21:25 +04:00
|
|
|
strcpy(name,n);
|
|
|
|
w->label(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void button_cb(Fl_Widget *,void *) {
|
|
|
|
fl_file_chooser_callback(file_cb);
|
2002-01-06 20:51:12 +03:00
|
|
|
fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name);
|
1998-10-06 22:21:25 +04:00
|
|
|
fl_file_chooser_callback(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int dvisual = 0;
|
|
|
|
int arg(int, char **argv, int &i) {
|
|
|
|
if (argv[i][1] == '8') {dvisual = 1; i++; return 1;}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i = 1;
|
2001-11-24 21:07:58 +03:00
|
|
|
Fl::args(argc,argv,i,arg);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
Fl_Window window(400,400); ::w = &window;
|
|
|
|
Fl_Box b(0,0,window.w(),window.h()); ::b = &b;
|
2001-11-24 21:07:58 +03:00
|
|
|
b.box(FL_FLAT_BOX);
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Button button(5,5,100,35,"load");
|
|
|
|
button.callback(button_cb);
|
|
|
|
if (!dvisual) Fl::visual(FL_RGB);
|
2001-11-24 21:07:58 +03:00
|
|
|
if (argv[1]) load_file(argv[1]);
|
1998-10-06 22:21:25 +04:00
|
|
|
window.resizable(window);
|
|
|
|
window.show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|
1998-10-20 17:25:25 +04:00
|
|
|
|
|
|
|
//
|
2002-01-06 20:51:12 +03:00
|
|
|
// End of "$Id: pixmap_browser.cxx,v 1.5.2.4.2.5 2002/01/06 17:51:12 easysw Exp $".
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|