resonance 1.0.1
Loading...
Searching...
No Matches
text.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4
5#include "math/color.h"
6#include "os/hxstr.h"
7#include "rnd/collideable.h"
8#include "rnd/drawable.h"
9#include "rnd/transformable.h"
10
11struct Vector3;
12namespace Rnd {
13class Dbg;
14class Font;
15class Mesh;
16class Object;
17class Stream;
18} // namespace Rnd
19
20namespace Rnd {
21
57class Text : public Drawable, public Collideable, public Transformable {
58public:
74
81 static Text *(*sNew)(const HxStr &name);
82
91 static void *operator new(size_t nSize);
92
100 static void operator delete(void *pBlock);
101
112 explicit Text(const HxStr &name);
113
120 virtual ~Text();
121
133 virtual void SetColor(const Color &color);
134
144 virtual void SetAlign(int nAlign);
145
156 virtual void SetText(const HxStr &text);
157
168 virtual void SetFont(Font *pFont);
169
177 void SetWordWrap(int nWordWrap);
178
186 void SetWrapWidth(float flWrapWidth);
187
200
213 virtual void DumpText(Dbg &sink);
214
222 virtual void Save(Stream &stream);
223
234 virtual void Replace(Object *pFrom, Object *pTo);
235
246 virtual const HxStr &ClassName() const;
247
260 virtual void Copy(const Object *pSource, unsigned nFlags);
261
278 virtual void Load(Stream &stream);
279
292 virtual void FindCollisions(const Segment &ray, std::list<Collision> &collisions);
293
303 virtual void SetBillboard(int nBillboard);
304
318 virtual int UpdateWorldXfm(Transformable *pParent, int nForce);
319
331 virtual void SetShowing(int nShowing);
332
342 virtual void SetHighlight(int nHighlight);
343
354 return mFont;
355 }
356
370 virtual int DrawShowing();
371
385 float GetFontWidth(const char *pText, int nCount);
386
402
416 void GetVerticalBounds(float &flTop, float &flBottom);
417
428
429private:
441 void BuildGlyphMesh();
442
458 void EmitLineGlyphs(
459 float flLineY, float flLineWidth, int nCharBase, const char *pBegin, const char *pEnd);
460
474 HxStr ApplyWordWrap(const HxStr &text);
475
489 int HowManyFit(const char *pText);
490
491 // Total advance of the first nCount characters of pText, truncated to a whole number. The
492 // compiler inlined this at all five measurement sites of HowManyFit(), which is its only
493 // caller. A text run with no font measures nothing.
494 float MeasureRun(const char *pText, int nCount);
495
505 void ReleaseObjects();
506
515 void AddRefObjects();
516
517 // Declared in recovered offset order. Every member but mWrapWidth and mPreWrapText is private:
518 // each one that the engine changes has a setter, and no call from outside this class arrives at
519 // one of those setters.
520
521 Color mColor; // +0xd0
522 int mAlign; // +0xe0
523 Font *mFont; // +0xe4
524 int mWordWrap; // +0xe8
525
526public:
536
537private:
538 // mPreWrapText with a newline inserted at every wrap point. Derived rather than stored, which
539 // is why Save() does not write it.
540 HxStr mText; // +0xf0
541
542public:
551
552private:
553 // Geometry built from mText. Owned outright, created through the Rnd::Mesh creator hook, and
554 // marked internal so that a scene save does not write it as an object of its own.
555 Mesh *mMesh; // +0x100
556 // Whether the glyph mesh reads the depth buffer. Set gives the mesh kZModeZReadOnly with
557 // kZFuncLess, and clear gives it kZModeDisable with kZFuncNever. The title is inferred from
558 // that pair, since the image supplies no string for the field and no setter for it either.
559 int mZTest; // +0x104
560
561 // Alignment padding rather than an unrecovered field. The quadword access to mColor gives the
562 // class 16-byte alignment, and the virtual base subobject therefore starts at 0x110.
563 unsigned char mReserved108[0x08];
564};
565
576Text *NewText(const HxStr &name);
577
591
604
614
622
623} // namespace Rnd
Heap-allocated NUL-terminated string.
Definition hxstr.h:41
Collideable()
Construct a collideable with no children.
Sink that the engine formats its diagnostic and failure text into.
Definition dbg.h:33
Drawable()
Construct a visible drawable with no children.
Glyph atlas, either a host font description or a grid of cells inside a material texture.
Definition font.h:59
Indexed triangle mesh with one material.
Definition mesh.h:46
Base of every object the renderer can load, resolve by name, and serialise.
Definition object.h:43
Byte stream that every renderer object serialises itself through.
Definition stream.h:31
Run of text drawn as a quad per glyph.
Definition text.h:57
virtual void SetBillboard(int nBillboard)
Set the billboard mode of this object and of its glyph mesh.
Vector3 CharPosition(int nIndex)
Report where one glyph of the laid-out text sits.
virtual void SetText(const HxStr &text)
Replace the text.
virtual void FindCollisions(const Segment &ray, std::list< Collision > &collisions)
Test a ray against the glyph mesh and append what it strikes to sink.
int CountLines()
Report the number of lines of mText, one more than its newline count.
virtual int DrawShowing()
Draw the glyph mesh.
float mWrapWidth
Width a wrapped line is broken at.
Definition text.h:535
virtual void SetColor(const Color &color)
Set the colour of every glyph.
virtual void SetFont(Font *pFont)
Replace the font.
float GetFontWidth(const char *pText, int nCount)
Report the total advance of the first nCount characters of pText in this text's font.
HxStr mPreWrapText
Text as a caller or a file supplied it, before wrapping.
Definition text.h:550
virtual void Load(Stream &stream)
Read this text run from stream.
Font * GetFont()
Report the font the text is set in.
Definition text.h:353
virtual const HxStr & ClassName() const
Report the class key a .rnd file writes for a text run.
virtual void SetAlign(int nAlign)
Set which point of the block the origin is.
void RebuildText()
Derive mText from mPreWrapText and rebuild the glyph mesh.
virtual ~Text()
Release the glyph mesh and drop the reference on the font.
void GetVerticalBounds(float &flTop, float &flBottom)
Report the vertical extent of the text block about the origin.
virtual void Replace(Object *pFrom, Object *pTo)
Retarget the font when it is the object being replaced.
void SetWrapWidth(float flWrapWidth)
Set the width a wrapped line is broken at.
virtual void SetShowing(int nShowing)
Set whether this object draws at all.
virtual void Copy(const Object *pSource, unsigned nFlags)
Copy the state of pSource into this text run.
virtual void SetHighlight(int nHighlight)
Set whether this object draws with its highlight treatment.
Text(const HxStr &name)
Construct an empty white text run.
virtual void DumpText(Dbg &sink)
Write a description of this text run to sink.
void SetWordWrap(int nWordWrap)
Set whether long lines are broken at word boundaries.
Alignment
Bits of the alignment word.
Definition text.h:66
@ kTextAlignMiddle
Definition text.h:71
@ kTextAlignCenter
Definition text.h:68
@ kTextAlignRight
Definition text.h:69
@ kTextAlignTop
Definition text.h:70
@ kTextAlignBottom
Definition text.h:72
@ kTextAlignLeft
Definition text.h:67
virtual void Save(Stream &stream)
Write this text run to stream at revision 6.
virtual int UpdateWorldXfm(Transformable *pParent, int nForce)
Compose the world transform of this object and then of its glyph mesh.
Transformable()
Construct a dirty transformable with identity transforms and no children.
The rendering engine.
Definition animhelper.h:3
Text * NewTextThroughHook(const HxStr &name)
Build a text run through the creator hook.
Object * CreateRegisteredText(const HxStr &name)
Build a text run for the registered "Text" class.
HxStr g_textClassName
Registered class name of Rnd::Text, the string "Text".
Text * NewText(const HxStr &name)
Allocate and construct a text run.
void RegisterTextClass()
Point Text::sNew at NewText() and register the "Text" class with Rnd::Manager.
Linear colour with four float components.
Definition color.h:10
Line segment a collision query is run along.
Definition collideable.h:22
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:12