elliotwoods / ofxCvGui

Panel based GUI library with DOM-like features for openFrameworks
http://www.kimchiandchips.com
32 stars 10 forks source link

keyReleased not working #25

Open antimodular opened 5 years ago

antimodular commented 5 years ago

I am using the 3D world panel inside the ofxCeres example. I am noticing that i can press h to move the world around but releasing h does not bring it back to mouse rotation mode. Placed a bunch of ofLog() and noticed that keyReleased never is called.

Also noticed in this line that it probably should say

ofArgs.type = ofKeyEventArgs::Type::Released;

https://github.com/elliotwoods/ofxCvGui/blob/master/src/ofxCvGui/Panels/World.cpp#L99

antimodular commented 5 years ago

Also had to add the following. Now it works.

    void Controller::keyReleased(ofKeyEventArgs & args) {
        if (!this->rootGroup) {
            return;
        }
        auto currentPanel = this->currentPanel.lock();
        KeyboardArguments action(args, KeyboardArguments::Released, currentPanel);
        if (this->activeDialog) {
//            if (args.key == OF_KEY_ESC) {
//                this->closeActiveDialog();
//            }
//            else {
                this->activeDialog->keyboardAction(action);
//            }
        }
        else {
            if (this->maximised) {
                //if something is maximised, only it get the key press
                currentPanel->keyboardAction(action);
            }
            else {
                //otherwise everything visible gets the key press
                rootGroup->keyboardAction(action);
            }
        }
    }

plus add and remove listeners

 ofAddListener(ofEvents().keyReleased, this, &Controller::keyReleased);