ControlP5 slider unexpected behaviour
in
Contributed Library Questions
•
1 year ago
I have a problem with sliders, in the full app, I have three sliders to select a date, hour, month and day, with a fourth slider, to move accross all the range. Here is the code that reproduces the problem:
- import controlP5.*;
- ControlP5 controlP5;
- int slider_hours;
- float hours[] = {
- 0.0, 0.383333, 0.766667, 1.15, 1.533333, 1.916667, 2.3, 2.683333, 3.066667, 3.45, 3.833333, 4.216667, 4.6, 4.983333, 5.366667, 5.75, 6.133333, 6.516667, 6.9, 7.283333, 7.666667, 8.05, 8.433333, 8.816667, 9.2, 9.583333, 9.966667, 10.35, 10.733333, 11.116667, 11.5, 11.883333, 12.266667, 12.65, 13.033333, 13.416667, 13.8, 14.183333, 14.566667, 14.95, 15.333333, 15.716667, 16.1, 16.483333, 16.866667, 17.25, 17.633333, 18.016667, 18.4, 18.783333, 19.166667, 19.55, 19.933333, 20.316667, 20.7, 21.083333, 21.466667, 21.85, 22.233333, 22.616667, 23.0
- };
- void setup()
- {
- size(640, 480);
- int i;
- controlP5 = new ControlP5(this);
- i = 0;
- controlP5.addSlider("slider_hours")
- .setPosition(10, 25 + 15*i++)
- .setSize(200, 10)
- .setRange(0, hours.length-1)
- .setValue(hours.length/2)
- .setLabel("Hour")
- .setSliderMode(Slider.FLEXIBLE)
- .setNumberOfTickMarks(hours.length)
- .showTickMarks(false)
- ;
- controlP5.addSlider("slider_global")
- .setPosition(10, 25 + 15*i++)
- .setSize(200, 10)
- .setRange(0, hours.length-1)
- .setValue(hours.length/2)
- .setLabel("Global")
- .setSliderMode(Slider.FLEXIBLE)
- ;
- }
- void draw()
- {
- }
- void slider_hours(int value)
- {
- slider_hours = value;
- println("h: " + value);
- if ( controlP5.getController("slider_hours").isMousePressed() )
- controlP5.getController("slider_global").setValue(slider_hours);
- }
- void slider_global(int value)
- {
- int temp;
- if ( controlP5.getController("slider_global").isMousePressed() )
- {
- println("Hour value to set: "+value + " " + hours.length + " " + (value%hours.length));
- temp = int(value%hours.length);
- println("setValue function " + temp);
- controlP5.getController("slider_hours").setValue(temp);
- println("custom function " + temp);
- slider_hours( temp );
- println("Hour value set: "+controlP5.getController("slider_hours").value());
- }
- }
1