Fl_Device.H 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // "$Id: Fl_Device.H 12226 2017-04-25 12:42:22Z manolo $"
  3. //
  4. // Definition of classes Fl_Surface_Device, Fl_Display_Device
  5. // for the Fast Light Tool Kit (FLTK).
  6. //
  7. // Copyright 2010-2017 by Bill Spitzak and others.
  8. //
  9. // This library is free software. Distribution and use rights are outlined in
  10. // the file "COPYING" which should have been included with this file. If this
  11. // file is missing or damaged, see the license at:
  12. //
  13. // http://www.fltk.org/COPYING.php
  14. //
  15. // Please report all bugs and problems on the following page:
  16. //
  17. // http://www.fltk.org/str.php
  18. //
  19. /** \file Fl_Device.H
  20. \brief declaration of classes Fl_Surface_Device, Fl_Display_Device, Fl_Device_Plugin.
  21. */
  22. #ifndef Fl_Device_H
  23. #define Fl_Device_H
  24. #include <FL/Fl_Plugin.H>
  25. #include <stdlib.h>
  26. class Fl_Graphics_Driver;
  27. class Fl_RGB_Image;
  28. class Fl_Widget;
  29. /**
  30. A drawing surface that's susceptible to receive graphical output.
  31. Any FLTK application has at any time a current drawing surface to which all drawing requests are directed.
  32. The current surface is given by Fl_Surface_Device::surface().
  33. When main() begins running, the current drawing surface has been set to the computer's display,
  34. an instance of the Fl_Display_Device class.
  35. A drawing surface other than the computer's display, is typically used as follows:
  36. <ol><li> Create \c surface, an object from a particular Fl_Surface_Device derived class (e.g., Fl_Copy_Surface, Fl_Printer).
  37. <li> Call \c Fl_Surface_Device::push_current(surface); to redirect all graphics requests to \c surface which becomes the new
  38. current drawing surface (not necessary with class Fl_Printer because it is done by Fl_Printer::start_job()).
  39. <li> At this point all of the \ref fl_drawings (e.g., fl_rect()) or the \ref fl_attributes or \ref drawing_images functions
  40. (e.g., fl_draw_image(), Fl_Image::draw()) operate on the new current drawing surface.
  41. Certain drawing surfaces allow additional ways to draw to them (e.g., Fl_Printer::print_widget(), Fl_Image_Surface::draw()).
  42. <li> After all drawing requests have been performed, redirect graphics requests back to their previous destination
  43. with \c Fl_Surface_Device::pop_current();.
  44. <li> Delete \c surface.
  45. </ol>
  46. For back-compatibility, it is also possible to use the Fl_Surface_Device::set_current() member function
  47. to change the current drawing surface, once to the new surface, once to the previous one.
  48. */
  49. class FL_EXPORT Fl_Surface_Device {
  50. /** The graphics driver in use by this surface. */
  51. Fl_Graphics_Driver *pGraphicsDriver;
  52. static Fl_Surface_Device *surface_; // the surface that currently receives graphics requests
  53. static Fl_Surface_Device *default_surface(); // create surface if none exists yet
  54. /* Some drawing surfaces (e.g., Fl_XXX_Image_Surface_Driver) re-implement this.
  55. Gets called each time a surface ceases to be the current drawing surface.
  56. The next_current argument gives the drawing surface that will become current next */
  57. virtual void end_current_(Fl_Surface_Device *next_current) {}
  58. protected:
  59. /** Constructor that sets the graphics driver to use for the created surface. */
  60. Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver; }
  61. public:
  62. /** A string that identifies each subclass of Fl_Device.
  63. Function class_name() applied to a device of this class returns this string.
  64. */
  65. static const char *class_id;
  66. /**
  67. Returns the name of the class of this object.
  68. Use of the class_name() function is discouraged because it will be removed from future FLTK versions.
  69. The class of an instance of an Fl_Device subclass can be checked with code such as:
  70. \code
  71. if ( instance->class_name() == Fl_Printer::class_id ) { ... }
  72. \endcode
  73. */
  74. virtual const char *class_name() {return class_id;};
  75. virtual void set_current(void);
  76. /** \brief Sets the graphics driver of this drawing surface. */
  77. inline void driver(Fl_Graphics_Driver *graphics_driver) {pGraphicsDriver = graphics_driver;};
  78. /** \brief Returns the graphics driver of this drawing surface. */
  79. inline Fl_Graphics_Driver *driver() {return pGraphicsDriver; };
  80. /** The current drawing surface.
  81. In other words, the Fl_Surface_Device object that currently receives all graphics requests */
  82. static inline Fl_Surface_Device *surface() {
  83. return surface_ ? surface_ : default_surface();
  84. };
  85. /** \brief The destructor. */
  86. virtual ~Fl_Surface_Device();
  87. static void push_current(Fl_Surface_Device *new_current);
  88. static Fl_Surface_Device *pop_current();
  89. };
  90. /**
  91. A display to which the computer can draw.
  92. When the program begins running, an object of class Fl_Display_Device has been created and made the current drawing surface.
  93. */
  94. class FL_EXPORT Fl_Display_Device : public Fl_Surface_Device {
  95. Fl_Display_Device(Fl_Graphics_Driver *graphics_driver);
  96. public:
  97. static Fl_Display_Device *display_device();
  98. static const char *class_id;
  99. const char *class_name() {return class_id;};
  100. };
  101. /**
  102. This plugin socket allows the integration of new device drivers for special
  103. window or screen types.
  104. This class is not intended for use outside the FLTK library.
  105. It is currently used to provide an automated printing
  106. service and screen capture for OpenGL windows, if linked with fltk_gl.
  107. */
  108. class FL_EXPORT Fl_Device_Plugin : public Fl_Plugin {
  109. public:
  110. /** \brief The constructor */
  111. Fl_Device_Plugin(const char *pluginName)
  112. : Fl_Plugin(klass(), pluginName) { }
  113. /** \brief Returns the class name */
  114. virtual const char *klass() { return "fltk:device"; }
  115. /** \brief Returns the plugin name */
  116. virtual const char *name() = 0;
  117. /** \brief Prints a widget
  118. \param w the widget
  119. \param x,y offsets where to print relatively to coordinates origin
  120. \param height height of the current drawing area
  121. */
  122. virtual int print(Fl_Widget* w, int x, int y, int height) = 0;
  123. /** captures a rectangle of a widget as an image
  124. \return The captured pixels as an RGB image
  125. */
  126. virtual Fl_RGB_Image* rectangle_capture(Fl_Widget *widget, int x, int y, int w, int h) = 0;
  127. };
  128. #endif // Fl_Device_H
  129. //
  130. // End of "$Id: Fl_Device.H 12226 2017-04-25 12:42:22Z manolo $".
  131. //