Compare commits

..

10 Commits

Author SHA1 Message Date
ffda761acc Use transparency for the fill color 2025-10-29 11:21:34 +01:00
43363b53b7 Bump version 1.0.0 → 1.1.0 2025-10-29 11:14:32 +01:00
3e37d54b5c Change fixed colors to animated colors 2025-10-29 11:13:45 +01:00
c862e584e0 Remove unnecessary empty line 2025-10-27 12:21:13 +01:00
680fd485c7 Bump version 1.2.0 → 1.2.1 2025-10-27 11:41:05 +01:00
fe3aa3b76c Use configure() instead of setup() for init 2025-10-27 11:39:40 +01:00
f7080fb83d Remove direct libscnumerics dependency
And use random_between() function
2025-10-27 11:36:20 +01:00
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
6 changed files with 41 additions and 31 deletions

View File

@@ -2,7 +2,6 @@
#include <cairo/cairo.h> #include <cairo/cairo.h>
#include <libscscreensaver.hpp> #include <libscscreensaver.hpp>
#include <libsccolor.hpp> #include <libsccolor.hpp>
#include <libscnumerics.hpp>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@@ -36,7 +35,7 @@ class FadingRects : public ScreensaverPlugin {
FadingRects() = default; FadingRects() = default;
~FadingRects() = default; ~FadingRects() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override; void configure() override;
int fps() const override; int fps() const override;
void update () override; void update () override;
void render() override; void render() override;
@@ -55,7 +54,7 @@ ScreensaverPlugin* create_instance() {
} }
std::string FadingRects::version() const { std::string FadingRects::version() const {
return "1.2.0"; return "1.2.1";
} }
int FadingRects::fps() const { int FadingRects::fps() const {
@@ -151,8 +150,7 @@ Color FadingRects::next_color() {
return Color {hsb}; return Color {hsb};
} }
void FadingRects::setup(cairo_t* context, const cairo_rectangle_t& rect) { void FadingRects::configure() {
ScreensaverPlugin::setup(context, rect); _hue = random_between(0.0, 360.0);
_hue = sc::random::double_between(0.0, 360.0);
_rects.clear(); _rects.clear();
} }

View File

@@ -1,4 +1,4 @@
LDLIBS := -lcairo -lscscreensaver -lscnumerics -lsccolor 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

@@ -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,19 +17,19 @@ 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 {};
double _min_speed {0.2}; double _min_speed {0.2};
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 _color {"#FFFFFF"};
Color _fill_color {"#006600"};
std::vector<Point> _points; std::vector<Point> _points;
double _hue;
}; };
ScreensaverPlugin *create_instance() { return new Polygon; } ScreensaverPlugin *create_instance() { return new Polygon; }
@@ -40,25 +39,30 @@ void Polygon::configure() {
_min_speed = _j["min-speed"]; _min_speed = _j["min-speed"];
_max_speed = _j["max-speed"]; _max_speed = _j["max-speed"];
_stroke_width = _j["stroke-width"]; _stroke_width = _j["stroke-width"];
_stroke_color = _j["stroke-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);
} }
_hue = random_between(0.0, 360.0);
} }
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.1.0"; }
void Polygon::update() { void Polygon::update() {
// update points
for (Point& p : _points) { for (Point& p : _points) {
p.x += p.speed_x; p.x += p.speed_x;
if (p.x < 0 || p.x > _r.width) { if (p.x < 0 || p.x > _r.width) {
@@ -71,6 +75,17 @@ void Polygon::update() {
p.y += p.speed_y; p.y += p.speed_y;
} }
} }
// update hue
_hue += 0.5;
if (_hue >= 360.0) {
_hue -= 360.0;
}
// construct color
HSB hsb;
hsb.h = _hue;
hsb.s = 1.0;
hsb.b = 0.7;
_color = hsb;
} }
void Polygon::render() { void Polygon::render() {
@@ -83,11 +98,10 @@ void Polygon::render() {
cairo_line_to(_c, p.x, p.y); cairo_line_to(_c, p.x, p.y);
} }
cairo_close_path(_c); cairo_close_path(_c);
RGB c = RGB(_stroke_color); RGB c = RGB(_color);
cairo_set_source_rgb(_c, c.r, c.g, c.b); cairo_set_source_rgb(_c, c.r, c.g, c.b);
cairo_set_line_width(_c, _stroke_width); cairo_set_line_width(_c, _stroke_width);
cairo_stroke_preserve(_c); cairo_stroke_preserve(_c);
RGB f = RGB(_fill_color); cairo_set_source_rgba(_c, c.r, c.g, c.b, 0.2);
cairo_set_source_rgb(_c, f.r, f.g, f.b);
cairo_fill(_c); cairo_fill(_c);
} }

View File

@@ -1,8 +1,6 @@
{ {
"num-points": 7, "num-points": 11,
"min-speed": 0.2, "min-speed": 0.2,
"max-speed": 2.0, "max-speed": 2.0,
"stroke-width": 3.0, "stroke-width": 2.0
"stroke-color": "#00D000",
"fill-color": "#006000"
} }

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

@@ -42,7 +42,6 @@ void print_help() {
void list_plugins() { void list_plugins() {
for (const auto& elem : sc::plugin<ScreensaverPlugin>::all()) { for (const auto& elem : sc::plugin<ScreensaverPlugin>::all()) {
std::cout << elem.first << " (" << elem.second()->version() << ")\n"; std::cout << elem.first << " (" << elem.second()->version() << ")\n";
} }
} }
@@ -73,6 +72,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;