Skip to content

Commit

Permalink
Merge pull request #41 from exomia/development
Browse files Browse the repository at this point in the history
v1.5.3
  • Loading branch information
baetz-daniel committed Feb 24, 2021
2 parents 77b3cee + c0988c2 commit 2338ec1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Exomia.Framework/Game/Camera/Camera3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public void Update(GameTime gameTime)
/// true if the instance is already disposed; false otherwise
/// </summary>
private bool _disposed;

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged/managed resources.
/// </summary>
Expand Down
17 changes: 15 additions & 2 deletions src/Exomia.Framework/Game/Camera/Controller/RotationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public sealed class RotationController : ICameraComponent, IInitializableCameraC
/// <inheritdoc />
public string Name { get; }

/// <summary>
/// Gets or sets the position the <see cref="IInputHandler"/> should be using while registering the callbacks.
/// </summary>
/// <remarks>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a negative index inserts the handler from the back
/// </para>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a positive index inserts the handler from the start
/// </para>
/// </remarks>
public int InputHandlerInsertPosition { get; set; } = -1;

/// <summary>
/// Initializes a new instance of the <see cref="RotationController" /> class.
/// </summary>
Expand Down Expand Up @@ -90,13 +103,13 @@ void IUpdateableCameraComponent.Update(GameTime gameTime, ICamera camera)
/// <inheritdoc />
void IInputHandler.RegisterInput(IInputDevice device)
{
device.RegisterRawMouseInput(CameraOnRawMouseInput);
device.RegisterRawMouseInput(CameraOnRawMouseInput, InputHandlerInsertPosition);
}

/// <inheritdoc />
void IInputHandler.UnregisterInput(IInputDevice device)
{
device.RegisterRawMouseInput(CameraOnRawMouseInput);
device.UnregisterRawMouseInput(CameraOnRawMouseInput);
}

private EventAction CameraOnRawMouseInput(in MouseEventArgs mouseEventArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public sealed class TranslationKeyboardController : ICameraComponent, IUpdateabl
/// <inheritdoc />
public string Name { get; }

/// <summary>
/// Gets or sets the position the <see cref="IInputHandler"/> should be using while registering the callbacks.
/// </summary>
/// <remarks>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a negative index inserts the handler from the back
/// </para>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a positive index inserts the handler from the start
/// </para>
/// </remarks>
public int InputHandlerInsertPosition { get; set; } = -1;

/// <summary>
/// Initializes a new instance of the <see cref="TranslationKeyboardController" /> class.
/// </summary>
Expand All @@ -42,8 +55,8 @@ public TranslationKeyboardController(string name)
/// <inheritdoc />
void IInputHandler.RegisterInput(IInputDevice device)
{
device.RegisterKeyDown(CameraOnKeyDown);
device.RegisterKeyUp(CameraOnKeyUp);
device.RegisterKeyDown(CameraOnKeyDown, InputHandlerInsertPosition);
device.RegisterKeyUp(CameraOnKeyUp, InputHandlerInsertPosition);
}

/// <inheritdoc />
Expand Down
17 changes: 15 additions & 2 deletions src/Exomia.Framework/Game/RenderForm.InputDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,21 @@ public Pipe()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Register(in TDelegate handler, int position = -1)
{
if (position == -1) { _list.Add(handler); }
else { _list.Insert(position >= 0 ? position : _list.Count + position, handler); }
if (position >= 0 && position < _list.Count)
{
_list.Insert(position, handler);
}
else if (position < 0)
{
_list.Insert(
_list.Count + position >= 0
? _list.Count + position
: 0, handler);
}
else
{
_list.Add(handler);
}
}

/// <summary>
Expand Down
36 changes: 24 additions & 12 deletions src/Exomia.Framework/UI/UiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public sealed class UiManager : IComponent, IInitializable, IDrawable, IDisposab
/// Occurs when the <see cref="Visible" /> property changes.
/// </summary>
public event EventHandler? VisibleChanged;

/// <summary>
/// Flag to identify, if the component is already initialized.
/// </summary>

private bool _isInitialized;

private readonly DisposeCollector _collector;
Expand Down Expand Up @@ -89,6 +86,19 @@ public bool Visible
}
}

/// <summary>
/// Gets or sets the position the <see cref="IInputHandler"/> should be using while registering the callbacks.
/// </summary>
/// <remarks>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a negative index inserts the handler from the back
/// </para>
/// <para>
/// e.g. <see cref="IInputDevice.RegisterRawKeyEvent" /> a positive index inserts the handler from the start
/// </para>
/// </remarks>
public int InputHandlerInsertPosition { get; set; } = 0;

/// <summary>
/// Gets the input handler.
/// </summary>
Expand All @@ -115,13 +125,13 @@ public UiManager(string name)

void IInputHandler.RegisterInput(IInputDevice device)
{
device.RegisterMouseMove(MouseMove);
device.RegisterMouseDown(MouseDown);
device.RegisterMouseUp(MouseUp);
device.RegisterMouseMove(MouseMove, InputHandlerInsertPosition);
device.RegisterMouseDown(MouseDown, InputHandlerInsertPosition);
device.RegisterMouseUp(MouseUp, InputHandlerInsertPosition);

device.RegisterKeyDown(KeyDown);
device.RegisterKeyUp(KeyUp);
device.RegisterKeyPress(KeyPress);
device.RegisterKeyDown(KeyDown, InputHandlerInsertPosition);
device.RegisterKeyUp(KeyUp, InputHandlerInsertPosition);
device.RegisterKeyPress(KeyPress, InputHandlerInsertPosition);
}

void IInputHandler.UnregisterInput(IInputDevice device)
Expand Down Expand Up @@ -179,9 +189,10 @@ void IDrawable.EndDraw() { }
/// <summary>
/// Adds the <paramref name="control" /> to this ui manger.
/// </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="control"> The control to add. </param>
/// <returns>The <paramref name="control"/></returns>
public Control Add(Control control)
public T Add<T>(T control) where T : Control
{
if (control.GetUiManager() != null || control._parent != null)
{
Expand All @@ -207,11 +218,12 @@ public Control Add(Control control)
/// <summary>
/// Removes the given <paramref name="control" /> from this ui manager.
/// </summary>
/// <typeparam name="T"> Generic type parameter. </typeparam>
/// <param name="control"> The control to remove. </param>
/// <param name="dispose"> True to dispose the control after removing. </param>
/// <returns>The <paramref name="control"/></returns>
/// <exception cref="InvalidOperationException"> Thrown when the requested operation is invalid. </exception>
public Control Remove(Control control, bool dispose = false)
public T Remove<T>(T control, bool dispose = false) where T : Control
{
if (control._parent != null)
{
Expand Down

0 comments on commit 2338ec1

Please sign in to comment.