Compare commits
10 Commits
38ee399483
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ffda761acc | |||
| 43363b53b7 | |||
| 3e37d54b5c | |||
| c862e584e0 | |||
| 680fd485c7 | |||
| fe3aa3b76c | |||
| f7080fb83d | |||
| 62b10ca8d0 | |||
| 4ab4b99bd5 | |||
| f7db4d10ec |
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Polygon::size_changed() {
|
||||||
|
for (Point &p : _points) {
|
||||||
|
p.x = random_x();
|
||||||
|
p.y = random_y();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Polygon::version() const { return "1.0.0"; }
|
std::string Polygon::version() const { return "1.1.0"; }
|
||||||
|
|
||||||
int Polygon::fps() const { return 30; }
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user