Table of Contents

Class Code

Namespace
MLEM.Formatting.Codes
Assembly
MLEM.dll

An instance of a formatting code that can be used for a TextFormatter. To add a new formatting code, see Codes

public class Code : GenericDataHolder, IGenericDataHolder
Inheritance
Code
Implements
Derived
Inherited Members

Constructors

Code(Match, Regex)

Creates a new formatting code based on a formatting code regex and its match.

protected Code(Match match, Regex regex)

Parameters

match Match

The match

regex Regex

The regex

Fields

Match

The match that this code encompasses

public readonly Match Match

Field Value

Match

Regex

The regex that this code was created from

public readonly Regex Regex

Field Value

Regex

Tokens

The tokens that this formatting code is a part of. Note that this collection only has multiple entries if additional tokens have to be started while this code is still applied.

public readonly List<Token> Tokens

Field Value

List<Token>

Methods

DrawCharacter(GameTime, SpriteBatch, int, string, Token, int, Vector2, ref Vector2, GenericFont, ref Color, ref Vector2, ref float, ref Vector2, float, SpriteEffects, Vector2, Vector2)

Draws a given code point using this token's formatting options.

public virtual bool DrawCharacter(GameTime time, SpriteBatch batch, int codePoint, string character, Token token, int indexInToken, Vector2 stringPos, ref Vector2 charPosOffset, GenericFont font, ref Color color, ref Vector2 scale, ref float rotation, ref 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

token Token
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.

Returns

bool

DrawSelf(GameTime, SpriteBatch, Token, 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 virtual void DrawSelf(GameTime time, SpriteBatch batch, Token token, 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

token Token
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.

EndsHere(Code)

Returns whether this formatting code should end when the passed formatting code starts. If this method returns true, a new Token is started at its position. This is the opposite version of EndsOther(Code).

public virtual bool EndsHere(Code other)

Parameters

other Code

The code that is started here.

Returns

bool

If this code should end here.

EndsOther(Code)

Returns whether the other Code should end when this formatting code starts. If this method returns true, a new Token is started at this code's position. This is the opposite version of EndsHere(Code).

public virtual bool EndsOther(Code other)

Parameters

other Code

The code that could end here.

Returns

bool

Whether the other code should end here.

GetColor(Color)

Get the color that this token will be rendered with

public virtual 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 virtual 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 virtual float GetSelfWidth(GenericFont font)

Parameters

font GenericFont

The font to use for calculating the width.

Returns

float

The width of this token itself.

Update(GameTime)

Update this formatting code's animations etc.

public virtual void Update(GameTime time)

Parameters

time GameTime

The game's time