Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F96943
Text.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
Text.h
View Options
#ifndef _ECHOTEXT_H_
#define _ECHOTEXT_H_
#include
<echo/Graphics/SceneEntity.h>
#include
<echo/Graphics/Font.h>
#include
<echo/UTF8String.h>
#include
"Mesh.h"
namespace
Echo
{
class
Texture
;
class
Mesh
;
class
MeshManager
;
/**
* A SceneRenderable that builds and renders a text mesh in a given font.
*/
class
Text
:
public
SceneEntity
{
public
:
/**
* Default constructor.
* You need to use SetFont() and Set() to set the font and content respectively.
*/
Text
();
/**
* Constructor
* @param content UTF8 content.
* @param font The font to use.
*/
Text
(
const
UTF8String
&
content
,
shared_ptr
<
Font
>
font
);
/**
* Constructor to allow you to specify mesh resource parameters.
* When constructing a Text object with this constructor you can specify a mesh manager, resource name
* and group, which will be used to create a Mesh object. This allows other objects to access the mesh
* via MeshManager::GetResource().
* You need to use SetFont() and Set() to set the font and content respectively.
*/
Text
(
MeshManager
&
meshManager
,
const
std
::
string
resourceName
);
~
Text
();
/**
* Set the font.
* This marks the mesh as out of date which causes the mesh to be rebuilt on the next render (if UpdateMesh()
* has not already been called).
* @note You need to make sure the font contains all of the characters for your content otherwise those characters won't be rendered.
* @param font the Font object, use the FontManager to acquire a font resource.
*/
void
SetFont
(
shared_ptr
<
Font
>
font
);
/**
* Set the text content.
* @note You need to make sure the font contains all of the characters for your content otherwise those characters won't be rendered.
* @param content UTF8String to build a mesh for, You can use ASCII strings (see UTF8String).
*/
void
Set
(
const
UTF8String
&
content
);
/**
* Append to the existing content content.
* @see Set();
*/
void
Append
(
const
UTF8String
&
content
);
/**
* Clears and builds a new mesh of the given content
* @param mString
*/
void
BuildMesh
(
const
UTF8String
&
utf8String
);
/**
* Get the dimensions of the text mesh.
* The dimensions returned are the actual mesh size determined when it is built.
* The X component is the width.
* The Y component is the height.
* @return
*/
const
Vector3
&
GetTextDimensions
()
const
;
/**
* Calls BuildMesh() passing in the internal content string.
*/
void
UpdateMesh
();
/**
* Override from SceneRenderable.
*/
virtual
AxisAlignedBox
GetLocalAxisAlignedBox
(
bool
applyLocalTransform
=
true
);
/**
* Override from SceneRenderable.
* When called, will automatically update the mesh if the mesh is out of date.
*/
void
Render
(
const
Matrix4
&
transform
,
RenderTarget
&
renderTarget
);
/**
* Set the colour of the text.
* @note This modifies the material.
* @param colour
*/
void
SetColour
(
const
Colour
&
colour
);
/**
* Get the colour of the text.
* @return the colour.
*/
const
Colour
&
GetColour
()
const
{
return
mColour
;}
/**
* Set the maximum width the text can be.
* The default value for this is 100, which is just arbitrary and intended to give
* some dimension so that you will see something rather than something scaled to 0.
* @see SetUseMaxWidth() for more information.
* @param maxWidth
*/
void
SetMaxWidth
(
f32
maxWidth
);
/**
* Get the max width.
* @see SetUseMaxWidth() for more information.
* @return
*/
const
f32
&
GetMaxWidth
()
const
{
return
mMaxWidth
;}
/**
* Set whether or not to enforce max text width.
* This is enforced per word. If the word plus the current line length will exceed
* the max width the text will be moved to the next line. If a word is longer than
* the max width then scaling to the word will be applied to make it fit.
* @param useMaxWidth
*/
void
SetUseMaxWidth
(
bool
useMaxWidth
);
/**
* Get whether or not to use the max width option.
* @see SetUseMaxWidth() for more information on this feature.
* @return
*/
const
bool
&
GetUseMaxWidth
()
const
{
return
mUseMaxWidth
;}
/**
* Set the text scale.
* This scale is applied to the text while building the mesh.
* @param textScale
*/
void
SetTextScale
(
f32
textScale
);
/**
* Get the text scale.
* @see SetTextScale();
* @return
*/
const
f32
&
GetTextScale
()
const
{
return
mTextScale
;}
/**
* Set the fixed line spacing.
* The value passed in is a multiplier. The font's maximum character height is used
* to determine the line height.
* You need to turn on fixed line spacing with SetUseFixedLineSpacing(). If fixed line spacing is
* not used then words that need to be scaled to fit in the fixed width will be positioned with
* respect to a scaled line height such that the word will be flush with the previous line.
* @note Fixed line spacing requires that mUseMaxWidth is true.
* @note The default for fixed line spacing is 1.0
* @param fixedLineSpacing value in font height multiples. e.g 1.0 or 1.5.
*/
void
SetFixedLineSpacing
(
f32
fixedLineSpacing
);
/**
* Get the fixed line spacing value.
* @return
*/
const
f32
&
GetFixedLineSpacing
()
const
{
return
mFixedLineSpacing
;}
/**
* Set whether or not to use fixed line spacing.
* @see SetFixedLineSpacing();
* @note Fixed line spacing is disabled by default.
* @param useFixedLineSpacing
*/
void
SetUseFixedLineSpacing
(
bool
useFixedLineSpacing
);
/**
* Get whether or not fixed line spacing will be used.
* @see SetFixedLineSpacing();
*/
const
bool
&
GetUseFixedLineSpacing
()
const
{
return
mUseFixedLineSpacing
;}
private
:
shared_ptr
<
Font
>
mFont
;
UTF8String
mString
;
Vector3
mDimensions
;
f32
mSpaceWidth
;
f32
mTextScale
;
f32
mMaxWidth
;
f32
mFixedLineSpacing
;
bool
mUseFixedLineSpacing
;
bool
mUseMaxWidth
;
bool
mMeshOutOfDate
;
Colour
mColour
;
void
AddWordToMesh
(
Vector2
position
,
const
UTF8String
&
word
,
f32
scale
);
void
AddCharacterToMesh
(
const
Vector2
&
position
,
const
Glyph
&
glyph
,
f32
scale
);
};
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Dec 5, 2:08 AM (7 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
61880
Default Alt Text
Text.h (6 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment