mirror of
https://github.com/VitalickS/BrightSharp.Toolkit.git
synced 2026-03-21 02:21:15 +00:00
Ok, Just Do It!
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
@@ -6,6 +7,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class ResizeRotateAdorner : Adorner
|
||||
{
|
||||
private VisualCollection visuals;
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class ResizeRotateChrome : Control
|
||||
{
|
||||
static ResizeRotateChrome()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class SizeAdorner : Adorner
|
||||
{
|
||||
private SizeChrome chrome;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -6,6 +7,8 @@ using System.Windows.Data;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
|
||||
[ToolboxItem(false)]
|
||||
public class SizeChrome : Control
|
||||
{
|
||||
static SizeChrome()
|
||||
|
||||
@@ -8,9 +8,11 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class DesignerItemDecorator : Control
|
||||
{
|
||||
private Adorner adorner;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System;
|
||||
|
||||
namespace BrightSharp.Diagrams
|
||||
namespace Diagrams
|
||||
{
|
||||
public static class SelectionBehavior
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
@@ -6,6 +7,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class MoveThumb : Thumb
|
||||
{
|
||||
private RotateTransform rotateTransform;
|
||||
|
||||
@@ -6,9 +6,11 @@ using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class ResizeThumb : Thumb
|
||||
{
|
||||
private RotateTransform rotateTransform;
|
||||
@@ -86,12 +88,14 @@ namespace Diagrams
|
||||
{
|
||||
case System.Windows.VerticalAlignment.Bottom:
|
||||
deltaVertical = Math.Min(-e.VerticalChange, this.designerItem.ActualHeight - this.designerItem.MinHeight);
|
||||
deltaVertical = Math.Max(deltaVertical, this.designerItem.ActualHeight - this.designerItem.MaxHeight);
|
||||
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) + (this.transformOrigin.Y * deltaVertical * (1 - Math.Cos(-this.angle))));
|
||||
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) - deltaVertical * this.transformOrigin.Y * Math.Sin(-this.angle));
|
||||
this.designerItem.Height -= deltaVertical;
|
||||
break;
|
||||
case System.Windows.VerticalAlignment.Top:
|
||||
deltaVertical = Math.Min(e.VerticalChange, this.designerItem.ActualHeight - this.designerItem.MinHeight);
|
||||
deltaVertical = Math.Max(deltaVertical, this.designerItem.ActualHeight - this.designerItem.MaxHeight);
|
||||
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) + deltaVertical * Math.Cos(-this.angle) + (this.transformOrigin.Y * deltaVertical * (1 - Math.Cos(-this.angle))));
|
||||
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) + deltaVertical * Math.Sin(-this.angle) - (this.transformOrigin.Y * deltaVertical * Math.Sin(-this.angle)));
|
||||
this.designerItem.Height -= deltaVertical;
|
||||
@@ -104,12 +108,14 @@ namespace Diagrams
|
||||
{
|
||||
case System.Windows.HorizontalAlignment.Left:
|
||||
deltaHorizontal = Math.Min(e.HorizontalChange, this.designerItem.ActualWidth - this.designerItem.MinWidth);
|
||||
deltaHorizontal = Math.Max(deltaHorizontal, this.designerItem.ActualWidth - this.designerItem.MaxWidth);
|
||||
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) + deltaHorizontal * Math.Sin(this.angle) - this.transformOrigin.X * deltaHorizontal * Math.Sin(this.angle));
|
||||
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) + deltaHorizontal * Math.Cos(this.angle) + (this.transformOrigin.X * deltaHorizontal * (1 - Math.Cos(this.angle))));
|
||||
this.designerItem.Width -= deltaHorizontal;
|
||||
break;
|
||||
case System.Windows.HorizontalAlignment.Right:
|
||||
deltaHorizontal = Math.Min(-e.HorizontalChange, this.designerItem.ActualWidth - this.designerItem.MinWidth);
|
||||
deltaHorizontal = Math.Max(deltaHorizontal, this.designerItem.ActualWidth - this.designerItem.MaxWidth);
|
||||
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) - this.transformOrigin.X * deltaHorizontal * Math.Sin(this.angle));
|
||||
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) + (deltaHorizontal * this.transformOrigin.X * (1 - Math.Cos(this.angle))));
|
||||
this.designerItem.Width -= deltaHorizontal;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
@@ -7,6 +8,7 @@ using System.Windows.Media;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class RotateThumb : Thumb
|
||||
{
|
||||
private double initialAngle;
|
||||
|
||||
115
BrightSharp/Diagrams/VisualExtensions.cs
Normal file
115
BrightSharp/Diagrams/VisualExtensions.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using BrightSharp;
|
||||
using BrightSharp.Extensions;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace Diagrams
|
||||
{
|
||||
/// <summary>
|
||||
/// If starts with a(A) then use animation,
|
||||
/// $FromZoom-$ToZoom pattern
|
||||
/// </summary>
|
||||
public class VisualExtensions : DependencyObject
|
||||
{
|
||||
#region LevelOfDetails Attached Property
|
||||
|
||||
public static readonly DependencyProperty LODZoomProperty =
|
||||
DependencyProperty.RegisterAttached("LODZoom",
|
||||
typeof(string),
|
||||
typeof(VisualExtensions),
|
||||
new UIPropertyMetadata(null, OnChangeLODZoomProperty));
|
||||
|
||||
public static void SetLODZoom(UIElement element, string o)
|
||||
{
|
||||
element.SetValue(LODZoomProperty, o);
|
||||
}
|
||||
|
||||
public static string GetLODZoom(UIElement element)
|
||||
{
|
||||
return (string)element.GetValue(LODZoomProperty);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static void OnChangeLODZoomProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var element = d as FrameworkElement;
|
||||
if (element == null) return;
|
||||
|
||||
var window = Window.GetWindow(element);
|
||||
if (window == null) return;
|
||||
|
||||
if (e.NewValue != e.OldValue)
|
||||
{
|
||||
var zoomControl = element.FindAncestor<ZoomControl>();
|
||||
if (zoomControl == null) return;
|
||||
|
||||
var zoomChangedHandler = new RoutedEventHandler((sender, args) =>
|
||||
{
|
||||
var lodInfo = new LodInfo(GetLODZoom(element));
|
||||
|
||||
var transform = element.TransformToVisual(window) as MatrixTransform;
|
||||
var scaleX = transform.Matrix.M11;
|
||||
|
||||
var newOpacity = (scaleX >= lodInfo.StartRange && scaleX <= lodInfo.EndRange) ? 1 : 0;
|
||||
|
||||
if (lodInfo.UseAnimation && args.RoutedEvent != FrameworkElement.LoadedEvent)
|
||||
{
|
||||
element.Visibility = Visibility.Visible;
|
||||
var animation = new DoubleAnimation(newOpacity, TimeSpan.FromSeconds(.5));
|
||||
element.BeginAnimation(UIElement.OpacityProperty, animation);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.Visibility = newOpacity == 1 ? Visibility.Visible : Visibility.Hidden;
|
||||
element.Opacity = newOpacity;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace((string)e.NewValue))
|
||||
{
|
||||
element.Opacity = 1;
|
||||
zoomControl.ZoomChanged -= zoomChangedHandler;
|
||||
zoomControl.Loaded -= zoomChangedHandler;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoomControl.ZoomChanged += zoomChangedHandler;
|
||||
zoomControl.Loaded += zoomChangedHandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class LodInfo
|
||||
{
|
||||
public LodInfo(string lod)
|
||||
{
|
||||
UseAnimation = lod.StartsWith("a", true, CultureInfo.InvariantCulture);
|
||||
lod = lod.TrimStart('a', 'A').Trim();
|
||||
|
||||
double rangeStart = 0;
|
||||
double rangeEnd = double.PositiveInfinity;
|
||||
var vals = lod.Split('-');
|
||||
|
||||
double.TryParse(vals[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rangeStart);
|
||||
|
||||
if (vals.Length > 1)
|
||||
{
|
||||
if (!double.TryParse(vals[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rangeEnd))
|
||||
{
|
||||
rangeEnd = double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
EndRange = rangeEnd;
|
||||
StartRange = rangeStart;
|
||||
}
|
||||
public double StartRange { get; set; }
|
||||
public double EndRange { get; set; }
|
||||
public bool UseAnimation { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user