Exemplo n.º 1
0
        protected NCompositeShape CreateState(XmlElement state)
        {
            string pathPoints = state.Attributes["PathPoints"].Value.ToString();
            string pathTypes  = state.Attributes["PathTypes"].Value.ToString();

            string[]  pathPointsStr = pathPoints.Split(' ');
            NPointF[] pathPointsF   = new NPointF[pathPointsStr.Length];

            float scaleX = NDrawingView1.Dimensions.Width;
            float scaleY = NDrawingView1.Dimensions.Height;

            for (int i = 0; i < pathPointsStr.Length; i++)
            {
                string[] xyStr = pathPointsStr[i].Split(',');

                pathPointsF[i].X = (Single.Parse(xyStr[0])) * scaleX;
                pathPointsF[i].Y = (Single.Parse(xyStr[1])) * scaleY;
            }

            string[] pathTypesStr = pathTypes.Split(' ');
            byte[]   pathTypesB   = new byte[pathTypesStr.Length];

            for (int i = 0; i < pathTypesStr.Length; i++)
            {
                pathTypesB[i] = Byte.Parse(pathTypesStr[i]);
            }

            NCustomPath     path  = new NCustomPath(pathPointsF, pathTypesB, PathType.ClosedFigure);
            NCompositeShape shape = new NCompositeShape();

            shape.Primitives.AddChild(path);
            shape.UpdateModelBounds();

            return(shape);
        }
Exemplo n.º 2
0
        private void CreateDoubleOpenedArrowShape()
        {
            NRectangleF modelBounds = new NRectangleF(0, -1, 2, 2);

            float fXCenter = modelBounds.X + modelBounds.Width / 2;
            float fYCenter = modelBounds.Y + modelBounds.Height / 2;

            PointF[]     lines = new PointF[3];
            GraphicsPath path  = new GraphicsPath();

            // arrow1
            lines[0] = new PointF(fXCenter, modelBounds.Y);
            lines[1] = new PointF(modelBounds.X, fYCenter);
            lines[2] = new PointF(fXCenter, modelBounds.Bottom);
            path.AddLines(lines);

            // arrow2
            path.StartFigure();
            lines[0] = new PointF(modelBounds.Right, modelBounds.Y);
            lines[1] = new PointF(fXCenter, fYCenter);
            lines[2] = new PointF(modelBounds.Right, modelBounds.Bottom);
            path.AddLines(lines);

            /// create a custom open figure and name it
            NCustomPath strokePath = new NCustomPath(path, PathType.OpenFigure);

            strokePath.Name = "Double Opened Arrow";

            // add it to the arrowhead shape stencil
            document.ArrowheadShapeStencil.AddChild(strokePath);
        }
Exemplo n.º 3
0
        private void CreateStarPointShape()
        {
            // create the graphics path representing the point shape
            NRectangleF  modelBounds = new NRectangleF(-1, -1, 2, 2);
            GraphicsPath path        = new GraphicsPath();

            CreateNGramPath(path, modelBounds, 5, -NMath.PIHalf, 0.5f);

            // wrap it in a model and name it
            NCustomPath customPath = new NCustomPath(path, PathType.ClosedFigure);

            customPath.Name = "Star";

            // add it to the stencil
            document.PointShapeStencil.AddChild(customPath);
        }
Exemplo n.º 4
0
        private void InitDocument()
        {
            document.Style.StartArrowheadStyle.Shape = ArrowheadShape.None;
            document.Style.EndArrowheadStyle.Shape   = ArrowheadShape.None;

            int row         = 0;
            int col         = 0;
            int maxColCount = 5;
            int index       = 0;

            foreach (NPointShape pointShape in document.PointShapeStencil.PredefinedPointShapes)
            {
                // create the path representing the arrow head shape
                NCustomPath path = new NCustomPath((GraphicsPath)pointShape.Path.Clone(), pointShape.Closed? PathType.ClosedFigure: PathType.OpenFigure);

                // create a shape to host the path
                NCompositeShape shape = new NCompositeShape();
                shape.Primitives.AddChild(path);
                shape.UpdateModelBounds();

                // reposition the shape and add to active layer
                shape.Bounds = base.GetGridCell(row, col);
                document.ActiveLayer.AddChild(shape);

                // describe it
                string     str  = NExamplesHelper.InsertSpacesBeforeUppers(((PointShape)(index + 2)).ToString());
                NTextShape text = new NTextShape(str, base.GetGridCell(row + 1, col));
                document.ActiveLayer.AddChild(text);

                col++;
                index++;

                if (col > maxColCount)
                {
                    row += 2;
                    col  = 0;
                }
            }
        }
            public NExpandCollapseCheck()
            {
                // base
                Primitives.AddChild(new NRectanglePath(-1, -1, 2, 2));

                // plus
                GraphicsPath path = new GraphicsPath();

                path.AddLine(new PointF(-0.5f, 0), new PointF(0.5f, 0));
                path.StartFigure();
                path.AddLine(new PointF(0, 0.5f), new PointF(0, -0.5f));

                NCustomPath customPath = new NCustomPath(path, PathType.OpenFigure);

                customPath.Visible = false;

                Primitives.AddChild(customPath);

                // minus
                NLinePath linePath = new NLinePath(-0.5f, 0, 0.5f, 0);

                Primitives.AddChild(linePath);

                // update the model bounds to fit the primitives
                UpdateModelBounds();

                // destory all optional shape elements
                DestroyShapeElements(ShapeElementsMask.All);

                // add interactivity
                Style.InteractivityStyle            = new NInteractivityStyle(true, string.Empty, "Click to expand/collapse subtree", CursorType.Hand);
                linePath.Style                      = linePath.ComposeStyle();
                linePath.Style.InteractivityStyle   = new NInteractivityStyle(true, string.Empty, "Click to expand/collapse subtree", CursorType.Hand);
                customPath.Style                    = customPath.ComposeStyle();
                customPath.Style.InteractivityStyle = new NInteractivityStyle(true, string.Empty, "Click to expand/collapse subtree", CursorType.Hand);
            }
Exemplo n.º 6
0
        protected NCompositeShape CreateCoffeeCupShape(NPointF location, float scale)
        {
            NCompositeShape shape = new NCompositeShape();

            // create the cup as a polygon path
            NPolygonPath cup = new NPolygonPath(new NPointF[] { new NPointF(45, 268),
                                                                new NPointF(63, 331),
                                                                new NPointF(121, 331),
                                                                new NPointF(140, 268) });

            shape.Primitives.AddChild(cup);

            // create the cup hangle as a closed curve path
            NClosedCurvePath handle = new NClosedCurvePath(new NPointF[] { new NPointF(175, 295),
                                                                           new NPointF(171, 278),
                                                                           new NPointF(140, 283),
                                                                           new NPointF(170, 290),
                                                                           new NPointF(128, 323) }, 1);

            NStyle.SetFillStyle(handle, new NColorFillStyle(Color.LightSalmon));
            shape.Primitives.AddChild(handle);

            // create the steam as a custom filled path
            GraphicsPath path = new GraphicsPath();

            path.AddBeziers(new PointF[] { new PointF(92, 258),
                                           new PointF(53, 163),
                                           new PointF(145, 160),
                                           new PointF(86, 50),
                                           new PointF(138, 194),
                                           new PointF(45, 145),
                                           new PointF(92, 258) });
            path.CloseAllFigures();

            NCustomPath steam = new NCustomPath(path, PathType.ClosedFigure);

            NStyle.SetFillStyle(steam, new NColorFillStyle(Color.FromArgb(50, 122, 122, 122)));
            shape.Primitives.AddChild(steam);

            // update the shape model bounds to fit the primitives it contains
            shape.UpdateModelBounds();

            // create the shape ports
            shape.CreateShapeElements(ShapeElementsMask.Ports);

            // create dynamic port anchored to the cup center
            NDynamicPort dynamicPort = new NDynamicPort(cup.UniqueId, ContentAlignment.MiddleCenter, DynamicPortGlueMode.GlueToContour);

            shape.Ports.AddChild(dynamicPort);

            // create rotated bounds port anchored to the middle right side of the handle
            NRotatedBoundsPort rotatedBoundsPort = new NRotatedBoundsPort(handle.UniqueId, ContentAlignment.MiddleRight);

            shape.Ports.AddChild(rotatedBoundsPort);

            // apply style to the shape
            shape.Style.FillStyle = new NColorFillStyle(Color.LightCoral);

            // position it and scale the shape
            shape.Location = location;
            shape.Width    = shape.Width * scale;
            shape.Height   = shape.Height * scale;

            return(shape);
        }