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:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2014-05-23 20:47:21 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2014-05-23 20:47:21 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2014-05-23 20:47:21 +04:00
|
|
|
//
|
|
|
|
|
|
|
|
#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>
|
2018-06-27 14:09:13 +03:00
|
|
|
#include <FL/platform_types.h> // for Fl_Offscreen
|
2014-05-23 20:47:21 +04:00
|
|
|
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/**
|
2016-03-07 23:50:18 +03:00
|
|
|
\brief Directs all graphics requests to an Fl_Image.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2018-02-25 09:53:34 +03:00
|
|
|
After creation of an Fl_Image_Surface object, make it the current drawing
|
|
|
|
surface calling Fl_Surface_Device::push_current(), and all
|
2020-07-01 19:03:10 +03:00
|
|
|
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
|
2016-03-07 23:50:18 +03:00
|
|
|
\ref fl_drawings or the \ref fl_attributes. Finally, call image() on the object
|
|
|
|
to obtain a newly allocated Fl_RGB_Image object.
|
2019-04-14 20:10:08 +03:00
|
|
|
Fl_Gl_Window objects can be drawn in the image as well.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
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());
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2016-03-07 23:50:18 +03:00
|
|
|
// direct all further graphics requests to the image
|
2018-02-25 09:53:34 +03:00
|
|
|
Fl_Surface_Device::push_current(image_surface);
|
2016-03-07 23:50:18 +03:00
|
|
|
|
|
|
|
// draw a white background
|
2020-07-01 19:03:10 +03:00
|
|
|
fl_color(FL_WHITE);
|
2016-03-07 23:50:18 +03:00
|
|
|
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();
|
2018-02-25 09:53:34 +03:00
|
|
|
|
|
|
|
// direct graphics requests back to their previous destination
|
|
|
|
Fl_Surface_Device::pop_current();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2016-03-07 23:50:18 +03:00
|
|
|
// delete the image_surface object, but not the image itself
|
|
|
|
delete image_surface;
|
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 {
|
2018-05-06 18:03:04 +03:00
|
|
|
friend class Fl_Graphics_Driver;
|
2014-05-23 20:47:21 +04:00
|
|
|
private:
|
2016-03-19 19:48:33 +03:00
|
|
|
class Fl_Image_Surface_Driver *platform_surface;
|
2018-05-06 18:03:04 +03:00
|
|
|
Fl_Offscreen get_offscreen_before_delete_();
|
2016-02-26 15:51:47 +03:00
|
|
|
protected:
|
2022-12-30 21:14:36 +03:00
|
|
|
void translate(int x, int y) FL_OVERRIDE;
|
|
|
|
void untranslate() FL_OVERRIDE;
|
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();
|
2022-12-30 21:14:36 +03:00
|
|
|
void set_current() FL_OVERRIDE;
|
|
|
|
bool is_current() FL_OVERRIDE;
|
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();
|
2022-12-30 21:14:36 +03:00
|
|
|
void origin(int *x, int *y) FL_OVERRIDE;
|
|
|
|
void origin(int x, int y) FL_OVERRIDE;
|
|
|
|
int printable_rect(int *w, int *h) FL_OVERRIDE;
|
2016-03-07 00:33:07 +03:00
|
|
|
Fl_Offscreen offscreen();
|
2018-05-25 07:36:49 +03:00
|
|
|
void rescale();
|
2014-05-23 20:47:21 +04:00
|
|
|
};
|
|
|
|
|
2016-03-19 19:48:33 +03:00
|
|
|
|
2018-06-23 19:47:40 +03:00
|
|
|
/**
|
2018-06-23 23:50:22 +03:00
|
|
|
\cond DriverDev
|
|
|
|
\addtogroup DriverDeveloper
|
|
|
|
\{
|
2018-06-23 19:47:40 +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;
|
2022-03-15 08:42:06 +03:00
|
|
|
private:
|
|
|
|
Fl_Image_Surface *image_surface_;
|
2016-03-19 19:48:33 +03:00
|
|
|
protected:
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
Fl_Offscreen offscreen;
|
2018-04-26 15:00:49 +03:00
|
|
|
int external_offscreen;
|
2021-12-09 10:09:44 +03:00
|
|
|
Fl_Image_Surface_Driver(int w, int h, int /*high_res*/, Fl_Offscreen off) : Fl_Widget_Surface(NULL), width(w), height(h), offscreen(off) {external_offscreen = (off != 0);}
|
2016-03-19 19:48:33 +03:00
|
|
|
virtual ~Fl_Image_Surface_Driver() {}
|
2022-12-30 21:14:36 +03:00
|
|
|
void set_current() FL_OVERRIDE = 0;
|
|
|
|
void translate(int x, int y) FL_OVERRIDE = 0;
|
|
|
|
void untranslate() FL_OVERRIDE = 0;
|
|
|
|
int printable_rect(int *w, int *h) FL_OVERRIDE;
|
2019-04-10 14:14:04 +03:00
|
|
|
virtual Fl_RGB_Image *image() = 0;
|
2016-04-24 22:30:17 +03:00
|
|
|
/** Each platform implements this function its own way.
|
|
|
|
It returns an object implementing all virtual functions
|
|
|
|
of class Fl_Image_Surface_Driver for the plaform.
|
|
|
|
*/
|
2016-03-19 19:48:33 +03:00
|
|
|
static Fl_Image_Surface_Driver *newImageSurfaceDriver(int w, int h, int high_res, Fl_Offscreen off);
|
2023-08-09 11:31:36 +03:00
|
|
|
public:
|
|
|
|
/** Returns pointer to the associated Fl_Image_Surface object */
|
|
|
|
Fl_Image_Surface *image_surface() { return image_surface_; }
|
2016-03-19 19:48:33 +03:00
|
|
|
};
|
|
|
|
|
2018-06-23 19:47:40 +03:00
|
|
|
/**
|
2018-06-23 23:50:22 +03:00
|
|
|
\}
|
|
|
|
\endcond
|
2018-06-23 19:47:40 +03:00
|
|
|
*/
|
|
|
|
|
2014-05-23 20:47:21 +04:00
|
|
|
#endif // Fl_Image_Surface_H
|