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
|
|
|
//
|
2023-11-20 22:12:02 +03:00
|
|
|
// Copyright 1998-2023 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:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2017-09-03 16:14:25 +03:00
|
|
|
#include <config.h>
|
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>
|
2023-01-21 19:27:58 +03:00
|
|
|
#include <FL/Fl_GIF_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>
|
2020-08-22 14:35:42 +03:00
|
|
|
#include <locale.h> // setlocale()..
|
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>
|
2020-06-27 10:56:00 +03:00
|
|
|
#include <FL/Fl_SVG_File_Surface.H>
|
|
|
|
#include <FL/Fl_Native_File_Chooser.H>
|
2020-07-12 00:46:34 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
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
|
|
|
|
2023-01-21 19:27:58 +03:00
|
|
|
void cb_forced_redraw(void *) {
|
|
|
|
Fl_Window *win = Fl::first_window();
|
|
|
|
while (win) {
|
|
|
|
if (!win->menu_window())
|
|
|
|
win->redraw();
|
|
|
|
win = Fl::next_window(win);
|
|
|
|
}
|
|
|
|
if (Fl::first_window())
|
|
|
|
Fl::repeat_timeout(1./10, cb_forced_redraw);
|
|
|
|
}
|
|
|
|
|
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);
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2015-03-11 00:06:22 +03:00
|
|
|
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);
|
2022-11-28 19:26:37 +03:00
|
|
|
const char *fname = fl_file_chooser("Image file?","*.{bm,bmp,gif,ico,jpg,pbm,pgm,png,ppm,xbm,xpm"
|
2020-06-27 10:56:00 +03:00
|
|
|
#ifdef FLTK_USE_SVG
|
2017-09-03 16:14:25 +03:00
|
|
|
",svg"
|
2017-10-04 19:26:51 +03:00
|
|
|
#ifdef HAVE_LIBZ
|
|
|
|
",svgz"
|
2020-06-27 10:56:00 +03:00
|
|
|
#endif // HAVE_LIBZ
|
|
|
|
#endif // FLTK_USE_SVG
|
2017-09-03 16:14:25 +03:00
|
|
|
"}", name);
|
2011-01-31 20:46:55 +03:00
|
|
|
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
|
|
|
}
|
2020-06-27 10:56:00 +03: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();
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2020-06-27 10:56:00 +03:00
|
|
|
void svg_cb(Fl_Widget *widget, void *) {
|
|
|
|
Fl_Native_File_Chooser fnfc;
|
|
|
|
fnfc.title("Pick a .svg file");
|
|
|
|
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
|
|
|
fnfc.filter("SVG\t*.svg\n");
|
|
|
|
fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
|
|
|
|
if (fnfc.show() ) return;
|
|
|
|
FILE *svg = fl_fopen(fnfc.filename(), "w");
|
|
|
|
Fl_SVG_File_Surface surf(widget->window()->decorated_w(), widget->window()->decorated_h(), svg);
|
|
|
|
surf.draw_decorated_window(widget->window());
|
|
|
|
surf.close();
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
int dvisual = 0;
|
2023-01-21 19:27:58 +03:00
|
|
|
int animate = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
int arg(int, char **argv, int &i) {
|
|
|
|
if (argv[i][1] == '8') {dvisual = 1; i++; return 1;}
|
2023-01-21 19:27:58 +03:00
|
|
|
if (argv[i][1] == 'a') {animate = 1; i++; return 1;}
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i = 1;
|
2002-06-29 01:04:37 +04:00
|
|
|
|
2020-07-12 00:46:34 +03:00
|
|
|
setlocale(LC_ALL, ""); // enable multilanguage errors in file chooser
|
2002-06-29 01:04:37 +04:00
|
|
|
fl_register_images();
|
|
|
|
|
2023-11-20 22:12:02 +03:00
|
|
|
Fl::args_to_utf8(argc, argv); // enable multilanguage commandlines on Windows
|
|
|
|
Fl::args(argc, argv, i, arg); // parse commandline
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-01-21 19:27:58 +03:00
|
|
|
if (animate)
|
|
|
|
Fl_GIF_Image::animate = true; // create animated shared .GIF images (e.g. file chooser)
|
|
|
|
|
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);
|
2020-06-27 10:56:00 +03:00
|
|
|
Fl_Button svg(190,425,100,25,"save as SVG");
|
|
|
|
svg.callback(svg_cb);
|
2015-03-11 00:06:22 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
window.show(argc,argv);
|
2023-01-21 19:27:58 +03:00
|
|
|
if (animate)
|
|
|
|
Fl::add_timeout(1./10, cb_forced_redraw); // force periodic redraw
|
1998-10-06 22:21:25 +04:00
|
|
|
return Fl::run();
|
|
|
|
}
|