2014-05-23 20:47:21 +04:00
|
|
|
//
|
2014-05-24 20:21:46 +04:00
|
|
|
// "$Id$"
|
2014-05-23 20:47:21 +04:00
|
|
|
//
|
|
|
|
// Draw-to-image code for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2016-02-18 19:21:51 +03:00
|
|
|
// Copyright 1998-2016 by Bill Spitzak and others.
|
2014-05-23 20:47:21 +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
|
|
|
|
//
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Fl_Image_Surface_H
|
|
|
|
#define Fl_Image_Surface_H
|
|
|
|
|
2016-03-01 21:07:12 +03:00
|
|
|
#include <FL/Fl_Widget_Surface.H>
|
2014-05-23 20:47:21 +04:00
|
|
|
#include <FL/Fl_Image.H>
|
2016-02-12 14:49:32 +03:00
|
|
|
#include <FL/Fl_Shared_Image.H>
|
2016-03-26 20:49:54 +03:00
|
|
|
#include <FL/Fl_Graphics_Driver.H> // for Fl_Offscreen
|
2014-05-23 20:47:21 +04:00
|
|
|
|
|
|
|
|
2016-03-07 23:50:18 +03:00
|
|
|
/**
|
|
|
|
\brief Directs all graphics requests to an Fl_Image.
|
2014-05-23 20:47:21 +04:00
|
|
|
|
2016-03-07 23:50:18 +03:00
|
|
|
After creation of an Fl_Image_Surface object, call set_current() on it, and all
|
|
|
|
subsequent graphics requests will be recorded in the image. It's possible to
|
|
|
|
draw widgets (using Fl_Image_Surface::draw()) or to use any of the
|
|
|
|
\ref fl_drawings or the \ref fl_attributes. Finally, call image() on the object
|
|
|
|
to obtain a newly allocated Fl_RGB_Image object.
|
|
|
|
Fl_GL_Window objects can be drawn in the image as well.
|
|
|
|
|
2016-04-23 09:27:31 +03:00
|
|
|
Usage example:
|
2014-05-23 20:47:21 +04:00
|
|
|
\code
|
2016-03-07 23:50:18 +03:00
|
|
|
// this is the widget that you want to draw into an image
|
|
|
|
Fl_Widget *g = ...;
|
|
|
|
|
|
|
|
// create an Fl_Image_Surface object
|
|
|
|
Fl_Image_Surface *image_surface = new Fl_Image_Surface(g->w(), g->h());
|
|
|
|
|
|
|
|
// direct all further graphics requests to the image
|
|
|
|
image_surface->set_current();
|
|
|
|
|
|
|
|
// draw a white background
|
|
|
|
fl_color(FL_WHITE);
|
|
|
|
fl_rectf(0, 0, g->w(), g->h());
|
|
|
|
|
|
|
|
// draw the g widget in the image
|
|
|
|
image_surface->draw(g);
|
|
|
|
|
|
|
|
// get the resulting image
|
|
|
|
Fl_RGB_Image* image = image_surface->image();
|
|
|
|
|
|
|
|
// delete the image_surface object, but not the image itself
|
|
|
|
delete image_surface;
|
|
|
|
|
|
|
|
// direct graphics requests back to the screen
|
|
|
|
Fl_Display_Device::display_device()->set_current();
|
2014-05-23 20:47:21 +04:00
|
|
|
\endcode
|
|
|
|
*/
|
2016-02-26 15:51:47 +03:00
|
|
|
class FL_EXPORT Fl_Image_Surface : public Fl_Widget_Surface {
|
2016-03-03 01:10:03 +03:00
|
|
|
friend Fl_Offscreen fl_create_offscreen(int w, int h);
|
|
|
|
friend void fl_begin_offscreen(Fl_Offscreen ctx);
|
2016-02-27 16:52:27 +03:00
|
|
|
friend void fl_end_offscreen(void);
|
2016-03-03 01:10:03 +03:00
|
|
|
friend void fl_delete_offscreen(Fl_Offscreen ctx);
|
2014-05-23 20:47:21 +04:00
|
|
|
private:
|
2016-03-19 19:48:33 +03:00
|
|
|
class Fl_Image_Surface_Driver *platform_surface;
|
2016-02-26 15:51:47 +03:00
|
|
|
protected:
|
|
|
|
void translate(int x, int y);
|
|
|
|
void untranslate();
|
2014-05-23 20:47:21 +04:00
|
|
|
public:
|
2016-03-19 19:48:33 +03:00
|
|
|
Fl_Image_Surface(int w, int h, int high_res = 0, Fl_Offscreen off = 0);
|
2014-05-23 20:47:21 +04:00
|
|
|
~Fl_Image_Surface();
|
|
|
|
void set_current();
|
2016-03-03 01:10:03 +03:00
|
|
|
void end_current();
|
2014-06-18 05:22:16 +04:00
|
|
|
Fl_RGB_Image *image();
|
2016-02-12 14:49:32 +03:00
|
|
|
Fl_Shared_Image *highres_image();
|
2016-03-03 01:10:03 +03:00
|
|
|
void origin(int *x, int *y);
|
|
|
|
void origin(int x, int y);
|
|
|
|
int printable_rect(int *w, int *h);
|
2016-03-03 11:32:16 +03:00
|
|
|
Fl_Offscreen get_offscreen_before_delete();
|
2016-03-07 00:33:07 +03:00
|
|
|
Fl_Offscreen offscreen();
|
2014-05-23 20:47:21 +04:00
|
|
|
};
|
|
|
|
|
2016-03-19 19:48:33 +03:00
|
|
|
|
2016-04-23 09:27:31 +03:00
|
|
|
/** A base class describing the interface between FLTK and draw-to-image operations.
|
|
|
|
This class is only for internal use by the FLTK library.
|
|
|
|
A supported platform should implement the virtual methods of this class
|
|
|
|
in order to support drawing to an Fl_RGB_Image through class Fl_Image_Surface.
|
|
|
|
*/
|
2016-03-19 19:48:33 +03:00
|
|
|
class Fl_Image_Surface_Driver : public Fl_Widget_Surface {
|
|
|
|
friend class Fl_Image_Surface;
|
|
|
|
protected:
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
Fl_Offscreen offscreen;
|
|
|
|
Fl_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {}
|
|
|
|
virtual ~Fl_Image_Surface_Driver() {}
|
|
|
|
virtual void set_current() {}
|
|
|
|
virtual void translate(int x, int y) {}
|
|
|
|
virtual void untranslate() {}
|
|
|
|
int printable_rect(int *w, int *h) {*w = width; *h = height; return 0;}
|
|
|
|
virtual Fl_RGB_Image *image() {return NULL;}
|
|
|
|
virtual void end_current() {}
|
|
|
|
static Fl_Image_Surface_Driver *newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off);
|
|
|
|
};
|
|
|
|
|
2014-05-23 20:47:21 +04:00
|
|
|
#endif // Fl_Image_Surface_H
|
|
|
|
|
|
|
|
//
|
2014-05-24 20:21:46 +04:00
|
|
|
// End of "$Id$".
|
2014-05-23 20:47:21 +04:00
|
|
|
//
|