Otter  0.9.88
2d Game Development Framework based on SFML.Net
 All Classes Namespaces Functions Variables Enumerations Properties
Otter.RichText Class Reference

Graphic that renders text with some more options than normal Text. RichText can be very slow to render with large strings of text so be careful! For large blocks of text use the normal Text graphic. More...

Inherits Otter.Graphic.

Public Member Functions

 RichText (string str, string font="", int size=16, int textWidth=-1, int textHeight=-1)
 Create a new RichText object. More...
 
 RichText (string str, Stream font, int size=16, int textWidth=-1, int textHeight=-1)
 Create a new RichText object. More...
 
 RichText (string str, BaseFont font, int size=16, int textWidth=-1, int textHeight=-1)
 
 RichText (string str, RichTextConfig config, int textWidth=-1, int textHeight=-1)
 Create a new RichText object using a RichTextConfig. More...
 
 RichText (string str, int size)
 Create a new RichText object. More...
 
 RichText (int size=16)
 Create a new RichText object. More...
 
 RichText (RichTextConfig config)
 Create a new RichText object More...
 
void CenterTextOrigin ()
 Center the RichText's origin. This factors in the RichText's local bounds. More...
 
void CenterTextOriginY ()
 Center the RichText's Y origin. This factors in the RichText's top bounds. More...
 
void CenterTextOriginX ()
 Center the RichText's X origin. This factors in the RichText's left bounds. More...
 
override void CenterOrigin ()
 Centers the graphic origin. More...
 
string PreWrap (string str)
 Insert new lines into a string to prepare it for word wrapping with this object's width. This function will not wrap text if AutoWidth is true! More...
 
int GetLineWidth (int lineNumber)
 The line width in pixels of a specific line. More...
 
void Refresh ()
 Refresh the text. This will reapply all commands and update the text image. More...
 
override void Update ()
 Update the RichText. More...
 
GetFont< T > ()
 Gets the font. More...
 
- Public Member Functions inherited from Otter.Graphic
Transformation AddTransform (Transformation transform)
 
Transformation AddTransform (Vector2 translation, Vector2 scale, Vector2 origin, float rotation)
 
Transformation AddTransform ()
 
Transformation RemoveTransformation (Transformation transform)
 
Transformation PopTransformation ()
 
virtual void ClearShader ()
 Removes the shader from the graphic. More...
 
void SetPosition (float x, float y)
 Set the position of the Graphic. More...
 
void SetPosition (Graphic g, float offsetX=0, float offsetY=0)
 Set the position of the Graphic. More...
 
void SetPosition (Vector2 xy)
 Set the position of the Graphic. More...
 
void SetOrigin (float x, float y)
 Set the origin of the Graphic. More...
 
void SetOrigin (Vector2 xy)
 Set the origin of the Graphic. More...
 
void SetTexture (string path)
 Set the Texture that the Graphic is using (if it is using one.) More...
 
void SetTexture (Texture texture)
 Set the Texture that the Graphic is using (if it is using one.) More...
 
void SetTexture (AtlasTexture atlasTexture)
 Set the Texture that the Graphic is using (if it is using one.) More...
 
virtual void CenterOriginZero ()
 Centers the graphic origin while retaining its relative position. More...
 
virtual void Render (float x=0, float y=0)
 Draws the graphic. More...
 

Static Public Member Functions

static void AddStyle (string name, string content)
 Add a global style to RichText objects. The style will not be updated unless Refresh() is called on the objects. More...
 
static void RemoveStyle (string name)
 Removes a style from all RichText objects. More...
 
static void ClearStyles ()
 Remove all styles from RichText objects. More...
 

Public Attributes

TextAlign TextAlign = TextAlign.Left
 The alignment of the text. Left, Right, or Center. More...
 
char CommandOpen = '{'
 The character used to mark an opening of a command. More...
 
char CommandClose = '}'
 The character used to mark the closing of a command. More...
 
char CommandDelim = ':'
 The character used to separate the command with the command value. More...
 
int MonospaceWidth = -1
 Controls the spacing between each character. If set above 0 the text will use a monospacing. More...
 
float DefaultSineAmpX
 The default horizontal amplitude of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultSineAmpY
 The default vertical amplitude of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultSineRateX = 1
 The default horizontal rate of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultSineRateY = 1
 The default vertical rate of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultSineOffsetX
 The default horizontal offset of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultSineOffsetY
 The default vertical offset of the sine wave. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultOffsetAmount = 10
 The default amount to offset each character for sine wave related transformations. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultShadowX
 The default X position of the text shadow. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultShadowY
 The default Y position of the text shadow. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultOutlineThickness
 The default outline thickness. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultShakeX
 The default horizontal shaking effect. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultShakeY
 The default vertical shaking effect. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultCharColor = Color.White
 The default character color. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultCharColor0 = Color.White
 The default color of the top left corner of each character. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultCharColor1 = Color.White
 The default color of the top right corner of each character. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultCharColor2 = Color.White
 The default color of the bottom right corner of each character. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultCharColor3 = Color.White
 The default color of the bottom left corner of each character. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultShadowColor = Color.Black
 The default shadow color. Will not take effect until the string changes, or Refresh() is called. More...
 
Color DefaultOutlineColor = Color.White
 The default outline color. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultScaleX = 1
 The default x scale of the characters. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultScaleY = 1
 The default y scale of the characters. Will not take effect until the string changes, or Refresh() is called. More...
 
float DefaultAngle = 0
 The default angle of the characters. Will not take effect until the string changes, or Refresh() is called. More...
 
float LineHeight = 1
 The line height. 1 is 100% of the normal line height for the font. More...
 
float LetterSpacing = 1
 The letter spacing. 1 is 100% of the normal letter spacing. More...
 
float OffsetX
 How far to offset the text rendering horizontally from the origin. More...
 
float OffsetY
 How far to offset the text rendering vertically from the origin. More...
 
- Public Attributes inherited from Otter.Graphic
List< TransformationTransforms = new List<Transformation>() { new Transformation() }
 
bool Relative = true
 Determines if the Graphic is rendered relative to its Entity. More...
 
bool Visible = true
 Determines if the Graphic will render. More...
 
float ScrollX = 1
 The scroll factor for the x position. Used for parallax like effects. Values lower than 1 will scroll slower than the camera (appear to be further away) and values higher than 1 will scroll faster than the camera (appear to be closer.) More...
 
float ScrollY = 1
 The scroll factor for the y position. Used for parallax like effects. Values lower than 1 will scroll slower than the camera (appear to be further away) and values higher than 1 will scroll faster than the camera (appear to be closer.) More...
 
float ShakeX
 The horizontal amount to randomly offset the graphic by each frame. More...
 
float ShakeY
 The vertial amount to randomly offset the graphic by each frame. More...
 
Rectangle TextureRegion
 The region to render the Texture with. More...
 
Rectangle AtlasRegion
 The Rectangle to render an AtlasTexture with. More...
 
Shader Shader
 The shader to be applied to this graphic. More...
 
string Name = "Graphic"
 The name of the graphic. More...
 
BlendMode Blend = BlendMode.Alpha
 The blend mode to be applied to this graphic. More...
 
bool RepeatX
 Determines if the image should be rendered multiple times horizontally. More...
 
bool RepeatY
 Determines if the image should be rendered multiple times vertically. More...
 

Static Public Attributes

static RichTextConfig Default = new RichTextConfig()
 The default config. More...
 

Protected Member Functions

override void UpdateDrawable ()
 Updates the internal SFML data for rendering. More...
 
- Protected Member Functions inherited from Otter.Graphic
void Append (float x, float y, Color color, float u, float v)
 
void Append (float x, float y, Color color=null)
 
virtual void SFMLRender (Drawable drawable, float x=0, float y=0)
 

Properties

bool Monospaced [get]
 True if the text is using MonospaceWidth. More...
 
int TextWidth [get, set]
 The width of the text box. If not set it will be automatically set. More...
 
int TextHeight [get, set]
 The height of the text box. If not set it will be automatically set. More...
 
float LineSpacing [get]
 The line spacing between each vertical line. More...
 
bool WordWrap [get, set]
 Determines if the text will automatically wrap. This will not work unless TextWidth is set. More...
 
int FontSize [get, set]
 The font size of the text. More...
 
bool AutoWidth [get]
 True of the width was not manually set. More...
 
bool AutoHeight [get]
 True if the height was not manually set. More...
 
string CleanString [get]
 The string to display stripped of all commands. More...
 
int LongestLine [get]
 The pixel width of the longest line in the displayed string. More...
 
string[] Lines [get, set]
 The displayed string broken up into an array by lines. More...
 
int NumLines [get]
 The total number of lines in the displayed string. More...
 
string String [get, set]
 The string to display. This string can contain commands to alter the text dynamically. More...
 
float BoundsTop [get]
 The top bounds of the RichText. More...
 
float BoundsLeft [get]
 The top bounds of the RichText. More...
 
RichTextCharacter this[int index] [get, set]
 Retrieve the RichTextCharacter from the string. More...
 
- Properties inherited from Otter.Graphic
Transformation Transform [get]
 
float X [get, set]
 The X position of the Graphic. More...
 
float Y [get, set]
 The Y position of the Graphic. More...
 
float ScaleX [get, set]
 The horizontal scale of the graphic. Used in the final transformation. More...
 
float ScaleY [get, set]
 The vertical scale of the graphic. Used in the final transformation. More...
 
float Angle [get, set]
 The angle of rotation of the graphic. Used in the final transformation. More...
 
float OriginX [get, set]
 The X origin point to scale and rotate the graphic with. Used in the final transformation. More...
 
float OriginY [get, set]
 The Y origin point to scale and rotate the graphic with. Used in the final transformation. More...
 
Color Color [get, set]
 The base color of the Graphic. Multiplies the vertices of the graphic by this color. More...
 
virtual Texture Texture [get, set]
 The texture that the graphic is using. More...
 
float Alpha [get, set]
 The base transparency of the graphic. A shortcut to access the base color's Alpha. More...
 
int Width [get, set]
 The width of the Graphic. More...
 
int Height [get, set]
 The height of the Graphic. More...
 
float ScaledWidth [get, set]
 The width in pixels of the image after applying the X scale. More...
 
float ScaledHeight [get, set]
 The height in pixels of the image after applying the Y scale. More...
 
virtual bool Smooth [get, set]
 Smooth the texture of a sprite image while scaling it. More...
 
float Scroll [get, set]
 Set both ScrollX and ScrollY. More...
 
float HalfWidth [get]
 Half of the width. More...
 
float HalfHeight [get]
 Half of the height. More...
 
float Scale [set]
 Sets both the ScaleX and ScaleY at the same time. More...
 
bool Repeat [set]
 Sets both RepeatX and RepeatY at the same time. More...
 
float Shake [set]
 A shortcut to set both ShakeX and ShakeY. More...
 
float Left [get]
 The X position of the left side of the Graphic. More...
 
float Top [get]
 The Y position of the top of the Graphic. More...
 
float Right [get]
 The X position of the right side of the Graphic. More...
 
float Bottom [get]
 The Y position of the bottom of the Graphic. More...
 
int TextureLeft [get]
 The X position of the left of the Texture. More...
 
int TextureRight [get]
 The X position of the right of the Texture. More...
 
int TextureTop [get]
 The Y position of the top of the Texture. More...
 
int TextureBottom [get]
 The Y position of the bottom of the Texture. More...
 

Additional Inherited Members

- Protected Attributes inherited from Otter.Graphic
VertexArray SFMLVertices = new VertexArray(PrimitiveType.Quads)
 
Drawable SFMLDrawable
 
float RepeatSizeX
 
bool roundRendering = true
 
bool Dynamic
 If true the graphic will always update its drawable. More...
 

Detailed Description

Graphic that renders text with some more options than normal Text. RichText can be very slow to render with large strings of text so be careful! For large blocks of text use the normal Text graphic.

richText.String = "Hello, {color:f00}this text is red!{clear} {shake:4}Shaking text!"; Commands: {clear} - Clear all styles and reset back to normal, white text. {style:name} - Apply the style 'name' to text. Create styles with AddStyle(). {color:fff} - Colors text. Strings of 3, 4, 6, or 8 hex digits allowed. {color0:fff} - Colors the top left corner of characters. Strings of 3, 4, 6, or 8 hex digits allowed. {color1:fff} - Colors the top right corner of characters. Strings of 3, 4, 6, or 8 hex digits allowed. {color2:fff} - Colors the bottom right corner of characters. Strings of 3, 4, 6, or 8 hex digits allowed. {color3:fff} - Colors the bottom left corner of characters. Strings of 3, 4, 6, or 8 hex digits allowed. {colorShadow:fff} - Colors text shadow. Strings of 3, 4, 6, or 8 hex digits allowed. {colorOutline:fff} - Colors text outline. Strings of 3, 4, 6, or 8 hex digits allowed. {shadowX:0} - Set the drop shadow of the text on the X axis. {shadowY:0} - Set the drop shadow of the text on the Y axis. {shadow:0} - Set the drop shadow of the text on the X and Y axes. {outline:0} - Set the outline thickness on text. {shakeX:0} - Shake the text on the X axis with a float range. {shakeY:0} - Shake the text on the Y axis with a float range. {shake:0} - Shake the text on the X and Y axes with a float range. {waveAmpX:0} - Wave the text on the X axis with a float range. {waveAmpY:0} - Wave the text on the Y axis with a float range. {waveAmp:0} - Wave the text on the X and Y axes with a float range. {waveRateX:0} - Set the wave speed for the X axis. {waveRateY:0} - Set the wave speed for the Y axis. {waveRate:0} - Set the wave speed for the X and Y axes. {waveOffsetX:0} - Set the wave offset for the X axis. {waveOffsetY:0} - Set the wave offset for the Y axis. {waveOffset:0} - Set the wave offset for the X and Y axes. {offset:0} - Set the offset rate for characters. {charOffsetX:0} - Set the character offset X for the BitmapFont. {charOffsetY:0} - Set the character offset Y for the BitmapFont.

Constructor & Destructor Documentation

Otter.RichText.RichText ( string  str,
string  font = "",
int  size = 16,
int  textWidth = -1,
int  textHeight = -1 
)

Create a new RichText object.

Parameters
strThe string to display. This can include commands to alter text.
fontThe file path to the font to use.
sizeThe font size to use.
textWidthThe width of the text box.
textHeightThe height of the text box.
Otter.RichText.RichText ( string  str,
Stream  font,
int  size = 16,
int  textWidth = -1,
int  textHeight = -1 
)

Create a new RichText object.

Parameters
strThe string to display. This can include commands to alter text.
fontThe stream of the font to use.
sizeThe font size to use.
textWidthThe width of the text box.
textHeightThe height of the text box.
Otter.RichText.RichText ( string  str,
RichTextConfig  config,
int  textWidth = -1,
int  textHeight = -1 
)

Create a new RichText object using a RichTextConfig.

Parameters
strThe starting default text.
configThe config to set all the default style values.
textWidthThe width of the text box.
textHeightThe height of the text box.
Otter.RichText.RichText ( string  str,
int  size 
)

Create a new RichText object.

Parameters
strThe string to display.
sizeThe size of the font.
Otter.RichText.RichText ( int  size = 16)

Create a new RichText object.

Parameters
sizeThe size of the font.
Otter.RichText.RichText ( RichTextConfig  config)

Create a new RichText object

Parameters
configThe RichTextConfig to use.

Member Function Documentation

static void Otter.RichText.AddStyle ( string  name,
string  content 
)
static

Add a global style to RichText objects. The style will not be updated unless Refresh() is called on the objects.

RichText.AddStyle("important","color:f00,waveAmpY:2,waveRate:2");

Parameters
nameThe name of the style.
contentThe properties to set using commas as a delim character.
override void Otter.RichText.CenterOrigin ( )
virtual

Centers the graphic origin.

Reimplemented from Otter.Graphic.

void Otter.RichText.CenterTextOrigin ( )

Center the RichText's origin. This factors in the RichText's local bounds.

void Otter.RichText.CenterTextOriginX ( )

Center the RichText's X origin. This factors in the RichText's left bounds.

void Otter.RichText.CenterTextOriginY ( )

Center the RichText's Y origin. This factors in the RichText's top bounds.

static void Otter.RichText.ClearStyles ( )
static

Remove all styles from RichText objects.

T Otter.RichText.GetFont< T > ( )

Gets the font.

Template Parameters
TThe specific type of Font.
Returns
The font as type font type T.
Type Constraints
T :BaseFont 
int Otter.RichText.GetLineWidth ( int  lineNumber)

The line width in pixels of a specific line.

Parameters
lineNumberThe line number to check.
Returns
The length of the line in pixels.
string Otter.RichText.PreWrap ( string  str)

Insert new lines into a string to prepare it for word wrapping with this object's width. This function will not wrap text if AutoWidth is true!

Parameters
strThe string to wrap.
Returns
The wrapped string.
void Otter.RichText.Refresh ( )

Refresh the text. This will reapply all commands and update the text image.

static void Otter.RichText.RemoveStyle ( string  name)
static

Removes a style from all RichText objects.

Parameters
nameThe name of the style to remove.
override void Otter.RichText.Update ( )
virtual

Update the RichText.

Reimplemented from Otter.Graphic.

override void Otter.RichText.UpdateDrawable ( )
protectedvirtual

Updates the internal SFML data for rendering.

Reimplemented from Otter.Graphic.

Member Data Documentation

char Otter.RichText.CommandClose = '}'

The character used to mark the closing of a command.

char Otter.RichText.CommandDelim = ':'

The character used to separate the command with the command value.

char Otter.RichText.CommandOpen = '{'

The character used to mark an opening of a command.

RichTextConfig Otter.RichText.Default = new RichTextConfig()
static

The default config.

float Otter.RichText.DefaultAngle = 0

The default angle of the characters. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultCharColor = Color.White

The default character color. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultCharColor0 = Color.White

The default color of the top left corner of each character. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultCharColor1 = Color.White

The default color of the top right corner of each character. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultCharColor2 = Color.White

The default color of the bottom right corner of each character. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultCharColor3 = Color.White

The default color of the bottom left corner of each character. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultOffsetAmount = 10

The default amount to offset each character for sine wave related transformations. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultOutlineColor = Color.White

The default outline color. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultOutlineThickness

The default outline thickness. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultScaleX = 1

The default x scale of the characters. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultScaleY = 1

The default y scale of the characters. Will not take effect until the string changes, or Refresh() is called.

Color Otter.RichText.DefaultShadowColor = Color.Black

The default shadow color. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultShadowX

The default X position of the text shadow. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultShadowY

The default Y position of the text shadow. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultShakeX

The default horizontal shaking effect. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultShakeY

The default vertical shaking effect. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineAmpX

The default horizontal amplitude of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineAmpY

The default vertical amplitude of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineOffsetX

The default horizontal offset of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineOffsetY

The default vertical offset of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineRateX = 1

The default horizontal rate of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.DefaultSineRateY = 1

The default vertical rate of the sine wave. Will not take effect until the string changes, or Refresh() is called.

float Otter.RichText.LetterSpacing = 1

The letter spacing. 1 is 100% of the normal letter spacing.

float Otter.RichText.LineHeight = 1

The line height. 1 is 100% of the normal line height for the font.

int Otter.RichText.MonospaceWidth = -1

Controls the spacing between each character. If set above 0 the text will use a monospacing.

float Otter.RichText.OffsetX

How far to offset the text rendering horizontally from the origin.

float Otter.RichText.OffsetY

How far to offset the text rendering vertically from the origin.

TextAlign Otter.RichText.TextAlign = TextAlign.Left

The alignment of the text. Left, Right, or Center.

Property Documentation

bool Otter.RichText.AutoHeight
get

True if the height was not manually set.

bool Otter.RichText.AutoWidth
get

True of the width was not manually set.

float Otter.RichText.BoundsLeft
get

The top bounds of the RichText.

float Otter.RichText.BoundsTop
get

The top bounds of the RichText.

string Otter.RichText.CleanString
get

The string to display stripped of all commands.

int Otter.RichText.FontSize
getset

The font size of the text.

string [] Otter.RichText.Lines
getset

The displayed string broken up into an array by lines.

float Otter.RichText.LineSpacing
get

The line spacing between each vertical line.

int Otter.RichText.LongestLine
get

The pixel width of the longest line in the displayed string.

bool Otter.RichText.Monospaced
get

True if the text is using MonospaceWidth.

int Otter.RichText.NumLines
get

The total number of lines in the displayed string.

string Otter.RichText.String
getset

The string to display. This string can contain commands to alter the text dynamically.

int Otter.RichText.TextHeight
getset

The height of the text box. If not set it will be automatically set.

int Otter.RichText.TextWidth
getset

The width of the text box. If not set it will be automatically set.

RichTextCharacter Otter.RichText.this[int index]
getset

Retrieve the RichTextCharacter from the string.

Parameters
indexThe index of the character.
Returns
The RichTextCharacter at that index in the RichText string.
bool Otter.RichText.WordWrap
getset

Determines if the text will automatically wrap. This will not work unless TextWidth is set.


The documentation for this class was generated from the following file: