resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::Text Class Reference

Run of text drawn as a quad per glyph. More...

#include <text.h>

Inheritance diagram for Rnd::Text:
Collaboration diagram for Rnd::Text:

Public Types

enum  Alignment {
  kTextAlignLeft = 0x01 , kTextAlignCenter = 0x02 , kTextAlignRight = 0x04 , kTextAlignTop = 0x10 ,
  kTextAlignMiddle = 0x20 , kTextAlignBottom = 0x40
}
 Bits of the alignment word. More...
Public Types inherited from Rnd::Transformable
enum  Billboard {
  kBillboardNone = 0 , kBillboardX = 1 , kBillboardY = 2 , kBillboardZ = 4 ,
  kBillboardXZ = 8 , kBillboardXYZ = 16 , kBillboardSimpleXYZ = 32 , kBillboardLocalRotate = 64 ,
  kBillboardScaleX = 129 , kBillboardScaleY = 130 , kBillboardScaleZ = 132 , kBillboardScaleXZ = 136 ,
  kBillboardScaleXYZ = 144 , kBillboardScaleSimpleXYZ = 160
}
 Mode mBillboard selects, recovered from the name dumper at 0x004f26f0. More...

Public Member Functions

 Text (const HxStr &name)
 Construct an empty white text run.
virtual ~Text ()
 Release the glyph mesh and drop the reference on the font.
virtual void SetColor (const Color &color)
 Set the colour of every glyph.
virtual void SetAlign (int nAlign)
 Set which point of the block the origin is.
virtual void SetText (const HxStr &text)
 Replace the text.
virtual void SetFont (Font *pFont)
 Replace the font.
void SetWordWrap (int nWordWrap)
 Set whether long lines are broken at word boundaries.
void SetWrapWidth (float flWrapWidth)
 Set the width a wrapped line is broken at.
void RebuildText ()
 Derive mText from mPreWrapText and rebuild the glyph mesh.
virtual void DumpText (Dbg &sink)
 Write a description of this text run to sink.
virtual void Save (Stream &stream)
 Write this text run to stream at revision 6.
virtual void Replace (Object *pFrom, Object *pTo)
 Retarget the font when it is the object being replaced.
virtual const HxStr & ClassName () const
 Report the class key a .rnd file writes for a text run.
virtual void Copy (const Object *pSource, unsigned nFlags)
 Copy the state of pSource into this text run.
virtual void Load (Stream &stream)
 Read this text run from stream.
virtual void FindCollisions (const Segment &ray, std::list< Collision > &collisions)
 Test a ray against the glyph mesh and append what it strikes to sink.
virtual void SetBillboard (int nBillboard)
 Set the billboard mode of this object and of its glyph mesh.
virtual int UpdateWorldXfm (Transformable *pParent, int nForce)
 Compose the world transform of this object and then of its glyph mesh.
virtual void SetShowing (int nShowing)
 Set whether this object draws at all.
virtual void SetHighlight (int nHighlight)
 Set whether this object draws with its highlight treatment.
Font * GetFont ()
 Report the font the text is set in.
virtual int DrawShowing ()
 Draw the glyph mesh.
float GetFontWidth (const char *pText, int nCount)
 Report the total advance of the first nCount characters of pText in this text's font.
Vector3 CharPosition (int nIndex)
 Report where one glyph of the laid-out text sits.
void GetVerticalBounds (float &flTop, float &flBottom)
 Report the vertical extent of the text block about the origin.
int CountLines ()
 Report the number of lines of mText, one more than its newline count.
Public Member Functions inherited from Rnd::Drawable
 Drawable ()
 Construct a visible drawable with no children.
virtual ~Drawable ()
 Drop this object's references on its children.
void Draw ()
 Draw this object followed by each of its children.
Drawable * Parent ()
 Report the drawable that draws this one.
void AddDraw (Drawable *pDraw, Drawable *pBefore)
 Insert pDraw into mDraws in front of pBefore.
void AddDraw (Drawable *pDraw)
 Insert pDraw at the front of mDraws.
void RemoveDraw (Drawable *pDraw)
 Erase pDraw from mDraws.
void RemoveAllDraws ()
 Empty mDraws, dropping this object's reference on every entry.
void MoveDraw (Drawable *pDraw, int nSteps)
 Move pDraw nSteps places later in mDraws, or earlier for a negative count.
void SetShowingRecursive (int nShowing)
 Set whether this object and every drawable beneath it in mDraws draw at all.
int GetHighlight () const
 Report the highlight flag.
int GetShowing () const
 Report the showing flag.
std::list< Drawable * > & GetDraws ()
 Report the child list.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().
Public Member Functions inherited from Rnd::Collideable
 Collideable ()
 Construct a collideable with no children.
virtual ~Collideable ()
 Drop this object's references on its children.
Collideable * Parent ()
 Report the collideable that hit-tests this one.
void AddCollide (Collideable *pCollide)
 Append pCollide to mCollides.
void RemoveCollide (Collideable *pCollide)
 Erase pCollide from mCollides.
virtual void FindCollisions (const Vector2 &point, std::list< Collision > &collisions)
 Test a screen point against this object and append what it strikes to collisions.
Public Member Functions inherited from Rnd::Transformable
 Transformable ()
 Construct a dirty transformable with identity transforms and no children.
virtual ~Transformable ()
 Drop this object's references on its children.
void AddTrans (Transformable *pTrans)
 Append pTrans to mTransList and mark it dirty.
void RemoveTrans (Transformable *pTrans)
 Erase pTrans from mTransList.
void RemoveAllTranses ()
 Drop this object's reference on every mTransList entry and empty the list.
Transformable * Parent ()
 Report the transformable that positions this one.
void SetOrigin (const float *pOrigin)
 Set the origin row and mark the transform dirty.
float * GetDrawXfm ()
 Build the transform this object draws with and return it.

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a text run under the tag "Rnd::Text".
static void operator delete (void *pBlock)
 Release a text run to the tagged heap.
Static Public Member Functions inherited from Rnd::Drawable
static Drawable * Find (const HxStr &name)
 Resolve a registry key to a drawable.

Public Attributes

float mWrapWidth
 Width a wrapped line is broken at.
HxStr mPreWrapText
 Text as a caller or a file supplied it, before wrapping.
Public Attributes inherited from Rnd::Drawable
int mShowing
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal
Public Attributes inherited from Rnd::Transformable
float mLocalXfm [kXfmRowCount][kXfmRowFloatCount]
 Transform this object is positioned by, before the parent transform is applied.
float mWorldXfm [kXfmRowCount][kXfmRowFloatCount]
 Composed world transform.
int mDirty
 Set by every writer of a transform field and cleared once UpdateWorldXfm has recomposed.

Static Public Attributes

static Text *(* sNew )(const HxStr &name)
 Creator the registered "Text" class builds through.

Additional Inherited Members

Protected Member Functions inherited from Rnd::Drawable
void ReleaseDrawsRefs ()
 Drop this object's reference on every mDraws entry without emptying the list.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.
Protected Member Functions inherited from Rnd::Collideable
void ReleaseCollidesRefs ()
 Drop this object's reference on every mCollides entry without emptying the list.
Protected Member Functions inherited from Rnd::Transformable
void AdoptXfmFrom (const Transformable &owner)
 Adopt the transform of an owner this object is being detached from.
void ReleaseTransRefs ()
 Drop this object's reference on every mTransList entry without emptying the list.
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs
Protected Attributes inherited from Rnd::Transformable
float mOrigin [kXfmRowFloatCount]
int mBillboard

Detailed Description

Run of text drawn as a quad per glyph.

Its RTTI descriptor is at 0x008ef4d0. It has three public non-virtual bases whose offsets the descriptor fixes: Rnd::Drawable at +0x00, Rnd::Collideable at +0x14, and Rnd::Transformable at +0x20. All three derive virtually from Rnd::Object, so one shared Object subobject sits at +0x110, which the constructor proves by writing that address into all three virtual-base pointers.

The class is 0x130 bytes, which the factory at 0x004cf800 pins by requesting exactly that many. The last member ends at 0x12c, and the quadword access to mColor gives the class 16-byte alignment, which accounts for the remaining four bytes. The same alignment accounts for the eight bytes between mZTest and the base subobject, since 0x108 is not a 16-byte boundary and 0x110 is. Neither run is an unrecovered field.

Four vtables belong to the class, laid out back to back and each terminated by an all-zero entry. The three-entry table at 0x00822508 is addressed by the Rnd::Transformable vptr with a -0x20 adjustment, the three-entry table at 0x00822528 by the Rnd::Collideable vptr with a -0x14 adjustment, the eight-entry table at 0x00822548 by the Rnd::Drawable vptr with no adjustment, and the eight-entry table at 0x00822590 by the Object subobject vptr with a -0x110 adjustment. Rnd::Drawable is the primary base, so the four virtuals this class declares of its own occupy slots 4 through 7 of its table.

The member titles come from the text DumpText() writes, "font:", " align:", "preWrapText:", "color:", " word wrap:", " wrap width:", "text:", and "mesh:".

Geometry is built rather than drawn directly. The object owns one Rnd::Mesh whose name is the object's own inside [ and _mesh], has four vertices and two triangles per glyph, and takes its material from the font. Every writer of a field that affects layout ends by rebuilding that mesh, and a Text whose font is not a Material font builds nothing at all.

Wrapping retains two strings. mPreWrapText is what a caller or a file supplied, and mText is the same text with a newline inserted at every wrap point. mText is the string the mesh is built from, and it is derived rather than stored, so only mPreWrapText is serialised.

Member Enumeration Documentation

◆ Alignment

Bits of the alignment word.

The six titles and the six bit values come from the printer at 0x004d0450. The printer tests the three vertical bits first and then the three horizontal ones, writing at most one of each. A word is not required to have one bit from each group.

Enumerator
kTextAlignLeft 

Lines start at the origin.

kTextAlignCenter 

Lines are centred on the origin.

kTextAlignRight 

Lines end at the origin.

kTextAlignTop 

The first line sits at the origin.

kTextAlignMiddle 

The block is centred on the origin.

kTextAlignBottom 

The last line sits at the origin.

Constructor & Destructor Documentation

◆ Text()

Rnd::Text::Text ( const HxStr & name)
explicit

Construct an empty white text run.

The colour starts fully opaque white, the alignment at Top and Left, the wrap width at 100.0, wrapping disabled, and both strings, the font, and the mesh empty.

Parameters
nameThe registry key for this object.
Ghidra address:
NTSC-U/C: 0x004c89c0
Ghidra address:
PAL: 0x00506bc8

◆ ~Text()

virtual Rnd::Text::~Text ( )
virtual

Release the glyph mesh and drop the reference on the font.

Ghidra address:
NTSC-U/C: 0x004cf2b8
Ghidra address:
PAL: 0x0050d618

Member Function Documentation

◆ operator new()

void * Rnd::Text::operator new ( size_t nSize)
static

Allocate a text run under the tag "Rnd::Text".

Parameters
nSizeThe object size the compiler supplies.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x004cf150
Ghidra address:
PAL: 0x0050d4b0

◆ operator delete()

void Rnd::Text::operator delete ( void * pBlock)
static

Release a text run to the tagged heap.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x004cf170
Ghidra address:
PAL: 0x0050d4d0

◆ SetColor()

virtual void Rnd::Text::SetColor ( const Color & color)
virtual

Set the colour of every glyph.

Rnd::Drawable vtable slot 4. The new colour is written over the colour of every vertex the glyph mesh already stores and the mesh is told that its colours changed, so the change takes effect without a rebuild.

Parameters
colorThe colour.
Ghidra address:
NTSC-U/C: 0x004cfec8
Ghidra address:
PAL: 0x0050e2c0

◆ SetAlign()

virtual void Rnd::Text::SetAlign ( int nAlign)
virtual

Set which point of the block the origin is.

Rnd::Drawable vtable slot 5.

Parameters
nAlignA set of the Alignment bits.
Ghidra address:
NTSC-U/C: 0x004cff48
Ghidra address:
PAL: 0x0050e340

◆ SetText()

virtual void Rnd::Text::SetText ( const HxStr & text)
virtual

Replace the text.

Rnd::Drawable vtable slot 6. The argument becomes mPreWrapText, and mText and the glyph mesh are derived from it.

Parameters
textThe text to draw.
Ghidra address:
NTSC-U/C: 0x004d0168
Ghidra address:
PAL: 0x0050e580

◆ SetFont()

virtual void Rnd::Text::SetFont ( Font * pFont)
virtual

Replace the font.

Rnd::Drawable vtable slot 7. A null argument is stored, unlike Rnd::Mesh::SetMat(), which drops the previous material without storing the null.

Parameters
pFontThe font, or null for none.
Ghidra address:
NTSC-U/C: 0x004cfde0
Ghidra address:
PAL: 0x0050e1b8

◆ SetWordWrap()

void Rnd::Text::SetWordWrap ( int nWordWrap)

Set whether long lines are broken at word boundaries.

Parameters
nWordWrapNon-zero to wrap.
Ghidra address:
NTSC-U/C: 0x004cfab8
Ghidra address:
PAL: 0x0050de50

◆ SetWrapWidth()

void Rnd::Text::SetWrapWidth ( float flWrapWidth)

Set the width a wrapped line is broken at.

Parameters
flWrapWidthThe width, in the units the font measures in.
Ghidra address:
NTSC-U/C: 0x004cfb78
Ghidra address:
PAL: 0x0050df30

◆ RebuildText()

void Rnd::Text::RebuildText ( )

Derive mText from mPreWrapText and rebuild the glyph mesh.

Wrapping is applied only when it is enabled and a font is attached, since wrapping needs glyph widths to measure with. Every setter of a field that affects layout ends here, and the compiler inlined this routine at each of those call sites while retaining the out-of-line body for Load() and Copy().

Ghidra address:
NTSC-U/C: 0x004cf9f8
Ghidra address:
PAL: 0x0050dd70

◆ DumpText()

virtual void Rnd::Text::DumpText ( Dbg & sink)
virtual

Write a description of this text run to sink.

The Rnd::Object description comes first and then each of the three mix-ins, because Rnd::Object is a virtual base and the mix-ins therefore do not write it themselves. Everything below is produced only at a positive dump level, and mText and the mesh only at a dump level of 2 or more.

Parameters
sinkThe diagnostic sink to write to.
Ghidra address:
NTSC-U/C: 0x004c7fc0
Ghidra address:
PAL: 0x00506198

Reimplemented from Rnd::Drawable.

◆ Save()

virtual void Rnd::Text::Save ( Stream & stream)
virtual

Write this text run to stream at revision 6.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x004c8330
Ghidra address:
PAL: 0x00506508

Reimplemented from Rnd::Drawable.

◆ Replace()

virtual void Rnd::Text::Replace ( Object * pFrom,
Object * pTo )
virtual

Retarget the font when it is the object being replaced.

Each of the three mix-ins is given the pair first.

Parameters
pFromThe object being replaced.
pToThe replacement, or null.
Ghidra address:
NTSC-U/C: 0x004cf888
Ghidra address:
PAL: 0x0050dc00

Reimplemented from Rnd::Drawable.

◆ ClassName()

virtual const HxStr & Rnd::Text::ClassName ( ) const
virtual

Report the class key a .rnd file writes for a text run.

The returned string is the global at 0x006feca0, which the class registration fills with "Text".

Returns
The class key.
Ghidra address:
NTSC-U/C: 0x004cf760
Ghidra address:
PAL: 0x0050dad8

Implements Rnd::Object.

◆ Copy()

virtual void Rnd::Text::Copy ( const Object * pSource,
unsigned nFlags )
virtual

Copy the state of pSource into this text run.

The colour is not among the fields copied, so a copy draws in whatever colour this object already had. A pSource that is not a Text is dereferenced through the null the cast produces rather than rejected.

Parameters
pSourceThe text run to copy from.
nFlagsThe set of fields to copy, passed on to each mix-in.
Ghidra address:
NTSC-U/C: 0x004cfca8
Ghidra address:
PAL: 0x0050e080

Reimplemented from Rnd::Drawable.

◆ Load()

virtual void Rnd::Text::Load ( Stream & stream)
virtual

Read this text run from stream.

A revision above 6 produces the report "Can't load new Text" followed by the abort handler of Rnd::TheDbg. The older revisions differ in five ways. Below revision 3 the alignment arrives as an index into a table of six words rather than as the bit set. Below revision 2 the transform is absent and a plain x and y pair stands in for it, becoming the translation row of the local transform with the y component negated and scaled by three quarters. Below revision 1 the colour is absent. Below revision 4 wrapping is absent and the wrap width returns to 100.0. Revision 5 alone writes mText, which this build derives instead, and revision 5 introduced the depth-test flag.

Parameters
streamThe stream to read from.
Ghidra address:
NTSC-U/C: 0x004c8560
Ghidra address:
PAL: 0x00506738

Reimplemented from Rnd::Drawable.

◆ FindCollisions()

virtual void Rnd::Text::FindCollisions ( const Segment & ray,
std::list< Collision > & collisions )
virtual

Test a ray against the glyph mesh and append what it strikes to sink.

Rnd::Collideable vtable slot 1. Every intersection the mesh records is retargeted at this object, so a caller receives the text run rather than the mesh it happens to own. A text run that is not showing is not tested at all.

Parameters
rayThe segment to test along.
collisionsThe list to append intersections to.
Ghidra address:
NTSC-U/C: 0x004c7ef8
Ghidra address:
PAL: 0x005060d0

Reimplemented from Rnd::Collideable.

◆ SetBillboard()

virtual void Rnd::Text::SetBillboard ( int nBillboard)
virtual

Set the billboard mode of this object and of its glyph mesh.

Rnd::Transformable vtable slot 1.

Parameters
nBillboardThe billboard mode.
Ghidra address:
NTSC-U/C: 0x004d02a0
Ghidra address:
PAL: 0x0050e6d8

Reimplemented from Rnd::Transformable.

◆ UpdateWorldXfm()

virtual int Rnd::Text::UpdateWorldXfm ( Transformable * pParent,
int nForce )
virtual

Compose the world transform of this object and then of its glyph mesh.

Rnd::Transformable vtable slot 2. The mesh is recomposed against this object, and the base report becomes the force argument of that second call, so the mesh follows unconditionally whenever this object moved.

Parameters
pParentThe transformable this one hangs off, or null for a root.
nForceNon-zero to recompose even when nothing is marked dirty.
Returns
Non-zero when the world transform was recomposed.
Ghidra address:
NTSC-U/C: 0x004d03e0
Ghidra address:
PAL: 0x0050e818

Reimplemented from Rnd::Transformable.

◆ SetShowing()

virtual void Rnd::Text::SetShowing ( int nShowing)
virtual

Set whether this object draws at all.

Rnd::Drawable vtable slot 1. Clearing the flag releases the glyph mesh outright rather than hiding it, and setting it rebuilds that mesh. A value equal to the current one is discarded, and the base implementation is not invoked.

Parameters
nShowingNon-zero to draw.
Ghidra address:
NTSC-U/C: 0x004d0378
Ghidra address:
PAL: 0x0050e7b0

Reimplemented from Rnd::Drawable.

◆ SetHighlight()

virtual void Rnd::Text::SetHighlight ( int nHighlight)
virtual

Set whether this object draws with its highlight treatment.

Rnd::Drawable vtable slot 2. The glyph mesh receives the same flag.

Parameters
nHighlightNon-zero to highlight.
Ghidra address:
NTSC-U/C: 0x004d0328
Ghidra address:
PAL: 0x0050e760

Reimplemented from Rnd::Drawable.

◆ GetFont()

Font * Rnd::Text::GetFont ( )
inline

Report the font the text is set in.

HudTextMessage's constructor inlines the load, and the out-of-line copy has no caller.

Returns
The font, or null.
Ghidra address:
NTSC-U/C: 0x004cf740
Ghidra address:
PAL: 0x0050dab8

◆ DrawShowing()

virtual int Rnd::Text::DrawShowing ( )
virtual

Draw the glyph mesh.

Rnd::Drawable vtable slot 3. Always reports that the children are still to be drawn, even when there is no mesh.

Public because HudWinMessage::Draw() at 0x0042a830, which Overlay::Draw() inlines, calls it directly on a text from outside the hierarchy.

Returns
Non-zero, always.
Ghidra address:
NTSC-U/C: 0x004d02f8
Ghidra address:
PAL: 0x0050e730

Reimplemented from Rnd::Drawable.

◆ GetFontWidth()

float Rnd::Text::GetFontWidth ( const char * pText,
int nCount )

Report the total advance of the first nCount characters of pText in this text's font.

Unlike the measurement HowManyFit() inlines, the sum is not truncated. A text with no font measures nothing. The jukebox screens lay their lists out with it. The name is inferred.

Parameters
pTextThe characters to measure.
nCountHow many characters to measure.
Returns
The summed advance.
Ghidra address:
NTSC-U/C: 0x004d0010
Ghidra address:
PAL: 0x0050e428

◆ CharPosition()

Vector3 Rnd::Text::CharPosition ( int nIndex)

Report where one glyph of the laid-out text sits.

A text with no glyph mesh or no font reports the origin. A glyph's position is the first vertex of its quad. An index past the last glyph reports the last vertex advanced by the font's tracking, which is how MetHelpScreen::FillTexts() at 0x00313208 measures a whole line. kTextAlignMiddle and kTextAlignBottom then lower the result by half or all of the font's cell size. The name is inferred.

Parameters
nIndexThe glyph.
Returns
The position.
Ghidra address:
NTSC-U/C: 0x004c9e98
Ghidra address:
PAL: 0x00508100

◆ GetVerticalBounds()

void Rnd::Text::GetVerticalBounds ( float & flTop,
float & flBottom )

Report the vertical extent of the text block about the origin.

The block is the line count times the font's cell size. kTextAlignMiddle centres it, so the top is half of it and the bottom its negation. kTextAlignBottom puts all of it above the origin, and any other alignment all of it below. A text with no font reports zero for both. The name is inferred.

Parameters
flTopReceives the extent above the origin.
flBottomReceives the extent below the origin, as a negative or zero value.
Ghidra address:
NTSC-U/C: 0x004d0088
Ghidra address:
PAL: 0x0050e4a0

◆ CountLines()

int Rnd::Text::CountLines ( )

Report the number of lines of mText, one more than its newline count.

The name is inferred.

Returns
The line count, at least 1.
Ghidra address:
NTSC-U/C: 0x004d0238
Ghidra address:
PAL: 0x0050e670

Member Data Documentation

◆ sNew

Text *(* Rnd::Text::sNew) (const HxStr &name)
static

Creator the registered "Text" class builds through.

Ghidra address:
NTSC-U/C: 0x006feca8
Ghidra address:
PAL: 0x007426a8

◆ mWrapWidth

float Rnd::Text::mWrapWidth

Width a wrapped line is broken at.

Load() clamps a value read from a file below revision 5 into 0 through 1000, and nothing clamps a value SetWrapWidth() receives. Public because MetSaveRemixScreen and the ShowRemixDetails() of MetJukeboxBaseScreen and MetJukeboxEditPlaylistScreen compare it against GetFontWidth() through a plain load, and the image has no accessor. +0xec

◆ mPreWrapText

HxStr Rnd::Text::mPreWrapText

Text as a caller or a file supplied it, before wrapping.

Public because MetConfigControllerScreen (HandleCommand() at 0x00200ba8 and the helpers at 0x00201eb8, 0x00202070, 0x00206b30, and 0x00206ca8) and MetSaveRemixScreen read it directly, and the image has no accessor. +0xf8


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