1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
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
|
|
|
//
|
2015-03-11 00:06:22 +03:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
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>
|
2009-04-21 13:09:37 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Button.H>
|
2001-11-24 21:07:58 +03:00
|
|
|
#include <FL/Fl_Shared_Image.H>
|
2015-03-11 00:06:22 +03:00
|
|
|
#include <FL/Fl_Printer.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2010-04-15 16:58:42 +04:00
|
|
|
#include <FL/Fl_File_Chooser.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/fl_message.H>
|
|
|
|
|
|
|
|
Fl_Box *b;
|
2009-04-21 13:09:37 +04:00
|
|
|
Fl_Double_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) {
|
2006-01-02 23:18:23 +03:00
|
|
|
if (img) {
|
2015-03-11 00:06:22 +03:00
|
|
|
((Fl_Shared_Image*)b->image())->release();
|
2006-01-02 23:18:23 +03:00
|
|
|
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;
|
|
|
|
}
|
2015-03-11 00:06:22 +03:00
|
|
|
Fl_Shared_Image *img2 = Fl_Shared_Image::get(n);
|
|
|
|
|
|
|
|
if (!img2) {
|
2006-01-02 23:18:23 +03:00
|
|
|
b->label("@filenew"); // show an empty document
|
|
|
|
b->labelsize(64);
|
|
|
|
b->labelcolor(FL_LIGHT2);
|
|
|
|
b->image(0);
|
|
|
|
b->redraw();
|
2002-06-13 22:18:33 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-03-11 00:06:22 +03:00
|
|
|
img = img2;
|
2006-01-02 23:18:23 +03:00
|
|
|
b->labelsize(14);
|
|
|
|
b->labelcolor(FL_FOREGROUND_COLOR);
|
2001-11-24 21:07:58 +03:00
|
|
|
b->image(img);
|
2015-03-11 00:06:22 +03:00
|
|
|
img->scale(b->w(), b->h());
|
|
|
|
b->label(NULL);
|
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 *) {
|
2010-04-15 16:58:42 +04:00
|
|
|
fl_file_chooser_callback(file_cb);
|
2011-01-31 20:46:55 +03:00
|
|
|
const char *fname = fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name);
|
|
|
|
puts(fname ? fname : "(null)"); fflush(stdout);
|
2010-04-15 16:58:42 +04:00
|
|
|
fl_file_chooser_callback(0);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2015-03-11 00:06:22 +03:00
|
|
|
void print_cb(Fl_Widget *widget, void *) {
|
|
|
|
Fl_Printer printer;
|
|
|
|
int width, height;
|
|
|
|
if (printer.start_job(1)) return;
|
|
|
|
printer.start_page();
|
|
|
|
printer.printable_rect(&width, &height);
|
|
|
|
float fw = widget->window()->decorated_w() / float(width);
|
|
|
|
float fh = widget->window()->decorated_h() / float(height);
|
|
|
|
if (fh > fw) fw = fh;
|
|
|
|
printer.scale(1/fw);
|
|
|
|
printer.print_window(widget->window());
|
|
|
|
printer.end_page();
|
|
|
|
printer.end_job();
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
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;
|
2002-06-29 01:04:37 +04:00
|
|
|
|
|
|
|
fl_register_images();
|
|
|
|
|
2001-11-24 21:07:58 +03:00
|
|
|
Fl::args(argc,argv,i,arg);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2015-03-11 00:06:22 +03:00
|
|
|
Fl_Double_Window window(400,450); ::w = &window;
|
2006-01-02 23:18:23 +03:00
|
|
|
Fl_Box b(10,45,380,380); ::b = &b;
|
|
|
|
b.box(FL_THIN_DOWN_BOX);
|
2015-03-11 00:06:22 +03:00
|
|
|
b.align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER|FL_ALIGN_CLIP);
|
2006-01-02 23:18:23 +03:00
|
|
|
Fl_Button button(150,5,100,30,"load");
|
1998-10-06 22:21:25 +04:00
|
|
|
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]);
|
2015-03-11 00:06:22 +03:00
|
|
|
window.resizable(b);
|
|
|
|
Fl_Button print(300,425,50,25,"Print");
|
|
|
|
print.callback(print_cb);
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
window.show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|
1998-10-20 17:25:25 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|