2018-04-21 21:24:46 +08:00
|
|
|
#include "..\e2dtransition.h"
|
2018-09-06 23:26:32 +08:00
|
|
|
#include "..\e2dobject.h"
|
2018-09-11 17:54:21 +08:00
|
|
|
#include "..\e2dmodule.h"
|
2017-12-09 15:27:11 +08:00
|
|
|
|
2018-09-10 15:28:19 +08:00
|
|
|
e2d::Transition::Transition(float duration)
|
2018-09-04 22:42:34 +08:00
|
|
|
: done_(false)
|
|
|
|
|
, started_()
|
2018-09-11 15:12:25 +08:00
|
|
|
, process_(0)
|
2018-09-11 00:37:52 +08:00
|
|
|
, window_size_()
|
2018-09-04 22:42:34 +08:00
|
|
|
, out_scene_(nullptr)
|
2018-09-10 20:22:47 +08:00
|
|
|
, in_scene_(nullptr)
|
2018-09-04 22:42:34 +08:00
|
|
|
, out_layer_(nullptr)
|
|
|
|
|
, in_layer_(nullptr)
|
|
|
|
|
, out_layer_param_()
|
|
|
|
|
, in_layer_param_()
|
2017-12-09 15:27:11 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
duration_ = std::max(duration, 0.f);
|
2017-12-09 15:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
e2d::Transition::~Transition()
|
2018-04-17 01:11:56 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
SafeRelease(out_layer_);
|
|
|
|
|
SafeRelease(in_layer_);
|
2018-09-07 00:28:54 +08:00
|
|
|
SafeRelease(out_scene_);
|
|
|
|
|
SafeRelease(in_scene_);
|
2018-04-17 01:11:56 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
bool e2d::Transition::IsDone()
|
2017-12-09 15:27:11 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
return done_;
|
2017-12-09 15:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-10 15:28:19 +08:00
|
|
|
void e2d::Transition::Init(Scene * prev, Scene * next)
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
started_ = Time::Now();
|
|
|
|
|
out_scene_ = prev;
|
2018-09-10 15:28:19 +08:00
|
|
|
in_scene_ = next;
|
2018-08-14 00:26:20 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
if (out_scene_)
|
|
|
|
|
out_scene_->Retain();
|
2018-09-10 15:28:19 +08:00
|
|
|
|
|
|
|
|
if (in_scene_)
|
|
|
|
|
in_scene_->Retain();
|
2018-08-14 00:26:20 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
auto renderer = Renderer::GetInstance();
|
|
|
|
|
if (in_scene_)
|
2018-08-14 00:26:20 +08:00
|
|
|
{
|
2018-09-10 15:28:19 +08:00
|
|
|
ThrowIfFailed(
|
|
|
|
|
renderer->GetRenderTarget()->CreateLayer(&in_layer_)
|
|
|
|
|
);
|
2018-08-14 00:26:20 +08:00
|
|
|
}
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-10 15:28:19 +08:00
|
|
|
if (out_scene_)
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-10 15:28:19 +08:00
|
|
|
ThrowIfFailed(
|
|
|
|
|
renderer->GetRenderTarget()->CreateLayer(&out_layer_)
|
|
|
|
|
);
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 00:37:52 +08:00
|
|
|
window_size_ = Window::GetInstance()->GetSize();
|
2018-09-04 22:42:34 +08:00
|
|
|
out_layer_param_ = in_layer_param_ = D2D1::LayerParameters(
|
2018-09-11 00:37:52 +08:00
|
|
|
D2D1::RectF(
|
|
|
|
|
0.f,
|
|
|
|
|
0.f,
|
|
|
|
|
window_size_.width,
|
|
|
|
|
window_size_.height
|
|
|
|
|
),
|
2018-07-24 00:24:29 +08:00
|
|
|
nullptr,
|
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
|
|
|
|
D2D1::Matrix3x2F::Identity(),
|
2018-07-28 20:06:27 +08:00
|
|
|
1.f,
|
2018-09-04 22:42:34 +08:00
|
|
|
renderer->GetSolidBrush(),
|
2018-07-24 00:24:29 +08:00
|
|
|
D2D1_LAYER_OPTIONS_NONE
|
|
|
|
|
);
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
void e2d::Transition::Update()
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
if (duration_ == 0)
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-11 15:12:25 +08:00
|
|
|
process_ = 1;
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-11 15:12:25 +08:00
|
|
|
process_ = (Time::Now() - started_).Seconds() / duration_;
|
|
|
|
|
process_ = std::min(process_, 1.f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process_ >= 1)
|
|
|
|
|
{
|
|
|
|
|
this->Stop();
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
void e2d::Transition::Draw()
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-05 00:09:23 +08:00
|
|
|
auto render_target = Renderer::GetInstance()->GetRenderTarget();
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-11 00:37:52 +08:00
|
|
|
if (out_scene_)
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-11 00:37:52 +08:00
|
|
|
render_target->SetTransform(out_scene_->GetTransform());
|
|
|
|
|
render_target->PushAxisAlignedClip(
|
|
|
|
|
D2D1::RectF(
|
|
|
|
|
0.f,
|
|
|
|
|
0.f,
|
|
|
|
|
window_size_.width,
|
|
|
|
|
window_size_.height
|
|
|
|
|
),
|
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
|
2018-05-09 00:34:15 +08:00
|
|
|
);
|
2018-09-05 00:09:23 +08:00
|
|
|
render_target->PushLayer(out_layer_param_, out_layer_);
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-06 23:26:32 +08:00
|
|
|
out_scene_->Draw();
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-05 00:09:23 +08:00
|
|
|
render_target->PopLayer();
|
|
|
|
|
render_target->PopAxisAlignedClip();
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-11 00:37:52 +08:00
|
|
|
if (in_scene_)
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-11 00:37:52 +08:00
|
|
|
render_target->SetTransform(in_scene_->GetTransform());
|
|
|
|
|
render_target->PushAxisAlignedClip(
|
|
|
|
|
D2D1::RectF(
|
|
|
|
|
0.f,
|
|
|
|
|
0.f,
|
|
|
|
|
window_size_.width,
|
|
|
|
|
window_size_.height
|
|
|
|
|
),
|
|
|
|
|
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
|
2018-05-09 00:34:15 +08:00
|
|
|
);
|
2018-09-05 00:09:23 +08:00
|
|
|
render_target->PushLayer(in_layer_param_, in_layer_);
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-06 23:26:32 +08:00
|
|
|
in_scene_->Draw();
|
2018-05-09 00:34:15 +08:00
|
|
|
|
2018-09-05 00:09:23 +08:00
|
|
|
render_target->PopLayer();
|
|
|
|
|
render_target->PopAxisAlignedClip();
|
2018-05-09 00:34:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
void e2d::Transition::Stop()
|
2018-05-09 00:34:15 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
done_ = true;
|
|
|
|
|
Reset();
|
2017-12-09 15:27:11 +08:00
|
|
|
}
|