Skip to content

Commit

Permalink
+ ZoomControl improvements, overall refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
panthernet committed Sep 5, 2016
1 parent 5d80aee commit ae60d5e
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 2,606 deletions.
4 changes: 3 additions & 1 deletion Documents/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
WIP 2.3.6
DETAILED CHANGELOG:
+ Added edge endpoint calculation for rotated vertex that use ellipse math shape
+ Added edge endpoint calculation for rotated vertex that use ellipse, circle and rectangle math shape
+ Added VertexControl::LabelAttached and LabelDetached events which fires when new label is attached to VertexControl or detached from it
+ 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
+ Added support for object visbility and attachable labels to GraphX serialization data
+ Added ZoomControl::ResetKeyBindings() method to clear all (incl default) set key bindings
+ Fixed ZoomControl dynamic content switch to corectly refresh viewfinder
+ Improved ZoomControl handling with disabled animation
+ Renamed ZoomControl::IsAnimationDisabled to IsAnimationEnabled and changed the logic according the modification
+ Renamed ZoomControl::MaximumZoomStep to ZoomStep and updated description
+ 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
+ Some class refactoring

RELEASE 2.3.5
Expand Down
File renamed without changes.
17 changes: 3 additions & 14 deletions GraphX.Controls/Controls/ZoomControl/ZoomContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@

namespace GraphX.Controls
{
public sealed class ZoomContentPresenter : ContentPresenter, INotifyPropertyChanged
public class ZoomContentPresenter : ContentPresenter, INotifyPropertyChanged
{
public event ContentSizeChangedHandler ContentSizeChanged;

private Size _contentSize;

/* public Point ContentTopLeft { get; private set; }
public Point ContentBottomRight { get; private set; }
public Point ContentActualSize { get; private set; }
*/
public Size ContentSize
{
get { return _contentSize; }
Expand All @@ -38,7 +34,7 @@ protected override Size MeasureOverride(Size constraint)

protected override Size ArrangeOverride(Size arrangeBounds)
{
UIElement child = VisualChildrenCount > 0
var child = VisualChildrenCount > 0
? VisualTreeHelper.GetChild(this, 0) as UIElement
: null;
if (child == null)
Expand All @@ -47,21 +43,14 @@ protected override Size ArrangeOverride(Size arrangeBounds)
//set the ContentSize
ContentSize = child.DesiredSize;
child.Arrange(new Rect(child.DesiredSize));
/* if (child is GraphAreaBase)
{
ContentBottomRight = (child as GraphAreaBase).BottomRight;
ContentTopLeft = (child as GraphAreaBase).TopLeft;
ContentActualSize = new Point((child as GraphAreaBase).ActualWidth, (child as GraphAreaBase).ActualHeight);
}*/

return arrangeBounds;
}

public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(name));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
96 changes: 59 additions & 37 deletions GraphX.Controls/Controls/ZoomControl/ZoomControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ private void FillToBounds(object sender, ExecutedRoutedEventArgs e)

#endregion

#region Fit Command
#region ResetZoom Command

public static RoutedUICommand Fit = new RoutedUICommand("Fit Content within Bounds", "FitToBounds", typeof(ZoomControl));

private void FitToBounds(object sender, ExecutedRoutedEventArgs e)
public static RoutedUICommand ResetZoom = new RoutedUICommand("Reset zoom", "ResetZoom", typeof(ZoomControl));
/// <summary>
/// Executes when ResetZoom command is fired and resets the Zoom value to default one. Override to reset to custom zoom value.
/// Default Zoom value is 1.
/// </summary>
protected virtual void ExecuteResetZoom(object sender, ExecutedRoutedEventArgs e)
{

Zoom = 1d;
}

#endregion
Expand Down Expand Up @@ -1051,8 +1054,12 @@ public ZoomControlModes Mode
set { SetValue(ModeProperty, value); }
}

protected RoutedUICommand CommandZoomIn = new RoutedUICommand("Zoom In", "ZoomIn", typeof(ZoomControl));
protected RoutedUICommand CommandZoomOut = new RoutedUICommand("Zoom Out", "ZoomOut", typeof(ZoomControl));
public RoutedUICommand CommandZoomIn = new RoutedUICommand("Zoom In", "ZoomIn", typeof(ZoomControl));
public RoutedUICommand CommandZoomOut = new RoutedUICommand("Zoom Out", "ZoomOut", typeof(ZoomControl));
public RoutedUICommand CommandPanLeft = new RoutedUICommand("Pan Left", "PanLeft", typeof(ZoomControl));
public RoutedUICommand CommandPanRight = new RoutedUICommand("Pan Right", "PanRight", typeof(ZoomControl));
public RoutedUICommand CommandPanTop = new RoutedUICommand("Pan Top", "PanTop", typeof(ZoomControl));
public RoutedUICommand CommandPanBottom = new RoutedUICommand("Pan Bottom", "PanBottom", typeof(ZoomControl));

#endregion

Expand All @@ -1061,6 +1068,11 @@ protected virtual void HookBeforeZoomChanging() { }
protected virtual void HookAfterZoomChanging() { }
#endregion

/// <summary>
/// Gets or sets manual pan sensivity in points when using keys to pan zoomed content. Default value is 10.
/// </summary>
public double ManualPanSensivity { get; set; } = 10d;

static ZoomControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomControl), new FrameworkPropertyMetadata(typeof(ZoomControl)));
Expand All @@ -1083,27 +1095,44 @@ public ZoomControl()
BindCommand(Refocus, RefocusView, CanRefocusView);
BindCommand(Center, CenterContent);
BindCommand(Fill, FillToBounds);
BindCommand(Fit, FitToBounds);

BindKey(CommandZoomIn, Key.Up, ModifierKeys.Control,
(sender, args) => MouseWheelAction(120, OrigoPosition));
BindKey(CommandZoomOut, Key.Down, ModifierKeys.Control,
(sender, args) => MouseWheelAction(-120, OrigoPosition));

BindCommand(ResetZoom, ExecuteResetZoom);
BindCommand(CommandZoomIn, (sender, args) => MouseWheelAction(ZoomSensitivity, OrigoPosition));
BindCommand(CommandZoomOut, (sender, args) => MouseWheelAction(-ZoomSensitivity, OrigoPosition));
BindCommand(CommandPanLeft, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(ManualPanSensivity, 0)));
BindCommand(CommandPanRight, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(-ManualPanSensivity, 0)));
BindCommand(CommandPanTop, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(0, ManualPanSensivity)));
BindCommand(CommandPanBottom, (sender, args) => PanAction(new Vector(TranslateX, TranslateY), new Vector(0, -ManualPanSensivity)));
BindKey(CommandPanLeft, Key.Left, ModifierKeys.None);
BindKey(CommandPanRight, Key.Right, ModifierKeys.None);
BindKey(CommandPanTop, Key.Up, ModifierKeys.None);
BindKey(CommandPanBottom, Key.Down, ModifierKeys.None);
BindKey(CommandZoomIn, Key.Up, ModifierKeys.Control);
BindKey(CommandZoomOut, Key.Down, ModifierKeys.Control);
}
}


protected void BindCommand(RoutedUICommand command, ExecutedRoutedEventHandler execute, CanExecuteRoutedEventHandler canExecute = null)
{
var binding = new CommandBinding(command, execute, canExecute);
CommandBindings.Add(binding);
}

protected void BindKey(RoutedUICommand command, Key key, ModifierKeys modifier, ExecutedRoutedEventHandler execute)
/// <summary>
/// Resets all key bindings for the control
/// </summary>
public void ResetKeyBindings()
{
InputBindings.Clear();
}

/// <summary>
/// Binds specified key to command
/// </summary>
/// <param name="command">Command to execute on key press</param>
/// <param name="key">Key</param>
/// <param name="modifier">Key modifier</param>
public void BindKey(RoutedUICommand command, Key key, ModifierKeys modifier)
{
var binding = new CommandBinding(command, execute);
CommandBindings.Add(binding);
InputBindings.Add(new KeyBinding(command, key, modifier));
}

Expand Down Expand Up @@ -1173,9 +1202,9 @@ private void MouseWheelAction(MouseWheelEventArgs e)
/// <summary>
/// Defines action on mousewheel
/// </summary>
/// <param name="delta"></param>
/// <param name="mousePosition"></param>
protected virtual void MouseWheelAction(int delta, Point mousePosition)
/// <param name="delta">Delta from mousewheel args</param>
/// <param name="mousePosition">Mouse position</param>
protected virtual void MouseWheelAction(double delta, Point mousePosition)
{
var origoPosition = OrigoPosition;
DoZoom(
Expand Down Expand Up @@ -1224,6 +1253,14 @@ private void ZoomControl_MouseUp(object sender, MouseButtonEventArgs e)
ReleaseMouseCapture();
}

protected virtual void PanAction(Vector initialPoint, Vector diff)
{
var translate = initialPoint + diff;
TranslateX = translate.X;
TranslateY = translate.Y;
UpdateViewport();
}

private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (_clickTrack)
Expand All @@ -1239,10 +1276,7 @@ private void ZoomControl_PreviewMouseMove(object sender, MouseEventArgs e)
case ZoomViewModifierMode.None:
return;
case ZoomViewModifierMode.Pan:
var translate = _startTranslate + (e.GetPosition(this) - _mouseDownPos);
TranslateX = translate.X;
TranslateY = translate.Y;
UpdateViewport();
PanAction(_startTranslate, e.GetPosition(this) - _mouseDownPos);
break;
case ZoomViewModifierMode.ZoomIn:
break;
Expand Down Expand Up @@ -1404,18 +1438,6 @@ void ZoomCompleted(object sender, EventArgs e)

#endregion

/// <summary>
/// Zoom to rectangle area (MAY BE DEPRECATED). Use ZoomToContent method instead.
/// </summary>
/// <param name="rect"></param>
/// <param name="setDelta"></param>
public void ZoomTo(Rect rect, bool setDelta = false)
{
ZoomToInternal(rect, setDelta);
UpdateViewFinderDisplayContentBounds();
UpdateViewport();
}

/// <summary>
/// Zoom to rectangle area of the content
/// </summary>
Expand Down
Loading

0 comments on commit ae60d5e

Please sign in to comment.