You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.2KB

  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. #include <FL/Fl.H>
  28. #include <FL/Fl_Box.H>
  29. #include <FL/Fl_Double_Window.H>
  30. #include <FL/Fl_Button.H>
  31. #include <FL/Fl_Shared_Image.H>
  32. #include <string.h>
  33. #include <errno.h>
  34. #include <FL/Fl_File_Chooser.H>
  35. #include <FL/fl_message.H>
  36. Fl_Box *b;
  37. Fl_Double_Window *w;
  38. Fl_Shared_Image *img;
  39. static char name[1024];
  40. void load_file(const char *n) {
  41. if (img) {
  42. img->release();
  43. img = 0L;
  44. }
  45. if (fl_filename_isdir(n)) {
  46. b->label("@fileopen"); // show a generic folder
  47. b->labelsize(64);
  48. b->labelcolor(FL_LIGHT2);
  49. b->image(0);
  50. b->redraw();
  51. return;
  52. }
  53. img = Fl_Shared_Image::get(n);
  54. if (!img) {
  55. b->label("@filenew"); // show an empty document
  56. b->labelsize(64);
  57. b->labelcolor(FL_LIGHT2);
  58. b->image(0);
  59. b->redraw();
  60. return;
  61. }
  62. if (img->w() > b->w() || img->h() > b->h()) {
  63. Fl_Image *temp;
  64. if (img->w() > img->h()) temp = img->copy(b->w(), b->h() * img->h() / img->w());
  65. else temp = img->copy(b->w() * img->w() / img->h(), b->h());
  66. img->release();
  67. img = (Fl_Shared_Image *)temp;
  68. }
  69. b->label(name);
  70. b->labelsize(14);
  71. b->labelcolor(FL_FOREGROUND_COLOR);
  72. b->image(img);
  73. b->redraw();
  74. }
  75. void file_cb(const char *n) {
  76. if (!strcmp(name,n)) return;
  77. load_file(n);
  78. strcpy(name,n);
  79. w->label(name);
  80. }
  81. void button_cb(Fl_Widget *,void *) {
  82. fl_file_chooser_callback(file_cb);
  83. const char *fname = fl_file_chooser("Image file?","*.{bm,bmp,gif,jpg,pbm,pgm,png,ppm,xbm,xpm}", name);
  84. puts(fname ? fname : "(null)"); fflush(stdout);
  85. fl_file_chooser_callback(0);
  86. }
  87. int dvisual = 0;
  88. int arg(int, char **argv, int &i) {
  89. if (argv[i][1] == '8') {dvisual = 1; i++; return 1;}
  90. return 0;
  91. }
  92. int main(int argc, char **argv) {
  93. int i = 1;
  94. fl_register_images();
  95. Fl::args(argc,argv,i,arg);
  96. Fl_Double_Window window(400,435); ::w = &window;
  97. Fl_Box b(10,45,380,380); ::b = &b;
  98. b.box(FL_THIN_DOWN_BOX);
  99. b.align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
  100. Fl_Button button(150,5,100,30,"load");
  101. button.callback(button_cb);
  102. if (!dvisual) Fl::visual(FL_RGB);
  103. if (argv[1]) load_file(argv[1]);
  104. window.resizable(window);
  105. window.show(argc,argv);
  106. return Fl::run();
  107. }
  108. //
  109. // End of "$Id: pixmap_browser.cxx 8344 2011-01-31 17:46:55Z manolo $".
  110. //