Quantcast
Viewing all articles
Browse latest Browse all 40524

Vector of ofxMSAInteractiveObject

Hi!

I'm trying to make a menu with buttons using the ofxMSAInteractiveObject addon, and the buttons using images that will be inside a folder. I'm using a vector, since the number of buttons will be according to the number of images that are in the folder. I created a new class extented ofxInteractiveObject:

class Botao : public ofxMSAInteractiveObject {
    public:
          ofBaseDraws    *content;
    
          Botao() {
              content = NULL;
          }
    
          void draw() {  
              if(content) {  
                  width = content->getWidth();  
                  height = content->getHeight();  
                  content->draw(x, y, width, height);  
              }

          void onPress(int x, int y, int button){
              cout << "click!" << endl;
          }
};

In ofApp.h:

class ofApp : public ofBaseApp {
   ...
   vector<ofxInteractiveObject> objVector;
   vector<ofImage> imagensVector;
}

In ofApp.cpp:

void ofApp::setup() {

    ofDirectory dir("images/");
    dir.listDir();
    for (unsigned int i = 0; i < dir.size(); i++) {
        ofImage img;
        img.load(dir.getPath(i));
        imagensVector.push_back(img);
    }

    for (int i = 0; i < imagensVector.size(); i++){
        Botao botao;
        botao.content = &imagensVector[i];
        botao.setPosition( (i*70)+40, 100 );
        botao.setSize(50, 40);
        botao.enableMouseEvents();

        objVector.push_back(botao);
    }
}

But this does not work! Why? If I declare a single Botao, he draws and events works like a charm.
Is there a better way to do this? Thanks in advance.

obs: I using vector<ofImage> because I will need them later.


Viewing all articles
Browse latest Browse all 40524

Trending Articles