Search in sources :

Example 1 with GraphicMock

use of com.b3dgs.lionengine.graphic.GraphicMock in project lionengine by b3dgs.

the class BarTest method testBar.

/**
 * Test the bar class.
 */
@Test
void testBar() {
    final Graphic g = new GraphicMock();
    final Bar bar = new Bar(10, 20);
    bar.setBorderSize(1, 1);
    bar.setColorBackground(ColorRgba.WHITE);
    bar.setColorForeground(ColorRgba.BLACK);
    bar.setLocation(0, 0);
    bar.setMaximumSize(10, 20);
    bar.setVerticalReferential(true);
    bar.setHorizontalReferential(true);
    bar.setWidthPercent(100);
    bar.setHeightPercent(100);
    assertEquals(10, bar.getWidthMax());
    assertEquals(20, bar.getHeightMax());
    assertEquals(100, bar.getWidthPercent());
    assertEquals(100, bar.getHeightPercent());
    assertEquals(10, bar.getWidth());
    assertEquals(20, bar.getHeight());
    bar.setWidthPercent(50);
    bar.setHeightPercent(50);
    assertEquals(50, bar.getWidthPercent());
    assertEquals(50, bar.getHeightPercent());
    assertEquals(5, bar.getWidth());
    assertEquals(10, bar.getHeight());
    bar.render(g);
    bar.setColorBackground(null);
    bar.setVerticalReferential(false);
    bar.setHorizontalReferential(true);
    bar.render(g);
    bar.setColorBackground(ColorRgba.WHITE);
    bar.setColorForeground(null);
    bar.setVerticalReferential(false);
    bar.setHorizontalReferential(false);
    bar.render(g);
    bar.setColor(null, null);
    bar.setVerticalReferential(true);
    bar.setHorizontalReferential(false);
    bar.render(g);
    bar.setWidthPercent(100);
    bar.setHeightPercent(0);
    bar.render(g);
    bar.setWidthPercent(0);
    bar.setHeightPercent(100);
    bar.render(g);
    bar.setWidthPercent(100);
    bar.setHeightPercent(100);
    bar.setColorGradient(0, 0, ColorRgba.WHITE, 50, 10, ColorRgba.BLACK);
    bar.render(g);
    bar.setColorGradient(ColorRgba.WHITE, ColorRgba.BLACK);
    bar.render(g);
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 2 with GraphicMock

use of com.b3dgs.lionengine.graphic.GraphicMock in project lionengine by b3dgs.

the class TextGameTest method testDraw.

/**
 * Test draw.
 */
@Test
void testDraw() {
    final Graphic g = new GraphicMock();
    final TextGame text = new TextGame(Constant.FONT_DIALOG, 8, TextStyle.NORMAL);
    text.setText("text");
    text.setAlign(Align.CENTER);
    text.setColor(ColorRgba.WHITE);
    text.render(g);
    text.draw(g, 0, 0, "toto");
    text.draw(g, 1, 2, Align.LEFT, "tata");
    text.draw(g, Geom.createLocalizable(3, 4), 1, 2, Align.RIGHT, "titi");
    text.drawRect(g, ColorRgba.BLACK, 0, 0, 10, 20);
    g.dispose();
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 3 with GraphicMock

use of com.b3dgs.lionengine.graphic.GraphicMock in project lionengine by b3dgs.

the class CursorTest method testCursor.

/**
 * Test the cursor class.
 */
@Test
public void testCursor() {
    final Graphic g = new GraphicMock();
    final MouseMock mouse = new MouseMock();
    final Cursor cursor = new Cursor();
    cursor.addImage(0, Medias.create("cursor.png"));
    cursor.setArea(0, 0, 320, 240);
    cursor.setSensibility(1.0, 2.0);
    cursor.setInputDevice(mouse);
    cursor.setSurfaceId(0);
    cursor.update(1.0);
    cursor.setSyncMode(true);
    Assert.assertTrue(cursor.isSynchronized());
    cursor.update(1.0);
    cursor.setSyncMode(false);
    Assert.assertTrue(!cursor.isSynchronized());
    cursor.update(1.0);
    cursor.setSyncMode(true);
    cursor.update(1.0);
    cursor.setLocation(10, 20);
    Assert.assertEquals(0.0, cursor.getX(), 0.000001);
    Assert.assertEquals(0.0, cursor.getY(), 0.000001);
    Assert.assertEquals(10.0, cursor.getScreenX(), 0.000001);
    Assert.assertEquals(20.0, cursor.getScreenY(), 0.000001);
    Assert.assertEquals(1.0, cursor.getSensibilityHorizontal(), 0.000001);
    Assert.assertEquals(2.0, cursor.getSensibilityVertical(), 0.000001);
    cursor.setRenderingOffset(0, 0);
    Assert.assertEquals(Integer.valueOf(0), cursor.getSurfaceId());
    Assert.assertEquals(0, cursor.getClick());
    cursor.render(g);
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.Test)

Example 4 with GraphicMock

use of com.b3dgs.lionengine.graphic.GraphicMock in project lionengine by b3dgs.

the class CameraTest method testCameraView.

/**
 * Test the camera view.
 */
@Test
void testCameraView() {
    camera.setView(1, 2, 3, 4, 4);
    assertEquals(1, camera.getViewX());
    assertEquals(2, camera.getViewY());
    assertEquals(3, camera.getWidth());
    assertEquals(4, camera.getHeight());
    camera.drawFov(new GraphicMock(), 0, 0, 1, 1, surface);
    assertThrows(() -> camera.setView(null, 0, 0, null), "Unexpected null argument !");
    camera.setView(new SourceResolutionProvider() {

        @Override
        public int getWidth() {
            return 320;
        }

        @Override
        public int getHeight() {
            return 240;
        }

        @Override
        public int getRate() {
            return 60;
        }
    }, 10, 20, Origin.TOP_LEFT);
    assertEquals(10, camera.getViewX());
    assertEquals(20, camera.getViewY());
    assertEquals(310, camera.getWidth());
    assertEquals(220, camera.getHeight());
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) Test(org.junit.jupiter.api.Test)

Example 5 with GraphicMock

use of com.b3dgs.lionengine.graphic.GraphicMock in project lionengine by b3dgs.

the class TextGameTest method testSize.

/**
 * Test size.
 */
@Test
void testSize() {
    final Graphic g = new GraphicMock();
    final TextGame text = new TextGame(Constant.FONT_DIALOG, 8, TextStyle.NORMAL);
    assertEquals(8, text.getSize());
    assertEquals(0, text.getWidth());
    assertEquals(0, text.getHeight());
    assertEquals(0, text.getStringWidth(g, "text"));
    assertEquals(0, text.getStringHeight(g, "text"));
    g.dispose();
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Aggregations

GraphicMock (com.b3dgs.lionengine.graphic.GraphicMock)5 Graphic (com.b3dgs.lionengine.graphic.Graphic)4 Test (org.junit.jupiter.api.Test)4 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)3 SourceResolutionProvider (com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider)1 Test (org.junit.Test)1