Skip to content

Commit a41072a

Browse files
Eiderenxen2
authored andcommitted
feat: Open event routing for multi-user interfaces
1 parent b7c7a45 commit a41072a

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

sources/engine/Stride.UI/KeyEventArgs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class KeyEventArgs : RoutedEventArgs
1313
/// <summary>
1414
/// The key that triggered the event.
1515
/// </summary>
16-
public Keys Key { get; internal set; }
16+
public Keys Key { get; init; }
1717

1818
/// <summary>
1919
/// A reference to the input system that can be used to check the status of the other keys.
2020
/// </summary>
21-
public InputManager Input { get; internal set; }
21+
public InputManager Input { get; init; }
2222
}
2323
}

sources/engine/Stride.UI/Rendering/UI/UIRenderFeature.Picking.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ private void UpdateTouchEvents(ref Viewport viewport, ref Matrix worldViewProj,
170170
// TODO: add the pointer type to the event args?
171171
var touchEvent = new TouchEventArgs
172172
{
173-
Action = TouchAction.Down,
173+
Action = pointerEvent.EventType switch
174+
{
175+
PointerEventType.Pressed => TouchAction.Down,
176+
PointerEventType.Moved => TouchAction.Move,
177+
PointerEventType.Released => TouchAction.Up,
178+
PointerEventType.Canceled => TouchAction.Move,
179+
_ => throw new ArgumentOutOfRangeException()
180+
},
174181
Timestamp = time,
175182
ScreenPosition = currentTouchPosition,
176183
ScreenTranslation = pointerEvent.DeltaPosition,
@@ -181,13 +188,10 @@ private void UpdateTouchEvents(ref Viewport viewport, ref Matrix worldViewProj,
181188
switch (pointerEvent.EventType)
182189
{
183190
case PointerEventType.Pressed:
184-
touchEvent.Action = TouchAction.Down;
185191
currentTouchedElement?.RaiseTouchDownEvent(touchEvent);
186192
break;
187193

188194
case PointerEventType.Released:
189-
touchEvent.Action = TouchAction.Up;
190-
191195
// generate enter/leave events if we passed from an element to another without move events
192196
if (currentTouchedElement != lastTouchedElement)
193197
ThrowEnterAndLeaveTouchEvents(currentTouchedElement, lastTouchedElement, touchEvent);
@@ -197,8 +201,6 @@ private void UpdateTouchEvents(ref Viewport viewport, ref Matrix worldViewProj,
197201
break;
198202

199203
case PointerEventType.Moved:
200-
touchEvent.Action = TouchAction.Move;
201-
202204
// first notify the move event (even if the touched element changed in between it is still coherent in one of its parents)
203205
currentTouchedElement?.RaiseTouchMoveEvent(touchEvent);
204206

@@ -208,8 +210,6 @@ private void UpdateTouchEvents(ref Viewport viewport, ref Matrix worldViewProj,
208210
break;
209211

210212
case PointerEventType.Canceled:
211-
touchEvent.Action = TouchAction.Move;
212-
213213
// generate enter/leave events if we passed from an element to another without move events
214214
if (currentTouchedElement != lastTouchedElement)
215215
ThrowEnterAndLeaveTouchEvents(currentTouchedElement, lastTouchedElement, touchEvent);

sources/engine/Stride.UI/TextEventArgs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ namespace Stride.UI
99
/// <summary>
1010
/// The arguments associated with a <see cref="TextInputEvent"/>
1111
/// </summary>
12-
internal class TextEventArgs : RoutedEventArgs
12+
public class TextEventArgs : RoutedEventArgs
1313
{
1414
/// <summary>
1515
/// The text that was entered
1616
/// </summary>
17-
public string Text { get; internal set; }
17+
public string Text { get; init; }
1818

1919
/// <summary>
2020
/// The type of text input event
2121
/// </summary>
22-
public TextInputEventType Type { get; internal set; }
22+
public TextInputEventType Type { get; init; }
2323

2424
/// <summary>
2525
/// Start of the current composition being edited
2626
/// </summary>
27-
public int CompositionStart { get; internal set; }
27+
public int CompositionStart { get; init; }
2828

2929
/// <summary>
3030
/// Length of the current part of the composition being edited
3131
/// </summary>
32-
public int CompositionLength { get; internal set; }
32+
public int CompositionLength { get; init; }
3333
}
34-
}
34+
}

sources/engine/Stride.UI/TouchEventArgs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@ public class TouchEventArgs : RoutedEventArgs
1515
/// <summary>
1616
/// Gets the time when this event occurred.
1717
/// </summary>
18-
public TimeSpan Timestamp { get; internal set; }
18+
public TimeSpan Timestamp { get; init; }
1919

2020
/// <summary>
2121
/// Gets the action that occurred.
2222
/// </summary>
23-
public TouchAction Action { get; internal set; }
23+
public TouchAction Action { get; init; }
2424

2525
/// <summary>
2626
/// Gets the position of the touch on the screen. Position is normalized between [0,1]. (0,0) is the left top corner, (1,1) is the right bottom corner.
2727
/// </summary>
28-
public Vector2 ScreenPosition { get; internal set; }
28+
public Vector2 ScreenPosition { get; init; }
2929

3030
/// <summary>
3131
/// Gets the translation of the touch on the screen since last triggered event (in normalized units). (1,1) represent a translation of the top left corner to the bottom right corner.
3232
/// </summary>
33-
public Vector2 ScreenTranslation { get; internal set; }
33+
public Vector2 ScreenTranslation { get; init; }
3434

3535
/// <summary>
3636
/// Gets the position of the touch in the UI virtual world space.
3737
/// </summary>
38-
public Vector3 WorldPosition { get; internal set; }
38+
public Vector3 WorldPosition { get; init; }
3939

4040
/// <summary>
4141
/// Gets the translation of the touch in the UI virtual world space.
4242
/// </summary>
43-
public Vector3 WorldTranslation { get; internal set; }
43+
public Vector3 WorldTranslation { get; init; }
4444
}
4545
}

sources/engine/Stride.UI/UIElement.Events.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,40 @@ public abstract partial class UIElement
1414
{
1515
#region Routed Events
1616

17-
private static readonly RoutedEvent<TouchEventArgs> PreviewTouchDownEvent =
17+
public static readonly RoutedEvent<TouchEventArgs> PreviewTouchDownEvent =
1818
EventManager.RegisterRoutedEvent<TouchEventArgs>("PreviewTouchDown", RoutingStrategy.Tunnel, typeof(UIElement));
1919

20-
private static readonly RoutedEvent<TouchEventArgs> PreviewTouchMoveEvent =
20+
public static readonly RoutedEvent<TouchEventArgs> PreviewTouchMoveEvent =
2121
EventManager.RegisterRoutedEvent<TouchEventArgs>("PreviewTouchMove", RoutingStrategy.Tunnel, typeof(UIElement));
2222

23-
private static readonly RoutedEvent<TouchEventArgs> PreviewTouchUpEvent =
23+
public static readonly RoutedEvent<TouchEventArgs> PreviewTouchUpEvent =
2424
EventManager.RegisterRoutedEvent<TouchEventArgs>("PreviewTouchUp", RoutingStrategy.Tunnel, typeof(UIElement));
2525

26-
private static readonly RoutedEvent<TouchEventArgs> TouchDownEvent =
26+
public static readonly RoutedEvent<TouchEventArgs> TouchDownEvent =
2727
EventManager.RegisterRoutedEvent<TouchEventArgs>("TouchDown", RoutingStrategy.Bubble, typeof(UIElement));
2828

29-
private static readonly RoutedEvent<TouchEventArgs> TouchEnterEvent =
29+
public static readonly RoutedEvent<TouchEventArgs> TouchEnterEvent =
3030
EventManager.RegisterRoutedEvent<TouchEventArgs>("TouchEnter", RoutingStrategy.Direct, typeof(UIElement));
3131

32-
private static readonly RoutedEvent<TouchEventArgs> TouchLeaveEvent =
32+
public static readonly RoutedEvent<TouchEventArgs> TouchLeaveEvent =
3333
EventManager.RegisterRoutedEvent<TouchEventArgs>("TouchLeave", RoutingStrategy.Direct, typeof(UIElement));
3434

35-
private static readonly RoutedEvent<TouchEventArgs> TouchMoveEvent =
35+
public static readonly RoutedEvent<TouchEventArgs> TouchMoveEvent =
3636
EventManager.RegisterRoutedEvent<TouchEventArgs>("TouchMove", RoutingStrategy.Bubble, typeof(UIElement));
3737

38-
private static readonly RoutedEvent<TouchEventArgs> TouchUpEvent =
38+
public static readonly RoutedEvent<TouchEventArgs> TouchUpEvent =
3939
EventManager.RegisterRoutedEvent<TouchEventArgs>("TouchUp", RoutingStrategy.Bubble, typeof(UIElement));
4040

41-
private static readonly RoutedEvent<KeyEventArgs> KeyPressedEvent =
41+
public static readonly RoutedEvent<KeyEventArgs> KeyPressedEvent =
4242
EventManager.RegisterRoutedEvent<KeyEventArgs>("KeyPressed", RoutingStrategy.Bubble, typeof(UIElement));
4343

44-
private static readonly RoutedEvent<KeyEventArgs> KeyDownEvent =
44+
public static readonly RoutedEvent<KeyEventArgs> KeyDownEvent =
4545
EventManager.RegisterRoutedEvent<KeyEventArgs>("KeyDown", RoutingStrategy.Bubble, typeof(UIElement));
4646

47-
private static readonly RoutedEvent<KeyEventArgs> KeyReleasedEvent =
47+
public static readonly RoutedEvent<KeyEventArgs> KeyReleasedEvent =
4848
EventManager.RegisterRoutedEvent<KeyEventArgs>("KeyReleased", RoutingStrategy.Bubble, typeof(UIElement));
4949

50-
private static readonly RoutedEvent<TextEventArgs> TextInputEvent =
50+
public static readonly RoutedEvent<TextEventArgs> TextInputEvent =
5151
EventManager.RegisterRoutedEvent<TextEventArgs>("TextInput", RoutingStrategy.Bubble, typeof(UIElement));
5252

5353
#endregion

0 commit comments

Comments
 (0)