X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=rack-fancy.c;h=c764677e6599eab7ff9dc6cd75e5f21f008333a3;hb=refs%2Fheads%2Fmaster;hp=8659d9ac9f3e09dcfb70cc13f0adeba95991c22d;hpb=98a8ac80d3f904b6502b39e093d473b8d4d4b246;p=wordgame diff --git a/rack-fancy.c b/rack-fancy.c index 8659d9a..c764677 100644 --- a/rack-fancy.c +++ b/rack-fancy.c @@ -1,7 +1,7 @@ /* * Copyright © 2006 Carl Worth * - * This program is free software; you can redistribute it and\/or modify + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. @@ -29,7 +29,7 @@ #define RACK_DICT_ENTRY_OBSCURE (1<<1) #define RACK_DICT_ENTRY_FOUND (1<<2) -#define MAX_TILES 6 +#define MAX_TILES 7 typedef struct _tile { @@ -98,7 +98,7 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) double new_x, new_y; int found, show_blanks = FALSE; - if (strlen (word) < 3) + if (strlen (word) < 5) return; found = *entry & RACK_DICT_ENTRY_FOUND; @@ -121,11 +121,16 @@ dict_paint_action (void *closure, char *word, dict_entry_t *entry) break; } - /* Don't bother displaying unfound obscure words. */ + /* "Obscure" words get some special coloring. */ if (*entry & RACK_DICT_ENTRY_OBSCURE) { - if (! found) - return; - cairo_set_source_rgb (cr, 0, 1, 0); /* green */ + if (found) { + cairo_set_source_rgb (cr, 0, 1, 0); /* green */ + } else { + if (cursor->show == DICT_PAINT_CURSOR_SHOW_ALL) + cairo_set_source_rgb (cr, 0, 0, 1); /* blue */ + else + return; + } } cairo_move_to (cr, cursor->x, cursor->y); @@ -354,13 +359,22 @@ _flag_obscure_word (void *closure, char *word, dict_entry_t *entry) *entry |= RACK_DICT_ENTRY_OBSCURE; } +static void +_at_least_one_is_not_obscure (void *closure, char *word, dict_entry_t *entry) +{ + int *result = closure; + + if ((*entry & RACK_DICT_ENTRY_OBSCURE) == 0) + *result = 1; +} + static void rack_new_game (rack_t *rack) { int i, bottom; char word[MAX_TILES + 1]; int length = MAX_TILES; - int count; + int has_full_length_non_obscure_word; /* We'll shuffle as many times as necessary until we can find a * sequence of letters with at least one full-length @@ -382,24 +396,29 @@ rack_new_game (rack_t *rack) } } + /* Look at each successive run of tiles in the bag until + * finding one that has at least one non-obscure word using + * all of its leters. */ for (i = 0; i + length <= bottom + 1; i++) { memcpy (word, &rack->bag.tiles[i], length); word[length] = '\0'; dict_fini (&rack->solution); dict_init (&rack->solution); subanagram_expand (word, &rack->dict, &rack->solution); - count = dict_for_each_of_length (&rack->solution, - NULL, NULL, - length, length); - if (count) + dict_for_each (&rack->solution, + _flag_obscure_word, &rack->obscure); + has_full_length_non_obscure_word = 0; + dict_for_each_of_length (&rack->solution, + _at_least_one_is_not_obscure, + &has_full_length_non_obscure_word, + length, length); + if (has_full_length_non_obscure_word) goto DONE; i++; } } DONE: - dict_for_each (&rack->solution, - _flag_obscure_word, &rack->obscure); rack->solution_total = dict_count (&rack->solution); goo_canvas_item_simple_changed (GOO_CANVAS_ITEM_SIMPLE (rack->solution_item), FALSE); @@ -545,7 +564,7 @@ create_window (rack_t *rack) GtkWidget *window, *scrolled_window; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (window), 430, 430); + gtk_window_set_default_size (GTK_WINDOW (window), 490, 490); gtk_widget_show (window); g_signal_connect (window, "delete_event", (GtkSignalFunc) on_delete_event, NULL); @@ -573,8 +592,8 @@ 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, 460, 460); + goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 460, 460); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (parent), canvas); @@ -583,7 +602,7 @@ create_canvas (GtkWidget *parent, rack_t *rack) rack->solution_item = goo_demo_item_new (root, 20, LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD), - 400 - 20, 400 - (LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD)), + 460 - 20, 460 - (LETTER_PAD + 2 * (LETTER_SIZE + 2 * LETTER_PAD)), dict_paint, rack, NULL);