Search in sources :

Example 11 with Rectangle

use of com.badlogic.gdx.math.Rectangle 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 12 with Rectangle

use of com.badlogic.gdx.math.Rectangle 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 13 with Rectangle

use of com.badlogic.gdx.math.Rectangle 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 14 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project commons-gdx by gemserk.

the class CameraRestrictedImplTest method bugWhenRecalculatingZoomShouldUseSmallerDimension.

@Test
public void bugWhenRecalculatingZoomShouldUseSmallerDimension() {
    CameraRestrictedImpl camera = new CameraRestrictedImpl(0f, 0f, 1f, 0f, 800f, 480f, new Rectangle(0f, 0f, 12f, 4f));
    assertThat(camera.getZoom(), IsEqual.equalTo(120f));
    camera = new CameraRestrictedImpl(0f, 0f, 1f, 0f, 800f, 480f, new Rectangle(0f, 0f, 4f, 12f));
    assertThat(camera.getZoom(), IsEqual.equalTo(200f));
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) Test(org.junit.Test)

Example 15 with Rectangle

use of com.badlogic.gdx.math.Rectangle in project commons-gdx by gemserk.

the class SpriteBatchUtils method getBounds.

public static Rectangle getBounds(BitmapFont font, CharSequence text, float x, float y, float sx, float sy) {
    TextBounds bounds = font.getMultiLineBounds(text);
    float w = bounds.width;
    float h = bounds.height;
    return new Rectangle(x - sx - w * 0.5f, y - sy - h * 0.5f, w + 2 * sx, h + 2 * sy);
}
Also used : Rectangle(com.badlogic.gdx.math.Rectangle) TextBounds(com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)

Aggregations

Rectangle (com.badlogic.gdx.math.Rectangle)35 Test (org.junit.Test)6 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)5 MockPointer (com.gemserk.commons.gdx.input.MockPointer)4 Circle (com.badlogic.gdx.math.Circle)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)2 Cell (com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 CoreEntity (com.ilargia.games.entitas.core.CoreEntity)2 View (com.ilargia.games.logicbrick.component.View)2 PlayerSoldier (me.dumfing.multiplayerTools.PlayerSoldier)2 FishColour (ca.hiphiparray.amazingmaze.FishCell.FishColour)1 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Camera (com.badlogic.gdx.graphics.Camera)1 Color (com.badlogic.gdx.graphics.Color)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 Batch (com.badlogic.gdx.graphics.g2d.Batch)1 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)1 TextBounds (com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds)1