Running FLTK in static initializers (cont'd):

the static method Fl_Surface_Device::surface() can be called before main() starts.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10970 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2015-12-16 07:18:34 +00:00
parent ca491166b9
commit 1b548ae1d5
2 changed files with 11 additions and 1 deletions

View File

@ -551,6 +551,7 @@ class FL_EXPORT Fl_Surface_Device : public Fl_Device {
/** \brief The graphics driver in use by this surface. */
Fl_Graphics_Driver *_driver;
static Fl_Surface_Device *_surface; // the surface that currently receives graphics output
static Fl_Surface_Device *default_surface(); // create surface is none exists yet
protected:
/** \brief Constructor that sets the graphics driver to use for the created surface. */
Fl_Surface_Device(Fl_Graphics_Driver *graphics_driver) {_driver = graphics_driver; };
@ -564,7 +565,9 @@ public:
inline Fl_Graphics_Driver *driver() {return _driver; };
/** The current drawing surface.
In other words, the Fl_Surface_Device object that currently receives all graphics output */
static inline Fl_Surface_Device *surface() {return _surface; };
static inline Fl_Surface_Device *surface() {
return _surface ? _surface : default_surface();
};
/** \brief The destructor. */
virtual ~Fl_Surface_Device() {}
};

View File

@ -93,6 +93,13 @@ Fl_Display_Device *Fl_Display_Device::display_device() {
return display;
};
Fl_Surface_Device *Fl_Surface_Device::default_surface()
{
return Fl_Display_Device::display_device();
}
Fl_Display_Device *Fl_Display_Device::_display = Fl_Display_Device::display_device();
//