|
@@ -1,14 +1,11 @@
|
|
|
package squidpony.squidgrid.gui.gdx;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
import com.badlogic.gdx.assets.AssetManager;
|
|
|
import com.badlogic.gdx.graphics.Color;
|
|
|
import com.badlogic.gdx.graphics.Pixmap;
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
|
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
|
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
|
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
|
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
|
|
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
|
@@ -48,20 +45,15 @@ public class TextCellFactory implements Disposable {
|
|
|
|
|
|
private final BitmapFont bmpFont;
|
|
|
protected Texture block = null;
|
|
|
- protected TextureRegion dirMarker = null;
|
|
|
protected String fitting = SQUID_FITTING;
|
|
|
- protected int leftPadding = 0, rightPadding = 0, topPadding = 0, bottomPadding = 0;
|
|
|
protected int width = 1, height = 1;
|
|
|
protected float actualCellWidth = 1, actualCellHeight = 1;
|
|
|
- protected float distanceFieldScaleX = 36f, distanceFieldScaleY = 36f;
|
|
|
private boolean initialized = false;
|
|
|
protected boolean distanceField = false;
|
|
|
protected ShaderProgram shader;
|
|
|
- protected float smoothingMultiplier = 1f;
|
|
|
- protected float descent, lineHeight;
|
|
|
+ protected float descent;
|
|
|
private Label.LabelStyle style;
|
|
|
protected OrderedMap<String, String> swap = new OrderedMap<>(32);
|
|
|
- protected char directionGlyph = '^';
|
|
|
|
|
|
/**
|
|
|
* A default valued factory that uses the given {@link AssetManager} to load the
|
|
@@ -93,8 +85,7 @@ public class TextCellFactory implements Disposable {
|
|
|
public TextCellFactory initByFont() {
|
|
|
bmpFont.setFixedWidthGlyphs(fitting);
|
|
|
width = (int) bmpFont.getSpaceWidth();
|
|
|
- lineHeight = bmpFont.getLineHeight();
|
|
|
- height = (int) (lineHeight);
|
|
|
+ height = (int) (bmpFont.getLineHeight());
|
|
|
descent = bmpFont.getDescent();
|
|
|
|
|
|
actualCellWidth = width;
|
|
@@ -107,8 +98,6 @@ public class TextCellFactory implements Disposable {
|
|
|
block.draw(temp, 0, 0);
|
|
|
temp.dispose();
|
|
|
style = new Label.LabelStyle(bmpFont, null);
|
|
|
- BitmapFont.Glyph g = bmpFont.getData().getGlyph(directionGlyph);
|
|
|
- dirMarker = new TextureRegion(bmpFont.getRegion(g.page), g.srcX, g.srcY, g.width, g.height);
|
|
|
initialized = true;
|
|
|
return this;
|
|
|
}
|
|
@@ -164,204 +153,10 @@ public class TextCellFactory implements Disposable {
|
|
|
*/
|
|
|
public TextCellFactory height(int height) {
|
|
|
this.height = Math.max(1, height);
|
|
|
- // modifiedHeight = this.height;
|
|
|
actualCellHeight = this.height;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Sets the factory's height used for text to the provided value, but does not
|
|
|
- * change the size of a cell. Clamps at 1 on the lower bound to ensure valid
|
|
|
- * calculations.
|
|
|
- *
|
|
|
- * @param width
|
|
|
- * the desired width
|
|
|
- * @return this factory for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory tweakWidth(int width) {
|
|
|
- this.width = Math.max(1, width);
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the factory's height used for text to the provided value, but does not
|
|
|
- * change the size of a cell. Clamps at 1 on the lower bound to ensure valid
|
|
|
- * calculations.
|
|
|
- *
|
|
|
- * @param height
|
|
|
- * the desired height
|
|
|
- * @return this factory for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory tweakHeight(int height) {
|
|
|
- this.height = Math.max(1, height);
|
|
|
- // modifiedHeight = this.height;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the current String of code points that are used for sizing the cells.
|
|
|
- *
|
|
|
- * Note that this is actually a set of codepoints and treating them as an array
|
|
|
- * of chars might give undesired results.
|
|
|
- *
|
|
|
- * @return the String used for sizing calculations
|
|
|
- */
|
|
|
- public String fit() {
|
|
|
- return fitting;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the characters that will be guaranteed to fit to the provided ones. This
|
|
|
- * will override any previously set string.
|
|
|
- *
|
|
|
- * @param fit
|
|
|
- * the String of code points to size to
|
|
|
- * @return this factory for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory fit(String fit) {
|
|
|
- fitting = fit;
|
|
|
- bmpFont.setFixedWidthGlyphs(fitting);
|
|
|
- width = (int) bmpFont.getSpaceWidth();
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds the code points in the string to the list of characters that will be
|
|
|
- * guaranteed to fit.
|
|
|
- *
|
|
|
- * @param fit
|
|
|
- * the String of code points to size to
|
|
|
- * @return this factory for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory addFit(String fit) {
|
|
|
- fitting += fit;
|
|
|
- bmpFont.setFixedWidthGlyphs(fitting);
|
|
|
- width = (int) bmpFont.getSpaceWidth();
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns whether this factory is currently set to do antialiasing on the
|
|
|
- * characters rendered, which is always true.
|
|
|
- *
|
|
|
- * @return true if antialiasing is set
|
|
|
- */
|
|
|
- public boolean antialias() {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * All fonts will be rendered with antialiasing, this doesn't do anything.
|
|
|
- *
|
|
|
- * @param antialias
|
|
|
- * ignored, will always use antialiasing
|
|
|
- * @return this factory for method chaining
|
|
|
- * @deprecated AA is the wave of the future!
|
|
|
- */
|
|
|
- @Deprecated
|
|
|
- public TextCellFactory antialias(boolean antialias) {
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the amount of padding on all sides to the provided value.
|
|
|
- *
|
|
|
- * @param padding
|
|
|
- * how much padding in pixels
|
|
|
- * @return this for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory padding(int padding) {
|
|
|
- leftPadding = padding;
|
|
|
- rightPadding = padding;
|
|
|
- topPadding = padding;
|
|
|
- bottomPadding = padding;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the padding on the left side.
|
|
|
- *
|
|
|
- * @return amount of padding in pixels
|
|
|
- */
|
|
|
- public int leftPadding() {
|
|
|
- return leftPadding;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the amount of padding on the left side to the provided value.
|
|
|
- *
|
|
|
- * @param padding
|
|
|
- * how much padding in pixels
|
|
|
- * @return this for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory leftPadding(int padding) {
|
|
|
- leftPadding = padding;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the padding on the right side.
|
|
|
- *
|
|
|
- * @return amount of padding in pixels
|
|
|
- */
|
|
|
- public int rightPadding() {
|
|
|
- return rightPadding;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the amount of padding on the right side to the provided value.
|
|
|
- *
|
|
|
- * @param padding
|
|
|
- * how much padding in pixels
|
|
|
- * @return this for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory rightPadding(int padding) {
|
|
|
- rightPadding = padding;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the padding on the top side.
|
|
|
- *
|
|
|
- * @return amount of padding in pixels
|
|
|
- */
|
|
|
- public int topPadding() {
|
|
|
- return topPadding;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the amount of padding on the top side to the provided value.
|
|
|
- *
|
|
|
- * @param padding
|
|
|
- * how much padding in pixels
|
|
|
- * @return this for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory topPadding(int padding) {
|
|
|
- topPadding = padding;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the padding on the bottom side.
|
|
|
- *
|
|
|
- * @return amount of padding in pixels
|
|
|
- */
|
|
|
- public int bottomPadding() {
|
|
|
- return bottomPadding;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the amount of padding on the bottom side to the provided value.
|
|
|
- *
|
|
|
- * @param padding
|
|
|
- * how much padding in pixels
|
|
|
- * @return this for method chaining
|
|
|
- */
|
|
|
- public TextCellFactory bottomPadding(int padding) {
|
|
|
- bottomPadding = padding;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Returns true if this factory is fully initialized and ready to build text
|
|
|
* cells.
|
|
@@ -372,32 +167,6 @@ public class TextCellFactory implements Disposable {
|
|
|
return initialized;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns true if the given character will fit inside the current cell
|
|
|
- * dimensions with the current font.
|
|
|
- *
|
|
|
- * ISO Control characters, non-printing characters and invalid unicode
|
|
|
- * characters are all considered by definition to fit.
|
|
|
- *
|
|
|
- * @param codepoint
|
|
|
- * the codepoint of the char in question
|
|
|
- * @return true if the char will fit, or if it is non-printing in some way;
|
|
|
- * false otherwise
|
|
|
- */
|
|
|
- public boolean willFit(int codepoint) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
-
|
|
|
- if (!Character.isValidCodePoint(codepoint) || (codepoint <= 0x001F)
|
|
|
- || (codepoint >= 0x007F && codepoint <= 0x009F)) // same as isIsoControl
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return fitting.contains(String.valueOf(Character.toChars(codepoint)));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 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
|
|
@@ -443,59 +212,6 @@ public class TextCellFactory implements Disposable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Use the specified Batch to draw a String (often just one char long) in the
|
|
|
- * specified rgba 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 s
|
|
|
- * the string to draw, often but not necessarily one char. 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, String s, 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 (s == null) {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- batch.draw(block, x, y - actualCellHeight, actualCellWidth, actualCellHeight); // descent * 1 / 3f
|
|
|
- batch.setColor(orig);
|
|
|
- } else if (s.length() > 0 && s.charAt(0) == '\0') {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- batch.draw(block, x, y - actualCellHeight, actualCellWidth * s.length(), actualCellHeight); // descent * 1 /
|
|
|
- // 3f
|
|
|
- batch.setColor(orig);
|
|
|
- } else {
|
|
|
- bmpFont.setColor(r, g, b, a);
|
|
|
- if (swap.containsKey(s))
|
|
|
- bmpFont.draw(batch, swap.get(s), x,
|
|
|
- y - descent + 1/* * 1.5f *//* - lineHeight * 0.2f */ /* + descent */, width * s.length(),
|
|
|
- Align.center, false);
|
|
|
- else
|
|
|
- bmpFont.draw(batch, s, x, y - descent + 1/* * 1.5f *//* - lineHeight * 0.2f */ /* + descent */,
|
|
|
- width * s.length(), 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
|
|
@@ -543,267 +259,6 @@ public class TextCellFactory implements Disposable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Use the specified Batch to draw a TextureRegion with the default tint color
|
|
|
- * (white, so un-tinted), 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 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 x, float y) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
-
|
|
|
- if (tr == null) {
|
|
|
- batch.draw(block, x, y - height, actualCellWidth, actualCellHeight);
|
|
|
- } else {
|
|
|
- batch.draw(tr, x, y - height, width, height);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 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) {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- batch.draw(block, x, y - height, actualCellWidth, actualCellHeight);
|
|
|
- batch.setColor(orig);
|
|
|
- } else {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- 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 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) {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(color);
|
|
|
- batch.draw(block, x, y - height, actualCellWidth, actualCellHeight);
|
|
|
- batch.setColor(orig);
|
|
|
- } else {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(color);
|
|
|
- batch.draw(tr, x, y - height, width, height);
|
|
|
- batch.setColor(orig);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Use the specified Batch to draw a TextureRegion with the default tint color
|
|
|
- * (white, so un-tinted), 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 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.
|
|
|
- * @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 x, float y, float width, float height) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
-
|
|
|
- if (tr == null) {
|
|
|
- batch.draw(block, x, y - height, width, height);
|
|
|
- } else {
|
|
|
- batch.draw(tr, x, y - height, width, height);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 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 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 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.
|
|
|
- * @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 r, float g, float b, float a, float x, float y, float width,
|
|
|
- float height) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
-
|
|
|
- if (tr == null) {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- batch.draw(block, x, y - height, width, height);
|
|
|
- batch.setColor(orig);
|
|
|
- } else {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(r, g, b, a);
|
|
|
- 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 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.
|
|
|
- * @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) {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(color);
|
|
|
- batch.draw(block, x, y - height, width, height);
|
|
|
- batch.setColor(orig);
|
|
|
- } else {
|
|
|
- Color orig = batch.getColor();
|
|
|
- batch.setColor(color);
|
|
|
- batch.draw(tr, x, y - height, width, height);
|
|
|
- batch.setColor(orig);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Converts a String into a Label, or if the argument s is null, creates an
|
|
|
- * Image of a solid block. Can be used for preparing glyphs for animation
|
|
|
- * effects.
|
|
|
- *
|
|
|
- * @param s
|
|
|
- * a String to make into an Actor, which can be null for a solid
|
|
|
- * block.
|
|
|
- * @return the Actor, with no position set.
|
|
|
- */
|
|
|
- public Label makeWrappingString(String s) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
- if (s == null) {
|
|
|
- s = "";
|
|
|
- }
|
|
|
- Label lb = new Label(s, style);
|
|
|
- lb.setWrap(true);
|
|
|
- // lb.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return lb;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Converts a String into a Label, or if the argument s is null, creates an
|
|
|
* Image of a solid block. Can be used for preparing glyphs for animation
|
|
@@ -853,129 +308,6 @@ public class TextCellFactory implements Disposable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a Image Actor that should look like the glyph '^' in this font, but
|
|
|
- * will be rotate-able.
|
|
|
- *
|
|
|
- * @param color
|
|
|
- * a Color to tint the '^' with
|
|
|
- * @return the Actor, with no position set.
|
|
|
- */
|
|
|
- public Actor makeDirectionMarker(Color color) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
- Image im = new Image(dirMarker);
|
|
|
- im.setColor(color);
|
|
|
- // im.setSize(width, height - MathUtils.ceil(bmpFont.getDescent() / 2f));
|
|
|
- im.setSize(actualCellWidth, actualCellHeight + (distanceField ? 1 : 0)); // - lineHeight / actualCellHeight //+
|
|
|
- // lineTweak * 1f
|
|
|
- im.setOrigin(1); // center
|
|
|
- // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return im;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Converts a TextureRegion into an Image, or if the argument s is null, creates
|
|
|
- * an Image of a solid block. Can be used for preparing images for animation
|
|
|
- * effects. Stretches the TextureRegion to match a single cell's dimensions.
|
|
|
- *
|
|
|
- * @param tr
|
|
|
- * a TextureRegion to make into an Actor, which can be null for a
|
|
|
- * solid block.
|
|
|
- * @param color
|
|
|
- * a Color to tint tr with.
|
|
|
- * @return the Actor, with no position set.
|
|
|
- */
|
|
|
- public Actor makeActor(TextureRegion tr, Color color) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
- if (tr == null) {
|
|
|
- Image im = new Image(block);
|
|
|
- im.setColor(color);
|
|
|
- im.setSize(width, height);
|
|
|
- // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return im;
|
|
|
- } else {
|
|
|
- Image im = new Image(tr);
|
|
|
- im.setColor(color);
|
|
|
- im.setSize(width, height);
|
|
|
- // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return im;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Converts a TextureRegion into an Image, or if the argument s is null, creates
|
|
|
- * an Image of a solid block. Can be used for preparing images for animation
|
|
|
- * effects. Ensures the returned Image has the given width and height.
|
|
|
- *
|
|
|
- * @param tr
|
|
|
- * a TextureRegion to make into an Actor, which can be null for a
|
|
|
- * solid block.
|
|
|
- * @param color
|
|
|
- * a Color to tint tr with.
|
|
|
- * @return the Actor, with no position set.
|
|
|
- */
|
|
|
- public Actor makeActor(TextureRegion tr, Color color, float width, float height) {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
- if (tr == null) {
|
|
|
- Image im = new Image(block);
|
|
|
- im.setColor(color);
|
|
|
- im.setSize(width, height);
|
|
|
- // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return im;
|
|
|
- } else {
|
|
|
- Image im = new Image(tr);
|
|
|
- im.setColor(color);
|
|
|
- im.setSize(width, height);
|
|
|
- // im.setPosition(x - width * 0.5f, y - height * 0.5f, Align.center);
|
|
|
- return im;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns a solid block of white, 1x1 pixel in size; can be drawn at other
|
|
|
- * sizes by Batch.
|
|
|
- *
|
|
|
- * @return a white 1x1 pixel Texture.
|
|
|
- */
|
|
|
- public Texture getSolid() {
|
|
|
- if (!initialized) {
|
|
|
- throw new IllegalStateException("This factory has not yet been initialized!");
|
|
|
- }
|
|
|
- return block;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * If this uses a distance field font, the smoothing multiplier affects how
|
|
|
- * crisp or blurry lines are, with higher numbers generally resulting in more
|
|
|
- * crisp fonts, but numbers that are too high cause jagged aliasing.
|
|
|
- *
|
|
|
- * @return the current smoothing multiplier as a float, which starts at 1f.
|
|
|
- */
|
|
|
- public float getSmoothingMultiplier() {
|
|
|
- return smoothingMultiplier;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * If this uses a distance field font, the smoothing multiplier affects how
|
|
|
- * crisp or blurry lines are, with higher numbers generally resulting in more
|
|
|
- * crisp fonts, but numbers that are too high cause jagged aliasing.
|
|
|
- *
|
|
|
- * @param smoothingMultiplier
|
|
|
- * the new value for the smoothing multiplier as a float; should be
|
|
|
- * fairly close to 1f.
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory setSmoothingMultiplier(float smoothingMultiplier) {
|
|
|
- this.smoothingMultiplier = smoothingMultiplier;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* If using a distance field font, you MUST call this at some point while the
|
|
|
* batch has begun, or use code that calls it for you (which is now much of
|
|
@@ -999,7 +331,7 @@ public class TextCellFactory implements Disposable {
|
|
|
public void configureShader(Batch batch) {
|
|
|
if (initialized && distanceField) {
|
|
|
batch.setShader(shader);
|
|
|
- shader.setUniformf("u_smoothing", 3.5f * smoothingMultiplier * bmpFont.getData().scaleX);
|
|
|
+ shader.setUniformf("u_smoothing", 3.5f * bmpFont.getData().scaleX);
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -1014,223 +346,4 @@ public class TextCellFactory implements Disposable {
|
|
|
if (block != null)
|
|
|
block.dispose();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Gets the descent of this TextCellFactory's BitmapFont, which may be useful
|
|
|
- * for layout outside this class.
|
|
|
- *
|
|
|
- * @return the descent of the BitmapFont this object uses
|
|
|
- */
|
|
|
- public float getDescent() {
|
|
|
- return descent;
|
|
|
- }
|
|
|
-
|
|
|
- public char getDirectionGlyph() {
|
|
|
- return directionGlyph;
|
|
|
- }
|
|
|
-
|
|
|
- public TextCellFactory setDirectionGlyph(char directionGlyph) {
|
|
|
- this.directionGlyph = directionGlyph;
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds a pair of Strings (typically both with length 1) as a replacement pair,
|
|
|
- * so when the find String is requested to be drawn, the replace String is used
|
|
|
- * instead. These are used when drawing text in each cell in SquidPanel and
|
|
|
- * related classes, so Strings longer than 1 char are rare, if they occur at
|
|
|
- * all. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @param find
|
|
|
- * the requested String that will be changed
|
|
|
- * @param replace
|
|
|
- * the replacement String that will be used in place of find
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory addSwap(String find, String replace) {
|
|
|
- if (find.startsWith("\0"))
|
|
|
- return this;
|
|
|
- swap.put(find, replace);
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Adds a pair of chars as a replacement pair, so when the find char is
|
|
|
- * requested to be drawn, the replace char is used instead. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap('^', ',')} and also {@code addSwap(',', ':')}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @param find
|
|
|
- * the requested char that will be changed (converted to a length-1
|
|
|
- * String)
|
|
|
- * @param replace
|
|
|
- * the replacement char that will be used in place of find (converted
|
|
|
- * to a length-1 String)
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory addSwap(char find, char replace) {
|
|
|
- if (find == '\0')
|
|
|
- return this;
|
|
|
- swap.put(String.valueOf(find), String.valueOf(replace));
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Removes the replacement pair, if present, that searches for the given key,
|
|
|
- * find. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @param find
|
|
|
- * the String that would be changed in the replacement pair
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory removeSwap(String find) {
|
|
|
- swap.remove(find);
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Removes the replacement pair, if present, that searches for the given key,
|
|
|
- * find. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap('^', ',')} and also {@code addSwap(',', ':')}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory removeSwap(char find) {
|
|
|
- swap.remove(String.valueOf(find));
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Gets the current mapping of "swaps", or replacement pairs, to replace keys
|
|
|
- * requested for drawing with their values in the OrderedMap. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @return the mapping of replacement pairs
|
|
|
- */
|
|
|
- public OrderedMap<String, String> getAllSwaps() {
|
|
|
- return swap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Sets the mapping of replacement pairs to a different one as a Map of String
|
|
|
- * keys to String values. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @param swaps
|
|
|
- * the Map of replacement pairs; keys requested for drawing will be
|
|
|
- * replaced with their values
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory setAllSwaps(Map<String, String> swaps) {
|
|
|
- this.swap = new OrderedMap<>(swaps.size());
|
|
|
- for (Map.Entry<String, String> kv : swaps.entrySet()) {
|
|
|
- if (!kv.getKey().startsWith("\0"))
|
|
|
- this.swap.put(kv.getKey(), kv.getValue());
|
|
|
- }
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Appends to the mapping of replacement pairs, adding or replacing any entries
|
|
|
- * in the current mapping with the entries in a Map of String keys to String
|
|
|
- * values. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @param swaps
|
|
|
- * the Map of replacement pairs to add; keys requested for drawing
|
|
|
- * will be replaced with their values
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory addSwaps(Map<String, String> swaps) {
|
|
|
-
|
|
|
- for (Map.Entry<String, String> kv : swaps.entrySet()) {
|
|
|
- if (!kv.getKey().startsWith("\0"))
|
|
|
- swap.put(kv.getKey(), kv.getValue());
|
|
|
- }
|
|
|
- return this;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Clears all replacement pairs this has been told to swap. <br>
|
|
|
- * This can be useful when you want to use certain defaults in squidlib-util's
|
|
|
- * dungeon generation, like '~' for deep water, but not others, like ',' for
|
|
|
- * shallow water, and would rather have a glyph of your choice replace something
|
|
|
- * that would be drawn. Replacements will not be chained; that is, if you
|
|
|
- * {@code addSwap("^", ",")} and also {@code addSwap(",", ":")}, then a
|
|
|
- * requested '^' will be drawn as ',', not ':', but a requested ',' will be
|
|
|
- * drawn as ':' (only one swap will be performed). Typically you want a
|
|
|
- * different TextCellFactory for UI elements that use swapping, like a top-down
|
|
|
- * char-based map, and elements that should not, like those that display normal
|
|
|
- * text.
|
|
|
- *
|
|
|
- * @return this for chaining
|
|
|
- */
|
|
|
- public TextCellFactory clearSwaps() {
|
|
|
- swap.clear();
|
|
|
- return this;
|
|
|
- }
|
|
|
}
|