Add --think switch
authorNick Gasson <nick@nickg.me.uk>
Fri, 29 Aug 2008 18:46:40 +0000 (19:46 +0100)
committerNick Gasson <nick@nickg.me.uk>
Fri, 29 Aug 2008 18:46:40 +0000 (19:46 +0100)
src/bubblegen.c
src/display_cow.c
src/display_cow.h
src/xcowsay.c

index 723fb159ff49bcb34e750d2770fa177fa45f77e0..ed153580c651a90361166ac035450ee496549db7 100644 (file)
@@ -24,6 +24,7 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include "floating_shape.h"
+#include "display_cow.h"
 #include "settings.h"
 #include "i18n.h"
 
@@ -252,7 +253,7 @@ GdkPixbuf *make_dream_bubble(const char *file, int *p_width, int *p_height)
    return bubble_tidy(&bubble);
 }
 
-GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height)
+GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height, cowmode_t mode)
 {
    bubble_t bubble;
    int text_width, text_height;
@@ -276,12 +277,14 @@ GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height)
    pango_layout_set_font_description(layout, font);
    pango_layout_set_text(layout, stripped, -1);
    pango_layout_get_pixel_size(layout, &text_width, &text_height);
+
+   bubble_style_t style = mode == COWMODE_NORMAL ? NORMAL : THOUGHT;   
    
-   bubble_size_from_content(&bubble, NORMAL, text_width, text_height);
+   bubble_size_from_content(&bubble, style, text_width, text_height);
    *p_width = bubble.width;
    *p_height = bubble.height;
    
-   bubble_init(&bubble, NORMAL);
+   bubble_init(&bubble, style);
    
    // Render the text
    gdk_draw_layout(bubble.pixmap, bubble.gc,
index 74c48928486cd2b4fa8fe01ef0bde6c65d7c4963..24d71b0fae50a127bed6e947f98ff0ef1c4672b8 100644 (file)
@@ -34,7 +34,7 @@
 #include "settings.h"
 #include "i18n.h"
 
-GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height);
+GdkPixbuf *make_text_bubble(char *text, int *p_width, int *p_height, cowmode_t mode);
 GdkPixbuf *make_dream_bubble(const char *file, int *p_width, int *p_height);
 
 #define TICK_TIMEOUT   100
@@ -151,7 +151,7 @@ static int count_words(const char *s)
    return words;
 }
 
-static void normal_setup(const char *text, bool debug)
+static void normal_setup(const char *text, bool debug, cowmode_t mode)
 {
    char *text_copy = strdup(text);
    
@@ -184,7 +184,7 @@ static void normal_setup(const char *text, bool debug)
    }
    
    xcowsay.bubble_pixbuf = make_text_bubble(text_copy, &xcowsay.bubble_width,
-                                            &xcowsay.bubble_height);
+                                            &xcowsay.bubble_height, mode);
    free(text_copy);
 }
 
@@ -203,7 +203,8 @@ void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode)
 {
    switch (mode) {
    case COWMODE_NORMAL:
-      normal_setup(text, debug);
+   case COWMODE_THINK:
+      normal_setup(text, debug, mode);
       break;
    case COWMODE_DREAM:
       dream_setup(text, debug);
index c5eed1a719649df8700e103f32205d68632104ab..fd22bb84e0768ff10c8351c840c1dff2e25bf69a 100644 (file)
@@ -31,6 +31,7 @@
 typedef enum {
    COWMODE_NORMAL,
    COWMODE_DREAM,
+   COWMODE_THINK,
 } cowmode_t;
 
 // Show a cow with the given string and clean up afterwards
index b4c7db2ababd79c0a0709f1d39b9a6f696fd5e84..6a1833881223b8c7b21743a53fe60486ae622998 100644 (file)
@@ -47,6 +47,7 @@
 
 static int daemon_flag = 0;
 static int debug = 0;
+static int think_flag = 0;
 
 static struct option long_options[] = {
    {"help", no_argument, 0, 'h'},
@@ -54,6 +55,7 @@ static struct option long_options[] = {
    {"time", required_argument, 0, 't'},
    {"font", required_argument, 0, 'f'},
    {"dream", required_argument, 0, 'd'},
+   {"think", no_argument, &think_flag, 1},
    {"cow-size", required_argument, 0, 'c'},
    {"reading-speed", required_argument, 0, 'r'},
    {"daemon", no_argument, &daemon_flag, 1},
@@ -61,7 +63,7 @@ static struct option long_options[] = {
    {0, 0, 0, 0}
 };
 
-static void read_from_stdin(void)
+static void read_from_stdin(cowmode_t mode)
 {
    char *data = malloc(MAX_STDIN);
    size_t n = fread(data, 1, MAX_STDIN, stdin);
@@ -71,7 +73,7 @@ static void read_from_stdin(void)
    }
    data[n] = '\0';
 
-   display_cow_or_invoke_daemon(debug, data, COWMODE_NORMAL);
+   display_cow_or_invoke_daemon(debug, data, mode);
    free(data);
 }
 
@@ -87,6 +89,7 @@ static void usage()
        " -r, --reading-speed=N\t%s\n"
        " -f, --font=FONT\t%s\n"
        " -d, --dream=FILE\t%s\n"
+       "     --think\t\t%s\n"
        "     --daemon\t\t%s\n"
        "     --cow-size=SIZE\t%s\n"
        "     --debug\t\t%s\n\n"
@@ -102,6 +105,7 @@ static void usage()
        i18n("Number of milliseconds to delay per word."),
        i18n("Set message font (Pango format)."),
        i18n("Display an image instead of text."),
+       i18n("Display a thought bubble rather than a speech bubble."),
        i18n("Run xcowsay in daemon mode."),
        i18n("Size of the cow (small, med, large)."),
        i18n("Keep daemon attached to terminal."),
@@ -225,6 +229,8 @@ int main(int argc, char **argv)
 
    srand((unsigned)time(NULL));
 
+   cowmode_t mode = think_flag ? COWMODE_THINK : COWMODE_NORMAL;
+
    if (daemon_flag) {
       run_cowsay_daemon(debug, argc, argv);
    }
@@ -237,11 +243,11 @@ int main(int argc, char **argv)
          display_cow_or_invoke_daemon(debug, dream_file, COWMODE_DREAM);
       }
       else if (optind == argc) {
-         read_from_stdin();
+         read_from_stdin(mode);
       }
       else {
          char *str = cat_from_index(optind, argc, argv);
-         display_cow_or_invoke_daemon(debug, str, COWMODE_NORMAL);
+         display_cow_or_invoke_daemon(debug, str, mode);
          free(str);
       }
    }