use of com.b3dgs.lionengine.graphic.ColorRgba in project lionengine by b3dgs.
the class Minimap method computeSheet.
/**
* Compute the current sheet.
*
* @param colors The colors data.
* @param sheet The sheet number.
*/
private void computeSheet(Map<TileRef, ColorRgba> colors, Integer sheet) {
final SpriteTiled tiles = map.getSheet(sheet);
final ImageBuffer tilesSurface = tiles.getSurface();
final int tw = map.getTileWidth();
final int th = map.getTileHeight();
int number = 0;
for (int i = 0; i < tilesSurface.getWidth(); i += tw) {
for (int j = 0; j < tilesSurface.getHeight(); j += th) {
final int h = number * tw % tiles.getWidth();
final int v = number / tiles.getTilesHorizontal() * th;
final ColorRgba color = UtilColor.getWeightedColor(tilesSurface, h, v, tw, th);
if (!(NO_TILE.equals(color) || color.getAlpha() == 0)) {
colors.put(new TileRef(sheet, number), color);
}
number++;
}
}
}
use of com.b3dgs.lionengine.graphic.ColorRgba in project lionengine by b3dgs.
the class MinimapConfig method exports.
/**
* Export tiles colors data to configuration media.
*
* @param configMinimap The configuration media output (must not be <code>null</code>).
* @param tiles The tiles data (must not be <code>null</code>).
* @throws LionEngineException If error on writing.
*/
public static void exports(Media configMinimap, Map<TileRef, ColorRgba> tiles) {
Check.notNull(configMinimap);
Check.notNull(tiles);
final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
final Xml nodeMinimap = new Xml(NODE_MINIMAP);
for (final Map.Entry<ColorRgba, Collection<TileRef>> entry : colors.entrySet()) {
final ColorRgba color = entry.getKey();
final Xml nodeColor = nodeMinimap.createChild(NODE_COLOR);
nodeColor.writeInteger(ATT_COLOR_RED, color.getRed());
nodeColor.writeInteger(ATT_COLOR_GREEN, color.getGreen());
nodeColor.writeInteger(ATT_COLOR_BLUE, color.getBlue());
for (final TileRef tileRef : entry.getValue()) {
final Xml nodeTileRef = TileConfig.exports(tileRef);
nodeColor.add(nodeTileRef);
}
}
nodeMinimap.save(configMinimap);
}
use of com.b3dgs.lionengine.graphic.ColorRgba 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 ColorRgba colorOld = g.getColor();
g.setColor(color);
final GlyphVector glyphVector = font.createGlyphVector(context, text);
g2d.drawGlyphVector(glyphVector, tx, ty - size / 2.0F);
g.setColor(colorOld);
}
use of com.b3dgs.lionengine.graphic.ColorRgba in project lionengine by b3dgs.
the class TilesExtractor method extract.
/**
* Extract the tile from level.
*
* @param level The level image reference.
* @param number The tile number on level.
* @return The extracted tile image from level.
*/
private static ImageBuffer extract(SpriteTiled level, int number) {
final ColorRgba transparency = level.getSurface().getTransparentColor();
final ImageBuffer tile = Graphics.createImageBuffer(level.getTileWidth(), level.getTileHeight(), transparency);
final Graphic g = tile.createGraphic();
level.setTile(number);
level.render(g);
g.dispose();
final ImageBuffer copy = Graphics.getImageBuffer(tile);
tile.dispose();
return copy;
}
use of com.b3dgs.lionengine.graphic.ColorRgba in project lionengine by b3dgs.
the class Minimap method prepare.
/**
* Fill minimap surface with tile color configuration.
*
* @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
*/
@Override
public void prepare() {
if (surface == null) {
throw new LionEngineException(ERROR_SURFACE);
}
final Graphic g = surface.createGraphic();
final int v = map.getInTileHeight();
final int h = map.getInTileWidth();
for (int ty = 0; ty < v; ty++) {
for (int tx = 0; tx < h; tx++) {
final Tile tile = map.getTile(tx, ty);
final ColorRgba color = getTileColor(tile);
if (!NO_TILE.equals(color)) {
g.setColor(color);
g.drawRect(tx, v - ty - 1, 0, 0, false);
}
}
}
g.dispose();
}
Aggregations