Created
December 21, 2012 14:09
-
-
Save anonymous/4353055 to your computer and use it in GitHub Desktop.
a very basic example showing ofEvent - sorry its so boring.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "testApp.h" | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
displayString = "press mouse to fire an event"; | |
ofAddListener(timeStampEvent, this, &testApp::eventsIn); | |
} | |
//-------------------------------------------------------------- | |
void testApp::eventsIn(string & eventStr){ | |
cout << "we got an event!" << endl; | |
cout << "timestamp is:" <<endl; | |
cout << eventStr << endl; | |
displayString = "last timestamp received: \n" + eventStr; | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
if( ofGetMousePressed(0) ){ | |
string str = ofGetTimestampString(); | |
ofNotifyEvent(timeStampEvent, str, this); | |
} | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
ofSetColor(30); | |
ofDrawBitmapString(displayString, 10, 20); | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyPressed(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::keyReleased(int key){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseMoved(int x, int y){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseDragged(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mousePressed(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::mouseReleased(int x, int y, int button){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::windowResized(int w, int h){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::gotMessage(ofMessage msg){ | |
} | |
//-------------------------------------------------------------- | |
void testApp::dragEvent(ofDragInfo dragInfo){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ofMain.h" | |
class testApp : public ofBaseApp{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
//note the type of the argument has to be the same as the type of ofEvent - in this case a string | |
//also note the & - without it the notification will not happen | |
void eventsIn( string & eventStr ); | |
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); | |
//this object 'timeStampEvent' allows anyone that adds a listener to it, to get notfication of that event. | |
//sometimes it makes sense to have the event be a global variable so muliple classes can register for notification. | |
ofEvent <string> timeStampEvent; | |
string displayString; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment