19 using System.Collections.Generic;
20 using System.ComponentModel;
23 using System.Drawing.Drawing2D;
28 using System.Threading.Tasks;
30 using System.Windows.Forms;
31 using System.Xml.Serialization;
42 delegate
void ViewMsgDlgDelegate(
string title ,
string msg);
43 delegate
void DrawSingleDelegate(
int y,
int x,
int sts,
int bk,
string text);
44 delegate
void CurColMsgDelegate(
string text);
45 delegate
void CurStsMsgDelegate(
string text);
46 delegate
void Reversi_ResizeEndDelegate(
object sender, EventArgs e);
67 System.IO.Directory.CreateDirectory(
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
"\\Y.Y Magic\\ReversiForm");
68 string setPath =
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
"\\Y.Y Magic\\ReversiForm\\" +
"AppSetting.xml";
72 if(this.m_AppSettings == null)
79 this.m_ReversiPlay.viewMsgDlg = this.
ViewMsgDlg;
80 this.m_ReversiPlay.drawSingle = this.
DrawSingle;
81 this.m_ReversiPlay.curColMsg = this.
CurColMsg;
82 this.m_ReversiPlay.curStsMsg = this.
CurStsMsg;
84 Task newTask =
new Task( () => { this.m_ReversiPlay.
reset(); } );
89 System.Console.WriteLine(
"FormMain(1) : " + ex.Message);
90 System.Console.WriteLine(
"FormMain(1) : " + ex.StackTrace);
109 XmlSerializer serializer =
new XmlSerializer(typeof(
ReversiSetting));
112 FileStream fsr =
new FileStream(path, FileMode.Open);
120 System.Console.WriteLine(
"LoadSettingXml() : " + ex.Message);
121 System.Console.WriteLine(
"LoadSettingXml() : " + ex.StackTrace);
143 XmlSerializer serializer =
new XmlSerializer(typeof(
ReversiSetting));
146 FileStream fsw =
new FileStream(path, FileMode.Create);
149 serializer.Serialize(fsw, appSet);
152 catch (Exception exl)
154 System.Console.WriteLine(
"SaveSettingXml() : " + exl.Message);
155 System.Console.WriteLine(
"SaveSettingXml() : " + exl.StackTrace);
172 Size formSize = this.Size;
173 Size tblSize = this.tableLayoutPanel1.Size;
177 formSize.Height = this.label1.Top;
178 formSize.Height -= startX << 1;
179 formSize.Width -= startY << 1;
180 int refSize = formSize.Height;
181 if (formSize.Width < refSize) refSize = formSize.Width;
182 double tmpD = (double)refSize / this.m_AppSettings.mMasuCnt;
183 refSize = (
int)Math.Ceiling(tmpD);
184 refSize *= this.m_AppSettings.mMasuCnt;
186 this.tableLayoutPanel1.Top = startX;
187 this.tableLayoutPanel1.Left = ( ( formSize.Width + ( startY << 1 ) ) - refSize ) >> 1;
188 tblSize.Height = refSize;
189 tblSize.Width = refSize;
190 this.tableLayoutPanel1.Height = refSize;
191 this.tableLayoutPanel1.Width = refSize;
193 Size curSize = tblSize;
194 float cellSizeAll = (float)curSize.Height;
195 if (curSize.Width < cellSizeAll) cellSizeAll = (float)curSize.Width;
196 float cellSize = cellSizeAll / (
float)this.m_AppSettings.mMasuCnt;
197 float per = cellSize / cellSizeAll * 100F;
198 this.tableLayoutPanel1.Visible =
false;
204 string curIdxStr =
"pictureBox" + curIdx.ToString();
205 Control c = this.tableLayoutPanel1.Controls[curIdxStr];
208 if( i < this.m_AppSettings.mMasuCnt && j <
this.m_AppSettings.mMasuCnt)
218 if(j < this.m_AppSettings.mMasuCnt)
220 this.tableLayoutPanel1.ColumnStyles[j] =
new System.Windows.Forms.ColumnStyle(
System.Windows.Forms.SizeType.Absolute, cellSize);
224 this.tableLayoutPanel1.ColumnStyles[j] =
new System.Windows.Forms.ColumnStyle(
System.Windows.Forms.SizeType.Absolute, 0F);
228 if(i < this.m_AppSettings.mMasuCnt)
230 this.tableLayoutPanel1.RowStyles[i] =
new System.Windows.Forms.RowStyle(
System.Windows.Forms.SizeType.Absolute, cellSize);
234 this.tableLayoutPanel1.RowStyles[i] =
new System.Windows.Forms.RowStyle(
System.Windows.Forms.SizeType.Absolute, 0F);
237 this.tableLayoutPanel1.Visible =
true;
267 MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
283 public void DrawSingle(
int y,
int x,
int sts,
int bk,
string text)
303 PictureBox curPict = (PictureBox) this.tableLayoutPanel1.GetControlFromPosition(x,y);
307 Bitmap canvas =
new Bitmap(curPict.Width, curPict.Height);
309 Graphics g = Graphics.FromImage(canvas);
310 g.SmoothingMode = SmoothingMode.HighQuality;
311 Pen curPen1 =
new Pen(m_AppSettings.mBorderColor,2);
313 SolidBrush curBru1 = null;
314 SolidBrush curBru2 = null;
315 SolidBrush curBru3 = null;
316 Color curBkColor = m_AppSettings.mBackGroundColor;
317 byte tmpA = curBkColor.A;
318 byte tmpR = curBkColor.R;
319 byte tmpG = curBkColor.G;
320 byte tmpB = curBkColor.B;
326 if (tmpG < 0) tmpG += 255;
328 if (255 < tmpB) tmpB -= 255;
329 curBkColor = Color.FromArgb(tmpA, tmpR, tmpG, tmpB);
334 if(255 < tmpR) tmpR -= 255;
336 if(tmpG < 0) tmpG += 255;
338 if(tmpB < 0) tmpB += 255;
339 curBkColor = Color.FromArgb(tmpA, tmpR, tmpG, tmpB);
340 }
else if (bk == 3) {
343 if(255 < tmpR) tmpR -= 255;
345 if(255 < tmpB) tmpB -= 255;
346 curBkColor = Color.FromArgb(tmpA, tmpR, tmpG, tmpB);
349 curBkColor = Color.FromArgb(tmpA, tmpR, tmpG, tmpB);
351 curBru1 =
new SolidBrush(curBkColor);
353 float h = workCol.
H + 180F;
354 if (359F < h) h -= 360F;
356 curBru3 =
new SolidBrush(curBkColorRev);
363 curBru2 =
new SolidBrush(m_AppSettings.mPlayerColor1);
367 curBru2 =
new SolidBrush(m_AppSettings.mPlayerColor2);
371 g.FillRectangle(curBru1, 0, 0, curPict.Width, curPict.Height);
373 g.DrawRectangle(curPen1, 0, 0, curPict.Width, curPict.Height);
375 if(curBru2 != null) g.FillEllipse(curBru2, 2, 2, curPict.Width - 4, curPict.Height - 4);
377 if (text != null && text.Length != 0 && text !=
"0")
380 int fntSize = curPict.Width;
381 if(curPict.Height < fntSize) fntSize = curPict.Height;
382 fntSize = (int)((
double)fntSize * 0.75);
383 fntSize /= text.Length;
384 if (fntSize < 8) fntSize = 8;
385 Font fnt =
new Font(
"MS UI Gothic", fntSize);
386 Rectangle rect1 =
new Rectangle(0, 0, curPict.Width, curPict.Height);
387 StringFormat stringFormat =
new StringFormat();
388 stringFormat.Alignment = StringAlignment.Center;
389 stringFormat.LineAlignment = StringAlignment.Center;
390 g.DrawString(text, fnt, curBru3, rect1, stringFormat);
397 curPict.Image = canvas;
426 this.label1.Text = text;
454 this.label2.Text = text;
469 TableLayoutPanelCellPosition pos = this.tableLayoutPanel1.GetCellPosition((Control)sender);
471 Console.WriteLine(
"click y=" + pos.Row +
" x=" + pos.Column);
473 Task newTask =
new Task( () => { this.m_ReversiPlay.
reversiPlay(pos.Row, pos.Column); } );
490 Task newTask =
new Task( () => { this.m_ReversiPlay.
reset(); } );
506 System.IO.Directory.CreateDirectory(
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
"\\Y.Y Magic\\ReversiForm");
507 string setPath =
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
"\\Y.Y Magic\\ReversiForm\\" +
"AppSetting.xml";
511 form.ShowDialog(
this);
513 this.m_AppSettings = form.mSetting;
520 Task newTask =
new Task( () => { this.m_ReversiPlay.
reset(); } );
536 System.Console.WriteLine(
"Reversi_Resize() : ");
539 double interval = 100.0;
563 private void Reversi_ResizeEnd(
object sender, EventArgs e)
566 System.Console.WriteLine(
"Reversi_ResizeEnd() : ");
568 this.PerformLayout();
570 Size curSize = this.Size;
571 if(oldSize.Width != curSize.Width || oldSize.Height != curSize.Height)
574 oldSize.Width = curSize.Width;
575 oldSize.Height = curSize.Height;
577 Task newTask =
new Task( () => { this.m_ReversiPlay.
drawUpdateForcibly(this.m_AppSettings.mAssist); } );
594 Invoke(
new Reversi_ResizeEndDelegate(this.Reversi_ResizeEnd), source, e);