Skip to content

Instantly share code, notes, and snippets.

@hiroMTB
Last active December 28, 2018 23:08
Show Gist options
  • Save hiroMTB/036954e9569f64386dd6008ae993ca44 to your computer and use it in GitHub Desktop.
Save hiroMTB/036954e9569f64386dd6008ae993ca44 to your computer and use it in GitHub Desktop.
ofxGui, Panel in each class example
#include "ofMain.h"
#include "ofApp.h"
//========================================================================
int main( ){
ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new ofApp());
}
//
// MyClass.h
//
#pragma once
#include "ofxGui.h"
class MyClass{
public:
MyClass(int i){
string name = "settings" + ofToString(i);
gui.setup(name, name+".xml", (i-1)*220, 0);
gui.add(grp);
gui.loadFromFile(name+".xml");
}
void draw(){
gui.draw();
}
ofParameter<int> myInt{"MyInt", 0, 0, 100};
ofParameterGroup grp{"My Class", myInt};
ofxPanel gui;
};
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
myClasses.reserve(10);
for(int i=0; i<2; i++){
myClasses.emplace_back(i+1);
}
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
for(auto & c : myClasses){
c.draw();
}
}
#pragma once
#include "ofMain.h"
#include "MyClass.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
vector<MyClass> myClasses;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment