Skip to content

Instantly share code, notes, and snippets.

@firmread
Created April 14, 2014 12:08
Show Gist options
  • Save firmread/10641924 to your computer and use it in GitHub Desktop.
Save firmread/10641924 to your computer and use it in GitHub Desktop.
simple circle and rectangle buttons for openFrameworks
void ofApp::setup(){
circleButton.set(100, 100);
radius = 50;
bCircleButton = false;
rectButton.set(200, 50, 100, 100);
bRectButton = false;
}
//--------------------------------------------------------------
void ofApp::update(){
if (bCircleButton){
//do something
}else{
//or do sth else
}
if (bRectButton){
//do some other things
}else{
//or do sth else
}
}
//--------------------------------------------------------------
void ofApp::draw(){
if (bCircleButton)
ofSetColor(ofColor::sandyBrown);
else
ofSetColor(ofColor::seaGreen);
ofCircle(circleButton, radius);
if (bRectButton)
ofSetColor(ofColor::sandyBrown);
else
ofSetColor(ofColor::seaGreen);
ofRect(rectButton);
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
if (circleButton.distance(ofPoint(x,y)) < radius) {
bCircleButton = !bCircleButton;
}
if (rectButton.inside(x, y)) {
bRectButton = !bRectButton;
}
}
//--------------------------------------------------------------
ofPoint circleButton;
bool bCircleButton;
int radius;
ofRectangle rectButton;
bool bRectButton;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment