screensaver/rects/RectSaver.cpp

41 lines
948 B
C++
Raw Normal View History

2020-10-26 23:03:12 +01:00
//
// RectSaver.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "RectSaver.hpp"
#include <libscscreensaver.hpp>
class RectSaver : public ScreensaverPlugin {
public:
RectSaver() = default;
~RectSaver() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override;
void draw_frame() override;
int fps() const override;
};
ScreensaverPlugin* create_instance() {
return new RectSaver;
}
2020-10-26 23:03:12 +01:00
void RectSaver::setup(cairo_t* context, const cairo_rectangle_t& rect) {
ScreensaverPlugin::setup(context, rect);
2020-10-26 23:03:12 +01:00
make_black();
}
int RectSaver::fps() const {
return 2;
}
2020-10-26 23:03:12 +01:00
void RectSaver::draw_frame() {
cairo_set_source_rgb(_c, random01(), random01(), random01());
cairo_rectangle_t rect {random_rect()};
cairo_rectangle(_c, rect.x, rect.y, rect.width, rect.height);
cairo_fill(_c);
}