Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose binding #906

Merged
merged 35 commits into from
Nov 16, 2022
Merged

Expose binding #906

merged 35 commits into from
Nov 16, 2022

Conversation

dlyr
Copy link
Contributor

@dlyr dlyr commented Apr 12, 2022

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Expose binding in KeyMappingManager, so client code can inspect and manage binding.

  • What is the current behavior? (You can also link to an open issue here)
    No access to binding.

  • What is the new behavior (if this is a feature change)?
    Nothing changes, this will allow to have better event management, like the one done for custom event in viewer, for all kind of event.

Todo in an upcomming PR: update viewer event handling with something like (example code adapted from WIP ...)

void Viewer::setupActionCallbacks() {
    setupActionCallback("ACTION_NAME", [this]( QEvent* e ) {
        if ( e->eventType() == QEvent::QPress ) { /* key press action */ }
    } );
}

void Viewer::setupActionCallback( std::string actionName,
                                    std::function<void( QKeyEvent* )> callback ) {
    auto keyMappingManager = KeyMappingManager::getInstance();
    auto context           = thisKeyMapping::getContext();
    auto actionIndex       = keyMappingManager->getActionIndex( context, actionName );
    auto binding           = keyMappingManager->getBinding( context, actionIndex );
    if ( binding )
    {
        if ( binding->isKeyEvent() )
        {
            m_customActions[KeyEventType::KeyPressed].insert( { actionIndex, callback } );
            m_customActions[KeyEventType::KeyReleased].insert( { actionIndex, callback } );
        }
        if ( binding->isMouseEvent() )
        {
            m_customActions[KeyEventType::MousePressed].insert( { actionIndex, callback } );
            m_customActions[KeyEventType::MouseMoved].insert( { actionIndex, callback } );
            m_customActions[KeyEventType::MouseReleased].insert( { actionIndex, callback } );
        }
        if ( binding->isWheelEvent() )
        {
            m_customActions[KeyEventType::WheelActivated].insert( { actionIndex, callback } );
        }
    }
    else
    { LOG( logERROR ) << "setupActionCallback: binding not found for  " << actionName; }
}
  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    No

@dlyr dlyr added enhancement Type of issue/PR: enhancement GUI Related to Ra::Gui labels Apr 12, 2022
@dlyr dlyr requested a review from MathiasPaulin April 12, 2022 10:40
@dlyr dlyr changed the base branch from master to release-candidate April 12, 2022 10:41
@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #906 (3185b50) into release-candidate (af38ec3) will decrease coverage by 0.47%.
The diff coverage is 48.98%.

❗ Current head 3185b50 differs from pull request most recent head 6497844. Consider uploading reports for the commit 6497844 to get more accurate results

@@                  Coverage Diff                  @@
##           release-candidate     #906      +/-   ##
=====================================================
- Coverage              44.51%   44.04%   -0.48%     
=====================================================
  Files                    337      336       -1     
  Lines                  22477    22430      -47     
=====================================================
- Hits                   10006     9879     -127     
- Misses                 12471    12551      +80     
Impacted Files Coverage Δ
src/Gui/Viewer/CameraManipulator.hpp 0.00% <ø> (ø)
src/Gui/Viewer/FlightCameraManipulator.cpp 0.00% <0.00%> (ø)
src/Gui/Viewer/Gizmo/GizmoManager.cpp 0.00% <ø> (ø)
src/Gui/Viewer/RotateAroundCameraManipulator.cpp 0.00% <ø> (ø)
src/Gui/Viewer/TrackballCameraManipulator.cpp 0.00% <0.00%> (ø)
src/Gui/Viewer/Viewer.cpp 0.00% <0.00%> (ø)
src/Gui/Viewer/Viewer.hpp 0.00% <ø> (ø)
src/Gui/Utils/KeyMappingManager.inl 26.92% <26.92%> (ø)
src/Gui/Utils/KeyMappingManager.cpp 82.02% <84.21%> (+5.28%) ⬆️
src/Gui/Utils/KeyMappingManager.hpp 100.00% <100.00%> (ø)
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

src/Gui/Utils/KeyMappingManager.hpp Outdated Show resolved Hide resolved
src/Gui/Utils/KeyMappingManager.hpp Outdated Show resolved Hide resolved
@dlyr
Copy link
Contributor Author

dlyr commented Apr 13, 2022

On second thought, the callback collection could also be on the KeyMappingManager side. With current proposed code, handle event is

    auto actionPainty = keyMap->getAction( thisKeyMapping::getContext(), buttons, modifiers, key );
    auto itr          = m_customActions[KeyEventType::KeyPressed].find( actionPainty );

    if ( itr != m_customKeyActions[KeyEventType::KeyPressed].end() )
    {
        itr->second( event );
        return true;
    }

I can try to have setup like

void Viewer::setupActionCallbacks() {
     auto keyMappingManager = KeyMappingManager::getInstance(); 
     keyMappingManager->setupActionCallback(thisKeyMapping::getContext(), "ACTION_NAME", [this]( QEvent* e ) {
        if ( e->eventType() == QEvent::QPress ) { /* key press action */ }
    } );
}

And handle event could be

    auto actionTriggered = keyMap->triggerAction( thisKeyMapping::getContext(), buttons, modifiers, key );
    if( !actrionTriggered) {
        // try another context
    }

@MathiasPaulin
Copy link
Contributor

On second thought, ...

I find this second option, with the callback collection on the KeyMappingManager side, quite better.
It simplifies the Viewer code (no need to manage callbacks collection) and is rather compact for configuration and handling.
Do you add it in this PR or do you open an issue to keep track of the discussion ?

@dlyr
Copy link
Contributor Author

dlyr commented Apr 13, 2022

In this PR, later

@dlyr dlyr marked this pull request as draft April 13, 2022 12:30
@dlyr
Copy link
Contributor Author

dlyr commented Apr 24, 2022

This PR will closes #793

@dlyr
Copy link
Contributor Author

dlyr commented Jun 22, 2022

I've done some test ... but it's not as versatile as before.
For instance, for TrackballCameraManipulator, the manipulator register its callback to the keymappingmanager.
But this means only instance of TrackballCameraManipulator should have registered its callbacks at some point ... and I'm not sure how to unregister the callback.
See current code version (last commits) to discuss.

@dlyr
Copy link
Contributor Author

dlyr commented Oct 4, 2022

Question here, currently keymapping configuration file is stored as a QDomDocument during loading, and updated when one adds new binding, so that when saved, the dom document contains loaded + added actions.
I'm working on a writer that use actual binding data (from the keymappingmanager's maps) to save the configuration file.
The main difference is that loaded file is lost, with it's optionnal comments, and anything not related to keymapping, and the saved file node order might change.
I think it's cleaner, but I'm open to feedback.

@nmellado
Copy link
Contributor

nmellado commented Oct 4, 2022

I guess the question is: do we want to have persistent comments in this file ?
I would be tempted to say that we don't, and I would go even further: in most cases, users will never open this file (and if they do, they know what they are doing ;) ).
So we can do whatever with this file, even changing the action order.

In the long term, it would be beneficial to have an UI to edit this file.

@dlyr dlyr marked this pull request as ready for review October 4, 2022 19:08
@dlyr dlyr requested review from nmellado and MathiasPaulin October 4, 2022 19:08
Copy link
Contributor

@MathiasPaulin MathiasPaulin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how everything work nor if the proposal is the right way to do that but it seems to allow finer customization of the gui event processing system. So, if others approve, I'll do not argue against their decision. I've just a concern on what seems to me to be a strong limitation as custom binding (at least as done in the EntityAnimationDemo, which is the only demo to rely on numeric-key events ) seems to be dependent of the langage (or configuration) of the keyboard.

doc/developer/keymapping.md Outdated Show resolved Hide resolved
doc/developer/keymapping.md Outdated Show resolved Hide resolved
doc/developer/keymapping.md Outdated Show resolved Hide resolved
doc/developer/keymapping.md Outdated Show resolved Hide resolved
examples/EntityAnimation/main.cpp Outdated Show resolved Hide resolved
src/Gui/Viewer/Viewer.cpp Show resolved Hide resolved
Copy link
Contributor

@nmellado nmellado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge, please update wrt to release_candidate.
Thanks !

dlyr and others added 2 commits November 16, 2022 08:18
dlyr added 26 commits November 16, 2022 08:18
remove unused ref (input version only is used)
Adds EventBinding factory, and remove meta enum data member.
bindKeyToAction -> setActionBinding

m_mappingAction -> m_bindingToAction
@dlyr dlyr merged commit 898c1be into STORM-IRIT:release-candidate Nov 16, 2022
@dlyr dlyr deleted the exposeBinding branch November 16, 2022 08:38
ntsh-oni pushed a commit to ntsh-oni/Radium-Engine that referenced this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type of issue/PR: enhancement GUI Related to Ra::Gui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants