Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofxGui: add setMin() and setMax() to ofxSliderGroup #6443

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 102 additions & 26 deletions addons/ofxGui/src/ofxSliderGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ ofxVecSlider_<VecType> * ofxVecSlider_<VecType>::setup(const std::string& contro
return setup(value,width,height);
}

template<class VecType>
void ofxVecSlider_<VecType>::setMin(const VecType& min) {
value.setMin(min);
for (size_t i = 0; i < dim(); i++){
parameters[i].template cast<float>().setMin(min[i]);
}
}

template<class VecType>
VecType ofxVecSlider_<VecType>::getMin() {
return value.getMin();
}

template<class VecType>
void ofxVecSlider_<VecType>::setMax(const VecType& max) {
value.setMax(max);
for (size_t i = 0; i < dim(); i++){
parameters[i].template cast<float>().setMax(max[i]);
}
}

template<class VecType>
VecType ofxVecSlider_<VecType>::getMax() {
return value.getMax();
}

template<class VecType>
void ofxVecSlider_<VecType>::changeSlider(const void * parameter, float & _value){
sliderChanging = true;
Expand Down Expand Up @@ -142,14 +168,8 @@ ofxColorSlider_<ColorType> * ofxColorSlider_<ColorType>::setup(ofParameter<ofCol
ofParameter<ColorType> p(names[i], val[i], min[i], max[i]);
add(new ofxSlider<ColorType>(p, width, height));
p.addListener(this, & ofxColorSlider_::changeSlider);
collection[i]->setFillColor(value.get());
float range = p.getMax()-p.getMin();
if(range == 0){
collection[i]->setTextColor( ofFloatColor(0.));
}else{
collection[i]->setTextColor( p/range > 0.75 ? ofFloatColor(0.) : ofFloatColor(1.));
}
}
updateSliderColors(value.get());
add(&picker);
picker.getParameter().template cast<ofColor_<ColorType>>().addListener(this, & ofxColorSlider_::changeValue);

Expand All @@ -166,6 +186,32 @@ ofxColorSlider_<ColorType> * ofxColorSlider_<ColorType>::setup(const std::string
return setup(color,width,height);
}

template<class ColorType>
void ofxColorSlider_<ColorType>::setMin(const ofColor_<ColorType>& min) {
picker.getParameter().template cast<ofColor_<ColorType>>().setMin(min);
for (int i = 0; i < 4; i++){
parameters[i].template cast<ColorType>().setMin(min[i]);
}
}

template<class ColorType>
ofColor_<ColorType> ofxColorSlider_<ColorType>::getMin() {
return picker.getParameter().template cast<ofColor_<ColorType>>().getMin();
}

template<class ColorType>
void ofxColorSlider_<ColorType>::setMax(const ofColor_<ColorType>& max) {
picker.getParameter().template cast<ofColor_<ColorType>>().setMax(max);
for (int i = 0; i < 4; i++){
parameters[i].template cast<ColorType>().setMax(max[i]);
}
}

template<class ColorType>
ofColor_<ColorType> ofxColorSlider_<ColorType>::getMax() {
return picker.getParameter().template cast<ofColor_<ColorType>>().getMax();
}

template<class ColorType>
void ofxColorSlider_<ColorType>::changeSlider(const void * parameter, ColorType & _value){
sliderChanging = true;
Expand All @@ -175,17 +221,7 @@ void ofxColorSlider_<ColorType>::changeSlider(const void * parameter, ColorType
data[i] = _value;
picker.getParameter().template cast<ofColor_<ColorType>>() = data;


for (int i=0; i<4; i++){
collection[i]->setFillColor(data);
auto p = parameters[i].template cast<ColorType>();
float range = p.getMax()-p.getMin();
if(range == 0){
collection[i]->setTextColor( ofFloatColor(0.));
}else{
collection[i]->setTextColor( p/range > 0.75 ? ofFloatColor(0.) : ofFloatColor(1.));
}
}
updateSliderColors(data);
sliderChanging = false;
}

Expand All @@ -196,22 +232,30 @@ void ofxColorSlider_<ColorType>::changeValue(ofColor_<ColorType> & value){
}
for (int i=0; i<4; i++){
parameters[i].template cast<ColorType>() = value[i];
collection[i]->setFillColor(value);
auto p = parameters[i].template cast<ColorType>();
float range = p.getMax()-p.getMin();
if(range == 0){
collection[i]->setTextColor( ofFloatColor(0.));
}else{
collection[i]->setTextColor( p/range > 0.75 ? ofFloatColor(0.) : ofFloatColor(1.));
}
}
updateSliderColors(value);
if(isMinimized()){
setHeaderBackgroundColor(value);
float b = value.getBrightness() / value.limit();
setTextColor(b > 0.75 ? ofFloatColor(0.0) : ofFloatColor(1.0));
}
}

template<class ColorType>
void ofxColorSlider_<ColorType>::updateSliderColors(ofColor_<ColorType> color) {
for (int i=0; i<4; i++){
collection[i]->setFillColor(color);
auto p = parameters[i].template cast<ColorType>();
float range = p.getMax()-p.getMin();
if(range == 0){ // Range of 0 is drawn as an empty bar.
collection[i]->setTextColor( ofFloatColor(1.));
}else{
auto amt = (p - p.getMin()) / range;
collection[i]->setTextColor( amt > 0.75 ? ofFloatColor(0.) : ofFloatColor(1.));
}
}
}

template<class ColorType>
ofAbstractParameter & ofxColorSlider_<ColorType>::getParameter(){
return picker.getParameter();
Expand Down Expand Up @@ -304,6 +348,38 @@ ofxRectangleSlider * ofxRectangleSlider::setup(const std::string& controlName, c
}


void ofxRectangleSlider::setMin(const ofRectangle& min) {
value.setMin(min);

// Order is the same as in setup().
parameters[0].template cast<float>().setMin(min.x);
parameters[1].template cast<float>().setMin(min.y);
parameters[2].template cast<float>().setMin(min.width);
parameters[3].template cast<float>().setMin(min.height);
}


ofRectangle ofxRectangleSlider::getMin() {
return value.getMin();
}


void ofxRectangleSlider::setMax(const ofRectangle& max) {
value.setMax(max);

// Order is the same as in setup().
parameters[0].template cast<float>().setMax(max.x);
parameters[1].template cast<float>().setMax(max.y);
parameters[2].template cast<float>().setMax(max.width);
parameters[3].template cast<float>().setMax(max.height);
}


ofRectangle ofxRectangleSlider::getMax() {
return value.getMax();
}


void ofxRectangleSlider::changeSlider(const void * parameter, float & _value){
sliderChanging = true;
ofParameter<float> & param = *(ofParameter<float>*)parameter;
Expand Down
18 changes: 17 additions & 1 deletion addons/ofxGui/src/ofxSliderGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class ofxVecSlider_ : public ofxGuiGroup {
ofxVecSlider_ * setup(ofParameter<VecType> value, float width = defaultWidth, float height = defaultHeight);
ofxVecSlider_ * setup(const std::string& controlName, const VecType & value, const VecType & min, const VecType & max, float width = defaultWidth, float height = defaultHeight);

void setMin(const VecType& min);
VecType getMin();
void setMax(const VecType& max);
VecType getMax();

ofAbstractParameter & getParameter();

VecType operator=(const VecType & v);
Expand Down Expand Up @@ -45,6 +50,11 @@ class ofxColorSlider_: public ofxGuiGroup{
ofxColorSlider_ * setup(ofParameter<ofColor_<ColorType> > value, float width = defaultWidth, float height = defaultHeight);
ofxColorSlider_ * setup(const std::string& controlName, const ofColor_<ColorType> & value, const ofColor_<ColorType> & min, const ofColor_<ColorType> & max, float width = defaultWidth, float height = defaultHeight);

void setMin(const ofColor_<ColorType>& min);
ofColor_<ColorType> getMin();
void setMax(const ofColor_<ColorType>& max);
ofColor_<ColorType> getMax();

ofAbstractParameter & getParameter();

ofColor_<ColorType> operator=(const ofColor_<ColorType> & v);
Expand All @@ -54,6 +64,7 @@ class ofxColorSlider_: public ofxGuiGroup{
void onMaximize();
void changeSlider(const void * parameter, ColorType & value);
void changeValue(ofColor_<ColorType> & value);
void updateSliderColors(ofColor_<ColorType> color);
bool sliderChanging;
ofColor originalHeaderBackground;
ofColor originalHeaderText;
Expand All @@ -74,7 +85,12 @@ class ofxRectangleSlider: public ofxGuiGroup{
ofxRectangleSlider * setup(ofParameter<ofRectangle>, float width = defaultWidth, float height = defaultHeight);
ofxRectangleSlider * setup(const std::string& controlName, const ofRectangle & value, const ofRectangle & min, const ofRectangle & max, float width = defaultWidth, float height = defaultHeight);

ofAbstractParameter & getParameter();
void setMin(const ofRectangle& min);
ofRectangle getMin();
void setMax(const ofRectangle& max);
ofRectangle getMax();

ofAbstractParameter & getParameter();

ofRectangle operator=(const ofRectangle & v);
operator const ofRectangle & ();
Expand Down
2 changes: 2 additions & 0 deletions tests/addons/ofxGuiSliders/addons.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ofxGui
ofxUnitTests
8 changes: 8 additions & 0 deletions tests/addons/ofxGuiSliders/icon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Icon Resource Definition
#define MAIN_ICON 102

#if defined(_DEBUG)
MAIN_ICON ICON "icon_debug.ico"
#else
MAIN_ICON ICON "icon.ico"
#endif
35 changes: 35 additions & 0 deletions tests/addons/ofxGuiSliders/ofxGuiSliders.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxGuiSliders", "ofxGuiSliders.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64
{7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64
{5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading