2014-07-22 08:12:30 +02:00
|
|
|
package controlP5;
|
|
|
|
|
|
|
|
import processing.core.PGraphics;
|
|
|
|
|
|
|
|
public class Spacer extends Controller< Spacer > {
|
|
|
|
|
|
|
|
private int _myWeight = 1;
|
|
|
|
|
|
|
|
public Spacer( ControlP5 theControlP5 , String theName ) {
|
|
|
|
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 20 , 20 );
|
|
|
|
theControlP5.register( theControlP5.papplet , theName , this );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Spacer( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theX , float theY , int theWidth , int theHeight ) {
|
|
|
|
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
|
2014-08-15 05:19:30 +02:00
|
|
|
_myControllerView = new SpacerView( );
|
2014-07-22 08:12:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Spacer setWeight( int theWeight ) {
|
|
|
|
_myWeight = theWeight;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Spacer setColor( int theColor ) {
|
|
|
|
getColor( ).setForeground( theColor );
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-08-15 05:19:30 +02:00
|
|
|
private class SpacerView implements ControllerView< Spacer > {
|
2014-07-22 08:12:30 +02:00
|
|
|
|
|
|
|
public void display( PGraphics g , Spacer c ) {
|
|
|
|
g.fill( c.getColor( ).getForeground( ) );
|
|
|
|
g.noStroke( );
|
|
|
|
if ( c.getWidth( ) >= c.getHeight( ) ) {
|
|
|
|
g.rect( 0 , ( c.getHeight( ) / 2 ) - _myWeight / 2 , c.getWidth( ) , _myWeight );
|
|
|
|
} else {
|
|
|
|
g.rect( ( c.getWidth( ) / 2 ) - _myWeight / 2 , 0 , _myWeight , c.getHeight( ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|