Fl_Image_Surface.H 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // "$Id: Fl_Image_Surface.H 12125 2016-11-30 07:09:48Z manolo $"
  3. //
  4. // Draw-to-image code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2016 by Bill Spitzak and others.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #ifndef Fl_Image_Surface_H
  19. #define Fl_Image_Surface_H
  20. #include <FL/Fl_Widget_Surface.H>
  21. #include <FL/Fl_Image.H>
  22. #include <FL/Fl_Shared_Image.H>
  23. #include <FL/Fl_Graphics_Driver.H> // for Fl_Offscreen
  24. /**
  25. \brief Directs all graphics requests to an Fl_Image.
  26. After creation of an Fl_Image_Surface object, call set_current() on it, and all
  27. subsequent graphics requests will be recorded in the image. It's possible to
  28. draw widgets (using Fl_Image_Surface::draw()) or to use any of the
  29. \ref fl_drawings or the \ref fl_attributes. Finally, call image() on the object
  30. to obtain a newly allocated Fl_RGB_Image object.
  31. Fl_GL_Window objects can be drawn in the image as well.
  32. Usage example:
  33. \code
  34. // this is the widget that you want to draw into an image
  35. Fl_Widget *g = ...;
  36. // create an Fl_Image_Surface object
  37. Fl_Image_Surface *image_surface = new Fl_Image_Surface(g->w(), g->h());
  38. // direct all further graphics requests to the image
  39. image_surface->set_current();
  40. // draw a white background
  41. fl_color(FL_WHITE);
  42. fl_rectf(0, 0, g->w(), g->h());
  43. // draw the g widget in the image
  44. image_surface->draw(g);
  45. // get the resulting image
  46. Fl_RGB_Image* image = image_surface->image();
  47. // delete the image_surface object, but not the image itself
  48. delete image_surface;
  49. // direct graphics requests back to the screen
  50. Fl_Display_Device::display_device()->set_current();
  51. \endcode
  52. */
  53. class FL_EXPORT Fl_Image_Surface : public Fl_Widget_Surface {
  54. friend FL_EXPORT Fl_Offscreen fl_create_offscreen(int w, int h);
  55. friend FL_EXPORT void fl_begin_offscreen(Fl_Offscreen ctx);
  56. friend FL_EXPORT void fl_end_offscreen(void);
  57. friend FL_EXPORT void fl_delete_offscreen(Fl_Offscreen ctx);
  58. private:
  59. class Fl_Image_Surface_Driver *platform_surface;
  60. protected:
  61. void translate(int x, int y);
  62. void untranslate();
  63. public:
  64. Fl_Image_Surface(int w, int h, int high_res = 0, Fl_Offscreen off = 0);
  65. ~Fl_Image_Surface();
  66. void set_current();
  67. Fl_RGB_Image *image();
  68. Fl_Shared_Image *highres_image();
  69. void origin(int *x, int *y);
  70. void origin(int x, int y);
  71. int printable_rect(int *w, int *h);
  72. Fl_Offscreen get_offscreen_before_delete();
  73. Fl_Offscreen offscreen();
  74. };
  75. /** A base class describing the interface between FLTK and draw-to-image operations.
  76. This class is only for internal use by the FLTK library.
  77. A supported platform should implement the virtual methods of this class
  78. in order to support drawing to an Fl_RGB_Image through class Fl_Image_Surface.
  79. */
  80. class Fl_Image_Surface_Driver : public Fl_Widget_Surface {
  81. friend class Fl_Image_Surface;
  82. protected:
  83. int width;
  84. int height;
  85. Fl_Offscreen offscreen;
  86. Fl_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {}
  87. virtual ~Fl_Image_Surface_Driver() {}
  88. virtual void set_current() {}
  89. virtual void translate(int x, int y) {}
  90. virtual void untranslate() {}
  91. int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
  92. virtual Fl_RGB_Image *image() {return NULL;}
  93. /** Each platform implements this function its own way.
  94. It returns an object implementing all virtual functions
  95. of class Fl_Image_Surface_Driver for the plaform.
  96. */
  97. static Fl_Image_Surface_Driver *newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off);
  98. };
  99. #endif // Fl_Image_Surface_H
  100. //
  101. // End of "$Id: Fl_Image_Surface.H 12125 2016-11-30 07:09:48Z manolo $".
  102. //