add transitions

This commit is contained in:
Nomango 2020-10-11 17:10:14 +08:00
parent e9c8ca63ad
commit 887024f916
22 changed files with 873 additions and 663 deletions

View File

@ -15,6 +15,11 @@
<ClInclude Include="..\..\src\kiwano\2d\animation\EaseFunc.h" />
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
<ClInclude Include="..\..\src\kiwano\2d\SpriteFrame.h" />
<ClInclude Include="..\..\src\kiwano\2d\transition\BoxTransition.h" />
<ClInclude Include="..\..\src\kiwano\2d\transition\FadeTransition.h" />
<ClInclude Include="..\..\src\kiwano\2d\transition\MoveTransition.h" />
<ClInclude Include="..\..\src\kiwano\2d\transition\RotationTransition.h" />
<ClInclude Include="..\..\src\kiwano\2d\transition\Transition.h" />
<ClInclude Include="..\..\src\kiwano\base\component\Button.h" />
<ClInclude Include="..\..\src\kiwano\base\component\Component.h" />
<ClInclude Include="..\..\src\kiwano\base\component\ComponentManager.h" />
@ -35,7 +40,6 @@
<ClInclude Include="..\..\src\kiwano\core\Flag.h" />
<ClInclude Include="..\..\src\kiwano\core\Function.h" />
<ClInclude Include="..\..\src\kiwano\core\IntrusiveList.h" />
<ClInclude Include="..\..\src\kiwano\core\Keys.h" />
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
<ClInclude Include="..\..\src\kiwano\core\Serializable.h" />
<ClInclude Include="..\..\src\kiwano\core\Singleton.h" />
@ -60,7 +64,6 @@
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h" />
<ClInclude Include="..\..\src\kiwano\2d\TextActor.h" />
<ClInclude Include="..\..\src\kiwano\2d\Transition.h" />
<ClInclude Include="..\..\src\kiwano\core\Resource.h" />
<ClInclude Include="..\..\src\kiwano\core\RefBasePtr.hpp" />
<ClInclude Include="..\..\src\kiwano\math\Constants.h" />
@ -75,6 +78,7 @@
<ClInclude Include="..\..\src\kiwano\platform\Application.h" />
<ClInclude Include="..\..\src\kiwano\platform\FileSystem.h" />
<ClInclude Include="..\..\src\kiwano\platform\Input.h" />
<ClInclude Include="..\..\src\kiwano\platform\Keys.h" />
<ClInclude Include="..\..\src\kiwano\platform\Runner.h" />
<ClInclude Include="..\..\src\kiwano\platform\win32\ComPtr.hpp" />
<ClInclude Include="..\..\src\kiwano\platform\win32\libraries.h" />
@ -139,7 +143,11 @@
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\TextActor.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Transition.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\transition\BoxTransition.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\transition\FadeTransition.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\transition\MoveTransition.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\transition\RotationTransition.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\transition\Transition.cpp" />
<ClCompile Include="..\..\src\kiwano\base\component\Button.cpp" />
<ClCompile Include="..\..\src\kiwano\base\component\Component.cpp" />
<ClCompile Include="..\..\src\kiwano\base\component\ComponentManager.cpp" />

View File

@ -37,6 +37,9 @@
<Filter Include="2d\animation">
<UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier>
</Filter>
<Filter Include="2d\transition">
<UniqueIdentifier>{f70cecd8-6d5b-405d-8466-d3ca2db9b806}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
@ -45,9 +48,6 @@
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\Transition.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\Resource.h">
<Filter>core</Filter>
</ClInclude>
@ -111,9 +111,6 @@
<ClInclude Include="..\..\src\kiwano\core\Common.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\Keys.h">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\Time.h">
<Filter>core</Filter>
</ClInclude>
@ -381,6 +378,24 @@
<ClInclude Include="..\..\src\kiwano\2d\SpriteFrame.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\platform\Keys.h">
<Filter>platform</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\transition\Transition.h">
<Filter>2d\transition</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\transition\FadeTransition.h">
<Filter>2d\transition</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\transition\MoveTransition.h">
<Filter>2d\transition</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\transition\RotationTransition.h">
<Filter>2d\transition</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\transition\BoxTransition.h">
<Filter>2d\transition</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
@ -389,9 +404,6 @@
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\Transition.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\core\Resource.cpp">
<Filter>core</Filter>
</ClCompile>
@ -623,6 +635,21 @@
<ClCompile Include="..\..\src\kiwano\2d\SpriteFrame.h.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\transition\Transition.cpp">
<Filter>2d\transition</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\transition\FadeTransition.cpp">
<Filter>2d\transition</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\transition\MoveTransition.cpp">
<Filter>2d\transition</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\transition\RotationTransition.cpp">
<Filter>2d\transition</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\transition\BoxTransition.cpp">
<Filter>2d\transition</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="suppress_warning.ruleset" />

View File

@ -1,388 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/Transition.h>
#include <kiwano/utils/Logger.h>
#include <kiwano/platform/Window.h>
#include <kiwano/render/Renderer.h>
namespace kiwano
{
//-------------------------------------------------------
// Transition
//-------------------------------------------------------
Transition::Transition()
: done_(false)
, duration_()
, delta_()
, process_(0)
, window_size_()
, out_stage_(nullptr)
, in_stage_(nullptr)
, out_layer_()
, in_layer_()
{
}
Transition::~Transition() {}
bool Transition::IsDone()
{
return done_;
}
void Transition::Init(Stage* prev, Stage* next)
{
process_ = 0;
delta_ = Duration{};
out_stage_ = prev;
in_stage_ = next;
window_size_ = Renderer::GetInstance().GetOutputSize();
if (in_stage_)
{
in_layer_.SetClipRect(Rect{ Point(), window_size_ });
}
if (out_stage_)
{
out_layer_.SetClipRect(Rect{ Point(), window_size_ });
}
}
void Transition::Update(Duration dt)
{
if (duration_.IsZero())
{
process_ = 1;
}
else
{
delta_ += dt;
process_ = std::min(delta_ / duration_, 1.f);
}
if (process_ >= 1)
{
this->Stop();
}
}
void Transition::Render(RenderContext& ctx)
{
if (out_stage_)
{
out_stage_->PrepareToRender(ctx);
ctx.PushClipRect(Rect{ Point{}, window_size_ });
ctx.PushLayer(out_layer_);
out_stage_->Render(ctx);
ctx.PopLayer();
ctx.PopClipRect();
}
if (in_stage_)
{
in_stage_->PrepareToRender(ctx);
ctx.PushClipRect(Rect{ Point{}, window_size_ });
ctx.PushLayer(in_layer_);
in_stage_->Render(ctx);
ctx.PopLayer();
ctx.PopClipRect();
}
}
void Transition::Stop()
{
done_ = true;
Reset();
}
//-------------------------------------------------------
// BoxTransition
//-------------------------------------------------------
BoxTransition::BoxTransition(Duration duration)
{
SetDuration(duration);
}
BoxTransition::BoxTransition() {}
void BoxTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
in_layer_.SetOpacity(0.f);
}
void BoxTransition::Update(Duration dt)
{
Transition::Update(dt);
if (process_ < .5f)
{
out_layer_.SetClipRect(Rect(window_size_.x * process_, window_size_.y * process_,
window_size_.x * (1 - process_), window_size_.y * (1 - process_)));
}
else
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
in_layer_.SetClipRect(Rect(window_size_.x * (1 - process_), window_size_.y * (1 - process_),
window_size_.x * process_, window_size_.y * process_));
}
}
//-------------------------------------------------------
// EmergeTransition
//-------------------------------------------------------
EmergeTransition::EmergeTransition(Duration duration)
{
SetDuration(duration);
}
EmergeTransition::EmergeTransition() {}
void EmergeTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
out_layer_.SetOpacity(1.f);
in_layer_.SetOpacity(0.f);
}
void EmergeTransition::Update(Duration dt)
{
Transition::Update(dt);
out_layer_.SetOpacity(1 - process_);
in_layer_.SetOpacity(process_);
}
//-------------------------------------------------------
// FadeTransition
//-------------------------------------------------------
FadeTransition::FadeTransition(Duration duration)
{
SetDuration(duration);
}
FadeTransition::FadeTransition() {}
void FadeTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
out_layer_.SetOpacity(1.f);
in_layer_.SetOpacity(0.f);
}
void FadeTransition::Update(Duration dt)
{
Transition::Update(dt);
if (process_ < 0.5)
{
out_layer_.SetOpacity(1 - process_ * 2);
in_layer_.SetOpacity(0.f);
}
else
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity((process_ - 0.5f) * 2);
}
}
//-------------------------------------------------------
// MoveTransition
//-------------------------------------------------------
MoveTransition::MoveTransition(Duration duration, Type type)
: type_(type)
{
SetDuration(duration);
}
MoveTransition::MoveTransition()
: type_(Type::Left)
{
}
void MoveTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
switch (type_)
{
case Type::Up:
pos_delta_ = Point(0, -window_size_.y);
start_pos_ = Point(0, window_size_.y);
break;
case Type::Down:
pos_delta_ = Point(0, window_size_.y);
start_pos_ = Point(0, -window_size_.y);
break;
case Type::Left:
pos_delta_ = Point(-window_size_.x, 0);
start_pos_ = Point(window_size_.x, 0);
break;
case Type::Right:
pos_delta_ = Point(window_size_.x, 0);
start_pos_ = Point(-window_size_.x, 0);
break;
}
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
}
if (in_stage_)
{
auto transform = Transform{};
transform.position = start_pos_;
in_stage_->SetTransform(transform);
}
}
void MoveTransition::Update(Duration dt)
{
Transition::Update(dt);
if (out_stage_)
{
auto transform = Transform{};
transform.position = pos_delta_ * process_;
out_stage_->SetTransform(transform);
}
if (in_stage_)
{
auto transform = Transform{};
transform.position = start_pos_ + pos_delta_ * process_;
in_stage_->SetTransform(transform);
}
}
void MoveTransition::Reset()
{
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
}
if (in_stage_)
{
in_stage_->SetTransform(Transform{});
}
}
//-------------------------------------------------------
// RotationTransition
//-------------------------------------------------------
RotationTransition::RotationTransition(Duration duration, float rotation)
: rotation_(rotation)
{
SetDuration(duration);
}
RotationTransition::RotationTransition()
: rotation_(0.0f)
{
}
void RotationTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
auto transform = Transform{};
transform.position = Point{ window_size_.x / 2, window_size_.y / 2 };
if (out_stage_)
{
out_stage_->SetTransform(transform);
out_stage_->SetAnchor(Vec2{ 0.5f, 0.5f });
}
if (in_stage_)
{
in_stage_->SetTransform(transform);
in_stage_->SetAnchor(Vec2{ 0.5f, 0.5f });
}
in_layer_.SetOpacity(0.f);
}
void RotationTransition::Update(Duration dt)
{
Transition::Update(dt);
if (process_ < .5f)
{
if (out_stage_)
{
auto transform = out_stage_->GetTransform();
transform.scale = Point{ (.5f - process_) * 2, (.5f - process_) * 2 };
transform.rotation = rotation_ * (.5f - process_) * 2;
out_stage_->SetTransform(transform);
}
}
else
{
if (in_stage_)
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
auto transform = in_stage_->GetTransform();
transform.scale = Point{ (process_ - .5f) * 2, (process_ - .5f) * 2 };
transform.rotation = rotation_ * (process_ - .5f) * 2;
in_stage_->SetTransform(transform);
}
}
}
void RotationTransition::Reset()
{
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
out_stage_->SetAnchor(Vec2{ 0.f, 0.f });
}
if (in_stage_)
{
in_stage_->SetTransform(Transform{});
in_stage_->SetAnchor(Vec2{ 0.f, 0.f });
}
}
} // namespace kiwano

View File

@ -1,256 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/Stage.h>
#include <kiwano/render/Layer.h>
namespace kiwano
{
class Director;
class RenderContext;
KGE_DECLARE_SMART_PTR(Transition);
KGE_DECLARE_SMART_PTR(FadeTransition);
KGE_DECLARE_SMART_PTR(EmergeTransition);
KGE_DECLARE_SMART_PTR(BoxTransition);
KGE_DECLARE_SMART_PTR(MoveTransition);
KGE_DECLARE_SMART_PTR(RotationTransition);
/**
* \~chinese
* @brief
*/
class KGE_API Transition : public ObjectBase
{
friend class Director;
public:
Transition();
virtual ~Transition();
/**
* \~chinese
* @brief
*/
void SetDuration(Duration dt);
/**
* \~chinese
* @brief
*/
bool IsDone();
protected:
/**
* \~chinese
* @brief
* @param[in] prev
* @param[in] next
*/
virtual void Init(Stage* prev, Stage* next);
/**
* \~chinese
* @brief
* @param dt
*/
virtual void Update(Duration dt);
/**
* \~chinese
* @brief
* @param[in] ctx
*/
virtual void Render(RenderContext& ctx);
/**
* \~chinese
* @brief
*/
virtual void Stop();
/**
* \~chinese
* @brief
*/
virtual void Reset() {}
protected:
bool done_;
float process_;
Duration duration_;
Duration delta_;
Size window_size_;
StagePtr out_stage_;
StagePtr in_stage_;
Layer out_layer_;
Layer in_layer_;
};
/**
* \~chinese
* @brief
* @details
*/
class FadeTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
FadeTransition(Duration duration);
FadeTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
};
/**
* \~chinese
* @brief
* @details
*/
class EmergeTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
EmergeTransition(Duration duration);
EmergeTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
};
/**
* \~chinese
* @brief
* @details
*/
class BoxTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
BoxTransition(Duration duration);
BoxTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
};
/**
* \~chinese
* @brief
* @details
*/
class MoveTransition : public Transition
{
public:
/**
* \~chinese
* @brief
*/
enum class Type : int
{
Up, ///< 上移
Down, ///< 下移
Left, ///< 左移
Right ///< 右移
};
/**
* \~chinese
* @brief
* @param duration
* @param type
*/
MoveTransition(Duration duration, Type type);
MoveTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
void Reset() override;
private:
Type type_;
Point pos_delta_;
Point start_pos_;
};
/**
* \~chinese
* @brief
* @details
*/
class RotationTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
* @param rotation
*/
RotationTransition(Duration duration, float rotation = 360.0f);
RotationTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
void Reset() override;
private:
float rotation_;
};
inline void Transition::SetDuration(Duration dt)
{
duration_ = dt;
}
} // namespace kiwano

View File

@ -0,0 +1,58 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/transition/BoxTransition.h>
namespace kiwano
{
BoxTransition::BoxTransition(Duration duration)
{
SetDuration(duration);
}
BoxTransition::BoxTransition() {}
void BoxTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
in_layer_.SetOpacity(0.f);
}
void BoxTransition::Update(Duration dt)
{
Transition::Update(dt);
if (process_ < .5f)
{
out_layer_.SetClipRect(Rect(window_size_.x * process_, window_size_.y * process_,
window_size_.x * (1 - process_), window_size_.y * (1 - process_)));
}
else
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
in_layer_.SetClipRect(Rect(window_size_.x * (1 - process_), window_size_.y * (1 - process_),
window_size_.x * process_, window_size_.y * process_));
}
}
} // namespace kiwano

View File

@ -0,0 +1,52 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/transition/Transition.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(BoxTransition);
/**
* \~chinese
* @brief
* @details
*/
class BoxTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
BoxTransition(Duration duration);
BoxTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
};
} // namespace kiwano

View File

@ -0,0 +1,66 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/transition/FadeTransition.h>
namespace kiwano
{
FadeTransition::FadeTransition(Duration duration, bool parallel)
: parallel_(parallel)
{
SetDuration(duration);
}
FadeTransition::FadeTransition() {}
void FadeTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
out_layer_.SetOpacity(1.f);
in_layer_.SetOpacity(0.f);
}
void FadeTransition::Update(Duration dt)
{
Transition::Update(dt);
if (parallel_)
{
out_layer_.SetOpacity(1 - process_);
in_layer_.SetOpacity(process_);
}
else
{
if (process_ < 0.5)
{
out_layer_.SetOpacity(1 - process_ * 2);
in_layer_.SetOpacity(0.f);
}
else
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity((process_ - 0.5f) * 2);
}
}
}
} // namespace kiwano

View File

@ -0,0 +1,56 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/transition/Transition.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(FadeTransition);
/**
* \~chinese
* @brief
* @details
*/
class FadeTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
* @param parallel
*/
FadeTransition(Duration duration, bool parallel = false);
FadeTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
private:
bool parallel_;
};
} // namespace kiwano

View File

@ -0,0 +1,106 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/transition/MoveTransition.h>
namespace kiwano
{
MoveTransition::MoveTransition(Duration duration, Type type)
: type_(type)
{
SetDuration(duration);
}
MoveTransition::MoveTransition()
: type_(Type::Left)
{
}
void MoveTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
switch (type_)
{
case Type::Up:
pos_delta_ = Point(0, -window_size_.y);
start_pos_ = Point(0, window_size_.y);
break;
case Type::Down:
pos_delta_ = Point(0, window_size_.y);
start_pos_ = Point(0, -window_size_.y);
break;
case Type::Left:
pos_delta_ = Point(-window_size_.x, 0);
start_pos_ = Point(window_size_.x, 0);
break;
case Type::Right:
pos_delta_ = Point(window_size_.x, 0);
start_pos_ = Point(-window_size_.x, 0);
break;
}
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
}
if (in_stage_)
{
auto transform = Transform{};
transform.position = start_pos_;
in_stage_->SetTransform(transform);
}
}
void MoveTransition::Update(Duration dt)
{
Transition::Update(dt);
if (out_stage_)
{
auto transform = Transform{};
transform.position = pos_delta_ * process_;
out_stage_->SetTransform(transform);
}
if (in_stage_)
{
auto transform = Transform{};
transform.position = start_pos_ + pos_delta_ * process_;
in_stage_->SetTransform(transform);
}
}
void MoveTransition::Reset()
{
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
}
if (in_stage_)
{
in_stage_->SetTransform(Transform{});
}
}
} // namespace kiwano

View File

@ -0,0 +1,72 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/transition/Transition.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(MoveTransition);
/**
* \~chinese
* @brief
* @details
*/
class MoveTransition : public Transition
{
public:
/**
* \~chinese
* @brief
*/
enum class Type : int
{
Up, ///< 上移
Down, ///< 下移
Left, ///< 左移
Right ///< 右移
};
/**
* \~chinese
* @brief
* @param duration
* @param type
*/
MoveTransition(Duration duration, Type type);
MoveTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
void Reset() override;
private:
Type type_;
Point pos_delta_;
Point start_pos_;
};
} // namespace kiwano

View File

@ -0,0 +1,104 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/transition/RotationTransition.h>
namespace kiwano
{
RotationTransition::RotationTransition(Duration duration, float rotation)
: rotation_(rotation)
{
SetDuration(duration);
}
RotationTransition::RotationTransition()
: rotation_(0.0f)
{
}
void RotationTransition::Init(Stage* prev, Stage* next)
{
Transition::Init(prev, next);
auto transform = Transform{};
transform.position = Point{ window_size_.x / 2, window_size_.y / 2 };
if (out_stage_)
{
out_stage_->SetTransform(transform);
out_stage_->SetAnchor(Vec2{ 0.5f, 0.5f });
}
if (in_stage_)
{
in_stage_->SetTransform(transform);
in_stage_->SetAnchor(Vec2{ 0.5f, 0.5f });
}
in_layer_.SetOpacity(0.f);
}
void RotationTransition::Update(Duration dt)
{
Transition::Update(dt);
if (process_ < .5f)
{
if (out_stage_)
{
auto transform = out_stage_->GetTransform();
transform.scale = Point{ (.5f - process_) * 2, (.5f - process_) * 2 };
transform.rotation = rotation_ * (.5f - process_) * 2;
out_stage_->SetTransform(transform);
}
}
else
{
if (in_stage_)
{
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
auto transform = in_stage_->GetTransform();
transform.scale = Point{ (process_ - .5f) * 2, (process_ - .5f) * 2 };
transform.rotation = rotation_ * (process_ - .5f) * 2;
in_stage_->SetTransform(transform);
}
}
}
void RotationTransition::Reset()
{
if (out_stage_)
{
out_stage_->SetTransform(Transform{});
out_stage_->SetAnchor(Vec2{ 0.f, 0.f });
}
if (in_stage_)
{
in_stage_->SetTransform(Transform{});
in_stage_->SetAnchor(Vec2{ 0.f, 0.f });
}
}
} // namespace kiwano

View File

@ -0,0 +1,58 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/transition/Transition.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(RotationTransition);
/**
* \~chinese
* @brief
* @details
*/
class RotationTransition : public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
* @param rotation
*/
RotationTransition(Duration duration, float rotation = 360.0f);
RotationTransition();
protected:
void Update(Duration dt) override;
virtual void Init(Stage* prev, Stage* next) override;
void Reset() override;
private:
float rotation_;
};
} // namespace kiwano

View File

@ -0,0 +1,118 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/transition/Transition.h>
#include <kiwano/render/Renderer.h>
namespace kiwano
{
Transition::Transition()
: done_(false)
, duration_()
, delta_()
, process_(0)
, window_size_()
, out_stage_(nullptr)
, in_stage_(nullptr)
, out_layer_()
, in_layer_()
{
}
Transition::~Transition() {}
bool Transition::IsDone()
{
return done_;
}
void Transition::Init(Stage* prev, Stage* next)
{
process_ = 0;
delta_ = Duration{};
out_stage_ = prev;
in_stage_ = next;
window_size_ = Renderer::GetInstance().GetOutputSize();
if (in_stage_)
{
in_layer_.SetClipRect(Rect{ Point(), window_size_ });
}
if (out_stage_)
{
out_layer_.SetClipRect(Rect{ Point(), window_size_ });
}
}
void Transition::Update(Duration dt)
{
if (duration_.IsZero())
{
process_ = 1;
}
else
{
delta_ += dt;
process_ = std::min(delta_ / duration_, 1.f);
}
if (process_ >= 1)
{
this->Stop();
}
}
void Transition::Render(RenderContext& ctx)
{
if (out_stage_)
{
out_stage_->PrepareToRender(ctx);
ctx.PushClipRect(Rect{ Point{}, window_size_ });
ctx.PushLayer(out_layer_);
out_stage_->Render(ctx);
ctx.PopLayer();
ctx.PopClipRect();
}
if (in_stage_)
{
in_stage_->PrepareToRender(ctx);
ctx.PushClipRect(Rect{ Point{}, window_size_ });
ctx.PushLayer(in_layer_);
in_stage_->Render(ctx);
ctx.PopLayer();
ctx.PopClipRect();
}
}
void Transition::Stop()
{
done_ = true;
Reset();
}
} // namespace kiwano

View File

@ -0,0 +1,121 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/Stage.h>
#include <kiwano/render/Layer.h>
namespace kiwano
{
class Director;
class RenderContext;
KGE_DECLARE_SMART_PTR(Transition);
/**
* \~chinese
* \defgroup Transition
*/
/**
* \addtogroup Transition
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Transition : public ObjectBase
{
friend class Director;
public:
Transition();
virtual ~Transition();
/**
* \~chinese
* @brief
*/
void SetDuration(Duration dt);
/**
* \~chinese
* @brief
*/
bool IsDone();
protected:
/**
* \~chinese
* @brief
* @param[in] prev
* @param[in] next
*/
virtual void Init(Stage* prev, Stage* next);
/**
* \~chinese
* @brief
* @param dt
*/
virtual void Update(Duration dt);
/**
* \~chinese
* @brief
* @param[in] ctx
*/
virtual void Render(RenderContext& ctx);
/**
* \~chinese
* @brief
*/
virtual void Stop();
/**
* \~chinese
* @brief
*/
virtual void Reset() {}
protected:
bool done_;
float process_;
Duration duration_;
Duration delta_;
Size window_size_;
StagePtr out_stage_;
StagePtr in_stage_;
Layer out_layer_;
Layer in_layer_;
};
/** @} */
inline void Transition::SetDuration(Duration dt)
{
duration_ = dt;
}
} // namespace kiwano

View File

@ -21,7 +21,6 @@
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/DebugActor.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/Transition.h>
#include <kiwano/base/Director.h>
namespace kiwano

View File

@ -21,7 +21,7 @@
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/Transition.h>
#include <kiwano/2d/transition/Transition.h>
#include <kiwano/base/Module.h>
namespace kiwano

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/core/Keys.h>
#include <kiwano/platform/Keys.h>
#include <kiwano/event/Event.h>
namespace kiwano

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/core/Keys.h>
#include <kiwano/platform/Keys.h>
#include <kiwano/event/Event.h>
#include <kiwano/math/Math.h>

View File

@ -102,7 +102,16 @@
#include <kiwano/2d/Sprite.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/TextActor.h>
#include <kiwano/2d/Transition.h>
//
// transition
//
#include <kiwano/2d/transition/Transition.h>
#include <kiwano/2d/transition/BoxTransition.h>
#include <kiwano/2d/transition/FadeTransition.h>
#include <kiwano/2d/transition/MoveTransition.h>
#include <kiwano/2d/transition/RotationTransition.h>
//
// animation

View File

@ -22,7 +22,7 @@
#include <array>
#include <kiwano/core/Common.h>
#include <kiwano/base/Module.h>
#include <kiwano/core/Keys.h>
#include <kiwano/platform/Keys.h>
#include <kiwano/event/Event.h>
#include <kiwano/macros.h>
#include <kiwano/math/Math.h>

View File

@ -24,7 +24,7 @@
#include <memory>
#include <array>
#include <kiwano/core/Keys.h>
#include <kiwano/platform/Keys.h>
#include <kiwano/utils/Logger.h>
#include <kiwano/event/Events.h>
#include <kiwano/platform/Application.h>