Slider
Slider
class Slider{
float x,y; //position
float w, h; //size
String label;
float min, max; //end points of range
float sliderX; //mouseX when slider value changes
float sliderVal; //calculate using the map function
float hue, sat, bright; //IMPORTANT REMEMBER THESE ALL HAVE VALUE of 0.0
//CONSTRUCTOR
Slider(float x, float y, float w, float h, float min, float max, String label ){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.min = min;
this.max = max;
this.label = label;
sliderX = x + w/2.0 ;
sliderVal = map( sliderX, x, x+w, min, max);
}
//Behaviors - Methods
void backgroundLayer(){
fill( 200);
noStroke();
rect( x-5, y-28,w+10, h+34); //larger than inner slider
fill(0); //text color
textAlign( RIGHT);
textSize(10);
text( label,x+w, y-16);
}
void display( ){
backgroundLayer( );
fill( 150);
rect( x,y,w,h);
//indicator rectangle
fill(0);//black
rect( sliderX-2, y-3, 4, h+6);
textSize(10);
text( (int)sliderVal, sliderX+2, y-4);
}
boolean checkPressed( int mx, int my){
boolean changed = false;
if( mx > x && mx < x+w && my> y && my< y+h){
sliderX = mx;
sliderVal = map( sliderX, x, x+w, min, max);
changed = true;
} //end if
return changed;
}//end checkPressed
} //end class sliderMain Tab Code:
HueSlider
SatSlider
Last updated