#pragma once
#include "ofMain.h"
class ofApp : 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 dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofVec2f pos;
ofVec2f size;
bool positionIn;
ofEvent<bool> inSide;
void onRect( bool & e );
};
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofRectangle test;
pos = ofVec2f( 300, 300 );
size = ofVec2f( 200, 200 );
ofAddListener(inSide, this, &ofApp::onRect);
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
if (positionIn) {
ofSetColor(255,0,0);
} else {
ofSetColor(0,0,255);
}
ofRect(pos, size.x, size.y);
}
void ofApp::onRect(bool & e){
cout << "bang" << endl;
ofRemoveListener(inSide, this, &ofApp::onRect);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
if (((x>pos.x)&&(x<pos.x+size.x))&&((y>pos.y)&&(y<pos.y+size.y))) {
positionIn = true;
ofNotifyEvent(inSide, positionIn, this);
} else {
positionIn = false;
ofAddListener(inSide, this, &ofApp::onRect);
}
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}