mirror of https://github.com/AxioDL/metaforce.git
CGuiTextSupport: Eliminate the use of const_cast
We can supply a const and non-const variant to eliminate the need to const_cast here.
This commit is contained in:
parent
f3afcf7299
commit
2d8e94911a
|
@ -25,21 +25,47 @@ CGuiTextSupport::CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& prop
|
||||||
x2cc_font = store->GetObj({SBIG('FONT'), fontId});
|
x2cc_font = store->GetObj({SBIG('FONT'), fontId});
|
||||||
}
|
}
|
||||||
|
|
||||||
CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() const {
|
CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() {
|
||||||
if (x60_renderBuf && !x308_multipageFlag)
|
if (x60_renderBuf && !x308_multipageFlag) {
|
||||||
return const_cast<CTextRenderBuffer*>(&*x60_renderBuf);
|
return &*x60_renderBuf;
|
||||||
if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter)
|
}
|
||||||
|
|
||||||
|
if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (const CTextRenderBuffer& buf : x2ec_renderBufferPages)
|
for (CTextRenderBuffer& buf : x2ec_renderBufferPages) {
|
||||||
if (idx++ == x304_pageCounter)
|
if (idx++ == x304_pageCounter) {
|
||||||
return const_cast<CTextRenderBuffer*>(&buf);
|
return &buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CTextRenderBuffer* CGuiTextSupport::GetCurrentPageRenderBuffer() const {
|
||||||
|
if (x60_renderBuf && !x308_multipageFlag) {
|
||||||
|
return &*x60_renderBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!x308_multipageFlag || x2ec_renderBufferPages.size() <= x304_pageCounter) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
for (const CTextRenderBuffer& buf : x2ec_renderBufferPages) {
|
||||||
|
if (idx++ == x304_pageCounter) {
|
||||||
|
return &buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CGuiTextSupport::GetCurrentAnimationOverAge() const {
|
float CGuiTextSupport::GetCurrentAnimationOverAge() const {
|
||||||
float ret = 0.f;
|
float ret = 0.f;
|
||||||
if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
||||||
if (x50_typeEnable) {
|
if (x50_typeEnable) {
|
||||||
if (x40_primStartTimes.size()) {
|
if (x40_primStartTimes.size()) {
|
||||||
auto& lastTime = x40_primStartTimes.back();
|
auto& lastTime = x40_primStartTimes.back();
|
||||||
|
@ -53,16 +79,18 @@ float CGuiTextSupport::GetCurrentAnimationOverAge() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float CGuiTextSupport::GetNumCharsTotal() const {
|
float CGuiTextSupport::GetNumCharsTotal() const {
|
||||||
if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
|
if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
||||||
if (x50_typeEnable)
|
if (x50_typeEnable) {
|
||||||
return buf->GetPrimitiveCount();
|
return buf->GetPrimitiveCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CGuiTextSupport::GetNumCharsPrinted() const {
|
float CGuiTextSupport::GetNumCharsPrinted() const {
|
||||||
if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
||||||
if (x50_typeEnable) {
|
if (x50_typeEnable) {
|
||||||
float charsPrinted = x3c_curTime * x58_chRate;
|
const float charsPrinted = x3c_curTime * x58_chRate;
|
||||||
return std::min(charsPrinted, float(buf->GetPrimitiveCount()));
|
return std::min(charsPrinted, float(buf->GetPrimitiveCount()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,9 +98,11 @@ float CGuiTextSupport::GetNumCharsPrinted() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float CGuiTextSupport::GetTotalAnimationTime() const {
|
float CGuiTextSupport::GetTotalAnimationTime() const {
|
||||||
if (CTextRenderBuffer* buf = GetCurrentPageRenderBuffer())
|
if (const CTextRenderBuffer* buf = GetCurrentPageRenderBuffer()) {
|
||||||
if (x50_typeEnable)
|
if (x50_typeEnable) {
|
||||||
return buf->GetPrimitiveCount() / x58_chRate;
|
return buf->GetPrimitiveCount() / x58_chRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,16 +265,23 @@ void CGuiTextSupport::SetText(std::u16string_view str, bool multipage) {
|
||||||
|
|
||||||
void CGuiTextSupport::SetText(std::string_view str, bool multipage) { SetText(hecl::UTF8ToChar16(str), multipage); }
|
void CGuiTextSupport::SetText(std::string_view str, bool multipage) { SetText(hecl::UTF8ToChar16(str), multipage); }
|
||||||
|
|
||||||
bool CGuiTextSupport::_GetIsTextSupportFinishedLoading() const {
|
bool CGuiTextSupport::_GetIsTextSupportFinishedLoading() {
|
||||||
for (const CToken& tok : x2bc_assets) {
|
for (CToken& tok : x2bc_assets) {
|
||||||
const_cast<CToken&>(tok).Lock();
|
tok.Lock();
|
||||||
if (!tok.IsLoaded())
|
|
||||||
|
if (!tok.IsLoaded()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!x2cc_font)
|
}
|
||||||
|
|
||||||
|
if (!x2cc_font) {
|
||||||
return true;
|
return true;
|
||||||
if (x2cc_font.IsLoaded())
|
}
|
||||||
|
|
||||||
|
if (x2cc_font.IsLoaded()) {
|
||||||
return x2cc_font->IsFinishedLoading();
|
return x2cc_font->IsFinishedLoading();
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,8 +306,8 @@ void CGuiTextSupport::SetImageBaseline(bool b) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGuiTextSupport::GetIsTextSupportFinishedLoading() const {
|
bool CGuiTextSupport::GetIsTextSupportFinishedLoading() {
|
||||||
const_cast<CGuiTextSupport*>(this)->CheckAndRebuildRenderBuffer();
|
CheckAndRebuildRenderBuffer();
|
||||||
return _GetIsTextSupportFinishedLoading();
|
return _GetIsTextSupportFinishedLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,10 @@ class CGuiTextSupport {
|
||||||
int x304_pageCounter = 0;
|
int x304_pageCounter = 0;
|
||||||
bool x308_multipageFlag = false;
|
bool x308_multipageFlag = false;
|
||||||
|
|
||||||
CTextRenderBuffer* GetCurrentPageRenderBuffer() const;
|
CTextRenderBuffer* GetCurrentPageRenderBuffer();
|
||||||
bool _GetIsTextSupportFinishedLoading() const;
|
const CTextRenderBuffer* GetCurrentPageRenderBuffer() const;
|
||||||
|
|
||||||
|
bool _GetIsTextSupportFinishedLoading();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& props, const zeus::CColor& fontCol,
|
CGuiTextSupport(CAssetId fontId, const CGuiTextProperties& props, const zeus::CColor& fontCol,
|
||||||
|
@ -114,7 +116,7 @@ public:
|
||||||
void SetJustification(EJustification j);
|
void SetJustification(EJustification j);
|
||||||
void SetVerticalJustification(EVerticalJustification j);
|
void SetVerticalJustification(EVerticalJustification j);
|
||||||
void SetImageBaseline(bool b);
|
void SetImageBaseline(bool b);
|
||||||
bool GetIsTextSupportFinishedLoading() const;
|
bool GetIsTextSupportFinishedLoading();
|
||||||
float GetCurTime() const { return x3c_curTime; }
|
float GetCurTime() const { return x3c_curTime; }
|
||||||
void SetCurTime(float t) { x3c_curTime = t; }
|
void SetCurTime(float t) { x3c_curTime = t; }
|
||||||
std::u16string_view GetString() const { return x0_string; }
|
std::u16string_view GetString() const { return x0_string; }
|
||||||
|
|
Loading…
Reference in New Issue