Beispiel #1
0
        //...........................................................

        public void Draw(avalon.Rendering.TextView VIEW, DrawingContext CONTEXT)
        {
            if (m_editor.Document == null)
            {
                return;
            }

            VIEW.EnsureVisualLines();
            if (m_editor.ExtentWidth < 1)
            {
                return;                                         // happens on init
            }
            // draw full-width, not just text width
            var size = new Size(
                m_editor.ExtentWidth,
                VIEW.DefaultLineHeight
                );

            for (var i = 0; i < Lines.Count; ++i)
            {
                var   diff  = Lines[i];
                Brush brush = null;

                if (diff.Text == null)
                {
                    brush = PaddingBrush;
                }
                else
                {
                    switch (diff.Type)
                    {
                    case diffplex.Model.ChangeType.Modified: brush = ModifiedBrush; break;

                    case diffplex.Model.ChangeType.Deleted:  brush = DeletedBrush;  break;

                    case diffplex.Model.ChangeType.Inserted: brush = InsertedBrush; break;
                    }
                }
                if (brush == null)
                {
                    continue;
                }

                var line = m_editor.Document.GetLineByNumber(i + 1);

                // usually only 1 rect per line, but may have more
                foreach (var rect in avalon.Rendering.BackgroundGeometryBuilder.GetRectsForSegment(VIEW, line))
                {
                    var extents = new Rect(rect.Location, size);
                    CONTEXT.DrawRectangle(brush, null, extents);
                }
            }
        }
Beispiel #2
0
        /*public void UpdatePosition(){
         *  Main main = Main.Get();
         *
         *  //this.SetPosition();
         * }*/

        /*protected void SetPosition(TextViewPosition position)
         * {
         *  TextView textView = this.TextArea.TextView;
         *
         *
         *  UpdatePosition();
         * }*/

        public void UpdatePosition()
        {
            Main main = Main.Get();

            ICSharpCode.AvalonEdit.Rendering.TextView textView = main.editor.TextArea.TextView;
            ICSharpCode.AvalonEdit.TextViewPosition   position = new ICSharpCode.AvalonEdit.TextViewPosition(main.editor.Document.GetLocation(main.completionStartPosition));

            Point visualLocation    = textView.GetVisualPosition(position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.LineBottom);
            Point visualLocationTop = textView.GetVisualPosition(position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.LineTop);

            // PointToScreen returns device dependent units (physical pixels)
            Point location    = textView.PointToScreen(visualLocation - textView.ScrollOffset);
            Point locationTop = textView.PointToScreen(visualLocationTop - textView.ScrollOffset);

            // Let's use device dependent units for everything
            //Size completionWindowSize = new Size(this.Width, this.Height).TransformToDevice(textView);
            Rect bounds = new Rect(location, new Size(this.Width, this.Height));

            System.Drawing.Rectangle systemRect = System.Windows.Forms.Screen.GetWorkingArea(new System.Drawing.Point((int)location.X, (int)location.Y));
            Rect workingScreen = new Rect(new Point(systemRect.Location.X, systemRect.Location.Y), new Size(systemRect.Size.Width, systemRect.Size.Height));//.ToWpf();

            if (!workingScreen.Contains(bounds))
            {
                if (bounds.Left < workingScreen.Left)
                {
                    bounds.X = workingScreen.Left;
                }
                else if (bounds.Right > workingScreen.Right)
                {
                    bounds.X = workingScreen.Right - bounds.Width;
                }
                if (bounds.Bottom > workingScreen.Bottom)
                {
                    bounds.Y = locationTop.Y - bounds.Height;
                }
                if (bounds.Y < workingScreen.Top)
                {
                    bounds.Y = workingScreen.Top;
                }
            }
            // Convert the window bounds to device independent units

            Matrix matrix = PresentationSource.FromVisual(textView).CompositionTarget.TransformFromDevice;

            bounds    = Rect.Transform(bounds, matrix);
            this.Left = (int)bounds.X - 29 - main.Left;
            this.Top  = (int)bounds.Y - 30 - main.Top;
        }