From bebab5f90a9b25d97dd5a0c923569e2ed00834df Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Sun, 2 Feb 2020 18:32:46 +0800 Subject: [PATCH] Fix rendering bug with left bubble --- src/bubblegen.c | 15 +++++++++++++-- test.sh | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bubblegen.c b/src/bubblegen.c index 605196b..6d6228a 100644 --- a/src/bubblegen.c +++ b/src/bubblegen.c @@ -238,18 +238,28 @@ static void bubble_init_cairo(bubble_t *b, cairo_t *cr, bubble_style_t style) // Draw the black rounded corners cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + // Top left cairo_arc(cr, (right ? middle : 0) + BUBBLE_BORDER + CORNER_RADIUS, BUBBLE_BORDER + CORNER_RADIUS, CORNER_RADIUS, M_PI, M_PI + (M_PI / 2.0)); + // Top right cairo_arc(cr, b->width - (!right ? middle : 0) - CORNER_RADIUS - BUBBLE_BORDER, BUBBLE_BORDER + CORNER_RADIUS, CORNER_RADIUS, M_PI + (M_PI / 2.0), 2 * M_PI); + if (style == NORMAL && !right) { + cairo_move_to(cr, tip_points[0].x, tip_points[0].y); + for (int i = 1; i < 5; i++) { + cairo_line_to(cr, tip_points[i].x, tip_points[i].y); + } + } + + // Bottom left cairo_arc(cr, b->width - (!right ? middle : 0) - CORNER_RADIUS - BUBBLE_BORDER, b->height - CORNER_RADIUS, @@ -262,14 +272,15 @@ static void bubble_init_cairo(bubble_t *b, cairo_t *cr, bubble_style_t style) CORNER_RADIUS, M_PI / 2.0, M_PI); - if (style == NORMAL) { + if (style == NORMAL && right) { cairo_move_to(cr, tip_points[0].x, tip_points[0].y); for (int i = 1; i < 5; i++) { cairo_line_to(cr, tip_points[i].x, tip_points[i].y); } } else { - cairo_close_path(cr); + cairo_line_to(cr, (right ? middle : 0) + BUBBLE_BORDER, + BUBBLE_BORDER + CORNER_RADIUS); } cairo_stroke(cr); diff --git a/test.sh b/test.sh index 5e9cdcf..4761127 100755 --- a/test.sh +++ b/test.sh @@ -11,5 +11,8 @@ $BUILD_DIR/src/xcowsay --left Hello World echo Thought bubble $BUILD_DIR/src/xcowsay --think Hello World +echo Left thought bubble +$BUILD_DIR/src/xcowsay --think Hello World --left + echo Dream $BUILD_DIR/src/xcowsay --dream $SRC_DIR/cow_small.png -t 2 -- 2.39.2