1 //
2 // "$Id$"
3 //
4 // Draw-to-image code for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2014 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 
19 #ifndef Fl_Image_Surface_H
20 #define Fl_Image_Surface_H
21 
22 #include <FL/Fl_Copy_Surface.H>
23 #include <FL/Fl_Image.H>
24 #include <FL/Fl_Shared_Image.H>
25 
26 
27 /** Directs all graphics requests to an Fl_Image.
28 
29  After creation of an Fl_Image_Surface object, call set_current() on it, and all subsequent graphics requests
30  will be recorded in the image. It's possible to draw widgets (using Fl_Image_Surface::draw())
31  or to use any of the \ref fl_drawings or the \ref fl_attributes.
32  Finally, call image() on the object to obtain a newly allocated Fl_RGB_Image object.
33  <br> Fl_GL_Window objects can be drawn in the image as well.
34 
35  <br> Usage example:
36  \code
37  Fl_Widget *g = ...; // a widget you want to draw in an image
38  Fl_Image_Surface *img_surf = new Fl_Image_Surface(g->w(), g->h()); // create an Fl_Image_Surface object
39  img_surf->set_current(); // direct graphics requests to the image
40  fl_color(FL_WHITE); fl_rectf(0, 0, g->w(), g->h()); // draw a white background
41  img_surf->draw(g); // draw the g widget in the image
42  Fl_RGB_Image* image = img_surf->image(); // get the resulting image
43  delete img_surf; // delete the img_surf object
44  Fl_Display_Device::display_device()->set_current();  // direct graphics requests back to the display
45  \endcode
46 */
47 class FL_EXPORT Fl_Image_Surface : public Fl_Surface_Device {
48 private:
49   void prepare_(int w, int h, int highres);
50   Fl_Offscreen offscreen;
51   int width;
52   int height;
53   Fl_Paged_Device *helper;
54 #ifdef __APPLE__
55 #elif defined(WIN32)
56   HDC _sgc;
57   Window _sw;
58   Fl_Surface_Device *_ss;
59   int _savedc;
60 #else
61   Fl_Surface_Device *previous;
62   Window pre_window;
63   GC gc;
64 #endif
65 public:
66   static const char *class_id;
class_name()67   const char *class_name() {return class_id;};
68 #if FLTK_ABI_VERSION >= 10304 || defined(FL_DOXYGEN)
69   Fl_Image_Surface(int w, int h, int highres = 0);
70 #else
71   Fl_Image_Surface(int w, int h, int highres);
72   Fl_Image_Surface(int w, int h);
73 #endif
74   ~Fl_Image_Surface();
75   void set_current();
76   void draw(Fl_Widget*, int delta_x = 0, int delta_y = 0);
77   void draw_decorated_window(Fl_Window* win, int delta_x = 0, int delta_y = 0);
78   Fl_RGB_Image *image();
79   Fl_Shared_Image *highres_image();
80 };
81 
82 #ifdef __APPLE__
83 /* Mac class to implement translate()/untranslate() for a flipped bitmap graphics context */
84 class FL_EXPORT Fl_Quartz_Flipped_Surface_ : public Fl_Quartz_Surface_ {
85 public:
86   static const char *class_id;
class_name()87   const char *class_name() {return class_id;};
88   Fl_Quartz_Flipped_Surface_(int w, int h);
89   void translate(int x, int y);
90   void untranslate();
~Fl_Quartz_Flipped_Surface_()91   virtual ~Fl_Quartz_Flipped_Surface_() {};
92 };
93 #endif
94 
95 #endif // Fl_Image_Surface_H
96 
97 //
98 // End of "$Id$".
99 //
100