View Javadoc

1   /*
2    * Copyright 2007-2008 motej
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 motejx.extensions.classic;
17  
18  /**
19   * 
20   * <p>
21   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
22   */
23  public class ClassicControllerButtonEvent {
24  	
25  	public static final int BUTTON_A = 4096;
26  	
27  	public static final int BUTTON_B = 16384;
28  
29  	public static final int BUTTON_HOME = 8;
30  
31  	public static final int BUTTON_LEFT_TRIGGER = 32;
32  
33  	public static final int BUTTON_MINUS = 16;
34  
35  	public static final int BUTTON_PLUS = 4;
36  
37  	public static final int BUTTON_RIGHT_TRIGGER = 2;
38  
39  	public static final int BUTTON_X = 2048;
40  
41  	public static final int BUTTON_Y = 8192;
42  	
43  	public static final int BUTTON_ZL = 32768;
44  	
45  	public static final int BUTTON_ZR = 1024;
46  
47  	public static final int D_PAD_DOWN = 64;
48  
49  	public static final int D_PAD_LEFT = 512;
50  
51  	public static final int D_PAD_RIGHT = 128;
52  	
53  	public static final int D_PAD_UP = 256;
54  	
55  	public static final int NO_BUTTON = 0;
56  
57  	private int modifiers;
58  	
59  	private ClassicController source;
60  	
61  	public ClassicControllerButtonEvent(ClassicController source, int modifiers) {
62  		this.source = source;
63  		this.modifiers = modifiers;
64  	}
65  	
66  	public ClassicController getSource() {
67  		return source;
68  	}
69  	
70  	public boolean isButtonAPressed() {
71  		return (BUTTON_A & modifiers) == BUTTON_A;
72  	}
73  	
74  	public boolean isButtonBPressed() {
75  		return (BUTTON_B & modifiers) == BUTTON_B;
76  	}
77  	
78  	public boolean isButtonHomePressed() {
79  		return (BUTTON_HOME & modifiers) == BUTTON_HOME;
80  	}
81  	
82  	public boolean isButtonLeftTriggerPressed() {
83  		return (BUTTON_LEFT_TRIGGER & modifiers) == BUTTON_LEFT_TRIGGER;
84  	}
85  	
86  	public boolean isButtonMinusPressed() {
87  		return (BUTTON_MINUS & modifiers) == BUTTON_MINUS;
88  	}
89  	
90  	public boolean isButtonPlusPressed() {
91  		return (BUTTON_PLUS & modifiers) == BUTTON_PLUS;
92  	}
93  	
94  	public boolean isButtonRightTriggerPressed() {
95  		return (BUTTON_RIGHT_TRIGGER & modifiers) == BUTTON_RIGHT_TRIGGER;
96  	}
97  	
98  	public boolean isButtonXPressed() {
99  		return (BUTTON_X & modifiers) == BUTTON_X;
100 	}
101 	
102 	public boolean isButtonYPressed() {
103 		return (BUTTON_Y & modifiers) == BUTTON_Y;
104 	}
105 	
106 	public boolean isButtonZLPressed() {
107 		return (BUTTON_ZL & modifiers) == BUTTON_ZL;
108 	}
109 	
110 	public boolean isButtonZRPressed() {
111 		return (BUTTON_ZR & modifiers) == BUTTON_ZR;
112 	}
113 	
114 	public boolean isDPadDownPressed() {
115 		return (D_PAD_DOWN & modifiers) == D_PAD_DOWN;
116 	}
117 	
118 	public boolean isDPadLeftPressed() {
119 		return (D_PAD_LEFT & modifiers) == D_PAD_LEFT;
120 	}
121 	
122 	public boolean isDPadRightPressed() {
123 		return (D_PAD_RIGHT & modifiers) == D_PAD_RIGHT;
124 	}
125 	
126 	public boolean isDPadUpPressed() {
127 		return (D_PAD_UP & modifiers) == D_PAD_UP;
128 	}
129 	
130 	public boolean isNoButtonPressed() {
131 		return modifiers == NO_BUTTON;
132 	}
133 	
134 }