示例#1
0
 /// <summary>
 /// Get solid color brush for the given color.
 /// </summary>
 private static Brush GetSolidColorBrush(RColor color)
 {
     Brush solidBrush;
     if (color == RColor.White)
         solidBrush = Brushes.White;
     else if (color == RColor.Black)
         solidBrush = Brushes.Black;
     else if (color.A < 1)
         solidBrush = Brushes.Transparent;
     else
         solidBrush = new SolidColorBrush(Util.Convert(color));
     return solidBrush;
 }
示例#2
0
        public override void Render(IDrawingContext context)
        {
            var selectionStart = SelectionStart;
            var selectionEnd = SelectionEnd;

            if (selectionStart != selectionEnd)
            {
                var start = Math.Min(selectionStart, selectionEnd);
                var length = Math.Max(selectionStart, selectionEnd) - start;
                var rects = FormattedText.HitTestTextRange(start, length);

                var brush = new SolidColorBrush(0xff086f9e);

                foreach (var rect in rects)
                {
                    context.FillRectange(brush, rect);
                }
            }

            base.Render(context);

            if (selectionStart == selectionEnd)
            {
                var charPos = FormattedText.HitTestTextPosition(CaretIndex);
                
                var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color;
                var caretBrush = Brushes.Black;

                if(backgroundColor.HasValue)
                {
                    byte red = (byte)~(backgroundColor.Value.R);
                    byte green = (byte)~(backgroundColor.Value.G);
                    byte blue = (byte)~(backgroundColor.Value.B);

                    caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue));
                }
                
                if (_caretBlink)
                {
                    var x = Math.Floor(charPos.X) + 0.5;
                    var y = Math.Floor(charPos.Y) + 0.5;
                    var b = Math.Ceiling(charPos.Bottom) - 0.5;

                    context.DrawLine(
                        new Pen(caretBrush, 1),
                        new Point(x, y),
                        new Point(x, b));
                }
            }
        }
示例#3
0
        /// <summary>
        /// Converts a brush to Direct2D.
        /// </summary>
        /// <param name="brush">The brush to convert.</param>
        /// <returns>The Direct2D brush.</returns>
        private SharpDX.Direct2D1.SolidColorBrush Convert(Perspex.Media.Brush brush)
        {
            Perspex.Media.SolidColorBrush solidColorBrush = brush as Perspex.Media.SolidColorBrush;

            if (solidColorBrush != null)
            {
                return(new SharpDX.Direct2D1.SolidColorBrush(
                           this.renderTarget,
                           this.Convert(solidColorBrush.Color)));
            }
            else
            {
                return(new SharpDX.Direct2D1.SolidColorBrush(
                           this.renderTarget,
                           new Color4()));
            }
        }
示例#4
0
        public override void Render(IDrawingContext context)
        {
            var selectionStart = SelectionStart;
            var selectionEnd = SelectionEnd;

            if (selectionStart != selectionEnd)
            {
                var start = Math.Min(selectionStart, selectionEnd);
                var length = Math.Max(selectionStart, selectionEnd) - start;
                var rects = FormattedText.HitTestTextRange(start, length);

                var brush = new SolidColorBrush(0xff086f9e);

                foreach (var rect in rects)
                {
                    context.FillRectange(brush, rect);
                }
            }

            base.Render(context);

            if (selectionStart == selectionEnd)
            {
                var charPos = FormattedText.HitTestTextPosition(CaretIndex);
                Brush caretBrush = Brushes.Black;

                if (_caretBlink)
                {
                    var x = Math.Floor(charPos.X) + 0.5;
                    var y = Math.Floor(charPos.Y) + 0.5;
                    var b = Math.Ceiling(charPos.Bottom) - 0.5;

                    context.DrawLine(
                        new Pen(caretBrush, 1),
                        new Point(x, y),
                        new Point(x, b));
                }
            }
        }
示例#5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="c"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 private void DrawBackground(DrawingContext dc, ArgbColor c, double width, double height)
 {
     var color = Color.FromArgb(c.A, c.R, c.G, c.B);
     var brush = new SolidColorBrush(color);
     var rect = new Rect(0, 0, width, height);
     dc.FillRectangle(brush, rect);
     // TODO: brush.Dispose();
 }