metaforce/Runtime/GuiSys/CGuiTextPane.cpp

156 lines
5.8 KiB
C++
Raw Permalink Normal View History

#include "Runtime/GuiSys/CGuiTextPane.hpp"
#include <array>
#include "Runtime/Graphics/CGraphics.hpp"
#include "Runtime/Graphics/CGraphicsPalette.hpp"
#include "Runtime/GuiSys/CFontImageDef.hpp"
#include "Runtime/GuiSys/CGuiFrame.hpp"
#include "Runtime/GuiSys/CGuiSys.hpp"
#include "Runtime/GuiSys/CGuiWidgetDrawParms.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
namespace {
constexpr std::array<zeus::CVector3f, 4> NormalPoints{{
{0.f, 0.f, -1.f},
{1.f, 0.f, -1.f},
{1.f, 0.f, 0.f},
{0.f, 0.f, 0.f},
}};
bool testProjectedLine(const zeus::CVector2f& a, const zeus::CVector2f& b, const zeus::CVector2f& point) {
const zeus::CVector2f normal = (b - a).perpendicularVector().normalized();
return point.dot(normal) >= a.dot(normal);
}
} // Anonymous namespace
CGuiTextPane::CGuiTextPane(const CGuiWidgetParms& parms, CSimplePool* sp, const zeus::CVector2f& dim,
2017-08-13 05:26:14 +00:00
const zeus::CVector3f& vec, CAssetId fontId, const CGuiTextProperties& props,
2018-12-08 05:30:43 +00:00
const zeus::CColor& fontCol, const zeus::CColor& outlineCol, s32 extentX, s32 extentY)
: CGuiPane(parms, dim, vec)
, xd4_textSupport(fontId, props, fontCol, outlineCol, zeus::skWhite, extentX, extentY, sp, xac_drawFlags) {}
2016-03-22 02:27:46 +00:00
2018-12-08 05:30:43 +00:00
void CGuiTextPane::Update(float dt) {
CGuiWidget::Update(dt);
xd4_textSupport.Update(dt);
2016-03-22 02:27:46 +00:00
}
2021-06-07 19:29:18 +00:00
bool CGuiTextPane::GetIsFinishedLoadingWidgetSpecific() { return xd4_textSupport.GetIsTextSupportFinishedLoading(); }
2016-03-22 02:27:46 +00:00
2018-12-08 05:30:43 +00:00
void CGuiTextPane::SetDimensions(const zeus::CVector2f& dim, bool initVBO) {
CGuiPane::SetDimensions(dim, initVBO);
if (initVBO)
InitializeBuffers();
}
2018-12-08 05:30:43 +00:00
void CGuiTextPane::ScaleDimensions(const zeus::CVector3f& scale) {}
void CGuiTextPane::Draw(const CGuiWidgetDrawParms& parms) {
if (!GetIsVisible()) {
2018-12-08 05:30:43 +00:00
return;
}
2020-04-11 22:51:39 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CGuiTextPane::Draw {}"), m_name).c_str(), zeus::skCyan);
2016-03-22 02:27:46 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector2f dims = GetDimensions();
2016-03-22 02:27:46 +00:00
if (xd4_textSupport.x34_extentX) {
2018-12-08 05:30:43 +00:00
dims.x() /= float(xd4_textSupport.x34_extentX);
} else {
2018-12-08 05:30:43 +00:00
dims.x() = 0.f;
}
2016-03-22 02:27:46 +00:00
if (xd4_textSupport.x38_extentY) {
2018-12-08 05:30:43 +00:00
dims.y() /= float(xd4_textSupport.x38_extentY);
} else {
2018-12-08 05:30:43 +00:00
dims.y() = 0.f;
}
2016-03-22 02:27:46 +00:00
const zeus::CTransform local = zeus::CTransform::Translate(xc0_verts.front().m_pos + xc8_scaleCenter) *
zeus::CTransform::Scale(dims.x(), 1.f, dims.y());
2018-12-08 05:30:43 +00:00
CGraphics::SetModelMatrix(x34_worldXF * local);
2016-03-22 02:27:46 +00:00
2018-12-08 05:30:43 +00:00
zeus::CColor geomCol = xa8_color2;
geomCol.a() *= parms.x0_alphaMod;
xd4_textSupport.SetGeometryColor(geomCol);
2016-03-22 02:27:46 +00:00
2018-01-26 09:48:42 +00:00
#if 0
CGraphics::SetDepthWriteMode(xb6_31_depthTest, ERglEnum::LEqual, xb7_24_depthWrite);
2016-03-22 02:27:46 +00:00
switch (xac_drawFlags)
2016-03-22 02:27:46 +00:00
{
case EGuiModelDrawFlags::Shadeless:
case EGuiModelDrawFlags::Opaque:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One,
ERglBlendFactor::Zero, ERglLogicOp::Clear);
xd4_textSupport.Render();
2016-03-22 02:27:46 +00:00
break;
case EGuiModelDrawFlags::Alpha:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear);
xd4_textSupport.Render();
2016-03-22 02:27:46 +00:00
break;
case EGuiModelDrawFlags::Additive:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::One, ERglLogicOp::Clear);
xd4_textSupport.Render();
2016-03-22 02:27:46 +00:00
break;
case EGuiModelDrawFlags::AlphaAdditiveOverdraw:
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear);
xd4_textSupport.Render();
xd4_textSupport.SetGeometryColor(geomCol * zeus::CColor(geomCol.a, geomCol.a, geomCol.a, 1.f));
2016-03-22 02:27:46 +00:00
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One,
ERglBlendFactor::One, ERglLogicOp::Clear);
xd4_textSupport.Render();
2016-03-22 02:27:46 +00:00
break;
}
2017-01-29 03:58:16 +00:00
#else
2018-12-08 05:30:43 +00:00
xd4_textSupport.Render();
2017-01-29 03:58:16 +00:00
#endif
2016-03-22 02:27:46 +00:00
}
2019-01-21 04:10:34 +00:00
bool CGuiTextPane::TestCursorHit(const zeus::CMatrix4f& vp, const zeus::CVector2f& point) const {
const zeus::CVector2f dims = GetDimensions();
const zeus::CTransform local = zeus::CTransform::Translate(xc0_verts.front().m_pos + xc8_scaleCenter) *
zeus::CTransform::Scale(dims.x(), 1.f, dims.y());
const zeus::CMatrix4f mvp = vp * (x34_worldXF * local).toMatrix4f();
2019-01-21 04:10:34 +00:00
std::array<zeus::CVector2f, 4> projPoints;
for (size_t i = 0; i < projPoints.size(); ++i) {
2019-01-21 04:10:34 +00:00
projPoints[i] = mvp.multiplyOneOverW(NormalPoints[i]).toVec2f();
}
2019-01-21 04:10:34 +00:00
size_t j;
2019-01-21 04:10:34 +00:00
for (j = 0; j < 3; ++j) {
if (!testProjectedLine(projPoints[j], projPoints[j + 1], point)) {
2019-01-21 04:10:34 +00:00
break;
}
2019-01-21 04:10:34 +00:00
}
return j == 3 && testProjectedLine(projPoints[3], projPoints[0], point);
}
2018-12-08 05:30:43 +00:00
std::shared_ptr<CGuiWidget> CGuiTextPane::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp) {
const CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
const zeus::CVector2f dim = zeus::CVector2f::ReadBig(in);
const zeus::CVector3f vec = zeus::CVector3f::ReadBig(in);
const u32 fontId = in.readUint32Big();
const bool wordWrap = in.readBool();
const bool horizontal = in.readBool();
const auto justification = EJustification(in.readUint32Big());
const auto vJustification = EVerticalJustification(in.readUint32Big());
const CGuiTextProperties props(wordWrap, horizontal, justification, vJustification);
2018-12-08 05:30:43 +00:00
zeus::CColor fontCol;
fontCol.readRGBABig(in);
zeus::CColor outlineCol;
outlineCol.readRGBABig(in);
const int extentX = static_cast<int>(in.readFloatBig());
const int extentY = static_cast<int>(in.readFloatBig());
auto ret = std::make_shared<CGuiTextPane>(parms, sp, dim, vec, fontId, props, fontCol, outlineCol, extentX, extentY);
2018-12-08 05:30:43 +00:00
ret->ParseBaseInfo(frame, in, parms);
ret->InitializeBuffers();
ret->TextSupport().SetText(u"");
return ret;
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce