Compare commits

...

3 Commits

Author SHA1 Message Date
62b10ca8d0 Implement correct size_changed() behaviour 2025-10-27 11:21:58 +01:00
4ab4b99bd5 Remove libscnumerics dependency 2025-10-27 11:21:45 +01:00
f7db4d10ec Add call to new size_changed() method 2025-10-27 11:21:11 +01:00
3 changed files with 17 additions and 12 deletions

View File

@@ -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) {

View File

@@ -1,4 +1,4 @@
LDLIBS := -lcairo -lscscreensaver -lsccolor -lscnumerics LDLIBS := -lcairo -lscscreensaver -lsccolor
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
PROJ := $(shell basename $$(pwd)) PROJ := $(shell basename $$(pwd))
PLUGIN := $(PROJ).saver PLUGIN := $(PROJ).saver

View File

@@ -73,6 +73,7 @@ bool handle_window_resize(const SDL_Event& event, bool quit) {
cairo_rectangle_t r {0, 0, static_cast<double>(event.window.data1), static_cast<double>(event.window.data2)}; cairo_rectangle_t r {0, 0, static_cast<double>(event.window.data1), static_cast<double>(event.window.data2)};
if (main_saver) { if (main_saver) {
main_saver->setup(main_context.get(), r); main_saver->setup(main_context.get(), r);
main_saver->size_changed();
} }
} }
return quit; return quit;