Skip to content
Myr

Make border-radius configurable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent e84ad03 · Browse files · 3 files+37 added−27 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+37 added−27 removed

  • other:+37 added−27 removed

3 files+37 added−27 removed

modified:main.c+11 added-1 removed
1054 unmodified lines
1055 {"text-color", required_argument, 0, 't'},1056 {"match-color", required_argument, 0, 'm'},1057 {"selection-color", required_argument, 0, 's'},1058 {"border-width", required_argument, 0, 'B'},1059 {"border-radius", required_argument, 0, 'r'},1060 {"border-color", required_argument, 0, 'C'},1061 {"help", no_argument, 0, 'h'},1062 {NULL, no_argument, 0, 0},1063 };
5 unmodified lines
1069 int height = 300;1070 const int x_margin = 20;1071 const int y_margin = 4;1072 int border_width = 1;1073 int border_radius = 10;1074 uint32_t text_color = 0xffffffff;1075 uint32_t match_color = 0xcc9393ff;1076 uint32_t background = 0x000000ff;1077 uint32_t selection_color = 0x333333ff;1078 uint32_t border_color = 0xffffffff;10791080 while (true) {1079 int c = getopt_long(argc, argv, ":o:f:g:b:t:m:s:B:C:h", longopts, NULL);1081 int c = getopt_long(argc, argv, ":o:f:g:b:t:m:s:B:r:C:h", longopts, NULL);1082 if (c == -1)1083 break;10841085 switch (c) {
47 unmodified lines
1133 return EXIT_FAILURE;1134 }1135 break;11361137 case 'r':1138 if (sscanf(optarg, "%d", &border_radius) != 1) {1139 LOG_ERR("%s: invalid border radius (must be an integer)", optarg);1140 return EXIT_FAILURE;1141 }1142 break;11431144 case 'C':1145 if (sscanf(optarg, "%x", &border_color) != 1) {1146 LOG_ERR("%s: invalid color", optarg);1147 return EXIT_FAILURE;
173 unmodified lines
1321 .height = c.height,1322 .x_margin = x_margin,1323 .y_margin = y_margin,1324 .border_size = border_width,1325 .border_radius = border_radius,1326 .background_color = hex_to_rgba(background),1327 .border_color = hex_to_rgba(border_color),1328 .text_color = hex_to_rgba(text_color),1329 .match_color = hex_to_rgba(match_color),
110 unmodified lines
modified:render.c+25 added-26 removed
14 unmodified lines
1516void17render_background(const struct render *render, struct buffer *buf)18{19 const double from_degree = M_PI / 180;20 const double radius = 10;2119 /*20 * Lines in cairo are *between* pixels.21 *22 * To get a sharp 1px line, we need to draw it with
5 unmodified lines
28 const double b = render->options.border_size;29 const double w = render->options.width - 2 * b;30 const double h = render->options.height - 2 * b;3135 /* Path describing an arc:ed rectangle */36 cairo_arc(buf->cairo, b + w - radius, b + h - radius, radius,37 0.0 * from_degree, 90.0 * from_degree);38 cairo_arc(buf->cairo, b + radius, b + h - radius, radius,39 90.0 * from_degree, 180.0 * from_degree);40 cairo_arc(buf->cairo, b + radius, b + radius, radius,41 180.0 * from_degree, 270.0 * from_degree);42 cairo_arc(buf->cairo, b + w - radius, b + radius, radius,43 270.0 * from_degree, 360.0 * from_degree);44 cairo_close_path(buf->cairo);32 if (render->options.border_radius == 0) {33 cairo_rectangle(buf->cairo, b, b, w, h);34 } else {35 const double from_degree = M_PI / 180;36 const double radius = render->options.border_radius;3746 {47 const struct rgba *bc = &render->options.border_color;3849 /* Border */50 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);51 cairo_set_line_width(buf->cairo, 2 * b);52 cairo_set_source_rgba(buf->cairo, bc->r, bc->g, bc->b, bc->a);53 cairo_stroke_preserve(buf->cairo);39 /* Path describing an arc:ed rectangle */40 cairo_arc(buf->cairo, b + w - radius, b + h - radius, radius,41 0.0 * from_degree, 90.0 * from_degree);42 cairo_arc(buf->cairo, b + radius, b + h - radius, radius,43 90.0 * from_degree, 180.0 * from_degree);44 cairo_arc(buf->cairo, b + radius, b + radius, radius,45 180.0 * from_degree, 270.0 * from_degree);46 cairo_arc(buf->cairo, b + w - radius, b + radius, radius,47 270.0 * from_degree, 360.0 * from_degree);48 cairo_close_path(buf->cairo);49 }5056 {57 const struct rgba *bg = &render->options.background_color;51 /* Border */52 const struct rgba *bc = &render->options.border_color;53 cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);54 cairo_set_line_width(buf->cairo, 2 * b);55 cairo_set_source_rgba(buf->cairo, bc->r, bc->g, bc->b, bc->a);56 cairo_stroke_preserve(buf->cairo);5759 /* Background */60 cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);61 cairo_fill(buf->cairo);62 }58 /* Background */59 const struct rgba *bg = &render->options.background_color;60 cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a);61 cairo_fill(buf->cairo);62}6364void65render_prompt(const struct render *render, struct buffer *buf,
309 unmodified lines
modified:render.h+1 added
12 unmodified lines
13 int height;14 int x_margin;15 int y_margin;16 int border_size;17 int border_radius;1819 struct rgba background_color;20 struct rgba border_color;21 struct rgba text_color;
22 unmodified lines