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)
|
2016-12-15 22:37:34 +00:00
|
|
|
: 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),
|
2017-01-09 03:44:00 +00:00
|
|
|
xb6_27_isSelectable(true), xb6_28_eventLock(false),
|
2016-12-15 22:37:34 +00:00
|
|
|
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
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiWidget::ReadWidgetHeader(CGuiFrame* frame, CInputStream& in)
|
2016-03-11 22:50:15 +00:00
|
|
|
{
|
|
|
|
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,
|
2017-01-22 01:40:12 +00:00
|
|
|
cullFaces, color, df, true, false);
|
2016-03-11 22:50:15 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 01:40:12 +00:00
|
|
|
std::shared_ptr<CGuiWidget> CGuiWidget::Create(CGuiFrame* frame, CInputStream& in, CSimplePool* sp)
|
2016-03-11 22:50:15 +00:00
|
|
|
{
|
2017-01-22 01:40:12 +00:00
|
|
|
CGuiWidgetParms parms = ReadWidgetHeader(frame, in);
|
|
|
|
std::shared_ptr<CGuiWidget> ret = std::make_shared<CGuiWidget>(parms);
|
2016-03-14 00:58:19 +00:00
|
|
|
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);
|
2017-01-22 01:40:12 +00:00
|
|
|
bool isWorker = in.readBool();
|
|
|
|
if (isWorker)
|
2016-12-15 22:37:34 +00:00
|
|
|
xb4_workerId = in.readInt16Big();
|
2017-01-22 01:40:12 +00:00
|
|
|
zeus::CVector3f trans = zeus::CVector3f::ReadBig(in);
|
|
|
|
zeus::CMatrix3f orient = zeus::CMatrix3f::ReadBig(in);
|
2016-12-15 22:37:34 +00:00
|
|
|
x74_transform = zeus::CTransform(orient, trans);
|
2016-03-14 00:58:19 +00:00
|
|
|
ReapplyXform();
|
2017-01-22 01:40:12 +00:00
|
|
|
zeus::CVector3f::ReadBig(in);
|
|
|
|
in.readUint32Big();
|
2016-12-15 22:37:34 +00:00
|
|
|
in.readUint16Big();
|
2017-01-22 01:40:12 +00:00
|
|
|
if (isWorker)
|
|
|
|
{
|
2016-03-14 00:58:19 +00:00
|
|
|
if (!parent->AddWorkerWidget(this))
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Warning,
|
|
|
|
"Warning: Discarding useless worker id. Parent is not a compound widget.");
|
2016-12-15 22:37:34 +00:00
|
|
|
xb4_workerId = -1;
|
2016-03-14 00:58:19 +00:00
|
|
|
}
|
2017-01-22 01:40:12 +00:00
|
|
|
}
|
2016-03-14 00:58:19 +00:00
|
|
|
parent->AddChildWidget(this, false, true);
|
|
|
|
}
|
|
|
|
|
2016-12-15 22:37:34 +00:00
|
|
|
void CGuiWidget::Update(float dt)
|
2016-03-14 00:58:19 +00:00
|
|
|
{
|
2016-12-15 22:37:34 +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
|
|
|
}
|
|
|
|
|
2016-12-15 22:37:34 +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
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
return xb6_25_isVisible;
|
2016-03-15 23:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGuiWidget::GetIsActive() const
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
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);
|
2016-12-15 22:37:34 +00:00
|
|
|
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)
|
2016-12-15 22:37:34 +00:00
|
|
|
xa8_color2 = xa4_color * parent->xa8_color2;
|
2016-03-15 23:23:45 +00:00
|
|
|
else
|
2016-12-15 22:37:34 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
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
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
xa4_color = color;
|
2016-03-15 23:23:45 +00:00
|
|
|
RecalcWidgetColor(ETraversalMode::Children);
|
2016-03-14 00:58:19 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 22:37:34 +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)
|
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
xb6_25_isVisible = vis;
|
|
|
|
OnVisibleChange();
|
2016-03-15 23:23:45 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 22:37:34 +00:00
|
|
|
void CGuiWidget::SetIsActive(bool a)
|
2016-03-14 00:58:19 +00:00
|
|
|
{
|
2016-12-15 22:37:34 +00:00
|
|
|
if (a != xb6_26_isActive)
|
2016-03-14 00:58:19 +00:00
|
|
|
{
|
2016-12-15 22:37:34 +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
|
|
|
}
|