how to set the mouse position in a GUI addons

637 views Asked by At

I'm developping an interface, but I'm new at openframeworks and I need a library function similiar to processing's controlP5's cp5.getPointer().set(mouseX, mouseY); in order to set the mouse position in relation to the graphic interface. Does anyone know of a way of doing that directly on openframes or any addons with the same function?

I've gone through some questions about mouse position setting, like this one: http://forum.openframeworks.cc/t/how-to-set-mouse-position/1438 but it's not what I'm looking for because I don't want to change the position of the mouse in relation to openframeworks, I just want to modify this information in relation to the library, so I can control it's buttons and gui elements.

Thanks in advance.

1

There are 1 answers

0
Levko Ivanchuk On

Since no specific GUI addon was mentioned (like ofxUI), I will assume you are using standard GUI addon called ofxGui, which comes with OpenFrameworks pre-installed.

Unfortunately, openFrameworks mouse coordinates are the same for both GUI and the drawing space. Therefore, there is no function to modify the mouse coordinates when mouse pointer is on top of a GUI element, which is what I think you're trying to do. It doesn't seem to be the case, at least for me, to easily detect if a mouse point is inside a GUI element. Of course, what you can do is the following:

void ofApp:mouseMoved(int x, int y){
    ofRectangle shape = testGUI.getShape();

    if(shape.inside(x,y))
        //modify x,y to suit your needs, do other stuff, etc...
}

Method .getShape() is inherited all the way from ofxBaseGui, so it can be applied to any ofxGui element.

Also, be sure to check ofxUI. In my humble opinion, it is a much more robust GUI library for openFrameworks.

Hope this helps.