First, let me say I love G4P. It saves me a lot of work. Using Processing 3 & G4P GUI Builder I have 3 GSliders. Lets call them LEFT Motor, RIGHT Motor and DUAL. All 3 sliders work as expected and no issues. What I want to do is update visually the position of Left & Right to match the value of DUAL when DUAL is moved. In other words; if LEFT, RIGHT & DUAL are at Maximum (100%) and I move DUAL to 50% the LEFT & RIGHT Slider will Update and be identical to DUAL. Is there a Function available in g4p_controls.GSlider that will accomplish it?
1 Like
This is easy enough. The sketch below demonstrates how do do it. I created it using GUI Builder but have merged the code in the two tabs and removed the bulk of the comments to reduce the code length for the forum.
Try the sketch out and then look at the code in in the slider event handlers.
import g4p_controls.*;
public void setup(){
size(360, 150, JAVA2D);
createGUI();
}
public void draw(){
background(230);
}
public void sliderLeftChange(GSlider source, GEvent event) { //_CODE_:sliderLeft:362079:
valueLeft.setText(source.getValueS());
} //_CODE_:sliderLeft:362079:
public void sliderRightChange(GSlider source, GEvent event) { //_CODE_:sliderRight:951269:
valueRight.setText(source.getValueS());
} //_CODE_:sliderRight:951269:
public void sliderDualChnge(GSlider source, GEvent event) { //_CODE_:sliderDual:893828:
valueDual.setText(source.getValueS());
sliderLeft.setValue(source.getValueF());
sliderRight.setValue(source.getValueF());
} //_CODE_:sliderDual:893828:
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
surface.setTitle("Sketch Window");
sliderLeft = new GSlider(this, 60, 10, 160, 30, 10.0);
sliderLeft.setLimits(0.5, 0.0, 1.0);
sliderLeft.setNumberFormat(G4P.DECIMAL, 2);
sliderLeft.setOpaque(false);
sliderLeft.addEventHandler(this, "sliderLeftChange");
sliderRight = new GSlider(this, 60, 50, 160, 30, 10.0);
sliderRight.setLimits(0.5, 0.0, 1.0);
sliderRight.setNumberFormat(G4P.DECIMAL, 2);
sliderRight.setOpaque(false);
sliderRight.addEventHandler(this, "sliderRightChange");
sliderDual = new GSlider(this, 60, 90, 160, 30, 10.0);
sliderDual.setLimits(0.5, 0.0, 1.0);
sliderDual.setNumberFormat(G4P.DECIMAL, 2);
sliderDual.setOpaque(false);
sliderDual.addEventHandler(this, "sliderDualChnge");
lblLeft = new GLabel(this, 10, 10, 40, 30);
lblLeft.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
lblLeft.setText("Left");
lblLeft.setOpaque(false);
lblRight = new GLabel(this, 10, 50, 40, 30);
lblRight.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
lblRight.setText("Right");
lblRight.setOpaque(false);
LblDual = new GLabel(this, 10, 90, 40, 30);
LblDual.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
LblDual.setText("Dual");
LblDual.setOpaque(false);
valueLeft = new GLabel(this, 230, 10, 120, 30);
valueLeft.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
valueLeft.setText("0.5");
valueLeft.setOpaque(true);
valueRight = new GLabel(this, 230, 50, 120, 30);
valueRight.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
valueRight.setText("0.5");
valueRight.setOpaque(true);
valueDual = new GLabel(this, 230, 90, 120, 30);
valueDual.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
valueDual.setText("0.5");
valueDual.setOpaque(true);
}
// Variable declarations
// autogenerated do not edit
GSlider sliderLeft;
GSlider sliderRight;
GSlider sliderDual;
GLabel lblLeft;
GLabel lblRight;
GLabel LblDual;
GLabel valueLeft;
GLabel valueRight;
GLabel valueDual;
1 Like
You da man!!! Works perfectly in my sketch. I owe you a pint. Thank You!
Make that a pint of Lager. LOL
you have PayPal? you ever get to Jamaica link me up.
Just a joke since my real surname is Lager.
I don’t expect payment for my Processing libraries or for any help I might provide on this forum.
2 Likes