CGuiTextPane imps

This commit is contained in:
Jack Andersen 2016-03-21 16:27:46 -10:00
parent 9f82900cdc
commit 5108456dc9
12 changed files with 188 additions and 69 deletions

View File

@ -241,9 +241,9 @@ void FRME::Widget::TXPNInfo::read(athena::io::IStreamReader& __dna_reader)
/* font */
font.read(__dna_reader);
/* unk1 */
unk1 = __dna_reader.readBool();
wordWrap = __dna_reader.readBool();
/* unk2 */
unk2 = __dna_reader.readBool();
vertical = __dna_reader.readBool();
/* justification */
justification = Justification(__dna_reader.readUint32Big());
/* verticalJustification */
@ -253,7 +253,7 @@ void FRME::Widget::TXPNInfo::read(athena::io::IStreamReader& __dna_reader)
/* outlineColor */
outlineColor = __dna_reader.readVec4fBig();
/* pointScale */
pointScale = __dna_reader.readVec2fBig();
blockExtent = __dna_reader.readVec2fBig();
if (version == 1)
{
/* jpnFont */
@ -277,9 +277,9 @@ void FRME::Widget::TXPNInfo::write(athena::io::IStreamWriter& __dna_writer) cons
/* font */
font.write(__dna_writer);
/* unk1 */
__dna_writer.writeBool(unk1);
__dna_writer.writeBool(wordWrap);
/* unk2 */
__dna_writer.writeBool(unk2);
__dna_writer.writeBool(vertical);
/* justification */
__dna_writer.writeUint32Big(atUint32(justification));
/* verticalJustification */
@ -289,7 +289,7 @@ void FRME::Widget::TXPNInfo::write(athena::io::IStreamWriter& __dna_writer) cons
/* outlineColor */
__dna_writer.writeVec4fBig(outlineColor);
/* pointScale */
__dna_writer.writeVec2fBig(pointScale);
__dna_writer.writeVec2fBig(blockExtent);
if (version == 1)
{
/* jpnFont */

View File

@ -194,10 +194,30 @@ struct FRME : BigDNA
{
enum class Justification : atUint32
{
Left = 0,
Center,
Right,
Full,
NLeft,
NCenter,
NRight,
Seven,
Eight,
Nine
};
enum class VerticalJustification : atUint32
{
Top = 0,
Center,
Bottom,
Full,
NTop,
NCenter,
NBottom,
Seven,
Eight,
Nine
};
DECL_EXPLICIT_DNA
@ -210,13 +230,13 @@ struct FRME : BigDNA
Value<float> zDim;
Value<atVec3f> scaleCenter;
UniqueID32 font;
Value<bool> unk1;
Value<bool> unk2;
Value<bool> wordWrap;
Value<bool> vertical;
Value<Justification> justification;
Value<VerticalJustification> verticalJustification;
Value<atVec4f> fillColor;
Value<atVec4f> outlineColor;
Value<atVec2f> pointScale;
Value<atVec2f> blockExtent; /* In points; converted to int by loader */
/* The following is only found in V1 */
UniqueID32 jpnFont;
Value<atInt32> jpnPointScale[2];

View File

@ -88,7 +88,7 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
CModelFlags flags;
flags.f1 = 4;
flags.f2 = 0;
flags.f3 = (xf7_24_ << 1) | xf6_31_;
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
flags.color = moduCol;
model->Draw(flags);
break;
@ -98,7 +98,7 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
CModelFlags flags;
flags.f1 = 3;
flags.f2 = 0;
flags.f3 = (xf7_24_ << 1) | xf6_31_;
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
flags.color = moduCol;
model->Draw(flags);
break;
@ -108,13 +108,13 @@ void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const
CModelFlags flags;
flags.f1 = 4;
flags.f2 = 0;
flags.f3 = xf6_31_;
flags.f3 = xf6_31_depthTest;
flags.color = moduCol;
model->Draw(flags);
flags.f1 = 5;
flags.f2 = 0;
flags.f3 = (xf7_24_ << 1) | xf6_31_;
flags.f3 = (xf7_24_depthWrite << 1) | xf6_31_depthTest;
flags.color = moduCol;
model->Draw(flags);
break;

View File

@ -1,38 +1,124 @@
#include "CGuiTextPane.hpp"
#include "CGuiAnimController.hpp"
#include "CGuiLogicalEventTrigger.hpp"
#include "CFontImageDef.hpp"
#include "CGuiFrame.hpp"
#include "CGuiSys.hpp"
#include "CGuiWidgetDrawParms.hpp"
#include "Graphics/CGraphics.hpp"
#include "Graphics/CGraphicsPalette.hpp"
namespace urde
{
CGuiTextPane::CGuiTextPane(const CGuiWidgetParms& parms, float a, float b,
const zeus::CVector3f& vec, u32 c, const CGuiTextProperties& props,
const zeus::CColor& col1, const zeus::CColor& col2,
int, int)
: CGuiPane(parms, a, b, vec)
CGuiTextPane::CGuiTextPane(const CGuiWidgetParms& parms, float xDim, float zDim,
const zeus::CVector3f& vec, TResId fontId, const CGuiTextProperties& props,
const zeus::CColor& fontCol, const zeus::CColor& outlineCol,
s32 extentX, s32 extentY)
: CGuiPane(parms, xDim, zDim, vec), x114_textSupport(fontId, props, fontCol, outlineCol,
zeus::CColor::skWhite, extentX, extentY,
&parms.x0_frame->GetGuiSys().GetResStore()) {}
void CGuiTextPane::Update(float dt)
{
CGuiWidget::Update(dt);
x114_textSupport.Update(dt);
}
bool CGuiTextPane::GetIsFinishedLoadingWidgetSpecific() const
{
return x114_textSupport.GetIsTextSupportFinishedLoading();
}
void CGuiTextPane::SetDimensions(const zeus::CVector2f& dim, bool initVBO)
{
CGuiPane::SetDimensions(dim, initVBO);
if (initVBO)
InitializeBuffers();
}
void CGuiTextPane::ScaleDimensions(const zeus::CVector3f& scale)
{
}
void CGuiTextPane::Draw(const CGuiWidgetDrawParms& parms) const
{
if (!GetIsVisible())
return;
zeus::CVector2f dims = GetDimensions();
if (x114_textSupport.x28_extentX)
dims.x /= float(x114_textSupport.x28_extentX);
else
dims.x = 0.f;
if (x114_textSupport.x2c_extentY)
dims.y /= float(x114_textSupport.x2c_extentY);
else
dims.y = 0.f;
zeus::CTransform local = zeus::CTransform::Translate(x100_verts.front().m_pos + x108_scaleCenter) *
zeus::CTransform::Scale(dims.x, 1.f, dims.y);
CGraphics::SetModelMatrix(x34_worldXF * local);
zeus::CColor geomCol = xb4_;
geomCol.a *= parms.x0_alphaMod;
((CGuiTextPane*)this)->x114_textSupport.SetGeometryColor(geomCol);
CGraphics::SetDepthWriteMode(xf6_31_depthTest, ERglEnum::LEqual, xf7_24_depthWrite);
switch (xc4_drawFlags)
{
case EGuiModelDrawFlags::Shadeless:
case EGuiModelDrawFlags::Opaque:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One,
ERglBlendFactor::Zero, ERglLogicOp::Clear);
x114_textSupport.Render();
break;
case EGuiModelDrawFlags::Alpha:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear);
x114_textSupport.Render();
break;
case EGuiModelDrawFlags::Additive:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::One, ERglLogicOp::Clear);
x114_textSupport.Render();
break;
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear);
x114_textSupport.Render();
((CGuiTextPane*)this)->x114_textSupport.SetGeometryColor
(geomCol * zeus::CColor(geomCol.a, geomCol.a, geomCol.a, 1.f));
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One,
ERglBlendFactor::One, ERglLogicOp::Clear);
x114_textSupport.Render();
break;
}
}
CGuiTextPane* CGuiTextPane::Create(CGuiFrame* frame, CInputStream& in, bool flag)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
float a = in.readFloatBig();
float b = in.readFloatBig();
float xDim = in.readFloatBig();
float zDim = in.readFloatBig();
zeus::CVector3f vec;
vec.readBig(in);
u32 c = in.readUint32Big();
bool d = in.readBool();
bool e = in.readBool();
u32 fontId = in.readUint32Big();
bool wordWrap = in.readBool();
bool vertical = in.readBool();
EJustification justification = EJustification(in.readUint32Big());
EVerticalJustification vJustification = EVerticalJustification(in.readUint32Big());
CGuiTextProperties props(d, e, false, justification, vJustification);
zeus::CColor col1;
col1.readRGBABig(in);
zeus::CColor col2;
col2.readRGBABig(in);
int f = in.readFloatBig();
int g = in.readFloatBig();
return new CGuiTextPane(parms, a, b, vec, c, props, col1, col2, f, g);
CGuiTextProperties props(wordWrap, vertical, false, justification, vJustification);
zeus::CColor fontCol;
fontCol.readRGBABig(in);
zeus::CColor outlineCol;
outlineCol.readRGBABig(in);
int extentX = in.readFloatBig();
int extentY = in.readFloatBig();
return new CGuiTextPane(parms, xDim, zDim, vec, fontId, props, fontCol, outlineCol, extentX, extentY);
}
}

View File

@ -9,10 +9,22 @@ namespace urde
class CGuiTextPane : public CGuiPane
{
CGuiTextSupport x114_textSupport;
public:
CGuiTextPane(const CGuiWidgetParms& parms, float a, float b, const zeus::CVector3f& vec,
u32, const CGuiTextProperties& props, const zeus::CColor& col1, const zeus::CColor& col2,
int, int);
CGuiTextPane(const CGuiWidgetParms& parms, float xDim, float zDim, const zeus::CVector3f& vec,
TResId fontId, const CGuiTextProperties& props, const zeus::CColor& col1,
const zeus::CColor& col2, s32 padX, s32 padY);
FourCC GetWidgetTypeID() const {return FOURCC('TXPN');}
CGuiTextSupport* TextSupport() {return &x114_textSupport;}
const CGuiTextSupport* GetTextSupport() const {return &x114_textSupport;}
void Update(float dt);
bool GetIsFinishedLoadingWidgetSpecific() const;
std::vector<TResId> GetFontAssets() const {return {x114_textSupport.x50_fontId};}
void SetDimensions(const zeus::CVector2f& dim, bool initVBO);
void ScaleDimensions(const zeus::CVector3f& scale);
void Draw(const CGuiWidgetDrawParms& parms) const;
static CGuiTextPane* Create(CGuiFrame* frame, CInputStream& in, bool);
};

View File

@ -11,10 +11,10 @@ namespace urde
{
CGuiTextSupport::CGuiTextSupport(TResId fontId, const CGuiTextProperties& props,
const zeus::CColor& col1, const zeus::CColor& col2,
const zeus::CColor& col3, s32 padX, s32 padY, CSimplePool* store)
: x10_props(props), x1c_fontColor(col1), x20_outlineColor(col2),
x24_geometryColor(col3), x28_padX(padX), x2c_padY(padY)
const zeus::CColor& fontCol, const zeus::CColor& outlineCol,
const zeus::CColor& geomCol, s32 padX, s32 padY, CSimplePool* store)
: x10_props(props), x1c_fontColor(fontCol), x20_outlineColor(outlineCol),
x24_geometryColor(geomCol), x28_extentX(padX), x2c_extentY(padY)
{
x2c0_font = store->GetObj({SBIG('FONT'), fontId});
}
@ -100,7 +100,7 @@ void CGuiTextSupport::CheckAndRebuildTextRenderBuffer()
g_TextExecuteBuf->Clear();
g_TextExecuteBuf->x18_textState.x48_enableWordWrap = x10_props.x0_wordWrap;
g_TextExecuteBuf->BeginBlock(0, 0, x28_padX, x2c_padY, ETextDirection(x10_props.x1_vertical),
g_TextExecuteBuf->BeginBlock(0, 0, x28_extentX, x2c_extentY, ETextDirection(x10_props.x1_vertical),
x10_props.x4_justification, x10_props.x8_vertJustification);
g_TextExecuteBuf->AddColor(EColorType::Main, x1c_fontColor);
g_TextExecuteBuf->AddColor(EColorType::Outline, x20_outlineColor);

View File

@ -66,21 +66,22 @@ class CGuiTextProperties
EJustification x4_justification;
EVerticalJustification x8_vertJustification;
public:
CGuiTextProperties(bool a, bool b, bool c, EJustification justification,
CGuiTextProperties(bool wordWrap, bool vertical, bool c, EJustification justification,
EVerticalJustification vertJustification)
: x0_wordWrap(a), x1_vertical(b), x2_c(c), x4_justification(justification),
: x0_wordWrap(wordWrap), x1_vertical(vertical), x2_c(c), x4_justification(justification),
x8_vertJustification(vertJustification) {}
};
class CGuiTextSupport
{
friend class CGuiTextPane;
std::wstring x0_string;
CGuiTextProperties x10_props;
zeus::CColor x1c_fontColor;
zeus::CColor x20_outlineColor;
zeus::CColor x24_geometryColor;
s32 x28_padX;
s32 x2c_padY;
s32 x28_extentX;
s32 x2c_extentY;
float x30_curTime = 0.f;
std::vector<std::pair<float, int>> x34_primStartTimes;
bool x44_typeEnable = false;
@ -93,8 +94,8 @@ class CGuiTextSupport
TLockedToken<CRasterFont> x2c0_font;
public:
CGuiTextSupport(TResId fontId, const CGuiTextProperties& props,
const zeus::CColor& col1, const zeus::CColor& col2,
const zeus::CColor& col3, s32 padX, s32 padY, CSimplePool* store);
const zeus::CColor& fontCol, const zeus::CColor& outlineCol,
const zeus::CColor& geomCol, s32 extX, s32 extY, CSimplePool* store);
float GetCurrentAnimationOverAge() const;
float GetNumCharsPrinted() const;
float GetTotalAnimationTime() const;

View File

@ -29,7 +29,7 @@ CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms)
xf6_26_isActive(parms.xb_defaultActive),
xf6_27_(true), xf6_28_eventLock(false),
xf6_29_cullFaces(parms.xc_cullFaces), xf6_30_(false),
xf6_31_(true), xf7_24_(false), xf7_25_(true)
xf6_31_depthTest(true), xf7_24_depthWrite(false), xf7_25_(true)
{
if (parms.x4_useAnimController)
EnsureHasAnimController();
@ -143,7 +143,7 @@ CGuiTextSupport* CGuiWidget::TextSupport()
return nullptr;
}
CGuiTextSupport* CGuiWidget::GetTextSupport() const
const CGuiTextSupport* CGuiWidget::GetTextSupport() const
{
return nullptr;
}

View File

@ -111,8 +111,8 @@ protected:
bool xf6_28_eventLock : 1;
bool xf6_29_cullFaces : 1;
bool xf6_30_ : 1;
bool xf6_31_ : 1;
bool xf7_24_ : 1;
bool xf6_31_depthTest : 1;
bool xf7_24_depthWrite : 1;
bool xf7_25_ : 1;
public:
@ -133,7 +133,7 @@ public:
virtual bool GetIsVisible() const;
virtual bool GetIsActive() const;
virtual CGuiTextSupport* TextSupport();
virtual CGuiTextSupport* GetTextSupport() const;
virtual const CGuiTextSupport* GetTextSupport() const;
virtual void ModifyRGBA(CGuiWidget* widget);
virtual void AddAnim(EGuiAnimBehListID, CGuiAnimBase*);
virtual void AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool atEnd);

View File

@ -78,29 +78,29 @@ void CLineInstruction::InvokeLTR(CFontRenderState& state) const
case EJustification::Center:
case EJustification::Eight:
state.x6c_curX = state.x54_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockPaddingX / 2 - x8_curX / 2;
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
break;
case EJustification::NCenter:
if (x4_wordCount == 1)
{
state.x6c_curX = state.x54_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockPaddingX / 2 - x8_curX / 2;
state.x54_curBlock->xc_blockExtentX / 2 - x8_curX / 2;
}
else
{
state.x6c_curX = state.x54_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockPaddingX / 2 -
state.x54_curBlock->xc_blockExtentX / 2 -
state.x54_curBlock->x2c_lineX / 2;
}
break;
case EJustification::Right:
case EJustification::Nine:
state.x6c_curX = state.x54_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockPaddingX - x8_curX;
state.x54_curBlock->xc_blockExtentX - x8_curX;
break;
case EJustification::NRight:
state.x6c_curX = state.x54_curBlock->x4_offsetX +
state.x54_curBlock->xc_blockPaddingX -
state.x54_curBlock->xc_blockExtentX -
state.x54_curBlock->x2c_lineX;
break;
default: break;
@ -121,7 +121,7 @@ void CLineInstruction::InvokeLTR(CFontRenderState& state) const
val = inst.xc_curY;
break;
case EVerticalJustification::Full:
val = state.x54_curBlock->x10_blockPaddingY - state.x54_curBlock->x30_lineY;
val = state.x54_curBlock->x10_blockExtentY - state.x54_curBlock->x30_lineY;
if (state.x54_curBlock->x34_lineCount > 1)
val /= state.x54_curBlock->x34_lineCount - 1;
else
@ -229,17 +229,17 @@ void CBlockInstruction::SetupPositionLTR(CFontRenderState& state) const
break;
case EVerticalJustification::Center:
case EVerticalJustification::NCenter:
state.x70_curY = x8_offsetY + (x10_blockPaddingY - x30_lineY) / 2;
state.x70_curY = x8_offsetY + (x10_blockExtentY - x30_lineY) / 2;
break;
case EVerticalJustification::Eight:
state.x70_curY = x8_offsetY + (x10_blockPaddingY - x34_lineCount * x24_largestMonoH) / 2;
state.x70_curY = x8_offsetY + (x10_blockExtentY - x34_lineCount * x24_largestMonoH) / 2;
break;
case EVerticalJustification::Bottom:
case EVerticalJustification::NBottom:
state.x70_curY = x8_offsetY + x10_blockPaddingY - x30_lineY;
state.x70_curY = x8_offsetY + x10_blockExtentY - x30_lineY;
break;
case EVerticalJustification::Nine:
state.x70_curY = x8_offsetY + x10_blockPaddingY - x34_lineCount * x24_largestMonoH;
state.x70_curY = x8_offsetY + x10_blockExtentY - x34_lineCount * x24_largestMonoH;
break;
}
}
@ -263,7 +263,7 @@ void CWordInstruction::InvokeLTR(CFontRenderState& state) const
switch (state.x54_curBlock->x18_justification)
{
case EJustification::Full:
w += (state.x54_curBlock->xc_blockPaddingX - inst.x8_curX) / (inst.x4_wordCount - 1);
w += (state.x54_curBlock->xc_blockExtentX - inst.x8_curX) / (inst.x4_wordCount - 1);
break;
case EJustification::NLeft:
case EJustification::NCenter:

View File

@ -135,8 +135,8 @@ class CBlockInstruction : public CInstruction
s32 x4_offsetX;
s32 x8_offsetY;
s32 xc_blockPaddingX;
s32 x10_blockPaddingY;
s32 xc_blockExtentX;
s32 x10_blockExtentY;
ETextDirection x14_direction;
EJustification x18_justification;
EVerticalJustification x1c_vertJustification;
@ -147,10 +147,10 @@ class CBlockInstruction : public CInstruction
s32 x30_lineY = 0;
s32 x34_lineCount = 0;
public:
CBlockInstruction(s32 offX, s32 offY, s32 padX, s32 padY, ETextDirection dir,
CBlockInstruction(s32 offX, s32 offY, s32 extX, s32 extY, ETextDirection dir,
EJustification just, EVerticalJustification vjust)
: x4_offsetX(offX), x8_offsetY(offY),
xc_blockPaddingX(padX), x10_blockPaddingY(padY), x14_direction(dir),
xc_blockExtentX(extX), x10_blockExtentY(extY), x14_direction(dir),
x18_justification(just), x1c_vertJustification(vjust) {}
void TestLargestFont(s32 monoW, s32 monoH, s32 baseline);
void SetupPositionLTR(CFontRenderState& state) const;

View File

@ -110,13 +110,13 @@ int CTextExecuteBuffer::WrapOneLTR(const wchar_t* str, int len)
if (x18_textState.x48_enableWordWrap)
{
if (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockPaddingX &&
if (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockExtentX &&
x70_curLine->x4_wordCount > 1 &&
x7c_curX + w < x6c_curBlock->xc_blockPaddingX)
x7c_curX + w < x6c_curBlock->xc_blockExtentX)
{
MoveWordLTR();
}
if (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockPaddingX && len > 1)
if (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockExtentX && len > 1)
{
const wchar_t* strEnd = str + len;
int aRank = 5;
@ -141,7 +141,7 @@ int CTextExecuteBuffer::WrapOneLTR(const wchar_t* str, int len)
w, h, str, rem);
}
} while (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockPaddingX && rem > 1);
} while (w + x70_curLine->x8_curX > x6c_curBlock->xc_blockExtentX && rem > 1);
}
}