Skip to content

Commit

Permalink
upped vers to 0.1.0 because of API changes; changed main Interactive.…
Browse files Browse the repository at this point in the history
…make() to take second arg 'force'; changed API for callbacks that take additional arguments, for example mousePressed(x,y) is now mousePressedAt(x,y) while mousePressed() stayed
  • Loading branch information
fjenett committed May 21, 2014
1 parent 8a43165 commit 8bd19aa
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 66 deletions.
6 changes: 3 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</description>

<property name="libraryName" value="Guido" />
<property name="versionNumber" value="0.0.6" />
<property name="versionNumber" value="0.1.0" />
<property name="author" value="Florian Jenett"/>
<property name="copyright" value="(c) 2012-2013"/>
<property name="copyright" value="(c) 2012-2014"/>

<buildnumber file="resources/build.number" />

Expand All @@ -24,7 +24,7 @@

<!--property name="processing.classes" location="/Applications/Processing.app/Contents/Resources/Java/"/-->
<property name="processing.classes"
location="/Users/fjenett/Repos/processing/build/macosx/work/Processing.app/Contents/Resources/Java/"/>
location="/Users/fjenett/Repos/processing/build/macosx/work/Processing.app/Contents/Java/"/>
<property name="processing.libs"
location="/Users/fjenett/Documents/Processing/libraries"/>

Expand Down
8 changes: 4 additions & 4 deletions releases/Guido.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = Guido
authorList = [Florian Jenett](http://www.bezier.de/)
url = https://github.com/fjenett/Guido
category = GUI
sentence = A simple cross mode GUI library.
paragraph = Guido is a small GUI library that is compatible with both Java (standard) and JavaScript modes.
version = 165
prettyVersion = 0.0.6
sentence = A simple cross mode (P5/JS/Py/Rb) GUI library
paragraph = Guido is a small GUI library that is compatible with both Java (standard) and JavaScript, Python and Ruby modes
version = 182
prettyVersion = 0.1.0
Binary file modified releases/Guido.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions resources/library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = Guido
authorList = [Florian Jenett](http://www.bezier.de/)
url = https://github.com/fjenett/Guido
category = GUI
sentence = A simple cross mode GUI library.
paragraph = Guido is a small GUI library that is compatible with both Java (standard) and JavaScript modes.
sentence = A simple cross mode (P5/JS/Py/Rb) GUI library
paragraph = Guido is a small GUI library that is compatible with both Java (standard) and JavaScript, Python and Ruby modes
version = @@VERSION@@
prettyVersion = @@PRETTYVERSION@@
55 changes: 29 additions & 26 deletions src-js/de.bezier.gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ var Interactive = (function(){
}
};

// helper to call one of many possible fns by name on a target
var getCallFn = function ( listener, methods ) {
for ( var m in methods ) {
if ( methods[m] in listener &&
typeof listener[methods[m]] === 'function' ) {
return listener[methods[m]];
}
}
return function(){}; // noop
}

// -----------------------------------------
// class Interactive
// -----------------------------------------
Expand Down Expand Up @@ -167,10 +178,11 @@ var Interactive = (function(){
// static
// -----------------------------------------

Interactive.make = function ( t ) {
// Java version has optional 2nd arg "force" that is not needed in JS
Interactive.make = function ( targ ) {
interactiveInstance = new Interactive({
target: t.externals.canvas,
papplet: t
target: targ.externals.canvas,
papplet: targ
});
}

Expand Down Expand Up @@ -326,7 +338,7 @@ var Interactive = (function(){
this.debug = tf ? true : false;
}

this.mousePressed = function ( mx, my ) {
this.mousePressed = this.mousePressedAt = function ( mx, my ) {
if ( !(this.activated) ) return;

this.pressed = this.listener.isInside( mx, my );
Expand All @@ -336,53 +348,45 @@ var Interactive = (function(){
this.clickedPositionY = this.listener.y;
this.clickedMouseX = mx;
this.clickedMouseY = my;
if ( 'mousePressed' in this.listener )
this.listener.mousePressed ( mx, my );
getCallFn( ['mousePressed','mousePressedAt'], this.listener )( mx, my );
}
}

this.mouseDoubleClicked = function ( mx, my ) {
this.mouseDoubleClicked = this.mouseDoubleClickedAt = function ( mx, my ) {
if ( !(this.activated) ) return;

if ( this.listener.isInside( mx, my ) ) {
if ( 'mouseDoubleClicked' in this.listener )
this.listener.mouseDoubleClicked( mx, my );
getCallFn( ['mouseDoubleClicked','mouseDoubleClickedAt'], this.listener )( mx, my );
}
}

this.mouseMoved = function ( mx, my ) {
this.mouseMoved = this.mouseMovedAt = function ( mx, my ) {
if ( !(this.activated) ) return;

this.dragged = this.pressed;
if ( this.dragged ) {
this.draggedDistX = this.clickedMouseX - mx;
this.draggedDistY = this.clickedMouseY - my;
if ( 'mouseDragged' in this.listener )
this.listener.mouseDragged( mx, my,
this.clickedPositionX - this.draggedDistX,
this.clickedPositionY - this.draggedDistY );
getCallFn( ['mouseDraggedAt','mouseDraggedFromTo'],
this.listener )( mx, my,
this.clickedPositionX - this.draggedDistX,
this.clickedPositionY - this.draggedDistY );
} else {
var nowInside = this.listener.isInside( mx, my );

if ( !nowInside && this.hover ) {
if ( 'mouseExited' in this.listener ) {
this.listener.mouseExited( mx, my );
}
getCallFn( ['mouseExited','mouseExitedAt'], this.listener )( mx, my );
} else if ( nowInside && !this.hover ) {
if ( 'mouseEntered' in this.listener ) {
this.listener.mouseEntered( mx, my );
}
getCallFn( ['mouseEntered','mouseEnteredAt'], this.listener )( mx, my );
} else if ( nowInside ) {
if ( 'mouseMoved' in this.listener ) {
this.listener.mouseMoved( mx, my );
}
getCallFn( ['mouseMoved','mouseMovedAt'], this.listener )( mx, my );
}

this.hover = nowInside;
}
}

this.mouseReleased = function ( mx, my ) {
this.mouseReleased = this.mouseReleasedAt = function ( mx, my ) {
if ( !(this.activated) ) return;

if ( this.dragged ) {
Expand All @@ -391,8 +395,7 @@ var Interactive = (function(){
}

if ( this.pressed ) {
if ( 'mouseReleased' in this.listener )
this.listener.mouseReleased( mx, my );
getCallFn( ['mouseReleased','mouseReleasedAt'], this.listener )( mx, my );
}

this.pressed = this.dragged = false;
Expand Down
26 changes: 13 additions & 13 deletions src/de/bezier/guido/AbstractActiveElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public boolean isActive ()
}

public void mouseEntered ( ) { }
public void mouseEntered ( float mx, float my ) { }
public void mouseEnteredAt ( float mx, float my ) { }

public void mouseMoved ( ) { }
public void mouseMoved ( float mx, float my ) { }
public void mouseMovedAt ( float mx, float my ) { }

public void mouseExited ( ) { }
public void mouseExited ( float mx, float my ) { }
public void mouseExitedAt ( float mx, float my ) { }

public void mousePressedPre ( float mx, float my )
{
Expand All @@ -65,20 +65,20 @@ public void mousePressedPre ( float mx, float my )
if ( now - lp < 200 )
{
mouseDoubleClicked( );
mouseDoubleClicked( mx, my );
mouseDoubleClickedAt( mx, my );
}
else
{
mousePressed( );
mousePressed( mx, my );
mousePressedAt( mx, my );
}
}
}

abstract public void mousePressed ( );
abstract public void mousePressed ( float mx, float my );
abstract public void mousePressedAt ( float mx, float my );
abstract public void mouseDoubleClicked ( );
abstract public void mouseDoubleClicked ( float mx, float my );
abstract public void mouseDoubleClickedAt ( float mx, float my );

public void mouseDraggedPre ( float mx, float my )
{
Expand All @@ -89,13 +89,13 @@ public void mouseDraggedPre ( float mx, float my )
{
draggedDistX = clickedMouseX - mx;
draggedDistY = clickedMouseY - my;
mouseDragged( mx, my );
mouseDragged( mx, my, clickedPositionX - draggedDistX, clickedPositionY - draggedDistY );
mouseDraggedAt( mx, my );
mouseDraggedFromTo( mx, my, clickedPositionX - draggedDistX, clickedPositionY - draggedDistY );
}
}

abstract public void mouseDragged ( float mx, float my );
abstract public void mouseDragged ( float mx, float my, float dx, float dy );
abstract public void mouseDraggedAt ( float mx, float my );
abstract public void mouseDraggedFromTo ( float mx, float my, float dx, float dy );

public void mouseReleasedPre ( float mx, float my )
{
Expand All @@ -109,11 +109,11 @@ public void mouseReleasedPre ( float mx, float my )

if ( pressed )
mouseReleased( );
mouseReleased( mx, my );
mouseReleasedAt( mx, my );
}

abstract public void mouseReleased ( );
abstract public void mouseReleased ( float mx, float my );
abstract public void mouseReleasedAt ( float mx, float my );

public void mouseReleasedPost ( float mx, float my )
{
Expand Down
11 changes: 6 additions & 5 deletions src/de/bezier/guido/ActiveElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
public class ActiveElement extends AbstractActiveElement
{
public ActiveElement ( float x, float y, float width, float height ) {super(x,y,width,height);}
// mouseEntered, mouseMoved, mouseExited missing?
public void mousePressed ( ){};
public void mousePressed ( float mx, float my ){};
public void mousePressedAt ( float mx, float my ){};
public void mouseDoubleClicked ( ){};
public void mouseDoubleClicked ( float mx, float my ){};
public void mouseDragged ( float mx, float my ){};
public void mouseDragged ( float mx, float my, float dx, float dy ){};
public void mouseDoubleClickedAt ( float mx, float my ){};
public void mouseDraggedAt ( float mx, float my ){};
public void mouseDraggedFromTo ( float mx, float my, float dx, float dy ){};
public void mouseReleased ( ){};
public void mouseReleased ( float mx, float my ){};
public void mouseReleasedAt ( float mx, float my ){};
}

25 changes: 20 additions & 5 deletions src/de/bezier/guido/Interactive.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ public static Interactive make ( PApplet papplet )
return manager;
}

/**
* Alternative entry point allows to force to renew the Interactive instance. This solves a problem with Python mode
*
* @param papplet Your sketch
* @param force Force a new instance
* @see #make(PApplet)
*/
public static Interactive make ( PApplet papplet, boolean force )
{
if ( manager == null || force )
manager = new Interactive( papplet );

return manager;
}

/**
* Get the actual manager instance.
*
Expand Down Expand Up @@ -438,12 +453,12 @@ private void mouseWheelMovedImpl ( float amount )
if ( interActiveElement.hover && !wasHover )
{
interActiveElement.mouseEntered( );
interActiveElement.mouseEntered( mx, my );
interActiveElement.mouseEnteredAt( mx, my );
}
else if ( !interActiveElement.hover && wasHover )
{
interActiveElement.mouseExited( );
interActiveElement.mouseExited( mx, my );
interActiveElement.mouseExitedAt( mx, my );
}
}

Expand Down Expand Up @@ -563,17 +578,17 @@ private void mouseMoved ( processing.event.MouseEvent evt )
if ( interActiveElement.hover && !wasHover )
{
interActiveElement.mouseEntered( );
interActiveElement.mouseEntered( mx, my );
interActiveElement.mouseEnteredAt( mx, my );
}
else if ( !interActiveElement.hover && wasHover )
{
interActiveElement.mouseExited( );
interActiveElement.mouseExited( mx, my );
interActiveElement.mouseExitedAt( mx, my );
}
else
{
interActiveElement.mouseMoved( );
interActiveElement.mouseMoved( mx, my );
interActiveElement.mouseMovedAt( mx, my );
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/de/bezier/guido/ReflectiveActiveElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void mouseEntered ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseEntered ( float mx, float my )
public void mouseEnteredAt ( float mx, float my )
{
updateXY();
try {
Expand Down Expand Up @@ -240,7 +240,7 @@ public void mouseMoved ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseMoved ( float mx, float my )
public void mouseMovedAt ( float mx, float my )
{
updateXY();
try {
Expand Down Expand Up @@ -274,7 +274,7 @@ public void mouseExited ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseExited ( float mx, float my )
public void mouseExitedAt ( float mx, float my )
{
updateXY();
try {
Expand Down Expand Up @@ -308,7 +308,7 @@ public void mousePressed ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mousePressed ( float mx, float my )
public void mousePressedAt ( float mx, float my )
{
updateXY();
try {
Expand Down Expand Up @@ -342,7 +342,7 @@ public void mouseDoubleClicked ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseDoubleClicked ( float mx, float my )
public void mouseDoubleClickedAt ( float mx, float my )
{
updateXY();
try {
Expand All @@ -360,7 +360,7 @@ public void mouseDoubleClicked ( float mx, float my )
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseDragged ( float mx, float my )
public void mouseDraggedAt ( float mx, float my )
{
updateXY();
try {
Expand All @@ -381,7 +381,7 @@ public void mouseDragged ( float mx, float my )
* @param dy horizontal drag distance: difference between mouse pressed y and current y
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseDragged ( float mx, float my, float dx, float dy )
public void mouseDraggedFromTo ( float mx, float my, float dx, float dy )
{
updateXY();
try {
Expand Down Expand Up @@ -415,7 +415,7 @@ public void mouseReleased ()
* @param my mouse pointer y coordinate
* @see de.bezier.guido.ReflectiveActiveElement#isInside(float mx,float my)
*/
public void mouseReleased ( float mx, float my )
public void mouseReleasedAt ( float mx, float my )
{
updateXY();
try {
Expand Down

0 comments on commit 8bd19aa

Please sign in to comment.