2010-03-18 18:15:41 +03:00
|
|
|
//
|
2016-02-25 20:56:48 +03:00
|
|
|
// Definition of classes Fl_Surface_Device, Fl_Display_Device
|
2010-05-27 21:20:18 +04:00
|
|
|
// for the Fast Light Tool Kit (FLTK).
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2021-03-20 23:39:28 +03:00
|
|
|
// Copyright 2010-2021 by Bill Spitzak and others.
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +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:
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2010-03-18 18:15:41 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** \file Fl_Device.H
|
2016-02-25 20:56:48 +03:00
|
|
|
\brief declaration of classes Fl_Surface_Device, Fl_Display_Device, Fl_Device_Plugin.
|
2010-03-25 16:59:00 +03:00
|
|
|
*/
|
2010-03-14 21:07:24 +03:00
|
|
|
|
|
|
|
#ifndef Fl_Device_H
|
|
|
|
#define Fl_Device_H
|
|
|
|
|
2010-03-17 01:51:31 +03:00
|
|
|
#include <FL/Fl_Plugin.H>
|
2018-11-29 20:50:55 +03:00
|
|
|
#include <FL/platform_types.h>
|
2010-03-14 21:07:24 +03:00
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
class Fl_Graphics_Driver;
|
2016-02-10 22:49:35 +03:00
|
|
|
class Fl_RGB_Image;
|
2016-02-20 00:41:02 +03:00
|
|
|
class Fl_Widget;
|
2022-03-15 08:42:06 +03:00
|
|
|
class Fl_Image_Surface;
|
2011-02-05 02:32:53 +03:00
|
|
|
|
2010-05-27 21:20:18 +04:00
|
|
|
/**
|
2015-12-22 13:15:28 +03:00
|
|
|
A drawing surface that's susceptible to receive graphical output.
|
|
|
|
Any FLTK application has at any time a current drawing surface to which all drawing requests are directed.
|
|
|
|
The current surface is given by Fl_Surface_Device::surface().
|
2020-07-01 19:03:10 +03:00
|
|
|
When main() begins running, the current drawing surface has been set to the computer's display,
|
2015-12-22 13:15:28 +03:00
|
|
|
an instance of the Fl_Display_Device class.
|
|
|
|
|
|
|
|
A drawing surface other than the computer's display, is typically used as follows:
|
2015-03-24 17:20:38 +03:00
|
|
|
<ol><li> Create \c surface, an object from a particular Fl_Surface_Device derived class (e.g., Fl_Copy_Surface, Fl_Printer).
|
2021-10-31 16:20:04 +03:00
|
|
|
<li> Call \c Fl_Surface_Device::push_current(surface); to redirect all graphics requests to
|
|
|
|
\c surface which becomes the new current drawing surface (not necessary with classes Fl_Printer / Fl_PostScript_File_Device
|
|
|
|
because it is done by Fl_Paged_Device::begin_page()).
|
2016-12-07 18:09:52 +03:00
|
|
|
<li> At this point all of the \ref fl_drawings (e.g., fl_rect()) or the \ref fl_attributes or \ref drawing_images functions
|
|
|
|
(e.g., fl_draw_image(), Fl_Image::draw()) operate on the new current drawing surface.
|
2019-04-14 20:07:14 +03:00
|
|
|
Drawing surfaces from Fl_Widget_Surface derived classes allow additional ways
|
|
|
|
to draw to them (e.g., Fl_Printer::print_widget(), Fl_Image_Surface::draw()).
|
2015-03-24 17:20:38 +03:00
|
|
|
<li> After all drawing requests have been performed, redirect graphics requests back to their previous destination
|
2021-10-31 16:20:04 +03:00
|
|
|
with \c Fl_Surface_Device::pop_current(); (not necessary with classes Fl_Printer / Fl_PostScript_File_Device).
|
2015-03-24 17:20:38 +03:00
|
|
|
<li> Delete \c surface.
|
|
|
|
</ol>
|
2016-12-07 18:09:52 +03:00
|
|
|
For back-compatibility, it is also possible to use the Fl_Surface_Device::set_current() member function
|
|
|
|
to change the current drawing surface, once to the new surface, once to the previous one.
|
2010-05-27 21:20:18 +04:00
|
|
|
*/
|
2016-02-25 20:56:48 +03:00
|
|
|
class FL_EXPORT Fl_Surface_Device {
|
2016-11-30 10:09:48 +03:00
|
|
|
/** The graphics driver in use by this surface. */
|
2016-03-07 23:50:18 +03:00
|
|
|
Fl_Graphics_Driver *pGraphicsDriver;
|
2016-12-07 18:09:52 +03:00
|
|
|
static Fl_Surface_Device *surface_; // the surface that currently receives graphics requests
|
2016-03-07 23:50:18 +03:00
|
|
|
static Fl_Surface_Device *default_surface(); // create surface if none exists yet
|
2019-05-25 12:59:16 +03:00
|
|
|
protected:
|
2021-10-31 08:47:18 +03:00
|
|
|
/** FLTK calls this each time a surface ceases to be the current drawing surface.
|
|
|
|
This member function is mostly of interest to developers of new Fl_Surface_Device derived classes.
|
|
|
|
It allows to perform surface-specific operations necessary when this surface ceases to be current.
|
|
|
|
Each implementation should end with a call to Fl_Surface_Device::end_current(). */
|
2019-11-07 16:28:20 +03:00
|
|
|
virtual void end_current() { surface_ = 0;}
|
2016-11-30 10:09:48 +03:00
|
|
|
/** Constructor that sets the graphics driver to use for the created surface. */
|
|
|
|
Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver; }
|
2019-04-10 16:20:00 +03:00
|
|
|
/** Sets the graphics driver of this drawing surface. */
|
2021-08-27 15:52:43 +03:00
|
|
|
inline void driver(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver;}
|
2010-05-27 21:20:18 +04:00
|
|
|
public:
|
|
|
|
virtual void set_current(void);
|
2019-04-10 14:14:04 +03:00
|
|
|
virtual bool is_current();
|
2010-05-27 21:20:18 +04:00
|
|
|
/** \brief Returns the graphics driver of this drawing surface. */
|
2021-08-27 15:52:43 +03:00
|
|
|
inline Fl_Graphics_Driver *driver() {return pGraphicsDriver; }
|
2015-03-24 17:20:38 +03:00
|
|
|
/** The current drawing surface.
|
2021-02-27 11:08:05 +03:00
|
|
|
In other words, the Fl_Surface_Device object that currently receives all graphics requests.
|
|
|
|
\note It's possible to transiently remove the GUI scaling factor in place in the current
|
|
|
|
drawing surface with \ref fl_override_scale(). */
|
2015-12-16 10:18:34 +03:00
|
|
|
static inline Fl_Surface_Device *surface() {
|
2016-12-01 09:40:17 +03:00
|
|
|
return surface_ ? surface_ : default_surface();
|
2021-08-27 15:52:43 +03:00
|
|
|
}
|
2010-05-27 21:20:18 +04:00
|
|
|
/** \brief The destructor. */
|
2016-03-03 03:07:17 +03:00
|
|
|
virtual ~Fl_Surface_Device();
|
2016-12-07 18:09:52 +03:00
|
|
|
static void push_current(Fl_Surface_Device *new_current);
|
|
|
|
static Fl_Surface_Device *pop_current();
|
2010-05-27 21:20:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2023-10-31 21:07:31 +03:00
|
|
|
The computer's display.
|
|
|
|
When FLTK begins to access the computer's display, it creates an object of class Fl_Display_Device and makes
|
|
|
|
it the current drawing surface.
|
2010-05-27 21:20:18 +04:00
|
|
|
*/
|
2010-12-13 02:21:03 +03:00
|
|
|
class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
|
2011-03-01 14:58:36 +03:00
|
|
|
Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
|
2016-04-26 08:44:54 +03:00
|
|
|
public:
|
2015-04-29 01:02:48 +03:00
|
|
|
static Fl_Display_Device *display_device();
|
2010-05-27 21:20:18 +04:00
|
|
|
};
|
|
|
|
|
2010-12-12 19:13:55 +03:00
|
|
|
/**
|
|
|
|
This plugin socket allows the integration of new device drivers for special
|
2020-07-01 19:03:10 +03:00
|
|
|
window or screen types.
|
2016-10-16 18:12:46 +03:00
|
|
|
This class is not intended for use outside the FLTK library.
|
|
|
|
It is currently used to provide an automated printing
|
2014-11-06 19:48:57 +03:00
|
|
|
service and screen capture for OpenGL windows, if linked with fltk_gl.
|
2010-12-12 19:13:55 +03:00
|
|
|
*/
|
2022-08-20 11:16:32 +03:00
|
|
|
class Fl_Device_Plugin : public Fl_Plugin {
|
2010-12-12 19:13:55 +03:00
|
|
|
public:
|
|
|
|
/** \brief The constructor */
|
2011-10-02 10:25:13 +04:00
|
|
|
Fl_Device_Plugin(const char *pluginName)
|
|
|
|
: Fl_Plugin(klass(), pluginName) { }
|
2010-12-12 19:13:55 +03:00
|
|
|
/** \brief Returns the class name */
|
|
|
|
virtual const char *klass() { return "fltk:device"; }
|
|
|
|
/** \brief Returns the plugin name */
|
|
|
|
virtual const char *name() = 0;
|
2018-11-30 12:01:12 +03:00
|
|
|
/** \brief Prints a widget */
|
|
|
|
virtual int print(Fl_Widget* w) = 0;
|
|
|
|
/** Captures a rectangle of a widget as an image
|
2014-11-06 19:48:57 +03:00
|
|
|
\return The captured pixels as an RGB image
|
|
|
|
*/
|
|
|
|
virtual Fl_RGB_Image* rectangle_capture(Fl_Widget *widget, int x, int y, int w, int h) = 0;
|
2018-12-05 13:04:58 +03:00
|
|
|
/** Returns the OpenGL plugin */
|
|
|
|
static Fl_Device_Plugin *opengl_plugin();
|
2010-12-12 19:13:55 +03:00
|
|
|
};
|
|
|
|
|
2010-03-14 21:07:24 +03:00
|
|
|
#endif // Fl_Device_H
|