Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
> - Breaking Changes:
> - Made the setter of NodifyEditor.IsPanning private
> - Renamed StartCutting to BeginCutting in NodifyEditor
> - Renamed PushItems to UpdatePushedArea and StartPushingItems to BeginPushingItems in NodifyEditor
> - Features:
> - Added BeginPanning, UpdatePanning, EndPanning, CancelPanning and AllowPanningCancellation to NodifyEditor
> - Added UpdateCuttingLine to NodifyEditor
Expand Down
12 changes: 4 additions & 8 deletions Nodify/EditorStates/EditorPushingItemsState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ public override void Enter(EditorState? from)

public override void Exit()
{
if (!Editor.IsPushingItems)
{
return;
}

// TODO: This is not canceled on LostMouseCapture (add OnLostMouseCapture/OnCancel callback?)
if (Canceled)
{
Editor.CancelPushingItems();
Expand All @@ -44,18 +40,18 @@ public override void HandleMouseMove(MouseEventArgs e)
{
if (Editor.IsPushingItems)
{
Editor.PushItems(Editor.MouseLocation - _prevPosition);
Editor.UpdatePushedArea(Editor.MouseLocation - _prevPosition);
_prevPosition = Editor.MouseLocation;
}
else
{
if (Math.Abs(Editor.MouseLocation.X - _prevPosition.X) >= _minDragDistance)
{
Editor.StartPushingItems(_prevPosition, Orientation.Horizontal);
Editor.BeginPushingItems(_prevPosition, Orientation.Horizontal);
}
else if (Math.Abs(Editor.MouseLocation.Y - _prevPosition.Y) >= _minDragDistance)
{
Editor.StartPushingItems(_prevPosition, Orientation.Vertical);
Editor.BeginPushingItems(_prevPosition, Orientation.Vertical);
}
}
}
Expand Down
49 changes: 26 additions & 23 deletions Nodify/NodifyEditor.PushingItems.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Windows;
using System;
using System.Windows.Controls;
using System.Windows.Shapes;

Expand Down Expand Up @@ -92,11 +91,15 @@ public Style PushedAreaStyle
/// <summary>
/// Starts the pushing items operation at the specified location with the specified orientation.
/// </summary>
/// <remarks>This method has no effect if a pushing operation is already in progress.</remarks>
/// <param name="location">The starting location for pushing items, in graph space coordinates.</param>
/// <param name="orientation">The orientation of the <see cref="PushedArea"/>.</param>
protected internal void StartPushingItems(Point location, Orientation orientation)
public void BeginPushingItems(Point location, Orientation orientation)
{
Debug.Assert(!IsPushingItems);
if(IsPushingItems)
{
return;
}

IsPushingItems = true;
PushedAreaOrientation = orientation;
Expand All @@ -107,30 +110,28 @@ protected internal void StartPushingItems(Point location, Orientation orientatio
}

/// <summary>
/// Cancels the current pushing operation and reverts the <see cref="PushedArea"/> to its initial state.
/// Cancels the current pushing operation and reverts the <see cref="PushedArea"/> to its initial state if <see cref="AllowPushItemsCancellation"/> is true.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if pushing item cancellation is not allowed (see <see cref="AllowPushItemsCancellation"/>).</exception>
protected internal void CancelPushingItems()
/// <remarks>This method has no effect if there's no pushing operation in progress.</remarks>
public void CancelPushingItems()
{
if (!AllowPushItemsCancellation)
throw new InvalidOperationException("Push items cancellation is not allowed");

Debug.Assert(IsPushingItems);
if (IsPushingItems)
if (!AllowPushItemsCancellation || !IsPushingItems)
{
PushedArea = _pushStrategy!.Cancel();
IsPushingItems = false;
return;
}

PushedArea = _pushStrategy!.Cancel();
IsPushingItems = false;
}

/// <summary>
/// Updates the pushed area based on the specified amount.
/// Updates the pushed area based on the specified amount taking the <see cref="PushedAreaOrientation"/> into account.
/// </summary>
/// <param name="offset">The amount to adjust the pushed area by.</param>
/// <param name="amount">The amount to adjust the pushed area by.</param>
/// <remarks>
/// This method adjusts the pushed area incrementally. It should only be called while a pushing operation is active (see <see cref="StartPushingItems(Point, Orientation)"/>).
/// This method adjusts the pushed area incrementally. It should only be called while a pushing operation is active (see <see cref="BeginPushingItems(Point, Orientation)"/>).
/// </remarks>
protected internal void PushItems(Vector amount)
public void UpdatePushedArea(Vector amount)
{
Debug.Assert(IsPushingItems);
PushedArea = _pushStrategy!.Push(amount);
Expand All @@ -139,15 +140,17 @@ protected internal void PushItems(Vector amount)
/// <summary>
/// Ends the current pushing operation and finalizes the pushed area state.
/// </summary>
protected internal void EndPushingItems()
/// <remarks>This method has no effect if there's no pushing operation in progress.</remarks>
public void EndPushingItems()
{
Debug.Assert(IsPushingItems);
if (IsPushingItems)
if (!IsPushingItems)
{
PushedArea = _pushStrategy!.End();
_pushStrategy = null;
IsPushingItems = false;
return;
}

PushedArea = _pushStrategy!.End();
_pushStrategy = null;
IsPushingItems = false;
}

private void UpdatePushedArea()
Expand Down
Loading