Quantcast
Viewing all articles
Browse latest Browse all 40524

[SOLVED] Using ofParameter to modify ofRect within a class with Gui

a simpler way to do it would be something like:

class ROI {
public:
    void draw(){
        ofDrawRectangle(getRectangle());
    }

    ofRectangle getRectangle(){
        return ofRectangle(x,y,width,height);
    }
    
    ofParameter<float> x{"x",0,0,MAX_W};
    ofParameter<float> y{"y",0,0,MAX_H};
    ofParameter<float> width{"width",0,0,MAX_W};
    ofParameter<float> height{"height",0,0,MAX_H};
    ofParameterGroup parameters{
         "roi parameters",
         x, y, width, height,
    };
};

that syntax to initialize the parameters in the header will only work in 0.9 but you can just initialize them in the constructor if you are using 0.8.4

That way you avoid having to use the events.

If you don't want to call getRectangle() you can also overload the cast operator:

operator ofRectangle(){
    return ofRectangle(x,y,width,height);
}

and then you can use an instance of ROI as if it was an ofRectangle


Viewing all articles
Browse latest Browse all 40524

Trending Articles