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

Fix ofx gui slider scrolling #6144

Merged
merged 4 commits into from
Nov 13, 2018
Merged
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
8 changes: 6 additions & 2 deletions addons/ofxGui/src/ofxInputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,15 @@ bool ofxInputField<Type>::mouseReleased(ofMouseEventArgs &){
//-----------------------------------------------------------
template<typename Type>
bool ofxInputField<Type>::mouseScrolled(ofMouseEventArgs & mouse){
if(!isGuiDrawing() || insideSlider){
//when insideSlider it is the slider object who is in charge of handling the scrolling
return false;
}
if(b.inside(mouse)){
if(!bGuiActive){
if(mouse.y>0 || mouse.y<0){
if(mouse.scrollY>0 || mouse.scrollY<0){
double range = getRange(value.getMin(), value.getMax(), b.width);
Type newValue = value + ofMap(mouse.y,-1,1,-range, range);
Type newValue = value + ofMap(mouse.scrollY,-1,1,-range, range);
newValue = ofClamp(newValue,value.getMin(),value.getMax());
value = newValue;
}
Expand Down
26 changes: 15 additions & 11 deletions addons/ofxGui/src/ofxSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,25 @@ getRange(Type min, Type max, float width){

template<typename Type>
bool ofxSlider<Type>::mouseScrolled(ofMouseEventArgs & args){
if(state==Slider){
if(mouseInside){
if(args.scrollY>0 || args.scrollY<0){
double range = getRange(value.getMin(),value.getMax(),b.width);
Type newValue = value + ofMap(args.scrollY,-1,1,-range, range);
newValue = ofClamp(newValue,value.getMin(),value.getMax());
value = newValue;
if(isGuiDrawing()){
if(state==Slider){
if(mouseInside){
if(args.scrollY>0 || args.scrollY<0){
double range = getRange(value.getMin(),value.getMax(),b.width);
Type newValue = value + ofMap(args.scrollY,-1,1,-range, range);
newValue = ofClamp(newValue,value.getMin(),value.getMax());
value = newValue;
}
return true;
}else{
return false;
}
return true;
}else{
return false;
// the following will always return false as it is inside the slider.
// return input.mouseScrolled(args);
}
}else{
return isGuiDrawing() && input.mouseScrolled(args);
}
return false;
}


Expand Down