Implement correct size_changed() behaviour

This commit is contained in:
2025-10-27 11:21:58 +01:00
parent 4ab4b99bd5
commit 62b10ca8d0

View File

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