Skip to content

Commit c0624aa

Browse files
committed
added ENABLE_KEY_REPEAT hint
1 parent e5faea6 commit c0624aa

File tree

4 files changed

+86
-57
lines changed

4 files changed

+86
-57
lines changed

core/src/processing/core/PApplet.java

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656

5757
public class PApplet extends Object implements PConstants {
5858

59+
//static final public boolean DEBUG = true;
60+
static final public boolean DEBUG = false;
61+
62+
// Convenience public constant holding the SDK version, akin to platform in Java mode
63+
static final public int SDK = Build.VERSION.SDK_INT;
64+
65+
//static final public int SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; // Forcing older SDK for testing
66+
5967
/**
6068
* The surface this sketch draws to.
6169
*/
@@ -69,14 +77,6 @@ public class PApplet extends Object implements PConstants {
6977
/** The PGraphics renderer associated with this PApplet */
7078
public PGraphics g;
7179

72-
// static final public boolean DEBUG = true;
73-
static final public boolean DEBUG = false;
74-
75-
// Convenience public constant holding the SDK version, akin to platform in Java mode
76-
static final public int SDK = Build.VERSION.SDK_INT;
77-
78-
// static final public int SDK = Build.VERSION_CODES.ICE_CREAM_SANDWICH; // Forcing older SDK for testing
79-
8080
/**
8181
* The screen size when the sketch was started. This is initialized inside
8282
* onCreate().
@@ -147,6 +147,9 @@ public class PApplet extends Object implements PConstants {
147147
public int pixelWidth;
148148
public int pixelHeight;
149149

150+
///////////////////////////////////////////////////////////////
151+
// Mouse events
152+
150153
/** absolute x position of input on screen */
151154
public int mouseX;
152155

@@ -203,6 +206,8 @@ public class PApplet extends Object implements PConstants {
203206
*/
204207
protected int touchPointerId;
205208

209+
///////////////////////////////////////////////////////////////
210+
// Key events
206211

207212
/**
208213
* Last key pressed.
@@ -236,6 +241,11 @@ public class PApplet extends Object implements PConstants {
236241
*/
237242
public boolean focused = false;
238243

244+
/**
245+
* Keeps track of ENABLE_KEY_REPEAT hint
246+
*/
247+
protected boolean keyRepeatEnabled = false;
248+
239249
///////////////////////////////////////////////////////////////
240250
// Permission handling
241251

@@ -250,31 +260,9 @@ public class PApplet extends Object implements PConstants {
250260
*/
251261
protected ArrayList<String> reqPermissions = new ArrayList<String>();
252262

263+
253264
///////////////////////////////////////////////////////////////
254-
// Wallpaper and watchface variables: these will go away soon...
255-
@Deprecated
256-
public boolean ambientMode = false;
257-
@Deprecated
258-
public boolean isRound = false;
259-
@Deprecated
260-
public int insetLeft = 0;
261-
@Deprecated
262-
public int insetRight = 0;
263-
@Deprecated
264-
public int insetTop = 0;
265-
@Deprecated
266-
public int insetBottom = 0;
267-
@Deprecated
268-
public boolean lowBitAmbient = false;
269-
@Deprecated
270-
public boolean burnInProtection = false;
271-
@Deprecated
272-
public boolean preview = false;
273-
@Deprecated
274-
public float homeScreenOffset = 0;
275-
@Deprecated
276-
public int homeScreenCount = 1;
277-
///////////////////////////////////////////////////////////////
265+
// Rendering/timing
278266

279267
/**
280268
* Time in milliseconds when the applet was started.
@@ -326,9 +314,31 @@ public class PApplet extends Object implements PConstants {
326314
*/
327315
protected boolean exitCalled;
328316

329-
// Thread thread;
317+
boolean insideSettings;
318+
319+
String renderer = JAVA2D;
320+
321+
int smooth = 1; // default smoothing (whatever that means for the renderer)
322+
323+
boolean fullScreen = false;
324+
325+
int display = -1; // use default
326+
327+
// Background default needs to be different from the default value in
328+
// PGraphics.backgroundColor, otherwise size(100, 100) bg spills over.
329+
// https://github.com/processing/processing/issues/2297
330+
int windowColor = 0xffDDDDDD;
330331

331-
// messages to send if attached as an external vm
332+
PStyle savedStyle;
333+
334+
///////////////////////////////////////////////////////////////
335+
// Error messages
336+
337+
static final String ERROR_MIN_MAX =
338+
"Cannot use min() or max() on an empty array.";
339+
340+
///////////////////////////////////////////////////////////////
341+
// Command line options
332342

333343
/**
334344
* Position of the upper-lefthand corner of the editor window
@@ -386,25 +396,6 @@ public class PApplet extends Object implements PConstants {
386396
/** true if this sketch is being run by the PDE */
387397
boolean external = false;
388398

389-
static final String ERROR_MIN_MAX =
390-
"Cannot use min() or max() on an empty array.";
391-
392-
boolean insideSettings;
393-
394-
String renderer = JAVA2D;
395-
396-
int smooth = 1; // default smoothing (whatever that means for the renderer)
397-
398-
boolean fullScreen = false;
399-
400-
int display = -1; // use default
401-
402-
// Background default needs to be different from the default value in
403-
// PGraphics.backgroundColor, otherwise size(100, 100) bg spills over.
404-
// https://github.com/processing/processing/issues/2297
405-
int windowColor = 0xffDDDDDD;
406-
407-
PStyle savedStyle;
408399

409400
//////////////////////////////////////////////////////////////
410401
//////////////////////////////////////////////////////////////
@@ -2428,6 +2419,10 @@ boolean wearBurnProtection() {
24282419

24292420

24302421
protected void handleKeyEvent(KeyEvent event) {
2422+
2423+
// Get rid of auto-repeating keys if desired and supported
2424+
if (!keyRepeatEnabled && event.isAutoRepeat()) return;
2425+
24312426
// keyEvent = event;
24322427
key = event.getKey();
24332428
keyCode = event.getKeyCode();
@@ -2469,8 +2464,10 @@ protected void nativeKeyEvent(android.view.KeyEvent event) {
24692464
// TODO set up proper key modifier handling
24702465
int keModifiers = 0;
24712466

2467+
// KeyEvent ke = new KeyEvent(event, event.getEventTime(),
2468+
// keAction, keModifiers, key, keyCode);
24722469
KeyEvent ke = new KeyEvent(event, event.getEventTime(),
2473-
keAction, keModifiers, key, keyCode);
2470+
keAction, keModifiers, key, keyCode, 0 < event.getRepeatCount());
24742471

24752472
postEvent(ke);
24762473
}

core/src/processing/core/PConstants.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,9 @@ public interface PConstants {
396396
// hints - hint values are positive for the alternate version,
397397
// negative of the same value returns to the normal/default state
398398

399+
@Deprecated
399400
static final int ENABLE_NATIVE_FONTS = 1;
401+
@Deprecated
400402
static final int DISABLE_NATIVE_FONTS = -1;
401403

402404
static final int DISABLE_DEPTH_TEST = 2;
@@ -426,10 +428,13 @@ public interface PConstants {
426428
static final int ENABLE_BUFFER_READING = 10;
427429
static final int DISABLE_BUFFER_READING = -10;
428430

429-
static final int DISABLE_ASYNC_SAVEFRAME = 11;
430-
static final int ENABLE_ASYNC_SAVEFRAME = -11;
431+
static final int DISABLE_KEY_REPEAT = 11;
432+
static final int ENABLE_KEY_REPEAT = -11;
433+
434+
static final int DISABLE_ASYNC_SAVEFRAME = 12;
435+
static final int ENABLE_ASYNC_SAVEFRAME = -12;
431436

432-
static final int HINT_COUNT = 12;
437+
static final int HINT_COUNT = 13;
433438

434439

435440
// error messages

core/src/processing/core/PGraphics.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,18 @@ protected void reapplySettings() {
984984
* turns off the z-buffer in the P3D or OPENGL renderers.
985985
* </UL>
986986
*/
987+
@SuppressWarnings("deprecation")
987988
public void hint(int which) {
989+
if (which == ENABLE_NATIVE_FONTS ||
990+
which == DISABLE_NATIVE_FONTS) {
991+
showWarning("hint(ENABLE_NATIVE_FONTS) no longer supported. " +
992+
"Use createFont() instead.");
993+
}
994+
if (which == ENABLE_KEY_REPEAT) {
995+
parent.keyRepeatEnabled = true;
996+
} else if (which == DISABLE_KEY_REPEAT) {
997+
parent.keyRepeatEnabled = false;
998+
}
988999
if (which > 0) {
9891000
hints[which] = true;
9901001
} else {

core/src/processing/event/KeyEvent.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class KeyEvent extends Event {
3131
char key;
3232
int keyCode;
3333

34+
boolean isAutoRepeat;
3435

3536
public KeyEvent(Object nativeObject,
3637
long millis, int action, int modifiers,
@@ -42,6 +43,17 @@ public KeyEvent(Object nativeObject,
4243
}
4344

4445

46+
public KeyEvent(Object nativeObject,
47+
long millis, int action, int modifiers,
48+
char key, int keyCode, boolean isAutoRepeat) {
49+
super(nativeObject, millis, action, modifiers);
50+
this.flavor = KEY;
51+
this.key = key;
52+
this.keyCode = keyCode;
53+
this.isAutoRepeat = isAutoRepeat;
54+
}
55+
56+
4557
public char getKey() {
4658
return key;
4759
}
@@ -50,4 +62,8 @@ public char getKey() {
5062
public int getKeyCode() {
5163
return keyCode;
5264
}
65+
66+
public boolean isAutoRepeat() {
67+
return isAutoRepeat;
68+
}
5369
}

0 commit comments

Comments
 (0)