moved all plugin subprojects into modules directory

This commit is contained in:
Bob Polis
2021-01-25 19:44:46 +01:00
parent 9491d24907
commit f8cd0a77ac
9 changed files with 0 additions and 0 deletions

@ -0,0 +1,158 @@
//
// FadingRects.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "FadingRects.hpp"
#include <libscscreensaver.hpp>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
const int default_frames_per_rect {10};
const int fade_time {5}; // seconds
enum class FadingState {
fadein,
sustain,
fadeout
};
struct Rect {
double x {0};
double y {0};
double width {0};
double height {0};
double red {0.0};
double green {0.0};
double blue {0.0};
double alpha {1.0};
double cur_alpha {0.0};
double delta {0.0};
FadingState state {FadingState::fadein};
int sustain_frame {0};
double line_width {2.0};
};
class FadingRects : public ScreensaverPlugin {
public:
FadingRects() = default;
~FadingRects() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override;
int fps() const override;
void update () override;
void render() override;
private:
double _hue {0.0};
std::vector<Rect> _rects;
int _frames_per_rect {default_frames_per_rect};
Color next_color();
};
ScreensaverPlugin* create_instance() {
return new FadingRects;
}
int FadingRects::fps() const {
return 20;
}
void FadingRects::update() {
// adjust rects
for (Rect& r : _rects) {
switch (r.state) {
case FadingState::fadein:
r.cur_alpha += r.delta;
if (r.cur_alpha > r.alpha) {
r.cur_alpha = r.alpha;
r.state = FadingState::sustain;
}
break;
case FadingState::sustain:
r.sustain_frame++;
if (r.sustain_frame > fps()) {
r.state = FadingState::fadeout;
}
break;
case FadingState::fadeout:
r.cur_alpha -= r.delta;
break;
}
}
auto it = std::remove_if(_rects.begin(), _rects.end(), [](const Rect& r) {
return r.cur_alpha < 0.0;
});
_rects.erase(it, _rects.end());
// add new rect, if allowed
_frames_per_rect--;
if (_frames_per_rect == 0) {
_frames_per_rect = default_frames_per_rect;
cairo_rectangle_t rr {_r};
rr.x -= 50.0;
rr.y -= 50.0;
rr.width += 100.0;
rr.height += 100.0;
rr = random_rect_in_rect(rr);
RGB rgb {RGB(next_color())};
Rect rect;
rect.red = rgb.r;
rect.green = rgb.g;
rect.blue = rgb.b;
rect.alpha = random01();
rect.cur_alpha = 0.0;
rect.state = FadingState::fadein;
rect.sustain_frame = 0;
rect.delta = rect.alpha / (fade_time * fps());
rect.line_width = random_between(1.0, 20.0);
rect.x = rr.x;
rect.y = rr.y;
rect.width = rr.width;
rect.height = rr.height;
_rects.push_back(rect);
}
}
void FadingRects::render() {
// clear screen
make_black();
// render rects
for (Rect r : _rects) {
cairo_set_source_rgba(_c, r.red, r.green, r.blue, r.cur_alpha);
cairo_rectangle_t rect;
rect.x = r.x;
rect.y = r.y;
rect.width = r.width;
rect.height = r.height;
rounded_rect(rect, 10.0);
cairo_set_line_width(_c, r.line_width);
cairo_stroke(_c);
}
}
Color FadingRects::next_color() {
_hue += 0.5;
if (_hue >= 360.0) {
_hue -= 360.0;
}
HSB hsb;
hsb.h = _hue;
hsb.s = random01();
hsb.b = random01();
return Color {hsb};
}
void FadingRects::setup(cairo_t* context, const cairo_rectangle_t& rect) {
ScreensaverPlugin::setup(context, rect);
std::uniform_real_distribution<double> dist {0.0, 360.0};
_hue = dist(_eng);
}

@ -0,0 +1,18 @@
//
// FadingRects.hpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#ifndef _Huey_H_
#define _Huey_H_
class ScreensaverPlugin;
extern "C" {
ScreensaverPlugin* create_instance();
}
#endif // _Huey_H_

@ -0,0 +1,62 @@
LIBNAME := $(shell basename $$(pwd))
MAJOR := 1
MINOR := 0.0
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME)
else
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR)
endif
PREFIX ?= ..
LIBDIR ?= $(PREFIX)/plugins
SRCS := $(wildcard *.cpp)
OBJS := $(subst .cpp,.o,$(SRCS))
DEPS := $(subst .cpp,.d,$(SRCS))
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp))
CXX ?= g++
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
else
CXXFLAGS += -D NDEBUG -O3
endif
LDLIBS := -lcairo -lscscreensaver
RM := /bin/rm -f
INSTALL := /usr/bin/install -c
.PHONY: all clean install
all: $(REALNAME)
$(REALNAME): $(OBJS) $(DEPS)
ifeq ($(UNAME_S),Darwin)
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS)
else
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
endif
%.o: %.cpp %.d Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
-include *.d
%.d: ;
clean:
$(RM) $(OBJS) $(DEPS) $(REALNAME)
install: $(REALNAME)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR)/$(LIBNAME).saver

81
modules/huey/Huey.cpp Normal file

@ -0,0 +1,81 @@
//
// Huey.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "Huey.hpp"
#include <libscscreensaver.hpp>
#include <string>
#include <sstream>
#include <iomanip>
class Huey : public ScreensaverPlugin {
public:
Huey() = default;
~Huey() = default;
int fps() const override;
void update() override;
void render() override;
private:
double _hue {0};
};
ScreensaverPlugin* create_instance() {
return new Huey;
}
int Huey::fps() const {
return 5;
}
void Huey::update() {
}
void Huey::render() {
// next color
HSB hsb;
hsb.h = _hue;
hsb.s = 1.0;
hsb.b = 0.4;
// convert to rgb
Color color {hsb};
RGB rgb {RGB(color)};
// setup color, fill whole window
cairo_set_source_rgb(_c, rgb.r, rgb.g, rgb.b);
cairo_rectangle(_c, _r.x, _r.y, _r.width, _r.height);
cairo_fill(_c);
// show hue value
std::ostringstream hue_oss;
hue_oss << "hue: " << std::setw(3) << static_cast<int>(_hue);
std::ostringstream rgb_oss;
rgb_oss << "red: " << std::setw(3) << static_cast<int>(255 * rgb.r);
rgb_oss << ", green: " << std::setw(3) << static_cast<int>(255 * rgb.g);
rgb_oss << ", blue: " << std::setw(3) << static_cast<int>(255 * rgb.b);
cairo_set_source_rgb(_c, 0, 0, 0);
cairo_select_font_face(_c, "Hack", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(_c, 24);
cairo_move_to(_c, 31, 51);
cairo_show_text(_c, hue_oss.str().c_str());
cairo_move_to(_c, 31, 87);
cairo_show_text(_c, rgb_oss.str().c_str());
cairo_set_source_rgb(_c, 1, 1, 1);
cairo_move_to(_c, 29, 49);
cairo_show_text(_c, hue_oss.str().c_str());
cairo_move_to(_c, 29, 85);
cairo_show_text(_c, rgb_oss.str().c_str());
// update for next frame
_hue += 0.5;
if (_hue >= 360.0) {
_hue -= 360.0;
}
}

18
modules/huey/Huey.hpp Normal file

@ -0,0 +1,18 @@
//
// Skembo.hpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#ifndef _Huey_H_
#define _Huey_H_
class ScreensaverPlugin;
extern "C" {
ScreensaverPlugin* create_instance();
}
#endif // _Huey_H_

62
modules/huey/Makefile Normal file

@ -0,0 +1,62 @@
LIBNAME := $(shell basename $$(pwd))
MAJOR := 1
MINOR := 0.0
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME)
else
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR)
endif
PREFIX ?= ..
LIBDIR ?= $(PREFIX)/plugins
SRCS := $(wildcard *.cpp)
OBJS := $(subst .cpp,.o,$(SRCS))
DEPS := $(subst .cpp,.d,$(SRCS))
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp))
CXX ?= g++
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
else
CXXFLAGS += -D NDEBUG -O3
endif
LDLIBS := -lcairo -lscscreensaver
RM := /bin/rm -f
INSTALL := /usr/bin/install -c
.PHONY: all clean install
all: $(REALNAME)
$(REALNAME): $(OBJS) $(DEPS)
ifeq ($(UNAME_S),Darwin)
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS)
else
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
endif
%.o: %.cpp %.d Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
-include *.d
%.d: ;
clean:
$(RM) $(OBJS) $(DEPS) $(REALNAME)
install: $(REALNAME)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR)/$(LIBNAME).saver

62
modules/rects/Makefile Normal file

@ -0,0 +1,62 @@
LIBNAME := $(shell basename $$(pwd))
MAJOR := 1
MINOR := 0.0
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME)
else
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR)
endif
PREFIX ?= ..
LIBDIR ?= $(PREFIX)/plugins
SRCS := $(wildcard *.cpp)
OBJS := $(subst .cpp,.o,$(SRCS))
DEPS := $(subst .cpp,.d,$(SRCS))
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp))
CXX ?= g++
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
else
CXXFLAGS += -D NDEBUG -O3
endif
LDLIBS := -lcairo -lscscreensaver
RM := /bin/rm -f
INSTALL := /usr/bin/install -c
.PHONY: all clean install
all: $(REALNAME)
$(REALNAME): $(OBJS) $(DEPS)
ifeq ($(UNAME_S),Darwin)
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS)
else
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
endif
%.o: %.cpp %.d Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
-include *.d
%.d: ;
clean:
$(RM) $(OBJS) $(DEPS) $(REALNAME)
install: $(REALNAME)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR)/$(LIBNAME).saver

@ -0,0 +1,39 @@
//
// RectSaver.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "RectSaver.hpp"
#include <libscscreensaver.hpp>
class RectSaver : public ScreensaverPlugin {
public:
RectSaver() = default;
~RectSaver() = default;
int fps() const override;
void update() override;
void render() override;
};
ScreensaverPlugin* create_instance() {
return new RectSaver;
}
int RectSaver::fps() const {
return 2;
}
void RectSaver::update() {
}
void RectSaver::render() {
cairo_set_source_rgba(_c, random01(), random01(), random01(), random01());
cairo_rectangle_t rect {random_rect()};
cairo_rectangle(_c, rect.x, rect.y, rect.width, rect.height);
cairo_fill(_c);
}

@ -0,0 +1,18 @@
//
// RectSaver.hpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#ifndef _RectSaver_H_
#define _RectSaver_H_
class ScreensaverPlugin;
extern "C" {
ScreensaverPlugin* create_instance();
}
#endif // _RectSaver_H_