From cddfd7e80a9898a6b632aa2e28c8d25a00a7e334 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Mon, 4 Jan 2010 07:44:28 +0000 Subject: [PATCH] Add --bubble-at option to change relative location of bubble --- ChangeLog | 9 ++++++++- src/display_cow.c | 12 +++++++----- src/xcowsay.c | 14 ++++++++++++++ xcowsay.6 | 17 +++++++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2f46d53..7c6e5d6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-01-04 Nick Gasson + + * src/xcowsay.c (main): Add --bubble-at option to change + relative location of speech bubble. + * src/display_cow.c (display_cow): Use bubble_x and bubble_y + config variables to alter relative location of bubble. + 2010-01-03 Nick Gasson * src/xcowsay.c (main): Add --at option to specify cow location @@ -6,7 +13,7 @@ as X,Y pairs. * src/display_cow.c (display_cow): Now recognises the at_x and at_y config variables to force cow to appear at a particular - position. + position. 2010-01-02 Nick Gasson diff --git a/src/display_cow.c b/src/display_cow.c index e3343e9..7caf11a 100644 --- a/src/display_cow.c +++ b/src/display_cow.c @@ -38,7 +38,6 @@ GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height, cowmode_t m GdkPixbuf *make_dream_bubble(const char *file, int *p_width, int *p_height); #define TICK_TIMEOUT 100 -#define BUBBLE_XOFFSET 5 // Distance from cow to bubble #define max(a, b) ((a) > (b) ? (a) : (b)) @@ -239,8 +238,9 @@ void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode) g_assert(xcowsay.cow_pixbuf); xcowsay.cow = make_shape_from_pixbuf(xcowsay.cow_pixbuf); - - int total_width = shape_width(xcowsay.cow) + BUBBLE_XOFFSET + + int total_width = shape_width(xcowsay.cow) + + get_int_option("bubble_x") + xcowsay.bubble_width; int total_height = max(shape_height(xcowsay.cow), xcowsay.bubble_height); @@ -285,9 +285,11 @@ void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode) show_shape(xcowsay.cow); xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf); - int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow) + BUBBLE_XOFFSET; + int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow) + + get_int_option("bubble_x"); int by = shape_y(xcowsay.cow) - + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2; + + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2 + + get_int_option("bubble_y"); move_shape(xcowsay.bubble, bx, by); xcowsay.state = csLeadIn; diff --git a/src/xcowsay.c b/src/xcowsay.c index ffd3f9e..ae05866 100644 --- a/src/xcowsay.c +++ b/src/xcowsay.c @@ -44,6 +44,7 @@ #define DEF_IMAGE_BASE "cow" #define DEF_DREAM_TIME 10000 #define DEF_ALT_IMAGE "" +#define DEF_BUBBLE_X 5 // Distance from cow to bubble #define MAX_STDIN 4096 // Maximum chars to read from stdin @@ -63,6 +64,7 @@ static struct option long_options[] = { {"daemon", no_argument, &daemon_flag, 1}, {"image", required_argument, 0, 'i'}, {"monitor", required_argument, 0, 'm'}, + {"bubble-at", required_argument, 0, 'b'}, {"at", required_argument, 0, 'a'}, {"debug", no_argument, &debug, 1}, {0, 0, 0, 0} @@ -100,6 +102,7 @@ static void usage() " --image=FILE\t%s\n" " --monitor=N\t%s\n" " --at=X,Y\t\t%s\n" + " --bubble-at=X,Y\t%s\n" " --debug\t\t%s\n\n" "%s\n\n" "%s\n\n" @@ -119,6 +122,7 @@ static void usage() i18n("Use a different image instead of the cow."), i18n("Display cow on monitor N."), i18n("Force the cow to appear at screen location (X,Y)."), + i18n("Change relative position of bubble."), i18n("Keep daemon attached to terminal."), i18n("Default values for these options can be specified in the " "xcowsay config\nfile. See the man page for more information."), @@ -224,6 +228,8 @@ int main(int argc, char **argv) add_int_option("monitor", -1); add_int_option("at_x", -1); add_int_option("at_y", -1); + add_int_option("bubble_x", DEF_BUBBLE_X); + add_int_option("bubble_y", 0); parse_config_file(); @@ -270,6 +276,14 @@ int main(int argc, char **argv) set_int_option("at_y", y); } break; + case 'b': + { + int x, y; + parse_position_option(optarg, &x, &y); + set_int_option("bubble_x", x); + set_int_option("bubble_y", y); + } + break; case '?': // getopt_long already printed an error message failure = 1; diff --git a/xcowsay.6 b/xcowsay.6 index ea2da48..493f904 100644 --- a/xcowsay.6 +++ b/xcowsay.6 @@ -103,7 +103,7 @@ Run xcowsay in daemon mode if DBus support has been enabled. See the description for more information. .TP .BI "--cow-size=" size -Size of the cow image. Current choices are +Size of the cow image. Current choices are .BR small ", " med ", or " large . The corresponding config file option is .IR cow_size . @@ -117,7 +117,20 @@ option is Make the cow appear on monitor N. .TP .BI "--at=" X,Y -Force that cow to appear at screen location (X,Y). +Force that cow to appear at screen location (X,Y). The config file options +are +.I at_x +and +.IR at_y . +.TP +.BI "--bubble-at=" X,Y +Change position of bubble relative to where it would normally appear. This +is most useful when combined with the +.I alt_image +option to create your own characters. The config file options are +.I bubble_x +and +.IR bubble_y . .TP .B "--debug" Print messages about what -- 2.39.2