Search in sources :

Example 1 with MockPointer

use of com.gemserk.commons.gdx.input.MockPointer in project commons-gdx by gemserk.

the class ToggleableImageButtonTest method shouldToggleIfPointerPressedAndInside.

@Test
public void shouldToggleIfPointerPressedAndInside() {
    MockPointer pointer = new MockPointer();
    MockToggleHandler toggleHandler = new MockToggleHandler();
    ToggleableImageButton toggleableImageButton = new ToggleableImageButton() {

        @Override
        protected void recalculateBounds() {
        }
    };
    toggleableImageButton.setPointer(pointer);
    toggleableImageButton.setToggleHandler(toggleHandler);
    toggleableImageButton.setPosition(0f, 0f);
    toggleableImageButton.setBounds(new Rectangle(20, 20, 100, 100));
    pointer.wasReleased = true;
    pointer.releasedPosition.set(25, 25);
    toggleableImageButton.update();
    assertThat(toggleHandler.toggleCalled, IsEqual.equalTo(true));
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MockPointer(com.gemserk.commons.gdx.input.MockPointer) Test(org.junit.Test)

Example 2 with MockPointer

use of com.gemserk.commons.gdx.input.MockPointer in project commons-gdx by gemserk.

the class ToggleableImageButtonTest method shouldNotToggleIfPointerPressedButOutside.

@Test
public void shouldNotToggleIfPointerPressedButOutside() {
    MockPointer pointer = new MockPointer();
    MockToggleHandler toggleHandler = new MockToggleHandler();
    ToggleableImageButton toggleableImageButton = new ToggleableImageButton() {

        @Override
        protected void recalculateBounds() {
        }
    };
    toggleableImageButton.setPointer(pointer);
    toggleableImageButton.setToggleHandler(toggleHandler);
    toggleableImageButton.setPosition(0f, 0f);
    toggleableImageButton.setBounds(new Rectangle(20, 20, 100, 100));
    pointer.wasReleased = true;
    pointer.releasedPosition.set(-20, -20);
    toggleableImageButton.update();
    assertThat(toggleHandler.toggleCalled, IsEqual.equalTo(false));
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MockPointer(com.gemserk.commons.gdx.input.MockPointer) Test(org.junit.Test)

Example 3 with MockPointer

use of com.gemserk.commons.gdx.input.MockPointer in project commons-gdx by gemserk.

the class ToggleableImageButtonTest method shouldToggleIfPointerPressedAndInsideOnlyOnce.

@Test
public void shouldToggleIfPointerPressedAndInsideOnlyOnce() {
    MockPointer pointer = new MockPointer();
    MockToggleHandler toggleHandler = new MockToggleHandler();
    ToggleableImageButton toggleableImageButton = new ToggleableImageButton() {

        @Override
        protected void recalculateBounds() {
        }
    };
    toggleableImageButton.setPointer(pointer);
    toggleableImageButton.setToggleHandler(toggleHandler);
    toggleableImageButton.setPosition(0f, 0f);
    toggleableImageButton.setBounds(new Rectangle(20, 20, 100, 100));
    pointer.wasReleased = true;
    pointer.releasedPosition.set(25, 25);
    toggleableImageButton.update();
    assertThat(toggleHandler.toggleCalled, IsEqual.equalTo(true));
    pointer.wasReleased = false;
    toggleHandler.toggleCalled = false;
    toggleableImageButton.update();
    assertThat(toggleHandler.toggleCalled, IsEqual.equalTo(false));
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MockPointer(com.gemserk.commons.gdx.input.MockPointer) Test(org.junit.Test)

Example 4 with MockPointer

use of com.gemserk.commons.gdx.input.MockPointer in project commons-gdx by gemserk.

the class ToggleableImageButtonTest method shouldNotToggleIfPointerIsNotPressed.

@Test
public void shouldNotToggleIfPointerIsNotPressed() {
    MockPointer pointer = new MockPointer();
    MockToggleHandler toggleHandler = new MockToggleHandler();
    ToggleableImageButton toggleableImageButton = new ToggleableImageButton() {

        @Override
        protected void recalculateBounds() {
        }
    };
    toggleableImageButton.setPointer(pointer);
    toggleableImageButton.setToggleHandler(toggleHandler);
    toggleableImageButton.setPosition(0f, 0f);
    toggleableImageButton.setBounds(new Rectangle(20, 20, 100, 100));
    pointer.wasReleased = false;
    toggleableImageButton.update();
    assertThat(toggleHandler.toggleCalled, IsEqual.equalTo(false));
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) MockPointer(com.gemserk.commons.gdx.input.MockPointer) Test(org.junit.Test)

Aggregations

Rectangle (com.badlogic.gdx.math.Rectangle)4 MockPointer (com.gemserk.commons.gdx.input.MockPointer)4 Test (org.junit.Test)4