controlP5
Class Slider

java.lang.Object
  extended by controlP5.Controller
      extended by controlP5.Slider
All Implemented Interfaces:
CDrawable, ControllerInterface, ControlP5Constants

public class Slider
extends Controller

a slider is either used horizontally or vertically. when adding a slider to controlP5, the width is compared versus the height. width is bigger, you get a horizontal slider, height is bigger, you get a vertical slider. a slider can have a fixed slide controller (one end of the slider is fixed to the left or bottom side of the controller), or a flexible slide control (a knob that you can drag).

+Example
/**
 * ControlP5 Slider. Horizontal and vertical sliders, 
 * with and without tick marks and snap-to-tick.
 * by andreas schlegel, 2010
 */

import controlP5.*;

ControlP5 controlP5;
int myColor = color(0,0,0);

int sliderValue = 100;
int sliderTicks1 = 100;
int sliderTicks2 = 30;


void setup() {
  size(400,400);
  controlP5 = new ControlP5(this);
  // add a vertical slider
  controlP5.addSlider("slider",0,200,128,20,100,10,100);
  // create another slider with tick marks, now without
  // default value, the initial value will be set according th
  // the value of variable sliderTicks2 then.
  controlP5.addSlider("sliderTicks1",0,255,100,100,10,100);
  Slider s1 = (Slider)controlP5.controller("sliderTicks1");
  s1.setNumberOfTickMarks(5);
  
  
  // add horizontal sliders
  controlP5.addSlider("sliderValue",0,255,128,200,180,100,10);
  controlP5.addSlider("sliderTicks2",0,255,128,200,220,100,10);
  Slider s2 = (Slider)controlP5.controller("sliderTicks2");
  s2.setNumberOfTickMarks(7);
  // use Slider.FIX or Slider.FLEXIBLE to change the slider handle
  // by default it is Slider.FIX
  s2.setSliderMode(Slider.FLEXIBLE);
  
}

void draw() {
  background(sliderTicks1);
  
  fill(sliderValue);
  rect(0,0,width,100);
  
  fill(myColor);
  rect(0,300,width,70);
  
  fill(sliderTicks2);
  rect(0,370,width,30);
}

void slider(float theColor) {
  myColor = color(theColor);
  println("a slider event. setting background to "+theColor);
}


Field Summary
static int FIX
           
static int FLEXIBLE
           
 int valueLabelPositioning
           
 
Fields inherited from interface controlP5.ControlP5Constants
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL
 
Constructor Summary
Slider(ControlP5 theControlP5, ControllerGroup theParent, java.lang.String theName, float theMin, float theMax, float theDefaultValue, int theX, int theY, int theWidth, int theHeight)
           
 
Method Summary
 void addToXMLElement(ControlP5XMLElement theElement)
           
 void alignValueLabel(int theValue)
          use static variables ControlP5.TOP, ControlP5.CENTER, ControlP5.BOTTOM to align the ValueLabel of a slider.
 int getNumberOfTickMarks()
           
 TickMark getTickMark(int theIndex)
           
 java.util.ArrayList<TickMark> getTickMarks()
           
 Controller linebreak()
           
 void onEnter()
           
 void onLeave()
           
 Controller setHeight(int theValue)
          set the height of the slider.
 void setMax(float theValue)
          set the maximum value of the slider.
 void setMin(float theValue)
          set the minimum value of the slider.
 void setNumberOfTickMarks(int theNumber)
           
 void setSliderMode(int theMode)
          use the slider mode to set the mode of the slider bar, which can be Slider.FLEXIBLE or Slider.FIX
 void setValue(float theValue)
          set the value of the slider.
 Controller setWidth(int theValue)
          set the width of the slider.
 void showTickMarks(boolean theFlag)
           
 void snapToTickMarks(boolean theFlag)
           
 void update()
          updates the value of the controller without having to set the value explicitly.
 void updateDisplayMode(int theMode)
           
 void updateInternalEvents(processing.core.PApplet theApplet)
          TODO
 
Methods inherited from class controlP5.Controller
absolutePosition, add, addListener, arrayValue, behavior, captionLabel, changeValue, color, continuousUpdateEvents, controlWindow, defaultValue, disableSprite, draw, enableSprite, getAsXML, getColor, getHeight, getPickingColor, getSprite, getTab, getWidth, getWindow, hide, id, init, isBroadcast, isInside, isLock, isMousePressed, isMoveable, isUpdate, isUserInteraction, isVisible, isXMLsavable, keyEvent, label, listenerSize, lock, max, min, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, name, parent, plugTo, plugTo, position, remove, remove, removeBehavior, removeListener, setArrayValue, setBehavior, setBroadcast, setCaptionLabel, setColor, setColorActive, setColorBackground, setColorCaptionLabel, setColorForeground, setColorLabel, setColorValue, setColorValueLabel, setDecimalPrecision, setDefaultValue, setDisplay, setDisplay, setGroup, setGroup, setId, setImage, setImage, setImages, setImages, setLabel, setLabelVisible, setLock, setMousePressed, setMoveable, setParent, setPosition, setSize, setSize, setSprite, setTab, setTab, setUpdate, setUserInteraction, setValueLabel, setVisible, setWindow, setWindow, show, stringValue, toString, trigger, unlock, unplugFrom, unplugFrom, updateAbsolutePosition, updateEvents, updateSize, value, valueLabel
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIX

public static final int FIX
See Also:
Constant Field Values

FLEXIBLE

public static final int FLEXIBLE
See Also:
Constant Field Values

valueLabelPositioning

public int valueLabelPositioning
Constructor Detail

Slider

public Slider(ControlP5 theControlP5,
              ControllerGroup theParent,
              java.lang.String theName,
              float theMin,
              float theMax,
              float theDefaultValue,
              int theX,
              int theY,
              int theWidth,
              int theHeight)
Parameters:
theControlP5 - ControlP5
theParent - ControllerGroup
theName - String
theMin - float
theMax - float
theDefaultValue - float
theX - int
theY - int
theWidth - int
theHeight - int
+Example
/**
 * ControlP5 Slider. Horizontal and vertical sliders, 
 * with and without tick marks and snap-to-tick.
 * by andreas schlegel, 2010
 */

import controlP5.*;

ControlP5 controlP5;
int myColor = color(0,0,0);

int sliderValue = 100;
int sliderTicks1 = 100;
int sliderTicks2 = 30;


void setup() {
  size(400,400);
  controlP5 = new ControlP5(this);
  // add a vertical slider
  controlP5.addSlider("slider",0,200,128,20,100,10,100);
  // create another slider with tick marks, now without
  // default value, the initial value will be set according th
  // the value of variable sliderTicks2 then.
  controlP5.addSlider("sliderTicks1",0,255,100,100,10,100);
  Slider s1 = (Slider)controlP5.controller("sliderTicks1");
  s1.setNumberOfTickMarks(5);
  
  
  // add horizontal sliders
  controlP5.addSlider("sliderValue",0,255,128,200,180,100,10);
  controlP5.addSlider("sliderTicks2",0,255,128,200,220,100,10);
  Slider s2 = (Slider)controlP5.controller("sliderTicks2");
  s2.setNumberOfTickMarks(7);
  // use Slider.FIX or Slider.FLEXIBLE to change the slider handle
  // by default it is Slider.FIX
  s2.setSliderMode(Slider.FLEXIBLE);
  
}

void draw() {
  background(sliderTicks1);
  
  fill(sliderValue);
  rect(0,0,width,100);
  
  fill(myColor);
  rect(0,300,width,70);
  
  fill(sliderTicks2);
  rect(0,370,width,30);
}

void slider(float theColor) {
  myColor = color(theColor);
  println("a slider event. setting background to "+theColor);
}

Method Detail

setSliderMode

public void setSliderMode(int theMode)
use the slider mode to set the mode of the slider bar, which can be Slider.FLEXIBLE or Slider.FIX

Parameters:
theMode - int

updateInternalEvents

public void updateInternalEvents(processing.core.PApplet theApplet)
Description copied from class: Controller
TODO

Specified by:
updateInternalEvents in interface ControllerInterface
Overrides:
updateInternalEvents in class Controller
See Also:
ControllerInterface.updateInternalEvents

setValue

public void setValue(float theValue)
set the value of the slider.

Specified by:
setValue in class Controller
Parameters:
theValue - float

update

public void update()
Description copied from class: Controller
updates the value of the controller without having to set the value explicitly. update does not visually update the controller. the updating status can be set with setUpdate(true/false) and checked with isUpdate(). setUpdate ( )

Specified by:
update in interface ControllerInterface
Overrides:
update in class Controller

setMin

public void setMin(float theValue)
set the minimum value of the slider.

Overrides:
setMin in class Controller
Parameters:
theValue - float

setMax

public void setMax(float theValue)
set the maximum value of the slider.

Overrides:
setMax in class Controller
Parameters:
theValue - float

setWidth

public Controller setWidth(int theValue)
set the width of the slider.

Overrides:
setWidth in class Controller
Parameters:
theValue - int

setHeight

public Controller setHeight(int theValue)
set the height of the slider.

Overrides:
setHeight in class Controller
Parameters:
theValue - int

addToXMLElement

public void addToXMLElement(ControlP5XMLElement theElement)
Parameters:
theElement - ControlP5XMLElement

onEnter

public void onEnter()

onLeave

public void onLeave()

setNumberOfTickMarks

public void setNumberOfTickMarks(int theNumber)

getNumberOfTickMarks

public int getNumberOfTickMarks()

showTickMarks

public void showTickMarks(boolean theFlag)

snapToTickMarks

public void snapToTickMarks(boolean theFlag)

getTickMark

public TickMark getTickMark(int theIndex)

getTickMarks

public java.util.ArrayList<TickMark> getTickMarks()

alignValueLabel

public void alignValueLabel(int theValue)
use static variables ControlP5.TOP, ControlP5.CENTER, ControlP5.BOTTOM to align the ValueLabel of a slider.

Parameters:
theValue -

linebreak

public Controller linebreak()
Overrides:
linebreak in class Controller

updateDisplayMode

public void updateDisplayMode(int theMode)


processing library controlP5 by Andreas Schlegel. (c) 2010