//////////////////////////////////////////////////////////////////////////////// /// @brief 1マス描画 /// @fn void DrawSingleLocal(int y, int x, int sts, int bk, string text) /// @param[in] int y Y座標 /// @param[in] int x X座標 /// @param[in] int sts ステータス /// @param[in] int bk 背景 /// @param[in] string text テキスト /// @return ありません /// @author Yuta Yoshinaga /// @date 2017.10.20 /// //////////////////////////////////////////////////////////////////////////////// public void DrawSingleLocal(int y, int x, int sts, int bk, string text) { Canvas curPict = (Canvas)this.grid_reversi_fields.Children.Cast <UIElement>().First(e => Grid.GetRow(e) == y && Grid.GetColumn(e) == x); if ( curPict != null && !Double.IsNaN(curPict.ActualWidth) && !Double.IsNaN(curPict.ActualHeight) && ((int)curPict.ActualWidth != 0) && ((int)curPict.ActualHeight != 0) ) { // 描画先とするImageオブジェクトを作成する Bitmap canvas = new Bitmap((int)curPict.ActualWidth, (int)curPict.ActualHeight); // ImageオブジェクトのGraphicsオブジェクトを作成する Graphics g = Graphics.FromImage(canvas); g.SmoothingMode = SmoothingMode.HighQuality; System.Drawing.Pen curPen1 = new System.Drawing.Pen(m_AppSettings.mBorderColor, 2); // Brushオブジェクトの作成 SolidBrush curBru1 = null; SolidBrush curBru2 = null; SolidBrush curBru3 = null; System.Drawing.Color curBkColor = m_AppSettings.mBackGroundColor; byte tmpA = curBkColor.A; byte tmpR = curBkColor.R; byte tmpG = curBkColor.G; byte tmpB = curBkColor.B; System.Drawing.Color curBkColorRev; if (bk == 1) { // *** cell_back_blue *** // tmpG -= 127; if (tmpG < 0) { tmpG += 255; } tmpB += 255; if (255 < tmpB) { tmpB -= 255; } curBkColor = System.Drawing.Color.FromArgb(tmpA, tmpR, tmpG, tmpB); } else if (bk == 2) { // *** cell_back_red *** // tmpR += 255; if (255 < tmpR) { tmpR -= 255; } tmpG -= 127; if (tmpG < 0) { tmpG += 255; } tmpB -= 127; if (tmpB < 0) { tmpB += 255; } curBkColor = System.Drawing.Color.FromArgb(tmpA, tmpR, tmpG, tmpB); } else if (bk == 3) { // *** cell_back_magenta *** // tmpR += 255; if (255 < tmpR) { tmpR -= 255; } tmpB += 255; if (255 < tmpB) { tmpB -= 255; } curBkColor = System.Drawing.Color.FromArgb(tmpA, tmpR, tmpG, tmpB); } else { // *** cell_back_green *** // curBkColor = System.Drawing.Color.FromArgb(tmpA, tmpR, tmpG, tmpB); } curBru1 = new SolidBrush(curBkColor); HslColor workCol = HslColor.FromRgb(curBkColor); float h = workCol.H + 180F; if (359F < h) { h -= 360F; } curBkColorRev = HslColor.ToRgb(new HslColor(h, workCol.S, workCol.L)); curBru3 = new SolidBrush(curBkColorRev); if (sts == ReversiConst.REVERSI_STS_NONE) { } else if (sts == ReversiConst.REVERSI_STS_BLACK) { curBru2 = new SolidBrush(m_AppSettings.mPlayerColor1); } else if (sts == ReversiConst.REVERSI_STS_WHITE) { curBru2 = new SolidBrush(m_AppSettings.mPlayerColor2); } else if (sts == ReversiConst.REVERSI_STS_BLUE) { curBru2 = new SolidBrush(m_AppSettings.mPlayerColor3); } else if (sts == ReversiConst.REVERSI_STS_RED) { curBru2 = new SolidBrush(m_AppSettings.mPlayerColor4); } // 位置(x, y)にActualWidth x ActualHeightの四角を描く g.FillRectangle(curBru1, 0, 0, (float)curPict.ActualWidth, (float)curPict.ActualHeight); // 位置(x, y)にActualWidth x ActualHeightの四角を描く g.DrawRectangle(curPen1, 0, 0, (float)curPict.ActualWidth, (float)curPict.ActualHeight); // 先に描いた四角に内接する楕円を黒で描く if (curBru2 != null) { g.FillEllipse(curBru2, 2, 2, (float)curPict.ActualWidth - 4, (float)curPict.ActualHeight - 4); } if (text != null && text.Length != 0 && text != "0") { // フォントオブジェクトの作成 int fntSize = (int)curPict.ActualWidth; if (curPict.ActualHeight < fntSize) { fntSize = (int)curPict.ActualHeight; } fntSize = (int)((double)fntSize * 0.75); fntSize /= text.Length; if (fntSize < 8) { fntSize = 8; } Font fnt = new Font("MS UI Gothic", fntSize); System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(0, 0, (int)curPict.ActualWidth, (int)curPict.ActualHeight); StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(text, fnt, curBru3, rect1, stringFormat); //リソースを解放する fnt.Dispose(); } // リソースを解放する g.Dispose(); // curPictに表示する System.Windows.Controls.Image img = new System.Windows.Controls.Image(); img.Source = this.ToImageSource(canvas); img.Width = canvas.Width; img.Height = canvas.Height; Canvas.SetLeft(img, 0); Canvas.SetTop(img, 0); curPict.Children.Add(img); } }