Skip to content

Instantly share code, notes, and snippets.

@moebiussurfing
Last active January 5, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moebiussurfing/5e3f7403a3e2b762525ccd697107a742 to your computer and use it in GitHub Desktop.
Save moebiussurfing/5e3f7403a3e2b762525ccd697107a742 to your computer and use it in GitHub Desktop.
openFrameworks / ofParameters cast
// casting ofParameters
float v = static_cast<ofParameter<float>&>(parameter);
ofParameter<float> prop = static_cast<ofParameter<float>&>(parameter);
ofParameter<float> prop = parameter.cast<float>();
//which internally does the static cast you are using now.
//https://forum.openframeworks.cc/t/ofparametergroup-best-practices/18752/8
//--
// static and multi class gui
//https://forum.openframeworks.cc/t/using-ofxgui-slider-values-outside-of-ofapp/21293/11
//NOTICE:
//If you use vector for MyClass like #1 example above, please make sure MyClass’s destructor won’t be called.
//This happen often for example when you push_back() new element to vector. When you add new element to your vector, it could be automatically change its memory size to prepare future addition. During this auto expansion process, destructor ofGui is called and lose callback pointer information. Resulting mouse event stop working. To avoid this, and makes really sure its pointer and memory is under your control always, one could use shared pointer like below
vector<shared_ptr<MyClass>> myClasses;
// emplace_back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment