Extending GamepadTrigger::OnButtonPress to conditionally handle events
Hello!
I'm currently attempting to extend the default GamepadTrigger behavior so that OnButtonPress will handle the associated event:
However, as noted in the code comment above, I'd like to only handle the event if the associated action was actually invoked in InvokeActions. InvokeActions performs a check to only actually call invoke on the associated actions if mPreviewInvoke does not set the PreviewInvokeEventArgs to 'cancelling = true'. For example, in the case where the GamepadTrigger has a ConditionalBehavior associated with it that is not satisfied in the given context, the call to InvokeActions would not actually perform the actions associated with the trigger.
However, InvokeActions does not return anything to indicate whether the associated actions were actually performed or not, so I'm not sure the best way to know in OnButtonPress whether the actions were performed - essentially, do you have any recommendations on replicating this code from InvokeActions within OnButtonPress/my GamepadTrigger class:
Any help would be appreciated!
I'm currently attempting to extend the default GamepadTrigger behavior so that OnButtonPress will handle the associated event:
Code: Select all
if (GetButton() == (GamepadButton)(e.originalKey - Noesis::Key_GamepadLeft))
{
InvokeActions(0);
// need logic here to only change e.handled if actions were actually invoked in InvokeActions
e.handled = true;
}
However, InvokeActions does not return anything to indicate whether the associated actions were actually performed or not, so I'm not sure the best way to know in OnButtonPress whether the actions were performed - essentially, do you have any recommendations on replicating this code from InvokeActions within OnButtonPress/my GamepadTrigger class:
Code: Select all
PreviewInvokeEventArgs args; args.cancelling = false;
mPreviewInvoke(this, args);
if (!args.cancelling)
{}
-
-
sfernandez
Site Admin
- Posts: 2866
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
Hello,
You can hook to the PreviewInvoke event too, so you can check if it was cancelled or not:
Hope this helps.
You can hook to the PreviewInvoke event too, so you can check if it was cancelled or not:
Code: Select all
void GamepadTrigger::OnButtonPress(Noesis::BaseComponent*, const Noesis::KeyEventArgs& e)
{
if (GetButton() == (GamepadButton)(e.originalKey - Noesis::Key_GamepadLeft))
{
bool invoked = false;
auto OnPreviewInvoke = [&invoked](Noesis::BaseComponent*, const PreviewInvokeEventArgs& e)
{
invoked = !e.cancelling;
};
PreviewInvoke() += OnPreviewInvoke;
InvokeActions(0);
PreviewInvoke() -= OnPreviewInvoke;
e.handled = invoked;
}
}
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
This worked perfectly! Thanks for the help!
-
-
sfernandez
Site Admin
- Posts: 2866
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
You're welcome, marking this as solved.
-
- christyjquinn
- Posts: 17
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
Sorry to comment on a solved thread but I'm wanting to do a similar thing and just wondered what the background was for GamepadTrigger and KeyTrigger not setting handled to true by default?
-
-
sfernandez
Site Admin
- Posts: 2866
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
We were just following the official implementation by Microsoft of KeyTrigger: https://github.com/microsoft/XamlBehavi ... Trigger.cs
And there might be situations where you want to listen to some key to fire an interactivity action (play an animation or sound for example), but still want to route the key event.
And there might be situations where you want to listen to some key to fire an interactivity action (play an animation or sound for example), but still want to route the key event.
-
- christyjquinn
- Posts: 17
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
Thanks that makes sense. The actual use case we have is the same as what is in the documentation being calling a close command in response to "Cancel". In this case handled should be set to true to avoid any further bubbling, is your suggestion to do something like above by extending GamepadTrigger or is there another approach maybe using code behind?
-
-
sfernandez
Site Admin
- Posts: 2866
- Joined:
Re: Extending GamepadTrigger::OnButtonPress to conditionally handle events
All the interactivity package comes with source code because we expect customers to fine-tune it to their needs or just use it as base to create their own required triggers, actions and behaviors.
In your case I would probably extend the GamepadTrigger with a new property to indicate if the trigger should handle the key event when it is executed (with a similar code as I proposed before). That way the trigger can be used in scenarios requiring the event to bubble up and others where you want to stop the routing.
Anyway, I'm thinking that as GamepadTrigger is a Noesis extension, we can expose that property in our implementation. Could you please create a feature request for this in our bugtracker?
In your case I would probably extend the GamepadTrigger with a new property to indicate if the trigger should handle the key event when it is executed (with a similar code as I proposed before). That way the trigger can be used in scenarios requiring the event to bubble up and others where you want to stop the routing.
Anyway, I'm thinking that as GamepadTrigger is a Noesis extension, we can expose that property in our implementation. Could you please create a feature request for this in our bugtracker?
Who is online
Users browsing this forum: Bing [Bot] and 2 guests