Search in sources :

Example 26 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class GraphicsTest method afterAll.

/**
 * Terminate engine.
 */
@AfterAll
static void afterAll() {
    try {
        UtilFile.deleteFile(new File(System.getProperty("java.io.tmpdir"), GraphicsTest.class.getSimpleName()));
    } catch (final LionEngineException exception) {
        Verbose.exception(exception);
    }
    Medias.setLoadFromJar(null);
    Graphics.setFactoryGraphic(null);
    Engine.terminate();
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) File(java.io.File) UtilFile(com.b3dgs.lionengine.UtilFile) AfterAll(org.junit.jupiter.api.AfterAll)

Example 27 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class FactoryGraphicMock method generateTileset.

@Override
public void generateTileset(ImageBuffer[] images, Media media) {
    Check.notNull(images);
    Check.notNull(media);
    final int tiles = images.length;
    if (images.length == 0) {
        throw new LionEngineException("No images found !");
    }
    final int width = images[0].getWidth();
    final int height = images[0].getHeight();
    final int multDistance = (int) Math.ceil(width * tiles / (double) height) / 4;
    final int[] mult = UtilMath.getClosestSquareMult(tiles, multDistance);
    try (OutputStream output = media.getOutputStream()) {
        output.write(UtilConversion.intToByteArray(width * mult[1]));
        output.write(UtilConversion.intToByteArray(height * mult[0]));
    } catch (final IOException exception) {
        throw new LionEngineException(exception, media, "Unable to save image: ");
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 28 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class ToolsAwt method getTransparency.

/**
 * Get the image transparency equivalence.
 *
 * @param transparency The transparency type (must not be <code>null</code>).
 * @return The transparency value.
 * @throws LionEngineException If invalid argument.
 */
public static int getTransparency(Transparency transparency) {
    Check.notNull(transparency);
    final int value;
    if (Transparency.OPAQUE == transparency) {
        value = java.awt.Transparency.OPAQUE;
    } else if (Transparency.BITMASK == transparency) {
        value = java.awt.Transparency.BITMASK;
    } else if (Transparency.TRANSLUCENT == transparency) {
        value = java.awt.Transparency.TRANSLUCENT;
    } else {
        throw new LionEngineException(transparency);
    }
    return value;
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Point(java.awt.Point)

Example 29 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class ScreenFullAwt method initFullscreen.

/**
 * Prepare fullscreen mode.
 *
 * @param output The output resolution
 * @param depth The bit depth color.
 * @throws LionEngineException If unsupported resolution.
 */
private void initFullscreen(Resolution output, int depth) {
    final java.awt.Window window = new java.awt.Window(frame, conf);
    window.setBackground(Color.BLACK);
    window.setIgnoreRepaint(true);
    window.setPreferredSize(new Dimension(output.getWidth(), output.getHeight()));
    dev.setFullScreenWindow(window);
    final DisplayMode disp = isSupported(new DisplayMode(output.getWidth(), output.getHeight(), depth, output.getRate()));
    if (disp == null) {
        throw new LionEngineException(ScreenFullAwt.ERROR_UNSUPPORTED_FULLSCREEN + formatResolution(output, depth) + getSupportedResolutions());
    }
    checkDisplayChangeSupport();
    dev.setDisplayMode(disp);
    window.validate();
    ToolsAwt.createBufferStrategy(window, conf);
    buf = window.getBufferStrategy();
    // Set input listeners
    componentForKeyboard = frame;
    componentForMouse = window;
    componentForCursor = window;
    frame.validate();
}
Also used : DisplayMode(java.awt.DisplayMode) LionEngineException(com.b3dgs.lionengine.LionEngineException) Dimension(java.awt.Dimension)

Example 30 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class TextAwt method draw.

@Override
public void draw(Graphic g, int x, int y, Align alignment, String text) {
    final Graphics2D g2d = (Graphics2D) g.getGraphic();
    final FontRenderContext context = g2d.getFontRenderContext();
    final Rectangle2D textSize = font.getStringBounds(text, context);
    final int tx;
    final int ty;
    if (Align.LEFT == alignment) {
        tx = x;
        ty = (int) textSize.getHeight() + y;
    } else if (Align.CENTER == alignment) {
        tx = x - (int) textSize.getWidth() / 2;
        ty = (int) textSize.getHeight() + y;
    } else if (Align.RIGHT == alignment) {
        tx = x - (int) textSize.getWidth();
        ty = (int) textSize.getHeight() + y;
    } else {
        throw new LionEngineException(alignment);
    }
    final Color colorOld = g2d.getColor();
    g2d.setColor(colorCache.get(color));
    final GlyphVector glyphVector = textCache.computeIfAbsent(text, t -> font.createGlyphVector(context, t));
    g2d.drawGlyphVector(glyphVector, tx, ty - size / 2.0F);
    g2d.setColor(colorOld);
}
Also used : GlyphVector(java.awt.font.GlyphVector) LionEngineException(com.b3dgs.lionengine.LionEngineException) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Graphics2D(java.awt.Graphics2D)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)75 IOException (java.io.IOException)13 File (java.io.File)8 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7 XmlReader (com.b3dgs.lionengine.XmlReader)6 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 Media (com.b3dgs.lionengine.Media)5 Configurer (com.b3dgs.lionengine.game.Configurer)4 UtilFile (com.b3dgs.lionengine.UtilFile)3 Graphic (com.b3dgs.lionengine.graphic.Graphic)3 UtilFile (com.b3dgs.lionengine.util.UtilFile)3 DisplayMode (java.awt.DisplayMode)3 BufferedImage (java.awt.image.BufferedImage)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AfterAll (org.junit.jupiter.api.AfterAll)3 Animation (com.b3dgs.lionengine.Animation)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Feature (com.b3dgs.lionengine.game.Feature)2