Table of Contents

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

int

RawIndex

The index in the RawSubstring that this token starts at.

public readonly int RawIndex

Field Value

int

RawSubstring

The substring that this token contains, without the formatting codes removed.

public readonly string RawSubstring

Field Value

string

Substring

The substring that this token contains.

public readonly string Substring

Field Value

string

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

string

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

time GameTime

The time

batch SpriteBatch

The sprite batch to use

codePoint int

The code point of the character to draw

character string

The string representation of the character to draw

indexInToken int

The index within this token that the character is at

stringPos Vector2

The position the string is drawn at.

charPosOffset Vector2

The offset from the stringPos that the current character is drawn at.

font GenericFont

The font to use to draw

color Color

The color to draw with

scale Vector2

The scale to draw with.

rotation float

The rotation to draw with.

origin Vector2

The origin to subtract from the position.

depth float

The depth to draw at

effects SpriteEffects

The flipping to draw with.

stringSize Vector2

The size of the string.

charSize Vector2

The 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

time GameTime

The time

batch SpriteBatch

The sprite batch to use

stringPos Vector2

The position the string is drawn at.

charPosOffset Vector2

The offset from the stringPos that the current character is drawn at.

font GenericFont

The font to use to draw

color Color

The color to draw with

scale Vector2

The scale to draw with.

rotation float

The rotation to draw with.

origin Vector2

The origin to subtract from the position.

depth float

The depth to draw at

effects SpriteEffects

The flipping to draw with.

stringSize Vector2

The 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

stringPos Vector2

The position that the string is drawn at

scale Vector2

The 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

stringPos Vector2

The position that the string is drawn at

scale float

The 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

defaultPick Color

The 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

defaultPick GenericFont

The 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

font GenericFont

The font to use for calculating the width.

Returns

float

The width of this token itself.