Skip to content
Merged
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
114 changes: 102 additions & 12 deletions src/rprocessing/RLangPApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ public void settings() {
this.renjinEngine.getTopLevelContext().evaluate(this.sizeFunction,
this.renjinEngine.getTopLevelContext().getEnvironment());
}
Object obj = this.renjinEngine.get(Constant.SETTINGS_NAME);
if (obj.getClass().equals(Closure.class)) {
((Closure) obj).doApply(this.renjinEngine.getTopLevelContext());
}
applyFunction(Constant.SETTINGS_NAME);
}

/**
Expand Down Expand Up @@ -320,10 +317,7 @@ public void setup() {
}
} else {
System.out.println("The program is in mix mode now.");
Object obj = this.renjinEngine.get(Constant.SETUP_NAME);
if (obj.getClass().equals(Closure.class)) {
((Closure) obj).doApply(this.renjinEngine.getTopLevelContext());
}
applyFunction(Constant.SETUP_NAME);
}
log("Setup done");
}
Expand All @@ -341,10 +335,7 @@ public void handleDraw() {
*/
@Override
public void draw() {
Object obj = this.renjinEngine.get(Constant.DRAW_NAME);
if (obj.getClass().equals(Closure.class)) {
((Closure) obj).doApply(this.renjinEngine.getTopLevelContext());
}
applyFunction(Constant.DRAW_NAME);
}

/*
Expand Down Expand Up @@ -390,6 +381,105 @@ protected void wrapProcessingVariables() {
// this.renjinEngine.put("keyPressed", keyPressed);
}

@Override
public void mouseClicked() {
wrapMouseVariables();
applyFunction(Constant.MOUSECLICKED_NAME);
}

@Override
public void mouseMoved() {
wrapMouseVariables();
applyFunction(Constant.MOUSEMOVED_NAME);
}

@Override
public void mousePressed() {
wrapMouseVariables();
applyFunction(Constant.MOUSEPRESSED_NAME);
}

@Override
public void mouseReleased() {
wrapMouseVariables();
applyFunction(Constant.MOUSERELEASED_NAME);
}

@Override
public void mouseDragged() {
wrapMouseVariables();
applyFunction(Constant.MOUSEDRAGGED_NAME);
}

/**
*
* @see processing.core.PApplet#focusGained()
*/
@Override
public void focusGained() {
super.focusGained();
this.renjinEngine.put("focused", super.focused);
}

/**
*
* @see processing.core.PApplet#focusLost()
*/
@Override
public void focusLost() {
super.focusLost();
this.renjinEngine.put("focused", super.focused);
}

private void wrapMouseVariables() {
this.renjinEngine.put("mouseX", mouseX);
this.renjinEngine.put("mouseY", mouseY);
this.renjinEngine.put("pmouseX", pmouseX);
this.renjinEngine.put("pmouseY", pmouseY);
// this.renjinEngine.put("mouseButton", mouseButton);
}

private void applyFunction(String name) {
Object obj = this.renjinEngine.get(name);
if (obj.getClass().equals(Closure.class)) {
((Closure) obj).doApply(this.renjinEngine.getTopLevelContext());
}
}

@Override
public void keyPressed() {
wrapKeyVariables();
applyFunction(Constant.KEYPRESSED_NAME);
}

@Override
public void keyReleased() {
wrapKeyVariables();
applyFunction(Constant.KEYRELEASED_NAME);
}

@Override
public void keyTyped() {
wrapKeyVariables();
applyFunction(Constant.KEYTYPED_NAME);
}

private char lastKey = Character.MIN_VALUE;

protected void wrapKeyVariables() {
if (lastKey != key) {
lastKey = key;
/*
* If key is "CODED", i.e., an arrow key or other non-printable, pass that value through
* as-is. If it's printable, convert it to a unicode string, so that the user can compare key
* == 'x' instead of key == ord('x').
*/
final char pyKey = key == CODED ? parseChar(Integer.valueOf(key)) : parseChar(key);
this.renjinEngine.put("key", pyKey);
}
this.renjinEngine.put("keyCode", keyCode);
}

/**
* Return whether the object has same class with clazz.
*
Expand Down
84 changes: 0 additions & 84 deletions src/rprocessing/applet/BuiltinApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,90 +107,6 @@ public double getPI() {
return PI;
}

@Override
public void mouseClicked() {
wrapMouseVariables();
}

@Override
public void mouseMoved() {
wrapMouseVariables();
}

@Override
public void mousePressed() {
wrapMouseVariables();
}

@Override
public void mouseReleased() {
wrapMouseVariables();
}

@Override
public void mouseDragged() {
wrapMouseVariables();
}

/**
*
* @see processing.core.PApplet#focusGained()
*/
@Override
public void focusGained() {
super.focusGained();
this.renjinEngine.put("focused", super.focused);
}

/**
*
* @see processing.core.PApplet#focusLost()
*/
@Override
public void focusLost() {
super.focusLost();
this.renjinEngine.put("focused", super.focused);
}

protected void wrapMouseVariables() {
this.renjinEngine.put("mouseX", mouseX);
this.renjinEngine.put("mouseY", mouseY);
this.renjinEngine.put("pmouseX", pmouseX);
this.renjinEngine.put("pmouseY", pmouseY);
// this.renjinEngine.put("mouseButton", mouseButton);
}

@Override
public void keyPressed() {
wrapKeyVariables();
}

@Override
public void keyReleased() {
wrapKeyVariables();
}

@Override
public void keyTyped() {
wrapKeyVariables();
}

private char lastKey = Character.MIN_VALUE;

protected void wrapKeyVariables() {
if (lastKey != key) {
lastKey = key;
/*
* If key is "CODED", i.e., an arrow key or other non-printable, pass that value through
* as-is. If it's printable, convert it to a unicode string, so that the user can compare key
* == 'x' instead of key == ord('x').
*/
final char pyKey = key == CODED ? parseChar(Integer.valueOf(key)) : parseChar(key);
this.renjinEngine.put("key", pyKey);
}
this.renjinEngine.put("keyCode", keyCode);
}

private void logWarningsforCast() {
log("WARNING: The function call casts double to int.");
}
Expand Down
9 changes: 0 additions & 9 deletions src/rprocessing/r/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ green = processing$green
hue = processing$hue
image = processing$image
imageMode = processing$imageMode
keyPressed = processing$keyPressed
keyReleased = processing$keyReleased
keyTyped = processing$keyTyped
lerpColor = processing$lerpColor
lightFalloff = processing$lightFalloff
lightSpecular = processing$lightSpecular
Expand All @@ -89,12 +86,6 @@ millis = processing$millis
modelX = processing$modelX
modelY = processing$modelY
modelZ = processing$modelZ
mouseClicked = processing$mouseClicked
mouseDragged = processing$mouseDragged
mouseMoved = processing$mouseMoved
mousePressed = processing$mousePressed
mouseReleased = processing$mouseReleased
mouseWheel = processing$mouseWheel
noClip = processing$noClip
noCursor = processing$noCursor
noFill = processing$noFill
Expand Down
18 changes: 18 additions & 0 deletions src/rprocessing/util/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,22 @@ public class Constant {
public static final String DRAW_NAME = "draw";

public static final String SIZE_NAME = "size";

public static final String MOUSECLICKED_NAME = "mouseClicked";

public static final String MOUSEDRAGGED_NAME = "mouseDragged";

public static final String MOUSEMOVED_NAME = "mouseMoved";

public static final String MOUSEPRESSED_NAME = "mousePressed";

public static final String MOUSERELEASED_NAME = "mouseReleased";

public static final String MOUSEWHEEL_NAME = "mouseWheel";

public static final String KEYPRESSED_NAME = "keyPressed";

public static final String KEYRELEASED_NAME = "keyReleased";

public static final String KEYTYPED_NAME = "keyTyped";
}