From 752e1ac0a5d920cd4fcc7becdd1d1f0a0c615a6c Mon Sep 17 00:00:00 2001 From: ubi Date: Thu, 15 Mar 2018 13:37:27 +0100 Subject: [PATCH 1/2] - removed reference to PApplet.setBounds(int, int, int, int) as it seems not to exist in Processing 3 anymore - added TickMark distance from component and fixed its relation to TickMark length --- src/controlP5/ControlWindow.java | 2 +- src/controlP5/TickMark.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) mode change 100755 => 100644 src/controlP5/TickMark.java diff --git a/src/controlP5/ControlWindow.java b/src/controlP5/ControlWindow.java index 968d172..0ca169f 100755 --- a/src/controlP5/ControlWindow.java +++ b/src/controlP5/ControlWindow.java @@ -843,7 +843,7 @@ public final class ControlWindow { _myApplet.frame.removeNotify( ); _myApplet.frame.setUndecorated( isUndecorated ); _myApplet.setSize( _myApplet.width , _myApplet.height ); - _myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height ); + //_myApplet.setBounds( 0 , 0 , _myApplet.width , _myApplet.height ); _myApplet.frame.setSize( _myApplet.width , _myApplet.height ); _myApplet.frame.addNotify( ); } diff --git a/src/controlP5/TickMark.java b/src/controlP5/TickMark.java old mode 100755 new mode 100644 index 2ff66fb..cdd7486 --- a/src/controlP5/TickMark.java +++ b/src/controlP5/TickMark.java @@ -20,8 +20,8 @@ package controlP5; * Boston, MA 02111-1307 USA * * @author Andreas Schlegel (http://www.sojamo.de) - * @modified ##date## - * @version ##version## + * @modified 03/15/2018 + * @version 2.2.6 * */ import processing.core.PApplet; @@ -35,6 +35,7 @@ public class TickMark implements CDrawable { protected Controller< ? > _myParent; protected int _myLen = 4; + protected int _myDistance = _myLen; protected Label _myLabel; @@ -52,14 +53,14 @@ public class TickMark implements CDrawable { theGraphics.pushMatrix( ); switch ( theDirection ) { case ( ControlP5Constants.HORIZONTAL ): - theGraphics.translate( 0 , _myLen ); + theGraphics.translate( 0 , _myDistance ); theGraphics.rect( 0 , 0 , 1 , _myLen ); if ( isLabel ) { _myLabel.draw( theGraphics , 0 , _myLen + 4 , _myParent ); } break; case ( ControlP5Constants.VERTICAL ): - theGraphics.translate( -_myLen , 0 ); + theGraphics.translate( -_myDistance - _myLen , 0 ); theGraphics.rect( 0 , 0 , _myLen , 1 ); if ( isLabel ) { _myLabel.draw( theGraphics , -_myLabel.getWidth( ) , 0 , _myParent ); @@ -74,6 +75,10 @@ public class TickMark implements CDrawable { _myLen = theLength; } + public void setDistance( int theDistance) { + _myDistance = theDistance; + } + public Label setLabel( String theLabeltext ) { if ( _myLabel == null ) { _myLabel = new Label( _myParent.cp5 , theLabeltext ); From 9cf4795dff64133a04effe6fac1001c105672534 Mon Sep 17 00:00:00 2001 From: ubi Date: Sun, 18 Mar 2018 10:00:31 +0100 Subject: [PATCH 2/2] - fixed TickMark positioning/spacing - implemented TickMark.setDistance(int) method to allow better positioning in respect to the slider - cleaned up after myself --- src/controlP5/ControlFont.java | 1 - src/controlP5/Slider.java | 44 ++++++++++++++++++++++++++++++---- src/controlP5/TickMark.java | 2 ++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/controlP5/ControlFont.java b/src/controlP5/ControlFont.java index 53d553b..e913a1f 100755 --- a/src/controlP5/ControlFont.java +++ b/src/controlP5/ControlFont.java @@ -236,7 +236,6 @@ public class ControlFont { theGraphics.textFont( pfont , size ); theGraphics.textAlign( theLabel.textAlign ); theGraphics.fill( theLabel.getColor( ) ); - if ( theLabel.isMultiline( ) ) { theGraphics.fill( theLabel.getColor( ) ); theGraphics.textLeading( theLabel.getLineHeight( ) ); diff --git a/src/controlP5/Slider.java b/src/controlP5/Slider.java index 4a55331..8229d77 100755 --- a/src/controlP5/Slider.java +++ b/src/controlP5/Slider.java @@ -523,6 +523,7 @@ public class Slider extends Controller< Slider > { } public void display( PGraphics theGraphics , Slider theController ) { + //theGraphics.clear(); theGraphics.fill( getColor( ).getBackground( ) ); theGraphics.noStroke( ); if ( ( getColor( ).getBackground( ) >> 24 & 0xff ) > 0 ) { @@ -552,11 +553,26 @@ public class Slider extends Controller< Slider > { theGraphics.pushStyle( ); theGraphics.translate( -4 , ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 ); theGraphics.fill( _myColorTickMark ); - float x = ( getHeight( ) - ( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) ) ) / ( getTickMarks( ).size( ) - 1 ); + float x = ( (float)getHeight( ) - ( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) ) ) / ( getTickMarks( ).size( ) - 1 ); + int tickMarksCount = 0; + int totalTickMarks = _myTickMarks.size(); + int xOffset; for ( TickMark tm : getTickMarks( ) ) { + theGraphics.pushMatrix(); + xOffset = PApplet.round(x*tickMarksCount); + + if(tickMarksCount < totalTickMarks -1){ + theGraphics.translate( 0, xOffset ); + }else{ + theGraphics.translate( 0, xOffset-1 ); + } + tm.draw( theGraphics , getDirection( ) ); - theGraphics.translate( 0 , x ); + theGraphics.popMatrix(); + //PApplet.println(tickMarksCount + " > xOffset: " + xOffset); + tickMarksCount++; } + theGraphics.popStyle( ); theGraphics.popMatrix( ); } @@ -614,18 +630,38 @@ public class Slider extends Controller< Slider > { } if ( isShowTickMarks ) { + theGraphics.pushMatrix( ); // theGraphics.pushStyle( ); theGraphics.translate( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 , getHeight( ) ); theGraphics.fill( _myColorTickMark ); theGraphics.noStroke( ); - float x = ( getWidth( ) - ( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) ) ) / ( getTickMarks( ).size( ) - 1 ); + + float x = ( (float)getWidth() - ( ( getSliderMode() == FIX ) ? 0 : getHandleSize() ) ) / ( getTickMarks().size() - 1 ); + + int tickMarksCount = 0; + int totalTickMarks = _myTickMarks.size(); + int xOffset; + + for ( TickMark tm : getTickMarks( ) ) { + theGraphics.pushMatrix(); + xOffset = PApplet.round(x*tickMarksCount); + + if(tickMarksCount < totalTickMarks -1){ + theGraphics.translate( xOffset , 0 ); + }else{ + theGraphics.translate( xOffset-1 , 0 ); + } + tm.draw( theGraphics , getDirection( ) ); - theGraphics.translate( x , 0 ); + theGraphics.popMatrix(); + //PApplet.println(tickMarksCount + " > xOffset: " + xOffset); + tickMarksCount++; } // theGraphics.popStyle( ); theGraphics.popMatrix( ); + } } } diff --git a/src/controlP5/TickMark.java b/src/controlP5/TickMark.java index cdd7486..75bd9b8 100644 --- a/src/controlP5/TickMark.java +++ b/src/controlP5/TickMark.java @@ -63,6 +63,7 @@ public class TickMark implements CDrawable { theGraphics.translate( -_myDistance - _myLen , 0 ); theGraphics.rect( 0 , 0 , _myLen , 1 ); if ( isLabel ) { + _myLabel.draw( theGraphics , -_myLabel.getWidth( ) , 0 , _myParent ); } break; @@ -80,6 +81,7 @@ public class TickMark implements CDrawable { } public Label setLabel( String theLabeltext ) { + if ( _myLabel == null ) { _myLabel = new Label( _myParent.cp5 , theLabeltext ); isLabel = true;