2020-10-29 09:19:17 +01:00
|
|
|
#include "Huey.hpp"
|
|
|
|
#include <libscscreensaver.hpp>
|
2020-10-30 23:53:15 +01:00
|
|
|
#include <string>
|
2020-10-31 00:42:32 +01:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2020-10-29 09:19:17 +01:00
|
|
|
|
|
|
|
class Huey : public ScreensaverPlugin {
|
|
|
|
public:
|
|
|
|
Huey() = default;
|
|
|
|
~Huey() = default;
|
|
|
|
|
|
|
|
int fps() const override;
|
2020-11-15 13:16:49 +01:00
|
|
|
void update() override;
|
|
|
|
void render() override;
|
2020-10-29 09:19:17 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
double _hue {0};
|
|
|
|
};
|
|
|
|
|
|
|
|
ScreensaverPlugin* create_instance() {
|
|
|
|
return new Huey;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Huey::fps() const {
|
2021-11-11 10:33:37 +01:00
|
|
|
return 50;
|
2020-10-29 09:19:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-15 13:16:49 +01:00
|
|
|
void Huey::update() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Huey::render() {
|
2020-10-29 09:19:17 +01:00
|
|
|
// 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);
|
|
|
|
|
2021-08-18 12:28:27 +02:00
|
|
|
// build hue text
|
2020-10-31 00:42:32 +01:00
|
|
|
std::ostringstream hue_oss;
|
2020-10-31 00:50:54 +01:00
|
|
|
hue_oss << "hue: " << std::setw(3) << static_cast<int>(_hue);
|
2021-08-18 12:28:27 +02:00
|
|
|
|
|
|
|
// build rgb text
|
2020-10-31 00:42:32 +01:00
|
|
|
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);
|
2021-08-18 12:28:27 +02:00
|
|
|
|
|
|
|
// font setup
|
2023-11-22 23:46:22 +00:00
|
|
|
cairo_select_font_face(_c, "Hack", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2020-10-30 23:53:15 +01:00
|
|
|
cairo_set_font_size(_c, 24);
|
2021-08-18 12:28:27 +02:00
|
|
|
|
|
|
|
// render hue and rgb texts in black (shadow)
|
|
|
|
cairo_set_source_rgb(_c, 0, 0, 0);
|
2020-10-31 00:42:32 +01:00
|
|
|
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());
|
2021-08-18 12:28:27 +02:00
|
|
|
|
|
|
|
// render hue and rgb texts in white, sligtly offset
|
2020-10-30 23:53:15 +01:00
|
|
|
cairo_set_source_rgb(_c, 1, 1, 1);
|
|
|
|
cairo_move_to(_c, 29, 49);
|
2020-10-31 00:42:32 +01:00
|
|
|
cairo_show_text(_c, hue_oss.str().c_str());
|
|
|
|
cairo_move_to(_c, 29, 85);
|
|
|
|
cairo_show_text(_c, rgb_oss.str().c_str());
|
2020-10-30 23:53:15 +01:00
|
|
|
|
2020-10-29 09:19:17 +01:00
|
|
|
// update for next frame
|
2020-10-31 00:50:54 +01:00
|
|
|
_hue += 0.5;
|
2020-10-30 23:53:15 +01:00
|
|
|
if (_hue >= 360.0) {
|
2020-10-29 09:19:17 +01:00
|
|
|
_hue -= 360.0;
|
|
|
|
}
|
|
|
|
}
|