fox GUI example
// h---------------------------------
#pragma once
#include "ofMain.h"
#include "ofxGui.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void exit();
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 mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void circleResolutionChanged(int & circleResolution);
void ringButtonPressed();
bool bHide;
ofxFloatSlider radius;
ofxColorSlider color;
ofxVec2Slider center;
ofxIntSlider circleResolution;
ofxToggle filled;
ofxButton twoCircles;
ofxButton ringButton;
ofxLabel screenSize;
ofxPanel gui;
ofSoundPlayer ring;
};
// cpp -----------------------------
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofSetVerticalSync(true);
// we add this listener before setting up so the initial circle resolution is correct
circleResolution.addListener(this, &ofApp::circleResolutionChanged);
ringButton.addListener(this, &ofApp::ringButtonPressed);
gui.setup(); // most of the time you don't need a name
gui.add(filled.setup("fill", true));
gui.add(radius.setup("radius", 140, 10, 300));
gui.add(center.setup("center", ofVec2f(ofGetWidth()*.5, ofGetHeight()*.5), ofVec2f(0, 0), ofVec2f(ofGetWidth(), ofGetHeight())));
gui.add(color.setup("color", ofColor(100, 100, 140), ofColor(0, 0), ofColor(255, 255)));
gui.add(circleResolution.setup("circle res", 5, 3, 90));
gui.add(twoCircles.setup("two circles"));
gui.add(ringButton.setup("ring"));
gui.add(screenSize.setup("screen size", ofToString(ofGetWidth())+"x"+ofToString(ofGetHeight())));
bHide = false;
ring.load("ring.wav");
}
//--------------------------------------------------------------
void ofApp::exit(){
ringButton.removeListener(this, &ofApp::ringButtonPressed);
circleResolution.removeListener(this, &ofApp::circleResolutionChanged);
}
//--------------------------------------------------------------
void ofApp::circleResolutionChanged(int &circleResolution){
ofSetCircleResolution(circleResolution);
}
//--------------------------------------------------------------
void ofApp::ringButtonPressed(){
ring.play();
}
//--------------------------------------------------------------
void ofApp::update(){
ofSetCircleResolution(circleResolution);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackgroundGradient(ofColor::white, ofColor::gray);
if(filled){
ofFill();
}else{
ofNoFill();
}
ofSetColor(color);
if(twoCircles){
ofDrawCircle(center->x-radius*.5, center->y, radius );
ofDrawCircle(center->x+radius*.5, center->y, radius );
}else{
ofDrawCircle((ofVec2f)center, radius );
}
// auto draw?
// should the gui control hiding?
if(!bHide){
gui.draw();
}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if(key == 'h'){
bHide = !bHide;
}
else if(key == 's'){
gui.saveToFile("settings.xml");
}
else if(key == 'l'){
gui.loadFromFile("settings.xml");
}
else if(key == ' '){
color = ofColor(255);
}
}
댓글
댓글 쓰기