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

Prevent mouse event propagation #50

Closed
dionysiusmarquis opened this issue Mar 17, 2016 · 2 comments
Closed

Prevent mouse event propagation #50

dionysiusmarquis opened this issue Mar 17, 2016 · 2 comments

Comments

@dionysiusmarquis
Copy link

Hi,

if you're using ofxDatGui with the default openFrameworks camera the mouse events are bubling through. Because of that you will still control the camera rotation while changing a slider value for example.

My current "hack" is this:

ofAddListener(ofEvents().mousePressed, this, &myClass::mousePressed, OF_EVENT_ORDER_BEFORE_APP);

bool myClass::mousePressed(ofMouseEventArgs &mouse) {
    float width = this->getWidth();
    float height = footer->getY() + footer->getHeight();

    float x = this->getPosition().x;
    float y = this->getPosition().y;

    return (mouse.x >= x && mouse.x <= x + width && mouse.y >= y && mouse.y <= y + height);
}

It uses the footer to determine the current menu size.

Maybe there could be a native option to prevent mouse event bubbling.

@dionysiusmarquis dionysiusmarquis changed the title Prevent mouse events propagation Prevent mouse event propagation Mar 17, 2016
braitsch added a commit that referenced this issue Mar 19, 2016
@braitsch
Copy link
Owner

This has come up before so I just added a gui->isMouseDown() method which will return true if the mouse is pressed on an interactive area of a component. You can use this to prevent mouse events from penetrating through the gui (which now detects events before the app) via the following:

void ofApp::update()
{
    if (ofGetMousePressed() && gui->getMouseDown() == false){
        // let the app handle the mouse event //
    }
}

Also just FYI guis have a getHeight() method in addition to getWidth() so you shouldn't have to rely on the footer to calculate a gui's height.

Let me know if this helps.

@marc-antimodular
Copy link

marc-antimodular commented Nov 22, 2017

My simple solution, for active controls:

void ofApp::update(){
    if ( gui->getMouseDown() )
        camera.disableMouseInput();
    else
        camera.enableMouseInput();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants