Thanks Arturo!
Your info was really good; I am actually in need of using vectors for my project. So thanks to your tip I got it working.
The trickiest part is the declaration of the vector, and its implementation:
//declaration:
std::vector<eventSender*> objectArray;
//creation of the objects inside the vector, and the activation of their event listeners:
for(int i = 0 ; i<10; i++) {
objectArray.push_back(new eventSender(100+60*i,100,30,i));
objectArray[i]->enable();
ofAddListener(objectArray[i]->sendValue,this,&testApp::receiveValue);
}
I decided to post the code in case somebody finds him/herself in the same situation as I was today…
Thanks again, and wow, the poco events are really amazing once you get the grasp of it…
Cheers!
Rodrigo
code:
class declaration:
class eventSender{
public:
eventSender(int _x, int _y, int _s, int _id) {
x=_x;
y=_y;
s=_s;
id=_id;
}
void draw() {
ofCircle(x,y,s);
}
int x,y,s,id;
void enable(){
ofAddListener(ofEvents.mouseMoved, this, &eventSender::mouseMoved);
}
void mouseMoved(ofMouseEventArgs & args) {
int d = sqrt(pow(x-args.x,2)+pow(y-args.y,2));
if(d<s)
ofNotifyEvent(sendValue,id,this);
}
ofEvent<int> sendValue;
};
testApp.h:
#ifndef _TEST_APP
#define _TEST_APP
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void receiveValue(int & i);
std::vector<eventSender*> objectArray;
string msg;
};
#endif
testApp.cpp:
#include "testApp.h"
#include "Poco/Delegate.h"
#include "Poco/Timestamp.h"
//--------------------------------------------------------------
void testApp::setup(){
for(int i = 0 ; i<10; i++) {
objectArray.push_back(new eventSender(100+60*i,100,30,i));
objectArray[i]->enable();
ofAddListener(objectArray[i]->sendValue,this,&testApp::receiveValue);
}
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
ofDrawBitmapString(msg,20,20);
for(int i=0; i<objectArray.size(); i++)
objectArray[i]->draw();
}
//--------------------------------------------------------------
void testApp::receiveValue(int & i){
msg = "valueReceived: " + ofToString(i);
}