openframeworks/openFrameworks — pull request #1367 by markpitchless (2012-06-30 18:04:19+00:00)
Title: Feature ofxgui fpsslider

Hello. This patch contains a few things.

First, ofxFpsSlider. A gui widget that shows an auto updating FPS value as a slider. This started as an experiment in sub classing a gui widget. I think it is important for this to be simple with ofxGui as you will often want one or two custom widgets for a given app. If that is easy the main library doesn't need to become too bloated with widgets, just good building blocks. An fps slider has been added to guiExample.

Second, updates to ofxSlider used by the fps slider but also more generally useful. It adds an autoMin and autoMax feature that makes the slider increase it's min and max when getting a value out of range. Useful when using sliders to display variable data like framerate.

Third. While playing with ofxGui I discovered the excellent ofxParameter. Brilliant! I had the idea if we make the attributes of a widget ofxParameters we get nice hook points for events for changes in state of the widgets without having to add lots of extra event code. So for ofxSlider the min, max, autoMin, autoMax attributes have all been made ofxParameters and have accessors added. The updated guiExample shows hooking the max value of the FPS slider changing to output the max FPS hit:

```cpp
gui.add(fpsSlider.setup("FPS", 60.0));
fpsSlider.getMax().addListener(this, &testApp::maxFpsChange);
//...
void testApp::maxFpsChange(float & max){
cout << "Max FPS: " << max << endl;
}
```

This seems to work really well. What do you think? I'd like to extend this idea out to the other widgets. Willing to code that if people agree. ofxParameter is so good we should make maximum use of it.

The accessors are implemented in the header file in the hopes the compiler will inline them. The getters can not be made const as that breaks the addListener call above.

(Note that on my machine guiExample segfaults on exit. However I think this related to #1366 as commenting out all the ring sound player code and not doing a file load makes the segfault go away).