Component_TextRenderer Class
A text-renderer component allow to draw plain or formatted text on a
game object's bitmap. For formatted text, different text-codes can be
used to add formatting or define a placeholder.
A text-code uses the following syntax:
{code:value} <- Single Value
{code:value1,value2,...} <- Multiple Values
Example:
"This is {Y:I}a Text{Y:N}" <- "a Text" will be italic here.
"The value is {GN:1}" <- "{GN:1}" will be replaced for the value of the global number variable 0001.
For a list of all available text-codes with examples, just take a look into the offical help-file.
Item Index
Methods
- calculateLines
- createListToken
- createToken
- drawControlToken
- drawFormattedLines
- drawFormattedText
- drawText
- executeWordWrap
- findToken
- findTokensBetween
- getRubyTextFont
- measureControlToken
- measureFormattedLines
- measureFormattedText
- measureText
- processControlToken
- wordWrapJapanese
- wordWrapNone
- wordWrapSpaceBased
Properties
Methods
calculateLines
-
message
-
wordWrap
-
[firstLineWidth=0]
Creates an a of line-objects. Each line-object is a list of token-objects. A token-object can be just a string or an object containing more information about how to process the token at runtime.
A line-object also contains additional information like the width and height of the line(in pixels).
If the wordWrap param is set, line-breaks are automatically created if a line doesn't fit into the width of the game object's bitmap.
Parameters:
-
message
String- A message creating the line-objects for.
-
wordWrap
Boolean- If wordWrap is set to true, line-breaks are automatically created.
-
[firstLineWidth=0]
Number optional- The current width of the first line.
Returns:
An array of line-objects.
createListToken
-
list
-
values
Creates the token-object for a list-placeholder. A list-placeholder allows to insert a value from a list-variable.
Parameters:
-
list
Array- The list.
-
values
Array- The values of the list-placeholder text-code.
Returns:
The token-object.
createToken
-
code
-
value
Creates a token-object for a specified text-code.
Parameters:
-
code
String- The code/type of the text-code.
-
value
String- The value of the text-code.
Returns:
The token-object.
drawControlToken
-
token
-
bitmap
-
offset
Draws the visual result of a token, like an icon for example, to the specified bitmap. This method is called for every token while the text is rendered.
Parameters:
-
token
Object- A control-token.
-
bitmap
gs.Bitmap- The bitmap used for the current text-line. Can be used to draw something on it like an icon, etc.
-
offset
Number- An x-offset for the draw-routine.
drawFormattedLines
-
pl
-
pt
-
pr
-
pb
-
lines
-
wordWrap
Draws an array of formatted text lines. If the wordWrap param is set, line-breaks are automatically created if a line doesn't fit into the width of the game object's bitmap.
Parameters:
-
pl
Number- The left-padding of the text's position.
-
pt
Number- The top-padding of the text's position.
-
pr
Number- The right-padding of the text's position.
-
pb
Number- The bottom-padding of the text's position.
-
lines
gs.RendererTextLine- An array of lines to draw.
-
wordWrap
Boolean- If wordWrap is set to true, line-breaks are automatically created.
drawFormattedText
-
x
-
y
-
width
-
height
-
text
-
wordWrap
Draws a formatted text. If the wordWrap param is set, line-breaks are automatically created if a line doesn't fit into the width of the game object's bitmap.
Parameters:
-
x
Number- The x-coordinate of the text's position.
-
y
Number- The y-coordinate of the text's position.
-
width
Number- Deprecated. Can be null.
-
height
Number- Deprecated. Can be null.
-
text
String- The text to draw.
-
wordWrap
Boolean- If wordWrap is set to true, line-breaks are automatically created.
Returns:
The drawn text lines.
drawText
-
x
-
y
-
width
-
height
-
text
Draws a plain text. Formatting and word-wrapping are not supported.
Parameters:
-
x
Number- The x-coordinate of the text's position.
-
y
Number- The y-coordinate of the text's position.
-
width
Number- Deprecated. Can be null.
-
height
Number- Deprecated. Can be null.
-
text
String- The text to draw.
executeWordWrap
-
token
-
line
-
width
-
height
-
-
Splits up the specified token using a word-wrap technique. The kind of word-wrap technique depends on the selected language. You can overwrite this method in derived classes to implement your own custom word-wrap techniques.
Parameters:
-
token
Object- The token to split up.
-
line
gs.RendererTextLine- The current line.
-
width
Number- The width of the current line.
-
height
Number- The height of the current line.
-
-
gs.RendererTextLineAn array of lines. If the token is split up into multiple lines, all new lines are added to this result array.
Returns:
The current line, that may be the same as the line parameters but if new lines are created it has to be the last new created line.
findToken
-
startIndex
-
code
-
direction
-
tokens
Searches for a token in a list of tokens and returns the first match.
Parameters:
-
startIndex
Number- The index in the list of tokens where the search will start.
-
code
String- The code of the token to search for.
-
direction
Number- The search direction, can be forward(1) or backward(-1).
-
tokens
Object- The list of tokens to search.
findTokensBetween
-
startIndex
-
endIndex
-
code
-
tokens
Searches for a specific kind of tokens between a start and an end token.
Parameters:
-
startIndex
Number- The index where the search will start.
-
endIndex
Number- The index where the search will end.
-
code
String- The code of the token-type to search for.
-
tokens
Object- The list of tokens to search.
getRubyTextFont
-
token
Gets the correct font for the specified ruby-text token.
Parameters:
-
token
Object- A ruby-text token.
Returns:
The font for the ruby-text which is shown above the original text.
measureControlToken
-
token
Measures a control-token. If a token produces a visual result like displaying an icon then it must return the size taken by the visual result. If the token has no visual result, null must be returned. This method is called for every token when the message is initialized.
Parameters:
-
token
Object- A control-token.
Returns:
The size of the area taken by the visual result of the token or null if the token has no visual result.
measureFormattedLines
-
lines
-
wordWrap
Measures the dimensions of formatted lines in pixels. The result is not pixel-perfect.
Parameters:
-
lines
gs.RendererTextLine- An array of text lines to measure.
-
wordWrap
Boolean- If wordWrap is set to true, automatically created line-breaks will be calculated.
measureFormattedText
-
text
-
wordWrap
Measures the dimensions of a formatted text in pixels. The result is not pixel-perfect.
Parameters:
-
text
String- The text to measure.
-
wordWrap
Boolean- If wordWrap is set to true, automatically created line-breaks will be calculated.
measureText
-
text
Measures the dimensions of a plain text in pixels. Formatting and word-wrapping are not supported.
Parameters:
-
text
String- The text to measure.
processControlToken
-
token
Processes a control-token. A control-token is a token which influences the text-rendering like changing the fonts color, size or style.
Changes will be automatically applied to the game object's font.
Parameters:
-
token
Object- A control-token.
Returns:
An object which can contain additional info needed for processing.
wordWrapJapanese
-
token
-
line
-
width
-
height
-
-
Splits up the specified token using a japanese word-wrap technique.
Parameters:
-
token
Object- The token to split up.
-
line
gs.RendererTextLine- The current line.
-
width
Number- The width of the current line.
-
height
Number- The height of the current line.
-
-
gs.RendererTextLineAn array of lines. If the token is split up into multiple lines, all new lines are added to this result array.
Returns:
The current line, that may be the same as the line parameters but if new lines are created it has to be the last new created line.
wordWrapNone
-
token
-
line
-
width
-
height
-
-
Does not word-wrapping at all. It just adds the text token to the line as is.
Parameters:
-
token
Object- The token to split up.
-
line
gs.RendererTextLine- The current line.
-
width
Number- The width of the current line.
-
height
Number- The height of the current line.
-
-
gs.RendererTextLineAn array of lines. If the token is split up into multiple lines, all new lines are added to this result array.
Returns:
The current line, that may be the same as the line parameters but if new lines are created it has to be the last new created line.
wordWrapSpaceBased
-
token
-
line
-
width
-
height
-
-
Splits up the specified token using a space-based word-wrap technique.
Parameters:
-
token
Object- The token to split up.
-
line
gs.RendererTextLine- The current line.
-
width
Number- The width of the current line.
-
height
Number- The height of the current line.
-
-
gs.RendererTextLineAn array of lines. If the token is split up into multiple lines, all new lines are added to this result array.
Returns:
The current line, that may be the same as the line parameters but if new lines are created it has to be the last new created line.
Properties
currentLineHeight
Number
protected
currentX
Number
protected
currentY
Number
protected
font
gs.Font
protected
fontSize
Number
protected
lineSpacing
Number
The spacing between text lines in pixels.
padding
Number
The left and right padding per line.