Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Textfield mouse support and corrected behaviour for delete key #143

Open
wants to merge 2 commits into
base: dev-2.2.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/controlP5/CColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
public class CColor implements Serializable {

private int colorBackground = 0xff003652;
private int colorSelectedBackground = 0xffffffff;
private int colorForeground = 0xff00698c;
private int colorActive = 0xff08a2cf; // 0699C4;
private int colorCaptionLabel = 0xffffffff;
Expand All @@ -52,6 +53,7 @@ public class CColor implements Serializable {

protected CColor set( CColor theColor ) {
colorBackground = theColor.colorBackground;
colorSelectedBackground = theColor.colorSelectedBackground;
colorForeground = theColor.colorForeground;
colorActive = theColor.colorActive;
colorCaptionLabel = theColor.colorCaptionLabel;
Expand Down Expand Up @@ -125,6 +127,15 @@ public CColor setBackground( int theColor ) {
return this;
}

public CColor setSelectedBackground( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorSelectedBackground = 0xff000000;
} else {
colorSelectedBackground = theColor;
}
return this;
}

public CColor setActive( int theColor ) {
if ( ( theColor & 0xff000000 ) == 0 ) {
colorActive = 0xff000000;
Expand Down Expand Up @@ -164,6 +175,10 @@ public int getBackground( ) {
return colorBackground;
}

public int getSelectedBackground( ) {
return colorSelectedBackground;
}

public int getActive( ) {
return colorActive;
}
Expand Down
17 changes: 15 additions & 2 deletions src/controlP5/ControlFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,22 @@ public void draw( PGraphics theGraphics , Label theLabel ) {
debug( theGraphics , theLabel );
theGraphics.fill( theLabel.getColor( ) );
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 ) {
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);
}

}
Expand Down
22 changes: 19 additions & 3 deletions src/controlP5/ControlWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public final class ControlWindow {
protected int mouseY;
protected int pmouseX;
protected int pmouseY;
protected int pclickMouseX;
protected int pclickMouseY;
protected boolean mousePressed;
protected long mousePressedTime;
protected long pmousePressedTime;
Expand Down Expand Up @@ -401,7 +403,9 @@ public ControlWindow pre( ) {
* boolean).
*/
public void mouseEvent( int theX , int theY , boolean pressed ) {

pclickMouseX = mouseX;
pclickMouseY = mouseY;

mouseX = theX - cp5.pgx - cp5.ox;
mouseY = theY - cp5.pgy - cp5.oy;

Expand Down Expand Up @@ -440,12 +444,16 @@ public void mouseEvent( int theX , int theY , boolean pressed ) {
*/
public void mouseEvent( MouseEvent theMouseEvent ) {
if ( isMouse ) {
int oldX = mouseX;
int oldY = mouseY;
mouseX = theMouseEvent.getX( ) - cp5.pgx - cp5.ox;
mouseY = theMouseEvent.getY( ) - cp5.pgy - cp5.oy;
if ( theMouseEvent.getAction( ) == MouseEvent.PRESS ) {
mousePressedEvent( );
}
if ( theMouseEvent.getAction( ) == MouseEvent.RELEASE ) {
pclickMouseX = oldX;
pclickMouseY = oldY;
mouseReleasedEvent( );
}
if ( theMouseEvent.getAction( ) == MouseEvent.WHEEL ) {
Expand Down Expand Up @@ -600,7 +608,7 @@ public void draw( PGraphics pg ) {

pmouseX = mouseX;
pmouseY = mouseY;

/* draw Tooltip here. */

cp5.getTooltip( ).draw( this );
Expand Down Expand Up @@ -843,7 +851,7 @@ public ControlWindow setUndecorated( boolean theFlag ) {
_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 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran into this too. Might be better off deleting it. For anyone unfamiliar, PApplet.setBounds is not present anymore and the project won't compile without this line commented out or deleted.

_myApplet.frame.setSize( _myApplet.width , _myApplet.height );
_myApplet.frame.addNotify( );
}
Expand Down Expand Up @@ -921,6 +929,14 @@ public int getPreviousY( ) {
return pmouseY;
}

public int getPreviousClickX( ) {
return pclickMouseX;
}

public int getPreviousClickY( ) {
return pclickMouseY;
}

public Pointer set( int theX , int theY ) {
setX( theX );
setY( theY );
Expand Down
9 changes: 4 additions & 5 deletions src/controlP5/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ public int y( ) {
}

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( ) {
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( ) {
Expand Down Expand Up @@ -590,7 +590,7 @@ public String toString( ) {
onPress( );
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_PRESS ) );
callListener( ACTION_PRESS );
if ( getPointer( ).dt( ) < 500 ) {
if ( getPointer( ).dt( ) < 500 && getPointer( ).dx() == 0 && getPointer( ).dy() == 0 ) {
onDoublePress( );
callListener( ACTION_DOUBLE_PRESS );
}
Expand Down Expand Up @@ -628,8 +628,7 @@ public String toString( ) {
onReleaseOutside( );
cp5.getControlBroadcaster( ).invokeAction( new CallbackEvent( this , ACTION_RELEASE_OUTSIDE ) );
callListener( ACTION_RELEASE_OUTSIDE );
}
if ( this instanceof Textfield ) {
} else if ( this instanceof Textfield ) {
mouseReleasedOutside( );
onReleaseOutside( );
callListener( ACTION_RELEASE_OUTSIDE );
Expand Down
29 changes: 29 additions & 0 deletions src/controlP5/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class Label implements CDrawable {
protected ControllerStyle _myControllerStyle = new ControllerStyle( );
protected boolean isVisible = true;
protected int _myColor = 0xffffffff;
protected int _mySelectedColor = 0xff000000;
protected boolean isColorBackground;
protected boolean isToUpperCase = isToUpperCaseDefault;
protected boolean changed;
Expand All @@ -67,6 +68,8 @@ public class Label implements CDrawable {
protected Labeltype _myLabeltype;
protected int _myTextHeight = 1;
protected float offsetYratio = 0;
protected int _mySelectedStart = 0;
protected int _mySelectedStop = 0;
private ControlP5 cp5;

private Label( Label theLabel ) {
Expand Down Expand Up @@ -366,6 +369,16 @@ public int getColor( ) {
return _myColor;
}

public int getSelectedColor( ) {
return _mySelectedColor;
}

public Label setSelectedColor( int theColor ) {
_mySelectedColor = theColor;
setChanged( true );
return this;
}

public Label setColorBackground( int theColor ) {
enableColorBackground( );
_myColorBackground = theColor;
Expand Down Expand Up @@ -404,6 +417,22 @@ public boolean 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( ) {
return new Label( this );
}
Expand Down
Loading