From: Carl Worth Date: Tue, 19 Dec 2006 05:40:55 +0000 (-0800) Subject: Add display of all missed words with control-C X-Git-Url: https://git.cworth.org/git?p=wordgame;a=commitdiff_plain;h=a2dddc88ee72109bd3cb34f676b5fc8587abe389 Add display of all missed words with control-C --- diff --git a/rack-fancy.c b/rack-fancy.c index 21c2953..3631a05 100644 --- a/rack-fancy.c +++ b/rack-fancy.c @@ -47,6 +47,7 @@ typedef struct _rack int guess_length; dict_t *solution; GooCanvasItem *solution_item; + gboolean done; } rack_t; #define LETTER_SIZE 60 @@ -74,6 +75,7 @@ typedef struct _dict_paint_cursor int y; int max_column_width; int max_y; + gboolean show_all; } dict_paint_cursor_t; static void @@ -87,7 +89,11 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) return; cairo_move_to (cr, cursor->x, cursor->y); - if (*entry & RACK_DICT_ENTRY_FOUND) { + if (*entry & RACK_DICT_ENTRY_FOUND || cursor->show_all) { + if (*entry & RACK_DICT_ENTRY_FOUND) + cairo_set_source_rgb (cr, 0, 0, 0); /* black */ + else + cairo_set_source_rgb (cr, 1, 0, 0); /* red */ cairo_show_text (cr, word); } else { int i, length = strlen (word); @@ -100,7 +106,7 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) cursor->y += cursor->line_height; if (cursor->y > cursor->max_y) { cursor->x = cursor->max_column_width + cursor->line_height / 2; - cursor->y = 0; + cursor->y = cursor->line_height; } } @@ -110,7 +116,7 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) static void dict_paint (cairo_t *cr, void *closure, double width, double height) { - dict_t *dict = closure; + rack_t *rack = closure; dict_paint_cursor_t cursor; cairo_save (cr); @@ -123,12 +129,14 @@ dict_paint (cairo_t *cr, void *closure, double width, double height) cursor.line_height = SOLUTION_LINE_HEIGHT; cursor.x = 0; - cursor.y = 0; + cursor.y = cursor.line_height; cursor.max_column_width = 0; cursor.max_y = height; - dict_for_each_by_length (dict, + cursor.show_all = rack->done; + + dict_for_each_by_length (rack->solution, dict_paint_action, &cursor); @@ -268,6 +276,7 @@ rack_init (rack_t *rack, rack->guess_length = 0; rack->solution = solution; rack->solution_item = NULL; + rack->done = FALSE; } static void @@ -338,6 +347,13 @@ on_key_press_event (GtkWidget *widget, char guess_letter; rack_t *rack = user_data; + if (event->state & GDK_CONTROL_MASK && + event->keyval == GDK_c) + { + rack->done = TRUE; + goo_canvas_item_simple_changed (GOO_CANVAS_ITEM_SIMPLE (rack->solution_item), FALSE); + } + if (event->keyval == GDK_Return) { dict_entry_t *entry; if (rack->guess_length >= 3) { @@ -345,6 +361,9 @@ on_key_press_event (GtkWidget *widget, if (DICT_ENTRY_IS_WORD (entry)) { *entry = *entry | RACK_DICT_ENTRY_FOUND; goo_canvas_item_simple_changed (GOO_CANVAS_ITEM_SIMPLE (rack->solution_item), FALSE); + } else { + printf ("\a"); + fflush (stdout); } } rack_return_all (rack); @@ -432,18 +451,18 @@ create_canvas (GtkWidget *parent, rack_t *rack) GooCanvasItem *root; canvas = goo_canvas_new (); - gtk_widget_set_size_request (canvas, 400, 400); - goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 400); + gtk_widget_set_size_request (canvas, 400, 480); + goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 480); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (parent), canvas); root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); rack->solution_item = goo_demo_item_new (root, - LETTER_PAD + SOLUTION_LINE_HEIGHT, + 20, LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD), - 400, 400 - (2 * (LETTER_SIZE + 2 * LETTER_PAD)), - dict_paint, rack->solution, + 400 - 20, 480 - (LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD)), + dict_paint, rack, NULL); return GOO_CANVAS (canvas);