added function to construct a rounded rect

This commit is contained in:
Bob Polis 2020-11-16 12:28:39 +01:00
parent 2e0d3a79f0
commit 4154624aa3
2 changed files with 21 additions and 0 deletions

View File

@ -73,3 +73,23 @@ double ScreensaverPlugin::random_between(double v1, double v2) {
std::uniform_real_distribution<double> dist {v1, v2};
return dist(_eng);
}
void ScreensaverPlugin::rounded_rect(const cairo_rectangle_t& rect, double radius) {
double x0 = rect.x;
double x1 = rect.x + radius;
double x3 = rect.x + rect.width;
double x2 = x3 - radius;
double y0 = rect.y;
double y3 = rect.y + rect.height;
double y1 = rect.y + radius;
double y2 = y3 - radius;
cairo_move_to(_c, x1, y0);
cairo_line_to(_c, x2, y0);
cairo_arc(_c, x2, y1, radius, 1.5 * M_PI, 0);
cairo_line_to(_c, x3, y2);
cairo_arc(_c, x2, y2, radius, 0, 0.5 * M_PI);
cairo_line_to(_c, x1, y3);
cairo_arc(_c, x1, y2, radius, 0.5 * M_PI, M_PI);
cairo_line_to(_c, x0, y1);
cairo_arc(_c, x1, y1, radius, M_PI, 1.5 * M_PI);
}

View File

@ -36,6 +36,7 @@ class ScreensaverPlugin {
double random_y();
double random01();
double random_between(double v1, double v2);
void rounded_rect(const cairo_rectangle_t& rect, double radius);
};
#endif // _ScreensaverPlugin_H_