2020-10-29 09:19:17 +01:00
|
|
|
//
|
|
|
|
// Huey.cpp
|
|
|
|
// screensaver
|
|
|
|
//
|
|
|
|
// Created by Bob Polis at 2020-10-26
|
|
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#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 {
|
2020-10-31 00:50:54 +01:00
|
|
|
return 5;
|
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);
|
|
|
|
|
2020-10-30 23:53:15 +01:00
|
|
|
// show hue value
|
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);
|
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);
|
2020-10-30 23:53:15 +01:00
|
|
|
cairo_set_source_rgb(_c, 0, 0, 0);
|
2021-08-18 11:31:10 +02:00
|
|
|
cairo_select_font_face(_c, "JuliaMono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2020-10-30 23:53:15 +01:00
|
|
|
cairo_set_font_size(_c, 24);
|
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());
|
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;
|
|
|
|
}
|
|
|
|
}
|