mirror of
https://github.com/sojamo/controlp5
synced 2024-11-22 14:07:55 +01:00
- fixed TickMark positioning/spacing
- implemented TickMark.setDistance(int) method to allow better positioning in respect to the slider - cleaned up after myself
This commit is contained in:
parent
752e1ac0a5
commit
9cf4795dff
@ -236,7 +236,6 @@ public class ControlFont {
|
|||||||
theGraphics.textFont( pfont , size );
|
theGraphics.textFont( pfont , size );
|
||||||
theGraphics.textAlign( theLabel.textAlign );
|
theGraphics.textAlign( theLabel.textAlign );
|
||||||
theGraphics.fill( theLabel.getColor( ) );
|
theGraphics.fill( theLabel.getColor( ) );
|
||||||
|
|
||||||
if ( theLabel.isMultiline( ) ) {
|
if ( theLabel.isMultiline( ) ) {
|
||||||
theGraphics.fill( theLabel.getColor( ) );
|
theGraphics.fill( theLabel.getColor( ) );
|
||||||
theGraphics.textLeading( theLabel.getLineHeight( ) );
|
theGraphics.textLeading( theLabel.getLineHeight( ) );
|
||||||
|
@ -523,6 +523,7 @@ public class Slider extends Controller< Slider > {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void display( PGraphics theGraphics , Slider theController ) {
|
public void display( PGraphics theGraphics , Slider theController ) {
|
||||||
|
//theGraphics.clear();
|
||||||
theGraphics.fill( getColor( ).getBackground( ) );
|
theGraphics.fill( getColor( ).getBackground( ) );
|
||||||
theGraphics.noStroke( );
|
theGraphics.noStroke( );
|
||||||
if ( ( getColor( ).getBackground( ) >> 24 & 0xff ) > 0 ) {
|
if ( ( getColor( ).getBackground( ) >> 24 & 0xff ) > 0 ) {
|
||||||
@ -552,11 +553,26 @@ public class Slider extends Controller< Slider > {
|
|||||||
theGraphics.pushStyle( );
|
theGraphics.pushStyle( );
|
||||||
theGraphics.translate( -4 , ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 );
|
theGraphics.translate( -4 , ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 );
|
||||||
theGraphics.fill( _myColorTickMark );
|
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( ) ) {
|
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( ) );
|
tm.draw( theGraphics , getDirection( ) );
|
||||||
theGraphics.translate( 0 , x );
|
theGraphics.popMatrix();
|
||||||
|
//PApplet.println(tickMarksCount + " > xOffset: " + xOffset);
|
||||||
|
tickMarksCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
theGraphics.popStyle( );
|
theGraphics.popStyle( );
|
||||||
theGraphics.popMatrix( );
|
theGraphics.popMatrix( );
|
||||||
}
|
}
|
||||||
@ -614,18 +630,38 @@ public class Slider extends Controller< Slider > {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( isShowTickMarks ) {
|
if ( isShowTickMarks ) {
|
||||||
|
|
||||||
theGraphics.pushMatrix( );
|
theGraphics.pushMatrix( );
|
||||||
// theGraphics.pushStyle( );
|
// theGraphics.pushStyle( );
|
||||||
theGraphics.translate( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 , getHeight( ) );
|
theGraphics.translate( ( getSliderMode( ) == FIX ) ? 0 : getHandleSize( ) / 2 , getHeight( ) );
|
||||||
theGraphics.fill( _myColorTickMark );
|
theGraphics.fill( _myColorTickMark );
|
||||||
theGraphics.noStroke( );
|
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( ) ) {
|
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( ) );
|
tm.draw( theGraphics , getDirection( ) );
|
||||||
theGraphics.translate( x , 0 );
|
theGraphics.popMatrix();
|
||||||
|
//PApplet.println(tickMarksCount + " > xOffset: " + xOffset);
|
||||||
|
tickMarksCount++;
|
||||||
}
|
}
|
||||||
// theGraphics.popStyle( );
|
// theGraphics.popStyle( );
|
||||||
theGraphics.popMatrix( );
|
theGraphics.popMatrix( );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ public class TickMark implements CDrawable {
|
|||||||
theGraphics.translate( -_myDistance - _myLen , 0 );
|
theGraphics.translate( -_myDistance - _myLen , 0 );
|
||||||
theGraphics.rect( 0 , 0 , _myLen , 1 );
|
theGraphics.rect( 0 , 0 , _myLen , 1 );
|
||||||
if ( isLabel ) {
|
if ( isLabel ) {
|
||||||
|
|
||||||
_myLabel.draw( theGraphics , -_myLabel.getWidth( ) , 0 , _myParent );
|
_myLabel.draw( theGraphics , -_myLabel.getWidth( ) , 0 , _myParent );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -80,6 +81,7 @@ public class TickMark implements CDrawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Label setLabel( String theLabeltext ) {
|
public Label setLabel( String theLabeltext ) {
|
||||||
|
|
||||||
if ( _myLabel == null ) {
|
if ( _myLabel == null ) {
|
||||||
_myLabel = new Label( _myParent.cp5 , theLabeltext );
|
_myLabel = new Label( _myParent.cp5 , theLabeltext );
|
||||||
isLabel = true;
|
isLabel = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user