1 /* Atomix -- a little puzzle game about atoms and molecules.
2 * Copyright (C) 1999-2001 Jens Finke
3 * Copyright (C) 2005 Guilherme de S. Pastore
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "main.h"
20 #include "undo.h"
21
22 extern AtomixApp *app;
23 static GSList *undo_stack = NULL;
24
undo_exists(void)25 gboolean undo_exists (void)
26 {
27 return ((undo_stack == NULL) ? FALSE : TRUE);
28 }
29
delete_move(UndoMove * move,gpointer data)30 static void delete_move (UndoMove *move, gpointer data)
31 {
32 g_free (move);
33 }
34
undo_clear(void)35 void undo_clear (void)
36 {
37 if (undo_stack == NULL)
38 return;
39
40 g_slist_foreach (undo_stack, (GFunc) delete_move, NULL);
41 g_slist_free (undo_stack);
42 undo_stack = NULL;
43 }
44
undo_push_move(gpointer item,gint src_row,gint src_col,gint dest_row,gint dest_col)45 void undo_push_move (gpointer item, gint src_row, gint src_col,
46 gint dest_row, gint dest_col)
47 {
48 UndoMove *move = g_new0 (UndoMove, 1);
49
50 move->item = item;
51 move->src_row = src_row;
52 move->src_col = src_col;
53 move->dest_row = dest_row;
54 move->dest_col = dest_col;
55
56 undo_stack = g_slist_prepend (undo_stack, move);
57 }
58
undo_pop_move(void)59 UndoMove *undo_pop_move (void)
60 {
61 UndoMove *move;
62
63 if (undo_stack == NULL)
64 return NULL;
65
66 move = (UndoMove *) undo_stack->data;
67 undo_stack = g_slist_delete_link (undo_stack, undo_stack);
68
69 if (undo_stack == NULL)
70 {
71 app->state = GAME_STATE_RUNNING_UNMOVED;
72 update_menu_item_state ();
73 }
74
75 return move;
76 }
77