ofBaseApp
The openFrameworks engine is contained in the "app" category. The project works, similar to processing, in that you have a base class which extends a class that already exists. In the case of OF, there is a class called "ofBaseApp" which contains various event driven functions. When you create an OF project, you use a main.cpp which is the boot-strap, that kicks off the application and another class, which inherits the properties of ofBaseApp. Essentially, when you write code in the testApp, you are re-writing already defined functions that exist in OF, such as update, draw, etc.
In versions pre 0.06 this class was called ofSimpleApp
dragEvent( ... )
void dragEvent(ofDragInfo dragInfo)dragged( ... )
void dragged(ofDragInfo &drag)draw( ... )
void draw(ofEventArgs &args)draw( )
void draw()This function gets called regularly just after update. It's where you draw things:
void draw(){
ofSetColor(255,255,255);
ofNoFill();
ofDrawRectangle(20,20,100,100);
}
exit( ... )
void exit(ofEventArgs &args)exit( )
void exit()Add this function to your ofApp to have it called at the moment before the app is terminated. This is useful for doing cleanup stuff or making sure files are saved before the app terminates. If you want to terminate the execution of your ofApp (from the inside), call ofExit().
gotMessage( ... )
void gotMessage(ofMessage msg)keyPressed( ... )
void keyPressed(ofKeyEventArgs &key)keyPressed( ... )
void keyPressed(int key)This function gets called when a key is pressed. The value key can be tested against:
void keyPressed(int key){
if (key == 't'){
; // do something
} else if (key == ' '){
; // do something else
}
}
There are more complicated character codes, for keys such as F1-F12, Down, Enter: OF_KEY_BACKSPACE, OF_KEY_RETURN, OF_KEY_PRINTSCR, OF_KEY_F1 - OF_KEY_F12, OF_KEY_LEFT, OF_KEY_UP, OF_KEY_RIGHT, OF_KEY_DOWN, OF_KEY_PAGE_UP, OF_KEY_PAGE_DOWN, OF_KEY_HOME, OF_KEY_END, OF_KEY_INSERT
keyReleased( ... )
void keyReleased(ofKeyEventArgs &key)keyReleased( ... )
void keyReleased(int key)This function gets called when a key is released. The value key can be tested against:
void keyReleased(int key){
if (key == 't'){
; // do something
} else if (key == ' '){
; // do something else
}
}
There are more complicated character codes, for keys such as F1-F12, Down, Enter: OF_KEY_BACKSPACE, OF_KEY_RETURN, OF_KEY_PRINTSCR, OF_KEY_F1 - OF_KEY_F12, OF_KEY_LEFT, OF_KEY_UP, OF_KEY_RIGHT, OF_KEY_DOWN, OF_KEY_PAGE_UP, OF_KEY_PAGE_DOWN, OF_KEY_HOME, OF_KEY_END, OF_KEY_INSERT
messageReceived( ... )
void messageReceived(ofMessage &message)mouseDragged( ... )
void mouseDragged(ofMouseEventArgs &mouse)mouseDragged( ... )
void mouseDragged(int x, int y, int button)Called on the active window when the mouse is dragged, i.e. moved with a button pressed
This function gets called when the mouse is moving and the button is down. The button (left 0, center 1, right 2) variable can be used to test against left or right button drags. You also receive the x and y coordinates of the mouse.
mouseEntered( ... )
void mouseEntered(ofMouseEventArgs &mouse)mouseEntered( ... )
void mouseEntered(int x, int y)Called on the active window when the mouse cursor enters the window area
Note that the mouse coordinates are the last known x/y before the event occurred, i.e. from the previous frame
mouseExited( ... )
void mouseExited(ofMouseEventArgs &mouse)mouseExited( ... )
void mouseExited(int x, int y)Called on the active window when the mouse cursor leaves the window area
Note that the mouse coordinates are the last known x/y before the event occurred, i.e. from the previous frame
mouseMoved( ... )
void mouseMoved(ofMouseEventArgs &mouse)mouseMoved( ... )
void mouseMoved(int x, int y)Called on the active window when the mouse is moved
This function gets when ever the mouse moves. You receive the x and y coordinates of the mouse.
mousePressed( ... )
void mousePressed(ofMouseEventArgs &mouse)mousePressed( ... )
void mousePressed(int x, int y, int button)Called on the active window when a mouse button is pressed
This function gets called when the mouse is pushed down. The button (left 0, center 1, right 2) is passed in, along with the x and y coordinate.
mouseReleased( ... )
void mouseReleased(ofMouseEventArgs &mouse)mouseReleased( ... )
void mouseReleased(int x, int y, int button)Called on the active window when a mouse button is released
This function gets called when the mouse is released. The button (left 0, center 1, right 2) is passed in, along with the x and y coordinate.
mouseScrolled( ... )
void mouseScrolled(ofMouseEventArgs &mouse)mouseScrolled( ... )
void mouseScrolled(int x, int y, float scrollX, float scrollY)Called on the active window when the mouse wheel is scrolled
ofBaseApp( )
ofBaseApp()The openFrameworks engine is contained in the "app" category. The project works, similar to processing, in that you have a base class which extends a class that already exists. In the case of OF, there is a class called "ofBaseApp" which contains various event driven functions. When you create an OF project, you use a main.cpp which is the boot-strap, that kicks off the application and another class, which inherits the properties of ofSimpleApp. Essentially, when you write code in the ofApp, you are re-writing already defined functions that exist in OF, such as update, draw, etc.
setup( ... )
void setup(ofEventArgs &args)setup( )
void setup()This function gets called once, just at the start of the app. It would be a good place, for example, to allocate variables or load in any files.
touchCancelled( ... )
void touchCancelled(ofTouchEventArgs &touch)touchCancelled( ... )
void touchCancelled(int x, int y, int id)touchDoubleTap( ... )
void touchDoubleTap(ofTouchEventArgs &touch)touchDoubleTap( ... )
void touchDoubleTap(int x, int y, int id)touchDown( ... )
void touchDown(ofTouchEventArgs &touch)touchDown( ... )
void touchDown(int x, int y, int id)touchMoved( ... )
void touchMoved(ofTouchEventArgs &touch)touchMoved( ... )
void touchMoved(int x, int y, int id)touchUp( ... )
void touchUp(ofTouchEventArgs &touch)touchUp( ... )
void touchUp(int x, int y, int id)update( ... )
void update(ofEventArgs &args)update( )
void update()This function gets called repeatedly. It gets called just before draw, so it is an ideal place to do any updating of variables. For example, imagine you have a variable already defined in your ofApp.h called "xpos"
void setup(){
xpos = 0;
}
void update(){
xpos += 1;
if (xPos
windowResized( ... )
void windowResized(ofResizeEventArgs &resize)windowResized( ... )
void windowResized(int w, int h)This function gets called when ever we resize the application window. You receive the new width (w) and the new height (h) of the window.
~ofBaseApp( )
~ofBaseApp()