示例#1
0
        /// <summary>
        /// Draws the background of a selected rectangle.
        /// </summary>
        /// <param name="rect">The rectangle to draw.</param>
        /// <param name="selectionStyle">The style to use when drawing.</param>
        public virtual void DrawSelectionRectangle(Rect rect, SelectionStyles selectionStyle)
        {
            Debug.Assert(WpfDrawingContext != null);
            Debug.Assert(RegionHelper.IsFixed(rect));

            Pen RectanglePen;

            switch (selectionStyle)
            {
            default:
                RectanglePen = GetPen(PenSettings.Default);
                break;

            case SelectionStyles.Node:
                RectanglePen = GetPen(PenSettings.SelectionNode);
                break;

            case SelectionStyles.NodeList:
                RectanglePen = GetPen(PenSettings.SelectionNodeList);
                break;

            case SelectionStyles.BlockList:
                RectanglePen = GetPen(PenSettings.SelectionBlockList);
                break;
            }

            WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.Selection), RectanglePen, new System.Windows.Rect(PagePadding.Left.Draw + rect.X, PagePadding.Top.Draw + rect.Y, rect.Width, rect.Height));
        }
示例#2
0
        /// <summary>
        /// Draws the background of a selected text.
        /// </summary>
        /// <param name="text">The text</param>
        /// <param name="origin">The location where to start drawing.</param>
        /// <param name="textStyle">The style used to measure selected text.</param>
        /// <param name="start">The starting point of the selection.</param>
        /// <param name="end">The ending point of the selection.</param>
        public virtual void DrawSelectionText(string text, Point origin, TextStyles textStyle, int start, int end)
        {
            Debug.Assert(WpfDrawingContext != null);
            Debug.Assert(start >= 0 && start <= text.Length);
            Debug.Assert(end >= 0 && end <= text.Length);
            Debug.Assert(start <= end);

            Brush         Brush = GetBrush(StyleToForegroundBrush(textStyle));
            FormattedText ft;
            double        X = PagePadding.Left.Draw + origin.X.Draw;
            double        Y = PagePadding.Top.Draw + origin.Y.Draw;

            if (textStyle == TextStyles.Comment)
            {
                X += CommentPadding.Left.Draw;
                Y += CommentPadding.Top.Draw;
            }

            ft = CreateFormattedText(text.Substring(0, start), EmSize, Brush);
            X += ft.WidthIncludingTrailingWhitespace;

            ft = CreateFormattedText(text.Substring(start, end - start), EmSize, Brush);
            System.Windows.Rect SelectionRect = new System.Windows.Rect(X, Y, ft.WidthIncludingTrailingWhitespace, LineHeight.Draw);

            WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.Selection), GetPen(PenSettings.SelectionText), SelectionRect);
        }
示例#3
0
        /// <summary>
        /// Draws the text background, at the location specified in <paramref name="origin"/>.
        /// </summary>
        /// <param name="text">The text to draw.</param>
        /// <param name="origin">The location where to start drawing.</param>
        /// <param name="textStyle">Style to use for the text.</param>
        public virtual void DrawTextBackground(string text, Point origin, TextStyles textStyle)
        {
            Debug.Assert(WpfDrawingContext != null);

            Brush         Brush = GetBrush(StyleToForegroundBrush(textStyle));
            FormattedText ft    = CreateFormattedText(text, EmSize, Brush);

            double X      = PagePadding.Left.Draw + origin.X.Draw;
            double Y      = PagePadding.Top.Draw + origin.Y.Draw;
            double Width  = ft.WidthIncludingTrailingWhitespace;
            double Height = LineHeight.Draw;

            if (textStyle == TextStyles.Comment)
            {
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CommentBackground), GetPen(PenSettings.Comment), new System.Windows.Rect(X, Y, CommentPadding.Left.Draw + Width + CommentPadding.Right.Draw, CommentPadding.Top.Draw + Height + CommentPadding.Bottom.Draw));
            }
        }
示例#4
0
        /// <summary></summary>
        protected virtual void ShowNormalCaret(Point origin, string text, TextStyles textStyle, CaretModes mode, int position)
        {
            string LeftText = text.Substring(0, position);

            Brush         Brush = GetBrush(StyleToForegroundBrush(textStyle));
            FormattedText ft    = CreateFormattedText(LeftText, EmSize, Brush);
            double        X     = origin.X.Draw + ft.WidthIncludingTrailingWhitespace;
            double        Y     = origin.Y.Draw;

            if (textStyle == TextStyles.Comment)
            {
                X += CommentPadding.Left.Draw;
                Y += CommentPadding.Top.Draw;
            }

            ChangeFlashClockOpacity(isVisible: true);

            if (mode == CaretModes.Insertion)
            {
                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + X, PagePadding.Top.Draw + Y, InsertionCaretWidth, LineHeight.Draw);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretInsertion), GetPen(PenSettings.CaretInsertion), CaretRect);
                WpfDrawingContext.Pop();
            }
            else
            {
                string CaretText = text.Substring(position, 1);
                ft = CreateFormattedText(CaretText, EmSize, GetBrush(BrushSettings.CaretOverride));

                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + X, PagePadding.Top.Draw + Y, ft.WidthIncludingTrailingWhitespace, LineHeight.Draw);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretOverride), GetPen(PenSettings.CaretOverride), CaretRect);
                WpfDrawingContext.Pop();
            }
        }
示例#5
0
        /// <summary></summary>
        protected virtual void ShowNumberCaretParts(FormattedNumber fn, CaretModes mode, int position, double x, double y, double caretEmSize, double caretHeight)
        {
            if (mode == CaretModes.Insertion)
            {
                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + x, PagePadding.Top.Draw + y, InsertionCaretWidth, caretHeight);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretInsertion), GetPen(PenSettings.CaretInsertion), CaretRect);
                WpfDrawingContext.Pop();
            }
            else
            {
                string CaretText;

                if (position < fn.SignificandPart.Length)
                {
                    CaretText = fn.SignificandPart.Substring(position, 1);
                }
                else if (position < fn.SignificandPart.Length + fn.ExponentPart.Length)
                {
                    CaretText = fn.ExponentPart.Substring(position - fn.SignificandPart.Length, 1);
                }
                else
                {
                    CaretText = fn.InvalidText.Substring(position - fn.SignificandPart.Length - fn.ExponentPart.Length, 1);
                }

                FormattedText ftCaret = CreateFormattedText(CaretText, caretEmSize, GetBrush(BrushSettings.CaretOverride));

                System.Windows.Rect CaretRect = new System.Windows.Rect(PagePadding.Left.Draw + x, PagePadding.Top.Draw + y, ftCaret.WidthIncludingTrailingWhitespace, caretHeight);

                WpfDrawingContext.PushOpacity(1, FlashClock);
                WpfDrawingContext.DrawRectangle(GetBrush(BrushSettings.CaretOverride), GetPen(PenSettings.CaretOverride), CaretRect);
                WpfDrawingContext.Pop();
            }
        }