Beispiel #1
0
        public override void Layout()
        {
            if (_points != null && _points.Count > 0)
            {
                double lineLength      = LineLength;
                int    currentPixelNum = 0;
                if (lineLength > 0)
                {
                    // Tracks the spacing between each of the pixels without worrying about the points.
                    double currentEmptySpace = 0;
                    // Length of the entire segment
                    for (int pointNum = 0; pointNum < _points.Count - 1; pointNum++)
                    {
                        double thisFullLineLength = SegmentLength(pointNum);
                        // First pixel is a special case
                        if (currentEmptySpace + thisFullLineLength > PixelSpacing || pointNum == 0)
                        {
                            double thisEmptyStartLength = PixelSpacing - currentEmptySpace;;
                            if (pointNum == 0)
                            {
                                thisEmptyStartLength = 0;
                            }
                            // Active length of the segment without the start
                            double thisActiveLineLength = thisFullLineLength - thisEmptyStartLength;
                            // Get the pixels in this line. No hangers on the end.
                            double pixelSpacesInThisLine = Math.Truncate(thisActiveLineLength / PixelSpacing);
                            //if (pixelSpacesInThisLine < 0) pixelSpacesInThisLine = 0;
                            double pixelsInThisLine = pixelSpacesInThisLine + 1;
                            // Re-calcuate the active line length
                            thisActiveLineLength = pixelSpacesInThisLine * PixelSpacing;

                            currentEmptySpace = thisFullLineLength - thisEmptyStartLength - thisActiveLineLength;

                            Point lineStartPoint = PreviewTools.CalculatePointOnLine(
                                new PreviewTools.Vector2(_points[pointNum].ToPoint()),
                                new PreviewTools.Vector2(_points[pointNum + 1].ToPoint()),
                                Convert.ToInt32(thisEmptyStartLength));

                            Point lineEndPoint = PreviewTools.CalculatePointOnLine(
                                new PreviewTools.Vector2(_points[pointNum].ToPoint()),
                                new PreviewTools.Vector2(_points[pointNum + 1].ToPoint()),
                                Convert.ToInt32(thisEmptyStartLength + thisActiveLineLength));

                            double xSpacing = (double)(lineStartPoint.X - lineEndPoint.X) / (double)(pixelSpacesInThisLine);
                            double ySpacing = (double)(lineStartPoint.Y - lineEndPoint.Y) / (double)(pixelSpacesInThisLine);
                            double x        = lineStartPoint.X;
                            double y        = lineStartPoint.Y;

                            for (int pixelNum = 0; pixelNum < pixelsInThisLine; pixelNum++)
                            {
                                if (currentPixelNum < Pixels.Count - 1)
                                {
                                    Pixels[currentPixelNum].X = Convert.ToInt32(x);
                                    Pixels[currentPixelNum].Y = Convert.ToInt32(y);
                                    x -= xSpacing;
                                    y -= ySpacing;
                                }

                                currentPixelNum++;
                            }
                            double a1 = _points[pointNum + 1].X - x;
                            double b1 = _points[pointNum + 1].Y - y;
                        }
                        else
                        {
                            currentEmptySpace += thisFullLineLength;
                        }

                        // Finally, put the last dot on the line
                        Pixels[PixelCount - 1].X = _points[_points.Count - 1].X;
                        Pixels[PixelCount - 1].Y = _points[_points.Count - 1].Y;
                    }
                }

                SetPixelZoom();
            }
        }