public void GBPatternDigit(RenderTargetBitmap bmp, int[,] GPat) { int LWid = pGNP00.lineWidth / 2; int csz = pGNP00.cellSize / 2; int cszP = csz + 1; bmp.Clear(); GFont gFnt16 = new GFont("Courier", 16, FontWeights.Normal, FontStyles.Normal); GFormattedText GF16 = new GFormattedText(gFnt16); var drawVisual = new DrawingVisual(); using (DrawingContext DC = drawVisual.RenderOpen()){ Brush br = new SolidColorBrush(Colors.DarkBlue); Point pt = new Point(); for (int rc = 0; rc < 81; rc++) { int r = rc / 9, c = rc % 9; int No = GPat[r, c]; if (No == 0) { continue; } pt.X = c * 19 + c / 3 + 6; pt.Y = r * 19 + r / 3 + 2; DC.DrawText(GF16.GFText(No.ToString(), br), pt); } } bmp.Render(drawVisual); }
public GFormattedText(GFont gf) { gFnt = gf; }
public void GBoardPaintPrint(RenderTargetBitmap bmp, UPuzzle pGP) { if (pGP == null) { return; } int LWid = pGNP00.lineWidth; int CSiz = pGNP00.cellSize; int CSizP = CSiz + LWid; Brush brBoad = new SolidColorBrush(Colors.White); Point ptS, ptE; //RenderTargetBitmap Rbmp; Rect Rrct = new Rect(0, 0, CSiz, CSiz); //Courier GFont gFnt32 = new GFont("Courier", 32, FontWeights.DemiBold, FontStyles.Normal); GFormattedText GF32 = new GFormattedText(gFnt32); var drawVisual = new DrawingVisual(); using (DrawingContext DC = drawVisual.RenderOpen()){ DC.DrawRectangle(brBoad, null, new Rect(0, 0, bmp.Width, bmp.Height)); Brush br = new SolidColorBrush(Colors.Black); Point pt = new Point(); foreach (UCell BDX in pGP.BDL) { int r = BDX.r, c = BDX.c; pt.X = c * CSizP + LWid / 2 + (c / 3); pt.Y = r * CSizP + LWid / 2 + (r / 3); Rrct.X = pt.X; Rrct.Y = pt.Y; int No = BDX.No; if (No != 0) { #region Problem/solved cell pt.X += 10; pt.Y += 2; string NoStr = Abs(No).ToString(); DC.DrawText(GF32.GFText(NoStr, br), pt); #endregion } } #region Draw line on board Pen pen1 = new Pen(br, 1), pen2 = new Pen(br, 2), pen; int hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(0, hh); ptE = new Point(CSiz * 10 - 2, hh); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(hh, 0); ptE = new Point(hh, CSiz * 10 - 2); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } #endregion } bmp.Render(drawVisual); return; }
public void GBoardPaint(RenderTargetBitmap bmp, List <UCell> qBDL, string GSmodeX = "", bool sNoAssist = false, bool whiteBack = false) { if (qBDL == null || bmp == null) { return; } int LWid = pGNP00.lineWidth; int CSiz = pGNP00.cellSize; int CSizP = CSiz + LWid; Brush brBL = new SolidColorBrush(pColorDic["BoardLine"]); Brush brBoad = new SolidColorBrush(pColorDic["Board"]); Brush brFNo = new SolidColorBrush(pColorDic["CellForeNo"]); Brush brPNo = new SolidColorBrush(pColorDic["CellBkgdPNo"]); Brush brMNo = new SolidColorBrush(pColorDic["CellBkgdMNo"]); Brush brZNo = new SolidColorBrush(pColorDic["CellBkgdZNo"]); if (whiteBack) { brBL = brFNo = Brushes.Black; brBoad = brPNo = brMNo = brZNo = Brushes.White; } //MS 明朝 平成明朝 MS ゴシック GFont gFnt32 = new GFont("Courier", 32, FontWeights.DemiBold, FontStyles.Normal); GFormattedText GF32 = new GFormattedText(gFnt32); Point pt = new Point(); var drawVisual = new DrawingVisual(); using (DrawingContext DC = drawVisual.RenderOpen()){ //Initialize DC.DrawRectangle(brBoad, null, new Rect(0, 0, bmp.Width, bmp.Height)); if (qBDL.Any(p => p.No != 0)) { #region Draw digit on board // ProblemCell(No>0) SolvedCell(No<0) Rect Rrct = new Rect(0, 0, CSiz, CSiz); foreach (UCell P in qBDL.Where(p => p.No != 0)) { int r = P.r, c = P.c; pt.X = LWid + c * CSizP + (c / 3); pt.Y = LWid + r * CSizP + (r / 3); Brush br = (P.No > 0)? brPNo: brMNo; Rrct.X = pt.X + 1; Rrct.Y = pt.Y + 1; DC.DrawRectangle(br, null, Rrct); string NoStr = Abs(P.No).ToString(); pt.X += 10; pt.Y += 2; DC.DrawText(GF32.GFText(NoStr, brFNo), pt); } //Unsolved if (sNoAssist) { foreach (UCell P in qBDL.Where(p => p.No == 0)) { int r = P.r, c = P.c; pt.X = LWid + c * CSizP + (c / 3); pt.Y = LWid + r * CSizP + (r / 3); Rrct.X = pt.X + 1; Rrct.Y = pt.Y + 1; RenderTargetBitmap Rbmp = CreateCellImage(P, true); DC.DrawImage(Rbmp, Rrct); } } #endregion } #region Draw line on board Pen pen, pen1 = new Pen(brBL, 1), pen2 = new Pen(brBL, 2); Point ptS, ptE; int hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(0, hh); ptE = new Point(CSiz * 10 - 2, hh); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } hh = 1; for (int k = 0; k < 10; k++) { ptS = new Point(hh, 0); ptE = new Point(hh, CSiz * 10 - 2); pen = ((k % 3) == 0)? pen2: pen1; DC.DrawLine(pen, ptS, ptE); hh += CSizP + (k % 3) / 2; } #endregion } bmp.Clear(); bmp.Render(drawVisual); return; }