Class Token
- Namespace
- MLEM.Formatting
- Assembly
- MLEM.dll
A part of a TokenizedString that has a certain list of formatting codes applied.
public class Token : GenericDataHolder, IGenericDataHolder
- Inheritance
-
Token
- Implements
- Inherited Members
Fields
AppliedCodes
The formatting codes that are applied on this token. Codes are stored application order, with the first entry in the array being the code that was most recently applied.
public readonly Code[] AppliedCodes
Field Value
- Code[]
Index
The index in the Substring that this token starts at.
public readonly int Index
Field Value
RawIndex
The index in the RawSubstring that this token starts at.
public readonly int RawIndex
Field Value
RawSubstring
The substring that this token contains, without the formatting codes removed.
public readonly string RawSubstring
Field Value
Substring
The substring that this token contains.
public readonly string Substring
Field Value
Properties
DisplayString
The string that is displayed by this token. If the tokenized string has been Split(GenericFont, float, float, TextAlignment) or Truncate(GenericFont, float, float, string, TextAlignment) has been used, this string will contain the newline characters.
public string DisplayString { get; }
Property Value
SplitDisplayString
The DisplayString, but split at newline characters
public string[] SplitDisplayString { get; }
Property Value
- string[]
Methods
DrawCharacter(GameTime, SpriteBatch, int, string, int, Vector2, Vector2, GenericFont, Color, Vector2, float, Vector2, float, SpriteEffects, Vector2, Vector2)
Draws a given code point using this token's formatting options.
public void DrawCharacter(GameTime time, SpriteBatch batch, int codePoint, string character, int indexInToken, Vector2 stringPos, Vector2 charPosOffset, GenericFont font, Color color, Vector2 scale, float rotation, Vector2 origin, float depth, SpriteEffects effects, Vector2 stringSize, Vector2 charSize)
Parameters
timeGameTimeThe time
batchSpriteBatchThe sprite batch to use
codePointintThe code point of the character to draw
characterstringThe string representation of the character to draw
indexInTokenintThe index within this token that the character is at
stringPosVector2The position the string is drawn at.
charPosOffsetVector2The offset from the
stringPosthat the current character is drawn at.fontGenericFontThe font to use to draw
colorColorThe color to draw with
scaleVector2The scale to draw with.
rotationfloatThe rotation to draw with.
originVector2The origin to subtract from the position.
depthfloatThe depth to draw at
effectsSpriteEffectsThe flipping to draw with.
stringSizeVector2The size of the string.
charSizeVector2The size of the current character.
DrawSelf(GameTime, SpriteBatch, Vector2, Vector2, GenericFont, Color, Vector2, float, Vector2, float, SpriteEffects, Vector2)
Draws the token itself, including all of the Code instances that this token contains. Note that, to draw the token's actual string, DrawCharacter(GameTime, SpriteBatch, int, string, int, Vector2, Vector2, GenericFont, Color, Vector2, float, Vector2, float, SpriteEffects, Vector2, Vector2) is used.
public void DrawSelf(GameTime time, SpriteBatch batch, Vector2 stringPos, Vector2 charPosOffset, GenericFont font, Color color, Vector2 scale, float rotation, Vector2 origin, float depth, SpriteEffects effects, Vector2 stringSize)
Parameters
timeGameTimeThe time
batchSpriteBatchThe sprite batch to use
stringPosVector2The position the string is drawn at.
charPosOffsetVector2The offset from the
stringPosthat the current character is drawn at.fontGenericFontThe font to use to draw
colorColorThe color to draw with
scaleVector2The scale to draw with.
rotationfloatThe rotation to draw with.
originVector2The origin to subtract from the position.
depthfloatThe depth to draw at
effectsSpriteEffectsThe flipping to draw with.
stringSizeVector2The size of the string.
GetArea(Vector2, Vector2)
Gets a list of rectangles that encompass this token's area. This can be used to invoke events when the mouse is hovered over the token, for example.
public IEnumerable<RectangleF> GetArea(Vector2 stringPos, Vector2 scale)
Parameters
stringPosVector2The position that the string is drawn at
scaleVector2The scale that the string is drawn at
Returns
- IEnumerable<RectangleF>
A set of rectangles that this token contains
GetArea(Vector2, float)
Gets a list of rectangles that encompass this token's area. This can be used to invoke events when the mouse is hovered over the token, for example.
public IEnumerable<RectangleF> GetArea(Vector2 stringPos = default, float scale = 1)
Parameters
stringPosVector2The position that the string is drawn at
scalefloatThe scale that the string is drawn at
Returns
- IEnumerable<RectangleF>
A set of rectangles that this token contains
GetColor(Color)
Get the color that this token will be rendered with
public Color GetColor(Color defaultPick)
Parameters
defaultPickColorThe default color, if none is specified
Returns
- Color
The color to render with
GetFont(GenericFont)
Get the font that this token will be rendered with
public GenericFont GetFont(GenericFont defaultPick)
Parameters
defaultPickGenericFontThe default font, if none is specified
Returns
- GenericFont
The font to render with
GetSelfWidth(GenericFont)
Returns the width of the token itself, including all of the Code instances that this token contains. Note that this method does not return the width of this token's DisplayString, but only the width that the codes themselves take up.
public float GetSelfWidth(GenericFont font)
Parameters
fontGenericFontThe font to use for calculating the width.
Returns
- float
The width of this token itself.