2018-09-06 23:26:32 +08:00
|
|
|
|
#include "..\e2dobject.h"
|
2018-08-14 00:41:59 +08:00
|
|
|
|
#include "..\e2devent.h"
|
2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dmanager.h"
|
|
|
|
|
|
#include "..\e2daction.h"
|
2017-10-12 23:34:13 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::Node::Property e2d::Node::Property::Origin = { };
|
2018-07-10 00:30:17 +08:00
|
|
|
|
|
|
|
|
|
|
e2d::Node::Property e2d::Node::Property::operator+(Property const & prop) const
|
|
|
|
|
|
{
|
|
|
|
|
|
Property result;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
result.pos = this->pos + prop.pos;
|
|
|
|
|
|
result.size = this->size + prop.size;
|
|
|
|
|
|
result.anchor = this->anchor + prop.anchor;
|
|
|
|
|
|
result.scale = this->scale + prop.scale;
|
|
|
|
|
|
result.skew = this->skew + prop.skew;
|
2018-07-10 00:30:17 +08:00
|
|
|
|
result.rotation = this->rotation + prop.rotation;
|
|
|
|
|
|
return std::move(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Node::Property e2d::Node::Property::operator-(Property const & prop) const
|
|
|
|
|
|
{
|
|
|
|
|
|
Property result;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
result.pos = this->pos - prop.pos;
|
|
|
|
|
|
result.size = this->size - prop.size;
|
|
|
|
|
|
result.anchor = this->anchor - prop.anchor;
|
|
|
|
|
|
result.scale = this->scale - prop.scale;
|
|
|
|
|
|
result.skew = this->skew - prop.skew;
|
2018-07-10 00:30:17 +08:00
|
|
|
|
result.rotation = this->rotation - prop.rotation;
|
|
|
|
|
|
return std::move(result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-09 18:22:41 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node::Node()
|
2018-09-05 00:08:03 +08:00
|
|
|
|
: visible_(true)
|
|
|
|
|
|
, parent_(nullptr)
|
|
|
|
|
|
, parent_scene_(nullptr)
|
|
|
|
|
|
, hash_name_(0)
|
|
|
|
|
|
, clip_enabled_(false)
|
2018-09-10 11:32:51 +08:00
|
|
|
|
, dirty_sort_(false)
|
|
|
|
|
|
, dirty_transform_(false)
|
2018-09-05 00:08:03 +08:00
|
|
|
|
, fixed_position_(false)
|
|
|
|
|
|
, collider_(this)
|
|
|
|
|
|
, border_(nullptr)
|
|
|
|
|
|
, order_(0)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
, pos_()
|
|
|
|
|
|
, size_()
|
|
|
|
|
|
, scale_(1.f, 1.f)
|
|
|
|
|
|
, rotation_(0)
|
|
|
|
|
|
, skew_(0, 0)
|
|
|
|
|
|
, display_opacity_(1.f)
|
|
|
|
|
|
, real_opacity_(1.f)
|
|
|
|
|
|
, anchor_()
|
2018-09-05 00:08:03 +08:00
|
|
|
|
, children_()
|
|
|
|
|
|
, actions_()
|
2018-09-07 18:20:07 +08:00
|
|
|
|
, tasks_()
|
2018-09-04 22:42:34 +08:00
|
|
|
|
, initial_matrix_(D2D1::Matrix3x2F::Identity())
|
|
|
|
|
|
, final_matrix_(D2D1::Matrix3x2F::Identity())
|
|
|
|
|
|
, border_color_(Color::Red, 0.6f)
|
|
|
|
|
|
, extrapolate_(Property::Origin)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node::~Node()
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(border_);
|
2018-09-01 23:00:08 +08:00
|
|
|
|
|
2018-09-07 00:28:54 +08:00
|
|
|
|
for (auto action : actions_)
|
2018-09-05 00:08:03 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
SafeRelease(action);
|
2018-09-05 00:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-07 23:47:21 +08:00
|
|
|
|
for (auto task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
SafeRelease(task);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-07 00:28:54 +08:00
|
|
|
|
for (auto child : children_)
|
2018-07-07 01:43:41 +08:00
|
|
|
|
{
|
2018-09-07 00:28:54 +08:00
|
|
|
|
SafeRelease(child);
|
2018-07-07 01:43:41 +08:00
|
|
|
|
}
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::Visit()
|
2017-10-13 11:42:36 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!visible_)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!Game::GetInstance()->IsPaused())
|
2018-08-19 17:46:37 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
UpdateActions();
|
2018-09-07 18:20:07 +08:00
|
|
|
|
UpdateTasks();
|
2018-09-05 00:08:03 +08:00
|
|
|
|
|
2018-08-19 17:46:37 +08:00
|
|
|
|
auto updatableNode = dynamic_cast<Updatable*>(this);
|
|
|
|
|
|
if (updatableNode)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
updatableNode->Update();
|
2018-08-19 17:46:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-13 01:59:04 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UpdateTransform();
|
|
|
|
|
|
extrapolate_ = this->GetProperty();
|
2018-09-01 23:00:08 +08:00
|
|
|
|
|
2018-09-05 00:09:23 +08:00
|
|
|
|
auto render_target = Renderer::GetInstance()->GetRenderTarget();
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (clip_enabled_)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-05 00:09:23 +08:00
|
|
|
|
render_target->SetTransform(final_matrix_);
|
|
|
|
|
|
render_target->PushAxisAlignedClip(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
D2D1::RectF(0, 0, size_.width, size_.height),
|
2018-07-28 18:44:37 +08:00
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (children_.empty())
|
2018-06-01 17:53:56 +08:00
|
|
|
|
{
|
2018-08-19 17:46:37 +08:00
|
|
|
|
auto drawableNode = dynamic_cast<Drawable*>(this);
|
|
|
|
|
|
if (drawableNode)
|
|
|
|
|
|
{
|
2018-09-05 00:09:23 +08:00
|
|
|
|
render_target->SetTransform(final_matrix_);
|
2018-09-04 22:42:34 +08:00
|
|
|
|
drawableNode->Draw();
|
2018-08-19 17:46:37 +08:00
|
|
|
|
}
|
2018-06-01 17:53:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-06-01 17:53:56 +08:00
|
|
|
|
// <20>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-10 11:32:51 +08:00
|
|
|
|
if (dirty_sort_)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::sort(
|
|
|
|
|
|
std::begin(children_),
|
|
|
|
|
|
std::end(children_),
|
|
|
|
|
|
[](Node * n1, Node * n2) { return n1->GetOrder() < n2->GetOrder(); }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
dirty_sort_ = false;
|
|
|
|
|
|
}
|
2018-06-01 17:53:56 +08:00
|
|
|
|
|
2018-01-30 16:45:38 +08:00
|
|
|
|
size_t i;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (i = 0; i < children_.size(); ++i)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto child = children_[i];
|
2018-01-30 16:45:38 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> Order С<><D0A1><EFBFBD><EFBFBD><EFBFBD>Ľڵ<C4BD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (child->GetOrder() < 0)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->Visit();
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-19 17:46:37 +08:00
|
|
|
|
|
|
|
|
|
|
auto drawableNode = dynamic_cast<Drawable*>(this);
|
|
|
|
|
|
if (drawableNode)
|
|
|
|
|
|
{
|
2018-09-05 00:09:23 +08:00
|
|
|
|
render_target->SetTransform(final_matrix_);
|
2018-09-04 22:42:34 +08:00
|
|
|
|
drawableNode->Draw();
|
2018-08-19 17:46:37 +08:00
|
|
|
|
}
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ڵ<EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (; i < children_.size(); ++i)
|
|
|
|
|
|
children_[i]->Visit();
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
2018-07-28 18:44:37 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (clip_enabled_)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-05 00:09:23 +08:00
|
|
|
|
render_target->PopAxisAlignedClip();
|
2018-07-28 18:44:37 +08:00
|
|
|
|
}
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::DrawBorder()
|
2018-07-07 18:04:18 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (visible_)
|
2018-07-07 18:04:18 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (border_)
|
2018-09-01 23:00:08 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto renderer = Renderer::GetInstance();
|
|
|
|
|
|
auto brush = renderer->GetSolidBrush();
|
|
|
|
|
|
brush->SetColor(D2D1_COLOR_F(border_color_));
|
|
|
|
|
|
renderer->GetRenderTarget()->DrawGeometry(
|
|
|
|
|
|
border_,
|
2018-09-01 23:00:08 +08:00
|
|
|
|
brush,
|
|
|
|
|
|
1.5f
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2018-07-07 18:04:18 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->DrawBorder();
|
2018-07-28 18:44:37 +08:00
|
|
|
|
}
|
2018-07-07 18:04:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::DrawCollider()
|
2017-10-29 23:48:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (visible_)
|
2018-07-24 00:24:29 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
collider_.Draw();
|
2017-10-29 23:48:32 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->DrawCollider();
|
2018-07-28 18:44:37 +08:00
|
|
|
|
}
|
2017-10-29 23:48:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::UpdateTransform()
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-10 11:32:51 +08:00
|
|
|
|
if (!dirty_transform_)
|
2018-06-01 17:53:56 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = false;
|
2018-07-13 00:45:39 +08:00
|
|
|
|
|
2018-08-23 16:58:32 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ê<EFBFBD><C3AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
D2D1_POINT_2F anchor = { size_.width * anchor_.x, size_.height * anchor_.y };
|
2018-07-13 01:59:04 +08:00
|
|
|
|
// <20>任 Initial <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ㽫<DAB5><E3BDAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б任
|
2018-09-04 22:42:34 +08:00
|
|
|
|
initial_matrix_ = D2D1::Matrix3x2F::Scale(
|
|
|
|
|
|
scale_.x,
|
|
|
|
|
|
scale_.y,
|
2018-08-23 16:58:32 +08:00
|
|
|
|
anchor
|
2018-07-13 01:59:04 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Skew(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
skew_.x,
|
|
|
|
|
|
skew_.y,
|
2018-08-23 16:58:32 +08:00
|
|
|
|
anchor
|
2018-07-13 01:59:04 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Rotation(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
rotation_,
|
2018-08-23 16:58:32 +08:00
|
|
|
|
anchor
|
2018-07-13 01:59:04 +08:00
|
|
|
|
) * D2D1::Matrix3x2F::Translation(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
pos_.x,
|
|
|
|
|
|
pos_.y
|
2018-07-13 01:59:04 +08:00
|
|
|
|
);
|
2018-08-23 16:58:32 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ê<EFBFBD><C3AA><EFBFBD>任 Final <20><><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
final_matrix_ = initial_matrix_ * D2D1::Matrix3x2F::Translation(-anchor.x, -anchor.y);
|
2018-07-13 01:59:04 +08:00
|
|
|
|
// <20><EFBFBD><CDB8>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!fixed_position_ && parent_)
|
2018-07-13 00:45:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
initial_matrix_ = initial_matrix_ * parent_->initial_matrix_;
|
|
|
|
|
|
final_matrix_ = final_matrix_ * parent_->initial_matrix_;
|
2018-07-13 00:45:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-01 23:00:08 +08:00
|
|
|
|
// <20><><EFBFBD>¹<EFBFBD><C2B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
SafeRelease(border_);
|
2018-09-01 23:00:08 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
ID2D1Factory * factory = Renderer::GetFactory();
|
2018-09-01 23:00:08 +08:00
|
|
|
|
ID2D1RectangleGeometry * rectangle = nullptr;
|
|
|
|
|
|
ID2D1TransformedGeometry * transformed = nullptr;
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
|
|
factory->CreateRectangleGeometry(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
D2D1::RectF(0, 0, size_.width, size_.height),
|
2018-09-01 23:00:08 +08:00
|
|
|
|
&rectangle
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
|
|
|
|
|
ThrowIfFailed(
|
|
|
|
|
|
factory->CreateTransformedGeometry(
|
|
|
|
|
|
rectangle,
|
2018-09-04 22:42:34 +08:00
|
|
|
|
final_matrix_,
|
2018-09-01 23:00:08 +08:00
|
|
|
|
&transformed
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2018-09-04 22:42:34 +08:00
|
|
|
|
border_ = transformed;
|
2018-09-01 23:00:08 +08:00
|
|
|
|
|
|
|
|
|
|
SafeRelease(rectangle);
|
|
|
|
|
|
|
2018-07-13 00:45:39 +08:00
|
|
|
|
// ֪ͨ<CDA8>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2018-07-13 00:45:39 +08:00
|
|
|
|
{
|
2018-09-10 11:32:51 +08:00
|
|
|
|
child->dirty_transform_ = true;
|
2018-07-13 00:45:39 +08:00
|
|
|
|
}
|
2018-08-13 23:24:08 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
collider_.Recreate();
|
2018-08-13 23:24:08 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (collider_.IsEnabled() &&
|
|
|
|
|
|
collider_.IsCollisionNotify() &&
|
|
|
|
|
|
collider_.GetShape() != Collider::Shape::None)
|
2018-08-13 23:24:08 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
CollisionManager::GetInstance()->UpdateCollider(&collider_);
|
2018-08-13 23:24:08 +08:00
|
|
|
|
}
|
2018-07-13 00:45:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::Dispatch(const MouseEvent & e, bool handled)
|
2018-07-16 22:11:27 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (visible_)
|
2018-08-12 14:30:28 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
|
|
|
|
|
handled = (*riter)->Dispatch(e, handled);
|
2018-08-19 17:46:37 +08:00
|
|
|
|
|
|
|
|
|
|
auto handler = dynamic_cast<MouseEventHandler*>(this);
|
|
|
|
|
|
if (handler)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
handler->Handle(e);
|
2018-08-12 14:30:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-13 23:24:08 +08:00
|
|
|
|
return handled;
|
2018-07-16 22:11:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::Dispatch(const KeyEvent & e, bool handled)
|
2018-07-16 22:11:27 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (visible_)
|
2018-08-12 14:30:28 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (auto riter = children_.crbegin(); riter != children_.crend(); ++riter)
|
|
|
|
|
|
handled = (*riter)->Dispatch(e, handled);
|
2018-08-19 17:46:37 +08:00
|
|
|
|
|
|
|
|
|
|
auto handler = dynamic_cast<KeyEventHandler*>(this);
|
|
|
|
|
|
if (handler)
|
2018-09-04 22:42:34 +08:00
|
|
|
|
handler->Handle(e);
|
2018-08-12 14:30:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-13 23:24:08 +08:00
|
|
|
|
return handled;
|
2018-07-16 22:11:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::UpdateOpacity()
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (parent_)
|
2018-04-24 10:35:58 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
display_opacity_ = real_opacity_ * parent_->display_opacity_;
|
2018-04-24 10:35:58 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->UpdateOpacity();
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-05 00:08:03 +08:00
|
|
|
|
void e2d::Node::UpdateActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Action*> currActions;
|
|
|
|
|
|
currActions.reserve(actions_.size());
|
|
|
|
|
|
std::copy_if(
|
|
|
|
|
|
actions_.begin(),
|
|
|
|
|
|
actions_.end(),
|
|
|
|
|
|
std::back_inserter(currActions),
|
|
|
|
|
|
[](Action* action) { return action->IsRunning() && !action->IsDone(); }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<D0B5><C4B6><EFBFBD>
|
|
|
|
|
|
for (const auto& action : currActions)
|
|
|
|
|
|
action->Update();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵĶ<C9B5><C4B6><EFBFBD>
|
|
|
|
|
|
for (auto iter = actions_.begin(); iter != actions_.end();)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((*iter)->IsDone())
|
|
|
|
|
|
{
|
|
|
|
|
|
(*iter)->Release();
|
|
|
|
|
|
iter = actions_.erase(iter);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
++iter;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::IsVisible() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return visible_;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const e2d::String& e2d::Node::GetName() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return name_;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_t e2d::Node::GetHashName() const
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return hash_name_;
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetPosX() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return pos_.x;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetPosY() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return pos_.y;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-09 12:21:15 +08:00
|
|
|
|
const e2d::Point& e2d::Node::GetPos() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-09 12:21:15 +08:00
|
|
|
|
return pos_;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetWidth() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return size_.width * scale_.x;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetHeight() const
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return size_.height * scale_.y;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetRealWidth() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return size_.width;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetRealHeight() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return size_.height;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-09 12:21:15 +08:00
|
|
|
|
const e2d::Size& e2d::Node::GetRealSize() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-09 12:21:15 +08:00
|
|
|
|
return size_;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetAnchorX() const
|
2017-10-26 17:17:30 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return anchor_.x;
|
2017-10-26 17:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetAnchorY() const
|
2017-10-26 17:17:30 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return anchor_.y;
|
2017-10-26 17:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Size e2d::Node::GetSize() const
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return Size(GetWidth(), GetHeight());
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetScaleX() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return scale_.x;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetScaleY() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return scale_.y;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetSkewX() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return skew_.x;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetSkewY() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return skew_.y;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetRotation() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return rotation_;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
float e2d::Node::GetOpacity() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return real_opacity_;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Node::Property e2d::Node::GetProperty() const
|
2018-04-21 18:42:07 +08:00
|
|
|
|
{
|
2018-05-17 15:22:14 +08:00
|
|
|
|
Property prop;
|
2018-09-04 22:42:34 +08:00
|
|
|
|
prop.pos = pos_;
|
|
|
|
|
|
prop.size = size_;
|
|
|
|
|
|
prop.anchor = anchor_;
|
|
|
|
|
|
prop.scale = scale_;
|
|
|
|
|
|
prop.rotation = rotation_;
|
|
|
|
|
|
prop.skew = skew_;
|
2018-07-10 00:30:17 +08:00
|
|
|
|
return std::move(prop);
|
2018-04-21 18:42:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Node::Property e2d::Node::GetExtrapolate() const
|
2018-07-13 00:45:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return this->GetProperty() - extrapolate_;
|
2018-07-13 00:45:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Collider* e2d::Node::GetCollider()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return &collider_;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
int e2d::Node::GetOrder() const
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return order_;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetOrder(int order)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (order_ == order)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2018-07-28 18:44:37 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
order_ = order;
|
|
|
|
|
|
if (parent_)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-10 11:32:51 +08:00
|
|
|
|
parent_->dirty_sort_ = true;
|
2018-07-28 18:44:37 +08:00
|
|
|
|
}
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetPosX(float x)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetPos(x, pos_.y);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetPosY(float y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetPos(pos_.x, y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetPos(const Point & p)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetPos(p.x, p.y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetPos(float x, float y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (pos_.x == x && pos_.y == y)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
pos_.x = x;
|
|
|
|
|
|
pos_.y = y;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetPosFixed(bool fixed)
|
2018-05-07 17:15:57 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (fixed_position_ == fixed)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2018-05-07 17:15:57 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
fixed_position_ = fixed;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2018-05-07 17:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::Move(float x, float y)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetPos(pos_.x + x, pos_.y + y);
|
2018-08-23 16:37:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::Move(const Point & v)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->Move(v.x, v.y);
|
2018-08-23 16:37:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetScaleX(float scale_x)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetScale(scale_x, scale_.y);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetScaleY(float scale_y)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetScale(scale_.x, scale_y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetScale(float scale)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetScale(scale, scale);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetScale(float scale_x, float scale_y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (scale_.x == scale_x && scale_.y == scale_y)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
scale_.x = scale_x;
|
|
|
|
|
|
scale_.y = scale_y;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetSkewX(float skew_x)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSkew(skew_x, skew_.y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetSkewY(float skew_y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSkew(skew_.x, skew_y);
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetSkew(float skew_x, float skew_y)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (skew_.x == skew_x && skew_.y == skew_y)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
skew_.x = skew_x;
|
|
|
|
|
|
skew_.y = skew_y;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetRotation(float angle)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (rotation_ == angle)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
rotation_ = angle;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2017-10-15 02:46:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetOpacity(float opacity)
|
2017-10-15 02:46:24 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (real_opacity_ == opacity)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-15 23:58:39 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
display_opacity_ = real_opacity_ = std::min(std::max(opacity, 0.f), 1.f);
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><><EFBFBD>½ڵ<C2BD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UpdateOpacity();
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetAnchorX(float anchor_x)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetAnchor(anchor_x, anchor_.y);
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetAnchorY(float anchor_y)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetAnchor(anchor_.x, anchor_y);
|
2017-10-15 23:58:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetAnchor(float anchor_x, float anchor_y)
|
2017-10-15 23:58:39 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (anchor_.x == anchor_x && anchor_.y == anchor_y)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-15 23:58:39 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
anchor_.x = std::min(std::max(anchor_x, 0.f), 1.f);
|
|
|
|
|
|
anchor_.y = std::min(std::max(anchor_y, 0.f), 1.f);
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetWidth(float width)
|
2018-03-01 19:28:22 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(width, size_.height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetHeight(float height)
|
2018-03-01 19:28:22 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(size_.width, height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetSize(float width, float height)
|
2018-03-01 19:28:22 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (size_.width == width && size_.height == height)
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2018-03-01 19:28:22 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_.width = width;
|
|
|
|
|
|
size_.height = height;
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_transform_ = true;
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetSize(Size size)
|
2018-03-01 19:28:22 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetSize(size.width, size.height);
|
2018-03-01 19:28:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetProperty(Property prop)
|
2018-04-21 18:42:07 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->SetPos(prop.pos.x, prop.pos.y);
|
|
|
|
|
|
this->SetSize(prop.size.width, prop.size.height);
|
|
|
|
|
|
this->SetAnchor(prop.anchor.x, prop.anchor.y);
|
|
|
|
|
|
this->SetScale(prop.scale.x, prop.scale.y);
|
|
|
|
|
|
this->SetRotation(prop.rotation);
|
|
|
|
|
|
this->SetSkew(prop.skew.x, prop.skew.y);
|
2018-04-21 18:42:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetClipEnabled(bool enabled)
|
2018-07-28 18:44:37 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
clip_enabled_ = enabled;
|
2018-07-28 18:44:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetBorderColor(const Color & color)
|
2018-09-01 23:00:08 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
border_color_ = color;
|
2018-09-01 23:00:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::AddChild(Node * child, int order /* = 0 */)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN_IF(child == nullptr, "Node::AddChild NULL pointer exception.");
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (child->parent_ != nullptr)
|
2018-05-24 00:58:16 +08:00
|
|
|
|
{
|
2018-09-10 20:55:20 +08:00
|
|
|
|
throw RuntimeException("<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><EFBFBD>ڵ<EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>");
|
2018-05-24 00:58:16 +08:00
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (Node * parent = this; parent != nullptr; parent = parent->GetParent())
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-05-24 00:58:16 +08:00
|
|
|
|
if (child == parent)
|
|
|
|
|
|
{
|
2018-09-10 20:55:20 +08:00
|
|
|
|
throw RuntimeException("һ<EFBFBD><EFBFBD><EFBFBD>ڵ㲻<EFBFBD><EFBFBD>ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD>ĸ<EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ<EFBFBD>");
|
2018-05-24 00:58:16 +08:00
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->Retain();
|
|
|
|
|
|
children_.push_back(child);
|
|
|
|
|
|
child->SetOrder(order);
|
|
|
|
|
|
child->parent_ = this;
|
|
|
|
|
|
if (this->parent_scene_)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->SetParentScene(this->parent_scene_);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->UpdateOpacity();
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD>½ڵ<C2BD>ת<EFBFBD><D7AA>
|
2018-09-10 11:32:51 +08:00
|
|
|
|
child->dirty_transform_ = true;
|
2017-11-09 18:22:41 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-10 11:32:51 +08:00
|
|
|
|
dirty_sort_ = true;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::AddChild(const Nodes& nodes, int order)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-08-12 14:30:28 +08:00
|
|
|
|
for (const auto& node : nodes)
|
2018-03-31 18:12:01 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
this->AddChild(node, order);
|
2018-03-31 18:12:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Node * e2d::Node::GetParent() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return parent_;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Scene * e2d::Node::GetParentScene() const
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return parent_scene_;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Node::Nodes e2d::Node::GetChildren(const String& name) const
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
Nodes children;
|
|
|
|
|
|
size_t hash = name.GetHash();
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><C6BF>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> Hash ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱȽ<C8B1> Hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (child->hash_name_ == hash && child->name_ == name)
|
2018-03-11 23:56:40 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
children.push_back(child);
|
2018-03-11 23:56:40 +08:00
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return std::move(children);
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
e2d::Node * e2d::Node::GetChild(const String& name) const
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_t hash = name.GetHash();
|
2018-04-24 13:28:21 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><C6BF>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC> Hash ֵ<><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȱȽ<C8B1> Hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (child->hash_name_ == hash && child->name_ == name)
|
2018-04-24 13:28:21 +08:00
|
|
|
|
{
|
|
|
|
|
|
return child;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
const std::vector<e2d::Node*>& e2d::Node::GetAllChildren() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return children_;
|
2018-03-11 23:56:40 +08:00
|
|
|
|
}
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
int e2d::Node::GetChildrenCount() const
|
2018-03-11 23:56:40 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
return static_cast<int>(children_.size());
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::RemoveFromParent()
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (parent_)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
parent_->RemoveChild(this);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::RemoveChild(Node * child)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception.");
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (children_.empty())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return false;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
auto iter = std::find(children_.begin(), children_.end(), child);
|
|
|
|
|
|
if (iter != children_.end())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
children_.erase(iter);
|
|
|
|
|
|
child->parent_ = nullptr;
|
2018-02-03 22:04:43 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (child->parent_scene_)
|
2018-05-21 23:04:58 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->SetParentScene(nullptr);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2018-05-21 23:04:58 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->Release();
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return true;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return false;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::RemoveChildren(const String& child_name)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN_IF(child_name.IsEmpty(), "Invalid Node name.");
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (children_.empty())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-08-23 16:37:51 +08:00
|
|
|
|
return;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Hash ֵ
|
2018-09-04 22:42:34 +08:00
|
|
|
|
size_t hash = child_name.GetHash();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2018-08-12 15:38:02 +08:00
|
|
|
|
auto iter = std::find_if(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
children_.begin(),
|
|
|
|
|
|
children_.end(),
|
|
|
|
|
|
[child_name, hash](Node* child) ->bool { return child->hash_name_ == hash && child->name_ == child_name; }
|
2018-08-12 15:38:02 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (iter != children_.end())
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
(*iter)->parent_ = nullptr;
|
|
|
|
|
|
if ((*iter)->parent_scene_)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
(*iter)->SetParentScene(nullptr);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2018-09-04 22:42:34 +08:00
|
|
|
|
(*iter)->Release();
|
|
|
|
|
|
children_.erase(iter);
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::RemoveAllChildren()
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>нڵ<D0BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
|
2018-09-04 22:42:34 +08:00
|
|
|
|
for (const auto& child : children_)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->Release();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
children_.clear();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::RunAction(Action * action)
|
2017-10-19 00:50:04 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
WARN_IF(action == nullptr, "Action NULL pointer exception!");
|
|
|
|
|
|
|
|
|
|
|
|
if (action)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (action->GetTarget() == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto iter = std::find(actions_.begin(), actions_.end(), action);
|
|
|
|
|
|
if (iter == actions_.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
action->Retain();
|
|
|
|
|
|
action->StartWithTarget(this);
|
|
|
|
|
|
actions_.push_back(action);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-09-10 20:55:20 +08:00
|
|
|
|
throw RuntimeException("<EFBFBD><EFBFBD> Action <20><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>Ŀ<EFBFBD><C4BF>");
|
2018-09-05 00:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-19 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::ResumeAction(const String& name)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
2017-10-19 12:47:36 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (action->GetName() == name)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->Resume();
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::PauseAction(const String& name)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (action->GetName() == name)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->Pause();
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::StopAction(const String& name)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (action->GetName() == name)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
action->Stop();
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::ContainsPoint(const Point& point)
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (size_.width == 0.f || size_.height == 0.f)
|
2018-09-01 23:00:08 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UpdateTransform();
|
2018-07-29 13:44:53 +08:00
|
|
|
|
|
|
|
|
|
|
BOOL ret = 0;
|
2018-08-15 00:06:03 +08:00
|
|
|
|
ThrowIfFailed(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
border_->FillContainsPoint(
|
2018-07-28 20:06:27 +08:00
|
|
|
|
D2D1::Point2F(point.x, point.y),
|
2018-09-01 23:00:08 +08:00
|
|
|
|
D2D1::Matrix3x2F::Identity(),
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&ret
|
2018-08-15 00:06:03 +08:00
|
|
|
|
)
|
|
|
|
|
|
);
|
2018-07-29 13:44:53 +08:00
|
|
|
|
return ret != 0;
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
bool e2d::Node::Intersects(Node * node)
|
2018-03-06 09:56:17 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (size_.width == 0.f || size_.height == 0.f || node->size_.width == 0.f || node->size_.height == 0.f)
|
2018-09-01 23:00:08 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2018-07-29 13:44:53 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
UpdateTransform();
|
|
|
|
|
|
node->UpdateTransform();
|
2018-07-29 13:44:53 +08:00
|
|
|
|
|
2018-09-01 23:00:08 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>ཻ״̬
|
2018-07-29 13:44:53 +08:00
|
|
|
|
D2D1_GEOMETRY_RELATION relation = D2D1_GEOMETRY_RELATION_UNKNOWN;
|
2018-08-15 00:06:03 +08:00
|
|
|
|
ThrowIfFailed(
|
2018-09-04 22:42:34 +08:00
|
|
|
|
border_->CompareWithGeometry(
|
|
|
|
|
|
node->border_,
|
2018-07-07 18:04:18 +08:00
|
|
|
|
D2D1::Matrix3x2F::Identity(),
|
2018-03-14 15:33:58 +08:00
|
|
|
|
&relation
|
2018-08-15 00:06:03 +08:00
|
|
|
|
)
|
|
|
|
|
|
);
|
2018-07-29 13:44:53 +08:00
|
|
|
|
return relation != D2D1_GEOMETRY_RELATION_UNKNOWN &&
|
|
|
|
|
|
relation != D2D1_GEOMETRY_RELATION_DISJOINT;
|
2018-03-06 09:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::ResumeAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->Resume();
|
|
|
|
|
|
}
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::PauseAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->Pause();
|
|
|
|
|
|
}
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::StopAllActions()
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2018-09-05 00:08:03 +08:00
|
|
|
|
if (actions_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto& action : actions_)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const e2d::Node::Actions & e2d::Node::GetAllActions() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return actions_;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-07 18:20:07 +08:00
|
|
|
|
void e2d::Node::AddTask(Task * task)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (task)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto iter = std::find(tasks_.begin(), tasks_.end(), task);
|
|
|
|
|
|
if (iter == tasks_.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
task->Retain();
|
|
|
|
|
|
task->last_time_ = Time::Now();
|
|
|
|
|
|
tasks_.push_back(task);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::StopTasks(const String& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (task->GetName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::StartTasks(const String& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (task->GetName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::RemoveTasks(const String& name)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (task->GetName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->stopped_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::StopAllTasks()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::StartAllTasks()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::RemoveAllTasks()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->stopped_ = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::UpdateTasks()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tasks_.empty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Task*> currTasks;
|
|
|
|
|
|
currTasks.reserve(tasks_.size());
|
|
|
|
|
|
std::copy_if(
|
|
|
|
|
|
tasks_.begin(),
|
|
|
|
|
|
tasks_.end(),
|
|
|
|
|
|
std::back_inserter(currTasks),
|
|
|
|
|
|
[](Task* task) { return task->IsReady() && !task->stopped_; }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
for (const auto& task : currTasks)
|
|
|
|
|
|
task->Update();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
for (auto iter = tasks_.begin(); iter != tasks_.end();)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((*iter)->stopped_)
|
|
|
|
|
|
{
|
|
|
|
|
|
(*iter)->Release();
|
|
|
|
|
|
iter = tasks_.erase(iter);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
++iter;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Node::UpdateTime()
|
2018-09-05 00:08:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (const auto& action : actions_)
|
|
|
|
|
|
{
|
|
|
|
|
|
action->ResetTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-07 18:20:07 +08:00
|
|
|
|
for (const auto& task : tasks_)
|
|
|
|
|
|
{
|
|
|
|
|
|
task->ResetTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-05 00:08:03 +08:00
|
|
|
|
for (const auto& child : children_)
|
|
|
|
|
|
{
|
2018-09-07 18:20:07 +08:00
|
|
|
|
child->UpdateTime();
|
2018-09-05 00:08:03 +08:00
|
|
|
|
}
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetVisible(bool value)
|
2017-10-12 23:34:13 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
visible_ = value;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetName(const String& name)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
WARN_IF(name.IsEmpty(), "Invalid Node name.");
|
2017-10-14 11:40:47 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
if (!name.IsEmpty() && name_ != name)
|
2017-10-14 11:40:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
name_ = name;
|
2017-10-14 11:40:47 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD> Hash <20><>
|
2018-09-04 22:42:34 +08:00
|
|
|
|
hash_name_ = name.GetHash();
|
2017-10-14 11:40:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
|
void e2d::Node::SetParentScene(Scene * scene)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
parent_scene_ = scene;
|
|
|
|
|
|
for (const auto& child : children_)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
|
child->SetParentScene(scene);
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|