84 lines
2.1 KiB
C++

#include "Huey.hpp"
#include <libsccolor.hpp>
#include <libscscreensaver.hpp>
#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 50;
}
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);
// build hue text
std::ostringstream hue_oss;
hue_oss << "hue: " << std::setw(3) << static_cast<int>(_hue) << "°";
hue_oss << ", saturation: " << static_cast<int>(hsb.s * 100) << "%";
hue_oss << ", brightness: " << static_cast<int>(hsb.b * 100) << "%";
// build rgb text
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);
// font setup
cairo_select_font_face(_c, "Hack", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(_c, 24);
// render hue and rgb texts in black (shadow)
cairo_set_source_rgb(_c, 0, 0, 0);
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());
// render hue and rgb texts in white, slightly offset
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;
}
}