screensaver/huey/Huey.cpp

66 lines
1.4 KiB
C++
Raw Normal View History

//
// 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>
class Huey : public ScreensaverPlugin {
public:
Huey() = default;
~Huey() = default;
int fps() const override;
2020-10-29 09:21:12 +01:00
void draw_frame() override;
private:
double _hue {0};
};
ScreensaverPlugin* create_instance() {
return new Huey;
}
int Huey::fps() const {
return 40;
}
void Huey::draw_frame() {
// 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::string hue_text {std::to_string(static_cast<int>(_hue))};
cairo_set_source_rgb(_c, 0, 0, 0);
cairo_select_font_face(_c, "Helvetica", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(_c, 24);
cairo_move_to(_c, 30, 50);
cairo_show_text(_c, hue_text.c_str());
cairo_set_source_rgb(_c, 1, 1, 1);
cairo_move_to(_c, 29, 49);
cairo_show_text(_c, hue_text.c_str());
// update for next frame
_hue += 0.5;
if (_hue >= 360.0) {
_hue -= 360.0;
}
}