fixed #337
This commit is contained in:
1 parent
a9f0e3fc06
commit
a448702108
2 files changed
+35
-70
No files matched your search
@@ -4,9 +4,11 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Media.Media3D;
|
using System.Windows.Media.Media3D;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
using HandyControl.Tools.Extension;
|
||||||
|
|
||||||
namespace HandyControl.Controls
|
namespace HandyControl.Controls
|
||||||
{
|
{
|
||||||
@@ -27,7 +29,7 @@ namespace HandyControl.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最大显示数量的一半
|
/// 最大显示数量的一半
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int MaxShowCountHalf = 7;
|
private const int MaxShowCountHalf = 3;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 页码
|
/// 页码
|
||||||
@@ -55,7 +57,7 @@ namespace HandyControl.Controls
|
|||||||
private static void OnPageIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnPageIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var ctl = (CoverFlow)d;
|
var ctl = (CoverFlow)d;
|
||||||
ctl.UpdateIndex((int)e.NewValue, (int)e.OldValue);
|
ctl.UpdateIndex((int)e.NewValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -72,13 +74,15 @@ namespace HandyControl.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前在显示范围内的项
|
/// 当前在显示范围内的项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Dictionary<int, CoverFlowItem> _itemShowList = new Dictionary<int, CoverFlowItem>();
|
private readonly Dictionary<int, CoverFlowItem> _itemShowDic = new Dictionary<int, CoverFlowItem>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 相机
|
/// 相机
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private ProjectionCamera _camera;
|
private ProjectionCamera _camera;
|
||||||
|
|
||||||
|
private Point3DAnimation _point3DAnimation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 3d画布
|
/// 3d画布
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -127,7 +131,7 @@ namespace HandyControl.Controls
|
|||||||
if (_viewport3D != null)
|
if (_viewport3D != null)
|
||||||
{
|
{
|
||||||
_viewport3D.Children.Clear();
|
_viewport3D.Children.Clear();
|
||||||
_itemShowList.Clear();
|
_itemShowDic.Clear();
|
||||||
_viewport3D.MouseLeftButtonDown -= Viewport3D_MouseLeftButtonDown;
|
_viewport3D.MouseLeftButtonDown -= Viewport3D_MouseLeftButtonDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +152,9 @@ namespace HandyControl.Controls
|
|||||||
PageIndex = _jumpToIndex;
|
PageIndex = _jumpToIndex;
|
||||||
_jumpToIndex = -1;
|
_jumpToIndex = -1;
|
||||||
}
|
}
|
||||||
_camera.Position = new Point3D(CoverFlowItem.Interval * PageIndex, _camera.Position.Y, _camera.Position.Z);
|
|
||||||
|
_point3DAnimation = new Point3DAnimation(new Point3D(CoverFlowItem.Interval * PageIndex, _camera.Position.Y, _camera.Position.Z), new Duration(TimeSpan.FromMilliseconds(200)));
|
||||||
|
_camera.BeginAnimation(ProjectionCamera.PositionProperty, _point3DAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -204,24 +210,17 @@ namespace HandyControl.Controls
|
|||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
private void Remove(int pos)
|
private void Remove(int pos)
|
||||||
{
|
{
|
||||||
if (!_itemShowList.TryGetValue(pos, out var item)) return;
|
if (!_itemShowDic.TryGetValue(pos, out var item)) return;
|
||||||
_visualParent.Children.Remove(item);
|
_visualParent.Children.Remove(item);
|
||||||
_itemShowList.Remove(pos);
|
_itemShowDic.Remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 移动项到指定的位置
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="index"></param>
|
|
||||||
/// <param name="animated"></param>
|
|
||||||
private void Move(int index, bool animated) => _itemShowList[index].Move(PageIndex, animated);
|
|
||||||
|
|
||||||
private void Viewport3D_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
private void Viewport3D_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
var result = (RayMeshGeometry3DHitTestResult)VisualTreeHelper.HitTest(_viewport3D, e.GetPosition(_viewport3D));
|
var result = (RayMeshGeometry3DHitTestResult)VisualTreeHelper.HitTest(_viewport3D, e.GetPosition(_viewport3D));
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
foreach (var item in _itemShowList.Values)
|
foreach (var item in _itemShowDic.Values)
|
||||||
{
|
{
|
||||||
if (item.HitTest(result.MeshHit))
|
if (item.HitTest(result.MeshHit))
|
||||||
{
|
{
|
||||||
@@ -236,35 +235,25 @@ namespace HandyControl.Controls
|
|||||||
/// 更新项的位置
|
/// 更新项的位置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newIndex"></param>
|
/// <param name="newIndex"></param>
|
||||||
/// <param name="oldIndex"></param>
|
private void UpdateIndex(int newIndex)
|
||||||
private void UpdateIndex(int newIndex, int oldIndex)
|
|
||||||
{
|
{
|
||||||
var animate = Math.Abs(newIndex - oldIndex) < MaxShowCountHalf;
|
|
||||||
UpdateShowRange();
|
UpdateShowRange();
|
||||||
if (newIndex > oldIndex)
|
_itemShowDic.Do(item =>
|
||||||
{
|
{
|
||||||
if (oldIndex < _firstShowIndex)
|
if (item.Value.Index < _firstShowIndex || item.Value.Index > _lastShowIndex)
|
||||||
{
|
{
|
||||||
oldIndex = _firstShowIndex;
|
Remove(item.Value.Index);
|
||||||
}
|
}
|
||||||
for (var i = oldIndex; i <= newIndex; i++)
|
else
|
||||||
{
|
{
|
||||||
Move(i, animate);
|
item.Value.Move(PageIndex);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
else
|
|
||||||
{
|
_point3DAnimation = new Point3DAnimation(new Point3D(CoverFlowItem.Interval * newIndex, _camera.Position.Y,
|
||||||
if (oldIndex > _lastShowIndex)
|
_camera.Position.Z), new Duration(TimeSpan.FromMilliseconds(200)));
|
||||||
{
|
|
||||||
oldIndex = _lastShowIndex;
|
_camera.BeginAnimation(ProjectionCamera.PositionProperty, _point3DAnimation);
|
||||||
}
|
|
||||||
for (var i = oldIndex; i >= newIndex; i--)
|
|
||||||
{
|
|
||||||
Move(i, animate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_camera.Position = new Point3D(CoverFlowItem.Interval * newIndex, _camera.Position.Y,
|
|
||||||
_camera.Position.Z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -275,27 +264,12 @@ namespace HandyControl.Controls
|
|||||||
var newFirstShowIndex = Math.Max(PageIndex - MaxShowCountHalf, 0);
|
var newFirstShowIndex = Math.Max(PageIndex - MaxShowCountHalf, 0);
|
||||||
var newLastShowIndex = Math.Min(PageIndex + MaxShowCountHalf, _contentDic.Count - 1);
|
var newLastShowIndex = Math.Min(PageIndex + MaxShowCountHalf, _contentDic.Count - 1);
|
||||||
|
|
||||||
if (_firstShowIndex < newFirstShowIndex)
|
|
||||||
{
|
|
||||||
for (var i = _firstShowIndex; i < newFirstShowIndex; i++)
|
|
||||||
{
|
|
||||||
Remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (newLastShowIndex < _lastShowIndex)
|
|
||||||
{
|
|
||||||
for (var i = newLastShowIndex; i < _lastShowIndex; i++)
|
|
||||||
{
|
|
||||||
Remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = newFirstShowIndex; i <= newLastShowIndex; i++)
|
for (var i = newFirstShowIndex; i <= newLastShowIndex; i++)
|
||||||
{
|
{
|
||||||
if (!_itemShowList.ContainsKey(i))
|
if (!_itemShowDic.ContainsKey(i))
|
||||||
{
|
{
|
||||||
var cover = CreateCoverFlowItem(i, _contentDic[i]);
|
var cover = CreateCoverFlowItem(i, _contentDic[i]);
|
||||||
_itemShowList[i] = cover;
|
_itemShowDic[i] = cover;
|
||||||
_visualParent.Children.Add(cover);
|
_visualParent.Children.Add(cover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,23 +124,14 @@ namespace HandyControl.Controls
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 移动
|
/// 移动
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void Move(int currentIndex, bool animated)
|
internal void Move(int currentIndex)
|
||||||
{
|
{
|
||||||
if (animated || _rotation3D.HasAnimatedProperties)
|
_rotation3D.BeginAnimation(AxisAngleRotation3D.AngleProperty,
|
||||||
{
|
AnimationHelper.CreateAnimation(GetAngleByPos(currentIndex), AnimationSpeed));
|
||||||
_rotation3D.BeginAnimation(AxisAngleRotation3D.AngleProperty,
|
_transform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty,
|
||||||
AnimationHelper.CreateAnimation(GetAngleByPos(currentIndex), AnimationSpeed));
|
AnimationHelper.CreateAnimation(GetXByPos(currentIndex), AnimationSpeed));
|
||||||
_transform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty,
|
_transform3D.BeginAnimation(TranslateTransform3D.OffsetZProperty,
|
||||||
AnimationHelper.CreateAnimation(GetXByPos(currentIndex), AnimationSpeed));
|
AnimationHelper.CreateAnimation(GetZByPos(currentIndex), AnimationSpeed));
|
||||||
_transform3D.BeginAnimation(TranslateTransform3D.OffsetZProperty,
|
|
||||||
AnimationHelper.CreateAnimation(GetZByPos(currentIndex), AnimationSpeed));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_rotation3D.Angle = GetAngleByPos(currentIndex);
|
|
||||||
_transform3D.OffsetX = GetXByPos(currentIndex);
|
|
||||||
_transform3D.OffsetZ = GetZByPos(currentIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in new issue
Block a user