GooCanvasItem *solution_item;
} rack_t;
-static rack_t the_rack;
-
#define LETTER_SIZE 60
#define LETTER_PAD 5
}
static void
-rack_init (rack_t *rack, GooCanvasItem *parent, char *word, dict_t *solution)
+rack_init (rack_t *rack,
+ dict_t *solution)
{
int i;
- for (i = 0; i < MIN (MAX_TILES, strlen (word)); i++)
- rack->tiles[i] = tile_create (parent, word[i], i);
- rack->num_tiles = i;
- while (i < MAX_TILES)
+ for (i = 0; i < MAX_TILES; i++)
rack->tiles[i] = NULL;
+ rack->num_tiles = 0;
+
rack->guess_length = 0;
rack->solution = solution;
rack->solution_item = NULL;
}
+static void
+rack_create_tiles (rack_t *rack,
+ GooCanvas *canvas,
+ char *word)
+{
+ int i;
+
+ GooCanvasItem *root = goo_canvas_get_root_item (canvas);
+
+ for (i = 0; i < MIN (MAX_TILES, strlen (word)); i++)
+ rack->tiles[i] = tile_create (root, word[i], i);
+ rack->num_tiles = i;
+}
+
static gboolean
rack_shuffle (rack_t *rack)
{
}
static GtkWidget *
-create_window (void)
+create_window (rack_t *rack)
{
GtkWidget *window, *scrolled_window;
gtk_widget_add_events (window, GDK_KEY_PRESS_MASK);
g_signal_connect (window, "key_press_event",
- (GtkSignalFunc) on_key_press_event, &the_rack);
+ (GtkSignalFunc) on_key_press_event, rack);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
return scrolled_window;
}
-static void
-create_canvas (GtkWidget *parent, char *word, dict_t *solution)
+static GooCanvas *
+create_canvas (GtkWidget *parent, rack_t *rack)
{
GtkWidget *canvas;
GooCanvasItem *root;
root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
- rack_init (&the_rack, root, word, solution);
+ 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, rack->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);
+ return GOO_CANVAS (canvas);
}
int
dict_t dict, solution;
struct timeval tv;
bag_t bag;
- char rack[8];
+ rack_t rack;
+ char word[8];
int i;
GtkWidget *window;
+ GooCanvas *canvas;
gettimeofday (&tv, NULL);
srand (tv.tv_sec ^ tv.tv_usec);
bag_init (&bag);
bag_shuffle (&bag);
- memcpy (rack, bag.tiles, 7);
- rack[7] = '\0';
+ memcpy (word, bag.tiles, 7);
+ word[7] = '\0';
for (i = 0; i < 7; i++)
- rack[i] = toupper (rack[i]);
+ word[i] = toupper (word[i]);
dict_init (&dict);
dict_add_words_from_file (&dict, "words.txt");
dict_init (&solution);
- subanagram_expand (rack, &dict, &solution);
+ subanagram_expand (word, &dict, &solution);
gtk_init (&argc, &argv);
- window = create_window ();
- create_canvas (window, rack, &solution);
+ rack_init (&rack, &solution);
+
+ window = create_window (&rack);
+
+ canvas = create_canvas (window, &rack);
+
+ rack_create_tiles (&rack, canvas, word);
gtk_main ();