/// <summary> /// デバッグ用に思考エンジンとやりとりしているログを画面上に表示するためのダイアログ。 /// </summary> /// <param name="log"></param> public DebugWindow(MemoryLog log) { InitializeComponent(); var ListAdded_ = new ListAddedEventHandler(args => { try { // UIスレッドからの呼び出しを保証する。 TheApp.app.UIThread(() => ListAdded(args)); } catch { } // 終了間際だとInvoke()で例外が出るかもしれないので握りつぶしておく。 }); log.AddHandler(ListAdded_, ref log_list); FormClosed += (sender, args) => { log.RemoveHandler(ListAdded_); }; memory_log = log; UpdateListBox(); // すぐに入力出来るようにフィルター用のテキストボックスにフォーカスを移動させておく。 ActiveControl = textBox1; // フォントの変更。即時反映 var fontSetter = new FontSetter(this, "DebugWindow"); Disposed += (sender, args) => fontSetter.Dispose(); }
/// <summary> /// フォントの初期化 /// </summary> private void InitFont() { // フォントの変更。即時反映 var fontSetter1 = new FontSetter(this, "ConsiderationWindow"); //var fontSetter2 = new FontSetter(this.toolStrip1, "SubToolStrip"); // → MiniShogiBoardに移動させた。 Disposed += (sender, args) => { fontSetter1.Dispose(); /* fontSetter2.Dispose(); */ }; }
public MiniShogiBoard() { InitializeComponent(); // フォントの変更。即時反映 var fontSetter = new FontSetter(this.toolStrip1, "SubToolStrip"); Disposed += (sender, args) => { fontSetter.Dispose(); }; }
/// <summary> /// 棋譜表示用のコントロール /// /// InitViewModel(Form)を初期化のために必ず呼び出すこと。 /// </summary> public KifuControl() { InitializeComponent(); if (TheApp.app.DesignMode) { return; } InitListView(); var fm = new FontSetter(this, "KifuWindow"); Disposed += (sender, args) => { fm.Dispose(); }; }
/// <summary> /// フォントの初期化 /// </summary> private void InitFont() { // --- フォントの変更。即時反映 // 検討ウインドウの文字フォント var fontSetter1 = new FontSetter(this, "ConsiderationWindow"); //var fontSetter2 = new FontSetter(this.toolStrip1, "SubToolStrip"); // → MiniShogiBoardに移動させた。 // ミニ盤面の上のタブの文字フォント var fontSetter2 = new FontSetter(this.tabControl1, "MiniBoardTab"); Disposed += (sender, args) => { fontSetter1.Dispose(); fontSetter2.Dispose(); }; }
/// <summary> /// グラフの描画 /// </summary> public void Render(object sender, PaintEventArgs e) { // ToDo: MainDialogで局面が変更された時(ToolStrip, KifuControlの操作など)にEvalGraphの更新をトリガする // フォントの変更。即時反映 var fontSetter = new FontSetter(this, "EvalGraphControl"); Disposed += (_sender, args) => fontSetter.Dispose(); Graphics g = e.Graphics; g.PageUnit = GraphicsUnit.Pixel; g.SmoothingMode = SmoothingMode.AntiAlias; geo = new ViewGeo(this); float graphPlyHPad = Math.Min(10f * geo.plyWidth, 0.5f * geo.graphBodyWidth); if (evalGraphPictureBox.Width != geo.boxWidth) { evalGraphPictureBox.Width = geo.boxWidth; scrollCheck = true; evalGraphPictureBox.Invalidate(); } if (scrollCheck && evaldata.selectedIndex >= 0) { var x0 = (int)(evaldata.selectedIndex * geo.plyWidth - geo.hScrollValue - graphPlyHPad); var x1 = (int)(x0 + geo.lPad + geo.rPad - Width + graphPlyHPad); if (x0 < 0) { geo.hScrollValue = Math.Max(HorizontalScroll.Value + x0, HorizontalScroll.Minimum); AutoScrollPosition = new Point(geo.hScrollValue, 0); } else if (x1 > 0) { geo.hScrollValue = Math.Min(HorizontalScroll.Value + x1, HorizontalScroll.Maximum); AutoScrollPosition = new Point(geo.hScrollValue, 0); } evalGraphPictureBox.Invalidate(); } scrollCheck = false; using (var brush = new SolidBrush(DColor.White)) { g.FillRectangle(brush, new Rectangle(0, 0, geo.boxWidth, evalGraphPictureBox.Height)); } var vertFunc = evaldata.eval2VertFunc; var strformatScore = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center, }; var strformatPar = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, }; var strformatPly = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near, }; // 手数目盛りの描画 using (var bpen = new Pen(DColor.Black, 2f * geo.lineWidthMul)) using (var bbrush = new SolidBrush(DColor.Black)) for (var i = 0; ; i += 10) { using (var pen = new Pen(DColor.Silver, ((i % 50) == 0 ? 2f : 1f) * geo.lineWidthMul)) { float x = geo.lPad + geo.plyWidth * i; if (x < geo.lPad + geo.hScrollValue) { continue; } if (x > geo.lPad + geo.graphBodyWidth + geo.hScrollValue) { break; } g.DrawLine(pen, x, geo.yadd - geo.ymul, x, geo.yadd + geo.ymul); if (i % 20 != 0) { continue; } g.DrawLine(bpen, x, geo.yadd + geo.ymul, x, geo.yadd + geo.ymul + geo.scaleLineLen); using (var path = new GraphicsPath()) { path.AddString( i.ToString(), Font.FontFamily, (int)Font.Style, geo.plyFontSize, new PointF(0f, 0f), strformatPly ); using (var matrix = new Matrix(geo.scoreFontSizeXmul, 0f, 0f, 1f, x, geo.yadd + geo.ymul + geo.scaleTextPad)) path.Transform(matrix); g.FillPath(bbrush, path); } } } // 評価値目盛りの描画 switch (evaldata.type) { case EvaluationGraphType.Normal: foreach (var ent in evalGraphPictureBox.Height >= 256 ? new[] { new { score = 0, width = 3 }, new { score = 100, width = 1 }, new { score = 200, width = 1 }, new { score = 300, width = 1 }, new { score = 400, width = 1 }, new { score = 500, width = 2 }, new { score = 600, width = 1 }, new { score = 700, width = 1 }, new { score = 800, width = 1 }, new { score = 900, width = 1 }, new { score = 1000, width = 3 }, new { score = 1100, width = 1 }, new { score = 1200, width = 1 }, new { score = 1300, width = 1 }, new { score = 1400, width = 1 }, new { score = 1500, width = 2 }, new { score = 1600, width = 1 }, new { score = 1700, width = 1 }, new { score = 1800, width = 1 }, new { score = 1900, width = 1 }, new { score = 2000, width = 3 }, new { score = 2100, width = 1 }, new { score = 2200, width = 1 }, new { score = 2300, width = 1 }, new { score = 2400, width = 1 }, new { score = 2500, width = 2 }, new { score = 2600, width = 1 }, new { score = 2700, width = 1 }, new { score = 2800, width = 1 }, new { score = 2900, width = 1 }, new { score = 3000, width = 3 }, }: new[] { new { score = 0, width = 3 }, new { score = 500, width = 2 }, new { score = 1000, width = 3 }, new { score = 1500, width = 2 }, new { score = 2000, width = 3 }, new { score = 2500, width = 2 }, new { score = 3000, width = 3 }, }) { var vert = vertFunc((EvalValue)ent.score); var color = DColor.Silver; var y0 = -vert * geo.ymul + geo.yadd; var y1 = +vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, ent.width * geo.lineWidthMul)) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y0, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y0); if (ent.score != 0) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y1, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y1); } } } foreach (var ent in new[] { new { text = "±0", score = 0 }, new { text = "+500", score = +500 }, new { text = "+1000", score = +1000 }, new { text = "+1500", score = +1500 }, new { text = "+2000", score = +2000 }, new { text = "+2500", score = +2500 }, new { text = "+3000", score = +3000 }, new { text = "-500", score = -500 }, new { text = "-1000", score = -1000 }, new { text = "-1500", score = -1500 }, new { text = "-2000", score = -2000 }, new { text = "-2500", score = -2500 }, new { text = "-3000", score = -3000 }, }) { var vert = vertFunc((EvalValue)ent.score); var color = Vert2Color(vert, evaldata.reverse); var y = -vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, 2f * geo.lineWidthMul)) g.DrawLine(pen, geo.lPad + geo.hScrollValue - geo.scaleLineLen, y, geo.lPad + geo.hScrollValue, y); using (var path = new GraphicsPath()) { path.AddString( ent.text, Font.FontFamily, (int)Font.Style, geo.scoreFontSize, new PointF(0f, 0f), strformatScore ); using (var matrix = new Matrix(geo.scoreFontSizeXmul, 0f, 0f, 1f, geo.lPad + geo.hScrollValue - geo.scaleTextPad, y)) path.Transform(matrix); using (var brush = new SolidBrush(color)) g.FillPath(brush, path); } } break; case EvaluationGraphType.TrigonometricSigmoid: foreach (var ent in evalGraphPictureBox.Height >= 192 ? new[] { new { score = 0, width = 3 }, new { score = 100, width = 1 }, new { score = 200, width = 1 }, new { score = 300, width = 1 }, new { score = 400, width = 1 }, new { score = 500, width = 1 }, new { score = 600, width = 1 }, new { score = 700, width = 1 }, new { score = 800, width = 1 }, new { score = 900, width = 1 }, new { score = 1000, width = 2 }, new { score = 2000, width = 1 }, new { score = 3000, width = 1 }, new { score = 4000, width = 1 }, new { score = 5000, width = 1 }, new { score = 6000, width = 1 }, new { score = 7000, width = 1 }, new { score = 8000, width = 1 }, new { score = 9000, width = 1 }, new { score = 9999, width = 2 }, new { score = 99999, width = 1 }, }: new[] { new { score = 0, width = 3 }, new { score = 200, width = 1 }, new { score = 500, width = 1 }, new { score = 1000, width = 2 }, new { score = 2500, width = 1 }, new { score = 9999, width = 2 }, new { score = 99999, width = 1 }, }) { var vert = vertFunc((EvalValue)ent.score); var color = DColor.Silver; var y0 = -vert * geo.ymul + geo.yadd; var y1 = +vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, ent.width * geo.lineWidthMul)) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y0, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y0); if (ent.score != 0) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y1, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y1); } } } foreach (var ent in new[] { new { text = "±0", score = 0 }, new { text = "+200", score = +200 }, new { text = "+500", score = +500 }, new { text = "+1000", score = +1000 }, new { text = "+2500", score = +2500 }, new { text = "+9999", score = +9999 }, new { text = "+∞", score = (int)EvalValue.MatePlus }, new { text = "-200", score = -200 }, new { text = "-500", score = -500 }, new { text = "-1000", score = -1000 }, new { text = "-2500", score = -2500 }, new { text = "-9999", score = -9999 }, new { text = "-∞", score = (int)EvalValue.MatedMinus }, }) { var vert = vertFunc((EvalValue)ent.score); var color = Vert2Color(vert, evaldata.reverse); var y = -vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, 2f * geo.lineWidthMul)) g.DrawLine(pen, geo.lPad + geo.hScrollValue - geo.scaleLineLen, y, geo.lPad + geo.hScrollValue, y); using (var path = new GraphicsPath()) { path.AddString( ent.text, Font.FontFamily, (int)Font.Style, geo.scoreFontSize, new PointF(0f, 0f), strformatScore ); using (var matrix = new Matrix(geo.scoreFontSizeXmul, 0f, 0f, 1f, geo.lPad + geo.hScrollValue - geo.scaleTextPad, y)) path.Transform(matrix); using (var brush = new SolidBrush(color)) g.FillPath(brush, path); } } foreach (var ent in new[] { new { text = "100%", score = (int)EvalValue.MatePlus }, new { text = "99%", score = (int)(600f * Math.Log(0.99f / 0.01f)) }, new { text = "90%", score = (int)(600f * Math.Log(0.9f / 0.1f)) }, new { text = "80%", score = (int)(600f * Math.Log(0.8f / 0.2f)) }, new { text = "70%", score = (int)(600f * Math.Log(0.7f / 0.3f)) }, new { text = "60%", score = (int)(600f * Math.Log(0.6f / 0.4f)) }, new { text = "50%", score = (int)(600f * Math.Log(0.5f / 0.5f)) }, new { text = "40%", score = (int)(600f * Math.Log(0.4f / 0.6f)) }, new { text = "30%", score = (int)(600f * Math.Log(0.3f / 0.7f)) }, new { text = "20%", score = (int)(600f * Math.Log(0.2f / 0.8f)) }, new { text = "10%", score = (int)(600f * Math.Log(0.1f / 0.9f)) }, new { text = "1%", score = (int)(600f * Math.Log(0.01f / 0.99f)) }, new { text = "0%", score = (int)EvalValue.MatedMinus }, }) { var vert = vertFunc((EvalValue)ent.score); var color = Vert2Color(vert, evaldata.reverse); var y = -vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, 2f * geo.lineWidthMul)) g.DrawLine(pen, geo.hScrollValue + geo.lPad + geo.graphBodyWidth, y, geo.hScrollValue + geo.lPad + geo.graphBodyWidth + geo.scaleLineLen, y); using (var path = new GraphicsPath()) { path.AddString( ent.text, Font.FontFamily, (int)Font.Style, geo.parFontSize, new PointF(0f, 0f), strformatPar ); using (var matrix = new Matrix(geo.scoreFontSizeXmul, 0f, 0f, 1f, geo.hScrollValue + geo.lPad + geo.graphBodyWidth + geo.scaleTextPad, y)) path.Transform(matrix); using (var brush = new SolidBrush(color)) g.FillPath(brush, path); } } break; case EvaluationGraphType.WinningRate: foreach (var ent in new[] { new { vert = -1.0f, width = 3 }, new { vert = -0.9f, width = 1 }, new { vert = -0.8f, width = 2 }, new { vert = -0.7f, width = 1 }, new { vert = -0.6f, width = 2 }, new { vert = -0.5f, width = 1 }, new { vert = -0.4f, width = 2 }, new { vert = -0.3f, width = 1 }, new { vert = -0.2f, width = 2 }, new { vert = -0.1f, width = 1 }, new { vert = +0.0f, width = 3 }, new { vert = +0.1f, width = 1 }, new { vert = +0.2f, width = 2 }, new { vert = +0.3f, width = 1 }, new { vert = +0.4f, width = 2 }, new { vert = +0.5f, width = 1 }, new { vert = +0.6f, width = 2 }, new { vert = +0.7f, width = 1 }, new { vert = +0.8f, width = 2 }, new { vert = +0.9f, width = 1 }, new { vert = +1.0f, width = 3 }, }) { var vert = ent.vert; var color = DColor.Silver; var y0 = -vert * geo.ymul + geo.yadd; var y1 = +vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, ent.width * geo.lineWidthMul)) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y0, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y0); if (ent.vert != 0) { g.DrawLine(pen, geo.lPad + geo.hScrollValue, y1, geo.lPad + geo.hScrollValue + geo.graphBodyWidth, y1); } } } foreach (var ent in new[] { new { text = "0%", vert = -1.0f }, new { text = "10%", vert = -0.8f }, new { text = "20%", vert = -0.6f }, new { text = "30%", vert = -0.4f }, new { text = "40%", vert = -0.2f }, new { text = "50%", vert = +0.0f }, new { text = "60%", vert = +0.2f }, new { text = "70%", vert = +0.4f }, new { text = "80%", vert = +0.6f }, new { text = "90%", vert = +0.8f }, new { text = "100%", vert = +1.0f }, }) { var vert = (evaldata.reverse ? -1 : +1) * ent.vert; var color = Vert2Color(vert, evaldata.reverse); var y = -vert * geo.ymul + geo.yadd; using (var pen = new Pen(color, 2f * geo.lineWidthMul)) g.DrawLine(pen, geo.lPad + geo.hScrollValue - geo.scaleLineLen, y, geo.lPad + geo.hScrollValue, y); using (var path = new GraphicsPath()) { path.AddString( ent.text, Font.FontFamily, (int)Font.Style, geo.scoreFontSize, new PointF(0f, 0f), strformatScore ); using (var matrix = new Matrix(geo.scoreFontSizeXmul, 0f, 0f, 1f, geo.lPad + geo.hScrollValue - geo.scaleTextPad, y)) path.Transform(matrix); using (var brush = new SolidBrush(color)) g.FillPath(brush, path); } } break; } // 外枠線の描画 using (var pen = new Pen(DColor.Silver, 3f * geo.lineWidthMul)) { g.DrawRectangle(pen, geo.lPad + geo.hScrollValue, geo.yadd - geo.ymul, geo.graphBodyWidth, geo.ymul + geo.ymul); } // 評価値推移線の描画 for (var p = evaldata.data_array.Count() - 1; p >= 0; --p) { var data = evaldata.data_array[p]; var color = p >= playerColor.Count() ? playerColor.Last() : playerColor[p]; using (var pen = new Pen(color, geo.scoreLineWidth)) for (var i = 1; i < data.values.Count; ++i) { if (i * geo.plyWidth < geo.hScrollValue) { continue; } var y = vertFunc(data.values[i]); if (float.IsNaN(y)) { continue; } int ip = -1; if (i >= 1 && data.values[i - 1] != EvalValue.NoValue) { ip = i - 1; } else if (i >= 2 && data.values[i - 2] != EvalValue.NoValue) { ip = i - 2; } else { continue; } if (ip * geo.plyWidth < geo.hScrollValue) { continue; } if (i * geo.plyWidth > geo.hScrollValue + geo.graphBodyWidth) { break; } var yp = vertFunc(data.values[ip]); g.DrawLine(pen, ip * geo.plyWidth + geo.lPad, -yp * geo.ymul + geo.yadd, i * geo.plyWidth + geo.lPad, -y * geo.ymul + geo.yadd); } } if (evaldata.selectedIndex * geo.plyWidth >= geo.hScrollValue && evaldata.selectedIndex * geo.plyWidth <= geo.hScrollValue + geo.graphBodyWidth) { var x = evaldata.selectedIndex * geo.plyWidth + geo.lPad; using (var pen = new Pen(DColor.DarkTurquoise, 3f)) { g.DrawLine(pen, x, geo.uPad, x, geo.uPad + geo.ymul * 2); } } // 評価値点の描画 for (var i = 0; i < evaldata.maxIndex; ++i) { if (i * geo.plyWidth < geo.hScrollValue) { continue; } if (i * geo.plyWidth > geo.hScrollValue + geo.graphBodyWidth) { break; } // 逆順に描画して番号の若い方を表になるようにする for (var p = evaldata.data_array.Count() - 1; p >= 0; --p) { if (i >= evaldata.data_array[p].values.Count()) { continue; } var color = p >= playerColor.Count() ? playerColor.Last() : playerColor[p]; var y = vertFunc(evaldata.data_array[p].values[i]); if (float.IsNaN(y)) { continue; } using (var brush = new SolidBrush(color)) g.FillEllipse(brush, i * geo.plyWidth + geo.lPad - geo.scoreRound, -y * geo.ymul + geo.yadd - geo.scoreRound, geo.scoreRound * 2, geo.scoreRound * 2); } } }