Esempio n. 1
0
        public IEnumerable <ListBoxItem> GetList()
        {
            List <ListBoxItem> list = new List <ListBoxItem>();

            for (int i = 0; i < datas.Count; ++i)
            {
                ListBoxItem item = new ListBoxItem();
                item.Content = datas[i].toString();
                if (datas[i].mode)
                {
                    Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush();
                    brush.Color     = Colors.DarkRed;
                    item.Background = brush.ToImmutable();
                }
                else if (datas[i].contrib.Contains(id))
                {
                    Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush();
                    brush.Color     = Colors.DarkViolet;
                    item.Background = brush.ToImmutable();
                }
                item.DataContext = datas[i];
                list.Add(item);
            }
            return(list.ToImmutableArray());
        }
Esempio n. 2
0
 /// <summary>
 /// Get solid color brush for the given color.
 /// </summary>
 private static IBrush GetSolidColorBrush(RColor color)
 {
     IBrush 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;
 }
Esempio n. 3
0
        public IEnumerable <ListBoxItem> Search(string s)
        {
            List <Tuple <byte, int> > tuples = new List <Tuple <byte, int> >();
            int Hash1, Hash2;

            try
            {
                Hash1 = new MolCalculator(s, AtomDB.hash1, 998244353).Calculate();
                Hash2 = new MolCalculator(s, AtomDB.hash2, 1234567891).Calculate();
            } catch (Exception)
            {
                Hash1 = Hash2 = -1;
            }
            for (int i = 0; i < datas.Count; ++i)
            {
                byte mode = datas[i].Filte(s, Hash1, Hash2);
                if (mode == 0)
                {
                    continue;
                }
                tuples.Add(new Tuple <byte, int>(mode, i));
            }
            tuples.Sort();
            List <ListBoxItem> list = new List <ListBoxItem>();

            for (int j = 0; j < tuples.Count; ++j)
            {
                int         i    = tuples[j].Item2;
                ListBoxItem item = new ListBoxItem();
                item.Content = datas[i].toString();
                if (datas[i].mode)
                {
                    Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush();
                    brush.Color     = Colors.DarkRed;
                    item.Background = brush.ToImmutable();
                }
                else if (datas[i].contrib.Contains(id))
                {
                    Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush();
                    brush.Color     = Colors.DarkViolet;
                    item.Background = brush.ToImmutable();
                }
                item.DataContext = datas[i];
                list.Add(item);
            }
            return(list.ToImmutableArray());
        }
Esempio n. 4
0
        public override void Render(DrawingContext context)
        {
            var selectionStart = SelectionStart;
            var selectionEnd = SelectionEnd;

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

                // issue #600: set constaint before any FormattedText manipulation
                //             see base.Render(...) implementation
                FormattedText.Constraint = Bounds.Size;

                var rects = FormattedText.HitTestTextRange(start, length);

                if (_highlightBrush == null)
                {
                    _highlightBrush = (IBrush)this.FindStyleResource("HighlightBrush");
                }

                foreach (var rect in rects)
                {
                    context.FillRectangle(_highlightBrush, rect);
                }
            }

            base.Render(context);

            if (selectionStart == selectionEnd)
            {                
                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 charPos = FormattedText.HitTestTextPosition(CaretIndex);
                    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));
                }
            }
        }
Esempio n. 5
0
        protected internal override void OnRender(DrawingContext drawingContext)
        {
            Rect rect = new Rect(new Size(this.ActualWidth, this.ActualHeight));

            drawingContext.DrawText(this.FormattedText, new Point());

            if (this.parent.IsKeyboardFocused)
            {
                Point caretPos = this.FormattedText.GetCaretPosition(this.parent.CaretIndex);
                Brush caretBrush = this.parent.CaretBrush;

                if (caretBrush == null)
                {
                    Color color = Colors.Black;
                    SolidColorBrush background = this.parent.Background as SolidColorBrush;

                    if (background != null)
                    {
                        color = Color.FromUInt32(0x00ffffffu ^ background.Color.ToUint32());
                    }

                    caretBrush = new SolidColorBrush(color);
                }

                if (this.caretBlink)
                {
                    drawingContext.DrawLine(
                        new Pen(caretBrush, 1),
                        caretPos,
                        caretPos + new Vector(0, this.FormattedText.Height));
                }
            }
        }