/** * Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y * determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched * only if the supplied width and height do not match what its own dimensions are. * * @param batch the LibGDX Batch to do the drawing * @param tr the TextureRegion to draw. Can be null to draw a solid block instead. * @param encodedColor the float encoding a color (as ABGR8888; SColor can produce these) to draw the image with * @param x x of the upper-left corner of the image in world coordinates. * @param y y of the upper-left corner of the image in world coordinates. * @param width the width of the TextureRegion or solid block in pixels. * @param height the height of the TextureRegion or solid block in pixels. */ public void draw(Batch batch, TextureRegion tr, float encodedColor, float x, float y, float width, float height) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (tr == null) { float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(block, x, y - height, width, height); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(tr, x, y - height, width, height); batch.setColor(orig); } }
float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); batch.setColor(orig); } else if(s.length() > 0 && s.charAt(0) == '\0') { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(block, x, y - actualCellHeight, actualCellWidth * s.length(), actualCellHeight); } else { Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); bmpFont.draw(batch, s, x, y - descent + 1, width, Align.center, false);
/** * Use the specified Batch to draw a TextureRegion tinted with the specified rgba color, with x and y * determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched * if its size does not match what this TextCellFactory uses for width and height. * * @param batch the LibGDX Batch to do the drawing * @param tr the TextureRegion to draw. Can be null to draw a solid block instead. * @param r 0.0 to 0.1 red value * @param g 0.0 to 0.1 green value * @param b 0.0 to 0.1 blue value * @param a 0.0 to 0.1 alpha value * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, TextureRegion tr, float r, float g, float b, float a, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (tr == null) { float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); batch.draw(block, x, y - height, actualCellWidth, actualCellHeight); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); batch.draw(tr, x, y - height, width, height); batch.setColor(orig); } }
float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); batch.setColor(orig); } else if(s.length() > 0 && s.charAt(0) == '\0') { float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(block, x, y - actualCellHeight, actualCellWidth * s.length(), actualCellHeight); Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); bmpFont.draw(batch, s, x, y - descent + 1, width, Align.center, false);
float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); batch.draw(block, x, y - actualCellHeight, actualCellWidth * s.length(), actualCellHeight); } else { Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); bmpFont.draw(batch, s, x, y - descent + 1, width, Align.center, false);
public static void draw(Batch batch, float posX, float posY, float width, float height, Color color) { if (texture == null) texture = makePixel(); float tmp = batch.getPackedColor(); batch.setColor(color); batch.draw(texture, posX, posY, 0, 0, width, height, 1, 1, 0, 0, 0, 1, 1, false, false); batch.setPackedColor(tmp); }
/** * Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y * determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched * if its size does not match what this TextCellFactory uses for width and height. * * @param batch the LibGDX Batch to do the drawing * @param tr the TextureRegion to draw. Can be null to draw a solid block instead. * @param color the LibGDX Color to draw the char(s) with, all the same color * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, TextureRegion tr, Color color, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (tr == null) { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(block, x, y - height, actualCellWidth, actualCellHeight); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(tr, x, y - height, width, height); batch.setColor(orig); } } /**
/** * Use the specified Batch to draw a TextureRegion tinted with the specified LibGDX Color, with x and y * determining the world-space coordinates for the upper-left corner. The TextureRegion will be stretched * only if the supplied width and height do not match what its own dimensions are. * * @param batch the LibGDX Batch to do the drawing * @param tr the TextureRegion to draw. Can be null to draw a solid block instead. * @param color the LibGDX Color to draw the image with, all the same color * @param x x of the upper-left corner of the image in world coordinates. * @param y y of the upper-left corner of the image in world coordinates. * @param width the width of the TextureRegion or solid block in pixels. * @param height the height of the TextureRegion or solid block in pixels. */ public void draw(Batch batch, TextureRegion tr, Color color, float x, float y, float width, float height) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (tr == null) { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(block, x, y - height, width, height); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(tr, x, y - height, width, height); batch.setColor(orig); } }
float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); batch.draw(block, x, y - height, width, height); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(r, g, b, a); batch.draw(tr, x, y - height, width, height);
float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(block, x, y - height, actualCellWidth, actualCellHeight); batch.setColor(orig); } else { float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(tr, x, y - height, width, height);
/** * Draws a 2D array of floats that represent encoded colors, with each float used for a block of color the size of * one character cell (it will be {@link #actualCellWidth} by {@link #actualCellHeight} in size, using world units). * @param batch the LibGDX Batch to do the drawing * @param encodedColors a 2D float array of encoded colors, each usually produced by {@link Color#toFloatBits()} or an SColor method * @param x the x-position where this should render the block of many colors * @param y the y-position where this should render the block of many colors */ public void draw(Batch batch, float[][] encodedColors, float x, float y) { float orig = batch.getPackedColor(); final int w = encodedColors.length, h = encodedColors[0].length; float wm = x, hm; for (int i = 0; i < w; i++, wm += actualCellWidth) { hm = y + (h - 1) * actualCellHeight; for (int j = 0; j < h; j++, hm -= actualCellHeight) { if(encodedColors[i][j] == 0f) continue; batch.setColor(encodedColors[i][j]); batch.draw(block, wm, hm, actualCellWidth, actualCellHeight); // descent * 1 / 3f } } batch.setColor(orig); }
/** * Use the specified Batch to draw a String (often just one char long) with the default color (white), with x and y * determining the world-space coordinates for the upper-left corner. * * @param batch the LibGDX Batch to do the drawing * @param s the string to draw, often but not necessarily one char. Can be null to draw a solid block instead. * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, String s, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } // + descent * 3 / 2f // - distanceFieldScaleY / 12f //height - lineTweak * 2f if (s == null || s.isEmpty() || s.charAt(0) == 0) { batch.setColor(1f,1f,1f,1f); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); // + descent * 1 / 3f } else { batch.setColor(SColor.FLOAT_WHITE); // round trip so FilterBatch can filter BitmapFontCache Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); bmpFont.draw(batch, s, x, y - descent + 1/* * 1.5f*//* - lineHeight * 0.2f */ /* + descent*/, width, Align.center, false); } }
/** * Use the specified Batch to draw a char in the specified LibGDX Color, with x and y * determining the world-space coordinates for the upper-left corner. * * @param batch the LibGDX Batch to do the drawing * @param c the char to draw. Can be {@code '\0'} to draw a solid block instead. * @param color the LibGDX Color (or SquidLib SColor) to use, as an object * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, char c, Color color, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (c == 0) { float orig = batch.getPackedColor(); batch.setColor(color); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); batch.setColor(orig); } else { batch.setColor(color); // round trip so FilterBatch can filter BitmapFontCache Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); mut.setCharAt(0, getOrDefault(c)); bmpFont.draw(batch, mut, x, y - descent + 1, width, Align.center, false); } }
/** * Use the specified Batch to draw a String (often just one char long) in the specified LibGDX Color, with x and y * determining the world-space coordinates for the upper-left corner. * * @param batch the LibGDX Batch to do the drawing * @param c the char to draw. Can be {@code '\0'} to draw a solid block instead. * @param encodedColor the LibGDX Color to use, converted to float as by {@link Color#toFloatBits()} * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, char c, float encodedColor, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } if (c == 0) { float orig = batch.getPackedColor(); batch.setColor(encodedColor); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); batch.setColor(orig); } else { batch.setColor(encodedColor); // round trip so FilterBatch can filter BitmapFontCache Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); mut.setCharAt(0, getOrDefault(c)); bmpFont.draw(batch, mut, x, y - descent + 1, width, Align.center, false); } }
/** * Draws a 2D array of floats that represent encoded colors, with each float used for a block of color that will be * a fraction of the size of one character cell (it will be {@link #actualCellWidth} divided by {@code xSubCells} by * {@link #actualCellHeight} divided by {@code ySubCells} in size, using world units). Typically the 2D float array * should be larger than the 2D storage for text drawn over the colorful blocks (such as a 2D char array), since * more than one subcell may be drawn in the space of one character cell. * @param batch the LibGDX Batch to do the drawing * @param encodedColors a 2D float array of encoded colors, each usually produced by {@link Color#toFloatBits()} or an SColor method * @param x the x-position where this should render the block of many colors * @param y the y-position where this should render the block of many colors * @param xSubCells how many blocks of color should fit across the span of {@link #actualCellWidth}, each one float; must not be 0 * @param ySubCells how many blocks of color should fit across the span of {@link #actualCellHeight}, each one float; must not be 0 */ public void draw(Batch batch, float[][] encodedColors, float x, float y, int xSubCells, int ySubCells) { float orig = batch.getPackedColor(); final int w = encodedColors.length, h = encodedColors[0].length; final float subW = actualCellWidth / xSubCells, subH = actualCellHeight / ySubCells; float wm = x, hm; for (int i = 0; i < w; i++, wm += subW) { hm = y + (h - 1) * subH; for (int j = 0; j < h; j++, hm -= subH) { if(encodedColors[i][j] == 0f) continue; batch.setColor(encodedColors[i][j]); batch.draw(block, wm, hm, subW, subH); } } batch.setColor(orig); }
/** * Use the specified Batch to draw a char with the default color (white), with x and y determining the world-space * coordinates for the upper-left corner. If c is {@code '\0'}, will draw a solid white block instead. * * @param batch the LibGDX Batch to do the drawing * @param c the char to draw. Can be {@code '\0'} to draw a solid block instead. * @param x x of the upper-left corner of the region of text in world coordinates. * @param y y of the upper-left corner of the region of text in world coordinates. */ public void draw(Batch batch, char c, float x, float y) { if (!initialized) { throw new IllegalStateException("This factory has not yet been initialized!"); } // + descent * 3 / 2f // - distanceFieldScaleY / 12f //height - lineTweak * 2f if (c == 0) { batch.setColor(1f,1f,1f,1f); batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); // + descent * 1 / 3f } else { batch.setColor(SColor.FLOAT_WHITE); // round trip so FilterBatch can filter BitmapFontCache Color.abgr8888ToColor(bmpFont.getColor(), batch.getPackedColor()); mut.setCharAt(0, getOrDefault(c)); bmpFont.draw(batch, mut, x, y - descent + 1/* * 1.5f*//* - lineHeight * 0.2f */ /* + descent*/, width, Align.center, false); } } /**
@Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); if (renderer == null || ((AnimationRenderer) renderer).getCurrentAnimation() == null) return; float tmp = batch.getPackedColor(); batch.setColor(Color.WHITE); renderer.update(Gdx.graphics.getDeltaTime()); RectangleRenderer.draw(batch, getX(), getY(), getWidth(), getHeight(), Color.MAGENTA); float scalew = getWidth() / renderer.getWidth(); float scaleh = getHeight() / renderer.getHeight(); float scale = scalew > scaleh ? scaleh : scalew; renderer.draw((SpriteBatch) batch, getX() + renderer.getWidth() * scale / 2, getY(), scale, scale, 0f, null); batch.setPackedColor(tmp); }
validate(); float tmp = batch.getPackedColor(); batch.setColor(Color.WHITE);