Home | History | Annotate | Download | only in replicaisland
      1 package com.replica.replicaisland;
      2 
      3 public class InputTouchScreen extends BaseObject {
      4 
      5 	private int MAX_TOUCH_POINTS = 5;
      6 	private InputXY mTouchPoints[];
      7 
      8 	public InputTouchScreen() {
      9 		mTouchPoints = new InputXY[MAX_TOUCH_POINTS];
     10 		for (int x = 0; x < MAX_TOUCH_POINTS; x++) {
     11 			mTouchPoints[x] = new InputXY();
     12 		}
     13 	}
     14 
     15 	@Override
     16 	public void reset() {
     17 		for (int x = 0; x < MAX_TOUCH_POINTS; x++) {
     18 			mTouchPoints[x].reset();
     19 		}
     20 	}
     21 
     22 	public final void press(int index, float currentTime, float x, float y) {
     23 		assert (index >= 0 && index < MAX_TOUCH_POINTS);
     24 		if (index < MAX_TOUCH_POINTS) {
     25 			mTouchPoints[index].press(currentTime, x, y);
     26 		}
     27 	}
     28 
     29 	public final void release(int index) {
     30 		if (index < MAX_TOUCH_POINTS) {
     31 			mTouchPoints[index].release();
     32 		}
     33 	}
     34 
     35 	public void resetAll() {
     36 		for (int x = 0; x < MAX_TOUCH_POINTS; x++) {
     37 			mTouchPoints[x].reset();
     38 		}
     39 	}
     40 
     41 	public boolean getTriggered(int index, float time) {
     42 		boolean triggered = false;
     43 		if (index < MAX_TOUCH_POINTS) {
     44 			triggered = mTouchPoints[index].getTriggered(time);
     45 		}
     46 		return triggered;
     47 	}
     48 
     49 	public boolean getPressed(int index) {
     50 		boolean pressed = false;
     51 		if (index < MAX_TOUCH_POINTS) {
     52 			pressed = mTouchPoints[index].getPressed();
     53 		}
     54 		return pressed;
     55 	}
     56 
     57 	public final void setVector(int index, Vector2 vector) {
     58 		if (index < MAX_TOUCH_POINTS) {
     59 			mTouchPoints[index].setVector(vector);
     60 		}
     61 	}
     62 
     63 	public final float getX(int index) {
     64 		float magnitude = 0.0f;
     65 		if (index < MAX_TOUCH_POINTS) {
     66 			magnitude = mTouchPoints[index].getX();
     67 		}
     68 		return magnitude;
     69 	}
     70 
     71 	public final float getY(int index) {
     72 		float magnitude = 0.0f;
     73 		if (index < MAX_TOUCH_POINTS) {
     74 			magnitude = mTouchPoints[index].getY();
     75 		}
     76 		return magnitude;
     77 	}
     78 
     79 	public final float getLastPressedTime(int index) {
     80 		float time = 0.0f;
     81 		if (index < MAX_TOUCH_POINTS) {
     82 			time = mTouchPoints[index].getLastPressedTime();
     83 		}
     84 		return time;
     85 	}
     86 
     87 	public InputXY findPointerInRegion(float regionX, float regionY, float regionWidth, float regionHeight) {
     88 		InputXY touch = null;
     89 		for (int x = 0; x < MAX_TOUCH_POINTS; x++) {
     90 			final InputXY pointer = mTouchPoints[x];
     91 			if (pointer.getPressed() &&
     92 					getTouchedWithinRegion(pointer.getX(), pointer.getY(), regionX, regionY, regionWidth, regionHeight)) {
     93 				touch = pointer;
     94 				break;
     95 			}
     96 		}
     97 		return touch;
     98 	}
     99 
    100 	private final boolean getTouchedWithinRegion(float x, float y, float regionX, float regionY, float regionWidth, float regionHeight) {
    101 		 return (x >= regionX &&
    102 				 y >= regionY &&
    103 				 x <= regionX + regionWidth &&
    104 				 y <= regionY + regionHeight);
    105 	}
    106 
    107 	public boolean getTriggered(float gameTime) {
    108 		boolean triggered = false;
    109 		for (int x = 0; x < MAX_TOUCH_POINTS && !triggered; x++) {
    110 			triggered = mTouchPoints[x].getTriggered(gameTime);
    111 		}
    112 		return triggered;
    113 	}
    114 
    115 }
    116