NLinearGradientFill GradientWithTwoStops()
        {
            NLinearGradientFill lgf = new NLinearGradientFill();

            lgf.GradientStops.Add(new NGradientStop(0, NColor.Red));
            lgf.GradientStops.Add(new NGradientStop(1, NColor.DarkBlue));
            return(lgf);
        }
        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);
        }
        NLinearGradientFill GradientWithFiveStops()
        {
            NLinearGradientFill lgf = new NLinearGradientFill();

            lgf.GradientStops.Add(new NGradientStop(0.00f, NColor.Red));
            lgf.GradientStops.Add(new NGradientStop(0.25f, NColor.Yellow));
            lgf.GradientStops.Add(new NGradientStop(0.50f, NColor.LimeGreen));
            lgf.GradientStops.Add(new NGradientStop(0.75f, NColor.RoyalBlue));
            lgf.GradientStops.Add(new NGradientStop(1.00f, NColor.BlueViolet));
            lgf.SetAngle(new NAngle(90, NUnit.Degree));
            return(lgf);
        }
Example #4
0
        void PaintRectangle(NPaintVisitor paintVisitor, double w, double h)
        {
            NLinearGradientFill lgf = new NLinearGradientFill();

            lgf.GradientStops.Add(new NGradientStop(0, NColor.Indigo));
            lgf.GradientStops.Add(new NGradientStop(0.5f, NColor.SlateBlue));
            lgf.GradientStops.Add(new NGradientStop(1, new NColor(NColor.Crimson, 30)));

            paintVisitor.SetStroke(NColor.Black, 1);
            paintVisitor.SetFill(lgf);

            paintVisitor.PaintRectangle(0.2 * w, 0.3 * h, 0.6 * w, 0.4 * h);
        }
        NLinearGradientFill GradientInStretchMode()
        {
            NLinearGradientFill lgf = new NLinearGradientFill();

            lgf.GradientStops.Add(new NGradientStop(0.0f, NColor.Red));
            lgf.GradientStops.Add(new NGradientStop(0.4f, NColor.BlueViolet));
            lgf.GradientStops.Add(new NGradientStop(0.5f, NColor.LavenderBlush));
            lgf.GradientStops.Add(new NGradientStop(0.6f, NColor.BlueViolet));
            lgf.GradientStops.Add(new NGradientStop(1.0f, NColor.Red));
            lgf.SetAngle(new NAngle(45, NUnit.Degree));
            // FIX: Gradient Transform
            // lgf.MappingMode = ENGradientMappingMode.Stretch;
            return(lgf);
        }
Example #6
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static NStyleNode()
        {
            defaultLinearGradientFill = new NLinearGradientFill();
            defaultLinearGradientFill.GradientStops.Add(new NGradientStop(0.0f, NColor.Red));
            defaultLinearGradientFill.GradientStops.Add(new NGradientStop(0.5f, NColor.Yellow));
            defaultLinearGradientFill.GradientStops.Add(new NGradientStop(1.0f, NColor.Indigo));

            defaultRadialGradientFill = new NRadialGradientFill();
            defaultRadialGradientFill.GradientStops.Add(new NGradientStop(0.0f, NColor.Red));
            defaultRadialGradientFill.GradientStops.Add(new NGradientStop(0.5f, NColor.Yellow));
            defaultRadialGradientFill.GradientStops.Add(new NGradientStop(1.0f, NColor.Indigo));

            defaultAdvancedGradientFill = new NAdvancedGradientFill();
            defaultAdvancedGradientFill.Points.Add(new NAdvancedGradientPoint(NColor.Red, NAngle.Zero, 0, 0, 1, ENAdvancedGradientPointShape.Circle));
            defaultAdvancedGradientFill.Points.Add(new NAdvancedGradientPoint(NColor.Blue, NAngle.Zero, 1, 1, 1, ENAdvancedGradientPointShape.Circle));

            NStyleNodeSchema = NSchema.Create(typeof(NStyleNode), NNode.NNodeSchema);

            // Properties - fill
            FillProperty                 = NStyleNodeSchema.AddSlot("Fill", typeof(NFill), defaultFill);
            ColorFillProperty            = NStyleNodeSchema.AddSlot("ColorFill", typeof(NColorFill), defaultColorFill);
            StockGradientFillProperty    = NStyleNodeSchema.AddSlot("StockGradientFill", typeof(NStockGradientFill), defaultStockGradientFill);
            LinearGradientFillProperty   = NStyleNodeSchema.AddSlot("LinearGradientFill", typeof(NLinearGradientFill), defaultLinearGradientFill);
            RadialGradientFillProperty   = NStyleNodeSchema.AddSlot("RadialGradientFill", typeof(NRadialGradientFill), defaultRadialGradientFill);
            AdvancedGradientFillProperty = NStyleNodeSchema.AddSlot("AdvancedGradientFill", typeof(NAdvancedGradientFill), defaultAdvancedGradientFill);
            HatchFillProperty            = NStyleNodeSchema.AddSlot("HatchFill", typeof(NHatchFill), defaultHatchFill);
            ImageFillProperty            = NStyleNodeSchema.AddSlot("ImageFill", typeof(NImageFill), defaultImageFill);

            // Broperties - border
            BorderProperty = NStyleNodeSchema.AddSlot("Border", typeof(NBorder), defaultBorder);

            // Broperties - stroke
            StrokeProperty = NStyleNodeSchema.AddSlot("Stroke", typeof(NStroke), defaultStroke);

            // Properties - font
            FontProperty = NStyleNodeSchema.AddSlot("Font", typeof(NFont), defaultFont);

            // Constants
            Designers = new NDesigner[] {
                new NStyleNodeHStackDesigner(),
                new NStyleNodeVStackDesigner(),
                new NStyleNodeTabDesigner(),
                new NStyleNodeMixedDesigner()
            };
        }