Create EventUtils to assist with repetitive macros

Added EventUtils.click(Button) to click button programmically and call its click listeners
This commit is contained in:
Collin Smith 2019-01-17 22:35:50 -08:00
parent cbaba5c40b
commit 8f4d8aaab6

View File

@ -0,0 +1,29 @@
package gdx.diablo.util;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.utils.Pools;
public class EventUtils {
private EventUtils() {}
public static boolean click(Button button) {
if (button.isDisabled()) return false;
InputEvent event = Pools.obtain(InputEvent.class);
event.setType(InputEvent.Type.touchDown);
event.setStage(button.getStage());
event.setStageX(0);
event.setStageY(0);
event.setPointer(0);
event.setButton(Input.Buttons.LEFT);
event.setListenerActor(button);
button.fire(event);
event.setType(InputEvent.Type.touchUp);
button.fire(event);
Pools.free(event);
return true;
}
}