+/* update the clue items */
+void update_clue_items ()
+{
+ gtk_list_store_clear (across_store);
+ gtk_list_store_clear (down_store);
+
+ /* if the puzzle is loaded */
+ if (app_data.is_loaded == true)
+ {
+ /* iterate through the puzzle grid and gte the clues */
+ for (int i = 0; i < app_data.puzzle.grid_size; i ++)
+ {
+ for (int j = 0; j < app_data.puzzle.grid_size; j ++)
+ {
+ /* if it is the start of an across word */
+ if (app_data.puzzle.start_across_word[i][j] != -1)
+ {
+ GtkTreeIter iter;
+
+ gtk_list_store_append (across_store, &iter);
+ gtk_list_store_set (across_store, &iter, 0,
+ app_data.puzzle.start_across_word[i][j],
+ 1, app_data.puzzle.clue_across[i][j],
+ -1);
+ }
+ /* if it is the start of a down word */
+ if (app_data.puzzle.start_down_word[i][j] != -1)
+ {
+ GtkTreeIter iter;
+ gtk_list_store_append (down_store, &iter);
+ gtk_list_store_set (down_store, &iter, 0,
+ app_data.puzzle.start_down_word[i][j],
+ 1, app_data.puzzle.clue_down[i][j],
+ -1);
+ }
+ }
+ }
+ }
+}
+
+/* move the current selection index left or right */
+void move_current_col (enum DIRECTION dir)
+{
+ int r = app_data.cur_row;
+ int c = app_data.cur_col;
+ if (dir == DIR_FORWARD)
+ {
+ c ++;
+ while (c < app_data.puzzle.grid_size)
+ {
+ if (app_data.puzzle.chars[r][c] == '#')
+ c ++;
+ else
+ break;
+ }
+ if (c < app_data.puzzle.grid_size)
+ app_data.cur_col = c;
+ }
+ else
+ {
+ c --;
+ while (c >= 0)
+ {
+ if (app_data.puzzle.chars[r][c] == '#')
+ c --;
+ else
+ break;
+ }
+ if (c >= 0)
+ app_data.cur_col = c;
+ }
+}
+
+/* move the current selection index up or down */
+void move_current_row (enum DIRECTION dir)
+{
+ int r = app_data.cur_row;
+ int c = app_data.cur_col;
+ if (dir == DIR_FORWARD)
+ {
+ r ++;
+ while (r < app_data.puzzle.grid_size)
+ {
+ if (app_data.puzzle.chars[r][c] == '#')
+ r ++;
+ else
+ break;
+ }
+ if (r < app_data.puzzle.grid_size)
+ app_data.cur_row = r;
+ }
+ else
+ {
+ r --;
+ while (r >= 0)
+ {
+ if (app_data.puzzle.chars[r][c] == '#')
+ r --;
+ else
+ break;
+ }
+ if (r >= 0)
+ app_data.cur_row = r;
+ }
+}
+
+
+/* slot for handling key press event for puzzle drawing area */
+gboolean on_puzzle_area_key_press_event (GtkWidget *widget,
+ GdkEventKey *event, gpointer data)
+{
+ /* respond to key events only if the puzzle is loaded */
+ if (app_data.is_loaded == true)
+ {
+ switch (event->keyval)
+ {
+ case GDK_KEY_Down : move_current_row (DIR_FORWARD);
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ app_data.puzzle.grid_size*GRID_PIXELS+10,
+ app_data.puzzle.grid_size*GRID_PIXELS+10);
+ break;
+ case GDK_KEY_Up : move_current_row (DIR_BACK);
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ app_data.puzzle.grid_size*GRID_PIXELS+10,
+ app_data.puzzle.grid_size*GRID_PIXELS+10);
+ break;
+ case GDK_KEY_Right: move_current_col (DIR_FORWARD);
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ app_data.puzzle.grid_size*GRID_PIXELS+10,
+ app_data.puzzle.grid_size*GRID_PIXELS+10);
+ break;
+ case GDK_KEY_Left : move_current_col (DIR_BACK);
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ app_data.puzzle.grid_size*GRID_PIXELS+10,
+ app_data.puzzle.grid_size*GRID_PIXELS+10);
+ }
+ }
+
+ return FALSE;
+}
+