Beispiel #1
0
        protected NShape CreateDrawEllipse()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the draw ellipse command draws an ellipse inside a relative or absolute rect inside the shape coordinate system.
            // The following draws an ellipse that fills the shape.
            NDrawEllipse drawEllipse = new NDrawEllipse(0, 0, 1, 1);

            shape.Geometry.AddRelative(drawEllipse);

            return(shape);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a shape
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        NShape CreateButtonShape(string text)
        {
            NShape buttonShape = new NShape();

            buttonShape.Init2DShape();

            // make a button and place it in the shape
            NButton button = new NButton(text);

            buttonShape.Widget = button;

            // bind size to button desired size
            BindSizeToDesiredSize(buttonShape);

            return(buttonShape);
        }
Beispiel #3
0
        protected NShape CreateLineTo()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the LineTo command draws a line from the prev plotter command to the command location
            {
                NMoveTo plotFigure =
                    shape.Geometry.RelMoveTo(0, 0);
                shape.Geometry.RelLineTo(1, 1);
                plotFigure.ShowFill = false;
            }

            return(shape);
        }
Beispiel #4
0
        protected NShape CreateCircularArcTo()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the CircularAcrTo command draws a circular arc from the prev plotter command to the command location.
            // the circular acr curve is controled by a control point which defines the circle trough which the arc passes.
            {
                NMoveTo plotFigure =
                    shape.Geometry.RelMoveTo(0, 0);
                shape.Geometry.RelCircularArcTo(1, 1, 1, 0);
                plotFigure.ShowFill = false;
            }

            return(shape);
        }
Beispiel #5
0
        protected NShape CreateCubicBezierTo()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the CubicBezierTo command draws a cubic bezier from the prev plotter command to the command location.
            // the cubic bezier curve is controled by two control points.
            {
                NMoveTo plotFigure =
                    shape.Geometry.RelMoveTo(0, 0);
                shape.Geometry.RelCubicBezierTo(1, 1, 1, 0, 0, 1);
                plotFigure.ShowFill = false;
            }

            return(shape);
        }
Beispiel #6
0
        protected NShape CreateArcTo()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the ArcTo command draws a circular arc from the prev plotter command to the command location.
            // the ArcTo Bow parameter defines the distance of the arc from the line formed by previous command location and the command location
            {
                NMoveTo plotFigure =
                    shape.Geometry.RelMoveTo(0, 0);
                shape.Geometry.RelArcTo(1, 1, 30);
                plotFigure.ShowFill = false;
            }

            return(shape);
        }
Beispiel #7
0
        protected void CreateDescriptionPair(int row, int col, NShape shape, string text)
        {
            const double startX  = 20;
            const double startY  = 100;
            const double width   = 80;
            const double height  = 100;
            const double spacing = 20;

            m_DrawingDocument.Content.ActivePage.Items.Add(shape);
            shape.SetBounds(new NRectangle(startX + col * (width + spacing), startY + row * (height + spacing), width, height / 2));

            NShape textShape = new NShape();

            textShape.Init2DShape();
            textShape.Text = text;
            textShape.SetBounds(new NRectangle(startX + col * (width + spacing), startY + row * (height + spacing) + height / 2, width, height / 2));
            m_DrawingDocument.Content.ActivePage.Items.Add(textShape);
        }
Beispiel #8
0
        protected NShape CreateEllipticalArcTo()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // the EllipticalArcTo command draws an elliptical arc from the prev plotter command to the command location.
            // the elliptical acr curve is controled by a control point which defines the ellipse trough which the arc passes,
            // the angle of the ellipse and the ratio between the ellipse radiuses.
            {
                NMoveTo plotFigure =
                    shape.Geometry.RelMoveTo(0, 0);
                shape.Geometry.RelEllipticalArcTo(1, 1, 1, 0, new NAngle(0, NUnit.Degree), 0.5);
                plotFigure.ShowFill = false;
            }

            return(shape);
        }
Beispiel #9
0
        protected NShape CreateDrawPath()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            NGraphicsPath path = new NGraphicsPath();

            path.AddRectangle(0, 0, 0.5, 0.5);
            path.AddEllipse(0.5, 0.5, 0.5, 0.5);

            // the draw path command draws a path inside a relative or absolute rect inside the shape coordinate system.
            // The following draws a path that contains a rectangle and an ellipse that fills the shape.
            NDrawPath drawPath = new NDrawPath(0, 0, 1, 1, path);

            shape.Geometry.AddRelative(drawPath);

            return(shape);
        }
Beispiel #10
0
        protected NShape CreateDrawPolygon(double tension)
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            NGenericNGram ngon = new NGenericNGram(4, 0, 0.5, 0.1, new NPoint(0.5, 0.5));

            NPoint[] points = ngon.CreateVertices();

            // the draw ellipse command draws an ellipse inside a relative or absolute rect inside the shape coordinate system.
            // The following draws an ellipse that fills the shape.
            NDrawPolygon drawPolygon = new NDrawPolygon(0, 0, 1, 1, points);

            drawPolygon.Tension = tension;
            shape.Geometry.AddRelative(drawPolygon);

            return(shape);
        }
Beispiel #11
0
        protected NShape CreateDrawPolyline(double tension)
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            NPoint[] points = new NPoint[] {
                new NPoint(0, 0),
                new NPoint(0.25, 1),
                new NPoint(0.50, 0),
                new NPoint(0.75, 1),
                new NPoint(1, 0),
            };

            // the draw ellipse command draws an ellipse inside a relative or absolute rect inside the shape coordinate system.
            // The following draws an ellipse that fills the shape.
            NDrawPolyline drawPolyline = new NDrawPolyline(0, 0, 1, 1, points);

            drawPolyline.Tension  = tension;
            drawPolyline.ShowFill = false;
            shape.Geometry.AddRelative(drawPolyline);

            return(shape);
        }
        private NShape CreateTrapezoidShape(double width, double height, double pinX, double pinY)
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            shape.Width  = width;
            shape.Height = height;

            shape.PinX = pinX;
            shape.PinY = pinY;

            // add controls
            NControl control = new NControl();

            control.SetFx(NControl.XProperty, new NShapeWidthFactorFx(0.3));
            control.Y         = 0.0d;
            control.XBehavior = ENCoordinateBehavior.OffsetFromMax;
            control.YBehavior = ENCoordinateBehavior.Locked;
            control.Tooltip   = "Modify strip width";
            shape.Controls.Add(control);

            // add a geometry
            NGeometry geometry1 = new NGeometry();

            {
                NMoveTo plotFigure =
                    geometry1.MoveTo("MIN(Controls.0.X,Width-Controls.0.X)", 0.0d);
                geometry1.LineTo("Width-Geometry.0.X", 0.0d);
                geometry1.LineTo(new NShapeWidthFactorFx(1), new NShapeHeightFactorFx(1));
                geometry1.LineTo(0.0d, "Height");
                geometry1.LineTo("Geometry.0.X", "Geometry.0.Y");
                plotFigure.CloseFigure = true;
            }
            shape.Geometry = geometry1;

            // add ports
            // top
            NPort port = new NPort();

            port.SetFx(NPort.XProperty, new NShapeWidthFactorFx(0.5));
            port.Y        = 0.0d;
            port.GlueMode = ENPortGlueMode.Outward;
            port.DirX     = 0.0d;
            port.DirY     = -1;
            shape.Ports.Add(port);

            // right
            port = new NPort();
            port.SetFx(NPort.XProperty, new NShapeWidthFactorFx(1));
            port.SetFx(NPort.YProperty, new NShapeHeightFactorFx(0.5));
            port.GlueMode = ENPortGlueMode.InwardAndOutward;
            port.DirX     = 1;
            port.DirY     = 0.0d;
            shape.Ports.Add(port);

            // bottom
            port = new NPort();
            port.SetFx(NPort.XProperty, "Controls.0.X");
            port.SetFx(NPort.YProperty, new NShapeHeightFactorFx(1));
            port.DirX = 0.0d;
            port.DirY = 1;
            shape.Ports.Add(port);

            // left
            port   = new NPort();
            port.X = 0.0d;
            port.SetFx(NPort.YProperty, new NShapeHeightFactorFx(0.5));
            port.DirX = -1;
            port.DirY = 0.0d;
            shape.Ports.Add(port);

            // shape.FillStyle = new NColorFillStyle(Color.Gray);
            shape.Geometry.Stroke          = new NStroke(1, NColor.Black);
            shape.Geometry.Stroke.LineJoin = ENLineJoin.Miter;

            /*			NShadow shadow = new NShadow(NColor.Green, 50, 50);
             *          shadow.ScalePinPoint = new NPoint(0.5, 0.5);
             *          shadow.Scale = 1.0;
             *          shadow.UseFillAndStrokeAlpha = false;
             *          shadow.ApplyToFilling = true;
             *          shadow.ApplyToOutline = true;
             *          shape.Shadow = shadow;*/

            NStackPanel stack = new NStackPanel();

            NButton button = new NButton("Hello Joro");

            //button.Click += new Function<NEventArgs>(button_Click);
            stack.Add(button);

            NLabel label = new NLabel("Hello World");

            stack.Add(label);
            //shape.Widget = stack;
            //shape.Widget = new NLabel("Hello World");

            return(shape);
        }
Beispiel #13
0
        private NShape CreateAndShape()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            NSize         normalSize = new NSize(1, 1);
            NGraphicsPath path       = new NGraphicsPath();

            // create input lines
            double x1 = 0;
            double y1 = normalSize.Height / 3;

            path.StartFigure(x1, y1);
            path.LineTo(normalSize.Width / 4, y1);

            double y2 = normalSize.Height * 2 / 3;
            double x2 = 0;

            path.StartFigure(x2, y2);
            path.LineTo(normalSize.Width / 4, y2);

            // create body
            path.StartFigure(normalSize.Width / 4, 0);
            path.LineTo(normalSize.Width / 4, 1);
            NPoint ellipseCenter = new  NPoint(normalSize.Width / 4, 0.5);

            path.AddEllipseSegment(NRectangle.FromCenterAndSize(ellipseCenter, normalSize.Width, normalSize.Height), NMath.PIHalf, -NMath.PI);
            path.CloseFigure();

            // create output
            double y3 = normalSize.Height / 2;
            double x3 = normalSize.Width;

            path.StartFigure(normalSize.Width * 3 / 4, y3);
            path.LineTo(x3, y3);

            shape.Geometry.AddRelative(new NDrawPath(new NRectangle(0, 0, 1, 1), path));

            // create ports
            NPort input1 = new NPort();

            input1.X        = x1;
            input1.Y        = y1;
            input1.Relative = true;
            input1.SetDirection(ENBoxDirection.Left);
            input1.FlowMode = ENPortFlowMode.Input;
            shape.Ports.Add(input1);

            NPort input2 = new NPort();

            input2.X        = x2;
            input2.Y        = y2;
            input2.Relative = true;
            input2.SetDirection(ENBoxDirection.Left);
            input2.FlowMode = ENPortFlowMode.Input;
            shape.Ports.Add(input2);

            NPort output1 = new NPort();

            output1.X        = x3;
            output1.Y        = y3;
            output1.Relative = true;
            output1.SetDirection(ENBoxDirection.Right);
            output1.FlowMode = ENPortFlowMode.Output;
            shape.Ports.Add(output1);

            // by default this shape does not accept shape-to-shape connections
            shape.DefaultShapeGlue = ENDefaultShapeGlue.None;

            // set text
            shape.Text = "AND";

            return(shape);
        }
Beispiel #14
0
        /// <summary>
        /// Creates the book store interface
        /// </summary>
        /// <param name="activePage"></param>
        void CreateBookStore(NPage activePage)
        {
            const double x1 = 50;
            const double x2 = x1 + 200;
            const double x3 = x2 + 50;
            const double x4 = x3 + 400;

            const double y1 = 50;
            const double y2 = y1 + 50;
            const double y3 = y2 + 50;
            const double y4 = y3 + 20;
            const double y5 = y4 + 200;
            const double y6 = y5 + 20;
            const double y7 = y6 + 50;

            // prev button
            NShape prevButtonShape = CreateButtonShape("Show Prev Book");

            SetLeftTop(prevButtonShape, new NPoint(x1, y1));
            ((NButton)prevButtonShape.Widget).Click += delegate(NEventArgs args)
            {
                LoadBook(m_nSelectedBook - 1);
            };
            activePage.Items.Add(prevButtonShape);

            // next button
            NShape nextButtonShape = CreateButtonShape("Show Next Book");

            SetRightTop(nextButtonShape, new NPoint(x2, y1));
            ((NButton)nextButtonShape.Widget).Click += delegate(NEventArgs args)
            {
                LoadBook(m_nSelectedBook + 1);
            };
            activePage.Items.Add(nextButtonShape);

            // add to cart
            NShape addToCartButton = CreateButtonShape("Add to Cart");

            SetRightTop(addToCartButton, new NPoint(x2, y6));
            ((NButton)addToCartButton.Widget).Click += delegate(NEventArgs args)
            {
                m_ShoppingCart.AddItem(m_Books[m_nSelectedBook], this);
            };
            activePage.Items.Add(addToCartButton);

            // create selected book shapes
            NBasicShapeFactory basicShapes = new NBasicShapeFactory();

            // selected image
            m_SelectedBookImage = basicShapes.CreateShape(ENBasicShape.Rectangle);
            SetLeftTop(m_SelectedBookImage, new NPoint(x1, y2));
            NSize minBookSize = GetMinBookImageSize();

            m_SelectedBookImage.Width  = x2 - x1;
            m_SelectedBookImage.Height = y5 - y2;
            activePage.Items.Add(m_SelectedBookImage);

            // selected title
            m_SelectedBookTitle = basicShapes.CreateShape(ENBasicShape.Text);
            m_SelectedBookTitle.TextBlock.InitXForm(ENTextBlockXForm.ShapeBox);
            m_SelectedBookTitle.TextBlock.FontSize = 25;
            m_SelectedBookTitle.TextBlock.Fill     = new NColorFill(NColor.DarkBlue);
            SetLeftTop(m_SelectedBookTitle, new NPoint(x3, y2));
            m_SelectedBookTitle.Width  = x4 - x3;
            m_SelectedBookTitle.Height = y3 - y2;
            activePage.Items.Add(m_SelectedBookTitle);

            // selected description
            m_SelectedBookDescription = basicShapes.CreateShape(ENBasicShape.Text);
            m_SelectedBookDescription.TextBlock.InitXForm(ENTextBlockXForm.ShapeBox);
            SetLeftTop(m_SelectedBookDescription, new NPoint(x3, y4));
            m_SelectedBookDescription.Width  = x4 - x3;
            m_SelectedBookDescription.Height = y5 - y4;
            activePage.Items.Add(m_SelectedBookDescription);

            // load the first book
            LoadBook(0);

            // create the shape that hosts the shopping cart widget
            NShape shoppingCartShape = new NShape();

            shoppingCartShape.Init2DShape();
            m_ShoppingCartWidget         = new NContentHolder();
            m_ShoppingCartWidget.Content = m_ShoppingCart.CreateWidget(this);
            shoppingCartShape.Widget     = m_ShoppingCartWidget;
            SetLeftTop(shoppingCartShape, new NPoint(x1, y7));
            BindSizeToDesiredSize(shoppingCartShape);
            activePage.Items.Add(shoppingCartShape);
        }
Beispiel #15
0
        /// <summary>
        /// Creates a custom shape that is a replica of the Visio Trapedzoid shape. With NOV diagram you can replicate the smart behavior of any Visio smart shape.
        /// </summary>
        /// <returns></returns>
        protected NShape CreateTrapedzoidShape()
        {
            NShape shape = new NShape();

            shape.Init2DShape();

            // add controls
            NControl control = new NControl();

            control.SetFx(NControl.XProperty, new NShapeWidthFactorFx(0.3));
            control.Y = 0.0d;
            control.SetFx(NControl.XBehaviorProperty, string.Format("IF(X<Width/2,{0},{1})", ((int)ENCoordinateBehavior.OffsetFromMin), ((int)ENCoordinateBehavior.OffsetFromMax)));
            control.YBehavior = ENCoordinateBehavior.Locked;
            control.Tooltip   = "Modify strip width";
            shape.Controls.Add(control);

            // add a geometry
            NGeometry geometry1 = shape.Geometry;

            {
                NMoveTo plotFigure =
                    geometry1.MoveTo("MIN(Controls.0.X,Width-Controls.0.X)", 0.0d);
                geometry1.LineTo("Width-Geometry.0.X", 0.0d);
                geometry1.LineTo("Width", "Height");
                geometry1.LineTo(0.0d, "Height");
                geometry1.LineTo("Geometry.0.X", "Geometry.0.Y");
                plotFigure.CloseFigure = true;
            }

            // add ports
            for (int i = 0; i < 4; i++)
            {
                NPort port = new NPort();
                shape.Ports.Add(port);

                switch (i)
                {
                case 0:     // top
                    port.Relative = true;
                    port.X        = 0.5;
                    port.Y        = 0.0d;
                    port.SetDirection(ENBoxDirection.Up);
                    break;

                case 1:     // right
                    port.SetFx(NPort.XProperty, "(Geometry.1.X + Geometry.2.X) / 2");
                    port.SetFx(NPort.YProperty, new NShapeHeightFactorFx(0.5));
                    port.SetDirection(ENBoxDirection.Right);
                    break;

                case 2:     // bottom
                    port.Relative = true;
                    port.X        = 0.5;
                    port.Y        = 1.0d;
                    port.SetDirection(ENBoxDirection.Down);
                    break;

                case 3:     // left
                    port.SetFx(NPort.XProperty, "(Geometry.0.X + Geometry.3.X) / 2");
                    port.SetFx(NPort.YProperty, new NShapeHeightFactorFx(0.5));
                    port.SetDirection(ENBoxDirection.Left);
                    break;
                }
            }

            return(shape);
        }
Beispiel #16
0
        /// <summary>
        /// Creates a custom shape that is essentially a group consisting of three other shapes each with different filling.
        /// You need to use groups to have shapes that mix different fill, or stroke styles.
        /// </summary>
        /// <returns></returns>
        protected NShape CreateCoffeeCupShape()
        {
            // create the points and paths from which the shape consits
            NPoint[] cupPoints = new NPoint[] {
                new NPoint(45, 268),
                new NPoint(63, 331),
                new NPoint(121, 331),
                new NPoint(140, 268)
            };

            NGraphicsPath handleGraphicsPath = new NGraphicsPath();

            handleGraphicsPath.AddClosedCurve(new NPoint[] {
                new NPoint(175, 295),
                new NPoint(171, 278),
                new NPoint(140, 283),
                new NPoint(170, 290),
                new NPoint(128, 323)
            }, 1);

            NGraphicsPath steamGraphicsPath = new NGraphicsPath();

            steamGraphicsPath.AddCubicBeziers(new NPoint[] {
                new NPoint(92, 270),
                new NPoint(53, 163),
                new NPoint(145, 160),
                new NPoint(86, 50),
                new NPoint(138, 194),
                new NPoint(45, 145),
                new NPoint(92, 270)
            });
            steamGraphicsPath.CloseFigure();

            // calculate some bounds
            NRectangle handleBounds   = handleGraphicsPath.ExactBounds;
            NRectangle cupBounds      = NGeometry2D.GetBounds(cupPoints);
            NRectangle steamBounds    = steamGraphicsPath.ExactBounds;
            NRectangle geometryBounds = NRectangle.Union(cupBounds, handleBounds, steamBounds);

            // normalize the points and paths by transforming them to relative coordinates
            NRectangle normalRect = new NRectangle(0, 0, 1, 1);
            NMatrix    transform  = NMatrix.CreateBoundsStretchMatrix(geometryBounds, normalRect);

            transform.TransformPoints(cupPoints);
            handleGraphicsPath.Transform(transform);
            steamGraphicsPath.Transform(transform);

            // create the cup shape
            NDrawPolygon cupPolygon = new NDrawPolygon(normalRect, cupPoints);

            cupPolygon.Relative = true;
            NShape cupShape = new NShape();

            cupShape.Init2DShape();
            cupShape.Geometry.Fill = new NColorFill(NColor.Brown);
            cupShape.Geometry.Add(cupPolygon);
            cupShape.SetBounds(geometryBounds);

            // create the cup handle
            NDrawPath handlePath = new NDrawPath(normalRect, handleGraphicsPath);

            handlePath.Relative = true;
            NShape handleShape = new NShape();

            handleShape.Init2DShape();
            handleShape.Geometry.Fill = new NColorFill(NColor.LightSalmon);
            handleShape.Geometry.Add(handlePath);
            handleShape.SetBounds(geometryBounds);

            // create the steam
            NDrawPath steamPath = new NDrawPath(steamGraphicsPath.Bounds, steamGraphicsPath);

            steamPath.Relative = true;
            NShape steamShape = new NShape();

            steamShape.Init2DShape();
            steamShape.Geometry.Fill = new NColorFill(new NColor(50, 122, 122, 122));
            steamShape.Geometry.Add(steamPath);
            steamShape.SetBounds(geometryBounds);

            // group the shapes as a single group
            NGroup      group;
            NBatchGroup batch = new NBatchGroup(m_DrawingDocument);

            batch.Build(cupShape, handleShape, steamShape);
            batch.Group(null, out group);

            // alter some properties of the group
            group.SelectionMode = ENGroupSelectionMode.GroupOnly;
            group.SnapToShapes  = false;

            return(group);
        }