protected void DrawPoint(ICanvas canvas, Pen pen, Brush fillBrush) { Rectangle screenrect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(canvas, m_boundingRect)); canvas.Graphics.DrawRectangle(pen, screenrect); screenrect.X++; screenrect.Y++; screenrect.Width--; screenrect.Height--; if (fillBrush != null) { canvas.Graphics.FillRectangle(fillBrush, screenrect); } }
static public void DrawNode(ICanvas canvas, UnitPoint nodepoint) { RectangleF r = new RectangleF(canvas.ToScreen(nodepoint), new SizeF(0, 0)); r.Inflate(3, 3); if (r.Right < 0 || r.Left > canvas.ClientRectangle.Width) { return; } if (r.Top < 0 || r.Bottom > canvas.ClientRectangle.Height) { return; } canvas.Graphics.FillRectangle(Brushes.White, r); r.Inflate(1, 1); canvas.Graphics.DrawRectangle(Pens.Black, ScreenUtils.ConvertRect(r)); }
bool InitPixelMatrix() { if (_canvas is CanvasWrapper) { int matrixSize = GetPixelMatrixSize(); if (matrixSize < 1) { return(false); } if (m_pixelMatrix == null) { m_pixelMatrix = new byte[matrixSize, matrixSize]; } for (int ii = 0; ii < matrixSize; ++ii) { for (int jj = 0; jj < matrixSize; ++jj) { //init m_pixelMatrix[ii, jj] = 1; //the path can pass through these point } } bool exportInfo = false; List <IDrawObject> allObjs = _canvas.DataModel.GetHitObjects(_canvas, ScreenPixelRectToUnitRect(), false); foreach (var obj in allObjs) { DrawTools.RectBase rectBase = obj as DrawTools.RectBase; if (rectBase == null) { continue; } Rectangle pixelRect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(_canvas, rectBase.GetExactBoundingRect(_canvas))); pixelRect.Inflate(-1, -1);//make sure the point can lay down on the boundary of rectangle PopulateValToMatrix(m_pixelMatrix, pixelRect); //for (int ii = pixelRect.Top; ii < pixelRect.Bottom; ++ii) //{ // for (int jj = pixelRect.Left; jj < pixelRect.Right; ++jj) // { // m_pixelMatrix[jj, ii] = 0;//the path should not pass throught these point // } //} //const int threshold = 10; //int[] leftXInterval = { pixelRect.Left, pixelRect.Left - threshold }; //int[] rightXInterval = { pixelRect.Right, pixelRect.Right + threshold }; //int[] topAndBottomXInterval = { pixelRect.Left, pixelRect.Right }; //int[] leftAndRightYInterval = { pixelRect.Top, pixelRect.Bottom }; //int[] topYInterval = { pixelRect.Top, pixelRect.Top - threshold }; //int[] bottomYInterval = { pixelRect.Bottom, pixelRect.Bottom + threshold }; //PopulateLinearBoundary(leftXInterval[0], leftXInterval[1], leftAndRightYInterval[0], leftAndRightYInterval[1], true); //PopulateLinearBoundary(rightXInterval[0], rightXInterval[1], leftAndRightYInterval[0], leftAndRightYInterval[1], true); //PopulateLinearBoundary(topYInterval[0], topYInterval[1], topAndBottomXInterval[0], topAndBottomXInterval[1], false); //PopulateLinearBoundary(bottomYInterval[0], bottomYInterval[1], topAndBottomXInterval[0], topAndBottomXInterval[1], false); //--------------------------------------------------- int nItems = m_pixelMatrix.GetUpperBound(0) + 1; int maxX = -1, maxY = -1, minX = 100000, minY = 100000; for (int ii = 0; ii < nItems && exportInfo; ++ii) //row { for (int jj = 0; jj < nItems; ++jj) //column { int val = m_pixelMatrix[jj, ii]; // Console.Write("{0} ", val); if (val != 0) { continue; } if (jj < minX) { minX = jj; } if (jj > maxX) { maxX = jj; } if (ii < minY) { minY = ii; } if (ii > maxY) { maxY = ii; } } // Console.Write("\n"); } //--------------------------------------------------- } return(true); } else { System.Diagnostics.Debug.Assert(false); return(false); } }