1 #include "components.h"
2 
History(int c)3 History::History(int c)
4 {
5     piece1 = new Point[c];
6     piece2 = new Point[c];
7     via1   = new Point[c];
8     via2   = new Point[c];
9     count  = 0;
10 }
11 
~History(void)12 History::~History(void)
13 {
14     delete[] piece1;
15     delete[] piece2;
16     delete[] via1;
17     delete[] via2;
18 }
19 
20 void
ChangeHistorySize(int c)21 History::ChangeHistorySize(int c)
22 {
23     delete[] piece1;
24     delete[] piece2;
25     delete[] via1;
26     delete[] via2;
27     piece1 = new Point[c];
28     piece2 = new Point[c];
29     via1   = new Point[c];
30     via2   = new Point[c];
31     count  = 0;
32 }
33 
34 void
AddHistory(const Point & a,const Point & b,const Point & c,const Point & d)35 History::AddHistory(const Point &a, const Point &b, const Point &c, const Point &d)
36 {
37     piece1[count] = a;   // Pai 1
38     piece2[count] = b;   // Pai 2
39     via1[count] = c;     // Via point 1
40     via2[count] = d;     // Via point 2
41     count++;
42 }
43 
44 int
BackHistory(void)45 History::BackHistory(void)
46 {
47     if (count > 0) {
48         count--;
49         return 1;
50     }
51     else
52         return 0;  // Cannot back any more
53 }
54 
55 void
GetXY(int c,Point & a,Point & b)56 History::GetXY(int c, Point &a, Point &b)
57 {
58     // c<0 means count back from current
59     if (c < 0)
60         c = count + c;
61     a = piece1[c];
62     b = piece2[c];
63 }
64 
65 void
GetV(int c,Point & a,Point & b)66 History::GetV(int c, Point &a, Point &b)
67 {
68     // c<0 means count back from current
69     if (c < 0)
70         c = count + c;
71     a = via1[c];
72     b = via2[c];
73 }
74 
75 void
ResetHistory(void)76 History::ResetHistory(void)
77 {
78     count = 0;
79 }
80