diff options
| author | Manolo Gouy <Manolo> | 2015-12-16 07:18:34 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2015-12-16 07:18:34 +0000 |
| commit | 1b548ae1d54ff31faa94bc4fd13b98cf4989c613 (patch) | |
| tree | 44895c529f0c3438056000aeea000a0a1de8b799 | |
| parent | ca491166b9fb9be18a1d7cc86b782ec1b6fea71a (diff) | |
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
| -rw-r--r-- | FL/Fl_Device.H | 5 | ||||
| -rw-r--r-- | src/Fl_Device.cxx | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index 4d506faec..fc12c6364 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -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() {} }; diff --git a/src/Fl_Device.cxx b/src/Fl_Device.cxx index 566039149..a35227b23 100644 --- a/src/Fl_Device.cxx +++ b/src/Fl_Device.cxx @@ -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(); // |
