public class GDXMarkup
extends java.lang.Object
implements squidpony.panel.IMarkup<com.badlogic.gdx.graphics.Color>
instance
would be passed to a class that uses
IMarkup of Color, and then anything else will be handled internally as Colors are given to the using class. This does
extend GDX's markup to handle bold and italic options for text; this only works if you are using a TextFamily
as your TextCellFactory
, such as DefaultResources.getSlabFamily()
, and only if you use
colorString(CharSequence)
or styleString(CharSequence)
to generate a value that can be drawn later.
You can use colorStringOnly(CharSequence)
if you aren't using a TextFamily; it ignores bold and italic style
tags and removes them from the IColoredString it returns, but otherwise colors and case-adjusts text as tags say.
[#FF00FF]Magenta text here[]
, which starts a tag for a hex color, uses the hex value for bright magenta,
then contains the text "Magenta text here" which will be shown in bright magenta, followed by "[]" to change the
color (and style, see next) back to the default white (and normal style). You can also use the names of colors, as
defined in the documentation for every SColor
, and some libGDX Color values as well; this looks like
[Inside Of A Bottle]Gray text[]
to produce the words "Gray text" with the color
SColor.INSIDE_OF_A_BOTTLE
(note that the docs for that SColor say what the precise name is, and case needs to
match; you can also look up the SColor.name
field). Another option for colors is to use hue, saturation,
value, and optionally opacity as 3 or 4 floats, in that order; this looks like [@ 0 0.7 0.96]
(hue,
saturation, and value, with opacity implicitly 1) or [@ 0 0.7 0.96 0.8]
(0.8 opacity is a bit translucent).
The HSV markup option is an addition to libGDX's syntax; any number of spaces/tabs can be used between HSV components
and the space between @ and the first component is optional. You can use [[
to escape an opening bracket, and
[]
to reset formatting. As an addition to GDX color markup, you can change case with [!]
to make text
ALL CAPS or [=]
to make it lower-case (encountering a tag toggles it, so [!]yelling[!] are we?
would
become YELLING are we?
), using []
to reset all markup or [,]
to reset just case and font
style (see next) markup. If using a TextFamily such as DefaultResources.getLeanFamily()
, you can toggle the
font style as bold with [*]
and as italic with [/]
. If bold is on when this encounters another bold
tag, it will turn bold off; the same is true for italic. These formatting styles can overlap and do not need to be
nested as in HTML; this notation is valid: [*]bold, [/]bold and italic, [*] just italic,[] plain
. While
[]
resets both color, case, and style to white color, normal case, and regular style, there is also
[,]
to reset only style/case, or [WHITE]
to reset only color (to white).
Constructor and Description |
---|
GDXMarkup() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
closeMarkup() |
squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color> |
colorString(java.lang.CharSequence markupString)
Takes a CharSequence (such as a String or StringBuilder) that contains the markup this class understands, and
produces an IColoredString (of Color) with the color markup tags used to mark text in colors in the resulting
IColoredString, and any style markup tags used to mark sections of text as bold or italic for a TextFamily to
render (normal TextCellFactory rendering may show bold/italic text as gibberish).
|
java.lang.StringBuilder |
colorStringMarkup(java.lang.CharSequence markupString)
Takes a CharSequence (such as a String or StringBuilder) that contains the markup this class understands, and
produces a StringBuilder with the color markup tags in
markupString all changed to libGDX-usable color
markup, and any style markup tags used to mark sections of text as bold or italic for a TextFamily to
render (normal TextCellFactory rendering may show bold/italic text as gibberish). |
squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color> |
colorStringOnly(java.lang.CharSequence markupString)
Takes a CharSequence (such as a String or StringBuilder) that contains the markup this class understands, and
produces an IColoredString (of Color) with the color markup tags used to mark text in colors in the resulting
IColoredString, but with both bold and italic style markup tags ignored (so normal TextCellFactory objects can
render the text correctly).
|
java.lang.StringBuilder |
colorStringOnlyMarkup(java.lang.CharSequence markupString)
Takes a CharSequence (such as a String or StringBuilder) that contains the markup this class understands, and
produces a StringBuilder with the color markup tags in
markupString all changed to libGDX-usable color
markup, but with both bold and italic style markup tags ignored (so normal TextCellFactory objects can
render the text correctly). |
java.lang.String |
getMarkup(com.badlogic.gdx.graphics.Color value) |
java.lang.StringBuilder |
removeMarkup(java.lang.CharSequence markupString)
Removes all SquidLib and libGDX markup from the given
markupString except for [[ to escape a left
bracket, returning the result as a new StringBuilder. |
char |
styleChar(char basis,
boolean bold,
boolean italic)
Directly styles one char value, toggling its bold state if
bold is true, and toggling its italic state if
italic is true. |
java.lang.StringBuilder |
styleString(java.lang.CharSequence markupString)
Similar to
colorString(CharSequence) , but leaves color tags as they are and only uses case and style
tags, like [*] for bold, [/] for italic, [!] for ALL CAPS and [=] for lower-case. |
char |
unstyleChar(char styled)
If given a char that has added style information for bold/italic modes (colors aren't stored in char data), this
removes the bold/italic data and makes the char what it will be rendered as in a normal font (not a special
TextFamily, which renders later sections of Unicode as bold and/or italic).
|
public static GDXMarkup instance
public java.lang.String getMarkup(com.badlogic.gdx.graphics.Color value)
getMarkup
in interface squidpony.panel.IMarkup<com.badlogic.gdx.graphics.Color>
public java.lang.String closeMarkup()
closeMarkup
in interface squidpony.panel.IMarkup<com.badlogic.gdx.graphics.Color>
public java.lang.StringBuilder removeMarkup(java.lang.CharSequence markupString)
markupString
except for [[
to escape a left
bracket, returning the result as a new StringBuilder.markupString
- a String or other CharSequence containing color and/or style markup tagspublic squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color> colorString(java.lang.CharSequence markupString)
markupString
- a String or other CharSequence containing color and/or style markup tagspublic squidpony.panel.IColoredString<com.badlogic.gdx.graphics.Color> colorStringOnly(java.lang.CharSequence markupString)
markupString
- a String or other CharSequence containing color and/or case markup tagspublic java.lang.StringBuilder styleString(java.lang.CharSequence markupString)
colorString(CharSequence)
, but leaves color tags as they are and only uses case and style
tags, like [*]
for bold, [/]
for italic, [!]
for ALL CAPS and [=]
for lower-case.
The StringBuilder this returns can be converted to a String or used directly for further modification, but styles
will probably only render correctly if using a TextFamily. You should be aware that if []
is used to
reset both color and style in the given markupString, then only the style will be reset here but the []
will be removed, which may affect colors if the result is later given to something that expects color markup to
also have been closed. A solution for this is to use [,]
to reset only styles, and to avoid using
[]
to change color by explicitly using [WHITE]
to set the text color back to pure white. This way
is only necessary if you have color markup in the markupString you pass to this method.markupString
- a String containing color markup (which is left as-is) and/or case/style markup (which is used)public char styleChar(char basis, boolean bold, boolean italic)
bold
is true, and toggling its italic state if
italic
is true. When either or both of bold or italic are enabled in a char, that char will be at some
unrelated section of Unicode, and the char will be hard to identify unless you call unstyleChar(char)
on
it or render it with a TextFamily (which will render bold and italic chars as the correct glyph and style).basis
- the char to potentially make bold or italic; can be bold or italic alreadybold
- if true, the bold-ness of basis will be toggled; if false, does not change bold dataitalic
- if true, the italic-ness of basis will be toggled; if false, does not change italic datapublic char unstyleChar(char styled)
styled
- a char that should have any bold or italic data set to normal (non-bold, non-italic)public java.lang.StringBuilder colorStringMarkup(java.lang.CharSequence markupString)
markupString
all changed to libGDX-usable color
markup, and any style markup tags used to mark sections of text as bold or italic for a TextFamily to
render (normal TextCellFactory rendering may show bold/italic text as gibberish). This needs markup to be enabled
on any BitmapFont that renders it, by setting
BitmapFont.BitmapFontData.markupEnabled
to true.markupString
- a String or other CharSequence containing color and/or style markup tagspublic java.lang.StringBuilder colorStringOnlyMarkup(java.lang.CharSequence markupString)
markupString
all changed to libGDX-usable color
markup, but with both bold and italic style markup tags ignored (so normal TextCellFactory objects can
render the text correctly). Case markup is still used as in other methods here, and all markup tags that libGDX
can't use, including those for bold and italic styles, will be removed (so you don't need to manually remove
styles that can't be shown by a TextCellFactory). This needs markup to be enabled on any BitmapFont that renders
it, by setting BitmapFont.BitmapFontData.markupEnabled
to true.markupString
- a String or other CharSequence containing color and/or case markup tags (style markup will be removed)Copyright © Eben Howard 2012–2022. All rights reserved.