changed to give it a default constructor

This commit is contained in:
Bob Polis 2020-10-27 15:23:35 +01:00
parent 5c5c702c91
commit 0f1a681908
2 changed files with 14 additions and 13 deletions

View File

@ -8,9 +8,9 @@
#include "ScreensaverPlugin.hpp" #include "ScreensaverPlugin.hpp"
ScreensaverPlugin::ScreensaverPlugin(cairo_t* context, const cairo_rectangle_t& rect) void ScreensaverPlugin::setup(cairo_t* context, const cairo_rectangle_t& rect) {
: _c {context}, _r {rect}, _x_dist {rect.x, rect.width}, _y_dist {rect.y, rect.height} { _c = context;
_r = rect;
} }
void ScreensaverPlugin::make_black() { void ScreensaverPlugin::make_black() {
@ -44,13 +44,16 @@ cairo_rectangle_t ScreensaverPlugin::random_rect() {
} }
double ScreensaverPlugin::random_x() { double ScreensaverPlugin::random_x() {
return _x_dist(_eng); std::uniform_real_distribution<double> dist {0, _r.width};
return dist(_eng);
} }
double ScreensaverPlugin::random_y() { double ScreensaverPlugin::random_y() {
return _y_dist(_eng); std::uniform_real_distribution<double> dist {0, _r.height};
return dist(_eng);
} }
double ScreensaverPlugin::random01() { double ScreensaverPlugin::random01() {
return _01_dist(_eng); std::uniform_real_distribution<double> dist {};
return dist(_eng);
} }

View File

@ -14,20 +14,18 @@
class ScreensaverPlugin { class ScreensaverPlugin {
public: public:
ScreensaverPlugin(cairo_t* context, const cairo_rectangle_t& rect); ScreensaverPlugin() = default;
virtual ~ScreensaverPlugin() = default; virtual ~ScreensaverPlugin() = default;
virtual void setup(cairo_t* context, const cairo_rectangle_t& rect) = 0;
virtual void draw_frame() = 0; virtual void draw_frame() = 0;
virtual int fps() const = 0; virtual int fps() const = 0;
protected: protected:
cairo_t* _c; cairo_t* _c {nullptr};
cairo_rectangle_t _r; cairo_rectangle_t _r {};
std::random_device _dev; std::random_device _dev {};
std::default_random_engine _eng {_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(); void make_black();
cairo_rectangle_t random_rect(); cairo_rectangle_t random_rect();