Skip to content

Commit

Permalink
fix broken isButtonJustPressed in GWT backend, fixes libgdx#5805 (lib…
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsx-dev authored and WickedShell committed Nov 20, 2019
1 parent 543937a commit 66d602e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Expand Up @@ -588,8 +588,9 @@ private void handleEvent (NativeEvent e) {
hasFocus = true;
this.justTouched = true;
this.touched[0] = true;
this.pressedButtons.add(getButton(e.getButton()));
justPressedButtons[e.getButton()] = true;
final int button = getButton(e.getButton());
this.pressedButtons.add(button);
justPressedButtons[button] = true;
this.deltaX[0] = 0;
this.deltaY[0] = 0;
if (isCursorCatched()) {
Expand Down
2 changes: 1 addition & 1 deletion gdx/src/com/badlogic/gdx/Input.java
Expand Up @@ -653,7 +653,7 @@ public enum Peripheral {
public boolean isButtonPressed (int button);

/** Returns whether a given button has just been pressed. Button constants can be found in {@link Buttons}. On Android only the Buttons#LEFT
* constant is meaningful before version 4.0.
* constant is meaningful before version 4.0. On WebGL (GWT), only LEFT, RIGHT and MIDDLE buttons are supported.
*
* @param button the button to check.
* @return true or false. */
Expand Down
10 changes: 10 additions & 0 deletions tests/gdx-tests/src/com/badlogic/gdx/tests/gwt/GwtInputTest.java
Expand Up @@ -19,6 +19,7 @@
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
Expand Down Expand Up @@ -74,6 +75,15 @@ public void render () {
if (Gdx.input.isKeyPressed(Keys.DOWN)) {
y -= 1;
}
if (Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
Gdx.app.log("GwtInputTest", "button pressed: LEFT");
}
if (Gdx.input.isButtonJustPressed(Input.Buttons.MIDDLE)){
Gdx.app.log("GwtInputTest", "button pressed: MIDDLE");
}
if (Gdx.input.isButtonJustPressed(Input.Buttons.RIGHT)){
Gdx.app.log("GwtInputTest", "button pressed: RIGHT");
}
}

@Override
Expand Down
Expand Up @@ -359,7 +359,7 @@ public boolean isKeyJustPressed (int key) {

@Override
public boolean isButtonJustPressed (int button) {
return false;
return input.isButtonJustPressed(button);
}

@Override
Expand Down

0 comments on commit 66d602e

Please sign in to comment.