Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
VText Class Reference

Object that renders text. More...

#include <VText.h>

Inheritance diagram for VText:
VObject VBase VTextPath VTypedText

Public Types

enum  VTextAlign : unsigned char { ALIGNLEFT = 0, ALIGNCENTER = 1, ALIGNCENTRE = 1, ALIGNRIGHT = 2 }
 Propertry for aligning the text within the text box.
 
enum  VTextWrap : unsigned char { WRAPNONE = 0, WRAPLETTER = 1, WRAPWORD = 2 }
 Property for the method of wrapping the text when it reaches the edge of the box.
 
typedef VObject VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 
- Public Types inherited from VObject
enum  SidesTouching : unsigned char {
  TOUCHNONE = 0, TOUCHLEFT = 1 << 0, TOUCHRIGHT = 1 << 1, TOUCHTOP = 1 << 2,
  TOUCHBOTTOM = 1 << 3, TOUCHWALL = TOUCHLEFT | TOUCHRIGHT, TOUCHALL = TOUCHLEFT | TOUCHRIGHT | TOUCHTOP | TOUCHBOTTOM
}
 Flags for which sides are allowed to check if being overlapped for collision purposes.
 
typedef VBase VSUPERCLASS
 Used to call parent class functions when they are overrided in class.
 

Public Member Functions

 VText (float x=0, float y=0, float width=0, const sf::String &text="", int charSize=8)
 
 VText (sf::Vector2f position, float width=0, const sf::String &text="", int charSize=8)
 
VTextSetFormat (const sf::String &filename, int charSize=8, sf::Color colour=sf::Color::White, VTextAlign alignment=VTextAlign::ALIGNLEFT, int style=sf::Text::Regular)
 
VTextSetFormat (sf::Font &fontData, int charSize=8, sf::Color colour=sf::Color::White, VTextAlign alignment=VTextAlign::ALIGNLEFT, int style=sf::Text::Regular)
 
void SetText (const sf::String &text)
 
void SetStyle (int style=sf::Text::Regular)
 
void SetFillTint (const sf::Color &colour)
 
void SetOutlineTint (const sf::Color &colour)
 
void SetFontSize (unsigned int size)
 
void SetWrap (const VTextWrap &wrapMode)
 
void SetLineSpaceModifier (int lineSpacing)
 
void SetAlignment (const VTextAlign &align)
 
void SetOutlineThickness (float thickness)
 
void SetOutlineOffset (const sf::Vector2f &offset)
 
void SetTextWidth (float width)
 
const sf::String & GetText ()
 
const int GetLength ()
 
unsigned int GetStyle ()
 
sf::Color const & GetFillTint ()
 
sf::Color const & GetOutlineTint ()
 
unsigned int GetFontSize ()
 
VTextWrap const & GetWrap ()
 
int GetLineSpaceModifier ()
 
VTextAlign const & GetAlignment ()
 
float GetOutlineThickness ()
 
sf::Vector2f const & GetOutlineOffset ()
 
float GetTextWidth ()
 
virtual void Destroy () override
 Destroys the text rendering data (and font if disposable is set for true).
 
virtual void Draw (sf::RenderTarget &RenderTarget) override
 
- Public Member Functions inherited from VObject
 VObject (sf::Vector2f position, sf::Vector2f size=sf::Vector2f())
 
 VObject (float x=0, float y=0, float width=0, float height=0)
 
void SetPositionAtCentre (float x, float y)
 
void SetPositionAtCentre (sf::Vector2f newPos)
 
bool IsSolid ()
 
virtual void Reset (sf::Vector2f newPos)
 
virtual void Reset (float x, float y)
 
virtual void Hurt (float damage)
 
virtual void Update (float dt)
 
- Public Member Functions inherited from VBase
virtual void Kill ()
 
virtual void Revive ()
 Revives the object by setting both alive and exists back to true.
 

Public Attributes

sf::RenderStates RenderState = sf::RenderStates::Default
 RenderState for the vertex data.
 
sf::Vector2f Origin
 Origin point as percentage.
 
sf::Vector2f Scale = sf::Vector2f(1, 1)
 Scale transform.
 
- Public Attributes inherited from VObject
sf::Vector2f Position
 Position of the object.
 
sf::Vector2f Size
 Size of the object.
 
sf::Vector2f Last
 Position of the object on the previous frame.
 
float Radius = 0
 Radius amount for Circle Collisions.
 
float Angle = 0
 Angle of object.
 
float AngleVelocity = 0
 Velocity of rotation.
 
float AngleAcceleration = 0
 Acceleration of rotation.
 
float AngleDrag = 0
 Drag of rotation.
 
float AngleMax = 10000
 Maximum Velocity of rotation.
 
bool Moves = true
 If true, updates the objects position and angle.
 
sf::Vector2f Velocity
 Velocity of movement.
 
sf::Vector2f Acceleration
 Acceleration of movement.
 
sf::Vector2f Drag
 Drag of movement.
 
sf::Vector2f MaxVelocity
 Maximum velocity of movement.
 
sf::Vector2f ScrollFactor
 The amount the object will appear to move when the camera scrolls (1.0f = Scrolls as fast as the camera, 0.5f = Scrolls half as fast as the camera). Good for parallax scrolling.
 
float RotateFactor = 1
 The amount the object will appear to rotate when the camera rotates (1.0f = Rotates as fast as the camera, 0.5f = Rotates half as fast as the camera). Good for parallax scrolling.
 
float ZoomFactor = 1
 The amount the object will appear to scale when the camera zooms (1.0f = Scales as fast as the camera, 0.5f = Scales half as fast as the camera). Good for parallax scrolling.
 
float Elasticity = 0
 Bounciness of the object (0 assumes no bounce)
 
float Mass = 1
 Mass of object in comparison to other objects in world.
 
float Health = 100
 Standard health value (object dies if health is <= 0 when modified in the Hurt function)
 
bool Immovable = false
 If true, the object will not change its velocity on collision.
 
unsigned char Touching = SidesTouching::TOUCHNONE
 Which sides are currently touching (is reset on each Update call!)
 
unsigned char WasTouching = SidesTouching::TOUCHNONE
 Which sides on previous frame were touching (is reset on each Update call!)
 
unsigned char AllowCollisions = SidesTouching::TOUCHALL
 Which sides are allowed to check collisions for.
 
bool CollisionXDrag = true
 Useful for moving platforms.
 
- Public Attributes inherited from VBase
bool active = true
 Base can be updated using Update if true.
 
bool visible = true
 Base can be rendered using Draw if true.
 
bool alive = true
 Helper member that is mainly used filter out behaviours to objects which aren't alive in the scene.
 
bool exists = true
 Base can be updated and rendered if true, else it would no longer be treated as being part of the scene.
 
VType type = NONE
 Base object type, typically set in the constructor of an inherited object to specify what type it is.
 
uint32_t RefCount = 0
 Counts the amount of times the object is referenced in groups, ensures an object is only destroyed when no longer part of a single group.
 

Protected Member Functions

virtual void updateTextRender (const sf::String &text)
 
virtual void updateTransform () override
 Update the transformable object.
 
void setDimensions ()
 Setup the string of text so that it fits within the text width.
 
void setCharacterRender (const sf::Glyph &glyph, float x, float y, sf::Color color, bool bold, float italic, int index, sf::VertexArray &vertices, float outline=0)
 
void setTextLine (float x, float y, sf::Color color, float offset, float thickness, int index, sf::VertexArray &vertices, float outline=0)
 
- Protected Member Functions inherited from VObject
virtual void updateMotion (float dt)
 

Protected Attributes

sf::VertexArray vertices
 Vertex Data.
 
sf::Font * font = nullptr
 Font object.
 
sf::String text
 String of text that will be rendered.
 
int length = 0
 Current length of text.
 
unsigned int fontSize = 8
 Size of the text per character.
 
unsigned int style = sf::Text::Regular
 Flags for setting a text's display style.
 
VTextWrap wrap = WRAPWORD
 Text wrapping mode.
 
int lineSpaceModifier = 0
 Used for adjusting the distance between lines different to the default.
 
VTextAlign alignment = ALIGNLEFT
 Text alignment property.
 
float outlineThickness = 0.0f
 The thickness of the outline.
 
sf::Vector2f outlineOffset
 The position offset of the outline. Good to modify if you want to display the outline like a shadow.
 
bool dirty = false
 If true, the text vertex data is rebuilt for all the new properties.
 
bool disposible = false
 If true, the font is disposed by the Text object (in case the font isn't loaded from VContent).
 
sf::Vector2f origin
 Origin point for rotation.
 
sf::Color fillColour = sf::Color::White
 Main colour of the font.
 
sf::Color outlineColour = sf::Color::White
 Colour of the font outline.
 

Additional Inherited Members

- Static Public Member Functions inherited from VObject
static bool separate (VObject *a, VObject *b)
 
static bool separateCircle (VObject *a, VObject *b)
 
static bool touchFlag (VObject *a, VObject *b)
 
static float computeVelocity (float v, float a, float d, float max, float dt)
 
static bool TestInView (const sf::View &renderTargetView, sf::View *defaultView, VObject *o, const sf::FloatRect &renderBox=sf::FloatRect())
 
- Static Public Member Functions inherited from VBase
static const wchar_t * VString (const char *fmt,...)
 
static void VLog (const char *fmt,...)
 
static void VLogError (const char *fmt,...)
 
static void VClearLog ()
 
- Static Public Attributes inherited from VObject
static float SeparateBias
 Adds to the maximum overlap distance between objects.
 

Detailed Description

Object that renders text.

Constructor & Destructor Documentation

◆ VText() [1/2]

VText::VText ( float  x = 0,
float  y = 0,
float  width = 0,
const sf::String &  text = "",
int  charSize = 8 
)
Parameters
xX position coordinate.
yY position coordinate.
widthThe width of the text area that will bound the text.
textThe string that the text object will display.
charSizeThe font size the text will be displayed at.

◆ VText() [2/2]

VText::VText ( sf::Vector2f  position,
float  width = 0,
const sf::String &  text = "",
int  charSize = 8 
)
Parameters
positionPosition coordinates.
widthThe width of the text area that will bound the text.
textThe string that the text object will display.
charSizeThe font size the text will be displayed at.

Member Function Documentation

◆ Draw()

virtual void VText::Draw ( sf::RenderTarget &  RenderTarget)
overridevirtual

Renders the text.

Parameters
RenderTargetThe game's sf::RenderTarget object to render data onto.

Reimplemented from VObject.

◆ GetAlignment()

VTextAlign const& VText::GetAlignment ( )
inline
Returns
Text alignment property.

◆ GetFillTint()

sf::Color const& VText::GetFillTint ( )
inline
Returns
The main text colour.

◆ GetFontSize()

unsigned int VText::GetFontSize ( )
inline
Returns
Size of the text per character.

◆ GetLength()

const int VText::GetLength ( )
inline
Returns
The current length of the string that is being rendered.

◆ GetLineSpaceModifier()

int VText::GetLineSpaceModifier ( )
inline
Returns
Used for adjusting the distance between lines different to the default.

◆ GetOutlineOffset()

sf::Vector2f const& VText::GetOutlineOffset ( )
inline
Returns
The position offset of the outline. Good to modify if you want to display the outline like a shadow.

◆ GetOutlineThickness()

float VText::GetOutlineThickness ( )
inline
Returns
The thickness of the outline.

◆ GetOutlineTint()

sf::Color const& VText::GetOutlineTint ( )
inline
Returns
The colour of the text outline.

◆ GetStyle()

unsigned int VText::GetStyle ( )
inline
Returns
Flags for setting a text's display style.

◆ GetText()

const sf::String& VText::GetText ( )
inline
Returns
The text that will be rendered.

◆ GetTextWidth()

float VText::GetTextWidth ( )
Returns
The maximum width area of text to display on. (Use this over the Size property to update the text rendering)

◆ GetWrap()

VTextWrap const& VText::GetWrap ( )
inline
Returns
Text wrapping mode.

◆ SetAlignment()

void VText::SetAlignment ( const VTextAlign align)
Parameters
alignText alignment property.

◆ setCharacterRender()

void VText::setCharacterRender ( const sf::Glyph &  glyph,
float  x,
float  y,
sf::Color  color,
bool  bold,
float  italic,
int  index,
sf::VertexArray &  vertices,
float  outline = 0 
)
protected

Sets the render infomation for a single character.

Parameters
glyphThe character texture infomation taken directly from the font.
xThe X Coordinate the character will be displayed in.
yThe Y Coordinate the character will be displayed in.
colorColour Tint of the character to display.
boldIf true, the bold version of the character will be displayed.
italicIf true, the rendered vertices will be set so the character will be rendered in italics.
indexThe first index position in the vertex array to set the character. Six vertex indices will be used for a single character.
verticesThe vertex array data to render the text into.
outlineThe outline thickness, used to setup the outline version of the character.

◆ SetFillTint()

void VText::SetFillTint ( const sf::Color &  colour)
Parameters
colourThe main colour of the text.

◆ SetFontSize()

void VText::SetFontSize ( unsigned int  size)
Parameters
sizeSize of the text per character.

◆ SetFormat() [1/2]

VText* VText::SetFormat ( const sf::String &  filename,
int  charSize = 8,
sf::Color  colour = sf::Color::White,
VTextAlign  alignment = VTextAlign::ALIGNLEFT,
int  style = sf::Text::Regular 
)

Sets up the main format of how the text will be rendered.

Parameters
filenameFont file path and name.
charSizeSize of the text.
colourFill colour of the text.
alignmentHow the text will be anchored line by line within the text area.
styleText font styles (i.e. bold, italic, strikethrough, ect).

◆ SetFormat() [2/2]

VText* VText::SetFormat ( sf::Font &  fontData,
int  charSize = 8,
sf::Color  colour = sf::Color::White,
VTextAlign  alignment = VTextAlign::ALIGNLEFT,
int  style = sf::Text::Regular 
)

Sets up the main format of how the text will be rendered.

Parameters
fontDatasf::Font object.
charSizeSize of the text.
colourFill colour of the text.
alignmentHow the text will be anchored line by line within the text area.
styleText font styles (i.e. bold, italic, strikethrough, ect).

◆ SetLineSpaceModifier()

void VText::SetLineSpaceModifier ( int  lineSpacing)
Parameters
lineSpacingUsed for adjusting the distance between lines different to the default.

◆ SetOutlineOffset()

void VText::SetOutlineOffset ( const sf::Vector2f &  offset)
Parameters
offsetThe position offset of the outline. Good to modify if you want to display the outline like a shadow.

◆ SetOutlineThickness()

void VText::SetOutlineThickness ( float  thickness)
Parameters
thicknessThe thickness of the outline.

◆ SetOutlineTint()

void VText::SetOutlineTint ( const sf::Color &  colour)
Parameters
colourThe text outline (requires OutlineThickness to be greater than 0).

◆ SetStyle()

void VText::SetStyle ( int  style = sf::Text::Regular)
Parameters
styleFont styles flags (i.e. Bold, Italic, Strikethrough, ect).

◆ SetText()

void VText::SetText ( const sf::String &  text)
Parameters
textsf::String of text that will be rendered.

◆ setTextLine()

void VText::setTextLine ( float  x,
float  y,
sf::Color  color,
float  offset,
float  thickness,
int  index,
sf::VertexArray &  vertices,
float  outline = 0 
)
protected

Sets the render infomation for a single line, for displaying strikethroughs and underlines.

Parameters
xThe X Coordinate the line will be displayed in.
yThe Y Coordinate the line will be displayed in.
colorColour Tint of the character to display.
offsetY offset the line will be diplayed at.
thicknessThe thickness of the line.
indexThe first index position in the vertex array to set the character. Six vertex indices will be used for a single character.
verticesThe vertex array data to render the text into.
outlineThe outline thickness, used to setup the outline version of the character.

◆ SetTextWidth()

void VText::SetTextWidth ( float  width)
Parameters
widthThe maximum width area of text to display on. (Use this over the Size property to update the text rendering)

◆ SetWrap()

void VText::SetWrap ( const VTextWrap wrapMode)
Parameters
wrapModeText wrapping mode.

◆ updateTextRender()

virtual void VText::updateTextRender ( const sf::String &  text)
protectedvirtual

Update the vertex data to display text and outline.

Parameters
textThe string that will be used for displaying text.

Reimplemented in VTextPath.


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