Ejemplo n.º 1
0
Archivo: SymDef.cs Proyecto: jonc/carto
        // Draw the pattern (at the given angle) inside the path.
        void DrawPattern(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
        {
            object graphicsState = g.Save();

            try {
                // Set the clipping region to draw only inside the area.
                g.SetClip(path);

                // use a transform to rotate
                Matrix matrix = GraphicsUtil.RotationMatrix(patternAngle + angle, new PointF(0, 0));
                g.Transform(matrix);

                // Get the correct bounding rect.
                RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(patternAngle + angle));

                DrawPatternRows(g, bounding, color, renderOpts);
            }
            finally {
                // restore the clip region and the transform
                g.Restore(graphicsState);
            }
        }
Ejemplo n.º 2
0
Archivo: SymDef.cs Proyecto: jonc/carto
        // Draw the pattern using the texture brush.
        void DrawPatternWithTexBrush(GraphicsTarget g, SymPathWithHoles path, float angle, SymColor color, RenderOptions renderOpts)
        {
            Brush brush = (Brush) patternBrushes[color];
            Debug.Assert(brush != null);

            if (angle != 0.0F) {
                object graphicsState = g.Save();

                try {
                    // Set the clipping region to draw only inside the area.
                    g.SetClip(path);

                    // use a transform to rotate.
                    Matrix matrix = GraphicsUtil.RotationMatrix(angle, new PointF(0, 0));
                    g.Transform(matrix);

                    // Get the correct bounding rect.
                    RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -angle);

                    g.FillRectangle(brush, bounding);
                }
                finally {
                    // restore the clip region and the transform
                    g.Restore(graphicsState);
                }
            }
            else {
                path.Fill(g, brush);
            }
        }
Ejemplo n.º 3
0
Archivo: SymDef.cs Proyecto: jonc/carto
        // Draw this area symbol in the graphics inside/around the path provided, with
        // the given color only.
        internal void Draw(GraphicsTarget g, SymPathWithHoles path, SymColor color, float angle, RenderOptions renderOpts)
        {
            if (!pensAndBrushesCreated)
                CreatePensAndBrushes();

            if (color == fillColor) {
                path.Fill(g, color.Brush);
            }

            if (hatchMode != 0 && hatchColor == color) {
                DrawHatching(g, path, angle, renderOpts);
            }

            if (drawPattern && patternGlyph.HasColor(color)) {
                // Faster to draw the pattern with a texture brush that has a bitmap
                // of the pattern in it. Better quality to do it all with glyph drawing.
                // Choose based on the renderOptions.
            #if false
                DrawPatternWithTexBrush(g, path, angle, color, renderOpts);
            #else
                if (renderOpts.usePatternBitmaps) {
                    CreatePatternBrush(renderOpts.minResolution);
                    DrawPatternWithTexBrush(g, path, angle, color, renderOpts);
                }
                else
                    DrawPattern(g, path, angle, color, renderOpts);
            #endif
            }

            // Draw the border. Take into account the subpaths defined by start/stop flags along the paths.
            if (borderSymdef != null && borderSymdef.HasColor(color)) {
                // Draw main part of border.
                foreach (SymPath subpath in path.MainPath.GetSubpaths(SymPath.AREA_BOUNDARY_STARTSTOPFLAG))
                    borderSymdef.Draw(g, subpath, color, renderOpts);

                // Draw the holes.
                if (path.Holes != null)
                    foreach (SymPath hole in path.Holes)
                        foreach (SymPath subpath in hole.GetSubpaths(SymPath.AREA_BOUNDARY_STARTSTOPFLAG))
                            borderSymdef.Draw(g, subpath, color, renderOpts);
            }
        }
Ejemplo n.º 4
0
Archivo: SymDef.cs Proyecto: jonc/carto
        // Draw the hatching into the interior of the SymPath.
        void DrawHatching(GraphicsTarget g, SymPathWithHoles path, float angle, RenderOptions renderOpts)
        {
            object graphicsState = g.Save();

            try {
                // Set the clipping region to draw only inside the area.
                g.SetClip(path);

                // use a transform to rotate and then draw hatching.
                Matrix matrix = GraphicsUtil.RotationMatrix(hatchAngle1 + angle, new PointF(0, 0));
                g.Transform(matrix);

                // Get the correct bounding rect.
                RectangleF bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle1 + angle));

                DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);

                // and again for the second bound of hatching
                if (hatchMode == 2) {
                    // Get the correct bounding rect.
                    bounding = Util.BoundsOfRotatedRectangle(path.BoundingBox, new PointF(), -(hatchAngle2 + angle));

                    matrix = GraphicsUtil.RotationMatrix(hatchAngle2 - hatchAngle1, new PointF(0, 0));
                    g.Transform(matrix);
                    DrawHatchLines(g, hatchPen, hatchSpacing, bounding, renderOpts);
                }
            }
            finally {
                // restore the clip region and the transform
                g.Restore(graphicsState);
            }
        }
Ejemplo n.º 5
0
 // Set a clip on the graphics drawing target.
 public void SetClip(SymPathWithHoles path)
 {
     Graphics.IntersectClip(new Region(path.GetPath()));
 }
Ejemplo n.º 6
0
Archivo: SymDef.cs Proyecto: jonc/carto
 // Calculate the bounding box
 internal RectangleF CalcBounds(SymPathWithHoles path)
 {
     if (borderSymdef != null)
         return borderSymdef.CalcBounds(path.MainPath);
     else
         return path.BoundingBox;
 }
Ejemplo n.º 7
0
Archivo: Glyph.cs Proyecto: jonc/carto
 public void AddArea(SymColor color, SymPathWithHoles path)
 {
     GlyphPart part = new GlyphPart();
     part.kind = GlyphPartKind.Area;
     part.color = color;
     part.areaPath = path;
     AddGlyphPart(part);
 }
Ejemplo n.º 8
0
 // Set a clip on the graphics drawing target.
 public void SetClip(SymPathWithHoles path)
 {
     DrawingContext.PushClip(path.Geometry);
     ++pushLevel;
 }
Ejemplo n.º 9
0
 // Offset the object by a given amount
 public override void Offset(float dx, float dy)
 {
     Matrix m = new Matrix();
     m.Translate(dx, dy);
     path = path.Transform(m);
 }
Ejemplo n.º 10
0
        SymPathWithHoles path; // closed path with the area to fill

        #endregion Fields

        #region Constructors

        protected AreaCourseObj(Id<ControlPoint> controlId, Id<CourseControl> courseControlId, Id<Special> specialId, float scaleRatio, CourseAppearance appearance, PointF[] pts)
            : base(controlId, courseControlId, specialId, scaleRatio, appearance)
        {
            bool lastPtSynthesized = false;

            if (pts[pts.Length - 1] != pts[0]) {
                // If needed, synthesize a final point to close the path.
                PointF[] newPts = new PointF[pts.Length + 1];
                Array.Copy(pts, newPts, pts.Length);
                newPts[pts.Length] = pts[0];
                pts = newPts;
                lastPtSynthesized = true;
            }

               PointKind[] kinds = new PointKind[pts.Length];
               for (int i = 0; i < kinds.Length; ++i)
               kinds[i] = PointKind.Normal;

               this.path = new SymPathWithHoles(new SymPath(pts, kinds, null, lastPtSynthesized), null);
        }
Ejemplo n.º 11
0
        // Move a handle on the area.
        public override void MoveHandle(PointF oldHandle, PointF newHandle)
        {
            PointF[] points = (PointF[]) path.MainPath.Points.Clone();
            PointKind[] kinds = path.MainPath.PointKinds;

            for (int i = 0; i < points.Length; ++i) {
                if (points[i] == oldHandle)
                    points[i] = newHandle;
            }

            path = new SymPathWithHoles(new SymPath(points, kinds), null);
        }
Ejemplo n.º 12
0
        OcadCoord[] CoordsFromSymPathWithHoles(SymPathWithHoles path)
        {
            OcadCoord[] firstCoords = CoordsFromSymPath(path.MainPath);

            SymPath[] holes = path.Holes;

            if (holes == null)
                return firstCoords;

            int totalLength = firstCoords.Length;

            OcadCoord[][] holeCoords = new OcadCoord[holes.Length][];
            for (int i = 0; i < holes.Length; ++i) {
                holeCoords[i] = CoordsFromSymPath(holes[i]);
                totalLength += holeCoords[i].Length;
            }

            OcadCoord[] fullCoords = new OcadCoord[totalLength];
            Array.Copy(firstCoords, 0, fullCoords, 0, firstCoords.Length);
            totalLength = firstCoords.Length;
            for (int i = 0; i < holes.Length; ++i) {
                Array.Copy(holeCoords[i], 0, fullCoords, totalLength, holeCoords[i].Length);
                fullCoords[totalLength].y |= 2; // mark beginning of hole.
                totalLength += holeCoords[i].Length;
            }

            return fullCoords;
        }
Ejemplo n.º 13
0
Archivo: Symbol.cs Proyecto: jonc/carto
 public AreaSymbol(AreaSymDef def, SymPathWithHoles path, float angle)
 {
     this.def = def; this.path = path; this.angle = angle;
     boundingBox = def.CalcBounds(path);
 }
Ejemplo n.º 14
0
Archivo: Symbol.cs Proyecto: jonc/carto
 public ImageAreaSymbol(ImageSymDef def, SymPathWithHoles path, Color fillColor)
 {
     this.def = def; this.path = path; this.fillColor = fillColor;
     boundingBox = path.BoundingBox;
 }
Ejemplo n.º 15
0
Archivo: Symbol.cs Proyecto: jonc/carto
 public GraphicsAreaSymbol(GraphicsSymDef def, SymPathWithHoles path, SymColor fillColor)
 {
     this.def = def; this.path = path; this.fillColor = fillColor;
     boundingBox = path.BoundingBox;
 }