public NItem(NImage image, NColor color, NFill fill, NStroke stroke)
 {
     Image  = image;
     Color  = color;
     Fill   = fill;
     Stroke = stroke;
 }
예제 #2
0
        void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NStroke stroke = (NStroke)canvas.Tag;

            NPaintVisitor visitor = args.PaintVisitor;

            visitor.SetStroke(stroke);
            visitor.SetFill(null);

            double strokeWidth   = stroke.Width;
            double rectWidth     = 300;
            double ellipseWidth  = 150;
            double polylineWidth = 180;
            double dist          = 20;

            double x1 = 10 + strokeWidth / 2;
            double x2 = x1 + rectWidth + dist + strokeWidth;
            double x3 = x2 + ellipseWidth;
            double x4 = x3 + dist + strokeWidth;
            double x5 = x4 + polylineWidth + dist + strokeWidth / 2;
            double y1 = 10 + strokeWidth / 2;
            double y2 = y1 + strokeWidth + 10;
            double y3 = y1 + 50;

            // draw a horizontal line
            visitor.PaintLine(x1, y1, x3, y1);

            // draw a rectangle
            visitor.PaintRectangle(x1, y2, rectWidth, 100);

            // draw an ellipse
            visitor.PaintEllipse(x2, y2, ellipseWidth, 100);

            // draw a polyline
            NPolyline polyLine = new NPolyline(4);

            polyLine.Add(new NPoint(x4, y2 + 90));
            polyLine.Add(new NPoint(x4 + 60, y2));
            polyLine.Add(new NPoint(x4 + 120, y2 + 90));
            polyLine.Add(new NPoint(x4 + 180, y2));
            visitor.PaintPolyline(polyLine);

            // draw text
            string dashStyleName = stroke.DashStyle.ToString();

            visitor.ClearStroke();
            visitor.SetFont(m_LabelFont);
            visitor.SetFill(m_LabelFill);

            NPaintTextRectSettings settings = new NPaintTextRectSettings();

            visitor.PaintString(new NRectangle(x5, y3, 200, 50), dashStyleName, ref settings);
        }
예제 #3
0
        void OnEditStrokeChanged(NEventArgs args)
        {
            NValueChangeEventArgs localValueChangeArgs = args as NValueChangeEventArgs;

            if (localValueChangeArgs != null)
            {
                for (int i = 0; i < m_arrStrokes.Length; i++)
                {
                    NStroke stroke = m_arrStrokes[i];
                    stroke.SetValue(localValueChangeArgs.Property, localValueChangeArgs.NewValue);

                    NCanvas canvas      = m_CanvasStack[i] as NCanvas;
                    double  strokeWidth = stroke.Width;

                    if (strokeWidth < 0)
                    {
                        strokeWidth = 0;
                    }

                    canvas.PreferredSize = GetCanvasPreferredSize(strokeWidth);

                    if (canvas != null)
                    {
                        canvas.InvalidateDisplay();
                    }
                }
            }
        }
예제 #4
0
        protected override NWidget CreateExampleContent()
        {
            m_PathAngle     = 0;
            m_PathPositionX = 200;
            m_PathPositionY = 100;

            m_Stroke = new NStroke(1, NColor.Red);

            // create an image fill using an embedded image
            m_ImageFill = new NImageFill(NResources.Image_Artistic_Plane_png);

            // create a custom texture mapping and assign it to the image fill
            m_MyTextureMapping = new MyTextureMapping();
            m_MyTextureMapping.TextureAngle = 45;
            m_MyTextureMapping.PinPoint     = new NPoint(m_PathPositionX, m_PathPositionY);
            m_ImageFill.TextureMapping      = m_MyTextureMapping;

            m_Canvas = new NCanvas();
            m_Canvas.PreferredSize       = new NSize(800, 600);
            m_Canvas.BackgroundFill      = new NColorFill(new NColor(220, 220, 200));
            m_Canvas.HorizontalPlacement = ENHorizontalPlacement.Center;
            m_Canvas.VerticalPlacement   = ENVerticalPlacement.Center;
            m_Canvas.PrePaint           += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

            NScrollContent scroll = new NScrollContent();

            scroll.Content        = m_Canvas;
            scroll.NoScrollHAlign = ENNoScrollHAlign.Center;
            scroll.NoScrollVAlign = ENNoScrollVAlign.Center;
            return(scroll);
        }
예제 #5
0
        protected override NWidget CreateExampleContent()
        {
            double width = 1;
            NColor color = NColor.Black;

            m_arrStrokes = new NStroke[]
            {
                new NStroke(width, color, ENDashStyle.Solid),
                new NStroke(width, color, ENDashStyle.Dot),
                new NStroke(width, color, ENDashStyle.Dash),
                new NStroke(width, color, ENDashStyle.DashDot),
                new NStroke(width, color, ENDashStyle.DashDotDot),
                new NStroke(width, color, new NDashPattern(2, 2, 2, 2, 0, 2))
            };

            m_EditStroke          = new NStroke();
            m_EditStroke.Width    = width;
            m_EditStroke.Color    = color;
            m_EditStroke.DashCap  = ENLineCap.Square;
            m_EditStroke.StartCap = ENLineCap.Square;
            m_EditStroke.EndCap   = ENLineCap.Square;

            for (int i = 0; i < m_arrStrokes.Length; i++)
            {
                NStroke stroke = m_arrStrokes[i];
                stroke.DashCap  = m_EditStroke.DashCap;
                stroke.StartCap = m_EditStroke.StartCap;
                stroke.EndCap   = m_EditStroke.EndCap;
            }

            m_LabelFont = new NFont(NFontDescriptor.DefaultSansFamilyName, 12, ENFontStyle.Bold);
            m_LabelFill = new NColorFill(ENNamedColor.Black);

            m_CanvasStack          = new NStackPanel();
            m_CanvasStack.FillMode = ENStackFillMode.None;
            m_CanvasStack.FitMode  = ENStackFitMode.None;

            NSize preferredSize = GetCanvasPreferredSize(m_EditStroke.Width);

            for (int i = 0; i < m_arrStrokes.Length; i++)
            {
                NCanvas canvas = new NCanvas();
                canvas.PrePaint      += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);
                canvas.PreferredSize  = preferredSize;
                canvas.Tag            = m_arrStrokes[i];
                canvas.BackgroundFill = new NColorFill(NColor.White);
                m_CanvasStack.Add(canvas);
            }

            // The stack must be scrollable
            NScrollContent scroll = new NScrollContent();

            scroll.Content = m_CanvasStack;
            return(scroll);
        }