Explorar el Código

Delete stuff that I don't use

smelc hace 7 años
padre
commit
b49cf39a5a

+ 0 - 164
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/ColorChangeLabel.java

@@ -1,164 +0,0 @@
-package squidpony.squidgrid.gui.gdx;
-
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.scenes.scene2d.ui.Label;
-import squidpony.squidgrid.Direction;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A Label that changes its color automatically, taking its current color from a list such as a gradient. Useful for
- * implementing a "blink" effect where a creature alternates being visible and invisible, for a magical object that has
- * all the colors of the rainbow, or for all sorts of similar uses. The color pattern loops, by default one loop per two
- * seconds (but this can be changed), so longer lists of colors will display each color for a shorter time.
- * Created by Tommy Ettinger on 3/23/2016.
- */
-public class ColorChangeLabel extends Label {
-
-    private List<Color> colors;
-    protected float progress = 0f;
-    protected float loopTime = 2f;
-    protected ColorChangeLabel()
-    {
-        this(null, null);
-    }
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param colors a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, Collection<Color> colors) {
-        this(text, style, 2f, false, colors);
-    }
-
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param loopTime the amount of time, in seconds, it takes to loop through all the colors in the list
-     * @param colors a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, float loopTime, Collection<Color> colors){
-        this(text, style, loopTime, false, colors);
-    }
-
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param loopTime the amount of time, in seconds, it takes to loop through all the colors in the list
-     * @param doubleWidth true if this takes up two grid cells; only matters if you use {@link AnimatedEntity#setDirection(Direction)}
-     * @param colors a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, float loopTime, boolean doubleWidth, Collection<Color> colors){
-        super(text, style);
-        if(colors == null || colors.isEmpty())
-            this.colors = DefaultResources.getSCC().rainbow(12);
-        else
-            this.colors = new ArrayList<>(colors);
-        this.loopTime = loopTime == 0 ? 1 : loopTime;
-    }
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param colors an array or vararg of Color
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, Color... colors) {
-        this(text, style, 2f, false, colors);
-    }
-
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param loopTime the amount of time, in seconds, it takes to loop through all the colors in the list
-     * @param colors an array or vararg of Color
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, float loopTime, Color... colors){
-        this(text, style, loopTime, false, colors);
-    }
-
-    /**
-     * Constructs a ColorChangeLabel. Used internally by TextCellFactory, but library users are unlikely to need this.
-     * @param text the text to display in this ColorChangeLabel
-     * @param style the LabelStyle to use for this; typically TextCellFactory handles this
-     * @param loopTime the amount of time, in seconds, it takes to loop through all the colors in the list
-     * @param doubleWidth true if this takes up two grid cells; only matters if you use {@link AnimatedEntity#setDirection(Direction)}
-     * @param colors an array or vararg of Color
-     */
-    public ColorChangeLabel(CharSequence text, LabelStyle style, float loopTime, boolean doubleWidth, Color... colors){
-        super(text, style);
-        if (colors == null || colors.length == 0)
-            this.colors = DefaultResources.getSCC().rainbow(12);
-        else {
-            this.colors = new ArrayList<>(colors.length);
-            Collections.addAll(this.colors, colors);
-        }
-        this.loopTime = loopTime == 0 ? 1 : loopTime;
-    }
-
-    /**
-     * Returns the color the actor will be tinted when drawn. Takes the Color from the List of Color this was constructed
-     * with or assigned with setColors, not the normal Actor color assigned with setColor.
-     * @return the Color this will be drawn with
-     */
-    @Override
-    public Color getColor() {
-        return colors.get((int)(progress * colors.size() / loopTime));
-    }
-
-    /**
-     * Sets the list of colors this uses to choose what color it draws with.
-     * @param colors a Collection (usually a List) of Color, such as one returned by SquidColorCenter's gradient method
-     */
-    public void setColors(Collection<Color> colors)
-    {
-        if(colors == null || colors.isEmpty())
-            this.colors = DefaultResources.getSCC().rainbow(12);
-        else
-            this.colors = new ArrayList<>(colors);
-    }
-
-    /**
-     * Sets the list of colors this uses to choose what color it draws with.
-     * @param colors an array or vararg of Color
-     */
-    public void setColors(Color... colors)
-    {
-        if (colors == null || colors.length == 0)
-            this.colors = DefaultResources.getSCC().rainbow(12);
-        else {
-            this.colors = new ArrayList<>(colors.length);
-            Collections.addAll(this.colors, colors);
-        }
-    }
-    /**
-     * Updates the actor based on time. Typically this is called each frame by
-     * {@link com.badlogic.gdx.scenes.scene2d.Stage#act(float)}.
-     * <p>
-     * The default implementation calls
-     * {@link com.badlogic.gdx.scenes.scene2d.Action#act(float)} on each action and removes actions that are complete.
-     *
-     * @param delta Time in seconds since the last frame.
-     */
-    @Override
-    public void act(float delta) {
-        super.act(delta);
-        progress = (progress + delta) % (loopTime - 0.001f);
-    }
-
-    /**
-     * Changes the amount of time this takes to loop through all colors, and also resets the current loop to its start.
-     * @param loopTime the amount of time, in seconds, it takes to loop through all the colors in the list
-     */
-    public void resetLoopTime(float loopTime)
-    {
-        this.loopTime = loopTime;
-        progress = 0f;
-    }
-}

+ 0 - 408
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/Filters.java

@@ -1,408 +0,0 @@
-package squidpony.squidgrid.gui.gdx;
-
-import com.badlogic.gdx.graphics.Color;
-
-import squidpony.IFilter;
-import squidpony.squidmath.LightRNG;
-
-/**
- * Implementations of {@link IFilter}, that all are meant to perform different changes
- * to colors before they are created (they should be passed to SquidColorCenter's constructor, which can use them).
- * Created by Tommy Ettinger on 10/31/2015.
- */
-public class Filters {
-
-	private Filters() {
-		/* You should not build me */
-	}
-
-    /**
-     * A Filter that does nothing to the colors it is given but pass them along unchanged.
-     */
-    public static class IdentityFilter implements IFilter<Color>
-    {
-        public IdentityFilter()
-        {
-        	/* Nothing to do */
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return new Color(r, g, b, a);
-        }
-    }
-
-    /**
-     * A Filter that converts all colors passed to it to grayscale, like a black and white film.
-     */
-    public static class GrayscaleFilter implements IFilter<Color>
-    {
-        public GrayscaleFilter()
-        {
-        	/* Nothing to do */
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            float v = (r + g + b) / 3f;
-            return new Color(v, v, v, a);
-        }
-    }
-
-    /**
-     * A Filter that tracks the highest brightness for any component it was assigned and stores it in state as the first
-     * and only element.
-     */
-    public static class MaxValueFilter extends Filter<Color>
-    {
-        public MaxValueFilter()
-        {
-            state = new float[]{0};
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            state[0] = Math.max(state[0], Math.max(r, Math.max(g, b)));
-            return new Color(r, g, b, a);
-        }
-
-    }
-
-    /**
-     * A Filter that performs a brightness adjustment to make dark areas lighter and light areas not much less bright.
-     */
-    public static class GammaCorrectFilter extends Filter<Color> {
-        /**
-         * Sets up a GammaCorrectFilter with the desired gamma adjustment.
-         *
-         * @param gamma    should be 1.0 or less, and must be greater than 0. Typical values are between 0.4 to 0.8.
-         * @param maxValue the maximum brightness in the colors this will be passed; use MaxValueFilter for this
-         */
-        public GammaCorrectFilter(float gamma, float maxValue) {
-            state = new float[]{gamma, 1f / (float) Math.pow(maxValue, gamma)};
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return new Color(state[1] * (float) Math.pow(r, state[0]),
-                    state[1] * (float) Math.pow(g, state[0]),
-                    state[1] * (float) Math.pow(b, state[0]),
-                    a);
-        }
-    }
-    /**
-     * A Filter that is constructed with a color and linear-interpolates any color it is told to alter toward the color
-     * it was constructed with.
-     */
-    public static class LerpFilter extends Filter<Color> {
-        /**
-         * Sets up a LerpFilter with the desired color to linearly interpolate towards.
-         *
-         * @param r the red component to lerp towards
-         * @param g the green component to lerp towards
-         * @param b the blue component to lerp towards
-         * @param a the opacity component to lerp towards
-         * @param amount the amount to lerp by, should be between 0.0 and 1.0
-         */
-        public LerpFilter(float r, float g, float b, float a, float amount) {
-            state = new float[]{r, g, b, a, amount};
-        }
-        /**
-         * Sets up a LerpFilter with the desired color to linearly interpolate towards.
-         *
-         * @param color the Color to lerp towards
-         * @param amount the amount to lerp by, should be between 0.0 and 1.0
-         */
-        public LerpFilter(Color color, float amount) {
-            state = new float[]{color.r, color.g, color.b, color.a, amount};
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return new Color(r, g, b, a).lerp(state[0], state[1], state[2], state[3], state[4]);
-        }
-    }
-    /**
-     * A Filter that is constructed with a group of colors and linear-interpolates any color it is told to alter toward
-     * the color it was constructed with that has the closest hue.
-     */
-    public static class MultiLerpFilter extends Filter<Color> {
-        private SquidColorCenter globalSCC;
-        /**
-         * Sets up a MultiLerpFilter with the desired colors to linearly interpolate towards; the lengths of each given
-         * array should be identical.
-         *
-         * @param r the red components to lerp towards
-         * @param g the green components to lerp towards
-         * @param b the blue components to lerp towards
-         * @param a the opacity components to lerp towards
-         * @param amount the amounts to lerp by, should each be between 0.0 and 1.0
-         */
-        public MultiLerpFilter(float[] r, float[] g, float[] b, float[] a, float[] amount) {
-            state = new float[Math.min(r.length, Math.min(g.length, Math.min(b.length,
-                    Math.min(a.length, amount.length)))) * 6];
-            globalSCC = DefaultResources.getSCC();
-            for (int i = 0; i < state.length / 6; i++) {
-                state[i * 6] = r[i];
-                state[i * 6 + 1] = g[i];
-                state[i * 6 + 2] = b[i];
-                state[i * 6 + 3] = a[i];
-                state[i * 6 + 4] = amount[i];
-                state[i * 6 + 5] = globalSCC.getHue(r[i], g[i], b[i]);
-            }
-        }/**
-         * Sets up a MultiLerpFilter with the desired colors to linearly interpolate towards and their amounts.
-         *
-         * @param colors the Colors to lerp towards
-         * @param amount the amounts to lerp by, should each be between 0.0 and 1.0
-         */
-        public MultiLerpFilter(Color[] colors, float[] amount) {
-            state = new float[Math.min(colors.length, amount.length) * 6];
-            globalSCC = DefaultResources.getSCC();
-            for (int i = 0; i < state.length / 6; i++) {
-                state[i * 6] = colors[i].r;
-                state[i * 6 + 1] = colors[i].g;
-                state[i * 6 + 2] = colors[i].b;
-                state[i * 6 + 3] = colors[i].a;
-                state[i * 6 + 4] = amount[i];
-                state[i * 6 + 5] = globalSCC.getHue(colors[i]);
-            }
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            float givenH = globalSCC.getHue(r, g, b), givenS = globalSCC.getSaturation(r, g, b),
-                    minDiff = 999.0f, temp;
-            if(givenS < 0.05)
-                return new Color(r, g, b, a);
-            int choice = 0;
-            for (int i = 5; i < state.length; i += 6) {
-                temp = state[i] - givenH;
-                temp = (temp >= 0.5f) ? Math.abs(temp - 1f) % 1f : Math.abs(temp);
-                if(temp < minDiff) {
-                    minDiff = temp;
-                    choice = i / 6; // rounds down
-                }
-            }
-            return new Color(r, g, b, a).lerp(state[choice * 6], state[choice * 6 + 1], state[choice * 6 + 2],
-                    state[choice * 6 + 3], state[choice * 6 + 4]);
-        }
-    }
-
-    /**
-     * A Filter that is constructed with a color and makes any color it is told to alter have the same hue as the given
-     * color, have saturation that is somewhere between the given color's and the altered colors, and chiefly is
-     * distinguishable from other colors by value. Useful for sepia effects, which can be created satisfactorily with
-     * {@code new Filters.ColorizeFilter(SColor.CLOVE_BROWN, 0.6f, 0.0f)}.
-     */
-    public static class ColorizeFilter extends Filter<Color> {
-        private SquidColorCenter globalSCC;
-        /**
-         * Sets up a ColorizeFilter with the desired color to colorize towards.
-         *
-         * @param r the red component to colorize towards
-         * @param g the green component to colorize towards
-         * @param b the blue component to colorize towards
-         */
-        public ColorizeFilter(float r, float g, float b) {
-            globalSCC = DefaultResources.getSCC();
-
-            state = new float[]{globalSCC.getHue(r, g, b), globalSCC.getSaturation(r, g, b), 1f, 0f};
-        }
-        /**
-         * Sets up a ColorizeFilter with the desired color to colorize towards.
-         *
-         * @param color the Color to colorize towards
-         */
-        public ColorizeFilter(Color color) {
-            globalSCC = DefaultResources.getSCC();
-            state = new float[]{globalSCC.getHue(color), globalSCC.getSaturation(color), 1f, 0f};
-        }
-        /**
-         * Sets up a ColorizeFilter with the desired color to colorize towards.
-         *
-         * @param r the red component to colorize towards
-         * @param g the green component to colorize towards
-         * @param b the blue component to colorize towards
-         * @param saturationMultiplier a multiplier to apply to the final color's saturation; may be greater than 1
-         * @param valueModifier a modifier that affects the final brightness value of any color this alters;
-         *                      typically very small, such as in the -0.2f to 0.2f range
-         */
-        public ColorizeFilter(float r, float g, float b, float saturationMultiplier, float valueModifier) {
-            globalSCC = DefaultResources.getSCC();
-
-            state = new float[]{
-                    globalSCC.getHue(r, g, b),
-                    globalSCC.getSaturation(r, g, b),
-                    saturationMultiplier,
-                    valueModifier};
-        }
-        /**
-         * Sets up a ColorizeFilter with the desired color to colorize towards.
-         *
-         * @param color the Color to colorize towards
-         * @param saturationMultiplier a multiplier to apply to the final color's saturation; may be greater than 1
-         * @param valueModifier a modifier that affects the final brightness value of any color this alters;
-         *                      typically very small, such as in the -0.2f to 0.2f range
-         */
-        public ColorizeFilter(Color color, float saturationMultiplier, float valueModifier) {
-            globalSCC = DefaultResources.getSCC();
-            state = new float[]{
-                    globalSCC.getHue(color),
-                    globalSCC.getSaturation(color),
-                    saturationMultiplier,
-                    valueModifier};
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return globalSCC.getHSV(
-                    state[0],
-                    Math.max(0f, Math.min((globalSCC.getSaturation(r, g, b) + state[1]) * 0.5f * state[2], 1f)),
-                    globalSCC.getValue(r, g, b) * (1f - state[3]) + state[3],
-                    a);
-        }
-    }
-    /**
-     * A Filter that makes the colors requested from it highly saturated, with the original hue, value and a timer that
-     * increments very slowly altering hue, with hue, value and the timer altering saturation, and the original hue,
-     * saturation, and value all altering value. It should look like a hallucination.
-     * <br>
-     * A short (poorly recorded) video can be seen here http://i.imgur.com/SEw2LXe.gifv ; performance should be smoother
-     * during actual gameplay.
-     */
-    public static class HallucinateFilter extends Filter<Color> {
-        private SquidColorCenter globalSCC;
-        /**
-         * Sets up a HallucinateFilter with the timer at 0..
-         */
-        public HallucinateFilter() {
-            globalSCC = DefaultResources.getSCC();
-
-            state = new float[]{0f};
-        }
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            state[0] += 0.00003f;
-            if(state[0] >= 1.0f)
-                state[0] = 0f;
-            float h = globalSCC.getHue(r, g, b),
-                    s = globalSCC.getSaturation(r, g, b),
-                    v = globalSCC.getValue(r, g, b);
-            return globalSCC.getHSV(
-                    (v * 4f + h + state[0]) % 1.0f,
-                    Math.max(0f, Math.min((h + v) * 0.65f + state[0] * 0.4f, 1f)),
-                    (h + v + s) * 0.35f + 0.7f,
-                    a);
-        }
-    }
-
-
-    /**
-     * A Filter that multiplies the saturation of any color requested from it by a number given during construction.
-     */
-    public static class SaturationFilter extends Filter<Color> {
-        private SquidColorCenter globalSCC;
-        /**
-         * Sets up a SaturationFilter with the desired saturation multiplier. Using a multiplier of 0f, as you would
-         * expect, makes the image grayscale. Using a multiplier of 0.5 make the image "muted", with no truly bright
-         * colors, while 1.0f makes no change, and and any numbers higher than 1.0f will make the image more saturated,
-         * with the exception of colors that were already grayscale or close to it. This clamps the result, so there's
-         * no need to worry about using too high of a saturation multiplier.
-         *
-         * @param multiplier the amount to multiply each requested color's saturation by; 1.0f means "no change"
-         */
-        public SaturationFilter(float multiplier) {
-            globalSCC = DefaultResources.getSCC();
-
-            state = new float[]{multiplier};
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return globalSCC.getHSV(
-                    globalSCC.getHue(r, g, b),
-                    Math.max(0f, Math.min((globalSCC.getSaturation(r, g, b) * state[0]), 1f)),
-                    globalSCC.getValue(r, g, b),
-                    a);
-        }
-    }
-
-    /**
-     * A Filter that is constructed with a palette of colors and randomly increases or decreases the red, green, and
-     * blue components of any color it is told to alter. Good for a "glitchy screen" effect.
-     */
-    public static class WiggleFilter extends Filter<Color> {
-        LightRNG rng;
-        public WiggleFilter()
-        {
-            rng = new LightRNG();
-        }
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            return new Color(r - 0.1f + rng.nextInt(5) * 0.05f,
-                    g - 0.1f + rng.nextInt(5) * 0.05f,
-                    b - 0.1f + rng.nextInt(5) * 0.05f,
-                    a);
-        }
-    }
-
-    /**
-     * A Filter that is constructed with a group of colors and forces any color it is told to alter to exactly
-     * the color it was constructed with that has the closest red, green, and blue components. A convenient way to
-     * use this is to pass in one of the color series from SColor, such as RED_SERIES or ACHROMATIC_SERIES.
-     *
-     * Preview using BLUE_GREEN_SERIES foreground, ACHROMATIC_SERIES background: http://i.imgur.com/2HdZpC9.png
-     */
-    public static class PaletteFilter extends Filter<Color> {
-        /**
-         * Sets up a PaletteFilter with the exact colors to use as individual components; the lengths of each given
-         * array should be identical.
-         *
-         * @param r the red components to use
-         * @param g the green components to use
-         * @param b the blue components to use
-         * @param a the opacity components to use
-         */
-        public PaletteFilter(float[] r, float[] g, float[] b, float[] a) {
-            state = new float[Math.min(r.length, Math.min(g.length, Math.min(b.length,
-                    a.length))) * 4];
-            for (int i = 0; i < state.length / 4; i++) {
-                state[i * 4] = r[i];
-                state[i * 4 + 1] = g[i];
-                state[i * 4 + 2] = b[i];
-                state[i * 4 + 3] = a[i];
-            }
-        }/**
-         * Sets up a PaletteFilter with the exact colors to use as Colors. A convenient way to
-         * use this is to pass in one of the color series from SColor, such as RED_SERIES or ACHROMATIC_SERIES.
-         *
-         * @param colors the Colors to use
-         */
-        public PaletteFilter(Color[] colors) {
-            state = new float[colors.length * 4];
-            for (int i = 0; i < state.length / 4; i++) {
-                state[i * 4] = colors[i].r;
-                state[i * 4 + 1] = colors[i].g;
-                state[i * 4 + 2] = colors[i].b;
-                state[i * 4 + 3] = colors[i].a;
-            }
-        }
-
-        @Override
-        public Color alter(float r, float g, float b, float a) {
-            float diff = 9999.0f, temp;
-            int choice = 0;
-            for (int i = 0; i < state.length; i += 4) {
-                temp = Math.abs(state[i] - r) + Math.abs(state[i + 1] - g) + Math.abs(state[i + 2] - b);
-                if(temp < diff) {
-                    diff = temp;
-                    choice = i;
-                }
-            }
-            return new Color(state[choice], state[choice + 1], state[choice + 2],
-                    state[choice + 3]);
-        }
-    }
-
-}

+ 22 - 0
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/GrayscaleFilter.java

@@ -0,0 +1,22 @@
+package squidpony.squidgrid.gui.gdx;
+
+import com.badlogic.gdx.graphics.Color;
+
+import squidpony.IFilter;
+
+/**
+ * A Filter that converts all colors passed to it to grayscale, like a black and white film.
+ */
+public class GrayscaleFilter implements IFilter<Color>
+{
+    public GrayscaleFilter()
+    {
+    	/* Nothing to do */
+    }
+
+    @Override
+    public Color alter(float r, float g, float b, float a) {
+        float v = (r + g + b) / 3f;
+        return new Color(v, v, v, a);
+    }
+}

+ 0 - 604
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/SColorFactory.java

@@ -1,604 +0,0 @@
-package squidpony.squidgrid.gui.gdx;
-
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.math.MathUtils;
-import squidpony.squidmath.Bresenham;
-import squidpony.squidmath.Coord3D;
-import squidpony.squidmath.RNG;
-
-import java.util.*;
-
-/**
- * Provides utilities for working with colors as well as caching operations for
- * color creation.
- *
- * All returned SColor objects are cached so multiple requests for the same
- * SColor will not create duplicate long term objects.
- *
- * @see SquidColorCenter another technique for caching colors that allows filters.
- *
- * @author Eben Howard - http://squidpony.com - howard@squidpony.com
- * @author Tommy Ettinger - responsible for mutilating this class to work on libGDX
- */
-public class SColorFactory {
-
-    private final TreeMap<String, SColor> nameLookup;
-    private final TreeMap<Integer, SColor> valueLookup;
-    private RNG rng;
-    private Map<Integer, SColor> colorBag;
-    private Map<String, ArrayList<SColor>> palettes;
-    private long floor = 1;//what multiple to floor rgb values to in order to reduce total colors
-
-    /**
-     * Constructs a new SColorFactory with an empty cache.
-     * <br>
-     * Implementation note: SColorFactory initially used static methods and was not intended to
-     * be constructed by users, but for compatibility with Android (where static instances may
-     * linger into another run of an application), it was reworked to require an object to be
-     * constructed and for that object to contain the cache, rather than a static instance. Code
-     * written for earlier versions of SquidLib may use static methods on SColorFactory; most
-     * code written in SquidLib 3.0.0 beta 2 and newer prefers the IColorCenter implementations
-     * such as SquidColorCenter when SColor features such as color names aren't required. As of
-     * the master revision after beta 3, SquidColorCenter implements most of SColorFactory's API,
-     * and also supports a Filter for automatic changes to requested colors..
-     */
-    public SColorFactory() {
-
-        nameLookup = new TreeMap<>();
-        valueLookup = new TreeMap<>();
-        rng = DefaultResources.getGuiRandom();
-        colorBag = new HashMap<>();
-        palettes = new HashMap<>();
-        floor = 1;
-
-    }
-
-    /**
-     * Returns the SColor Constant who's name is the one provided. If one cannot
-     * be found then null is returned.
-     *
-     * This method constructs a list of the SColor constants the first time it
-     * is called.
-     *
-     * @param s the name
-     * @return  the SColor by name s
-     */
-    public SColor colorForName(String s) {
-        if (nameLookup.isEmpty()) {
-            for (SColor sc : SColor.FULL_PALETTE) {
-                nameLookup.put(sc.getName(), sc);
-            }
-        }
-
-        return nameLookup.get(s);
-    }
-
-    /**
-     * Returns the SColor who's value matches the one passed in. If no SColor
-     * Constant matches that value then a cached or new SColor is returned that
-     * matches the provided value.
-     *
-     * This method constructs a list of the SColor constants the first time it
-     * is called.
-     *
-     * @param rgb an int encoding 256 * 256 * red + 256 * green + blue
-     * @return the SColor with value rgb
-     */
-    public SColor colorForValue(int rgb) {
-        if (valueLookup.isEmpty()) {
-            for (SColor sc : SColor.FULL_PALETTE) {
-                valueLookup.put(sc.toIntBits(), sc);
-            }
-        }
-
-        return valueLookup.containsKey(rgb) ? valueLookup.get(rgb) : asSColor(rgb);
-    }
-
-    /**
-     * Returns the number of SColor objects currently cached.
-     *
-     * @return
-     */
-    public int quantityCached() {
-        return colorBag.size();
-    }
-
-    /**
-     * Utility method to blend the two colors by the amount passed in as the
-     * coefficient.
-     *
-     * @param a
-     * @param b
-     * @param coef
-     * @return
-     */
-    @SuppressWarnings("unused")
-	private int blend(int a, int b, double coef) {
-        coef = MathUtils.clamp(coef, 0, 1);
-        return (int) (a + (b - a) * coef);
-    }
-    /**
-     * Utility method to blend the two colors by the amount passed in as the
-     * coefficient.
-     *
-     * @param a
-     * @param b
-     * @param coef
-     * @return
-     */
-    private float blend(float a, float b, double coef) {
-        float cf = MathUtils.clamp((float)coef, 0, 1);
-        return (a + (b - a) * cf);
-    }
-
-    /**
-     * Returns an SColor that is the given distance from the first color to the
-     * second color.
-     *
-     * @param color1 The first color
-     * @param color2 The second color
-     * @param coef The percent towards the second color, as 0.0 to 1.0
-     * @return
-     */
-    public SColor blend(SColor color1, SColor color2, double coef) {
-        return asSColor(blend(color1.a, color2.a, coef),
-                blend(color1.r, color2.r, coef),
-                blend(color1.g, color2.g, coef),
-                blend(color1.b, color2.b, coef));
-    }
-
-    /**
-     * Returns an SColor that is randomly chosen from the color line between the
-     * two provided colors from the two provided points.
-     *
-     * @param color1
-     * @param color2
-     * @param min The minimum percent towards the second color, as 0.0 to 1.0
-     * @param max The maximum percent towards the second color, as 0.0 to 1.0
-     * @return
-     */
-    public SColor randomBlend(SColor color1, SColor color2, double min, double max) {
-        return blend(color1, color2, rng.between(min, max));
-    }
-
-    /**
-     * Adds the two colors together.
-     *
-     * @param color1
-     * @param color2
-     * @return
-     */
-    public SColor add(SColor color1, SColor color2) {
-        return asSColor(color1.a + color2.a, color1.r + color2.r, color1.g + color2.g, color1.b + color2.b);
-    }
-
-    /**
-     * Uses the second color as a light source, meaning that each of the red,
-     * green, and blue values of the first color are multiplied by the lighting
-     * color's percentage of full value (1.0).
-     *
-     * @param color
-     * @param light
-     * @return
-     */
-    public SColor lightWith(SColor color, SColor light) {
-        return asSColor((color.a * light.a), (color.r * light.r), (color.g * light.g), (color.b * light.b));
-    }
-
-    /**
-     * Clears the backing cache.
-     *
-     * Should only be used if an extreme number of colors are being created and
-     * then not reused, such as when blending different colors in different
-     * areas that will not be revisited.
-     */
-    public void emptyCache() {
-        colorBag = new HashMap<>();
-    }
-
-    /**
-     * Sets the value at which each of the red, green, and blue values will be
-     * set to the nearest lower multiple of.
-     *
-     * For example, a floor value of 5 would mean that each of those values
-     * would be considered the nearest lower multiple of 5 when building the
-     * colors.
-     *
-     * If the value passed in is less than 1, then the flooring value is set at
-     * 1.
-     *
-     * @param value used to determine the precision of rounding
-     */
-    public void setFloor(int value) {
-        floor = Math.max(1, value);
-    }
-
-    /**
-     * Gets the value at which each of the red, green, and blue values will be
-     * set to the nearest lower multiple of.
-     * <br>
-     * For example, a floor value of 5 would mean that each of those values
-     * would be considered the nearest lower multiple of 5 when building the
-     * colors.
-     *
-     * @return the current floor value as a long, which defaults to 1.
-     */
-    public long getFloor() {
-        return floor;
-    }
-
-    /**
-     * Returns the cached color that matches the desired rgb value.
-     *
-     * If the color is not already in the cache, it is created and added to the
-     * cache.
-     *
-     * This method does not check to see if the value is already available as a
-     * SColor constant. If such functionality is desired then please use
-     * colorForValue(int rgb) instead.
-     *
-     * @param argb
-     * @return
-     */
-    public SColor asSColor(int argb) {
-        int working = argb;
-        if (floor != 1) {//need to convert to floored values
-            int r = (argb >>> 24) & 0xff;
-            r -= r % floor;
-            int g = (argb >> 16) & 0xff;
-            g -= g % floor;
-            int b = (argb >> 8) & 0xff;
-            b -= b % floor;
-            int a = (argb) & 0xff;
-            a -= a % floor;
-
-            //put back together
-            working = ((r & 0xFF) << 24)
-                    | ((g & 0xFF) << 16)
-                    | ((b & 0xFF) << 8)
-                    | (a & 0xFF);
-        }
-
-        if (colorBag.containsKey(working)) {
-            return colorBag.get(working);
-        } else {
-            SColor color = new SColor(working);
-            colorBag.put(working, color);
-            return color;
-        }
-    }
-    /**
-     * Returns the cached color that matches the desired rgb value.
-     *
-     * If the color is not already in the cache, it is created and added to the
-     * cache.
-     *
-     * This method does not check to see if the value is already available as a
-     * SColor constant. If such functionality is desired then please use
-     * colorForValue(int rgb) instead.
-     *
-     * @param a
-     * @param r 
-     * @param g 
-     * @param b 
-     * @return
-     */
-    public SColor asSColor(float a, float r, float g, float b) {
-        int working = 0;
-        int aa = MathUtils.round(255 * a);
-        aa -= aa % floor;
-        int rr = MathUtils.round(255 * r);
-        rr -= rr % floor;
-        int gg = MathUtils.round(255 * g);
-        gg -= gg % floor;
-        int bb = MathUtils.round(255 * b);
-        bb -= bb % floor;
-
-        //put back together
-        working = ((aa & 0xFF) << 24)
-                | ((rr & 0xFF) << 16)
-                | ((gg & 0xFF) << 8)
-                | (bb & 0xFF);
-
-
-        if (colorBag.containsKey(working)) {
-            return colorBag.get(working);
-        } else {
-            SColor color = new SColor(working);
-            colorBag.put(working, color);
-            return color;
-        }
-    }
-
-    /**
-     * Returns an SColor that is opaque.
-     *
-     * @param r
-     * @param g
-     * @param b
-     * @return
-     */
-    public SColor asSColor(int r, int g, int b) {
-        return asSColor(255, r, g, b);
-    }
-
-    /**
-     * Returns an SColor with the given values, with those values clamped
-     * between 0 and 255.
-     *
-     * @param a
-     * @param r
-     * @param g
-     * @param b
-     * @return
-     */
-    public SColor asSColor(int a, int r, int g, int b) {
-        a = Math.min(a, 255);
-        a = Math.max(a, 0);
-        r = Math.min(r, 255);
-        r = Math.max(r, 0);
-        g = Math.min(g, 255);
-        g = Math.max(g, 0);
-        b = Math.min(b, 255);
-        b = Math.max(b, 0);
-        return asSColor((a << 24) | (r << 16) | (g << 8) | b);
-    }
-
-    /**
-     * Returns an SColor representation of the provided Color. If there is a
-     * named SColor constant that matches the value, then that constant is
-     * returned.
-     *
-     * @param color
-     * @return
-     */
-    public SColor asSColor(Color color) {
-        return colorForValue(Color.rgba8888(color.a, color.r, color.g, color.b));
-    }
-
-    /**
-     * Returns an SColor that is a slightly dimmer version of the provided
-     * color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor dim(SColor color) {
-        return blend(color, SColor.BLACK, 0.1);
-    }
-
-    /**
-     * Returns an SColor that is a somewhat dimmer version of the provided
-     * color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor dimmer(SColor color) {
-        return blend(color, SColor.BLACK, 0.3);
-    }
-
-    /**
-     * Returns an SColor that is a lot darker version of the provided color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor dimmest(SColor color) {
-        return blend(color, SColor.BLACK, 0.7);
-    }
-
-    /**
-     * Returns an SColor that is a slightly lighter version of the provided
-     * color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor light(SColor color) {
-        return blend(color, SColor.WHITE, 0.1);
-    }
-
-    /**
-     * Returns an SColor that is a somewhat lighter version of the provided
-     * color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor lighter(SColor color) {
-        return blend(color, SColor.WHITE, 0.3);
-    }
-
-    /**
-     * Returns an SColor that is a lot lighter version of the provided color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor lightest(SColor color) {
-        return blend(color, SColor.WHITE, 0.6);
-    }
-
-    /**
-     * Returns an SColor that is the fully desaturated (greyscale) version of
-     * the provided color.
-     *
-     * @param color
-     * @return
-     */
-    public SColor desaturated(SColor color) {
-        int r = MathUtils.round(color.r * 255);
-        int g = MathUtils.round(color.g * 255);
-        int b = MathUtils.round(color.b * 255);
-
-        int average = (int) (r * 0.299 + g * 0.587 + b * 0.114);
-
-        return asSColor(average, average, average);
-    }
-
-    /**
-     * Returns an SColor that is the version of the provided color desaturated
-     * the given amount.
-     *
-     * @param color
-     * @param percent The percent to desaturate, from 0.0 for none to 1.0 for
-     * fully desaturated
-     * @return
-     */
-    public SColor desaturate(SColor color, double percent) {
-        return blend(color, desaturated(color), percent);
-    }
-
-    /**
-     * Returns a list of colors starting at the first color and moving to the
-     * second color. The end point colors are included in the list.
-     *
-     * @param color1 starting color
-     * @param color2 ending color
-     * @return an ArrayList of SColor going from color1 to color2; the length should be no greater than 256.
-     */
-    public ArrayList<SColor> asGradient(SColor color1, SColor color2) {
-        String name = paletteNamer(color1, color2);
-        if (palettes.containsKey(name)) {
-            return palettes.get(name);
-        }
-
-        //get the gradient
-        Queue<Coord3D> gradient = Bresenham.line3D(scolorToCoord3D(color1), scolorToCoord3D(color2));
-        ArrayList<SColor> ret = new ArrayList<>();
-        for (Coord3D coord : gradient) {
-            ret.add(coord3DToSColor(coord));
-        }
-
-        palettes.put(name, ret);
-        return ret;
-    }
-
-    /**
-     * Returns the palette associate with the provided name, or null if there is
-     * no such palette.
-     *
-     * @param name
-     * @return
-     */
-    public ArrayList<SColor> palette(String name) {
-        return palettes.get(name);
-    }
-    /**
-     * Returns the palette associate with the provided name, or null if there is
-     * no such palette.
-     *
-     * @param name
-     * @return
-     * @deprecated Prefer palette over this misspelled version.
-     */
-    public ArrayList<SColor> pallet(String name) {
-        return palettes.get(name);
-    }
-
-    /**
-     * Returns the SColor that is the provided percent towards the end of the
-     * palette. Bounds are checked so as long as there is at least one color in
-     * the palette, values below 0 will return the first element and values
-     * above 1 will return the last element;
-     *
-     * If there is no palette keyed to the provided name, null is returned.
-     *
-     * @param name
-     * @param percent
-     * @return
-     */
-    public SColor fromPalette(String name, float percent) {
-        ArrayList<SColor> list = palettes.get(name);
-        if (list == null) {
-            return null;
-        }
-
-        int index = Math.round(list.size() * percent);//find the index that's the given percent into the gradient
-        index = Math.min(index, list.size() - 1);
-        index = Math.max(index, 0);
-        return list.get(index);
-    }
-    /**
-     * Returns the SColor that is the provided percent towards the end of the
-     * palette. Bounds are checked so as long as there is at least one color in
-     * the palette, values below 0 will return the first element and values
-     * above 1 will return the last element;
-     *
-     * If there is no palette keyed to the provided name, null is returned.
-     *
-     * @param name
-     * @param percent
-     * @return
-     *
-     * @deprecated Prefer fromPalette over this misspelled version; they are equivalent.
-     */
-    public SColor fromPallet(String name, float percent) {
-        ArrayList<SColor> list = palettes.get(name);
-        if (list == null) {
-            return null;
-        }
-
-        int index = Math.round(list.size() * percent);//find the index that's the given percent into the gradient
-        index = Math.min(index, list.size() - 1);
-        index = Math.max(index, 0);
-        return list.get(index);
-    }
-
-    /**
-     * Places the palette into the cache, along with each of the member colors.
-     *
-     * @param name
-     * @param palette
-     * 
-     * @deprecated Prefer addPalette over this misspelled version; they are equivalent.
-     */
-    public void addPallet(String name, ArrayList<SColor> palette) {
-        addPalette(name, palette);
-    }
-
-    /**
-     * Places the palette into the cache, along with each of the member colors.
-     *
-     * @param name
-     * @param palette
-     */
-    public void addPalette(String name, ArrayList<SColor> palette) {
-        ArrayList<SColor> temp = new ArrayList<>();
-
-        //make sure all the colors in the palette are also in the general color cache
-        for (SColor sc : palette) {
-            temp.add(asSColor(sc.a, sc.r, sc.g, sc.b));
-        }
-
-        palettes.put(name, temp);
-    }
-
-    /**
-     * Converts the provided color into a three dimensional coordinate point for
-     * use in the Bresenham algorithms.
-     *
-     * @param color
-     * @return
-     */
-    private Coord3D scolorToCoord3D(SColor color) {
-        return new Coord3D(MathUtils.floor(color.r * 255), MathUtils.floor(color.g * 255), MathUtils.floor(color.b * 255));
-    }
-
-    /**
-     * Converts the provided three dimensional coordinate into a color for use
-     * in the Bresenham algorithms.
-     *
-     * @param coord
-     * @return
-     */
-    private SColor coord3DToSColor(Coord3D coord) {
-        return asSColor(coord.x, coord.y, coord.z);
-    }
-
-    private String paletteNamer(SColor color1, SColor color2) {
-        return color1.getName() + " to " + color2.getName();
-    }
-
-}

+ 0 - 2
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/SquidPanel.java

@@ -3,7 +3,6 @@ package squidpony.squidgrid.gui.gdx;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.g2d.Batch;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.scenes.scene2d.Action;
 import com.badlogic.gdx.scenes.scene2d.Actor;
@@ -20,7 +19,6 @@ import squidpony.squidmath.StatefulRNG;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 
 /**
  * Displays text and images in a grid pattern. Supports basic animations.

+ 0 - 509
squidlib/src/main/java/squidpony/squidgrid/gui/gdx/TextPanel.java

@@ -1,509 +0,0 @@
-package squidpony.squidgrid.gui.gdx;
-
-import com.badlogic.gdx.graphics.Color;
-import com.badlogic.gdx.graphics.g2d.Batch;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.BitmapFontCache;
-import com.badlogic.gdx.graphics.g2d.GlyphLayout;
-import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
-import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.math.Matrix4;
-import com.badlogic.gdx.scenes.scene2d.Actor;
-import com.badlogic.gdx.scenes.scene2d.InputEvent;
-import com.badlogic.gdx.scenes.scene2d.InputListener;
-import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
-import com.badlogic.gdx.utils.Align;
-import squidpony.panel.IColoredString;
-import squidpony.panel.IMarkup;
-import squidpony.squidgrid.gui.gdx.UIUtil.CornerStyle;
-import squidpony.squidgrid.gui.gdx.UIUtil.YMoveKind;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * A panel to display some text using libgdx directly (i.e. without using
- * {@link SquidPanel}) as in these examples (no scrolling first, then with a
- * scroll bar):
- * 
- * <p>
- * <ul>
- * <li><img src="http://i.imgur.com/EqEXqlu.png"/></li>
- * <li><img src="http://i.imgur.com/LYbxQZE.png"/></li>
- * </ul>
- * </p>
- * 
- * <p>
- * It supports vertical scrolling, i.e. it'll put a vertical scrollbar if
- * there's too much text to display. This class does a lot of stuff, you
- * typically only have to provide the textures for the scrollbars and the scroll
- * knobs (see example below).
- * </p>
- * 
- * <p>
- * A typical usage of this class is as follows:
- * 
- * <pre>
- * final TextPanel<Color> tp = new TextPanel<>(new GDXMarkup(), font);
- * tp.init(screenWidth, screenHeight, text); <- first 2 params: for fullscreen
- * final ScrollPane sp = tp.getScrollPane();
- * sp.setScrollPaneStyle(new ScrollPaneStyle(...)); <- set textures
- * stage.addActor(sp);
- * stage.setKeyboardFocus(sp);
- * stage.setScrollFocus(sp);
- * stage.draw();
- * </pre>
- * </p>
- * 
- * <p>
- * In addition to what {@link ScrollPane} does (knobs, handling of the wheel);
- * this class plugs scrolling with arrow keys (up, down, page up, page down) and
- * vim shortcuts (j/k).
- * </p>
- * 
- * @author smelC
- * 
- * @see ScrollPane
- */
-public class TextPanel<T extends Color> {
-
-	/**
-	 * The color to use to paint the background (outside buttons) using
-	 * {@link ShapeRenderer}. Or {@code null} to disable background coloring.
-	 */
-	public /* @Nullable */ T backgroundColor;
-
-	/**
-	 * The color of the border around this panel, if any. If set, it'll be
-	 * rendered using {@link ShapeRenderer} and {@link #borderStyle}.
-	 */
-	public /* @Nullable */ T borderColor;
-
-	/** The size of the border, if any */
-	public float borderSize;
-
-	public CornerStyle borderStyle = CornerStyle.ROUNDED;
-
-	/**
-	 * Whether to use 'j' to scroll down, and 'k' to scroll up. Serious
-	 * roguelikes leave that to {@code true}, assuming they don't use j and k for movement...
-	 */
-	public boolean vimShortcuts = true;
-
-	protected /* @Nullable */ IMarkup<T> markup;
-
-	protected BitmapFont font;
-    protected boolean distanceField;
-    protected TextCellFactory tcf;
-	/** The text to display */
-	protected List<IColoredString<T>> text;
-
-    protected StringBuilder builder;
-
-	protected final ScrollPane scrollPane;
-
-	/**
-	 * The actor whose size is adjusted to the text. When scrolling is required,
-	 * it is bigger than {@link #scrollPane}.
-	 */
-	protected final Actor textActor;
-
-	/** Do not access directly, use {@link #getRenderer()} */
-	private /* @Nullable */ ShapeRenderer renderer;
-
-    /**
-     * The text to display MUST be set later on with
-     * {@link #init(float, float, Collection)}.
-     *
-     * @param markup
-     *            An optional way to compute markup.
-     * @param font
-     *            The font to use. It can be set later using
-     *            {@link #setFont(BitmapFont)}, but it MUST be set before
-     *            drawing this panel.
-     */
-    public TextPanel(/* @Nullable */IMarkup<T> markup, /* @Nullable */ BitmapFont font) {
-        if (markup != null)
-            setMarkup(markup);
-        if (font != null)
-            setFont(font);
-        builder = new StringBuilder(512);
-        textActor = new TextActor();
-
-        this.scrollPane = new ScrollPane(textActor);
-
-        this.scrollPane.addListener(new InputListener() {
-            @Override
-            public boolean keyDown(InputEvent event, int keycode) {
-				/* To receive key up */
-                return true;
-            }
-
-            @Override
-            public boolean keyUp(InputEvent event, int keycode) {
-                final YMoveKind d = UIUtil.YMoveKind.of(keycode, vimShortcuts);
-                if (d == null)
-                    return false;
-                else {
-                    switch (d) {
-                        case DOWN:
-                        case UP: {
-                            handleArrow(!d.isDown());
-                            return true;
-                        }
-                        case PAGE_DOWN:
-                        case PAGE_UP:
-                            final float scrollY = scrollPane.getScrollY();
-                            final int mult = d.isDown() ? 1 : -1;
-                            scrollPane.setScrollY(scrollY + mult * textActor.getHeight());
-                            return true;
-                    }
-                    throw new IllegalStateException(
-                            "Unmatched " + YMoveKind.class.getSimpleName() + ": " + d);
-                }
-            }
-
-            @Override
-            public boolean keyTyped(InputEvent event, char character) {
-                if (vimShortcuts && (character == 'j' || character == 'k'))
-                    return true;
-                else
-                    return super.keyTyped(event, character);
-            }
-
-            private void handleArrow(boolean up) {
-                final float scrollY = scrollPane.getScrollY();
-                final int mult = up ? -1 : 1;
-                scrollPane.setScrollY(scrollY + (scrollPane.getHeight() * 0.8f * mult));
-            }
-        });
-    }
-
-    /**
-     * The text to display MUST be set later on with
-     * {@link #init(float, float, Collection)}.
-     *
-     * @param markup
-     *            An optional way to compute markup.
-     * @param distanceFieldFont
-     *            A distance field font as a TextCellFactory to use.
-     *            Won't be used for drawing in cells, just the distance field code it has matters.
-     */
-    public TextPanel(/* @Nullable */IMarkup<T> markup, /* @Nullable */ TextCellFactory distanceFieldFont) {
-        if (markup != null)
-            setMarkup(markup);
-        if (distanceFieldFont != null)
-        {
-            tcf = distanceFieldFont;
-            distanceField = distanceFieldFont.distanceField;
-            tcf.initBySize();
-            font = tcf.font();
-            if (markup != null)
-                font.getData().markupEnabled = true;
-        }
-        builder = new StringBuilder(512);
-        textActor = new TextActor();
-        scrollPane = new ScrollPane(textActor);
-
-        this.scrollPane.addListener(new InputListener() {
-            @Override
-            public boolean keyDown(InputEvent event, int keycode) {
-				/* To receive key up */
-                return true;
-            }
-
-            @Override
-            public boolean keyUp(InputEvent event, int keycode) {
-                final YMoveKind d = UIUtil.YMoveKind.of(keycode, vimShortcuts);
-                if (d == null)
-                    return false;
-                else {
-                    switch (d) {
-                        case DOWN:
-                        case UP: {
-                            handleArrow(!d.isDown());
-                            return true;
-                        }
-                        case PAGE_DOWN:
-                        case PAGE_UP:
-                            final float scrollY = scrollPane.getScrollY();
-                            final int mult = d.isDown() ? 1 : -1;
-                            scrollPane.setScrollY(scrollY + mult * textActor.getHeight());
-                            return true;
-                    }
-                    throw new IllegalStateException(
-                            "Unmatched " + YMoveKind.class.getSimpleName() + ": " + d);
-                }
-            }
-
-            @Override
-            public boolean keyTyped(InputEvent event, char character) {
-                if (vimShortcuts && (character == 'j' || character == 'k'))
-                    return true;
-                else
-                    return super.keyTyped(event, character);
-            }
-
-            private void handleArrow(boolean up) {
-                final float scrollY = scrollPane.getScrollY();
-                final int mult = up ? -1 : 1;
-                scrollPane.setScrollY(scrollY + (scrollPane.getHeight() * 0.8f * mult));
-            }
-        });
-    }
-
-    /**
-	 * @param m
-	 *            The markup to use.
-	 */
-	public void setMarkup(IMarkup<T> m) {
-		if (font != null)
-			font.getData().markupEnabled |= true;
-		this.markup = m;
-	}
-
-	/**
-	 * Sets the font to use. This method should be called once before
-	 * {@link #init(float, float, Collection)} if the font wasn't given at
-	 * creation-time.
-	 * 
-	 * @param font
-	 *            The font to use.
-	 */
-	public void setFont(BitmapFont font) {
-		this.font = font;
-        tcf = new TextCellFactory().font(font).height(MathUtils.ceil(font.getLineHeight()))
-                .width(MathUtils.round(font.getSpaceWidth()));
-		if (markup != null)
-			font.getData().markupEnabled |= true;
-	}
-
-	/**
-	 * This method sets the sizes of {@link #scrollPane} and {@link #textActor}.
-	 * This method MUST be called before rendering.
-	 * 
-	 * @param maxHeight
-	 *            The maximum height that the scrollpane can take (equal or
-	 *            smaller than the height of the text actor).
-	 * @param width
-	 *            The width of the scrollpane and the text actor.
-	 * @param text
-	 */
-	public void init(float width, float maxHeight, Collection<? extends IColoredString<T>> text) {
-        this.text = new ArrayList<>(text);
-
-        scrollPane.setWidth(width);
-        textActor.setWidth(width);
-
-        if (tcf == null)
-            throw new NullPointerException(
-                    "The font should be set before calling " + TextPanel.class.getSimpleName() + "::init");
-
-        final BitmapFontCache cache = font.getCache();
-        final List<String> toDisplay = getTypesetText();
-        float totalTextHeight = tcf.height();
-        GlyphLayout layout = cache.addText(builder, 0, 0, 0, builder.length(), width, Align.left, true);
-        totalTextHeight += layout.height;
-        if(totalTextHeight < 0)
-            totalTextHeight = 0;
-		textActor.setHeight(/* Entire height */ totalTextHeight);
-		final boolean yscroll = maxHeight < totalTextHeight;
-		scrollPane.setHeight(/* Maybe not the entire height */ Math.min(totalTextHeight, maxHeight));
-        scrollPane.setWidget(new TextActor());
-		yScrollingCallback(yscroll);
-	}
-
-    public void init(float width, float maxHeight, T color, String... text)
-    {
-        ArrayList<IColoredString.Impl<T>> coll = new ArrayList<>(text.length);
-        for(String t : text)
-        {
-            coll.add(new IColoredString.Impl<T>(t, color));
-        }
-        init(width, maxHeight, coll);
-    }
-
-	/**
-	 * Draws the border. You have to call this method manually, because the
-	 * border is outside the actor and hence should be drawn at the very end,
-	 * otherwise it can get overwritten by UI element.
-	 * 
-	 * @param batch
-	 */
-	public void drawBorder(Batch batch) {
-		if (borderColor != null && 0 < borderSize) {
-			final boolean reset = batch.isDrawing();
-			if (reset)
-				batch.end();
-
-			final ShapeRenderer sr = getRenderer();
-			final Matrix4 m = batch.getTransformMatrix();
-			sr.setTransformMatrix(m);
-			sr.begin(ShapeType.Filled);
-			sr.setColor(borderColor);
-			UIUtil.drawMarginsAround(sr, scrollPane.getX(), scrollPane.getY(), scrollPane.getWidth(),
-					scrollPane.getHeight() - 1, borderSize, borderColor, borderStyle, 1f, 1f);
-			sr.end();
-
-			if (reset)
-				batch.begin();
-		}
-	}
-
-	/**
-	 * @return The text to draw, after applying {@link #present(IColoredString)}
-	 *         and {@link #applyMarkup(IColoredString)}.
-	 */
-	public /* @Nullable */ List<String> getTypesetText() {
-		if (text == null)
-			return null;
-        builder.delete(0, builder.length());
-		final List<String> result = new ArrayList<>();
-		for (IColoredString<T> line : text) {
-			/* This code must be consistent with #draw in the custom Actor */
-			final IColoredString<T> tmp = present(line);
-            final String marked = applyMarkup(tmp);
-			result.add(marked);
-            builder.append(marked);
-            builder.append('\n');
-		}
-        if(builder.length() > 0)
-            builder.deleteCharAt(builder.length() - 1);
-		return result;
-	}
-
-	/**
-	 * @return The {@link ScrollPane} containing {@link #getTextActor()}.
-	 */
-	public ScrollPane getScrollPane() {
-		return scrollPane;
-	}
-
-	/**
-	 * @return The {@link Actor} where the text is drawn. It may be bigger than
-	 *         {@link #getScrollPane()}.
-	 */
-	public Actor getTextActor() {
-		return textActor;
-	}
-
-	/**
-	 * @return The font used, if set.
-	 */
-	public /* @Nullable */ BitmapFont getFont() {
-		return font;
-	}
-
-	public void dispose() {
-		if (renderer != null)
-			renderer.dispose();
-	}
-
-	/**
-	 * Callback done to do stuff according to whether y-scrolling is required
-	 * 
-	 * @param required
-	 *            Whether y scrolling is required.
-	 */
-	protected void yScrollingCallback(boolean required) {
-		if (required) {
-			/* Disable borders, they don't mix well with scrollbars */
-			borderSize = 0;
-			scrollPane.setFadeScrollBars(false);
-			scrollPane.setForceScroll(false, true);
-		}
-	}
-
-	/**
-	 * @param ics
-	 *            Text set when building {@code this}
-	 * @return The text to display to screen. If you wanna
-	 *         {@link squidpony.IColorCenter#filter(IColoredString) filter} your
-	 *         text , do it here.
-	 */
-	protected IColoredString<T> present(IColoredString<T> ics) {
-		return ics;
-	}
-
-	/**
-	 * @param ics
-	 * @return The text obtained after applying {@link #markup}.
-	 */
-	protected String applyMarkup(IColoredString<T> ics) {
-		return markup == null ? ics.toString() : ics.presentWithMarkup(markup);
-	}
-
-	/**
-	 * @return A fresh renderer.
-	 */
-	protected ShapeRenderer buildRenderer() {
-		return new ShapeRenderer();
-	}
-
-	/**
-	 * @return The renderer to use.
-	 */
-	protected ShapeRenderer getRenderer() {
-		if (renderer == null)
-			renderer = buildRenderer();
-		return renderer;
-	}
-
-    private class TextActor extends Actor
-    {
-        TextActor()
-        {
-
-        }
-        @Override
-        public void draw(Batch batch, float parentAlpha) {
-
-            final float tx = 0;//getX();
-            final float ty = 0;//getY();
-            final float twidth = getWidth();
-            final float theight = getHeight();
-
-            final float height = scrollPane.getHeight();
-
-            if (backgroundColor != null) {
-                batch.setColor(backgroundColor);
-                batch.draw(tcf.getSolid(), tx, ty, twidth, theight);
-                batch.setColor(Color.WHITE);
-                /*
-                batch.end();
-
-                final Matrix4 m = batch.getTransformMatrix();
-                final ShapeRenderer sr = getRenderer();
-                sr.setTransformMatrix(m);
-                sr.begin(ShapeType.Filled);
-                sr.setColor(backgroundColor);
-                UIUtil.drawRectangle(renderer, tx, ty, twidth, theight, ShapeType.Filled,
-                        backgroundColor);
-                sr.end();
-
-                batch.begin();
-                */
-            }
-
-            if (font == null)
-                throw new NullPointerException(
-                        "The font should be set when drawing a " + getClass().getSimpleName());
-            if (text == null)
-                throw new NullPointerException(
-                        "The text should be set when drawing a " + getClass().getSimpleName());
-            if (tcf != null) {
-                tcf.configureShader(batch);
-            }
-            float yscroll = scrollPane.getScrollY();
-
-            final float destx = tx, offY = (tcf != null) ? tcf.height * 0.5f : 0;
-            getTypesetText();
-            font.draw(batch, builder, destx, theight + yscroll - offY,
-                    0, builder.length(), twidth, Align.left, true);
-
-        }
-    }
-
-}