mirror of
https://github.com/sojamo/controlp5
synced 2024-12-23 03:33:49 +01:00
Added text selection
Fixed double-click Fixed double call to mouse release
This commit is contained in:
parent
2e47b179cf
commit
52b30f99bf
@ -34,6 +34,7 @@ import java.io.Serializable;
|
|||||||
public class CColor implements Serializable {
|
public class CColor implements Serializable {
|
||||||
|
|
||||||
private int colorBackground = 0xff003652;
|
private int colorBackground = 0xff003652;
|
||||||
|
private int colorSelectedBackground = 0xffffffff;
|
||||||
private int colorForeground = 0xff00698c;
|
private int colorForeground = 0xff00698c;
|
||||||
private int colorActive = 0xff08a2cf; // 0699C4;
|
private int colorActive = 0xff08a2cf; // 0699C4;
|
||||||
private int colorCaptionLabel = 0xffffffff;
|
private int colorCaptionLabel = 0xffffffff;
|
||||||
@ -52,6 +53,7 @@ public class CColor implements Serializable {
|
|||||||
|
|
||||||
protected CColor set( CColor theColor ) {
|
protected CColor set( CColor theColor ) {
|
||||||
colorBackground = theColor.colorBackground;
|
colorBackground = theColor.colorBackground;
|
||||||
|
colorSelectedBackground = theColor.colorSelectedBackground;
|
||||||
colorForeground = theColor.colorForeground;
|
colorForeground = theColor.colorForeground;
|
||||||
colorActive = theColor.colorActive;
|
colorActive = theColor.colorActive;
|
||||||
colorCaptionLabel = theColor.colorCaptionLabel;
|
colorCaptionLabel = theColor.colorCaptionLabel;
|
||||||
@ -125,6 +127,15 @@ public class CColor implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CColor setSelectedBackground( int theColor ) {
|
||||||
|
if ( ( theColor & 0xff000000 ) == 0 ) {
|
||||||
|
colorSelectedBackground = 0xff000000;
|
||||||
|
} else {
|
||||||
|
colorSelectedBackground = theColor;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public CColor setActive( int theColor ) {
|
public CColor setActive( int theColor ) {
|
||||||
if ( ( theColor & 0xff000000 ) == 0 ) {
|
if ( ( theColor & 0xff000000 ) == 0 ) {
|
||||||
colorActive = 0xff000000;
|
colorActive = 0xff000000;
|
||||||
@ -164,6 +175,10 @@ public class CColor implements Serializable {
|
|||||||
return colorBackground;
|
return colorBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSelectedBackground( ) {
|
||||||
|
return colorSelectedBackground;
|
||||||
|
}
|
||||||
|
|
||||||
public int getActive( ) {
|
public int getActive( ) {
|
||||||
return colorActive;
|
return colorActive;
|
||||||
}
|
}
|
||||||
|
@ -247,9 +247,22 @@ public class ControlFont {
|
|||||||
debug( theGraphics , theLabel );
|
debug( theGraphics , theLabel );
|
||||||
theGraphics.fill( theLabel.getColor( ) );
|
theGraphics.fill( theLabel.getColor( ) );
|
||||||
theGraphics.textLeading( theLabel.getLineHeight( ) );
|
theGraphics.textLeading( theLabel.getLineHeight( ) );
|
||||||
theGraphics.text( theLabel.getTextFormatted( ) , 0 , 0 );
|
String myText = theLabel.getTextFormatted( );
|
||||||
|
|
||||||
|
theGraphics.fill(theLabel.getColor());
|
||||||
|
theGraphics.text(myText.substring(0, theLabel.getSelectedStart()) , 0 , 0);
|
||||||
|
theGraphics.fill( theLabel.getSelectedColor( ) );
|
||||||
|
theGraphics.text(myText.substring(theLabel.getSelectedStart(), theLabel.getSelectedStop()) , theGraphics.textWidth(myText.substring(0, theLabel.getSelectedStart())) , 0);
|
||||||
|
theGraphics.fill( theLabel.getColor( ) );
|
||||||
|
theGraphics.text(myText.substring(theLabel.getSelectedStop(), myText.length()) , theGraphics.textWidth(myText.substring(0, theLabel.getSelectedStop())) , 0);
|
||||||
|
|
||||||
if ( RENDER_2X ) {
|
if ( RENDER_2X ) {
|
||||||
theGraphics.text( theLabel.getTextFormatted( ) , 0 , 0 );
|
theGraphics.fill(theLabel.getColor());
|
||||||
|
theGraphics.text(myText.substring(0, theLabel.getSelectedStart()) , 0 , 0);
|
||||||
|
theGraphics.fill( theLabel.getSelectedColor( ) );
|
||||||
|
theGraphics.text(myText.substring(theLabel.getSelectedStart(), theLabel.getSelectedStop()) , theGraphics.textWidth(myText.substring(0, theLabel.getSelectedStart())) , 0);
|
||||||
|
theGraphics.fill( theLabel.getColor( ) );
|
||||||
|
theGraphics.text(myText.substring(theLabel.getSelectedStop(), myText.length()) , theGraphics.textWidth(myText.substring(0, theLabel.getSelectedStop())) , 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,8 @@ public final class ControlWindow {
|
|||||||
protected int mouseY;
|
protected int mouseY;
|
||||||
protected int pmouseX;
|
protected int pmouseX;
|
||||||
protected int pmouseY;
|
protected int pmouseY;
|
||||||
|
protected int pclickMouseX;
|
||||||
|
protected int pclickMouseY;
|
||||||
protected boolean mousePressed;
|
protected boolean mousePressed;
|
||||||
protected long mousePressedTime;
|
protected long mousePressedTime;
|
||||||
protected long pmousePressedTime;
|
protected long pmousePressedTime;
|
||||||
@ -401,6 +403,8 @@ public final class ControlWindow {
|
|||||||
* boolean).
|
* boolean).
|
||||||
*/
|
*/
|
||||||
public void mouseEvent( int theX , int theY , boolean pressed ) {
|
public void mouseEvent( int theX , int theY , boolean pressed ) {
|
||||||
|
pclickMouseX = mouseX;
|
||||||
|
pclickMouseY = mouseY;
|
||||||
|
|
||||||
mouseX = theX - cp5.pgx - cp5.ox;
|
mouseX = theX - cp5.pgx - cp5.ox;
|
||||||
mouseY = theY - cp5.pgy - cp5.oy;
|
mouseY = theY - cp5.pgy - cp5.oy;
|
||||||
@ -440,12 +444,16 @@ public final class ControlWindow {
|
|||||||
*/
|
*/
|
||||||
public void mouseEvent( MouseEvent theMouseEvent ) {
|
public void mouseEvent( MouseEvent theMouseEvent ) {
|
||||||
if ( isMouse ) {
|
if ( isMouse ) {
|
||||||
|
int oldX = mouseX;
|
||||||
|
int oldY = mouseY;
|
||||||
mouseX = theMouseEvent.getX( ) - cp5.pgx - cp5.ox;
|
mouseX = theMouseEvent.getX( ) - cp5.pgx - cp5.ox;
|
||||||
mouseY = theMouseEvent.getY( ) - cp5.pgy - cp5.oy;
|
mouseY = theMouseEvent.getY( ) - cp5.pgy - cp5.oy;
|
||||||
if ( theMouseEvent.getAction( ) == MouseEvent.PRESS ) {
|
if ( theMouseEvent.getAction( ) == MouseEvent.PRESS ) {
|
||||||
mousePressedEvent( );
|
mousePressedEvent( );
|
||||||
}
|
}
|
||||||
if ( theMouseEvent.getAction( ) == MouseEvent.RELEASE ) {
|
if ( theMouseEvent.getAction( ) == MouseEvent.RELEASE ) {
|
||||||
|
pclickMouseX = oldX;
|
||||||
|
pclickMouseY = oldY;
|
||||||
mouseReleasedEvent( );
|
mouseReleasedEvent( );
|
||||||
}
|
}
|
||||||
if ( theMouseEvent.getAction( ) == MouseEvent.WHEEL ) {
|
if ( theMouseEvent.getAction( ) == MouseEvent.WHEEL ) {
|
||||||
@ -921,6 +929,14 @@ public final class ControlWindow {
|
|||||||
return pmouseY;
|
return pmouseY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPreviousClickX( ) {
|
||||||
|
return pclickMouseX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPreviousClickY( ) {
|
||||||
|
return pclickMouseY;
|
||||||
|
}
|
||||||
|
|
||||||
public Pointer set( int theX , int theY ) {
|
public Pointer set( int theX , int theY ) {
|
||||||
setX( theX );
|
setX( theX );
|
||||||
setY( theY );
|
setY( theY );
|
||||||
|
@ -545,11 +545,11 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int px( ) {
|
public int px( ) {
|
||||||
return ( int ) ( _myControlWindow.pmouseX - Controller.x( _myParent.getAbsolutePosition( ) ) - Controller.x( position ) );
|
return ( int ) ( _myControlWindow.pclickMouseX - Controller.x( _myParent.getAbsolutePosition( ) ) - Controller.x( position ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int py( ) {
|
public int py( ) {
|
||||||
return ( int ) ( _myControlWindow.pmouseY - Controller.y( _myParent.getAbsolutePosition( ) ) - Controller.y( position ) );
|
return ( int ) ( _myControlWindow.pclickMouseY - Controller.y( _myParent.getAbsolutePosition( ) ) - Controller.y( position ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int dx( ) {
|
public int dx( ) {
|
||||||
@ -590,7 +590,7 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra
|
|||||||
onPress( );
|
onPress( );
|
||||||
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_PRESS ) );
|
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_PRESS ) );
|
||||||
callListener( ACTION_PRESS );
|
callListener( ACTION_PRESS );
|
||||||
if ( getPointer( ).dt( ) < 500 ) {
|
if ( getPointer( ).dt( ) < 500 && getPointer( ).dx() == 0 && getPointer( ).dy() == 0 ) {
|
||||||
onDoublePress( );
|
onDoublePress( );
|
||||||
callListener( ACTION_DOUBLE_PRESS );
|
callListener( ACTION_DOUBLE_PRESS );
|
||||||
}
|
}
|
||||||
@ -628,8 +628,7 @@ public abstract class Controller< T > implements ControllerInterface< T > , CDra
|
|||||||
onReleaseOutside( );
|
onReleaseOutside( );
|
||||||
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_RELEASE_OUTSIDE ) );
|
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_RELEASE_OUTSIDE ) );
|
||||||
callListener( ACTION_RELEASE_OUTSIDE );
|
callListener( ACTION_RELEASE_OUTSIDE );
|
||||||
}
|
} else if ( this instanceof Textfield ) {
|
||||||
if ( this instanceof Textfield ) {
|
|
||||||
mouseReleasedOutside( );
|
mouseReleasedOutside( );
|
||||||
onReleaseOutside( );
|
onReleaseOutside( );
|
||||||
callListener( ACTION_RELEASE_OUTSIDE );
|
callListener( ACTION_RELEASE_OUTSIDE );
|
||||||
|
@ -48,6 +48,7 @@ public class Label implements CDrawable {
|
|||||||
protected ControllerStyle _myControllerStyle = new ControllerStyle( );
|
protected ControllerStyle _myControllerStyle = new ControllerStyle( );
|
||||||
protected boolean isVisible = true;
|
protected boolean isVisible = true;
|
||||||
protected int _myColor = 0xffffffff;
|
protected int _myColor = 0xffffffff;
|
||||||
|
protected int _mySelectedColor = 0xff000000;
|
||||||
protected boolean isColorBackground;
|
protected boolean isColorBackground;
|
||||||
protected boolean isToUpperCase = isToUpperCaseDefault;
|
protected boolean isToUpperCase = isToUpperCaseDefault;
|
||||||
protected boolean changed;
|
protected boolean changed;
|
||||||
@ -67,6 +68,8 @@ public class Label implements CDrawable {
|
|||||||
protected Labeltype _myLabeltype;
|
protected Labeltype _myLabeltype;
|
||||||
protected int _myTextHeight = 1;
|
protected int _myTextHeight = 1;
|
||||||
protected float offsetYratio = 0;
|
protected float offsetYratio = 0;
|
||||||
|
protected int _mySelectedStart = 0;
|
||||||
|
protected int _mySelectedStop = 0;
|
||||||
private ControlP5 cp5;
|
private ControlP5 cp5;
|
||||||
|
|
||||||
private Label( Label theLabel ) {
|
private Label( Label theLabel ) {
|
||||||
@ -366,6 +369,16 @@ public class Label implements CDrawable {
|
|||||||
return _myColor;
|
return _myColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSelectedColor( ) {
|
||||||
|
return _mySelectedColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Label setSelectedColor( int theColor ) {
|
||||||
|
_mySelectedColor = theColor;
|
||||||
|
setChanged( true );
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Label setColorBackground( int theColor ) {
|
public Label setColorBackground( int theColor ) {
|
||||||
enableColorBackground( );
|
enableColorBackground( );
|
||||||
_myColorBackground = theColor;
|
_myColorBackground = theColor;
|
||||||
@ -404,6 +417,22 @@ public class Label implements CDrawable {
|
|||||||
return isToUpperCase;
|
return isToUpperCase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSelectedStart( ) {
|
||||||
|
return _mySelectedStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelectedStop( ) {
|
||||||
|
return _mySelectedStop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedStart(int start) {
|
||||||
|
_mySelectedStart = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedStop(int stop) {
|
||||||
|
_mySelectedStop = stop;
|
||||||
|
}
|
||||||
|
|
||||||
protected Label copy( ) {
|
protected Label copy( ) {
|
||||||
return new Label( this );
|
return new Label( this );
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,9 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
protected boolean isPasswordMode;
|
protected boolean isPasswordMode;
|
||||||
protected boolean autoclear = true;
|
protected boolean autoclear = true;
|
||||||
protected int _myColorCursor = 0x88ffffff;
|
protected int _myColorCursor = 0x88ffffff;
|
||||||
|
protected int startDragIndex = 0;
|
||||||
|
protected int currentDragIndex = 0;
|
||||||
|
protected boolean isDragging = false;
|
||||||
private PGraphics buffer;
|
private PGraphics buffer;
|
||||||
|
|
||||||
public enum InputFilter {
|
public enum InputFilter {
|
||||||
@ -266,6 +269,9 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
int x = ( int ) ( getControlWindow( ).mouseX - x( getPosition( ) ) );
|
int x = ( int ) ( getControlWindow( ).mouseX - x( getPosition( ) ) );
|
||||||
int y = ( int ) ( getControlWindow( ).mouseY - y( getPosition( ) ) );
|
int y = ( int ) ( getControlWindow( ).mouseY - y( getPosition( ) ) );
|
||||||
|
|
||||||
|
_myValueLabel.setSelectedStart(0);
|
||||||
|
_myValueLabel.setSelectedStop(0);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int textWidth;
|
int textWidth;
|
||||||
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
|
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
|
||||||
@ -286,8 +292,79 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void mouseReleasedOutside( ) {
|
@Override protected void mouseReleasedOutside( ) {
|
||||||
if ( isKeepFocus == false ) {
|
if ( isKeepFocus == false && !isDragging ) {
|
||||||
isTexfieldActive = isActive = false;
|
isTexfieldActive = isActive = false;
|
||||||
|
startDragIndex = 0;
|
||||||
|
currentDragIndex = 0;
|
||||||
|
updateLabelSelection();
|
||||||
|
}
|
||||||
|
isDragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onStartDrag( ) {
|
||||||
|
int x = (int) (getControlWindow().mouseX - x(getPosition()));
|
||||||
|
int i = 0;
|
||||||
|
int textWidth;
|
||||||
|
isDragging = true;
|
||||||
|
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
|
||||||
|
textWidth = ControlFont.getWidthFor( _myTextBuffer.substring( 0 , i ) , _myValueLabel , buffer );
|
||||||
|
if(textWidth > x) {
|
||||||
|
if(i != 0 && textWidth-x > ControlFont.getWidthFor( _myTextBuffer.substring( i-1 , i ) , _myValueLabel , buffer )/2) {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i > _myTextBuffer.length())
|
||||||
|
i = _myTextBuffer.length();
|
||||||
|
|
||||||
|
startDragIndex = i;
|
||||||
|
setIndex(i);
|
||||||
|
|
||||||
|
setFocus( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onDrag( ) {
|
||||||
|
int x = (int) (getControlWindow().mouseX - x(getPosition()));
|
||||||
|
int i = 0;
|
||||||
|
int textWidth;
|
||||||
|
for(i = 0 ; i <= _myTextBuffer.length() ; i++) {
|
||||||
|
textWidth = ControlFont.getWidthFor( _myTextBuffer.substring( 0 , i ) , _myValueLabel , buffer );
|
||||||
|
if(textWidth > x) {
|
||||||
|
if(i != 0 && textWidth-x > ControlFont.getWidthFor( _myTextBuffer.substring( i-1 , i ) , _myValueLabel , buffer )/2) {
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(i > _myTextBuffer.length())
|
||||||
|
i = _myTextBuffer.length();
|
||||||
|
|
||||||
|
currentDragIndex = i;
|
||||||
|
updateLabelSelection();
|
||||||
|
|
||||||
|
setIndex(i);
|
||||||
|
setFocus( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onDoublePress( ) {
|
||||||
|
startDragIndex = 0;
|
||||||
|
currentDragIndex = _myTextBuffer.length();
|
||||||
|
updateLabelSelection();
|
||||||
|
setIndex(currentDragIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected void onEndDrag( ) {
|
||||||
|
isDragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateLabelSelection() {
|
||||||
|
if(startDragIndex > currentDragIndex) {
|
||||||
|
_myValueLabel.setSelectedStart(currentDragIndex);
|
||||||
|
_myValueLabel.setSelectedStop(startDragIndex);
|
||||||
|
} else {
|
||||||
|
_myValueLabel.setSelectedStart(startDragIndex);
|
||||||
|
_myValueLabel.setSelectedStop(currentDragIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,11 +394,21 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
|
|
||||||
@Override public void draw( PGraphics theGraphics ) {
|
@Override public void draw( PGraphics theGraphics ) {
|
||||||
|
|
||||||
|
final String text = passCheck( getText( ) );
|
||||||
|
|
||||||
theGraphics.pushStyle( );
|
theGraphics.pushStyle( );
|
||||||
theGraphics.fill( color.getBackground( ) );
|
theGraphics.fill( color.getBackground( ) );
|
||||||
theGraphics.pushMatrix( );
|
theGraphics.pushMatrix( );
|
||||||
theGraphics.translate( x( position ) , y( position ) );
|
theGraphics.translate( x( position ) , y( position ) );
|
||||||
theGraphics.rect( 0 , 0 , getWidth( ) , getHeight( ) );
|
theGraphics.fill(color.getBackground());
|
||||||
|
theGraphics.rect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
|
//theGraphics.fill(color.getBackground());
|
||||||
|
//theGraphics.rect(0, 0, theGraphics.textWidth(text.substring(0, _myValueLabel.getSelectedStart())), getHeight());
|
||||||
|
theGraphics.fill(color.getSelectedBackground());
|
||||||
|
theGraphics.rect(ControlFont.getWidthFor(text.substring(0, _myValueLabel.getSelectedStart()), _myValueLabel, buffer), 0, ControlFont.getWidthFor(text.substring(_myValueLabel.getSelectedStart(), _myValueLabel.getSelectedStop()), _myValueLabel, buffer), getHeight());
|
||||||
|
theGraphics.fill(color.getBackground());
|
||||||
|
|
||||||
theGraphics.noStroke( );
|
theGraphics.noStroke( );
|
||||||
|
|
||||||
theGraphics.fill( _myColorCursor );
|
theGraphics.fill( _myColorCursor );
|
||||||
@ -330,7 +417,6 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
|
|
||||||
buffer.beginDraw( );
|
buffer.beginDraw( );
|
||||||
buffer.background( 0 , 0 );
|
buffer.background( 0 , 0 );
|
||||||
final String text = passCheck( getText( ) );
|
|
||||||
final int textWidth = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
|
final int textWidth = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
|
||||||
final int dif = PApplet.max( textWidth - _myValueLabel.getWidth( ) , 0 );
|
final int dif = PApplet.max( textWidth - _myValueLabel.getWidth( ) , 0 );
|
||||||
final int _myTextBufferIndexPosition = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
|
final int _myTextBufferIndexPosition = ControlFont.getWidthFor( text.substring( 0 , _myTextBufferIndex ) , _myValueLabel , buffer );
|
||||||
@ -417,6 +503,20 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( _myInputFilter.apply( cp5.getKey( ) ) ) {
|
if ( _myInputFilter.apply( cp5.getKey( ) ) ) {
|
||||||
|
if(startDragIndex != currentDragIndex) {
|
||||||
|
int strt = startDragIndex;
|
||||||
|
int current = currentDragIndex;
|
||||||
|
startDragIndex = 0;
|
||||||
|
currentDragIndex = 0;
|
||||||
|
updateLabelSelection();
|
||||||
|
if(strt > current) {
|
||||||
|
_myTextBuffer.delete(current, strt);
|
||||||
|
setIndex(current);
|
||||||
|
} else {
|
||||||
|
_myTextBuffer.delete(strt, current);
|
||||||
|
setIndex(strt);
|
||||||
|
}
|
||||||
|
}
|
||||||
_myTextBuffer.insert( _myTextBufferIndex , ( char ) cp5.getKey( ) );
|
_myTextBuffer.insert( _myTextBufferIndex , ( char ) cp5.getKey( ) );
|
||||||
setIndex( _myTextBufferIndex + 1 );
|
setIndex( _myTextBufferIndex + 1 );
|
||||||
}
|
}
|
||||||
@ -444,21 +544,51 @@ public class Textfield extends Controller< Textfield > {
|
|||||||
|
|
||||||
public void execute( ) {
|
public void execute( ) {
|
||||||
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
|
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex > 0 ) {
|
||||||
|
if(startDragIndex != currentDragIndex) {
|
||||||
|
int strt = startDragIndex;
|
||||||
|
int current = currentDragIndex;
|
||||||
|
startDragIndex = 0;
|
||||||
|
currentDragIndex = 0;
|
||||||
|
updateLabelSelection();
|
||||||
|
if(strt > current) {
|
||||||
|
_myTextBuffer.delete(current, strt);
|
||||||
|
setIndex(current);
|
||||||
|
} else {
|
||||||
|
_myTextBuffer.delete(strt, current);
|
||||||
|
setIndex(strt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
_myTextBuffer.deleteCharAt( _myTextBufferIndex - 1 );
|
_myTextBuffer.deleteCharAt( _myTextBufferIndex - 1 );
|
||||||
setIndex( _myTextBufferIndex - 1 );
|
setIndex( _myTextBufferIndex - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DeleteCharacterRight implements TextfieldCommand {
|
class DeleteCharacterRight implements TextfieldCommand {
|
||||||
|
|
||||||
public void execute( ) {
|
public void execute( ) {
|
||||||
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex < _myTextBuffer.length( ) ) {
|
if ( _myTextBuffer.length( ) > 0 && _myTextBufferIndex < _myTextBuffer.length( ) ) {
|
||||||
|
if(startDragIndex != currentDragIndex) {
|
||||||
|
int strt = startDragIndex;
|
||||||
|
int current = currentDragIndex;
|
||||||
|
startDragIndex = 0;
|
||||||
|
currentDragIndex = 0;
|
||||||
|
updateLabelSelection();
|
||||||
|
if(strt > current) {
|
||||||
|
_myTextBuffer.delete(current, strt);
|
||||||
|
setIndex(current);
|
||||||
|
} else {
|
||||||
|
_myTextBuffer.delete(strt, current);
|
||||||
|
setIndex(strt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
_myTextBuffer.deleteCharAt( _myTextBufferIndex );
|
_myTextBuffer.deleteCharAt( _myTextBufferIndex );
|
||||||
setIndex( _myTextBufferIndex );
|
setIndex( _myTextBufferIndex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MoveLeft implements TextfieldCommand {
|
class MoveLeft implements TextfieldCommand {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user