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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations