13 ctx->arc(x +
width - radius, y + radius, radius, -M_PI_2, 0);
14 ctx->arc(x +
width - radius, y +
height - radius, radius, 0, M_PI_2);
15 ctx->arc(x + radius, y +
height - radius, radius, M_PI_2, M_PI);
16 ctx->arc(x + radius, y + radius, radius, M_PI, 3 * M_PI_2);
21 ctx->line_to(x +
width, y);
23 ctx->line_to(x, y +
width);
29void circle(
const Cairo::RefPtr<Cairo::Context>& ctx,
const Geom::Point& center,
double radius) {
30 ctx->arc(center.
x(), center.
y(), radius, 0, 2 * M_PI);
34void draw_border(
const Cairo::RefPtr<Cairo::Context>& ctx,
Geom::Rect rect,
double radius,
const Gdk::RGBA& color,
int device_scale,
bool circular) {
37 if (device_scale > 1) {
39 auto pix = 1.0 / device_scale;
44 ctx->scale(1.0 / device_scale, 1.0 / device_scale);
46 ctx->translate(0.5, 0.5);
47 ctx->set_line_width(1.0);
48 radius *= device_scale;
50 const int steps = 3 * device_scale;
51 auto alpha = color.get_alpha();
52 ctx->set_operator(Cairo::Context::Operator::OVER);
55 for (
int i = 0; i < steps; ++i) {
63 ctx->set_source_rgba(color.get_red(), color.get_green(), color.get_blue(), alpha);
71 auto color = dark_theme ? Gdk::RGBA(1, 1, 1, 0.25) : Gdk::RGBA(0, 0, 0, 0.25);
72 draw_border(ctx, rect, radius, color, device_scale, circular);
77 if (style && style->lookup_color(
"theme_bg_color", color)) {
85 if (style && style->lookup_color(
"theme_fg_color", color)) {
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
C top() const
Return top coordinate of the rectangle (+Y is downwards).
void shrinkBy(C amount)
Shrink the rectangle in both directions by the specified amount.
CPoint midpoint() const
Get the point in the geometric center of the rectangle.
C left() const
Return leftmost coordinate of the rectangle (+X is to the right).
C height() const
Get the vertical extent of the rectangle.
C minExtent() const
Get the smaller extent (width or height) of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Two-dimensional point that doubles as a vector.
constexpr Coord y() const noexcept
constexpr Coord x() const noexcept
Axis aligned, non-empty rectangle.
Rect shrunkBy(Coord amount) const
Return a new rectangle which results from shrinking this one by the same amount along both axes.
Miscellaneous supporting code.
Geom::Rect rounded_rectangle(const Cairo::RefPtr< Cairo::Context > &ctx, const Geom::Rect &rect, double radius)
std::optional< Gdk::RGBA > lookup_background_color(Glib::RefPtr< Gtk::StyleContext > &style)
std::optional< Gdk::RGBA > lookup_foreground_color(Glib::RefPtr< Gtk::StyleContext > &style)
void draw_border(const Cairo::RefPtr< Cairo::Context > &ctx, Geom::Rect rect, double radius, const Gdk::RGBA &color, int device_scale, bool circular)
void circle(const Cairo::RefPtr< Cairo::Context > &ctx, const Geom::Point ¢er, double radius)
void draw_standard_border(const Cairo::RefPtr< Cairo::Context > &ctx, Geom::Rect rect, bool dark_theme, double radius, int device_scale, bool circular)