Search in sources :

Example 26 with Graphic

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

the class Sequence method initResolution.

/**
 * Initialize resolution.
 *
 * @param source The resolution source (must not be <code>null</code>).
 * @throws LionEngineException If invalid argument.
 */
private void initResolution(Resolution source) {
    Check.notNull(source);
    config.setSource(source);
    screen.onSourceChanged(source);
    // Store source size
    final int width = source.getWidth();
    final int height = source.getHeight();
    // Standard rendering
    final Resolution output = config.getOutput();
    if (FilterNone.INSTANCE.equals(filter) && source.getWidth() == output.getWidth() && source.getHeight() == output.getHeight()) {
        buf = null;
        transform = null;
        directRendering = true;
    } else // Scaled rendering
    {
        buf = Graphics.createImageBuffer(width, height);
        transform = getTransform(filter);
        final Graphic gbuf = buf.createGraphic();
        graphic.setGraphic(gbuf.getGraphic());
        directRendering = false;
    }
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) Resolution(com.b3dgs.lionengine.Resolution)

Example 27 with Graphic

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

the class FactoryGraphicAwt method createImageBuffer.

@Override
public ImageBuffer createImageBuffer(int width, int height, ColorRgba transparency) {
    Check.notNull(transparency);
    final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.BITMASK);
    final ImageBuffer buffer = new ImageBufferAwt(image);
    final Graphic g = buffer.createGraphic();
    g.setColor(transparency);
    g.drawRect(0, 0, width, height, true);
    g.dispose();
    return buffer;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic) BufferedImage(java.awt.image.BufferedImage)

Example 28 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic 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 29 with Graphic

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

the class SpriteTest method testRender.

/**
 * Test render.
 */
@Test
public void testRender() {
    final Graphic g = Graphics.createImageBuffer(100, 100).createGraphic();
    try {
        final Sprite sprite = new SpriteImpl(Graphics.createImageBuffer(64, 32));
        sprite.render(g);
        sprite.setMirror(Mirror.HORIZONTAL);
        sprite.render(g);
        sprite.setMirror(Mirror.VERTICAL);
        sprite.render(g);
    } finally {
        g.dispose();
    }
}
Also used : Sprite(com.b3dgs.lionengine.graphic.Sprite) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.Test)

Example 30 with Graphic

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

the class SpriteTiledTest method testRender.

/**
 * Test render.
 */
@Test
public void testRender() {
    final Graphic g = Graphics.createImageBuffer(100, 100).createGraphic();
    try {
        final SpriteTiled sprite = new SpriteTiledImpl(Graphics.createImageBuffer(64, 32), 16, 8);
        sprite.render(g);
        sprite.setTile(0);
        sprite.setMirror(Mirror.HORIZONTAL);
        sprite.render(g);
        sprite.setMirror(Mirror.VERTICAL);
        sprite.render(g);
    } finally {
        g.dispose();
    }
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) Test(org.junit.Test)

Aggregations

Graphic (com.b3dgs.lionengine.graphic.Graphic)45 Test (org.junit.jupiter.api.Test)18 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 Test (org.junit.Test)8 BufferedImage (java.awt.image.BufferedImage)5 GraphicMock (com.b3dgs.lionengine.graphic.GraphicMock)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Resolution (com.b3dgs.lionengine.Resolution)3 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)3 Media (com.b3dgs.lionengine.Media)2 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)2 SpriteFont (com.b3dgs.lionengine.graphic.SpriteFont)2 Text (com.b3dgs.lionengine.graphic.Text)2 Align (com.b3dgs.lionengine.Align)1 Surface (com.b3dgs.lionengine.Surface)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 Image (com.b3dgs.lionengine.graphic.Image)1 Sprite (com.b3dgs.lionengine.graphic.Sprite)1 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)1