From a1c209a7168d34084d89b2fb41bdd18bd5fd3360 Mon Sep 17 00:00:00 2001 From: sojamo Date: Mon, 8 Sep 2014 15:30:57 +0800 Subject: [PATCH] src updates, adding Background and Icon --- src/controlP5/Background.java | 12 + src/controlP5/Button.java | 19 +- src/controlP5/Chart.java | 3 + src/controlP5/ControlBroadcaster.java | 45 ++- src/controlP5/ControlP5Legacy.java | 35 +++ src/controlP5/Controller.java | 1 - src/controlP5/Icon.java | 380 ++++++++++++++++++++++++++ src/controlP5/Knob.java | 2 +- src/controlP5/Matrix.java | 58 ++-- src/controlP5/Slider2D.java | 14 + src/controlP5/Textfield.java | 10 +- src/controlP5/Toggle.java | 24 +- src/controlP5/changeLog.txt | 19 ++ 13 files changed, 541 insertions(+), 81 deletions(-) create mode 100644 src/controlP5/Background.java create mode 100644 src/controlP5/Icon.java diff --git a/src/controlP5/Background.java b/src/controlP5/Background.java new file mode 100644 index 0000000..10deb74 --- /dev/null +++ b/src/controlP5/Background.java @@ -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); + } + +} diff --git a/src/controlP5/Button.java b/src/controlP5/Button.java index 4513242..771b28f 100755 --- a/src/controlP5/Button.java +++ b/src/controlP5/Button.java @@ -77,7 +77,7 @@ public class Button extends Controller< Button > { @Override protected void onLeave( ) { 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( ) { if ( isActive ) { isActive = false; - if ( getParent( ) instanceof Tab ) { - //setIsInside( false ); // TODO why do we setIsInside to false here? - } isOn = !isOn; setValue( _myValue ); @@ -158,13 +155,14 @@ public class Button extends Controller< Button > { * Turns a button into a switch, or use a Toggle * instead. * - * @see controlP5.Toggle - * @param theFlag turns the button into a switch when - * true - * @return Button */ public Button setSwitch( boolean theFlag ) { isSwitch = theFlag; + if ( isSwitch ) { + _myBroadcastType = BOOLEAN; + } else { + _myBroadcastType = FLOAT; + } return this; } @@ -209,6 +207,10 @@ public class Button extends Controller< Button > { return isOn; } + public boolean isSwitch( ) { + return isSwitch; + } + /** * @return boolean */ @@ -312,5 +314,4 @@ public class Button extends Controller< Button > { return super.toString( ) + " [ " + getValue( ) + " ] " + "Button" + " (" + this.getClass( ).getSuperclass( ) + ")"; } - } \ No newline at end of file diff --git a/src/controlP5/Chart.java b/src/controlP5/Chart.java index 82b05fd..3999247 100755 --- a/src/controlP5/Chart.java +++ b/src/controlP5/Chart.java @@ -43,6 +43,8 @@ public class Chart extends Controller< Chart > { super( theControlP5 , theParent , theName , theX , theY , theWidth , theHeight ); setRange( 0 , theHeight ); _myDataSet = new LinkedHashMap< String , ChartDataSet >( ); + getCaptionLabel( ).align( LEFT, BOTTOM_OUTSIDE ).paddingX = 0; + } public Chart setRange( float theMin , float theMax ) { @@ -418,6 +420,7 @@ public class Chart extends Controller< Chart > { } theGraphics.noStroke( ); theGraphics.popStyle( ); + getCaptionLabel( ).draw( theGraphics , 0 , 0 , theController ); } } diff --git a/src/controlP5/ControlBroadcaster.java b/src/controlP5/ControlBroadcaster.java index bde78d4..d6ab0fa 100755 --- a/src/controlP5/ControlBroadcaster.java +++ b/src/controlP5/ControlBroadcaster.java @@ -2,9 +2,9 @@ package controlP5; /** * controlP5 is a processing gui library. - * - * 2006-2012 by Andreas Schlegel - * + * + * 2006-2012 by Andreas Schlegel + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 @@ -13,16 +13,16 @@ package controlP5; * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA - * - * @author Andreas Schlegel (http://www.sojamo.de) - * @modified ##date## - * @version ##version## - * + * + * @author Andreas Schlegel (http://www.sojamo.de) + * @modified ##date## + * @version ##version## + * */ import java.lang.reflect.Field; @@ -259,7 +259,6 @@ public class ControlBroadcaster { } public ControlBroadcaster broadcast( final ControlEvent theControlEvent , final int theType ) { - if ( broadcast ) { for ( ControlListener cl : _myControlListeners ) { cl.controlEvent( theControlEvent ); @@ -274,6 +273,17 @@ public class ControlBroadcaster { } } 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 { for ( ControllerPlug cp : theControlEvent.getController( ).getControllerPlugList( ) ) { @@ -295,7 +305,6 @@ public class ControlBroadcaster { protected void callTarget( final ControllerPlug thePlug , final float theValue ) { if ( thePlug.checkType( ControlP5Constants.METHOD ) ) { - invokeMethod( thePlug.getObject( ) , thePlug.getMethod( ) , thePlug.getMethodParameter( theValue ) ); } else if ( thePlug.checkType( ControlP5Constants.FIELD ) ) { 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 ) { try { theField.set( theObject , theParam ); @@ -386,8 +403,7 @@ public class ControlBroadcaster { // TODO Auto-generated constructor stub } - @Override - public EmptyController setValue( float theValue ) { + @Override public EmptyController setValue( float theValue ) { // TODO Auto-generated method stub return this; } @@ -397,8 +413,7 @@ public class ControlBroadcaster { /** * @exclude */ - @Deprecated - public void plug( final String theControllerName , final String theTargetMethod ) { + @Deprecated public void plug( final String theControllerName , final String theTargetMethod ) { plug( cp5.papplet , theControllerName , theTargetMethod ); } } diff --git a/src/controlP5/ControlP5Legacy.java b/src/controlP5/ControlP5Legacy.java index 64e9e57..67c7af8 100644 --- a/src/controlP5/ControlP5Legacy.java +++ b/src/controlP5/ControlP5Legacy.java @@ -25,6 +25,16 @@ public class ControlP5Legacy { 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 ) { 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 ); @@ -33,6 +43,14 @@ public class ControlP5Legacy { 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 ) { ButtonBar myController = new ButtonBar( base.cp5 , ( ControllerGroup< ? > ) base.cp5.controlWindow.getTabs( ).get( 1 ) , theName , theX , theY , theW , theH ); base.cp5.register( theObject , theIndex , myController ); @@ -425,6 +443,23 @@ public class ControlP5Legacy { 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 ) { int x = ( int ) x( base.currentGroupPointer.autoPosition ); int y = ( int ) y( base.currentGroupPointer.autoPosition ); diff --git a/src/controlP5/Controller.java b/src/controlP5/Controller.java index 6763c48..0b952ae 100755 --- a/src/controlP5/Controller.java +++ b/src/controlP5/Controller.java @@ -1344,7 +1344,6 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra return me; } - /** * @param theValue float */ diff --git a/src/controlP5/Icon.java b/src/controlP5/Icon.java new file mode 100644 index 0000000..c754728 --- /dev/null +++ b/src/controlP5/Icon.java @@ -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( ) + ")"; + } +} diff --git a/src/controlP5/Knob.java b/src/controlP5/Knob.java index 91ba6cb..2bf536a 100755 --- a/src/controlP5/Knob.java +++ b/src/controlP5/Knob.java @@ -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 - * 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 */ diff --git a/src/controlP5/Matrix.java b/src/controlP5/Matrix.java index dc2fce4..593bdf4 100755 --- a/src/controlP5/Matrix.java +++ b/src/controlP5/Matrix.java @@ -2,9 +2,9 @@ package controlP5; /** * controlP5 is a processing gui library. - * - * 2006-2012 by Andreas Schlegel - * + * + * 2006-2012 by Andreas Schlegel + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 @@ -13,16 +13,16 @@ package controlP5; * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA - * - * @author Andreas Schlegel (http://www.sojamo.de) - * @modified ##date## - * @version ##version## - * + * + * @author Andreas Schlegel (http://www.sojamo.de) + * @modified ##date## + * @version ##version## + * */ import java.lang.reflect.InvocationTargetException; @@ -117,14 +117,13 @@ public class Matrix extends Controller< Matrix > { return _myInterval; } - @ControlP5.Invisible - public Matrix updateInternalEvents( PApplet theApplet ) { + @ControlP5.Invisible public Matrix updateInternalEvents( PApplet theApplet ) { setIsInside( inside( ) ); if ( getIsInside( ) ) { if ( isPressed ) { - int tX = ( int ) ( ( theApplet.mouseX - x(position) ) / stepX ); - int tY = ( int ) ( ( theApplet.mouseY - y(position) ) / stepY ); + int tX = ( int ) ( ( theApplet.mouseX - x( position ) ) / stepX ); + int tY = ( int ) ( ( theApplet.mouseY - y( position ) ) / stepY ); if ( tX != currentX || tY != currentY ) { tX = PApplet.min( PApplet.max( 0 , tX ) , _myCellX ); @@ -164,8 +163,7 @@ public class Matrix extends Controller< Matrix > { isActive = false; } - @ControlP5.Invisible - public void mousePressed( ) { + @ControlP5.Invisible public void mousePressed( ) { isActive = getIsInside( ); if ( getIsInside( ) ) { isPressed = true; @@ -176,8 +174,7 @@ public class Matrix extends Controller< Matrix > { mouseReleased( ); } - @ControlP5.Invisible - public void mouseReleased( ) { + @ControlP5.Invisible public void mouseReleased( ) { if ( isActive ) { isActive = false; } @@ -186,8 +183,7 @@ public class Matrix extends Controller< Matrix > { currentY = -1; } - @Override - public Matrix setValue( float theValue ) { + @Override public Matrix setValue( float theValue ) { _myValue = theValue; broadcast( FLOAT ); return this; @@ -232,7 +228,7 @@ public class Matrix extends Controller< Matrix > { } catch ( SecurityException ex ) { ex.printStackTrace( ); } catch ( NoSuchMethodException ex ) { - ex.printStackTrace( ); + //ex.printStackTrace( ); } catch ( IllegalArgumentException ex ) { ex.printStackTrace( ); } catch ( IllegalAccessException ex ) { @@ -245,8 +241,7 @@ public class Matrix extends Controller< Matrix > { return this; } - @Override - public Matrix update( ) { + @Override public Matrix update( ) { return setValue( _myValue ); } @@ -346,8 +341,7 @@ public class Matrix extends Controller< Matrix > { } } - @Override - public void remove( ) { + @Override public void remove( ) { if ( t != null ) { t.interrupt( ); } @@ -377,9 +371,7 @@ public class Matrix extends Controller< Matrix > { return this; } - @Override - @ControlP5.Invisible - public Matrix updateDisplayMode( int theMode ) { + @Override @ControlP5.Invisible public Matrix updateDisplayMode( int theMode ) { _myDisplayMode = theMode; switch ( theMode ) { case ( DEFAULT ): @@ -400,16 +392,14 @@ public class Matrix extends Controller< Matrix > { theGraphics.noStroke( ); theGraphics.fill( bg ); theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) ); + + float gx = gapX / 2; + float gy = gapY / 2; for ( int x = 0 ; x < _myCellX ; x++ ) { for ( int y = 0 ; y < _myCellY ; y++ ) { - if ( _myCells[ x ][ y ] == 1 ) { - theGraphics.fill( color.getActive( ) ); - 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 ); - } + theGraphics.fill( _myCells[ x ][ y ] == 1 ? color.getActive( ) : color.getBackground( ) ); + theGraphics.rect( x * stepX + gx , y * stepY + gy , stepX - gapX , stepY - gapY ); } } if ( isInside( ) ) { diff --git a/src/controlP5/Slider2D.java b/src/controlP5/Slider2D.java index 73a3c69..fa661c9 100755 --- a/src/controlP5/Slider2D.java +++ b/src/controlP5/Slider2D.java @@ -67,6 +67,14 @@ public class Slider2D extends Controller< Slider2D > { 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 * @@ -190,6 +198,12 @@ public class Slider2D extends Controller< Slider2D > { 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. */ diff --git a/src/controlP5/Textfield.java b/src/controlP5/Textfield.java index 88105e6..b71e983 100755 --- a/src/controlP5/Textfield.java +++ b/src/controlP5/Textfield.java @@ -320,8 +320,14 @@ public class Textfield extends Controller< Textfield > { _myValueLabel.setText( text ); _myValueLabel.draw( buffer , -dif , 0 , this ); buffer.noStroke( ); - buffer.fill( _myColorCursor ); - buffer.rect( PApplet.max( 1 , PApplet.min( _myTextBufferIndexPosition , _myValueLabel.getWidth( ) - 3 ) ) , 0 , 1 , getHeight( ) ); + if ( isTexfieldActive ) { + if ( !cp5.papplet.keyPressed ) { + buffer.fill( _myColorCursor , PApplet.abs( PApplet.sin( cp5.papplet.frameCount * 0.05f )) * 255 ); + } else { + buffer.fill( _myColorCursor ); + } + buffer.rect( PApplet.max( 1 , PApplet.min( _myTextBufferIndexPosition , _myValueLabel.getWidth( ) - 3 ) ) , 0 , 1 , getHeight( ) ); + } buffer.endDraw( ); theGraphics.image( buffer , 0 , 0 ); diff --git a/src/controlP5/Toggle.java b/src/controlP5/Toggle.java index 478d087..e2af6d4 100755 --- a/src/controlP5/Toggle.java +++ b/src/controlP5/Toggle.java @@ -37,15 +37,10 @@ import processing.core.PImage; public class Toggle extends Controller< Toggle > { protected int cnt; - protected boolean isOn = false; - protected float internalValue = -1; - public static int autoWidth = 39; - public static int autoHeight = 19; - protected float[] autoSpacing = new float[] { 10 , 20 }; /** @@ -72,7 +67,7 @@ public class Toggle extends Controller< Toggle > { */ @ControlP5.Invisible public void draw( PGraphics theGraphics ) { theGraphics.pushMatrix( ); - theGraphics.translate( x(position) , y(position) ); + theGraphics.translate( x( position ) , y( position ) ); _myControllerView.display( theGraphics , this ); theGraphics.popMatrix( ); } @@ -113,6 +108,10 @@ public class Toggle extends Controller< Toggle > { return this; } + public boolean getBooleanValue( ) { + return getState( ); + } + /** * {@inheritDoc} */ @@ -132,10 +131,6 @@ public class Toggle extends Controller< Toggle > { return this; } - /** - * - * @return - */ public boolean getState( ) { return isOn; } @@ -245,18 +240,11 @@ public class Toggle extends Controller< Toggle > { public void display( PGraphics theGraphics , Toggle theController ) { - // if ( isActive ) { - // theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[ - // DEFAULT ] , 0 , 0 ); - // } else { if ( isOn ) { theGraphics.image( ( availableImages[ ACTIVE ] == true ) ? images[ ACTIVE ] : images[ DEFAULT ] , 0 , 0 ); } else { 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 ) { theGraphics.fill( color.getBackground( ) ); - theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) ); - theGraphics.fill( color.getActive( ) ); if ( isOn ) { diff --git a/src/controlP5/changeLog.txt b/src/controlP5/changeLog.txt index 33ffa3a..45ab97a 100755 --- a/src/controlP5/changeLog.txt +++ b/src/controlP5/changeLog.txt @@ -1,3 +1,22 @@ +2014-09-08 Andreas Schlegel + + * 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 + + * src controlP5.Background: + adding Background class, a convenience class for grouping controllers with + the top bar disabled by default. + + 2014-07-21 Andreas Schlegel * src controlP5.Textfield: