Skip to content

Commit 6ebd7ba

Browse files
authored
Example: Add data (#192)
* *: Add mouseButton Signed-off-by: Ce Gao <ce.gao@outlook.com> * coala: Fix coding style issues Signed-off-by: Ce Gao <ce.gao@outlook.com>
1 parent 10ddad8 commit 6ebd7ba

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Click within the image and press the left and right mouse buttons to change the
2+
# value of the rectangle
3+
draw <- function() {
4+
rect(25, 25, 50, 50)
5+
}
6+
7+
mousePressed <- function() {
8+
if (mouseButton == LEFT) {
9+
fill(0)
10+
} else if (mouseButton == RIGHT) {
11+
fill(255)
12+
} else {
13+
fill(126)
14+
}
15+
}

src/rprocessing/RLangPApplet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import processing.core.PApplet;
2727
import processing.core.PConstants;
2828
import processing.core.PSurface;
29+
import processing.event.MouseEvent;
2930
import processing.javafx.PSurfaceFX;
3031
import processing.opengl.PSurfaceJOGL;
3132
import rprocessing.applet.BuiltinApplet;
@@ -381,6 +382,12 @@ protected void wrapProcessingVariables() {
381382
// this.renjinEngine.put("keyPressed", keyPressed);
382383
}
383384

385+
@Override
386+
protected void handleMouseEvent(MouseEvent event) {
387+
super.handleMouseEvent(event);
388+
wrapMouseVariables();
389+
}
390+
384391
@Override
385392
public void mouseClicked() {
386393
wrapMouseVariables();
@@ -436,7 +443,7 @@ private void wrapMouseVariables() {
436443
this.renjinEngine.put("mouseY", mouseY);
437444
this.renjinEngine.put("pmouseX", pmouseX);
438445
this.renjinEngine.put("pmouseY", pmouseY);
439-
// this.renjinEngine.put("mouseButton", mouseButton);
446+
this.renjinEngine.put("mouseButton", mouseButton);
440447
}
441448

442449
private void applyFunction(String name) {

0 commit comments

Comments
 (0)