Browse Source

replaced CaretHighlight control by animated rectangle geometry

pull/15/head
Siegfried Pammer 15 years ago
parent
commit
e9ea4767b7
  1. 5
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 35
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlight.xaml
  3. 26
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlight.xaml.cs
  4. 82
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlightAdorner.cs
  5. 4
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

5
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -94,10 +94,6 @@ @@ -94,10 +94,6 @@
<Compile Include="Src\CodeEditorView.cs" />
<Compile Include="Src\ContextActionsRenderer.cs" />
<Compile Include="Src\ExpressionHighlightRenderer.cs" />
<Compile Include="Src\CaretHighlight.xaml.cs">
<DependentUpon>CaretHighlight.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\CaretHighlightAdorner.cs" />
<Compile Include="Src\NewLineConsistencyCheck.cs" />
<Compile Include="Src\SharpDevelopTextEditor.cs" />
@ -165,7 +161,6 @@ @@ -165,7 +161,6 @@
<EmbeddedResource Include="Resources\ReverseIncrementalSearchCursor.cur" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\CaretHighlight.xaml" />
<Page Include="Src\SharpDevelopCompletionWindow.xaml">
<DependentUpon>SharpDevelopCompletionWindow.cs</DependentUpon>
</Page>

35
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlight.xaml

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
<UserControl x:Class="ICSharpCode.AvalonEdit.AddIn.CaretHighlight"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Border
Name="el"
CornerRadius="2"
BorderThickness="1"
BorderBrush="Black">
<Border.Triggers>
<EventTrigger RoutedEvent="Border.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Width"
From="2" To="12" Duration="0:0:0.4"
AutoReverse="True" RepeatBehavior="1x" />
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Height"
From="17" To="27" Duration="0:0:0.4"
AutoReverse="True" RepeatBehavior="1x" />
<DoubleAnimation
Storyboard.TargetName="el"
Storyboard.TargetProperty="Opacity"
From="1" To="0" Duration="0:0:0.2" BeginTime="0:0:0.6"
RepeatBehavior="1x" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Border.Triggers>
</Border>
</Grid>
</UserControl>

26
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlight.xaml.cs

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.AvalonEdit.AddIn
{
/// <summary>
/// Interaction logic for CaretHighlight.xaml
/// </summary>
public partial class CaretHighlight : UserControl
{
public CaretHighlight()
{
InitializeComponent();
}
}
}

82
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CaretHighlightAdorner.cs

@ -3,10 +3,12 @@ @@ -3,10 +3,12 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.Editing;
namespace ICSharpCode.AvalonEdit.AddIn
{
@ -15,71 +17,37 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -15,71 +17,37 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// </summary>
public class CaretHighlightAdorner : Adorner
{
CaretHighlight highlight;
const double SizeFactor = 0.5;
Rect min, max;
Pen blackPen;
public CaretHighlightAdorner(UIElement adornedElement, Point origin)
: base(adornedElement)
public CaretHighlightAdorner(TextArea textArea)
: base(textArea.TextView)
{
this.Highlight = new CaretHighlight() {
RenderTransform = new TranslateTransform(origin.X, origin.Y),
};
}
Rect caret = textArea.Caret.CalculateCaretRectangle();
/// <summary>
/// Gets/sets the visual child.
/// </summary>
protected CaretHighlight Highlight {
get { return highlight; }
set {
RemoveVisualChild(highlight);
highlight = value;
AddVisualChild(highlight);
InvalidateMeasure();
}
}
this.min = caret;
this.max = new Rect(caret.Location, new Size(caret.Width + Math.Max(caret.Width, caret.Height) * SizeFactor, caret.Height + Math.Max(caret.Width, caret.Height) * SizeFactor));
/// <summary>
/// Gets the visual child.
/// </summary>
protected override Visual GetVisualChild(int index)
{
if (index == 0 && highlight != null)
return highlight;
else
throw new ArgumentOutOfRangeException("index");
}
Vector centerOffset = new Vector(caret.Width / 2, caret.Height / 2);
/// <summary>
/// Gets the number of visual children.
/// </summary>
protected override int VisualChildrenCount {
get { return highlight != null ? 1 : 0; }
}
min.Offset(-textArea.TextView.ScrollOffset);
max.Offset(-textArea.TextView.ScrollOffset);
/// <summary>
/// Measure the visual child.
/// </summary>
protected override Size MeasureOverride(Size availableSize)
{
if (highlight != null) {
highlight.Measure(availableSize);
return availableSize;
} else {
return base.MeasureOverride(availableSize);
}
max.Offset(-centerOffset);
blackPen = new Pen(TextBlock.GetForeground(textArea.TextView).Clone(), 1);
}
/// <summary>
/// Arrange the visual child.
/// </summary>
protected override Size ArrangeOverride(Size finalSize)
protected override void OnRender(DrawingContext drawingContext)
{
if (highlight != null) {
highlight.Arrange(new Rect(new Point(0, 0), finalSize));
return finalSize;
} else {
return base.ArrangeOverride(finalSize);
}
var geometry = new RectangleGeometry(max, 2, 2);
geometry.BeginAnimation(RectangleGeometry.RectProperty, new RectAnimation(max, min, new Duration(TimeSpan.FromMilliseconds(400))) { AutoReverse = true });
blackPen.Brush.BeginAnimation(Brush.OpacityProperty, new DoubleAnimation(1, 0, new Duration(TimeSpan.FromMilliseconds(600))) { BeginTime = TimeSpan.FromMilliseconds(200), AutoReverse = true });
drawingContext.DrawGeometry(null, blackPen, geometry);
}
}
}

4
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditorView.cs

@ -13,8 +13,8 @@ using System.Windows.Controls; @@ -13,8 +13,8 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.AvalonEdit.AddIn.Options;
using ICSharpCode.AvalonEdit.AddIn.Snippets;
using ICSharpCode.AvalonEdit.Editing;
@ -463,7 +463,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -463,7 +463,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
return;
AdornerLayer layer = AdornerLayer.GetAdornerLayer(textArea.TextView);
CaretHighlightAdorner adorner = new CaretHighlightAdorner(textArea.TextView, textArea.Caret.CalculateCaretRectangle().Location - textArea.TextView.ScrollOffset - new Vector(3, 6.75));
CaretHighlightAdorner adorner = new CaretHighlightAdorner(textArea);
layer.Add(adorner);
WorkbenchSingleton.CallLater(TimeSpan.FromSeconds(1), (Action)(() => layer.Remove(adorner)));

Loading…
Cancel
Save