From 2e3edd46bde974512bbb87925cbe3b9550f2671c Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Fri, 28 Sep 2012 23:08:23 -0400 Subject: [PATCH] add roundness and border color --- termite.cc | 43 +++++++++++++++++++++++++++++++++---------- termite.cfg | 4 +++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/termite.cc b/termite.cc index 8699fcb..ea92dfa 100644 --- a/termite.cc +++ b/termite.cc @@ -69,8 +69,8 @@ struct keybind_info { struct hint_info { PangoFontDescription *font; - cairo_pattern_t *fg, *bg; - double border; + cairo_pattern_t *fg, *bg, *border; + double border_width, roundness; }; static char *browser_cmd[3] = {NULL}; @@ -159,6 +159,16 @@ static void launch_url(const char *text, search_panel_info *info) { } } +static void draw_rectangle(cairo_t *cr, double x, double y, double height, double width) { + double radius = hints.roundness; + double a = x, b = x + height, c = y, d = y + width; + cairo_arc(cr, a + radius, c + radius, radius, 2*(M_PI/2), 3*(M_PI/2)); + cairo_arc(cr, b - radius, c + radius, radius, 3*(M_PI/2), 4*(M_PI/2)); + cairo_arc(cr, b - radius, d - radius, radius, 0*(M_PI/2), 1*(M_PI/2)); + cairo_arc(cr, a + radius, d - radius, radius, 1*(M_PI/2), 2*(M_PI/2)); + cairo_close_path(cr); +} + static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, long y, int padding, unsigned id) { char buffer[std::numeric_limits::digits10 + 1]; cairo_text_extents_t ext; @@ -172,19 +182,19 @@ static void draw_marker(cairo_t *cr, const PangoFontDescription *desc, long x, l pango_layout_set_text(layout, buffer, -1); pango_layout_get_size (layout, &width, &height); - cairo_set_source(cr, hints.fg); - cairo_rectangle(cr, static_cast(x), static_cast(y), - static_cast(width / PANGO_SCALE + padding * 2), - static_cast(height / PANGO_SCALE + padding * 2)); + draw_rectangle(cr, static_cast(x), static_cast(y), + static_cast(width / PANGO_SCALE + padding * 2), + static_cast(height / PANGO_SCALE + padding * 2)); + cairo_set_source(cr, hints.border); + cairo_set_line_width(cr, hints.border_width); cairo_stroke_preserve(cr); cairo_set_source(cr, hints.bg); cairo_fill(cr); cairo_new_path(cr); - cairo_set_line_width(cr, hints.border); - cairo_set_source(cr, hints.fg); cairo_move_to(cr, static_cast(x + padding), static_cast(y + padding)); + cairo_set_source(cr, hints.fg); pango_cairo_update_layout(cr, layout); pango_cairo_layout_path(cr, layout); cairo_fill(cr); @@ -1043,8 +1053,21 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info, hints.bg = cairo_pattern_create_rgb(0, 0, 0); } - hints.border = 0.5; - get_config_double(config, "hints", "border", &hints.border); + if (get_config_color(config, "hints", "border", &color)) { + hints.border = cairo_pattern_create_rgb(color.red / 65535.0, + color.green / 65535.0, + color.blue / 65535.0); + } else { + hints.border = hints.fg; + } + + if (!get_config_double(config, "hints", "border_width", &hints.border_width)) { + hints.border_width = 1.0; + } + + if (!get_config_double(config, "hints", "roundness", &hints.roundness)) { + hints.roundness = 1.5; + } } g_free(path); g_key_file_free(config); diff --git a/termite.cfg b/termite.cfg index 8c425db..7a121dc 100644 --- a/termite.cfg +++ b/termite.cfg @@ -64,4 +64,6 @@ color15 = #ffffff #font = Monospace 12 #foreground = #dcdccc #background = #3f3f3f -#border = 0.5 +#border = #3f3f3f +#border_width = 0.5 +#roundness = 2.0