Implement correct size_changed() behaviour
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
#include "Polygon.hpp"
|
#include "Polygon.hpp"
|
||||||
#include <cairo/cairo.h>
|
#include <cairo/cairo.h>
|
||||||
#include <libsccolor.hpp>
|
#include <libsccolor.hpp>
|
||||||
#include <libscnumerics.hpp>
|
|
||||||
#include <libscscreensaver.hpp>
|
#include <libscscreensaver.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -18,10 +17,10 @@ public:
|
|||||||
~Polygon() = default;
|
~Polygon() = default;
|
||||||
|
|
||||||
void configure() override;
|
void configure() override;
|
||||||
int fps() const override;
|
|
||||||
void update() override;
|
void update() override;
|
||||||
void render() override;
|
void render() override;
|
||||||
std::string version() const override;
|
std::string version() const override;
|
||||||
|
void size_changed() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _num_points {};
|
int _num_points {};
|
||||||
@@ -29,7 +28,7 @@ private:
|
|||||||
double _max_speed {2.0};
|
double _max_speed {2.0};
|
||||||
double _stroke_width {1.0};
|
double _stroke_width {1.0};
|
||||||
Color _stroke_color {"#FFFFFF"};
|
Color _stroke_color {"#FFFFFF"};
|
||||||
Color _fill_color {"#006600"};
|
Color _fill_color {"#606060"};
|
||||||
std::vector<Point> _points;
|
std::vector<Point> _points;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,19 +43,24 @@ void Polygon::configure() {
|
|||||||
_fill_color = _j["fill-color"];
|
_fill_color = _j["fill-color"];
|
||||||
for (int i = 0; i < _num_points; ++i) {
|
for (int i = 0; i < _num_points; ++i) {
|
||||||
Point p;
|
Point p;
|
||||||
p.x = sc::random::double_between(0, _r.width);
|
p.x = random_x();
|
||||||
p.y = sc::random::double_between(0, _r.height);
|
p.y = random_y();
|
||||||
p.speed_x = sc::random::double_between(_min_speed, _max_speed);
|
p.speed_x = random_between(_min_speed, _max_speed);
|
||||||
p.speed_x *= sc::random::boolean() ? 1 : -1;
|
p.speed_x *= random_bool() ? 1 : -1;
|
||||||
p.speed_y = sc::random::double_between(_min_speed, _max_speed);
|
p.speed_y = random_between(_min_speed, _max_speed);
|
||||||
p.speed_y *= sc::random::boolean() ? 1 : -1;
|
p.speed_y *= random_bool() ? 1 : -1;
|
||||||
_points.push_back(p);
|
_points.push_back(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Polygon::version() const { return "1.0.0"; }
|
void Polygon::size_changed() {
|
||||||
|
for (Point &p : _points) {
|
||||||
|
p.x = random_x();
|
||||||
|
p.y = random_y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Polygon::fps() const { return 30; }
|
std::string Polygon::version() const { return "1.0.0"; }
|
||||||
|
|
||||||
void Polygon::update() {
|
void Polygon::update() {
|
||||||
for (Point& p : _points) {
|
for (Point& p : _points) {
|
||||||
|
|||||||
Reference in New Issue
Block a user