metaforce/Runtime/GuiSys/CGuiWidget.cpp

257 lines
6.7 KiB
C++
Raw Normal View History

2016-03-10 03:47:37 +00:00
#include "CGuiWidget.hpp"
2016-03-11 22:50:15 +00:00
#include "CGuiFrame.hpp"
2016-03-10 03:47:37 +00:00
namespace urde
{
2016-03-14 00:58:19 +00:00
static logvisor::Module Log("urde::CGuiWidget");
2016-03-10 03:47:37 +00:00
2016-03-11 22:50:15 +00:00
CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms)
: x70_selfId(parms.x6_selfId), x72_parentId(parms.x8_parentId),
xa4_color(parms.x10_color), xa8_color2(parms.x10_color),
xac_drawFlags(parms.x14_drawFlags), xb0_frame(parms.x0_frame),
xb6_24_pg(parms.xd_g), xb6_25_isVisible(parms.xa_defaultVisible),
xb6_26_isActive(parms.xb_defaultActive),
xb6_27_(true), xb6_28_eventLock(false),
xb6_29_cullFaces(parms.xc_cullFaces), xb6_30_(false),
xb6_31_depthTest(true), xb7_24_depthWrite(false), xb7_25_(true)
2016-03-11 22:50:15 +00:00
{
2016-03-15 23:23:45 +00:00
RecalcWidgetColor(ETraversalMode::Single);
2016-03-11 22:50:15 +00:00
}
CGuiWidget::CGuiWidgetParms
CGuiWidget::ReadWidgetHeader(CGuiFrame* frame, CInputStream& in, bool flag)
{
std::string name = in.readString(-1);
s16 selfId = frame->GetWidgetIdDB().AddWidget(name);
std::string parent = in.readString(-1);
s16 parentId = frame->GetWidgetIdDB().AddWidget(parent);
2016-03-16 03:37:51 +00:00
bool useAnimController = in.readBool();
2016-03-15 23:23:45 +00:00
bool defaultVis = in.readBool();
bool defaultActive = in.readBool();
2016-03-17 02:18:01 +00:00
bool cullFaces = in.readBool();
2016-03-11 22:50:15 +00:00
zeus::CColor color;
2016-03-14 00:58:19 +00:00
color.readRGBABig(in);
2016-03-11 22:50:15 +00:00
EGuiModelDrawFlags df = EGuiModelDrawFlags(in.readUint32Big());
2016-03-16 03:37:51 +00:00
return CGuiWidget::CGuiWidgetParms(frame, useAnimController, selfId,
parentId, defaultVis, defaultActive,
2016-03-17 02:18:01 +00:00
cullFaces, color, df, true, flag);
2016-03-11 22:50:15 +00:00
}
2016-03-14 00:58:19 +00:00
CGuiWidget* CGuiWidget::Create(CGuiFrame* frame, CInputStream& in, bool flag)
2016-03-11 22:50:15 +00:00
{
2016-03-14 00:58:19 +00:00
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
CGuiWidget* ret = new CGuiWidget(parms);
ret->ParseBaseInfo(frame, in, parms);
return ret;
}
2016-12-16 04:35:49 +00:00
void CGuiWidget::Initialize()
2016-03-14 23:32:44 +00:00
{
}
2016-03-14 00:58:19 +00:00
void CGuiWidget::ParseBaseInfo(CGuiFrame* frame, CInputStream& in, const CGuiWidgetParms& parms)
{
CGuiWidget* parent = frame->FindWidget(parms.x8_parentId);
bool a = in.readBool();
if (a)
xb4_workerId = in.readInt16Big();
2016-03-14 00:58:19 +00:00
zeus::CVector3f trans;
trans.readBig(in);
zeus::CMatrix3f orient;
orient.readBig(in);
x74_transform = zeus::CTransform(orient, trans);
2016-03-14 00:58:19 +00:00
ReapplyXform();
zeus::CVector3f rotCenter;
rotCenter.readBig(in);
SetRotationCenter(rotCenter);
in.readUint16Big();
2016-03-14 00:58:19 +00:00
if (a)
if (!parent->AddWorkerWidget(this))
{
Log.report(logvisor::Warning,
"Warning: Discarding useless worker id. Parent is not a compound widget.");
xb4_workerId = -1;
2016-03-14 00:58:19 +00:00
}
parent->AddChildWidget(this, false, true);
}
void CGuiWidget::Update(float dt)
2016-03-14 00:58:19 +00:00
{
CGuiWidget* ch = static_cast<CGuiWidget*>(GetChildObject());
if (ch)
ch->Update(dt);
CGuiWidget* sib = static_cast<CGuiWidget*>(GetNextSibling());
if (sib)
sib->Update(dt);
2016-03-15 23:23:45 +00:00
}
void CGuiWidget::Draw(const CGuiWidgetDrawParms&) const {}
2016-12-16 04:35:49 +00:00
void CGuiWidget::ProcessUserInput(const CFinalInput& input) {}
2016-03-15 23:23:45 +00:00
void CGuiWidget::Touch() const {}
bool CGuiWidget::GetIsVisible() const
{
return xb6_25_isVisible;
2016-03-15 23:23:45 +00:00
}
bool CGuiWidget::GetIsActive() const
{
return xb6_26_isActive;
2016-03-15 23:23:45 +00:00
}
void CGuiWidget::InitializeRGBAFactor()
{
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->InitializeRGBAFactor();
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->InitializeRGBAFactor();
}
bool CGuiWidget::GetIsFinishedLoadingWidgetSpecific() const
{
return true;
}
void CGuiWidget::SetIdlePosition(const zeus::CVector3f& pos, bool reapply)
{
x74_transform.origin = pos;
2016-03-15 23:23:45 +00:00
if (reapply)
ReapplyXform();
}
2016-03-14 00:58:19 +00:00
void CGuiWidget::ReapplyXform()
{
RotateReset();
SetLocalPosition(zeus::CVector3f::skZero);
MultiplyO2P(x74_transform);
2016-03-15 23:23:45 +00:00
}
void CGuiWidget::AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool atEnd)
{
AddChildObject(widget, makeWorldLocal, atEnd);
}
2016-03-16 20:49:35 +00:00
bool CGuiWidget::AddWorkerWidget(CGuiWidget* worker)
{
return false;
}
2016-03-15 23:23:45 +00:00
void CGuiWidget::SetVisibility(bool vis, ETraversalMode mode)
{
switch (mode)
{
case ETraversalMode::Children:
{
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
break;
}
case ETraversalMode::ChildrenAndSiblings:
{
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->SetVisibility(vis, ETraversalMode::ChildrenAndSiblings);
break;
}
default: break;
}
SetIsVisible(vis);
}
void CGuiWidget::RecalcWidgetColor(ETraversalMode mode)
{
CGuiWidget* parent = static_cast<CGuiWidget*>(GetParent());
if (parent)
xa8_color2 = xa4_color * parent->xa8_color2;
2016-03-15 23:23:45 +00:00
else
xa8_color2 = xa4_color;
2016-03-15 23:23:45 +00:00
switch (mode)
{
case ETraversalMode::ChildrenAndSiblings:
{
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
nextSib->RecalcWidgetColor(ETraversalMode::ChildrenAndSiblings);
}
case ETraversalMode::Children:
{
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
child->RecalcWidgetColor(ETraversalMode::ChildrenAndSiblings);
}
default: break;
}
}
CGuiWidget* CGuiWidget::FindWidget(s16 id)
{
if (x70_selfId == id)
2016-03-15 23:23:45 +00:00
return this;
CGuiWidget* child = static_cast<CGuiWidget*>(GetChildObject());
if (child)
{
CGuiWidget* found = child->FindWidget(id);
if (found)
return found;
}
CGuiWidget* nextSib = static_cast<CGuiWidget*>(GetNextSibling());
if (nextSib)
{
CGuiWidget* found = nextSib->FindWidget(id);
if (found)
return found;
}
return nullptr;
}
bool CGuiWidget::GetIsFinishedLoading() const
{
return GetIsFinishedLoadingWidgetSpecific();
2016-03-15 23:23:45 +00:00
}
2016-03-14 00:58:19 +00:00
2016-12-16 04:35:49 +00:00
void CGuiWidget::DispatchInitialize()
2016-03-14 00:58:19 +00:00
{
Initialize();
CGuiWidget* ch = static_cast<CGuiWidget*>(GetChildObject());
if (ch)
2016-12-16 04:35:49 +00:00
ch->DispatchInitialize();
2016-03-14 00:58:19 +00:00
CGuiWidget* sib = static_cast<CGuiWidget*>(GetNextSibling());
if (sib)
2016-12-16 04:35:49 +00:00
sib->DispatchInitialize();
2016-03-14 00:58:19 +00:00
}
void CGuiWidget::SetColor(const zeus::CColor& color)
{
xa4_color = color;
2016-03-15 23:23:45 +00:00
RecalcWidgetColor(ETraversalMode::Children);
2016-03-14 00:58:19 +00:00
}
void CGuiWidget::OnActiveChange() {}
void CGuiWidget::OnVisibleChange() {}
2016-03-14 00:58:19 +00:00
2016-03-15 23:23:45 +00:00
void CGuiWidget::SetIsVisible(bool vis)
{
xb6_25_isVisible = vis;
OnVisibleChange();
2016-03-15 23:23:45 +00:00
}
void CGuiWidget::SetIsActive(bool a)
2016-03-14 00:58:19 +00:00
{
if (a != xb6_26_isActive)
2016-03-14 00:58:19 +00:00
{
xb6_26_isActive = a;
OnActiveChange();
2016-03-14 00:58:19 +00:00
}
2016-03-11 22:50:15 +00:00
}
2016-03-10 03:47:37 +00:00
}