com.watabou.input.Touchscreen Java Examples

The following examples show how to use com.watabou.input.Touchscreen. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Game.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@SneakyThrows
private void step() {

    if (requestedReset) {
        requestedReset = false;
        switchScene(sceneClass.newInstance());
        return;
   }

    Game.elapsed = Game.timeScale * step * 0.001f;

    synchronized (motionEvents) {
        Touchscreen.processTouchEvents(motionEvents);
        motionEvents.clear();
    }
    synchronized (keysEvents) {
        Keys.processTouchEvents(keysEvents);
        keysEvents.clear();
    }

    scene.update();
    Camera.updateAll();
}
 
Example #2
Source File: Game.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
protected void update() {
	Game.elapsed = Game.timeScale * step * 0.001f;
	
	synchronized (motionEvents) {
		Touchscreen.processTouchEvents( motionEvents );
		motionEvents.clear();
	}
	synchronized (keysEvents) {
		Keys.processTouchEvents( keysEvents );
		keysEvents.clear();
	}
	
	scene.update();		
	Camera.updateAll();
}
 
Example #3
Source File: TouchArea.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
public TouchArea( float x, float y, float width, float height ) {
	super( x, y, width, height );
	this.target = this;
	
	visible = false;
	
	Touchscreen.event.add( this );
}
 
Example #4
Source File: TouchArea.java    From PD-classes with GNU General Public License v3.0 5 votes vote down vote up
public TouchArea( float x, float y, float width, float height ) {
	super( x, y, width, height );
	this.target = this;
	
	visible = false;
	
	Touchscreen.event.add( this );
}
 
Example #5
Source File: Game.java    From PD-classes with GNU General Public License v3.0 5 votes vote down vote up
protected void update() {
	Game.elapsed = Game.timeScale * step * 0.001f;
	
	synchronized (motionEvents) {
		Touchscreen.processTouchEvents( motionEvents );
		motionEvents.clear();
	}
	synchronized (keysEvents) {
		Keys.processTouchEvents( keysEvents );
		keysEvents.clear();
	}
	
	scene.update();		
	Camera.updateAll();
}
 
Example #6
Source File: TouchArea.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public TouchArea(float x, float y, float width, float height) {
    super(x, y, width, height);
    this.target = this;

    setVisible(false);

    Touchscreen.event.add(this);
}
 
Example #7
Source File: TouchArea.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public TouchArea(Visual target) {
    super(0, 0, 0, 0);
    this.target = target;

    Touchscreen.event.add(this);
}
 
Example #8
Source File: TouchArea.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	Touchscreen.event.remove( this );
	super.destroy();
}
 
Example #9
Source File: TouchArea.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSignal( Touch touch ) {
	
	if (!isActive()) {
		return;
	}
	
	boolean hit = touch != null && target.overlapsScreenPoint( (int)touch.start.x, (int)touch.start.y );
	
	if (hit) {

		Touchscreen.event.cancel();
		
		if (touch.down) {
			
			if (this.touch == null) {
				this.touch = touch;
			}
			onTouchDown( touch );
			
		} else {
			
			onTouchUp( touch );
			
			if (this.touch == touch) {
				this.touch = null;
				onClick( touch );
			}

		}
		
	} else {
		
		if (touch == null && this.touch != null) {
			onDrag( this.touch );
		}
		
		else if (this.touch != null && touch != null && !touch.down) {
			onTouchUp( touch );
			this.touch = null;
		}
		
	}
}
 
Example #10
Source File: TouchArea.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public TouchArea( Visual target ) {
	super( 0, 0, 0, 0 );
	this.target = target;
	
	Touchscreen.event.add( this );
}
 
Example #11
Source File: WndSelectLanguage.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public WndSelectLanguage(String title, String... options) {
	super();

	int WIDTH = WndHelper.getFullscreenWidth();

	int maxW = WIDTH - GAP * 2;

	Text tfTitle = PixelScene.createMultiline(title, GuiProperties.titleFontSize());
	tfTitle.hardlight(TITLE_COLOR);
	tfTitle.x = tfTitle.y = GAP;
	tfTitle.maxWidth(maxW);
	add(tfTitle);

	Text pleaseHelpTranslate = PixelScene.createMultiline(Game.getVar(R.string.WndSelectLanguage_ImproveTranslation), GuiProperties.titleFontSize());
	pleaseHelpTranslate.maxWidth(maxW);
	pleaseHelpTranslate.x = GAP;
	pleaseHelpTranslate.y = tfTitle.y + tfTitle.height() + GAP;
	add(pleaseHelpTranslate);

	Text translateLink = PixelScene.createMultiline(Game.getVar(R.string.WndSelectLanguage_LinkToTranslationSite), GuiProperties.titleFontSize());
	translateLink.hardlight(TITLE_COLOR);
	translateLink.maxWidth(maxW);
	translateLink.x = GAP;
	translateLink.y = pleaseHelpTranslate.y + pleaseHelpTranslate.height() + GAP;
	add(translateLink);

	TouchArea area = new TouchArea(translateLink) {
		@Override
		protected void onClick(Touchscreen.Touch touch) {
			Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Game.getVar(R.string.WndSelectLanguage_TranslationLink)));

			Game.instance().startActivity(Intent.createChooser(intent, Game.getVar(R.string.WndSelectLanguage_TranslationLink)));
		}
	};
	add(area);

	float pos = translateLink.y + translateLink.height() + GAP;

	final int columns = RemixedDungeon.landscape() ? 3 : 2;

	int BUTTON_WIDTH = WIDTH / columns - GAP;

	int lastButtonBottom = 0;

	for (int i = 0; i < options.length / columns + 1; i++) {

		for (int j = 0; j < columns; j++) {
			final int index = i * columns + j;
			if (!(index < options.length)) {
				break;
			}
			SystemRedButton btn = new SystemRedButton(options[index]) {
				@Override
				protected void onClick() {
					hide();
					onSelect(index);
				}
			};

			btn.setRect(GAP + j * (BUTTON_WIDTH + GAP), pos, BUTTON_WIDTH, BUTTON_HEIGHT);
			add(btn);

			lastButtonBottom = (int) btn.bottom();
		}
		pos += BUTTON_HEIGHT + GAP;
	}

	resize(WIDTH, lastButtonBottom + GAP);
}
 
Example #12
Source File: PixelScene.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	Touchscreen.event.removeAll();
}
 
Example #13
Source File: TouchArea.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
    Touchscreen.event.remove(this);
    super.destroy();
}
 
Example #14
Source File: TouchArea.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSignal(Touch touch) {

    if (!isActive()) {
        return;
    }

    boolean hit = touch != null && target.overlapsScreenPoint((int) touch.start.x, (int) touch.start.y);

    if (hit) {

        if (catchTouch) {
            Touchscreen.event.cancel();
        }

        if (touch.down) {

            if (this.touch == null) {
                this.touch = touch;
            }
            onTouchDown(touch);

        } else {

            onTouchUp(touch);

            if (this.touch == touch) {
                this.touch = null;
                onClick(touch);
            }

        }

    } else {

        if (touch == null && this.touch != null) {
            onDrag(this.touch);
        } else if (this.touch != null && !touch.down) {
            onTouchUp(touch);
            this.touch = null;
        }
    }
}
 
Example #15
Source File: PixelScene.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	Touchscreen.event.removeAll();
}
 
Example #16
Source File: PixelScene.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	Touchscreen.event.removeAll();
}
 
Example #17
Source File: PixelScene.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	super.destroy();
	Touchscreen.event.removeAll();
}
 
Example #18
Source File: TouchArea.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void destroy() {
	Touchscreen.event.remove( this );
	super.destroy();
}
 
Example #19
Source File: TouchArea.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onSignal( Touch touch ) {
	
	if (!isActive()) {
		return;
	}
	
	boolean hit = touch != null && target.overlapsScreenPoint( (int)touch.start.x, (int)touch.start.y );
	
	if (hit) {

		Touchscreen.event.cancel();
		
		if (touch.down) {
			
			if (this.touch == null) {
				this.touch = touch;
			}
			onTouchDown( touch );
			
		} else {
			
			onTouchUp( touch );
			
			if (this.touch == touch) {
				this.touch = null;
				onClick( touch );
			}

		}
		
	} else {
		
		if (touch == null && this.touch != null) {
			onDrag( this.touch );
		}
		
		else if (this.touch != null && touch != null && !touch.down) {
			onTouchUp( touch );
			this.touch = null;
		}
		
	}
}
 
Example #20
Source File: TouchArea.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
public TouchArea( Visual target ) {
	super( 0, 0, 0, 0 );
	this.target = target;
	
	Touchscreen.event.add( this );
}
 
Example #21
Source File: WndBag.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onClick( Touchscreen.Touch touch ){
    WndBag.this.add( new WndItem( WndBag.this, ankh ) );
}