示例#1
0
        /// <summary>
        /// Performs the element post-children custom paint. Overriden to paint the status
        /// of this example tile (if it has one) in its bottom-left corner.
        /// </summary>
        /// <param name="visitor"></param>
        protected override void OnPostPaint(NPaintVisitor visitor)
        {
            base.OnPostPaint(visitor);

            if (String.IsNullOrEmpty(m_Status))
            {
                return;
            }

            // Paint a new label in the bottom left corner
            NRectangle bounds = GetContentEdge();

            NFont font = new NFont(FontName, 5.0, ENFontStyle.Regular);

            font.RasterizationMode = ENFontRasterizationMode.Aliased;
            NSize      textSize = font.MeasureString(m_Status, this.OwnerDocument);
            NRectangle textRect = new NRectangle(bounds.X - 1, bounds.Bottom - textSize.Height,
                                                 textSize.Width + 3, textSize.Height);

            // Paint the text background
            NColor color = HomePage.GetStatusColor(m_Status);

            visitor.SetFill(color);
            visitor.PaintRectangle(textRect);

            // Paint the text
            visitor.SetFill(NColor.White);
            visitor.SetFont(font);

            NPoint location = textRect.Location;
            NPaintTextPointSettings settings = new NPaintTextPointSettings();

            visitor.PaintString(location, m_Status, ref settings);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static NExampleCategoryHeader()
        {
            NExampleCategoryHeaderSchema = NSchema.Create(typeof(NExampleCategoryHeader), NPairBox.NPairBoxSchema);

            // Properties
            StatusProperty = NExampleCategoryHeaderSchema.AddMember("Status", NDomType.String, defaultStatus,
                                                                    delegate(NNode o) { return(((NExampleCategoryHeader)o).m_Status); },
                                                                    delegate(NNode o, object v) { ((NExampleCategoryHeader)o).m_Status = (string)v; });

            // Constants
            StatusFont = new NFont(NExampleTile.FontName, 5.0, ENFontStyle.Regular);
            StatusFont.RasterizationMode = ENFontRasterizationMode.Aliased;
        }
示例#4
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);
        }
示例#5
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);
        }