screensaver/skembo/Skembo.cpp

59 lines
1.0 KiB
C++

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