小数点以下四捨五入による顔のビット:SelectionBorderを作成しますか?
質問
私は現在、WPFでSelectionBorderというクラスを実装しています。これは、Shapeクラスから派生します。
これは、基本的にはこのようになります:
public class SelectionBorder : Shape
{
public Point StartPoint {get; set;}
public PointCollection Points {get; set;}
public double StrokeLength {get; set;}
protected override Geometry DefiningGeometry{
get{
//Magic!
}
}
}
StartPointのとポイント特性は、境界のコーナーを決定します。境界は、一般的なストロークのライン境界である(一方黒脳卒中、そのようなもの不可視ストローク: - - - - )
私が今持っている問題があるコーナーポイントを自由にしているので、それは(黒と不可視のストロークを意味する)のストロークのカウントが偶数(実際にはない偶数の整数)ではないことはかなり一般的なので、第1ストロークルックスだが選択可能なこと他のものより長い(画像に表示)。これはおそらく大したことしていないようですが、私は、後のストロークがコンテンツの周りを一周するように境界線をアニメーション化します。このアニメーションを行う場合は、静的ビューの小さな欠陥がはっきり見えるようになり、私の意見では非常に憂慮されます。
http://img14.imageshack.us/img14/2874/selectionborder .PNGする
問題は、私は可能な限り元のStrokeLengthに近い取得し、ストロークの偶数を作成StrokeLengthを決定しようとしたことです。しかし、私はに実行した問題は、(明らかに)WPFは、二重小数StrokeLengthの全体の精度を表示することができないため、結果のストローク数が再び不均一であるということです。
この問題の任意の回避策はありますか?あなたは、おそらく私の問題のため、別の解決策を持っていますか?
事前に感謝します!
編集:私は再テストやフィットネスのために少し休憩今日の後に、コードを見直し、すべての後に、それは非常に大きなStrokeLengthsに起こります。私は少しアニメーションジャンプが問題で、私が当初考えていたよりもはるかに少ないを行い2のStrokeLengthsを使用する予定。
解決 2
私はちょうどそれが道に簡単なアニメーションSelectionBorderを作成することができます方法を見つけます。
その代わり、私はちょうどネイティブShapeクラスによって提供さStrokeDashOffsetプロパティをアニメーションアニメーションを通じて自己作成AnimationPointを移動しStrokeLengthを定義するためにStrokeDashArrayを設定することで、アニメーションを作成します。
これは、XAMLで次のようになります:
<namespace:SelectionBorder StrokeDashArray="2" AnimationDuration="0:0:1" Stroke="Black" />
クラスは次のようになります:
public class SelectionBorder : Shape
{
private DoubleAnimation m_Animation;
private bool m_AnimationStarted;
public SelectionBorder()
{
IsVisibleChanged += OnIsVisibleChanged;
}
protected void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (Visibility == Visibility.Visible)
{
StartAnimation();
}
else
{
StopAnimation();
}
}
public void StartAnimation()
{
if (m_AnimationStarted)
return;
if (m_Animation == null)
{
m_Animation = CreateAnimation();
}
BeginAnimation(StrokeDashOffsetProperty, m_Animation);
m_AnimationStarted = true;
}
protected virtual DoubleAnimation CreateAnimation()
{
DoubleAnimation animation = new DoubleAnimation();
animation.From = 0;
if (StrokeDashArray.Count == 0)
animation.To = 4;
else
animation.To = StrokeDashArray.First() * 2;
animation.Duration = AnimationDuration;
animation.RepeatBehavior = RepeatBehavior.Forever;
return animation;
}
public void StopAnimation()
{
if (m_AnimationStarted)
{
BeginAnimation(StrokeDashOffsetProperty, null);
m_AnimationStarted = false;
}
}
#region Dependency Properties
public Duration AnimationDuration
{
get { return (Duration)GetValue(AnimationDurationProperty); }
set { SetValue(AnimationDurationProperty, value); }
}
public static readonly DependencyProperty AnimationDurationProperty =
DependencyProperty.Register("AnimationDuration", typeof(Duration), typeof(SelectionBorder), new UIPropertyMetadata(new Duration(TimeSpan.FromSeconds(0.5))));
#endregion Dependency Properties
protected override Geometry DefiningGeometry
{
get
{
double width = (double.IsNaN(Width)) ? ((Panel)Parent).ActualWidth : Width;
double height = (double.IsNaN(Height)) ? ((Panel)Parent).ActualHeight : Height;
RectangleGeometry geometry = new RectangleGeometry(new Rect(0, 0, width, height));
return geometry;
}
}
}
他のヒント
あなたは、複数のコーナー「非マッチ」という点では作ることができます。たとえば、代わりに1ポイントは、「ソース」やアニメダッシュの「目的地」であると、あなたは2点を選択できます。一つは、ダッシュ2つの方向に離れてから3月、別の点はダッシュが収束して消滅「宛先」、であるように見える、「ソース」になります。
GIMPは、例えば、選択は、このように破線および「ソース」と点「宛先」の右上に最も近いため左下に最も近い点を選ぶように見えるアニメーション
あなたにも、いくつかの他のスキームを考え出すことができます。
ただ、それはあなたに邪魔に見えるかもしれないが、ほとんどのユーザーは気にしないであろうことを覚えています。