/** * @param c the character to get the width of * @return the width of the provided character in pixels */ public static int getCharacterWidth(char c) { if(c >= '\u2588' && c <= '\u258F') { return ('\u258F' - c) + 2; } switch(c) { case ' ': return 4; case '\u2714': return 8; case '\u2718': return 7; default: MapFont.CharacterSprite mcChar = MinecraftFont.Font.getChar(c); if(mcChar != null) return mcChar.getWidth() + 1; return 0; } }
public Byte[][][] loadNumbers(int giftsSize) { Byte[][][] numbers = new Byte[giftsSize][][]; for(int i = 0; i < giftsSize; i++) { String day = Integer.toString(i + 1); int width = getWidth(day) + 2; int height = MinecraftFont.Font.getHeight() + 2; Byte[][] number = new Byte[width][height]; //Shadow for(int x = 0; x < 3; x++) for(int y = 0; y < 3; y++) drawText(number, x, y, 1, 1, MinecraftFont.Font, day, COLOR_TEXT_BACKGROUND); //Front drawText(number, 1, 1, 1, 1, MinecraftFont.Font, day, COLOR_TEXT); numbers[i] = number; } return numbers; }
@Override @SuppressWarnings("deprecation") public void render(MapView map, MapCanvas canvas, Player player) { // Only render when on this world if (!map.getWorld().equals(plugin.getBeaconzWorld())) { return; } // Only render if the map is in a hand ItemStack inMainHand = player.getInventory().getItemInMainHand(); ItemStack inOffHand = player.getInventory().getItemInOffHand(); if (inMainHand.getType().equals(Material.MAP) || inOffHand.getType().equals(Material.MAP)) { //Bukkit.getLogger().info("DEBUG: render"); // here's where you do your drawing - see the Javadocs for the MapCanvas class for // the methods you can use canvas.drawText(10, 10, MinecraftFont.Font, Lang.beaconMapBeaconMap); // Get the text BeaconObj beacon = plugin.getRegister().getBeaconMap(map.getId()); if (beacon != null) { canvas.drawText(10, 20, MinecraftFont.Font, Lang.generalLocation + ": " + beacon.getName()); canvas.setPixel(64, 64, (byte) 64); } else { canvas.drawText(10, 20, MinecraftFont.Font, Lang.beaconMapUnknownBeacon); } } }
public void drawHeader(MapCanvas canvas) { int width = getWidth(header) * 2; int height = MinecraftFont.Font.getHeight() * 2; int startX = (MAP_SIZE - width) / 2; int startY = (iconStartY - 1 - height) / 3; drawText(canvas, startX, startY + 1, 2, 2, MinecraftFont.Font, header, COLOR_HEADER_BACKGROUND); drawText(canvas, startX, startY, 2, 2, MinecraftFont.Font, header, COLOR_HEADER); }
public void drawDescription(MapCanvas canvas) { int width = getWidth(description); int height = MinecraftFont.Font.getHeight(); int startX = (MAP_SIZE - width) / 2; int startY = ((iconStartY - 1 - height) / 4) * 3; drawText(canvas, startX, startY + 1, 1, 1, MinecraftFont.Font, description, COLOR_DESCRIPTION_BACKGROUND); drawText(canvas, startX, startY, 1, 1, MinecraftFont.Font, description, COLOR_DESCRIPTION); }
public int getWidth(String string) { String noColors = ChatColor.stripColor(string); int width = 0; String noSpaces = noColors.replace(" ", ""); int spaces = 0; for (int i = 0; i < noColors.length(); i++) if (string.charAt(i) == ' ') spaces += spaceWidth; width += MinecraftFont.Font.getWidth(noSpaces); width += spaces; return width; }
@Override public void render(MapView view, MapCanvas canvas, Player player) { byte textFrontColor = BPMapPalette.getColor(BPMapPalette.WHITE, 2); byte textBackColor = BPMapPalette.getColor(BPMapPalette.DARK_GRAY, 0); int textWidth = 2;//MAP_SIZE / getWidth(name); int textHeight = 2; drawBytes(canvas, image); drawText(canvas, 3, 3, textWidth, textHeight, MinecraftFont.Font, name, textBackColor); drawText(canvas, 2, 2, textWidth, textHeight, MinecraftFont.Font, name, textFrontColor); }
public void drawSize(MapCanvas canvas) { String sSize = Integer.toString(size); int totalWidth = getWidth(sSize); int fontWidth = MAP_SIZE / totalWidth; int startX = ((MAP_SIZE - (totalWidth * fontWidth)) / 2); int startY = ((MAP_SIZE - (MinecraftFont.Font.getHeight() * fontHeight)) / 2); drawRectangle(canvas, 0, 0, MAP_SIZE, MAP_SIZE, backgroundColor); drawText(canvas, startX, startY, fontWidth, fontHeight, MinecraftFont.Font, sSize, foregroundColor); }
@Override public void render(MapView view, MapCanvas canvas, Player player) { String value = getValue(); drawRectangleFade(canvas, 0, 0, MAP_SIZE, MAP_SIZE, BACKGROUND_COLORS, 0); drawCenteredText(canvas, label, LABEL_COLOR, - MinecraftFont.Font.getHeight() * FONT_SCALE_Y - FONT_DISTANCE_FROM_CENTER); if(value != null) drawCenteredText(canvas, value, color, FONT_DISTANCE_FROM_CENTER); drawBorder(canvas, color, BORDER); }
private void drawCenteredText(MapCanvas canvas, String text, byte color, int distanceFromCenter) { int labelWidth = getWidth(text); int labelScaleX = getScaleX(text, labelWidth); labelWidth *= labelScaleX; int labelX = (MAP_SIZE - labelWidth) / 2; int labelY = (MAP_SIZE / 2) + distanceFromCenter; drawText(canvas, labelX, labelY, labelScaleX, FONT_SCALE_Y, MinecraftFont.Font, text, color); }
public static int getWidth(String s) { if(s.length() == 0) return MinecraftFont.Font.getWidth(s); else return MinecraftFont.Font.getWidth(s) + s.length() - 1; }
@Override public void render(MapView view, MapCanvas canvas, Player player) { int headerHeight = MinecraftFont.Font.getHeight() + 4; BPPlayer bpPlayer = BPPlayer.get(player); drawRectangle(canvas, 0, 0, MAP_SIZE, headerHeight, headColor); drawText(canvas, 2, 2, 1, 1, MinecraftFont.Font, "Graf online hracu:", headTextColor); drawRectangleFade(canvas, 0, headerHeight, MAP_SIZE, MAP_SIZE - headerHeight, bgColor, 0); drawGraph(canvas, headerHeight, bpPlayer); }
@Override public void render(MapView map, MapCanvas canvas, Player player) { if (nextUpdate <= 0) { //paint only every half seconds (20 Ticks / 2) nextUpdate = 10; if (nextPosX >= MAX_WIDTH) { //start again from the beginning nextPosX = 0; } clearMap(canvas, nextPosX); //make it more visual where the renderer is at the moment clearMap(canvas, nextPosX + 1); int maxValue = renderGraphTick(canvas, nextPosX); //override the color canvas.drawText(0, 0, MinecraftFont.Font, title); //count indicators canvas.drawText(110, 0, MinecraftFont.Font, Integer.toString(maxValue)); canvas.drawText(110, MAX_HEIGHT / 2, MinecraftFont.Font, Integer.toString(maxValue / 2)); canvas.drawText(MAX_WIDTH - MinecraftFont.Font.getWidth("0"), 120, MinecraftFont.Font, "0"); nextPosX++; } nextUpdate--; }
@Override protected void execute(Event e) { SkellettMapRenderer render = SkellettMapRenderer.getRenderer(map.getSingle(e)); if (render != null) { render.update(new MapRenderTask() { @Override public void render(MapView mapView, MapCanvas mapCanvas, Player player) { mapCanvas.drawText(x.getSingle(e).intValue(), y.getSingle(e).intValue(), MinecraftFont.Font, ChatColor.stripColor(string.getSingle(e))); } }); } }
public static void drawTextOld(MapCanvas canvas, int x, int y, int width, int height, MapFont font, String text) { int xStart = x; byte color = MapPalette.DARK_GRAY; /* String text = ""; for(char c : rawText.toCharArray()) if(MinecraftFont.Font.getChar(c) != null) text += c;*/ if(!MinecraftFont.Font.isValid(text)) return; for (int i = 0; i < text.length(); ++i) { char ch = text.charAt(i); if (ch == '\n') { x = xStart; y += font.getHeight() + 1; continue; } else if (ch == '§') { int j = text.indexOf(';', i); if (j >= 0) try { color = Byte.parseByte(text.substring(i + 1, j)); i = j; continue; } catch (NumberFormatException ex) { } } CharacterSprite sprite = font.getChar(text.charAt(i)); for(int r = 0; r < font.getHeight(); ++r) for(int c = 0; c < sprite.getWidth(); ++c) for(int xx = 0; xx < width; xx++) for(int yy = 0; yy < height; yy++) if(sprite.get(r, c)) canvas.setPixel(x + xx + c * width, y + yy + r * height, color); x += (sprite.getWidth() + 1) * width; } }
public static void drawTextOld(Byte[][] canvas, int x, int y, int width, int height, MapFont font, String text) { int xStart = x; byte color = MapPalette.DARK_GRAY; /* String text = ""; for(char c : rawText.toCharArray()) if(MinecraftFont.Font.getChar(c) != null) text += c;*/ if(!MinecraftFont.Font.isValid(text)) return; for (int i = 0; i < text.length(); ++i) { char ch = text.charAt(i); if (ch == '\n') { x = xStart; y += font.getHeight() + 1; continue; } else if (ch == '§') { int j = text.indexOf(';', i); if (j >= 0) try { color = Byte.parseByte(text.substring(i + 1, j)); i = j; continue; } catch (NumberFormatException ex) { } } CharacterSprite sprite = font.getChar(text.charAt(i)); for (int r = 0; r < font.getHeight(); ++r) for (int c = 0; c < sprite.getWidth(); ++c) for (int xx = 0; xx < width; xx++) for (int yy = 0; yy < height; yy++) if (sprite.get(r, c)) { int absX = x + xx + c * width; int absY = y + yy + r * height; if(canvas.length > absX && canvas[absX].length > absY) canvas[absX][absY] = color; } x += (sprite.getWidth() + 1) * width; } }
public MinecraftFont() { }