Quantcast
Viewing all articles
Browse latest Browse all 40524

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

For the record. In case it is usefull to anyone.

Header

class ROI : public ofBaseDraws, public ofRectangle {
public:
    ROI();
    ~ROI();
    void draw();
    
    ofParameterGroup parameters;
    ofParameter<float> posX;
    ofParameter<float> posY;
    ofParameter<float> width;
    ofParameter<float> height;
        
    void changeRoiX(float &posX);
    void changeRoiY(float &posY);
    void changeRoiWidth(float &width);
    void changeRoiHeight(float &height);
};

.cpp

#include "ROI.h"

ROI::ROI() {
    
    posX.addListener(this, &ROI::changeRoiX);
    posY.addListener(this, &ROI::changeRoiY);
    width.addListener(this, &ROI::changeRoiWidth);
    height.addListener(this, &ROI::changeRoiHeight);
    
    parameters.setName("ROI Settings");
    parameters.add(posX.set("position x", 0, 0, CAM_WIDTH));
    parameters.add(posY.set("position y", 0, 0, CAM_HEIGHT));
    parameters.add(width.set("width", 0, 0, CAM_WIDTH));
    parameters.add(height.set("height", 0, 0, CAM_HEIGHT));
    
}

ROI::~ROI() {
    posX.removeListener(this, &ROI::changeRoiX);
    posY.removeListener(this, &ROI::changeRoiY);
    width.removeListener(this, &ROI::changeRoiWidth);
    height.removeListener(this, &ROI::changeRoiHeight);
}

void ROI::draw() {
    ofPushMatrix();
    ofPushStyle();
    ofSetColor(255, 0, 0);
    ofNoFill();
    ofSetLineWidth(2);
    ofRect(*this);
    ofPopStyle();
    ofPopMatrix();
}
    
void ROI::changeRoiX(float &posX) {
    this->setX(posX);
}

void ROI::changeRoiY(float &posY) {
    this->setY(posY);
}

void ROI::changeRoiWidth(float &width) {
    this->setWidth(width);

}

void ROI::changeRoiHeight(float &height) {
    this->setHeight(height);
}

Viewing all articles
Browse latest Browse all 40524

Trending Articles