My favorites | Sign in
Project Logo
                
Search
for
Updated Oct 15, 2008 by memosan
Labels: Featured
ofxMSAInteractiveObject  

The basic idea is to extend ofxMSAInteractiveObject and inherit a bunch of its functionality in your object. Once you extend it, you can override all or any of the virtual functions you see below and they will be called automatically. And you can also call methods like isMouseOver(), isMouseDown() etc.

One thing to look out for, if your object is moving, you need to call checkForMotion() in your update() function for the mouse events to function correctly. This is because at the moment I cannot register two update callbacks. Maybe with a future version poco/oF.

Check the sample files that come with the zip (make sure you have your console on to see all the printfs).

   void enableMouseEvents();            // call this if object should receive mouse events
    void disableMouseEvents();            // call this if object doesn't need to receive mouse events (default)

    void enableKeyEvents();                // call this if object should receive key events
    void disableKeyEvents();            // call this if object doesn't need to receive key events (default)

    void enableAppEvents();                // call this if object should update/draw automatically    (default)
    void disableAppEvents();            // call this if object doesn't need to update/draw automatically

    void setPos(float _x, float _y);        // set position of object
    void setSize(float _w, float _h);        // set size of object

    void setPosAndSize(float _x, float _y, float _w, float _h);        // set pos and size

    bool isMouseOver();                    // returns true if mouse is over object (based on position and size)
    bool isMouseDown();                    // returns true if mouse button is down and over object (based on position and size)
    int  getMouseX();                    // returns mouse X (in screen coordinates)
    int  getMouseY();                    // returns mouse Y (in screen coordinates)
    int  getLastMouseButton();            // returns last mouse button to have activity

    bool hitTest(int tx, int ty);        // returns true if given (x, y) coordinates (in screen space) are over the object (based on position and size)

    void checkForMotion();                // if your object is moving, this needs to be called in the update function for onRollOver, onRollOut callbacks to operate correctly

    void killMe();                        // if your object is a pointer, and you are done with it, call this

    // extend ofxMSAInteractiveObject and override any of the following methods
    virtual void setup() {}
    virtual void update() {}
    virtual void draw() {}
    virtual void exit() {}

    virtual void onRollOver(int x, int y) {}
    virtual void onRollOut() {}
    virtual void onMouseMove(int x, int y) {}
    virtual void onDragOver(int x, int y, int button) {}
    virtual void onPress(int x, int y, int button) {}
    virtual void onRelease(int x, int y, int button) {}
    virtual void onReleaseOutside(int x, int y, int button)    {}

Sign in to add a comment
Hosted by Google Code