Skip to content

Commit

Permalink
Rename Process to ProcessEvent in InputProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
miroiu committed Dec 17, 2024
1 parent de2d254 commit ff589bd
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 40 deletions.
14 changes: 7 additions & 7 deletions Nodify/Connections/BaseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,12 +803,12 @@ public void StopAnimation()

/// <inheritdoc />
protected override void OnMouseDown(MouseButtonEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseUp(MouseButtonEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released
if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released)
Expand All @@ -819,20 +819,20 @@ protected override void OnMouseUp(MouseButtonEventArgs e)

/// <inheritdoc />
protected override void OnMouseMove(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseWheel(MouseWheelEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnLostMouseCapture(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnKeyUp(KeyEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released
if (IsMouseCaptured && Mouse.RightButton == MouseButtonState.Released && Mouse.LeftButton == MouseButtonState.Released && Mouse.MiddleButton == MouseButtonState.Released)
Expand All @@ -843,7 +843,7 @@ protected override void OnKeyUp(KeyEventArgs e)

/// <inheritdoc />
protected override void OnKeyDown(KeyEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

#endregion

Expand Down
14 changes: 7 additions & 7 deletions Nodify/Connectors/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ public void UpdateAnchor()

/// <inheritdoc />
protected override void OnMouseDown(MouseButtonEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseUp(MouseButtonEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -348,20 +348,20 @@ protected override void OnMouseUp(MouseButtonEventArgs e)

/// <inheritdoc />
protected override void OnMouseMove(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseWheel(MouseWheelEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnLostMouseCapture(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnKeyUp(KeyEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && Mouse.RightButton == MouseButtonState.Released && Mouse.LeftButton == MouseButtonState.Released && Mouse.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -372,7 +372,7 @@ protected override void OnKeyUp(KeyEventArgs e)

/// <inheritdoc />
protected override void OnKeyDown(KeyEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <summary>
/// Determines whether any toggled interaction is currently in progress.
Expand Down
14 changes: 7 additions & 7 deletions Nodify/Containers/ItemContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ public void Select(SelectionType type)

/// <inheritdoc />
protected override void OnMouseDown(MouseButtonEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseUp(MouseButtonEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -385,20 +385,20 @@ protected override void OnMouseUp(MouseButtonEventArgs e)

/// <inheritdoc />
protected override void OnMouseMove(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnMouseWheel(MouseWheelEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnLostMouseCapture(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnKeyUp(KeyEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && Mouse.RightButton == MouseButtonState.Released && Mouse.LeftButton == MouseButtonState.Released && Mouse.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -409,7 +409,7 @@ protected override void OnKeyUp(KeyEventArgs e)

/// <inheritdoc />
protected override void OnKeyDown(KeyEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <summary>
/// Determines whether any toggled interaction is currently in progress.
Expand Down
2 changes: 1 addition & 1 deletion Nodify/Editor/NodifyEditor.Panning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void HandleAutoPanning(object? sender, EventArgs e)

_autoPanningEventArgs.Handled = false;
_autoPanningEventArgs.Source = this;
InputProcessor.Process(_autoPanningEventArgs);
InputProcessor.ProcessEvent(_autoPanningEventArgs);
}
}

Expand Down
14 changes: 7 additions & 7 deletions Nodify/Editor/NodifyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,14 @@ protected void OnRemoveConnection(object? dataContext)
protected override void OnMouseDown(MouseButtonEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnMouseUp(MouseButtonEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -818,24 +818,24 @@ protected override void OnMouseUp(MouseButtonEventArgs e)
protected override void OnMouseMove(MouseEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnLostMouseCapture(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnKeyUp(KeyEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && Mouse.RightButton == MouseButtonState.Released && Mouse.LeftButton == MouseButtonState.Released && Mouse.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -846,7 +846,7 @@ protected override void OnKeyUp(KeyEventArgs e)

/// <inheritdoc />
protected override void OnKeyDown(KeyEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <summary>
/// Determines whether any toggled interaction is currently in progress.
Expand Down
10 changes: 8 additions & 2 deletions Nodify/Interactivity/DragState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void TryHandleEvent(InputEventArgs e)
private void BeginDrag(InputEventArgs e)
{
// Avoid stealing mouse capture from other elements
if (Mouse.Captured == null || Element.IsMouseCaptured)
if (IsInputCaptured(e))
{
_interactionState = InteractionState.InProgress;
HandleEvent(e); // Handle the event, otherwise CaptureMouse will send a MouseMove event and the current event will be handled out of order
Expand All @@ -213,7 +213,7 @@ private void BeginDrag(InputEventArgs e)
}

Element.Focus();
Element.CaptureMouse();
CaptureInput(e);
}
}

Expand Down Expand Up @@ -256,6 +256,12 @@ private void CancelDrag(InputEventArgs e)

#endregion

protected virtual bool IsInputCaptured(InputEventArgs e)
=> Mouse.Captured == null || Element.IsMouseCaptured;

protected virtual void CaptureInput(InputEventArgs e)
=> Element.CaptureMouse();

protected virtual bool IsInputCaptureLost(InputEventArgs e)
{
return e.RoutedEvent == UIElement.LostMouseCaptureEvent;
Expand Down
2 changes: 1 addition & 1 deletion Nodify/Interactivity/InputProcessor.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static Shared()
}

public void HandleEvent(InputEventArgs e)
=> Process(e);
=> ProcessEvent(e);

/// <summary>
/// Registers a factory method for creating an input handler of the specified type.
Expand Down
2 changes: 1 addition & 1 deletion Nodify/Interactivity/InputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Clear()
/// Processes an input event and delegates it to the registered handlers.
/// </summary>
/// <param name="e">The input event arguments to process.</param>
public void Process(InputEventArgs e)
public void ProcessEvent(InputEventArgs e)
{
if (ProcessHandledEvents)
{
Expand Down
14 changes: 7 additions & 7 deletions Nodify/Minimap/Minimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ protected override bool IsItemItsOwnContainerOverride(object item)
protected override void OnMouseDown(MouseButtonEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnMouseUp(MouseButtonEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && e.RightButton == MouseButtonState.Released && e.LeftButton == MouseButtonState.Released && e.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -169,24 +169,24 @@ protected override void OnMouseUp(MouseButtonEventArgs e)
protected override void OnMouseMove(MouseEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
MouseLocation = e.GetPosition(ItemsHost);
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);
}

/// <inheritdoc />
protected override void OnLostMouseCapture(MouseEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <inheritdoc />
protected override void OnKeyUp(KeyEventArgs e)
{
InputProcessor.Process(e);
InputProcessor.ProcessEvent(e);

// Release the mouse capture if all the mouse buttons are released and there's no interaction in progress
if (IsMouseCaptured && Mouse.RightButton == MouseButtonState.Released && Mouse.LeftButton == MouseButtonState.Released && Mouse.MiddleButton == MouseButtonState.Released && !IsToggledInteractionInProgress())
Expand All @@ -197,7 +197,7 @@ protected override void OnKeyUp(KeyEventArgs e)

/// <inheritdoc />
protected override void OnKeyDown(KeyEventArgs e)
=> InputProcessor.Process(e);
=> InputProcessor.ProcessEvent(e);

/// <summary>
/// Determines whether any toggled interaction is currently in progress.
Expand Down
3 changes: 3 additions & 0 deletions Nodify/Nodes/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Nodify
/// </summary>
[TemplatePart(Name = ElementInputItemsControl, Type = typeof(ItemsControl))]
[TemplatePart(Name = ElementOutputItemsControl, Type = typeof(ItemsControl))]
[StyleTypedProperty(Property = nameof(ContentContainerStyle), StyleTargetType = typeof(Border))]
[StyleTypedProperty(Property = nameof(HeaderContainerStyle), StyleTargetType = typeof(Border))]
[StyleTypedProperty(Property = nameof(FooterContainerStyle), StyleTargetType = typeof(Border))]
public class Node : HeaderedContentControl
{
protected const string ElementInputItemsControl = "PART_Input";
Expand Down

0 comments on commit ff589bd

Please sign in to comment.