src updates, adding Background and Icon

This commit is contained in:
sojamo 2014-09-08 15:30:57 +08:00
parent c7a75ff6cb
commit a1c209a716
13 changed files with 541 additions and 81 deletions

View File

@ -0,0 +1,12 @@
package controlP5;
public class Background extends ControlGroup< Background > {
public Background( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , int theX , int theY , int theW , int theH ) {
super( theControlP5 , theParent , theName , theX , theY , theW , theH );
hideBar( );
setBackgroundColor( 0x55000000 );
setSize(theW, theH);
}
}

View File

@ -77,7 +77,7 @@ public class Button extends Controller< Button > {
@Override protected void onLeave( ) { @Override protected void onLeave( ) {
isActive = false; isActive = false;
setIsInside( false ); // TODO setIsInside needs to be set false here if we remove setIsInside from activate; see below. setIsInside( false );
} }
/** /**
@ -122,9 +122,6 @@ public class Button extends Controller< Button > {
protected void activate( ) { protected void activate( ) {
if ( isActive ) { if ( isActive ) {
isActive = false; isActive = false;
if ( getParent( ) instanceof Tab ) {
//setIsInside( false ); // TODO why do we setIsInside to false here?
}
isOn = !isOn; isOn = !isOn;
setValue( _myValue ); setValue( _myValue );
@ -158,13 +155,14 @@ public class Button extends Controller< Button > {
* Turns a button into a switch, or use a Toggle * Turns a button into a switch, or use a Toggle
* instead. * instead.
* *
* @see controlP5.Toggle
* @param theFlag turns the button into a switch when
* true
* @return Button
*/ */
public Button setSwitch( boolean theFlag ) { public Button setSwitch( boolean theFlag ) {
isSwitch = theFlag; isSwitch = theFlag;
if ( isSwitch ) {
_myBroadcastType = BOOLEAN;
} else {
_myBroadcastType = FLOAT;
}
return this; return this;
} }
@ -209,6 +207,10 @@ public class Button extends Controller< Button > {
return isOn; return isOn;
} }
public boolean isSwitch( ) {
return isSwitch;
}
/** /**
* @return boolean * @return boolean
*/ */
@ -312,5 +314,4 @@ public class Button extends Controller< Button > {
return super.toString( ) + " [ " + getValue( ) + " ] " + "Button" + " (" + this.getClass( ).getSuperclass( ) + ")"; return super.toString( ) + " [ " + getValue( ) + " ] " + "Button" + " (" + this.getClass( ).getSuperclass( ) + ")";
} }
} }

View File

@ -43,6 +43,8 @@ public class Chart extends Controller< Chart > {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight ); super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
setRange( 0 , theHeight ); setRange( 0 , theHeight );
_myDataSet = new LinkedHashMap< String , ChartDataSet >( ); _myDataSet = new LinkedHashMap< String , ChartDataSet >( );
getCaptionLabel( ).align( LEFT, BOTTOM_OUTSIDE ).paddingX = 0;
} }
public Chart setRange( float theMin , float theMax ) { public Chart setRange( float theMin , float theMax ) {
@ -418,6 +420,7 @@ public class Chart extends Controller< Chart > {
} }
theGraphics.noStroke( ); theGraphics.noStroke( );
theGraphics.popStyle( ); theGraphics.popStyle( );
getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController );
} }
} }

View File

@ -259,7 +259,6 @@ public class ControlBroadcaster {
} }
public ControlBroadcaster broadcast( final ControlEvent theControlEvent , final int theType ) { public ControlBroadcaster broadcast( final ControlEvent theControlEvent , final int theType ) {
if ( broadcast ) { if ( broadcast ) {
for ( ControlListener cl : _myControlListeners ) { for ( ControlListener cl : _myControlListeners ) {
cl.controlEvent( theControlEvent ); cl.controlEvent( theControlEvent );
@ -274,6 +273,17 @@ public class ControlBroadcaster {
} }
} else if ( theType == ControlP5Constants.ARRAY ) { } else if ( theType == ControlP5Constants.ARRAY ) {
} else if ( theType == ControlP5Constants.BOOLEAN ) {
for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) {
Controller controller = theControlEvent.getController( );
if ( controller instanceof Icon ) {
callTarget( cp , ( ( Icon ) controller ).getBooleanValue( ) );
} else if ( controller instanceof Button ) {
callTarget( cp , ( ( Button ) controller ).getBooleanValue( ) );
} else if ( controller instanceof Toggle ) {
callTarget( cp , ( ( Toggle ) controller ).getBooleanValue( ) );
}
}
} else { } else {
for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) { for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) {
@ -295,7 +305,6 @@ public class ControlBroadcaster {
protected void callTarget( final ControllerPlug thePlug , final float theValue ) { protected void callTarget( final ControllerPlug thePlug , final float theValue ) {
if ( thePlug.checkType( ControlP5Constants.METHOD ) ) { if ( thePlug.checkType( ControlP5Constants.METHOD ) ) {
invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , thePlug.getMethodParameter( theValue ) ); invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , thePlug.getMethodParameter( theValue ) );
} else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) { } else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) {
invokeField( thePlug.getObject( ) , thePlug.getField( ) , thePlug.getFieldParameter( theValue ) ); invokeField( thePlug.getObject( ) , thePlug.getField( ) , thePlug.getFieldParameter( theValue ) );
@ -310,6 +319,14 @@ public class ControlBroadcaster {
} }
} }
protected void callTarget( final ControllerPlug thePlug , final boolean theValue ) {
if ( thePlug.checkType( ControlP5Constants.METHOD ) ) {
invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , new Object[] { theValue } );
} else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) {
invokeField( thePlug.getObject( ) , thePlug.getField( ) , theValue );
}
}
private void invokeField( final Object theObject , final Field theField , final Object theParam ) { private void invokeField( final Object theObject , final Field theField , final Object theParam ) {
try { try {
theField.set( theObject , theParam ); theField.set( theObject , theParam );
@ -386,8 +403,7 @@ public class ControlBroadcaster {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@Override @Override public EmptyController setValue( float theValue ) {
public EmptyController setValue( float theValue ) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return this; return this;
} }
@ -397,8 +413,7 @@ public class ControlBroadcaster {
/** /**
* @exclude * @exclude
*/ */
@Deprecated @Deprecated public void plug( final String theControllerName , final String theTargetMethod ) {
public void plug( final String theControllerName , final String theTargetMethod ) {
plug( cp5.papplet , theControllerName , theTargetMethod ); plug( cp5.papplet , theControllerName , theTargetMethod );
} }
} }

View File

@ -25,6 +25,16 @@ public class ControlP5Legacy {
return myController; return myController;
} }
public Background addBackground( final String theName ) {
return addBackground( null , "" , theName , 0 , 0 , 300 , base.cp5.papplet.height );
}
public Background addBackground( Object theObject , final String theIndex , String theName , int theX , int theY , int theW , int theHeight ) {
Background myController = new Background( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theHeight );
base.cp5.register( theObject , theIndex , myController );
return myController;
}
public Button addButton( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) { public Button addButton( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
Button myController = new Button( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theValue , theX , theY , theW , theH ); Button myController = new Button( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController ); base.cp5.register( theObject , theIndex , myController );
@ -33,6 +43,14 @@ public class ControlP5Legacy {
return myController; return myController;
} }
public Icon addIcon( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
Icon myController = new Icon( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theValue , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController );
myController.registerProperty( "value" );
myController.getProperty( "value" ).disable( );
return myController;
}
public ButtonBar addButtonBar( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) { public ButtonBar addButtonBar( final Object theObject , String theIndex , final String theName , final float theValue , final int theX , final int theY , final int theW , final int theH ) {
ButtonBar myController = new ButtonBar( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH ); ButtonBar myController = new ButtonBar( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH );
base.cp5.register( theObject , theIndex , myController ); base.cp5.register( theObject , theIndex , myController );
@ -425,6 +443,23 @@ public class ControlP5Legacy {
return b; return b;
} }
public Icon addIcon( Object theObject , final String theIndex , String theName ) {
return addIcon( theObject , theIndex , theName , 1 );
}
public Icon addIcon( String theName , float theValue ) {
return addIcon( null , "" , theName , theValue );
}
public Icon addIcon( Object theObject , final String theIndex , String theName , float theValue ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition );
Icon icon = addIcon( theObject , theIndex , theName , theValue , x , y , Icon.autoWidth , Icon.autoHeight );
base.linebreak( icon , false , Icon.autoWidth , Icon.autoHeight , Icon.autoSpacing );
icon.moveTo( base.currentGroupPointer );
return icon;
}
public Bang addBang( Object theObject , final String theIndex , String theName ) { public Bang addBang( Object theObject , final String theIndex , String theName ) {
int x = ( int ) x( base.currentGroupPointer.autoPosition ); int x = ( int ) x( base.currentGroupPointer.autoPosition );
int y = ( int ) y( base.currentGroupPointer.autoPosition ); int y = ( int ) y( base.currentGroupPointer.autoPosition );

View File

@ -1344,7 +1344,6 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra
return me; return me;
} }
/** /**
* @param theValue float * @param theValue float
*/ */

380
src/controlP5/Icon.java Normal file
View File

@ -0,0 +1,380 @@
package controlP5;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphics;
public class Icon extends Controller< Icon > {
protected boolean isPressed;
protected boolean isOn = false;
public static int autoWidth = 69;
public static int autoHeight = 19;
protected int activateBy = RELEASE;
protected boolean isSwitch = false;
protected int roundedCorners = 0;
protected boolean isFill = true;
protected boolean isStroke = false;
protected float scl = 1;
protected int[] fontIcons = new int[] { -1 , -1 , -1 , -1 };
protected boolean isHideBackground = true;
protected float strokeWeight = 1;
protected float scalePressed = 1.0f;
protected float scaleReleased = 1.0f;
public Icon( ControlP5 theControlP5 , String theName ) {
this( theControlP5 , theControlP5.getDefaultTab( ) , theName , 0 , 0 , 0 , autoWidth , autoHeight );
theControlP5.register( theControlP5.papplet , theName , this );
}
protected Icon( ControlP5 theControlP5 , ControllerGroup< ? > theParent , String theName , float theDefaultValue , int theX , int theY , int theWidth , int theHeight ) {
super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight );
_myValue = theDefaultValue;
_myCaptionLabel.align( CENTER , CENTER );
}
@Override protected void onEnter( ) {
isActive = true;
}
@Override protected void onLeave( ) {
isActive = false;
setIsInside( false );
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mousePressed( ) {
isActive = getIsInside( );
isPressed = true;
if ( activateBy == PRESSED ) {
activate( );
}
scl = scalePressed;
}
/**
* @exclude
*/
@Override @ControlP5.Invisible public void mouseReleased( ) {
isPressed = false;
if ( activateBy == RELEASE ) {
activate( );
}
isActive = false;
scl = scaleReleased;
}
/**
* A Icon can be activated by a mouse PRESSED or mouse
* RELEASE. Default value is RELEASE.
*/
public Icon activateBy( int theValue ) {
if ( theValue == PRESS ) {
activateBy = PRESS;
} else {
activateBy = RELEASE;
}
return this;
}
protected void activate( ) {
if ( isActive ) {
isActive = false;
isOn = !isOn;
setValue( _myValue );
}
}
@Override @ControlP5.Invisible public void mouseReleasedOutside( ) {
mouseReleased( );
}
@Override public Icon setValue( float theValue ) {
_myValue = theValue;
broadcast( FLOAT );
return this;
}
@Override public Icon update( ) {
return setValue( _myValue );
}
/**
* Turns an icon into a switch.
*/
public Icon setSwitch( boolean theFlag ) {
isSwitch = theFlag;
if ( isSwitch ) {
_myBroadcastType = BOOLEAN;
} else {
_myBroadcastType = FLOAT;
}
return this;
}
/**
* If the Icon acts as a switch, setOn will turn on
* the switch. Use
* {@link controlP5.Icon#setSwitch(boolean) setSwitch}
* to turn a Icon into a Switch.
*/
public Icon setOn( ) {
if ( isSwitch ) {
isOn = false;
isActive = true;
activate( );
}
return this;
}
/**
* If the Icon acts as a switch, setOff will turn off
* the switch. Use
* {@link controlP5.Icon#setSwitch(boolean) setSwitch}
* to turn a Icon into a Switch.
*/
public Icon setOff( ) {
if ( isSwitch ) {
isOn = true;
isActive = true;
activate( );
}
return this;
}
public boolean isOn( ) {
return isOn;
}
public boolean isSwitch( ) {
return isSwitch;
}
public boolean isPressed( ) {
return isPressed;
}
/**
* Returns true or false and indicates the switch state
* of the Icon. {@link setSwitch(boolean) setSwitch}
* should have been set before.
*/
public boolean getBooleanValue( ) {
return isOn;
}
public Icon setRoundedCorners( int theRadius ) {
roundedCorners = theRadius;
return this;
}
public Icon setFontIconSize( int theSize ) {
_myCaptionLabel.setSize( theSize );
return this;
}
public Icon setFont( PFont thePFont ) {
_myCaptionLabel.setFont( thePFont );
return this;
}
public Icon setFont( PFont thePFont , int theSize ) {
_myCaptionLabel.setFont( thePFont );
setFontIconSize( theSize );
return this;
}
public Icon setFontIndex( int theIndex ) {
_myCaptionLabel.set( "" + ( char ) theIndex );
return this;
}
public Icon setStroke( boolean theBoolean ) {
isStroke = theBoolean;
return this;
}
public Icon setStrokeWeight( float theStrokeWeight ) {
strokeWeight = theStrokeWeight;
return this;
}
public Icon setFill( boolean theBoolean ) {
isFill = theBoolean;
return this;
}
public Icon setFontIcons( int theStateOff , int theStateOn ) {
setFontIcon( theStateOn , ACTIVE );
setFontIcon( theStateOff , DEFAULT );
return this;
}
public Icon setFontIconOn( int theStateOn ) {
setFontIcon( theStateOn , ACTIVE );
return this;
}
public Icon setFontIconOff( int theStateOff ) {
setFontIcon( theStateOff , DEFAULT );
return this;
}
public Icon setFontIcons( int ... theIds ) {
if ( theIds.length < 3 || theIds.length > 4 ) {
return this;
}
setFontIcon( theIds[ 0 ] , DEFAULT );
setFontIcon( theIds[ 1 ] , OVER );
setFontIcon( theIds[ 2 ] , ACTIVE );
setFontIcon( theIds.length == 3 ? theIds[ 2 ] : theIds[ 3 ] , HIGHLIGHT );
return this;
}
public Icon setFontIcon( int theId ) {
return setFontIcon( theId , DEFAULT );
}
public int getFontIcon( int theState ) {
if ( theState >= 0 && theState < 4 ) {
return fontIcons[ theState ];
} else {
return fontIcons[ DEFAULT ];
}
}
/**
* @param theImage
* @param theState use Controller.DEFAULT (background) Controller.OVER (foreground) Controller.ACTIVE (active)
*/
public Icon setFontIcon( int theId , int theState ) {
fontIcons[ theState ] = theId;
updateDisplayMode( DEFAULT );
return this;
}
public Icon hideBackground( ) {
isHideBackground = true;
return this;
}
public Icon showBackground( ) {
isHideBackground = false;
return this;
}
public Icon setScale( float theScalePressed , float theScaleReleased ) {
scalePressed = theScalePressed;
scaleReleased = theScaleReleased;
return this;
}
@Override @ControlP5.Invisible public Icon updateDisplayMode( int theMode ) {
return updateViewMode( theMode );
}
/**
* @exclude
*/
@ControlP5.Invisible public Icon updateViewMode( int theMode ) {
_myDisplayMode = theMode;
switch ( theMode ) {
case ( DEFAULT ):
_myControllerView = new IconView( );
break;
case ( IMAGE ):
_myControllerView = new IconImageView( );
break;
case ( CUSTOM ):
default:
break;
}
return this;
}
private class IconView implements ControllerView< Icon > {
public void display( PGraphics theGraphics , Icon theController ) {
if ( !isHideBackground ) {
if ( isStroke ) {
theGraphics.stroke( color.getBackground( ) );
theGraphics.strokeWeight( strokeWeight );
} else {
theGraphics.noStroke( );
}
if ( isFill ) {
theGraphics.fill( color.getBackground( ) );
} else {
theGraphics.noFill( );
}
}
float w_half = getWidth( ) / 2;
float h_half = getHeight( ) / 2;
theGraphics.translate( w_half , h_half );
theGraphics.scale( scl );
if ( !isHideBackground ) {
if ( roundedCorners == 0 ) {
theGraphics.rect( -w_half , -h_half , getWidth( ) , getHeight( ) );
} else if ( roundedCorners == -1 ) {
theGraphics.ellipseMode(PApplet.CORNER);
theGraphics.ellipse( -w_half , -h_half , getWidth( ) , getHeight( ) );
} else {
theGraphics.rect( -w_half , -h_half , getWidth( ) , getHeight( ) , roundedCorners , roundedCorners , roundedCorners , roundedCorners );
}
}
if ( isSwitch ) {
if ( !isOn ) {
setFontIndex( getFontIcon( ACTIVE ) );
} else {
setFontIndex( getFontIcon( DEFAULT ) );
}
} else {
setFontIndex( getFontIcon( DEFAULT ) );
}
_myCaptionLabel.setColor( isOn && isSwitch || isPressed && !isSwitch ? color.getActive( ) : color.getForeground( ) );
_myCaptionLabel.draw( theGraphics , -( int ) w_half , -( int ) ( h_half * 1.05f ) , theController );
}
}
private class IconImageView implements ControllerView< Icon > {
public void display( PGraphics theGraphics , Icon theController ) {
float w_half = getWidth( ) / 2;
float h_half = getHeight( ) / 2;
theGraphics.translate( w_half , h_half );
theGraphics.scale( scl );
if ( isOn && isSwitch ) {
theGraphics.image( ( availableImages[ HIGHLIGHT ] == true ) ? images[ HIGHLIGHT ] : images[ DEFAULT ] , -w_half , -h_half );
return;
}
if ( getIsInside( ) ) {
if ( isPressed ) {
theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[ DEFAULT ] , -w_half , -h_half );
} else {
theGraphics.image( ( availableImages[ OVER ] == true ) ? images[ OVER ] : images[ DEFAULT ] , -w_half , -h_half );
}
} else {
theGraphics.image( images[ DEFAULT ] , -w_half , -h_half );
}
}
}
@Override public String getInfo( ) {
return "type:\tIcon\n" + super.getInfo( );
}
@Override public String toString( ) {
return super.toString( ) + " [ " + getValue( ) + " ] " + "Icon" + " (" + this.getClass( ).getSuperclass( ) + ")";
}
}

View File

@ -30,7 +30,7 @@ import processing.core.PGraphics;
/** /**
* A knob is a circular slider which can be used with a limited and unlimited range. Knobs come in 3 * A knob is a circular slider which can be used with a limited and unlimited range. Knobs come in 3
* designs LINE, ARC and ELIPSE and can be controller with both the mouse and the mouse wheel. * designs LINE, ARC and ELLIPSE and can be controller with both the mouse and the mouse wheel.
* *
* @example controllers/ControlP5knob * @example controllers/ControlP5knob
*/ */

View File

@ -117,14 +117,13 @@ public class Matrix extends Controller< Matrix > {
return _myInterval; return _myInterval;
} }
@ControlP5.Invisible @ControlP5.Invisible public Matrix updateInternalEvents( PApplet theApplet ) {
public Matrix updateInternalEvents( PApplet theApplet ) {
setIsInside( inside( ) ); setIsInside( inside( ) );
if ( getIsInside( ) ) { if ( getIsInside( ) ) {
if ( isPressed ) { if ( isPressed ) {
int tX = ( int ) ( ( theApplet.mouseX - x(position) ) / stepX ); int tX = ( int ) ( ( theApplet.mouseX - x( position ) ) / stepX );
int tY = ( int ) ( ( theApplet.mouseY - y(position) ) / stepY ); int tY = ( int ) ( ( theApplet.mouseY - y( position ) ) / stepY );
if ( tX != currentX || tY != currentY ) { if ( tX != currentX || tY != currentY ) {
tX = PApplet.min( PApplet.max( 0 , tX ) , _myCellX ); tX = PApplet.min( PApplet.max( 0 , tX ) , _myCellX );
@ -164,8 +163,7 @@ public class Matrix extends Controller< Matrix > {
isActive = false; isActive = false;
} }
@ControlP5.Invisible @ControlP5.Invisible public void mousePressed( ) {
public void mousePressed( ) {
isActive = getIsInside( ); isActive = getIsInside( );
if ( getIsInside( ) ) { if ( getIsInside( ) ) {
isPressed = true; isPressed = true;
@ -176,8 +174,7 @@ public class Matrix extends Controller< Matrix > {
mouseReleased( ); mouseReleased( );
} }
@ControlP5.Invisible @ControlP5.Invisible public void mouseReleased( ) {
public void mouseReleased( ) {
if ( isActive ) { if ( isActive ) {
isActive = false; isActive = false;
} }
@ -186,8 +183,7 @@ public class Matrix extends Controller< Matrix > {
currentY = -1; currentY = -1;
} }
@Override @Override public Matrix setValue( float theValue ) {
public Matrix setValue( float theValue ) {
_myValue = theValue; _myValue = theValue;
broadcast( FLOAT ); broadcast( FLOAT );
return this; return this;
@ -232,7 +228,7 @@ public class Matrix extends Controller< Matrix > {
} catch ( SecurityException ex ) { } catch ( SecurityException ex ) {
ex.printStackTrace( ); ex.printStackTrace( );
} catch ( NoSuchMethodException ex ) { } catch ( NoSuchMethodException ex ) {
ex.printStackTrace( ); //ex.printStackTrace( );
} catch ( IllegalArgumentException ex ) { } catch ( IllegalArgumentException ex ) {
ex.printStackTrace( ); ex.printStackTrace( );
} catch ( IllegalAccessException ex ) { } catch ( IllegalAccessException ex ) {
@ -245,8 +241,7 @@ public class Matrix extends Controller< Matrix > {
return this; return this;
} }
@Override @Override public Matrix update( ) {
public Matrix update( ) {
return setValue( _myValue ); return setValue( _myValue );
} }
@ -346,8 +341,7 @@ public class Matrix extends Controller< Matrix > {
} }
} }
@Override @Override public void remove( ) {
public void remove( ) {
if ( t != null ) { if ( t != null ) {
t.interrupt( ); t.interrupt( );
} }
@ -377,9 +371,7 @@ public class Matrix extends Controller< Matrix > {
return this; return this;
} }
@Override @Override @ControlP5.Invisible public Matrix updateDisplayMode( int theMode ) {
@ControlP5.Invisible
public Matrix updateDisplayMode( int theMode ) {
_myDisplayMode = theMode; _myDisplayMode = theMode;
switch ( theMode ) { switch ( theMode ) {
case ( DEFAULT ): case ( DEFAULT ):
@ -400,16 +392,14 @@ public class Matrix extends Controller< Matrix > {
theGraphics.noStroke( ); theGraphics.noStroke( );
theGraphics.fill( bg ); theGraphics.fill( bg );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) ); theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
float gx = gapX / 2;
float gy = gapY / 2;
for ( int x = 0 ; x < _myCellX ; x++ ) { for ( int x = 0 ; x < _myCellX ; x++ ) {
for ( int y = 0 ; y < _myCellY ; y++ ) { for ( int y = 0 ; y < _myCellY ; y++ ) {
if ( _myCells[ x ][ y ] == 1 ) { theGraphics.fill( _myCells[ x ][ y ] == 1 ? color.getActive( ) : color.getBackground( ) );
theGraphics.fill( color.getActive( ) ); theGraphics.rect( x * stepX + gx , y * stepY + gy , stepX - gapX , stepY - gapY );
theGraphics.rect( x * stepX , y * stepY , stepX - gapX , stepY - gapY );
} else {
theGraphics.fill( color.getBackground( ) );
theGraphics.rect( x * stepX , y * stepY , stepX - gapX , stepY - gapY );
}
} }
} }
if ( isInside( ) ) { if ( isInside( ) ) {

View File

@ -67,6 +67,14 @@ public class Slider2D extends Controller< Slider2D > {
return setValue( 0 ); return setValue( 0 );
} }
public Slider2D setMinMax( float theMinX , float theMinY , float theMaxX , float theMaxY ) {
_myMinX = theMinX;
_myMinY = theMinY;
_myMaxX = theMaxX;
_myMaxY = theMaxY;
return setValue( _myArrayValue[ 0 ] , _myArrayValue[ 1 ] );
}
/** /**
* sets the minimum value for the x-axis * sets the minimum value for the x-axis
* *
@ -190,6 +198,12 @@ public class Slider2D extends Controller< Slider2D > {
return this; return this;
} }
public Slider2D setValue( float theValue1 , float theValue2 ) {
cursorX = PApplet.map( theValue1 , _myMinX , _myMaxX , 0 , getWidth( ) - cursorWidth );
cursorY = PApplet.map( theValue2 , _myMinY , _myMaxY , 0 , getHeight( ) - cursorHeight );
return setValue( 0 );
}
/** /**
* assigns a random value to the controller. * assigns a random value to the controller.
*/ */

View File

@ -320,8 +320,14 @@ public class Textfield extends Controller< Textfield > {
_myValueLabel.setText( text ); _myValueLabel.setText( text );
_myValueLabel.draw( buffer , -dif , 0 , this ); _myValueLabel.draw( buffer , -dif , 0 , this );
buffer.noStroke( ); buffer.noStroke( );
if ( isTexfieldActive ) {
if ( !cp5.papplet.keyPressed ) {
buffer.fill( _myColorCursor , PApplet.abs( PApplet.sin( cp5.papplet.frameCount * 0.05f )) * 255 );
} else {
buffer.fill( _myColorCursor ); buffer.fill( _myColorCursor );
}
buffer.rect( PApplet.max( 1 , PApplet.min( _myTextBufferIndexPosition , _myValueLabel.getWidth( ) - 3 ) ) , 0 , 1 , getHeight( ) ); buffer.rect( PApplet.max( 1 , PApplet.min( _myTextBufferIndexPosition , _myValueLabel.getWidth( ) - 3 ) ) , 0 , 1 , getHeight( ) );
}
buffer.endDraw( ); buffer.endDraw( );
theGraphics.image( buffer , 0 , 0 ); theGraphics.image( buffer , 0 , 0 );

View File

@ -37,15 +37,10 @@ import processing.core.PImage;
public class Toggle extends Controller< Toggle > { public class Toggle extends Controller< Toggle > {
protected int cnt; protected int cnt;
protected boolean isOn = false; protected boolean isOn = false;
protected float internalValue = -1; protected float internalValue = -1;
public static int autoWidth = 39; public static int autoWidth = 39;
public static int autoHeight = 19; public static int autoHeight = 19;
protected float[] autoSpacing = new float[] { 10 , 20 }; protected float[] autoSpacing = new float[] { 10 , 20 };
/** /**
@ -72,7 +67,7 @@ public class Toggle extends Controller< Toggle > {
*/ */
@ControlP5.Invisible public void draw( PGraphics theGraphics ) { @ControlP5.Invisible public void draw( PGraphics theGraphics ) {
theGraphics.pushMatrix( ); theGraphics.pushMatrix( );
theGraphics.translate( x(position) , y(position) ); theGraphics.translate( x( position ) , y( position ) );
_myControllerView.display( theGraphics , this ); _myControllerView.display( theGraphics , this );
theGraphics.popMatrix( ); theGraphics.popMatrix( );
} }
@ -113,6 +108,10 @@ public class Toggle extends Controller< Toggle > {
return this; return this;
} }
public boolean getBooleanValue( ) {
return getState( );
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -132,10 +131,6 @@ public class Toggle extends Controller< Toggle > {
return this; return this;
} }
/**
*
* @return
*/
public boolean getState( ) { public boolean getState( ) {
return isOn; return isOn;
} }
@ -245,18 +240,11 @@ public class Toggle extends Controller< Toggle > {
public void display( PGraphics theGraphics , Toggle theController ) { public void display( PGraphics theGraphics , Toggle theController ) {
// if ( isActive ) {
// theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[
// DEFAULT ] , 0 , 0 );
// } else {
if ( isOn ) { if ( isOn ) {
theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 ); theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 );
} else { } else {
theGraphics.image( images[ DEFAULT ] , 0 , 0 ); theGraphics.image( images[ DEFAULT ] , 0 , 0 );
} }
// }
//theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
} }
} }
@ -265,9 +253,7 @@ public class Toggle extends Controller< Toggle > {
public void display( PGraphics theGraphics , Toggle theController ) { public void display( PGraphics theGraphics , Toggle theController ) {
theGraphics.fill( color.getBackground( ) ); theGraphics.fill( color.getBackground( ) );
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) ); theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
theGraphics.fill( color.getActive( ) ); theGraphics.fill( color.getActive( ) );
if ( isOn ) { if ( isOn ) {

View File

@ -1,3 +1,22 @@
2014-09-08 Andreas Schlegel <andi at sojamo.de>
* src controlP5.Icon:
adding Icon class, acts like a button; can be used with images and font-icons
from "Font Awesome".
* src controlP5.Button:
when theButton acts as a switch (setSwitch(true)), the corresponding
method inside a sketch should use type boolean as argument instead of float;
a java.lang.IllegalArgumentException will be thrown in case of a float argument
2014-08-28 Andreas Schlegel <andi at sojamo.de>
* src controlP5.Background:
adding Background class, a convenience class for grouping controllers with
the top bar disabled by default.
2014-07-21 Andreas Schlegel <andi at sojamo.de> 2014-07-21 Andreas Schlegel <andi at sojamo.de>
* src controlP5.Textfield: * src controlP5.Textfield: