From f3089e88f23803be5c6f4dbc41ce43115de23160 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 21 Mar 2017 14:49:33 +0100 Subject: [PATCH] feat(conf): Properties for top/bottom radius #445 --- include/cairo/context.hpp | 9 ++++----- include/cairo/types.hpp | 3 ++- include/components/types.hpp | 11 ++++++++++- src/components/bar.cpp | 7 ++++--- src/components/renderer.cpp | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/cairo/context.hpp b/include/cairo/context.hpp index 98623d38..624173d6 100644 --- a/include/cairo/context.hpp +++ b/include/cairo/context.hpp @@ -130,13 +130,12 @@ namespace cairo { } context& operator<<(const rounded_corners& c) { - double radius = c.radius / 1.0; double d = M_PI / 180.0; cairo_new_sub_path(m_c); - cairo_arc(m_c, c.x + c.w - radius, c.y + radius, radius, -90 * d, 0 * d); - cairo_arc(m_c, c.x + c.w - radius, c.y + c.h - radius, radius, 0 * d, 90 * d); - cairo_arc(m_c, c.x + radius, c.y + c.h - radius, radius, 90 * d, 180 * d); - cairo_arc(m_c, c.x + radius, c.y + radius, radius, 180 * d, 270 * d); + cairo_arc(m_c, c.x + c.w - c.radius.top, c.y + c.radius.top, c.radius.top, -90 * d, 0 * d); + cairo_arc(m_c, c.x + c.w - c.radius.bottom, c.y + c.h - c.radius.bottom, c.radius.bottom, 0 * d, 90 * d); + cairo_arc(m_c, c.x + c.radius.bottom, c.y + c.h - c.radius.bottom, c.radius.bottom, 90 * d, 180 * d); + cairo_arc(m_c, c.x + c.radius.top, c.y + c.radius.top, c.radius.top, 180 * d, 270 * d); cairo_close_path(m_c); return *this; } diff --git a/include/cairo/types.hpp b/include/cairo/types.hpp index dc4fb087..42e9111a 100644 --- a/include/cairo/types.hpp +++ b/include/cairo/types.hpp @@ -3,6 +3,7 @@ #include #include "common.hpp" +#include "components/types.hpp" POLYBAR_NS @@ -51,7 +52,7 @@ namespace cairo { double y; double w; double h; - double radius; + struct radius radius; }; struct textblock { alignment align; diff --git a/include/components/types.hpp b/include/components/types.hpp index e25f1869..82450c9a 100644 --- a/include/components/types.hpp +++ b/include/components/types.hpp @@ -78,6 +78,15 @@ struct edge_values { unsigned int bottom{0U}; }; +struct radius { + double top{0.0}; + double bottom{0.0}; + + operator bool() const { + return top != 0.0 || bottom != 0.0; + } +}; + struct border_settings { unsigned int color{0xFF000000}; unsigned int size{0U}; @@ -135,7 +144,7 @@ struct bar_settings { std::unordered_map borders{}; - double radius{0.0}; + struct radius radius {}; int spacing{0}; string separator{}; diff --git a/src/components/bar.cpp b/src/components/bar.cpp index d3583a46..5c4051ec 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -135,11 +135,12 @@ bar::bar(connection& conn, signal_emitter& emitter, const config& config, const m_opts.spacing = m_conf.get(bs, "spacing", m_opts.spacing); m_opts.separator = m_conf.get(bs, "separator", ""s); m_opts.locale = m_conf.get(bs, "locale", ""s); - m_opts.radius = m_conf.get(bs, "radius", m_opts.radius); + + auto radius = m_conf.get(bs, "radius", 0.0); + m_opts.radius.top = m_conf.get(bs, "radius-top", radius); + m_opts.radius.bottom = m_conf.get(bs, "radius-bottom", radius); auto padding = m_conf.get(bs, "padding", 0U); - m_opts.padding.left = padding; - m_opts.padding.right = padding; m_opts.padding.left = m_conf.get(bs, "padding-left", padding); m_opts.padding.right = m_conf.get(bs, "padding-right", padding); diff --git a/src/components/renderer.cpp b/src/components/renderer.cpp index a5fb2f82..6cde36b3 100644 --- a/src/components/renderer.cpp +++ b/src/components/renderer.cpp @@ -215,7 +215,7 @@ void renderer::begin(xcb_rectangle_t rect) { m_context->clear(); // Create corner mask - if (m_bar.radius != 0.0 && m_cornermask == nullptr) { + if (m_bar.radius && m_cornermask == nullptr) { m_context->save(); m_context->push(); // clang-format off