X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=rack-fancy.c;h=d08cd539c61615450c64c6ebd54b64bb95104e03;hb=51f861aa11ac5df79d26dd61c64e772c78f7cd24;hp=87b39f56c74283d05bd34f4382d00d362b434365;hpb=c11f1953e31a1baa1d6785757169c7fd35cdc51d;p=wordgame diff --git a/rack-fancy.c b/rack-fancy.c index 87b39f5..d08cd53 100644 --- a/rack-fancy.c +++ b/rack-fancy.c @@ -27,6 +27,7 @@ #include "word-game.h" #include "demo-item.h" +#define RACK_DICT_ENTRY_FOUND (1<<1) #define MAX_TILES 7 typedef struct _tile @@ -45,6 +46,7 @@ typedef struct _rack char guess[MAX_TILES+1]; int guess_length; dict_t *solution; + GooCanvasItem *solution_item; } rack_t; static rack_t the_rack; @@ -84,7 +86,13 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) double new_x, new_y; cairo_move_to (cr, cursor->x, cursor->y); - cairo_show_text (cr, word); + if (*entry & RACK_DICT_ENTRY_FOUND) { + cairo_show_text (cr, word); + } else { + int i, length = strlen (word); + for (i = 0; i < length; i++) + cairo_show_text (cr, "_"); + } cairo_get_current_point (cr, &new_x, &new_y); if (new_x > cursor->max_column_width) cursor->max_column_width = new_x; @@ -254,6 +262,7 @@ rack_init (rack_t *rack, GooCanvasItem *parent, char *word, dict_t *solution) rack->tiles[i] = NULL; rack->guess_length = 0; rack->solution = solution; + rack->solution_item = NULL; } static gboolean @@ -313,10 +322,10 @@ on_key_press_event (GtkWidget *widget, if (event->keyval == GDK_Return) { dict_entry_t *entry; entry = dict_lookup (rack->solution, rack->guess); - if (DICT_ENTRY_IS_WORD (entry)) - printf ("%s is good\n", rack->guess); - else - printf ("%s is not a word\n", rack->guess); + 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); + } rack_return_all (rack); return TRUE; } @@ -411,12 +420,12 @@ create_canvas (GtkWidget *parent, char *word, dict_t *solution) rack_init (&the_rack, root, word, solution); - goo_demo_item_new (root, - LETTER_PAD, - LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD), - 400, 400 - (2 * (LETTER_SIZE + 2 * LETTER_PAD)), - dict_paint, - solution, NULL); + the_rack.solution_item = goo_demo_item_new (root, + LETTER_PAD, + LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD), + 400, 400 - (2 * (LETTER_SIZE + 2 * LETTER_PAD)), + dict_paint, + solution, NULL); } int