diff --git a/ScreensaverPlugin.cpp b/ScreensaverPlugin.cpp index c80a4a4..73afeb6 100644 --- a/ScreensaverPlugin.cpp +++ b/ScreensaverPlugin.cpp @@ -8,9 +8,9 @@ #include "ScreensaverPlugin.hpp" -ScreensaverPlugin::ScreensaverPlugin(cairo_t* context, const cairo_rectangle_t& rect) - : _c {context}, _r {rect}, _x_dist {rect.x, rect.width}, _y_dist {rect.y, rect.height} { - +void ScreensaverPlugin::setup(cairo_t* context, const cairo_rectangle_t& rect) { + _c = context; + _r = rect; } void ScreensaverPlugin::make_black() { @@ -44,13 +44,16 @@ cairo_rectangle_t ScreensaverPlugin::random_rect() { } double ScreensaverPlugin::random_x() { - return _x_dist(_eng); + std::uniform_real_distribution dist {0, _r.width}; + return dist(_eng); } double ScreensaverPlugin::random_y() { - return _y_dist(_eng); + std::uniform_real_distribution dist {0, _r.height}; + return dist(_eng); } double ScreensaverPlugin::random01() { - return _01_dist(_eng); + std::uniform_real_distribution dist {}; + return dist(_eng); } diff --git a/ScreensaverPlugin.hpp b/ScreensaverPlugin.hpp index 22a505f..d7e61ab 100644 --- a/ScreensaverPlugin.hpp +++ b/ScreensaverPlugin.hpp @@ -14,20 +14,18 @@ class ScreensaverPlugin { public: - ScreensaverPlugin(cairo_t* context, const cairo_rectangle_t& rect); + ScreensaverPlugin() = default; virtual ~ScreensaverPlugin() = default; + virtual void setup(cairo_t* context, const cairo_rectangle_t& rect) = 0; virtual void draw_frame() = 0; virtual int fps() const = 0; protected: - cairo_t* _c; - cairo_rectangle_t _r; - std::random_device _dev; + cairo_t* _c {nullptr}; + cairo_rectangle_t _r {}; + std::random_device _dev {}; std::default_random_engine _eng {_dev()}; - std::uniform_real_distribution<> _01_dist {}; - std::uniform_real_distribution<> _x_dist; - std::uniform_real_distribution<> _y_dist; void make_black(); cairo_rectangle_t random_rect();