Magic_Game/src/kiwano/2d/Transition.h

257 lines
5.6 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
2020-01-21 10:09:55 +08:00
//
// 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:
2020-01-21 10:09:55 +08:00
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
2020-01-21 10:09:55 +08:00
//
// 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
2019-12-23 18:05:08 +08:00
#include <kiwano/2d/Stage.h>
#include <kiwano/render/Layer.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2020-01-21 10:09:55 +08:00
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
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
class KGE_API Transition : public virtual ObjectBase
{
friend class Director;
public:
2020-02-06 16:54:47 +08:00
Transition();
virtual ~Transition();
2020-01-21 10:09:55 +08:00
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
void SetDuration(Duration dt);
2020-01-21 10:09:55 +08:00
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
bool IsDone();
protected:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param[in] prev
* @param[in] next
2020-01-21 10:09:55 +08:00
*/
virtual void Init(StagePtr prev, StagePtr next);
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param dt
2020-01-21 10:09:55 +08:00
*/
virtual void Update(Duration dt);
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param[in] ctx
2020-01-21 10:09:55 +08:00
*/
virtual void Render(RenderContext& ctx);
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
virtual void Stop();
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
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_;
2020-01-21 10:09:55 +08:00
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @details
2020-01-21 10:09:55 +08:00
*/
class FadeTransition : public Transition
{
public:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param duration
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
static FadeTransitionPtr Create(Duration duration);
FadeTransition();
2020-01-21 10:09:55 +08:00
protected:
void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override;
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @details
2020-01-21 10:09:55 +08:00
*/
class EmergeTransition : public Transition
{
public:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param duration
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
static EmergeTransitionPtr Create(Duration duration);
EmergeTransition();
2020-01-21 10:09:55 +08:00
protected:
void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override;
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @details
2020-01-21 10:09:55 +08:00
*/
class BoxTransition : public Transition
{
public:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param duration
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
static BoxTransitionPtr Create(Duration duration);
BoxTransition();
2020-01-21 10:09:55 +08:00
protected:
void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override;
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @details
2020-01-21 10:09:55 +08:00
*/
class MoveTransition : public Transition
{
public:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
2020-01-21 10:09:55 +08:00
*/
enum class Type : int
{
2020-02-10 17:32:04 +08:00
Up, ///< 上移
Down, ///< 下移
Left, ///< 左移
Right ///< 右移
2020-01-21 10:09:55 +08:00
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param duration
* @param type
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
static MoveTransitionPtr Create(Duration duration, Type type);
MoveTransition();
2020-01-21 10:09:55 +08:00
protected:
void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override;
void Reset() override;
private:
Type type_;
Point pos_delta_;
Point start_pos_;
};
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @details
2020-01-21 10:09:55 +08:00
*/
class RotationTransition : public Transition
{
public:
/**
* \~chinese
2020-02-10 17:32:04 +08:00
* @brief
* @param duration
* @param rotation
2020-01-21 10:09:55 +08:00
*/
2020-02-06 16:54:47 +08:00
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f);
RotationTransition();
2020-01-21 10:09:55 +08:00
protected:
void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override;
void Reset() override;
private:
float rotation_;
};
2020-02-06 16:54:47 +08:00
inline void Transition::SetDuration(Duration dt)
{
duration_ = dt;
}
2020-01-21 10:09:55 +08:00
} // namespace kiwano