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