View Javadoc

1   /*
2    * Copyright 2007-2008 Volker Fritzsch
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License. 
15   */
16  package motej.event;
17  
18  import motej.Mote;
19  
20  /**
21   * 
22   * <p>
23   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
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 }