class methods
- dragEvent()
- dragged()
- draw()
- exit()
- gotMessage()
- keyPressed()
- keyReleased()
- messageReceived()
- mouseDragged()
- mouseEntered()
- mouseExited()
- mouseMoved()
- mousePressed()
- mouseReleased()
- mouseScrolled()
- setup()
- touchCancelled()
- touchDoubleTap()
- touchDown()
- touchMoved()
- touchUp()
- update()
- windowResized()
variables
Extends
This class extends others, you can call their methods on an instance of ofBaseApp too:
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
draw()
void ofBaseApp::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 ofBaseApp::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().
keyPressed(...)
void ofBaseApp::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 ofBaseApp::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
mouseDragged(...)
void ofBaseApp::mouseDragged(int x, int y, int button)
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.
Documentation from code comments
Called on the active window when the mouse is dragged, i.e. moved with a button pressed
mouseEntered(...)
void ofBaseApp::mouseEntered(int x, int y)
Documentation from code comments
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 ofBaseApp::mouseExited(int x, int y)
Documentation from code comments
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 ofBaseApp::mouseMoved(int x, int y)
This function gets when ever the mouse moves. You receive the x and y coordinates of the mouse.
Documentation from code comments
Called on the active window when the mouse is moved
mousePressed(...)
void ofBaseApp::mousePressed(int x, int y, int button)
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.
Documentation from code comments
Called on the active window when a mouse button is pressed
mouseReleased(...)
void ofBaseApp::mouseReleased(int x, int y, int button)
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.
Documentation from code comments
Called on the active window when a mouse button is released
mouseScrolled(...)
void ofBaseApp::mouseScrolled(int x, int y, float scrollX, float scrollY)
Documentation from code comments
Called on the active window when the mouse wheel is scrolled
setup()
void ofBaseApp::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.
update()
void ofBaseApp::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 > ofGetWidth()) xPos = 0;
}
void draw(){
ofDrawRectangle(xPos, 30,10,10);
}
windowResized(...)
void ofBaseApp::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.
int mouseX
int ofBaseApp::mouseX
int mouseY
int ofBaseApp::mouseY
Last updated Tuesday, 19 November 2024 17:24:46 UTC - 2537ee49f6d46d5fe98e408849448314fd1f180e
If you have any doubt about the usage of this module you can ask in the forum.
If you want to contribute better documentation or start documenting this section you can do so here
If you find anything wrong with this docs you can report any error by opening an issue