screensaver/huey/Huey.cpp

60 lines
1.1 KiB
C++

//
// Huey.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "Huey.hpp"
#include <libscscreensaver.hpp>
class Huey : public ScreensaverPlugin {
public:
Huey() = default;
~Huey() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override;
void draw_frame() override;
int fps() const override;
private:
double _hue {0};
};
ScreensaverPlugin* create_instance() {
return new Huey;
}
void Huey::setup(cairo_t* context, const cairo_rectangle_t& rect) {
ScreensaverPlugin::setup(context, rect);
make_black();
}
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);
// update for next frame
_hue += 0.5;
if (_hue > 360.0) {
_hue -= 360.0;
}
}