Skip to content

Commit fe92c07

Browse files
committed
major work to clean up event handling
1 parent c98981d commit fe92c07

15 files changed

Lines changed: 589 additions & 211 deletions

File tree

android/core/src/processing/core/PApplet.java

Lines changed: 385 additions & 119 deletions
Large diffs are not rendered by default.

android/core/src/processing/core/PConstants.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,6 @@ public interface PConstants {
167167
public final static int DODGE = 1 << 12;
168168
public final static int BURN = 1 << 13;
169169

170-
// colour component bitmasks
171-
172-
public static final int ALPHA_MASK = 0xff000000;
173-
public static final int RED_MASK = 0x00ff0000;
174-
public static final int GREEN_MASK = 0x0000ff00;
175-
public static final int BLUE_MASK = 0x000000ff;
176-
177170

178171
// for messages
179172

@@ -262,6 +255,13 @@ public interface PConstants {
262255
static final int CENTER_DIAMETER = 3;
263256

264257

258+
// arc drawing modes
259+
260+
//static final int OPEN = 1; // shared
261+
static final int CHORD = 2;
262+
static final int PIE = 3;
263+
264+
265265
// vertically alignment modes for text
266266

267267
/** Default vertical alignment for text placement */

android/core/src/processing/core/PGraphics.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,12 @@ protected void ellipseImpl(float x, float y, float w, float h) {
19951995
*/
19961996
public void arc(float a, float b, float c, float d,
19971997
float start, float stop) {
1998+
arc(a, b, c, d, start, stop, 0);
1999+
}
2000+
2001+
2002+
public void arc(float a, float b, float c, float d,
2003+
float start, float stop, int mode) {
19982004
float x = a;
19992005
float y = b;
20002006
float w = c;
@@ -2015,11 +2021,23 @@ public void arc(float a, float b, float c, float d,
20152021
y = b - d/2f;
20162022
}
20172023

2018-
// make sure this loop will exit before starting while
2019-
if (Float.isInfinite(start) || Float.isInfinite(stop)) return;
2020-
while (stop < start) stop += TWO_PI;
2024+
// make sure the loop will exit before starting while
2025+
if (!Float.isInfinite(start) && !Float.isInfinite(stop)) {
2026+
// ignore equal and degenerate cases
2027+
if (stop > start) {
2028+
// make sure that we're starting at a useful point
2029+
while (start < 0) {
2030+
start += TWO_PI;
2031+
stop += TWO_PI;
2032+
}
20212033

2022-
arcImpl(x, y, w, h, start, stop);
2034+
if (stop - start > TWO_PI) {
2035+
start = 0;
2036+
stop = TWO_PI;
2037+
}
2038+
arcImpl(x, y, w, h, start, stop, mode);
2039+
}
2040+
}
20232041
}
20242042

20252043

@@ -2030,7 +2048,8 @@ public void arc(float a, float b, float c, float d,
20302048
* and the user will still collect $200.
20312049
*/
20322050
protected void arcImpl(float x, float y, float w, float h,
2033-
float start, float stop) {
2051+
float start, float stop, int mode) {
2052+
showMissingWarning("arc");
20342053
}
20352054

20362055

android/core/src/processing/core/PImage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public class PImage implements PConstants, Cloneable {
9999
private int[] blurKernel;
100100
private int[][] blurMult;
101101

102+
// colour component bitmasks (moved from PConstants in 2.0b7)
103+
public static final int ALPHA_MASK = 0xff000000;
104+
public static final int RED_MASK = 0x00ff0000;
105+
public static final int GREEN_MASK = 0x0000ff00;
106+
public static final int BLUE_MASK = 0x000000ff;
107+
102108

103109
//////////////////////////////////////////////////////////////
104110

android/core/src/processing/event/Event.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ public class Event {
2929
protected long millis;
3030
protected int action;
3131

32-
static public final int SHIFT_MASK = 1 << 6;
33-
static public final int CTRL_MASK = 1 << 7;
34-
static public final int META_MASK = 1 << 8;
35-
static public final int ALT_MASK = 1 << 9;
32+
// These correspond to the java.awt.Event modifiers (not to be confused with
33+
// the newer getModifiersEx), though they're not guaranteed to in the future.
34+
static public final int SHIFT = 1 << 0;
35+
static public final int CTRL = 1 << 1;
36+
static public final int META = 1 << 2;
37+
static public final int ALT = 1 << 3;
3638
protected int modifiers;
3739

40+
// Types of events. As with all constants in Processing, brevity's preferred.
41+
static public final int KEY = 1;
42+
static public final int MOUSE = 2;
43+
static public final int TOUCH = 3;
44+
protected int flavor;
45+
3846

3947
public Event(Object nativeObject, long millis, int action, int modifiers) {
4048
this.nativeObject = nativeObject;
@@ -44,6 +52,18 @@ public Event(Object nativeObject, long millis, int action, int modifiers) {
4452
}
4553

4654

55+
public int getFlavor() {
56+
return flavor;
57+
}
58+
59+
60+
/**
61+
* Get the platform-native event object. This might be the java.awt event
62+
* on the desktop, though if you're using OpenGL on the desktop it'll be a
63+
* NEWT event that JOGL uses. Android events are something else altogether.
64+
* Bottom line, use this only if you know what you're doing, and don't make
65+
* assumptions about the class type.
66+
*/
4767
public Object getNative() {
4868
return nativeObject;
4969
}
@@ -85,21 +105,21 @@ public int getModifiers() {
85105

86106

87107
public boolean isShiftDown() {
88-
return (modifiers & SHIFT_MASK) != 0;
108+
return (modifiers & SHIFT) != 0;
89109
}
90110

91111

92112
public boolean isControlDown() {
93-
return (modifiers & CTRL_MASK) != 0;
113+
return (modifiers & CTRL) != 0;
94114
}
95115

96116

97117
public boolean isMetaDown() {
98-
return (modifiers & META_MASK) != 0;
118+
return (modifiers & META) != 0;
99119
}
100120

101121

102122
public boolean isAltDown() {
103-
return (modifiers & ALT_MASK) != 0;
123+
return (modifiers & ALT) != 0;
104124
}
105125
}

android/core/src/processing/event/KeyEvent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525

2626
public class KeyEvent extends Event {
27-
static public final int PRESSED = 1;
28-
static public final int RELEASED = 2;
29-
static public final int TYPED = 3;
27+
static public final int PRESS = 1;
28+
static public final int RELEASE = 2;
29+
static public final int TYPE = 3;
3030

3131
char key;
3232
int keyCode;
@@ -36,6 +36,7 @@ public KeyEvent(Object nativeObject,
3636
long millis, int action, int modifiers,
3737
char key, int keyCode) {
3838
super(nativeObject, millis, action, modifiers);
39+
this.flavor = KEY;
3940
this.key = key;
4041
this.keyCode = keyCode;
4142
}

android/core/src/processing/event/MouseEvent.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@
2626

2727

2828
public class MouseEvent extends Event {
29-
static public final int PRESSED = 1;
30-
static public final int RELEASED = 2;
31-
static public final int CLICKED = 3;
32-
static public final int DRAGGED = 4;
33-
static public final int MOVED = 5;
34-
static public final int ENTERED = 6;
35-
static public final int EXITED = 7;
29+
static public final int PRESS = 1;
30+
static public final int RELEASE = 2;
31+
static public final int CLICK = 3;
32+
static public final int DRAG = 4;
33+
static public final int MOVE = 5;
34+
static public final int ENTER = 6;
35+
static public final int EXIT = 7;
3636

3737
protected int x, y;
3838
protected int button;
@@ -50,6 +50,7 @@ public MouseEvent(Object nativeObject,
5050
long millis, int action, int modifiers,
5151
int x, int y, int button, int clickCount) {
5252
super(nativeObject, millis, action, modifiers);
53+
this.flavor = MOUSE;
5354
this.x = x;
5455
this.y = y;
5556
this.button = button;

android/core/src/processing/event/TouchEvent.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,24 @@
2323
package processing.event;
2424

2525

26+
/*
27+
http://developer.android.com/guide/topics/ui/ui-events.html
28+
http://developer.android.com/reference/android/view/MotionEvent.html
29+
http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html
30+
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer
31+
32+
Apple's high-level gesture names:
33+
tap
34+
pinch
35+
rotate
36+
swipe
37+
pan
38+
longpress
39+
*/
2640
public class TouchEvent extends Event {
2741

2842
public TouchEvent(Object nativeObject, long millis, int action, int modifiers) {
2943
super(nativeObject, millis, action, modifiers);
44+
this.flavor = TOUCH;
3045
}
31-
}
46+
}

android/todo.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ X removing default imports for
33
X android.view.MotionEvent, android.view.KeyEvent,android.graphics.Bitmap
44
X due to conflicts w/ the new p5 event system
55

6+
cleaning/earlier
7+
A Defects in the tessellation of SVG shapes in A3D
8+
A http://code.google.com/p/processing/issues/detail?id=291
9+
10+
11+
_ Finish implementation of OPEN and CHORD drawing modes for arc()
12+
_ http://code.google.com/p/processing/issues/detail?id=1405
13+
14+
_ implement blendMode() for Android
15+
_ should be fairly straightforward given Java2D implementation
16+
_ http://code.google.com/p/processing/issues/detail?id=1386
17+
18+
_ Update documentation and tools for Android SDK Tools revision 21
19+
_ http://code.google.com/p/processing/issues/detail?id=1398
20+
21+
_ re-implement to use Fragment API
22+
_ and what about daydream or widgets or whatever?
23+
_ http://code.google.com/p/processing/issues/detail?id=1335
24+
625
_ implement Android version of command line tools
726
_ http://code.google.com/p/processing/issues/detail?id=1323
827

@@ -30,6 +49,7 @@ _ PApplet.match(scrubbed, processing.mode.java.JavaBuild.SIZE_REGEX);
3049
_ test libraries on android
3150

3251
_ no ES2 in the emulator, and no error reported in the PDE
52+
_ http://code.google.com/p/processing/issues/detail?id=1059
3353
_ problem is probably that the error comes via E/AndroidRuntime
3454
_ java.lang.RuntimeException: Unable to start activity ComponentInfo{processing.test.fisheye/processing.test.fisheye.FishEye}: java.lang.RuntimeException: P3D: OpenGL ES 2.0 is not supported by this device.
3555

0 commit comments

Comments
 (0)