Compare commits
14 Commits
700f094642
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| ffda761acc | |||
| 43363b53b7 | |||
| 3e37d54b5c | |||
| c862e584e0 | |||
| 680fd485c7 | |||
| fe3aa3b76c | |||
| f7080fb83d | |||
| 62b10ca8d0 | |||
| 4ab4b99bd5 | |||
| f7db4d10ec | |||
| 38ee399483 | |||
| 6e1ddf1b86 | |||
| 6ed3bdb941 | |||
| 0516ab3f51 |
@@ -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
|
||||||
|
|||||||
53
modules/Polygon/Makefile
Normal file
53
modules/Polygon/Makefile
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
include premake.make
|
||||||
|
|
||||||
|
# some important install locations
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
DATADIR ?= $(PREFIX)/share
|
||||||
|
INSTALLDIR ?= $(DATADIR)/$(INSTALLDIRNAME)
|
||||||
|
|
||||||
|
SRCS := $(wildcard *.cpp)
|
||||||
|
OBJS := $(SRCS:.cpp=.o)
|
||||||
|
DEPS := $(SRCS:.cpp=.dep)
|
||||||
|
|
||||||
|
CXX ?= g++
|
||||||
|
|
||||||
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
||||||
|
CXXFLAGS += -g3 -std=c++20 -fPIC
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
|
CXXFLAGS += -D DEBUG -O0
|
||||||
|
else
|
||||||
|
CXXFLAGS += -D NDEBUG -O3
|
||||||
|
endif
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $*.dep -c $<
|
||||||
|
|
||||||
|
%.dep: ;
|
||||||
|
|
||||||
|
.PHONY: all clean install uninstall
|
||||||
|
|
||||||
|
all: $(PLUGIN)
|
||||||
|
|
||||||
|
$(PLUGIN): $(OBJS)
|
||||||
|
ifeq ($(UNAME_S),Darwin)
|
||||||
|
$(CXX) -g3 -dynamiclib -o $(PLUGIN) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
|
else
|
||||||
|
$(CXX) -g3 -shared -o $(PLUGIN) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
-include $(DEPS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJS) $(DEPS) $(PLUGIN)
|
||||||
|
|
||||||
|
$(INSTALLDIR):
|
||||||
|
install -m 0755 -d $@
|
||||||
|
|
||||||
|
install: $(INSTALLDIR)
|
||||||
|
install -m 0644 $(PLUGIN) $(INSTALLDIR)
|
||||||
|
ifdef EXTRAFILES
|
||||||
|
install -m 0644 $(EXTRAFILES) $(INSTALLDIR)
|
||||||
|
endif
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES))
|
||||||
107
modules/Polygon/Polygon.cpp
Normal file
107
modules/Polygon/Polygon.cpp
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
#include "Polygon.hpp"
|
||||||
|
#include <cairo/cairo.h>
|
||||||
|
#include <libsccolor.hpp>
|
||||||
|
#include <libscscreensaver.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Point {
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
double speed_x;
|
||||||
|
double speed_y;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Polygon : public ScreensaverPlugin {
|
||||||
|
public:
|
||||||
|
Polygon() = default;
|
||||||
|
~Polygon() = default;
|
||||||
|
|
||||||
|
void configure() override;
|
||||||
|
void update() override;
|
||||||
|
void render() override;
|
||||||
|
std::string version() const override;
|
||||||
|
void size_changed() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int _num_points {};
|
||||||
|
double _min_speed {0.2};
|
||||||
|
double _max_speed {2.0};
|
||||||
|
double _stroke_width {1.0};
|
||||||
|
Color _color {"#FFFFFF"};
|
||||||
|
std::vector<Point> _points;
|
||||||
|
double _hue;
|
||||||
|
};
|
||||||
|
|
||||||
|
ScreensaverPlugin *create_instance() { return new Polygon; }
|
||||||
|
|
||||||
|
void Polygon::configure() {
|
||||||
|
_num_points = _j["num-points"];
|
||||||
|
_min_speed = _j["min-speed"];
|
||||||
|
_max_speed = _j["max-speed"];
|
||||||
|
_stroke_width = _j["stroke-width"];
|
||||||
|
for (int i = 0; i < _num_points; ++i) {
|
||||||
|
Point p;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
_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.1.0"; }
|
||||||
|
|
||||||
|
void Polygon::update() {
|
||||||
|
// update points
|
||||||
|
for (Point& p : _points) {
|
||||||
|
p.x += p.speed_x;
|
||||||
|
if (p.x < 0 || p.x > _r.width) {
|
||||||
|
p.speed_x *= -1;
|
||||||
|
p.x += p.speed_x;
|
||||||
|
}
|
||||||
|
p.y += p.speed_y;
|
||||||
|
if (p.y < 0 || p.y > _r.height) {
|
||||||
|
p.speed_y *= -1;
|
||||||
|
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() {
|
||||||
|
make_black();
|
||||||
|
Point first = _points[0];
|
||||||
|
cairo_new_path(_c);
|
||||||
|
cairo_move_to(_c, first.x, first.y);
|
||||||
|
for (size_t i = 1; i < _points.size(); ++i) {
|
||||||
|
Point& p = _points[i];
|
||||||
|
cairo_line_to(_c, p.x, p.y);
|
||||||
|
}
|
||||||
|
cairo_close_path(_c);
|
||||||
|
RGB c = RGB(_color);
|
||||||
|
cairo_set_source_rgb(_c, c.r, c.g, c.b);
|
||||||
|
cairo_set_line_width(_c, _stroke_width);
|
||||||
|
cairo_stroke_preserve(_c);
|
||||||
|
cairo_set_source_rgba(_c, c.r, c.g, c.b, 0.2);
|
||||||
|
cairo_fill(_c);
|
||||||
|
}
|
||||||
10
modules/Polygon/Polygon.hpp
Normal file
10
modules/Polygon/Polygon.hpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _Polygon_H_
|
||||||
|
#define _Polygon_H_
|
||||||
|
|
||||||
|
class ScreensaverPlugin;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
ScreensaverPlugin* create_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _Polygon_H_
|
||||||
6
modules/Polygon/Polygon.json
Normal file
6
modules/Polygon/Polygon.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"num-points": 11,
|
||||||
|
"min-speed": 0.2,
|
||||||
|
"max-speed": 2.0,
|
||||||
|
"stroke-width": 2.0
|
||||||
|
}
|
||||||
6
modules/Polygon/premake.make
Normal file
6
modules/Polygon/premake.make
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
LDLIBS := -lcairo -lscscreensaver -lsccolor
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
PROJ := $(shell basename $$(pwd))
|
||||||
|
PLUGIN := $(PROJ).saver
|
||||||
|
INSTALLDIRNAME := screensaver/plugins
|
||||||
|
EXTRAFILES := $(PROJ).json
|
||||||
@@ -9,12 +9,17 @@ class {MODULE} : public ScreensaverPlugin {
|
|||||||
int fps() const override;
|
int fps() const override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void render() override;
|
void render() override;
|
||||||
|
std::string version() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScreensaverPlugin* create_instance() {
|
ScreensaverPlugin* create_instance() {
|
||||||
return new {MODULE};
|
return new {MODULE};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string {MODULE}::version() const {
|
||||||
|
return "1.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
int {MODULE}::fps() const {
|
int {MODULE}::fps() const {
|
||||||
return 30;
|
return 30;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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