Repository navigation
Expand file tree
/
Copy pathRenartist.cpp
More file actions
209 lines (168 loc) · 4.48 KB
/
Copy pathRenartist.cpp
File metadata and controls
209 lines (168 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Renartist.cpp: implementation of the Renartist class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "renlib.h"
#include "Renartist.h"
#include "MoveList.h"
#include "MoveNode.h"
#include "Utils.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace
{
void addByte(CString& strValue, BYTE value)
{
CString strHex;
strHex.Format("%02x", value);
strValue += strHex;
}
void addOneLineComment(CString& strValue, CString& strComment)
{
CString strNew(strComment);
while (strNew.GetLength() < 79)
{
strNew += ' ';
}
strNew += TCHAR(0);
if (strNew.GetLength() % 2)
{
strNew += TCHAR(0);
}
for (int i=0; i < strNew.GetLength(); i++)
{
addByte(strValue, strNew[i]);
}
}
void addMultiLineComment(CString& strValue, CString& strMultiLineComment)
{
int nLeft = 0;
int nRight;
while (nLeft < strMultiLineComment.GetLength())
{
nRight = strMultiLineComment.Find(TCHAR(13), nLeft);
if (nRight == -1)
{
nRight = strMultiLineComment.GetLength();
}
CString strLine(strMultiLineComment.Mid(nLeft, nRight - nLeft));
strValue += strLine + TCHAR(10);
nLeft = nRight + 2;
}
}
}
Renartist::Renartist()
{
}
Renartist::~Renartist()
{
}
bool Renartist::Create (const CString& fileName, const MoveList& aMoveList)
{
if (!m_file.Open(fileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText))
{
CString strMessage(Utils::GetString(IDS_MSG_OPEN_FILE, fileName));
Utils::ShowMessage(strMessage, Utils::GetString(IDS_CAP_CREATE_RENARTIST_APPLET), MB_ICONERROR);
return false;
}
CString strTitle("renartist applet");
CString strComment(aMoveList.Current()->getOneLineComment());
if (!strComment.IsEmpty())
{
strTitle = strComment;
}
CString strValue;
for (int i = 1; i <= aMoveList.Index(); i++)
{
addByte(strValue, Utils::PointToPos(aMoveList.Get(i)->getPos()));
CString strInfo;
if (i < aMoveList.Index())
{
strInfo = "0";
}
else
{
strInfo = "4"; // Last move
}
strValue += strInfo;
CString strComment(aMoveList.Get(i)->getOneLineComment());
if (i == 1 && strComment.IsEmpty())
{
strComment = "renartist applet";
}
if (strComment.IsEmpty())
{
strInfo = "0";
}
else
{
strInfo = "8";
}
strValue += strInfo;
if (!strComment.IsEmpty())
{
addOneLineComment(strValue, strComment);
}
}
WriteLine("<html>");
WriteLine("<head>");
WriteLine("<meta name=\"GENERATOR\" content=\"RenLib\">");
WriteLine("<title>" + strTitle + "</title>");
WriteLine("</head>");
WriteLine("<body>");
WriteLine("<div align=\"center\">");
WriteLine("<center>");
WriteLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\">");
WriteLine("<tr>");
WriteLine("<td valign=\"bottom\" colspan=\"3\">");
WriteLine("<p><font size=\"6\"> " + strTitle + "</font></p></td>");
WriteLine("</tr>");
WriteLine("<tr>");
WriteLine("<td valign=\"top\" width=\"330\">");
WriteLine("<br>");
WriteLine("<applet code=\"Rena.class\" codebase=\"http://www.renju.se/renlib/renartist/\" width=330 height=354 align=\"left\" hspace=\"3\">");
WriteLine("<param name=data value=\"" + strValue + "\">");
WriteLine("</applet>");
WriteLine("</td>");
WriteLine("<td width=\"15\" rowspan=\"2\"></td>");
WriteLine("<td valign=\"top\" width=\"330\" rowspan=\"2\" height=\"420\"><font size=\"3\">");
WriteLine("<br><br>");
WriteLine("<textarea rows=\"19\" name=\"comment\" cols=\"30\">");
for (i = 1; i <= aMoveList.Index(); i++)
{
CString strMultiLineComment(aMoveList.Get(i)->getMultiLineComment());
if (!strMultiLineComment.IsEmpty())
{
strValue.Empty();
addMultiLineComment(strValue, strMultiLineComment);
CString strLine;
strLine.Format("%d. %s", i, strValue);
WriteLine(strLine);
}
}
WriteLine("</textarea>");
WriteLine("</font></td>");
WriteLine("</tr>");
WriteLine("<tr>");
WriteLine("<td valign=\"top\" width=\"330\">");
WriteLine("<br><i>renartist applet commands:<br>left click (forward) - right click (back)</i>");
WriteLine("</td>");
WriteLine("</tr>");
WriteLine("</table>");
WriteLine("</center>");
WriteLine("</div>");
WriteLine("</body>");
WriteLine("</html>");
m_file.Close();
return true;
}
void Renartist::WriteLine(const CString& line)
{
m_file.WriteString(line + TCHAR(10));
}