From 4154624aa3b43ffe3647436d81088a5a9a2b6f0c Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 16 Nov 2020 12:28:39 +0100 Subject: [PATCH] added function to construct a rounded rect --- src/ScreensaverPlugin.cpp | 20 ++++++++++++++++++++ src/ScreensaverPlugin.hpp | 1 + 2 files changed, 21 insertions(+) diff --git a/src/ScreensaverPlugin.cpp b/src/ScreensaverPlugin.cpp index 4b17fe9..ca204cc 100644 --- a/src/ScreensaverPlugin.cpp +++ b/src/ScreensaverPlugin.cpp @@ -73,3 +73,23 @@ double ScreensaverPlugin::random_between(double v1, double v2) { std::uniform_real_distribution 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); +} diff --git a/src/ScreensaverPlugin.hpp b/src/ScreensaverPlugin.hpp index 84a67ee..2ff05bb 100644 --- a/src/ScreensaverPlugin.hpp +++ b/src/ScreensaverPlugin.hpp @@ -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_