1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package motej.event;
17
18 import motej.Mote;
19
20
21
22
23
24
25 public class CoreButtonEvent {
26
27 public static final int NO_BUTTON = 0;
28
29 public static final int D_PAD_LEFT = 1;
30
31 public static final int D_PAD_RIGHT = 2;
32
33 public static final int D_PAD_UP = 8;
34
35 public static final int D_PAD_DOWN = 4;
36
37 public static final int BUTTON_ONE = 512;
38
39 public static final int BUTTON_TWO = 256;
40
41 public static final int BUTTON_A = 2048;
42
43 public static final int BUTTON_B = 1024;
44
45 public static final int BUTTON_PLUS = 16;
46
47 public static final int BUTTON_MINUS = 4096;
48
49 public static final int BUTTON_HOME = 32768;
50
51 private int modifiers;
52
53 private Mote source;
54
55 public CoreButtonEvent(Mote source, int modifiers) {
56 this.source = source;
57 this.modifiers = modifiers;
58 }
59
60 public int getButton() {
61 return modifiers;
62 }
63
64 public Mote getSource() {
65 return source;
66 }
67
68 public boolean isButtonAPressed() {
69 return (BUTTON_A & modifiers) == BUTTON_A;
70 }
71
72 public boolean isButtonBPressed() {
73 return (BUTTON_B & modifiers) == BUTTON_B;
74 }
75
76 public boolean isButtonHomePressed() {
77 return (BUTTON_HOME & modifiers) == BUTTON_HOME;
78 }
79
80 public boolean isButtonMinusPressed() {
81 return (BUTTON_MINUS & modifiers) == BUTTON_MINUS;
82 }
83
84 public boolean isButtonPlusPressed() {
85 return (BUTTON_PLUS & modifiers) == BUTTON_PLUS;
86 }
87
88 public boolean isButtonOnePressed() {
89 return (BUTTON_ONE & modifiers) == BUTTON_ONE;
90 }
91
92 public boolean isButtonTwoPressed() {
93 return (BUTTON_TWO & modifiers) == BUTTON_TWO;
94 }
95
96 public boolean isDPadLeftPressed() {
97 return (D_PAD_LEFT & modifiers) == D_PAD_LEFT;
98 }
99
100 public boolean isDPadRightPressed() {
101 return (D_PAD_RIGHT & modifiers) == D_PAD_RIGHT;
102 }
103
104 public boolean isDPadUpPressed() {
105 return (D_PAD_UP & modifiers) == D_PAD_UP;
106 }
107
108 public boolean isDPadDownPressed() {
109 return (D_PAD_DOWN & modifiers) == D_PAD_DOWN;
110 }
111
112 public boolean isNoButtonPressed() {
113 return modifiers == NO_BUTTON;
114 }
115 }