Fix discard rects larger than combined line widths

This commit is contained in:
2025-02-14 12:01:22 +01:00
parent 97110a1489
commit 518596a06b

View File

@ -1,12 +1,13 @@
#include "FadingRects.hpp"
#include "cairo/cairo.h"
#include <libscscreensaver.hpp>
#include <libsccolor.hpp>
#include <libscnumerics.hpp>
#include <vector>
#include <algorithm>
const int default_frames_per_rect {10};
const int fade_time {5}; // seconds
constexpr int default_frames_per_rect {10};
constexpr int fade_time {5}; // seconds
enum class FadingState {
fadein,
@ -87,12 +88,6 @@ void FadingRects::update() {
_frames_per_rect--;
if (_frames_per_rect == 0) {
_frames_per_rect = default_frames_per_rect;
cairo_rectangle_t rr {_r};
rr.x -= 50.0;
rr.y -= 50.0;
rr.width += 100.0;
rr.height += 100.0;
rr = random_rect_in_rect(rr);
RGB rgb {RGB(next_color())};
Rect rect;
rect.red = rgb.r;
@ -104,10 +99,19 @@ void FadingRects::update() {
rect.sustain_frame = 0;
rect.delta = rect.alpha / (fade_time * fps());
rect.line_width = random_between(1.0, 20.0);
rect.x = rr.x;
rect.y = rr.y;
rect.width = rr.width;
rect.height = rr.height;
cairo_rectangle_t rr {_r};
rr.x -= 50.0;
rr.y -= 50.0;
rr.width += 100.0;
rr.height += 100.0;
cairo_rectangle_t rcr;
do {
rcr = random_rect_in_rect(rr);
} while (rcr.width < 2 * rect.line_width + 1 || rcr.height < 2 * rect.line_width + 1);
rect.x = rcr.x;
rect.y = rcr.y;
rect.width = rcr.width;
rect.height = rcr.height;
_rects.push_back(rect);
}
}
@ -117,7 +121,7 @@ void FadingRects::render() {
make_black();
// render rects
for (Rect r : _rects) {
for (const Rect& r : _rects) {
cairo_set_source_rgba(_c, r.red, r.green, r.blue, r.cur_alpha);
cairo_rectangle_t rect;
rect.x = r.x;