Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            PaintPrimitiveDelegate paintDelegate = canvas.Tag as PaintPrimitiveDelegate;

            if (paintDelegate == null)
            {
                throw new Exception("The canvas has no assigned paint delegate.");
            }

            // Clear all styles and set the shadow
            args.PaintVisitor.ClearStyles();
            args.PaintVisitor.SetShadow(m_Shadow);

            // Paint the scene for the current canvas
            paintDelegate(args.PaintVisitor, canvas.Width, canvas.Height);

            // Paint a bounding rectangle for the canvas
            args.PaintVisitor.ClearStyles();
            args.PaintVisitor.SetStroke(NColor.Red, 1);
            args.PaintVisitor.PaintRectangle(0, 0, canvas.Width, canvas.Height);
        }
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            int bookId = -1;

            if (context.Request["id"] != null)
            {
                int.TryParse(context.Request["id"], out bookId);
            }

            NDrawingDocument document = CreateDocument(bookId);
            NCanvas          canvas   = CreateCanvas(document);

            document.RefreshAllViews();
            canvas.DoLayout();

            MemoryStream ms = new MemoryStream();

            NPngImageFormat imageFormet = new NPngImageFormat();

            using (INImage image = CreateImage(document, canvas, canvas.Size, imageFormet))
            {
                image.SaveToStream(ms, imageFormet);
            }

            byte[] bytes = ms.GetBuffer();
            context.Response.ContentType = "image/png";
            context.Response.OutputStream.Write(bytes, 0, bytes.Length);
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            // Create a transform matrix for the graphics path
            NMatrix matrix = NMatrix.CreateRotationMatrix(m_PathAngle * NAngle.Degree2Rad, NPoint.Zero);

            matrix.Translate(m_PathPositionX, m_PathPositionY);

            // Create a graphics path containing a rectangle and transform it
            NGraphicsPath path = new NGraphicsPath();

            path.AddRectangle(0, 0, RectWidth, RectHeight);
            path.Transform(matrix);

            // Paint the graphics path
            NPaintVisitor pv = args.PaintVisitor;

            pv.SetStroke(m_Stroke);
            pv.SetFill(m_ImageFill);
            pv.PaintPath(path);

            // Paint a border around the canvas
            pv.ClearFill();
            pv.SetStroke(NColor.Black, 1);
            pv.PaintRectangle(0, 0, canvas.Width, canvas.Height);
        }
Exemplo n.º 6
0
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor pv = args.PaintVisitor;

            pv.ClearStyles();

            if (m_PaintImageInRectangle)
            {
                pv.PaintImage(NResources.Image_JpegSuite_q080_jpg.ImageSource, new NRectangle(m_PosX, m_PosY, m_Width, m_Height));
            }
            else
            {
                pv.PaintImage(NResources.Image_JpegSuite_q080_jpg.ImageSource, new NPoint(m_PosX, m_PosY));
            }

            // paint a border around the canvas
            pv.SetStroke(NColor.Black, 1);
            pv.PaintRectangle(0, 0, canvas.Width, canvas.Height);
        }
        private void OnNumericUpDownValueChanged(NValueChangeEventArgs args)
        {
            if (m_Table == null)
            {
                return;
            }

            double width  = m_CanvasWidthUpDown.Value;
            double height = m_CanvasHeightUpDown.Value;

            // Recreate all graphics paths
            NGraphicsPath[] paths = CreatePaths(width, height);
            int             index = 0;

            // Resize the canvases
            INIterator <NNode> iterator = m_Table.GetSubtreeIterator(ENTreeTraversalOrder.DepthFirstPreOrder, new NInstanceOfSchemaFilter(NCanvas.NCanvasSchema));

            while (iterator.MoveNext())
            {
                NCanvas canvas = (NCanvas)iterator.Current;

                ((NWidget)canvas.ParentNode).PreferredWidth = width;
                canvas.PreferredHeight = height;

                canvas.Tag = paths[index++];
            }
        }
Exemplo n.º 8
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();
                    }
                }
            }
        }
Exemplo n.º 9
0
        protected override NWidget CreateExampleContent()
        {
            m_Canvas                = new NCanvas();
            m_Canvas.PrePaint      += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);
            m_Canvas.BackgroundFill = new NColorFill(NColor.White);

            return(m_Canvas);
        }
Exemplo n.º 10
0
        protected override NWidget CreateExampleContent()
        {
            m_Shadow = new NShadow(new NColor(160, 160, 160), 20, 20);

            string[] names = new string[]
            {
                "Line", "Polyline", "Rectangle", "Ellipse", "Triangle", "Quad", "Polygon", "Graphics Path"
            };

            PaintPrimitiveDelegate[] delegates = new PaintPrimitiveDelegate[]
            {
                new PaintPrimitiveDelegate(PaintLine),
                new PaintPrimitiveDelegate(PaintPolyline),
                new PaintPrimitiveDelegate(PaintRectangle),
                new PaintPrimitiveDelegate(PaintEllipse),
                new PaintPrimitiveDelegate(PaintTriangle),
                new PaintPrimitiveDelegate(PaintQuadrangle),
                new PaintPrimitiveDelegate(PaintPolygon),
                new PaintPrimitiveDelegate(PaintPath),
            };

            int count = delegates.Length;

            // Create a table panel to hold the canvases and the labels
            m_Table = new NTableFlowPanel();
            m_Table.HorizontalPlacement = ENHorizontalPlacement.Left;
            m_Table.VerticalPlacement   = ENVerticalPlacement.Top;
            m_Table.Padding             = new NMargins(30);
            m_Table.HorizontalSpacing   = 30;
            m_Table.VerticalSpacing     = 30;
            m_Table.MaxOrdinal          = 4;

            for (int i = 0; i < count; i++)
            {
                NStackPanel stack = new NStackPanel();
                m_Table.Add(stack);
                stack.VerticalSpacing = 5;

                // Create a canvas to draw in
                NCanvas canvas = new NCanvas();
                canvas.PreferredSize  = new NSize(defaultCanvasWidth, defaultCanvasHeight);
                canvas.Tag            = delegates[i];
                canvas.BackgroundFill = new NColorFill(NColor.White);
                canvas.PrePaint      += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);
                stack.Add(canvas);

                // Create a label for the geometry primitive's name
                NLabel label = new NLabel(names[i]);
                label.HorizontalPlacement = ENHorizontalPlacement.Center;
                stack.Add(label);
            }

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

            scroll.Content = m_Table;
            return(scroll);
        }
        protected override NWidget CreateExampleContent()
        {
            // Create a table panel to hold the canvases and the labels
            m_Table = new NTableFlowPanel();
            m_Table.HorizontalPlacement = ENHorizontalPlacement.Left;
            m_Table.VerticalPlacement   = ENVerticalPlacement.Top;
            m_Table.Padding             = new NMargins(30);
            m_Table.HorizontalSpacing   = 30;
            m_Table.VerticalSpacing     = 30;
            m_Table.MaxOrdinal          = 2;

            string[] texts = new string[]
            {
                "Two Gradient Stops, Horizontal Gradient Axis",
                "Five Gradient Stops, Vertical Gradient Axis",
                "Gradient Axis Angle = 45deg, Mapping Mode = ZoomToFill",
                "Gradient Axis Angle = 45deg, Mapping Mode = Stretch"
            };

            NLinearGradientFill[] fills = new NLinearGradientFill[]
            {
                GradientWithTwoStops(),
                GradientWithFiveStops(),
                GradientInZoomToFillMode(),
                GradientInStretchMode(),
            };

            // Add a canvas for each demonstrated gradient
            for (int i = 0; i < fills.Length; i++)
            {
                NStackPanel stack = new NStackPanel();
                m_Table.Add(stack);
                stack.Direction = ENHVDirection.TopToBottom;
                stack.FillMode  = ENStackFillMode.First;
                stack.FitMode   = ENStackFitMode.First;

                // Create a widget with the proper filling
                NCanvas canvas = new NCanvas();
                canvas.PreferredSize = new NSize(defaultCanvasWidth, defaultCanvasHeight);
                canvas.Tag           = fills[i];
                stack.Add(canvas);
                canvas.PrePaint += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

                // Create a label with the corresponding name
                NLabel label = new NLabel(texts[i]);
                stack.Add(label);
                label.HorizontalPlacement = ENHorizontalPlacement.Center;
            }

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

            scroll.Content = m_Table;
            return(scroll);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor pv = args.PaintVisitor;

            int count = m_Values.Length;

            // calculate total value
            double total = 0;

            for (int i = 0; i < count; i++)
            {
                total += m_Values[i];
            }

            // paint the pie slices
            double beginAngle = 0;

            pv.ClearStyles();

            for (int i = 0; i < count; i++)
            {
                double sweepAngle = NMath.PI2 * (m_Values[i] / total);

                NGraphicsPath path = new NGraphicsPath();
                path.AddPie(0.1 * W, 0.1 * H, 0.8 * W, 0.8 * H, beginAngle, sweepAngle);

                if (i == 0)
                {
                    const double detachment = 20;
                    double       midAngle   = beginAngle + sweepAngle / 2;
                    double       dx         = Math.Cos(midAngle) * detachment;
                    double       dy         = Math.Sin(midAngle) * detachment;
                    path.Translate(dx, dy);
                }

                pv.SetFill(m_ColorFills[i]);
                pv.PaintPath(path);

                beginAngle += sweepAngle;
            }

            // paint a border around the canvas
            pv.ClearFill();
            pv.SetStroke(NColor.Black, 1);
            pv.PaintRectangle(0, 0, canvas.Width, canvas.Height);
        }
Exemplo n.º 14
0
        NCanvas CreateCanvas(NDrawingDocument document)
        {
            NCanvas canvas = new NCanvas(document);

            canvas.Layout                     = CanvasLayout.Normal;
            canvas.ScaleX                     = 1;
            canvas.ScaleY                     = 1;
            canvas.GlobalVisibility           = new NGlobalVisibility();
            canvas.GlobalVisibility.ShowPorts = false;
            canvas.Size             = new NSize((int)document.Width, (int)document.Height);
            canvas.GraphicsSettings = document.GraphicsSettings;

            return(canvas);
        }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor paintVisitor = args.PaintVisitor;

            NRectangle contentEge = canvas.GetContentEdge();

            // create the text bounds
            double width  = contentEge.Width * m_WidthPercentUpDown.Value / 100.0;
            double height = contentEge.Height * m_HeightPercentUpDown.Value / 100.0;
            NPoint center = contentEge.Center;

            NRectangle textBounds = new NRectangle(center.X - width / 2.0, center.Y - height / 2.0, width, height);

            // create the settings
            NPaintTextRectSettings settings = new NPaintTextRectSettings();

            settings.SingleLine = m_SingleLineCheckBox.Checked;
            settings.WrapMode   = (ENTextWrapMode)m_WrapModeCombo.SelectedIndex;
            settings.HorzAlign  = (ENTextHorzAlign)m_HorizontalAlignmentCombo.SelectedIndex;
            settings.VertAlign  = (ENTextVertAlign)m_VerticalAlignmentCombo.SelectedIndex;

            // create the text
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Paint text at bounds [" + textBounds.X.ToString("0.") + ", " + textBounds.Y.ToString("0.") + "]");
            builder.AppendLine("Horizontal Alignment [" + settings.HorzAlign.ToString() + "]");
            builder.AppendLine("Vertical Alignment [" + settings.VertAlign.ToString() + "]");

            // paint the bounding box
            paintVisitor.ClearStyles();
            paintVisitor.SetFill(NColor.LightBlue);
            paintVisitor.PaintRectangle(textBounds);

            // init font and fill
            paintVisitor.SetFill(NColor.Black);
            NFont font = new NFont(NFontDescriptor.DefaultSansFamilyName, 10);


            NGraphicsPath path = font.GetTextPath(builder.ToString(), textBounds, this.OwnerDocument, ref settings);

            paintVisitor.PaintPath(path);
        }
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NFill fill = (NFill)canvas.Tag;

            args.PaintVisitor.ClearStyles();
            args.PaintVisitor.SetFill(fill);
            args.PaintVisitor.PaintRectangle(0, 0, canvas.Width, canvas.Height);
        }
        void InvalidateCanvases()
        {
            if (m_Table == null)
            {
                return;
            }

            INIterator <NNode> iterator = m_Table.GetSubtreeIterator(ENTreeTraversalOrder.DepthFirstPreOrder, new NInstanceOfSchemaFilter(NCanvas.NCanvasSchema));

            while (iterator.MoveNext())
            {
                NCanvas canvas = (NCanvas)iterator.Current;
                canvas.InvalidateDisplay();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor paintVisitor = args.PaintVisitor;

            NRectangle contentEge = canvas.GetContentEdge();

            // create the text bounds
            double width  = contentEge.Width * 0.5;
            double height = contentEge.Height * 0.5;
            NPoint center = contentEge.Center;

            NRectangle textBounds = new NRectangle(center.X - width / 2.0, center.Y - height / 2.0, width, height);

            // create the settings
            NPaintTextRectSettings settings = new NPaintTextRectSettings();

            settings.SingleLine = false;
            settings.WrapMode   = ENTextWrapMode.WordWrap;
            settings.HorzAlign  = ENTextHorzAlign.Center;
            settings.VertAlign  = ENTextVertAlign.Center;

            // create the text
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("This text is displayed using Liberation Fonts!");
            builder.AppendLine("distributed under the SIL Open Font License (OFL)");

            // paint the bounding box
            paintVisitor.ClearStyles();
            paintVisitor.SetFill(NColor.LightBlue);
            paintVisitor.PaintRectangle(textBounds);

            // init font and fill
            paintVisitor.SetFill(NColor.Black);
            ENFontStyle fontStyle = NFontFaceDescriptor.FontVariantToFontStyle(m_FontDescriptor.FontVariant);

            paintVisitor.SetFont(new NFont(m_FontDescriptor.FamilyName, 10, fontStyle));

            // paint the text
            paintVisitor.PaintString(textBounds, builder.ToString(), ref settings);
        }
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NGraphicsPath path = (NGraphicsPath)canvas.Tag;

            args.PaintVisitor.ClearStyles();
            args.PaintVisitor.SetStroke(m_Stroke);
            args.PaintVisitor.SetFill(Fill);
            args.PaintVisitor.PaintPath(path, ENFillRule.EvenOdd);
        }
Exemplo n.º 20
0
        protected override NWidget CreateExampleContent()
        {
            // Create a table panel to hold the canvases and the labels
            NStackPanel stack = new NStackPanel();

            stack.FillMode = ENStackFillMode.Last;
            stack.FitMode  = ENStackFitMode.Last;

            m_Canvas = new NCanvas();
            stack.Add(m_Canvas);

            m_Canvas.PrePaint      += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);
            m_Canvas.BackgroundFill = new NColorFill(NColor.White);

            return(stack);
        }
Exemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor paintVisitor = args.PaintVisitor;
            NRectangle    contentEge   = canvas.GetContentEdge();

            // create the settings
            NPaintTextRectSettings settings = new NPaintTextRectSettings();

            settings.SingleLine = false;
            settings.WrapMode   = ENTextWrapMode.WordWrap;
            settings.HorzAlign  = ENTextHorzAlign.Left;
            settings.VertAlign  = ENTextVertAlign.Top;

            // create the text
            string text = m_TextBox.Text;

            // calculate the text bounds the text bounds
            double resolution = canvas.OwnerDocument.GetEffectiveResolution();
            NFont  font       = new NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Regular);
            NSize  textSize   = font.MeasureString(text.ToCharArray(), resolution, contentEge.Width, false, ref settings);

            NPoint     center     = contentEge.Center;
            NRectangle textBounds = new NRectangle(
                center.X - textSize.Width / 2.0,
                center.Y - textSize.Height / 2.0,
                textSize.Width,
                textSize.Height);

            // paint the bounding box
            paintVisitor.ClearStyles();
            paintVisitor.SetFill(NColor.LightBlue);
            paintVisitor.PaintRectangle(textBounds);

            // init font and fill
            paintVisitor.SetFill(NColor.Black);
            paintVisitor.SetFont(font);

            // paint the text
            paintVisitor.PaintString(textBounds, text.ToCharArray(), ref settings);
        }
Exemplo n.º 22
0
        protected override NWidget CreateExampleContent()
        {
            m_Canvas = new NCanvas();
            m_Canvas.PreferredSize  = new NSize(W, H);
            m_Canvas.BackgroundFill = new NHatchFill(ENHatchStyle.LargeCheckerBoard, NColor.LightGray, NColor.White);
            m_Canvas.PrePaint      += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

            m_Canvas.HorizontalPlacement = ENHorizontalPlacement.Center;
            m_Canvas.VerticalPlacement   = ENVerticalPlacement.Center;

            NScrollContent scroll = new NScrollContent();

            scroll.Content        = m_Canvas;
            scroll.NoScrollHAlign = ENNoScrollHAlign.Center;
            scroll.NoScrollVAlign = ENNoScrollVAlign.Center;
            return(scroll);
        }
Exemplo n.º 23
0
        protected override NWidget CreateExampleContent()
        {
            m_InputPaths = new NList <NGraphicsPath>();
            m_OutputPath = new NGraphicsPath();

            m_Canvas = new NCanvas();
            m_Canvas.HorizontalPlacement = ENHorizontalPlacement.Fit;
            m_Canvas.VerticalPlacement   = ENVerticalPlacement.Fit;
            m_Canvas.PrePaint           += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);
            m_Canvas.BackgroundFill      = new NColorFill(NColor.White);

            NScrollContent scrollContent = new NScrollContent();

            scrollContent.Content = m_Canvas;

            return(scrollContent);
        }
Exemplo n.º 24
0
        protected override NWidget CreateExampleContent()
        {
            m_Canvas           = new NCanvas();
            m_Canvas.PrePaint += OnCanvasPrePaint;

            // subscribe for touch events
            m_Canvas.TouchDown += OnCanvasTouchDown;
            m_Canvas.TouchMove += OnCanvasTouchMove;
            m_Canvas.TouchUp   += OnCanvasTouchUp;

            // subscribe for mouse events
            m_Canvas.MouseDown += OnCanvasMouseDown;
            m_Canvas.MouseUp   += OnCanvasMouseUp;
            m_Canvas.MouseMove += OnCanvasMouseMove;

            return(m_Canvas);
        }
Exemplo n.º 25
0
        protected override NWidget CreateExampleContent()
        {
            // Get the fill styles
            ENHatchStyle[] hatches = NEnum.GetValues <ENHatchStyle>();
            int            count   = hatches.Length;

            // Create a table layout panel
            m_Table = new NTableFlowPanel();
            m_Table.HorizontalPlacement = ENHorizontalPlacement.Left;
            m_Table.VerticalPlacement   = ENVerticalPlacement.Top;
            m_Table.Padding             = new NMargins(30);
            m_Table.HorizontalSpacing   = 30;
            m_Table.VerticalSpacing     = 30;
            m_Table.MaxOrdinal          = 6;

            // Add widgets with the proper filling and names to the panel

            for (int i = 0; i < count; i++)
            {
                NStackPanel stack = new NStackPanel();
                m_Table.Add(stack);
                stack.Direction = ENHVDirection.TopToBottom;
                stack.FillMode  = ENStackFillMode.First;
                stack.FitMode   = ENStackFitMode.First;

                // Create a widget with the proper filling
                NCanvas canvas = new NCanvas();
                canvas.PreferredSize = new NSize(defaultCanvasWidth, defaultCanvasHeight);
                canvas.Tag           = new NHatchFill(hatches[i], defaultForegroundColor, defaultBackgroundColor);
                stack.Add(canvas);
                canvas.PrePaint += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

                // Create a label with the corresponding name
                NLabel label = new NLabel(hatches[i].ToString());
                stack.Add(label);
                label.HorizontalPlacement = ENHorizontalPlacement.Center;
            }

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

            scroll.Content = m_Table;
            return(scroll);
        }
        protected override NWidget CreateExampleContent()
        {
            // Create the gradient fills
            NFill[]  fills;
            string[] texts;

            int columnCount = CreateFillsAndDescriptions(out fills, out texts);

            // Create a table panel to hold the canvases and the labels
            m_Table = new NTableFlowPanel();
            m_Table.HorizontalPlacement = ENHorizontalPlacement.Left;
            m_Table.VerticalPlacement   = ENVerticalPlacement.Top;
            m_Table.Padding             = new NMargins(30);
            m_Table.HorizontalSpacing   = 30;
            m_Table.VerticalSpacing     = 30;
            m_Table.MaxOrdinal          = columnCount;

            for (int i = 0; i < fills.Length; i++)
            {
                NStackPanel stack = new NStackPanel();
                m_Table.Add(stack);
                stack.Direction = ENHVDirection.TopToBottom;
                stack.FillMode  = ENStackFillMode.First;
                stack.FitMode   = ENStackFitMode.First;

                // Create a widget with the proper filling
                NCanvas canvas = new NCanvas();
                canvas.PreferredSize = new NSize(defaultCanvasWidth, defaultCanvasHeight);
                canvas.Tag           = fills[i];
                stack.Add(canvas);
                canvas.PrePaint += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

                // Create a label with the corresponding name
                NLabel label = new NLabel(texts[i]);
                stack.Add(label);
                label.HorizontalPlacement = ENHorizontalPlacement.Center;
            }

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

            scroll.Content = m_Table;
            return(scroll);
        }
        private void OnRadioGroupSelectedIndexChanged(NValueChangeEventArgs args)
        {
            if (m_Table == null)
            {
                return;
            }

            ENAdvancedGradientColorScheme[] predefinedGradientSchemes = NEnum.GetValues <ENAdvancedGradientColorScheme>();
            INIterator <NNode> iterator = m_Table.GetSubtreeIterator(ENTreeTraversalOrder.DepthFirstPreOrder, new NInstanceOfSchemaFilter(NCanvas.NCanvasSchema));

            int gradientVariant = (int)args.NewValue;
            int schemeIndex     = 0;

            while (iterator.MoveNext())
            {
                NCanvas canvas = (NCanvas)iterator.Current;
                canvas.Tag = NAdvancedGradientFill.Create(predefinedGradientSchemes[schemeIndex++], gradientVariant);
                canvas.InvalidateDisplay();
            }
        }
Exemplo n.º 28
0
        private void OnColorBoxSelectedColorChanged(NValueChangeEventArgs args)
        {
            if (m_Table == null)
            {
                return;
            }

            NColor    color    = (NColor)args.NewValue;
            NColorBox colorBox = (NColorBox)args.TargetNode;
            NProperty property = (NProperty)colorBox.Tag;

            INIterator <NNode> iterator = m_Table.GetSubtreeIterator(ENTreeTraversalOrder.DepthFirstPreOrder, new NInstanceOfSchemaFilter(NCanvas.NCanvasSchema));

            while (iterator.MoveNext())
            {
                NCanvas canvas = (NCanvas)iterator.Current;
                ((NHatchFill)canvas.Tag).SetValue(property, color);
                canvas.InvalidateDisplay();
            }
        }
Exemplo n.º 29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        private void OnCanvasPrePaint(NCanvasPaintEventArgs args)
        {
            NCanvas canvas = args.TargetNode as NCanvas;

            if (canvas == null)
            {
                return;
            }

            NPaintVisitor paintVisitor = args.PaintVisitor;

            NPaintTextPointSettings settings = new NPaintTextPointSettings();

            settings.SingleLine = m_SingleLineCheckBox.Checked;
            settings.VertAlign  = (ENTextVertAlign)m_VerticalAlignmentCombo.SelectedItem.Tag;
            settings.HorzAlign  = (ENTextHorzAlign)m_HorizontalAlignmentCombo.SelectedItem.Tag;

            NPoint location = canvas.GetContentEdge().Center;

            // set styles
            paintVisitor.ClearStyles();
            paintVisitor.SetFont(new NFont(NFontDescriptor.DefaultSansFamilyName, 10));
            paintVisitor.SetFill(NColor.Black);

            // create text to paint
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Paint text at location [" + location.X.ToString("0.") + ", " + location.Y.ToString("0.") + "]");
            builder.AppendLine("Horizontal Alignment [" + settings.HorzAlign.ToString() + "]");
            builder.AppendLine("Vertical Alignment [" + settings.VertAlign.ToString() + "]");

            // paint string
            paintVisitor.PaintString(location, builder.ToString(), ref settings);

            // paint location
            double inflate = 5.0;

            paintVisitor.SetFill(NColor.Red);
            paintVisitor.PaintRectangle(new NRectangle(location.X - inflate, location.Y - inflate, inflate * 2.0, inflate * 2.0));
        }
        protected override NWidget CreateExampleContent()
        {
            // Create a table panel to hold the canvases and the labels
            m_Table = new NTableFlowPanel();
            m_Table.HorizontalPlacement = ENHorizontalPlacement.Left;
            m_Table.VerticalPlacement   = ENVerticalPlacement.Top;
            m_Table.Padding             = new NMargins(30);
            m_Table.HorizontalSpacing   = 30;
            m_Table.VerticalSpacing     = 30;
            m_Table.MaxOrdinal          = 4;

            ENAdvancedGradientColorScheme[] predefinedGradientSchemes = NEnum.GetValues <ENAdvancedGradientColorScheme>();

            for (int i = 0; i < predefinedGradientSchemes.Length; i++)
            {
                NStackPanel stack = new NStackPanel();
                m_Table.Add(stack);
                stack.Direction = ENHVDirection.TopToBottom;
                stack.FillMode  = ENStackFillMode.First;
                stack.FitMode   = ENStackFitMode.First;

                // Create a widget with the proper filling
                NCanvas canvas = new NCanvas();
                canvas.PreferredSize = new NSize(defaultCanvasWidth, defaultCanvasHeight);
                canvas.Tag           = NAdvancedGradientFill.Create(predefinedGradientSchemes[i], 0);
                stack.Add(canvas);
                canvas.PrePaint += new Function <NCanvasPaintEventArgs>(OnCanvasPrePaint);

                // Create a label with the corresponding name
                NLabel label = new NLabel(predefinedGradientSchemes[i].ToString());
                stack.Add(label);
                label.HorizontalPlacement = ENHorizontalPlacement.Center;
            }

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

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