1 /* 2 * Copyright (C) 2010 The Android Open Source Project 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 17 18 package com.replica.replicaisland; 19 20 21 public class InputXY { 22 private InputButton mXAxis; 23 private InputButton mYAxis; 24 InputXY()25 public InputXY() { 26 mXAxis = new InputButton(); 27 mYAxis = new InputButton(); 28 } 29 InputXY(InputButton xAxis, InputButton yAxis)30 public InputXY(InputButton xAxis, InputButton yAxis) { 31 mXAxis = xAxis; 32 mYAxis = yAxis; 33 } 34 press(float currentTime, float x, float y)35 public final void press(float currentTime, float x, float y) { 36 mXAxis.press(currentTime, x); 37 mYAxis.press(currentTime, y); 38 } 39 release()40 public final void release() { 41 mXAxis.release(); 42 mYAxis.release(); 43 } 44 getTriggered(float time)45 public boolean getTriggered(float time) { 46 return mXAxis.getTriggered(time) || mYAxis.getTriggered(time); 47 } 48 getPressed()49 public boolean getPressed() { 50 return mXAxis.getPressed() || mYAxis.getPressed(); 51 } 52 setVector(Vector2 vector)53 public final void setVector(Vector2 vector) { 54 vector.x = mXAxis.getMagnitude(); 55 vector.y = mYAxis.getMagnitude(); 56 } 57 getX()58 public final float getX() { 59 return mXAxis.getMagnitude(); 60 } 61 getY()62 public final float getY() { 63 return mYAxis.getMagnitude(); 64 } 65 getLastPressedTime()66 public final float getLastPressedTime() { 67 return Math.max(mXAxis.getLastPressedTime(), mYAxis.getLastPressedTime()); 68 } 69 releaseX()70 public final void releaseX() { 71 mXAxis.release(); 72 } 73 releaseY()74 public final void releaseY() { 75 mYAxis.release(); 76 } 77 78 setMagnitude(float x, float y)79 public void setMagnitude(float x, float y) { 80 mXAxis.setMagnitude(x); 81 mYAxis.setMagnitude(y); 82 } 83 reset()84 public void reset() { 85 mXAxis.reset(); 86 mYAxis.reset(); 87 } 88 clone(InputXY other)89 public void clone(InputXY other) { 90 if (other.getPressed()) { 91 press(other.getLastPressedTime(), other.getX(), other.getY()); 92 } else { 93 release(); 94 } 95 } 96 } 97