Skip to content

Commit ae60d5e

Browse files
committed
+ ZoomControl improvements, overall refactoring
1 parent 5d80aee commit ae60d5e

18 files changed

+210
-2606
lines changed

Documents/CHANGELOG.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
WIP 2.3.6
22
DETAILED CHANGELOG:
3-
+ Added edge endpoint calculation for rotated vertex that use ellipse math shape
3+
+ Added edge endpoint calculation for rotated vertex that use ellipse, circle and rectangle math shape
44
+ Added VertexControl::LabelAttached and LabelDetached events which fires when new label is attached to VertexControl or detached from it
55
+ Added new parameter to GraphArea::UpdateParallelEdgesData(Dictionary<TEdge, EdgeControl> edgeList) to be able to specify edges list to parse for parallelization instead of full edge list parse
66
+ Added support for object visbility and attachable labels to GraphX serialization data
7+
+ Added ZoomControl::ResetKeyBindings() method to clear all (incl default) set key bindings
78
+ Fixed ZoomControl dynamic content switch to corectly refresh viewfinder
89
+ Improved ZoomControl handling with disabled animation
910
+ Renamed ZoomControl::IsAnimationDisabled to IsAnimationEnabled and changed the logic according the modification
1011
+ Renamed ZoomControl::MaximumZoomStep to ZoomStep and updated description
12+
+ Implemented easy ZoomControl key bindings with BindKey() method and exposed base commands for zoom and pan actions to be able to bind keys for them
1113
+ Some class refactoring
1214

1315
RELEASE 2.3.5

GraphX.Controls/Controls/ZoomControl/ZoomContentPresenter.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55

66
namespace GraphX.Controls
77
{
8-
public sealed class ZoomContentPresenter : ContentPresenter, INotifyPropertyChanged
8+
public class ZoomContentPresenter : ContentPresenter, INotifyPropertyChanged
99
{
1010
public event ContentSizeChangedHandler ContentSizeChanged;
1111

1212
private Size _contentSize;
1313

14-
/* public Point ContentTopLeft { get; private set; }
15-
public Point ContentBottomRight { get; private set; }
16-
public Point ContentActualSize { get; private set; }
17-
*/
1814
public Size ContentSize
1915
{
2016
get { return _contentSize; }
@@ -38,7 +34,7 @@ protected override Size MeasureOverride(Size constraint)
3834

3935
protected override Size ArrangeOverride(Size arrangeBounds)
4036
{
41-
UIElement child = VisualChildrenCount > 0
37+
var child = VisualChildrenCount > 0
4238
? VisualTreeHelper.GetChild(this, 0) as UIElement
4339
: null;
4440
if (child == null)
@@ -47,21 +43,14 @@ protected override Size ArrangeOverride(Size arrangeBounds)
4743
//set the ContentSize
4844
ContentSize = child.DesiredSize;
4945
child.Arrange(new Rect(child.DesiredSize));
50-
/* if (child is GraphAreaBase)
51-
{
52-
ContentBottomRight = (child as GraphAreaBase).BottomRight;
53-
ContentTopLeft = (child as GraphAreaBase).TopLeft;
54-
ContentActualSize = new Point((child as GraphAreaBase).ActualWidth, (child as GraphAreaBase).ActualHeight);
55-
}*/
5646

5747
return arrangeBounds;
5848
}
5949

6050
public event PropertyChangedEventHandler PropertyChanged;
6151
public void OnPropertyChanged(string name)
6252
{
63-
if (PropertyChanged != null)
64-
PropertyChanged(this, new PropertyChangedEventArgs(name));
53+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
6554
}
6655
}
6756
}

GraphX.Controls/Controls/ZoomControl/ZoomControl.cs

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ private void FillToBounds(object sender, ExecutedRoutedEventArgs e)
4242

4343
#endregion
4444

45-
#region Fit Command
45+
#region ResetZoom Command
4646

47-
public static RoutedUICommand Fit = new RoutedUICommand("Fit Content within Bounds", "FitToBounds", typeof(ZoomControl));
48-
49-
private void FitToBounds(object sender, ExecutedRoutedEventArgs e)
47+
public static RoutedUICommand ResetZoom = new RoutedUICommand("Reset zoom", "ResetZoom", typeof(ZoomControl));
48+
/// <summary>
49+
/// Executes when ResetZoom command is fired and resets the Zoom value to default one. Override to reset to custom zoom value.
50+
/// Default Zoom value is 1.
51+
/// </summary>
52+
protected virtual void ExecuteResetZoom(object sender, ExecutedRoutedEventArgs e)
5053
{
51-
54+
Zoom = 1d;
5255
}
5356

5457
#endregion
@@ -1051,8 +1054,12 @@ public ZoomControlModes Mode
10511054
set { SetValue(ModeProperty, value); }
10521055
}
10531056

1054-
protected RoutedUICommand CommandZoomIn = new RoutedUICommand("Zoom In", "ZoomIn", typeof(ZoomControl));
1055-
protected RoutedUICommand CommandZoomOut = new RoutedUICommand("Zoom Out", "ZoomOut", typeof(ZoomControl));
1057+
public RoutedUICommand CommandZoomIn = new RoutedUICommand("Zoom In", "ZoomIn", typeof(ZoomControl));
1058+
public RoutedUICommand CommandZoomOut = new RoutedUICommand("Zoom Out", "ZoomOut", typeof(ZoomControl));
1059+
public RoutedUICommand CommandPanLeft = new RoutedUICommand("Pan Left", "PanLeft", typeof(ZoomControl));
1060+
public RoutedUICommand CommandPanRight = new RoutedUICommand("Pan Right", "PanRight", typeof(ZoomControl));
1061+
public RoutedUICommand CommandPanTop = new RoutedUICommand("Pan Top", "PanTop", typeof(ZoomControl));
1062+
public RoutedUICommand CommandPanBottom = new RoutedUICommand("Pan Bottom", "PanBottom", typeof(ZoomControl));
10561063

10571064
#endregion
10581065

@@ -1061,6 +1068,11 @@ protected virtual void HookBeforeZoomChanging() { }
10611068
protected virtual void HookAfterZoomChanging() { }
10621069
#endregion
10631070

1071+
/// <summary>
1072+
/// Gets or sets manual pan sensivity in points when using keys to pan zoomed content. Default value is 10.
1073+
/// </summary>
1074+
public double ManualPanSensivity { get; set; } = 10d;
1075+
10641076
static ZoomControl()
10651077
{
10661078
DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomControl), new FrameworkPropertyMetadata(typeof(ZoomControl)));
@@ -1083,27 +1095,44 @@ public ZoomControl()
10831095
BindCommand(Refocus, RefocusView, CanRefocusView);
10841096
BindCommand(Center, CenterContent);
10851097
BindCommand(Fill, FillToBounds);
1086-
BindCommand(Fit, FitToBounds);
1087-
1088-
BindKey(CommandZoomIn, Key.Up, ModifierKeys.Control,
1089-
(sender, args) => MouseWheelAction(120, OrigoPosition));
1090-
BindKey(CommandZoomOut, Key.Down, ModifierKeys.Control,
1091-
(sender, args) => MouseWheelAction(-120, OrigoPosition));
1092-
1098+
BindCommand(ResetZoom, ExecuteResetZoom);
1099+
BindCommand(CommandZoomIn, (sender, args) => MouseWheelAction(ZoomSensitivity, OrigoPosition));
1100+
BindCommand(CommandZoomOut, (sender, args) => MouseWheelAction(-ZoomSensitivity, OrigoPosition));
1101+
BindCommand(CommandPanLeft, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(ManualPanSensivity, 0)));
1102+
BindCommand(CommandPanRight, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(-ManualPanSensivity, 0)));
1103+
BindCommand(CommandPanTop, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(0, ManualPanSensivity)));
1104+
BindCommand(CommandPanBottom, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(0, -ManualPanSensivity)));
1105+
BindKey(CommandPanLeft, Key.Left, ModifierKeys.None);
1106+
BindKey(CommandPanRight, Key.Right, ModifierKeys.None);
1107+
BindKey(CommandPanTop, Key.Up, ModifierKeys.None);
1108+
BindKey(CommandPanBottom, Key.Down, ModifierKeys.None);
1109+
BindKey(CommandZoomIn, Key.Up, ModifierKeys.Control);
1110+
BindKey(CommandZoomOut, Key.Down, ModifierKeys.Control);
10931111
}
10941112
}
10951113

1096-
10971114
protected void BindCommand(RoutedUICommand command, ExecutedRoutedEventHandler execute, CanExecuteRoutedEventHandler canExecute = null)
10981115
{
10991116
var binding = new CommandBinding(command, execute, canExecute);
11001117
CommandBindings.Add(binding);
11011118
}
11021119

1103-
protected void BindKey(RoutedUICommand command, Key key, ModifierKeys modifier, ExecutedRoutedEventHandler execute)
1120+
/// <summary>
1121+
/// Resets all key bindings for the control
1122+
/// </summary>
1123+
public void ResetKeyBindings()
1124+
{
1125+
InputBindings.Clear();
1126+
}
1127+
1128+
/// <summary>
1129+
/// Binds specified key to command
1130+
/// </summary>
1131+
/// <param name="command">Command to execute on key press</param>
1132+
/// <param name="key">Key</param>
1133+
/// <param name="modifier">Key modifier</param>
1134+
public void BindKey(RoutedUICommand command, Key key, ModifierKeys modifier)
11041135
{
1105-
var binding = new CommandBinding(command, execute);
1106-
CommandBindings.Add(binding);
11071136
InputBindings.Add(new KeyBinding(command, key, modifier));
11081137
}
11091138

@@ -1173,9 +1202,9 @@ private void MouseWheelAction(MouseWheelEventArgs e)
11731202
/// <summary>
11741203
/// Defines action on mousewheel
11751204
/// </summary>
1176-
/// <param name="delta"></param>
1177-
/// <param name="mousePosition"></param>
1178-
protected virtual void MouseWheelAction(int delta, Point mousePosition)
1205+
/// <param name="delta">Delta from mousewheel args</param>
1206+
/// <param name="mousePosition">Mouse position</param>
1207+
protected virtual void MouseWheelAction(double delta, Point mousePosition)
11791208
{
11801209
var origoPosition = OrigoPosition;
11811210
DoZoom(
@@ -1224,6 +1253,14 @@ private void ZoomControl_MouseUp(object sender, MouseButtonEventArgs e)
12241253
ReleaseMouseCapture();
12251254
}
12261255

1256+
protected virtual void PanAction(Vector initialPoint, Vector diff)
1257+
{
1258+
var translate = initialPoint + diff;
1259+
TranslateX = translate.X;
1260+
TranslateY = translate.Y;
1261+
UpdateViewport();
1262+
}
1263+
12271264
private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
12281265
{
12291266
if (_clickTrack)
@@ -1239,10 +1276,7 @@ private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
12391276
case ZoomViewModifierMode.None:
12401277
return;
12411278
case ZoomViewModifierMode.Pan:
1242-
var translate = _startTranslate + (e.GetPosition(this) - _mouseDownPos);
1243-
TranslateX = translate.X;
1244-
TranslateY = translate.Y;
1245-
UpdateViewport();
1279+
PanAction(_startTranslate, e.GetPosition(this) - _mouseDownPos);
12461280
break;
12471281
case ZoomViewModifierMode.ZoomIn:
12481282
break;
@@ -1404,18 +1438,6 @@ void ZoomCompleted(object sender, EventArgs e)
14041438

14051439
#endregion
14061440

1407-
/// <summary>
1408-
/// Zoom to rectangle area (MAY BE DEPRECATED). Use ZoomToContent method instead.
1409-
/// </summary>
1410-
/// <param name="rect"></param>
1411-
/// <param name="setDelta"></param>
1412-
public void ZoomTo(Rect rect, bool setDelta = false)
1413-
{
1414-
ZoomToInternal(rect, setDelta);
1415-
UpdateViewFinderDisplayContentBounds();
1416-
UpdateViewport();
1417-
}
1418-
14191441
/// <summary>
14201442
/// Zoom to rectangle area of the content
14211443
/// </summary>

0 commit comments

Comments
 (0)