remove Create functions
This commit is contained in:
parent
c0f90d235a
commit
5a877ccf7b
|
|
@ -18,6 +18,7 @@
|
|||
<ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\ObjectPool.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\RefObject.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\base\RefPtr.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Allocator.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Any.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\Cloneable.h" />
|
||||
|
|
@ -52,7 +53,7 @@
|
|||
<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\RefPtr.hpp" />
|
||||
<ClInclude Include="..\..\src\kiwano\core\RefBasePtr.hpp" />
|
||||
<ClInclude Include="..\..\src\kiwano\math\Constants.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\math\EaseFunctions.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\math\Math.h" />
|
||||
|
|
|
|||
|
|
@ -348,10 +348,13 @@
|
|||
<ClInclude Include="..\..\src\kiwano\2d\action\Action.h">
|
||||
<Filter>2d\action</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\core\RefPtr.hpp">
|
||||
<ClInclude Include="..\..\src\kiwano\base\RefObject.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\core\RefBasePtr.hpp">
|
||||
<Filter>core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\base\RefObject.h">
|
||||
<ClInclude Include="..\..\src\kiwano\base\RefPtr.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -27,26 +27,16 @@ namespace kiwano
|
|||
{
|
||||
namespace audio
|
||||
{
|
||||
SoundPtr Sound::Create(const String& file_path)
|
||||
Sound::Sound(const String& file_path)
|
||||
: Sound()
|
||||
{
|
||||
SoundPtr ptr = new (autogc) Sound;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
SoundPtr Sound::Create(const Resource& res)
|
||||
Sound::Sound(const Resource& res)
|
||||
: Sound()
|
||||
{
|
||||
SoundPtr ptr = new (autogc) Sound;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(res);
|
||||
}
|
||||
|
||||
Sound::Sound()
|
||||
|
|
|
|||
|
|
@ -50,12 +50,12 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 本地音频文件路径
|
||||
static SoundPtr Create(const String& file_path);
|
||||
Sound(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建音频对象
|
||||
/// @param res 音频资源
|
||||
static SoundPtr Create(const Resource& res);
|
||||
Sound(const Resource& res);
|
||||
|
||||
Sound();
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,6 @@ namespace kiwano
|
|||
namespace audio
|
||||
{
|
||||
|
||||
SoundPlayerPtr SoundPlayer::Create()
|
||||
{
|
||||
SoundPlayerPtr ptr = new (autogc) SoundPlayer;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SoundPlayer::SoundPlayer()
|
||||
: volume_(1.f)
|
||||
{
|
||||
|
|
@ -47,7 +41,7 @@ size_t SoundPlayer::Load(const String& file_path)
|
|||
if (sound_cache_.end() != sound_cache_.find(hash))
|
||||
return hash;
|
||||
|
||||
SoundPtr sound = new (autogc) Sound;
|
||||
SoundPtr sound = MakePtr<Sound>();
|
||||
if (sound)
|
||||
{
|
||||
if (sound->Load(file_path))
|
||||
|
|
@ -66,7 +60,7 @@ size_t SoundPlayer::Load(const Resource& res)
|
|||
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
||||
return hash_code;
|
||||
|
||||
SoundPtr sound = new (autogc) Sound;
|
||||
SoundPtr sound = MakePtr<Sound>();
|
||||
|
||||
if (sound)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -40,10 +40,6 @@ KGE_DECLARE_SMART_PTR(SoundPlayer);
|
|||
class KGE_API SoundPlayer : public ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建音频播放器
|
||||
static SoundPlayerPtr Create();
|
||||
|
||||
SoundPlayer();
|
||||
|
||||
~SoundPlayer();
|
||||
|
|
|
|||
|
|
@ -25,27 +25,17 @@ namespace kiwano
|
|||
namespace imgui
|
||||
{
|
||||
|
||||
ImGuiLayerPtr ImGuiLayer::Create()
|
||||
{
|
||||
ImGuiLayerPtr ptr = new (autogc) ImGuiLayer;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ImGuiLayerPtr ImGuiLayer::Create(const String& name, const ImGuiPipeline& item)
|
||||
{
|
||||
ImGuiLayerPtr ptr = new (autogc) ImGuiLayer;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->AddItem(name, item);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ImGuiLayer::ImGuiLayer()
|
||||
{
|
||||
SetSwallowEvents(true);
|
||||
}
|
||||
|
||||
ImGuiLayer::ImGuiLayer(const String& name, const ImGuiPipeline& item)
|
||||
: ImGuiLayer()
|
||||
{
|
||||
AddItem(name, item);
|
||||
}
|
||||
|
||||
ImGuiLayer::~ImGuiLayer() {}
|
||||
|
||||
void ImGuiLayer::OnRender(RenderContext& ctx)
|
||||
|
|
|
|||
|
|
@ -38,17 +38,13 @@ using ImGuiPipeline = Function<void()>;
|
|||
class ImGuiLayer : public LayerActor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨ImGuiͼ²ã
|
||||
static ImGuiLayerPtr Create();
|
||||
ImGuiLayer();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨ImGuiͼ²ã
|
||||
/// @param name ÔªËØÃû³Æ
|
||||
/// @param item ¹ÜµÀ
|
||||
static ImGuiLayerPtr Create(const String& name, const ImGuiPipeline& item);
|
||||
|
||||
ImGuiLayer();
|
||||
ImGuiLayer(const String& name, const ImGuiPipeline& item);
|
||||
|
||||
virtual ~ImGuiLayer();
|
||||
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ void HttpModule::NetworkThread()
|
|||
return;
|
||||
}
|
||||
|
||||
HttpResponsePtr response = new (autogc) HttpResponse(request);
|
||||
HttpResponsePtr response = MakePtr<HttpResponse>(request);
|
||||
Perform(request, response);
|
||||
|
||||
response_mutex_.lock();
|
||||
|
|
|
|||
|
|
@ -26,42 +26,23 @@ namespace kiwano
|
|||
namespace network
|
||||
{
|
||||
|
||||
HttpRequestPtr HttpRequest::Create(const String& url, HttpType type, const ResponseCallback& callback)
|
||||
HttpRequest::HttpRequest(const String& url, HttpType type, const ResponseCallback& callback)
|
||||
: type_(type)
|
||||
, url_(url)
|
||||
, response_cb_(callback)
|
||||
{
|
||||
HttpRequestPtr ptr = new (autogc) HttpRequest;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetUrl(url);
|
||||
ptr->SetType(type);
|
||||
ptr->SetResponseCallback(callback);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
HttpRequestPtr HttpRequest::Create(const String& url, HttpType type, const String& data, const ResponseCallback& callback)
|
||||
HttpRequest::HttpRequest(const String& url, HttpType type, const String& data, const ResponseCallback& callback)
|
||||
: HttpRequest(url, type, callback)
|
||||
{
|
||||
HttpRequestPtr ptr = new (autogc) HttpRequest;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetUrl(url);
|
||||
ptr->SetType(type);
|
||||
ptr->SetData(data);
|
||||
ptr->SetResponseCallback(callback);
|
||||
}
|
||||
return ptr;
|
||||
SetData(data);
|
||||
}
|
||||
|
||||
HttpRequestPtr HttpRequest::Create(const String& url, HttpType type, const Json& json, const ResponseCallback& callback)
|
||||
HttpRequest::HttpRequest(const String& url, HttpType type, const Json& json, const ResponseCallback& callback)
|
||||
: HttpRequest(url, type, callback)
|
||||
{
|
||||
HttpRequestPtr ptr = new (autogc) HttpRequest;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetUrl(url);
|
||||
ptr->SetType(type);
|
||||
ptr->SetJsonData(json);
|
||||
ptr->SetResponseCallback(callback);
|
||||
}
|
||||
return ptr;
|
||||
SetJsonData(json);
|
||||
}
|
||||
|
||||
void HttpRequest::SetJsonData(const Json& json)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public:
|
|||
/// @param url 请求地址
|
||||
/// @param type 请求类型
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(const String& url, HttpType type, const ResponseCallback& callback);
|
||||
HttpRequest(const String& url, HttpType type, const ResponseCallback& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建HTTP请求
|
||||
|
|
@ -71,7 +71,7 @@ public:
|
|||
/// @param type 请求类型
|
||||
/// @param data 请求数据
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(const String& url, HttpType type, const String& data, const ResponseCallback& callback);
|
||||
HttpRequest(const String& url, HttpType type, const String& data, const ResponseCallback& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建HTTP请求
|
||||
|
|
@ -79,12 +79,10 @@ public:
|
|||
/// @param type 请求类型
|
||||
/// @param json 请求的JSON数据
|
||||
/// @param callback 响应回调函数
|
||||
static HttpRequestPtr Create(const String& url, HttpType type, const Json& json, const ResponseCallback& callback);
|
||||
HttpRequest(const String& url, HttpType type, const Json& json, const ResponseCallback& callback);
|
||||
|
||||
HttpRequest();
|
||||
|
||||
HttpRequest(HttpType type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置请求地址
|
||||
void SetUrl(const String& url);
|
||||
|
|
@ -152,11 +150,6 @@ inline HttpRequest::HttpRequest()
|
|||
{
|
||||
}
|
||||
|
||||
inline HttpRequest::HttpRequest(HttpType type)
|
||||
: type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetUrl(const String& url)
|
||||
{
|
||||
url_ = url;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace physics
|
|||
|
||||
FixturePtr Fixture::CreateCircle(const Param& param, float radius, const Point& offset)
|
||||
{
|
||||
FixturePtr ptr = new (autogc) Fixture;
|
||||
FixturePtr ptr = MakePtr<Fixture>();
|
||||
if (ptr)
|
||||
{
|
||||
auto shape = std::make_unique<b2CircleShape>();
|
||||
|
|
@ -44,7 +44,7 @@ FixturePtr Fixture::CreateCircle(const Param& param, float radius, const Point&
|
|||
|
||||
FixturePtr Fixture::CreateRect(const Param& param, const Size& size, const Point& offset, float rotation)
|
||||
{
|
||||
FixturePtr ptr = new (autogc) Fixture;
|
||||
FixturePtr ptr = MakePtr<Fixture>();
|
||||
if (ptr)
|
||||
{
|
||||
b2Vec2 b2size = global::LocalToWorld(size);
|
||||
|
|
@ -61,7 +61,7 @@ FixturePtr Fixture::CreateRect(const Param& param, const Size& size, const Point
|
|||
|
||||
FixturePtr Fixture::CreatePolygon(const Param& param, const Vector<Point>& vertexs)
|
||||
{
|
||||
FixturePtr ptr = new (autogc) Fixture;
|
||||
FixturePtr ptr = MakePtr<Fixture>();
|
||||
if (ptr)
|
||||
{
|
||||
Vector<b2Vec2> b2vertexs;
|
||||
|
|
@ -82,7 +82,7 @@ FixturePtr Fixture::CreatePolygon(const Param& param, const Vector<Point>& verte
|
|||
|
||||
FixturePtr Fixture::CreateEdge(const Param& param, const Point& p1, const Point& p2)
|
||||
{
|
||||
FixturePtr ptr = new (autogc) Fixture;
|
||||
FixturePtr ptr = MakePtr<Fixture>();
|
||||
if (ptr)
|
||||
{
|
||||
b2Vec2 start = global::LocalToWorld(p1);
|
||||
|
|
@ -99,7 +99,7 @@ FixturePtr Fixture::CreateEdge(const Param& param, const Point& p1, const Point&
|
|||
|
||||
FixturePtr Fixture::CreateChain(const Param& param, const Vector<Point>& vertices, bool loop)
|
||||
{
|
||||
FixturePtr ptr = new (autogc) Fixture;
|
||||
FixturePtr ptr = MakePtr<Fixture>();
|
||||
if (ptr)
|
||||
{
|
||||
Vector<b2Vec2> b2vertices;
|
||||
|
|
|
|||
|
|
@ -107,18 +107,9 @@ void Joint::Destroy()
|
|||
// DistanceJoint
|
||||
//
|
||||
|
||||
DistanceJointPtr DistanceJoint::Create(const Param& param)
|
||||
{
|
||||
DistanceJointPtr ptr = new (autogc) DistanceJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
DistanceJoint::DistanceJoint()
|
||||
: raw_joint_(nullptr)
|
||||
DistanceJoint::DistanceJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -154,18 +145,9 @@ float DistanceJoint::GetLength() const
|
|||
// FrictionJoint
|
||||
//
|
||||
|
||||
FrictionJointPtr FrictionJoint::Create(const Param& param)
|
||||
{
|
||||
FrictionJointPtr ptr = new (autogc) FrictionJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
FrictionJoint::FrictionJoint()
|
||||
: raw_joint_(nullptr)
|
||||
FrictionJoint::FrictionJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -212,18 +194,9 @@ float FrictionJoint::GetMaxTorque() const
|
|||
// GearJoint
|
||||
//
|
||||
|
||||
GearJointPtr GearJoint::Create(const Param& param)
|
||||
{
|
||||
GearJointPtr ptr = new (autogc) GearJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
GearJoint::GearJoint()
|
||||
: raw_joint_(nullptr)
|
||||
GearJoint::GearJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -258,18 +231,9 @@ float GearJoint::GetRatio() const
|
|||
// MotorJoint
|
||||
//
|
||||
|
||||
MotorJointPtr MotorJoint::Create(const Param& param)
|
||||
{
|
||||
MotorJointPtr ptr = new (autogc) MotorJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
MotorJoint::MotorJoint()
|
||||
: raw_joint_(nullptr)
|
||||
MotorJoint::MotorJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -317,18 +281,9 @@ float MotorJoint::GetMaxTorque() const
|
|||
// PrismaticJoint
|
||||
//
|
||||
|
||||
PrismaticJointPtr PrismaticJoint::Create(const Param& param)
|
||||
{
|
||||
PrismaticJointPtr ptr = new (autogc) PrismaticJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PrismaticJoint::PrismaticJoint()
|
||||
: raw_joint_(nullptr)
|
||||
PrismaticJoint::PrismaticJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -386,18 +341,9 @@ void PrismaticJoint::SetLimits(float lower, float upper)
|
|||
// PulleyJoint
|
||||
//
|
||||
|
||||
PulleyJointPtr PulleyJoint::Create(const Param& param)
|
||||
{
|
||||
PulleyJointPtr ptr = new (autogc) PulleyJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PulleyJoint::PulleyJoint()
|
||||
: raw_joint_(nullptr)
|
||||
PulleyJoint::PulleyJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -462,18 +408,9 @@ float PulleyJoint::GetCurrentLengthB() const
|
|||
// RevoluteJoint
|
||||
//
|
||||
|
||||
RevoluteJointPtr RevoluteJoint::Create(const Param& param)
|
||||
{
|
||||
RevoluteJointPtr ptr = new (autogc) RevoluteJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RevoluteJoint::RevoluteJoint()
|
||||
: raw_joint_(nullptr)
|
||||
RevoluteJoint::RevoluteJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -542,18 +479,9 @@ float RevoluteJoint::GetMaxMotorTorque() const
|
|||
// RopeJoint
|
||||
//
|
||||
|
||||
RopeJointPtr RopeJoint::Create(const Param& param)
|
||||
{
|
||||
RopeJointPtr ptr = new (autogc) RopeJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RopeJoint::RopeJoint()
|
||||
: raw_joint_(nullptr)
|
||||
RopeJoint::RopeJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -590,18 +518,9 @@ float RopeJoint::GetMaxLength() const
|
|||
// WeldJoint
|
||||
//
|
||||
|
||||
WeldJointPtr WeldJoint::Create(const Param& param)
|
||||
{
|
||||
WeldJointPtr ptr = new (autogc) WeldJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
WeldJoint::WeldJoint()
|
||||
: raw_joint_(nullptr)
|
||||
WeldJoint::WeldJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -624,18 +543,9 @@ bool WeldJoint::Init(PhysicWorld* world)
|
|||
// WheelJoint
|
||||
//
|
||||
|
||||
WheelJointPtr WheelJoint::Create(const Param& param)
|
||||
{
|
||||
WheelJointPtr ptr = new (autogc) WheelJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
WheelJoint::WheelJoint()
|
||||
: raw_joint_(nullptr)
|
||||
WheelJoint::WheelJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -686,18 +596,9 @@ float WheelJoint::GetMaxMotorTorque() const
|
|||
// MouseJoint
|
||||
//
|
||||
|
||||
MouseJointPtr MouseJoint::Create(const Param& param)
|
||||
{
|
||||
MouseJointPtr ptr = new (autogc) MouseJoint;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->param_ = param;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
MouseJoint::MouseJoint()
|
||||
: raw_joint_(nullptr)
|
||||
MouseJoint::MouseJoint(const Param& param)
|
||||
: param_(param)
|
||||
, raw_joint_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,9 +161,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建固定距离关节
|
||||
/// @param param 关节参数
|
||||
static DistanceJointPtr Create(const Param& param);
|
||||
|
||||
DistanceJoint();
|
||||
DistanceJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -226,9 +224,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建摩擦关节
|
||||
/// @param param 关节参数
|
||||
static FrictionJointPtr Create(const Param& param);
|
||||
|
||||
FrictionJoint();
|
||||
FrictionJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -285,9 +281,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建齿轮关节
|
||||
/// @param param 关节参数
|
||||
static GearJointPtr Create(const Param& param);
|
||||
|
||||
GearJoint();
|
||||
GearJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -336,9 +330,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建马达关节
|
||||
/// @param param 关节参数
|
||||
static MotorJointPtr Create(const Param& param);
|
||||
|
||||
MotorJoint();
|
||||
MotorJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -405,9 +397,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建平移关节
|
||||
/// @param param 关节参数
|
||||
static PrismaticJointPtr Create(const Param& param);
|
||||
|
||||
PrismaticJoint();
|
||||
PrismaticJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -509,9 +499,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建滑轮关节
|
||||
/// @param param 关节参数
|
||||
static PulleyJointPtr Create(const Param& param);
|
||||
|
||||
PulleyJoint();
|
||||
PulleyJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -588,9 +576,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建旋转关节
|
||||
/// @param param 关节参数
|
||||
static RevoluteJointPtr Create(const Param& param);
|
||||
|
||||
RevoluteJoint();
|
||||
RevoluteJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -687,9 +673,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建绳关节
|
||||
/// @param param 关节参数
|
||||
static RopeJointPtr Create(const Param& param);
|
||||
|
||||
RopeJoint();
|
||||
RopeJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -738,9 +722,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建焊接关节
|
||||
/// @param param 关节参数
|
||||
static WeldJointPtr Create(const Param& param);
|
||||
|
||||
WeldJoint();
|
||||
WeldJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -809,9 +791,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建轮关节
|
||||
/// @param param 关节参数
|
||||
static WheelJointPtr Create(const Param& param);
|
||||
|
||||
WheelJoint();
|
||||
WheelJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
@ -911,9 +891,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建鼠标关节
|
||||
/// @param param 关节参数
|
||||
static MouseJointPtr Create(const Param& param);
|
||||
|
||||
MouseJoint();
|
||||
MouseJoint(const Param& param);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化关节
|
||||
|
|
|
|||
|
|
@ -28,37 +28,20 @@ namespace kiwano
|
|||
namespace physics
|
||||
{
|
||||
|
||||
PhysicBodyPtr PhysicBody::Create(PhysicWorldPtr world, Type type)
|
||||
{
|
||||
return PhysicBody::Create(world.Get(), type);
|
||||
}
|
||||
|
||||
PhysicBodyPtr PhysicBody::Create(PhysicWorld* world, Type type)
|
||||
{
|
||||
KGE_ASSERT(world);
|
||||
|
||||
PhysicBodyPtr ptr = new (autogc) PhysicBody;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetType(type);
|
||||
if (ptr->Init(world))
|
||||
{
|
||||
world->AddBody(ptr);
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PhysicBody::PhysicBody()
|
||||
PhysicBody::PhysicBody(PhysicWorld* world, Type type)
|
||||
: body_(nullptr)
|
||||
, world_(nullptr)
|
||||
, world_(world)
|
||||
, type_(Type::Static)
|
||||
, category_bits_(0x0001)
|
||||
, mask_bits_(0xFFFF)
|
||||
, group_index_(0)
|
||||
{
|
||||
SetName(KGE_PHYSIC_COMP_NAME);
|
||||
|
||||
if (Init(world))
|
||||
{
|
||||
world->AddBody(this);
|
||||
}
|
||||
}
|
||||
|
||||
PhysicBody::~PhysicBody() {}
|
||||
|
|
@ -88,11 +71,6 @@ void PhysicBody::DestroyComponent()
|
|||
}
|
||||
}
|
||||
|
||||
bool PhysicBody::Init(PhysicWorldPtr world)
|
||||
{
|
||||
return Init(world.Get());
|
||||
}
|
||||
|
||||
bool PhysicBody::Init(PhysicWorld* world)
|
||||
{
|
||||
KGE_ASSERT(body_ == nullptr);
|
||||
|
|
|
|||
|
|
@ -54,23 +54,10 @@ public:
|
|||
/// @brief 初始化物体
|
||||
/// @param world 物理世界
|
||||
/// @param type 物体类型
|
||||
static PhysicBodyPtr Create(PhysicWorldPtr world, Type type);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化物体
|
||||
/// @param world 物理世界
|
||||
/// @param type 物体类型
|
||||
static PhysicBodyPtr Create(PhysicWorld* world, Type type);
|
||||
|
||||
PhysicBody();
|
||||
PhysicBody(PhysicWorld* world, Type type);
|
||||
|
||||
virtual ~PhysicBody();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化物体
|
||||
/// @param[in] world 物理世界
|
||||
bool Init(PhysicWorldPtr world);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 初始化物体
|
||||
/// @param[in] world 物理世界
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ class PhysicWorld::DebugDrawer : public b2Draw
|
|||
public:
|
||||
DebugDrawer(const Size& size)
|
||||
{
|
||||
canvas_ = Canvas::Create(size);
|
||||
canvas_ = MakePtr<Canvas>(size);
|
||||
ctx_ = canvas_->GetContext2D();
|
||||
|
||||
fill_brush_ = Brush::Create(Color::White);
|
||||
line_brush_ = Brush::Create(Color::White);
|
||||
fill_brush_ = MakePtr<Brush>(Color::White);
|
||||
line_brush_ = MakePtr<Brush>(Color::White);
|
||||
|
||||
b2Draw::SetFlags(b2Draw::e_shapeBit | b2Draw::e_jointBit | b2Draw::e_jointBit | b2Draw::e_centerOfMassBit);
|
||||
}
|
||||
|
|
@ -211,20 +211,10 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
PhysicWorldPtr PhysicWorld::Create()
|
||||
PhysicWorld::PhysicWorld(const Vec2& gravity)
|
||||
: PhysicWorld()
|
||||
{
|
||||
PhysicWorldPtr ptr = new (autogc) PhysicWorld;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PhysicWorldPtr PhysicWorld::Create(const Vec2& gravity)
|
||||
{
|
||||
PhysicWorldPtr ptr = new (autogc) PhysicWorld;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetGravity(gravity);
|
||||
}
|
||||
return ptr;
|
||||
SetGravity(gravity);
|
||||
}
|
||||
|
||||
PhysicWorld::PhysicWorld()
|
||||
|
|
|
|||
|
|
@ -47,16 +47,12 @@ class KGE_API PhysicWorld : public Component
|
|||
friend class Joint;
|
||||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建物理世界
|
||||
static PhysicWorldPtr Create();
|
||||
PhysicWorld();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建物理世界
|
||||
/// @param gravity 重力
|
||||
static PhysicWorldPtr Create(const Vec2& gravity);
|
||||
|
||||
PhysicWorld();
|
||||
PhysicWorld(const Vec2& gravity);
|
||||
|
||||
virtual ~PhysicWorld();
|
||||
|
||||
|
|
|
|||
|
|
@ -39,12 +39,6 @@ void Actor::SetDefaultAnchor(float anchor_x, float anchor_y)
|
|||
default_anchor_y = anchor_y;
|
||||
}
|
||||
|
||||
ActorPtr Actor::Create()
|
||||
{
|
||||
ActorPtr ptr = new (autogc) Actor;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Actor::Actor()
|
||||
: ComponentManager(this)
|
||||
, visible_(true)
|
||||
|
|
@ -264,18 +258,18 @@ bool Actor::HandleEvent(Event* evt)
|
|||
{
|
||||
hover_ = true;
|
||||
|
||||
MouseHoverEventPtr hover = new (autogc) MouseHoverEvent;
|
||||
hover->pos = mouse_evt->pos;
|
||||
HandleEvent(hover.Get());
|
||||
auto hover = new (autogc) MouseHoverEvent;
|
||||
hover->pos = mouse_evt->pos;
|
||||
HandleEvent(hover);
|
||||
}
|
||||
else if (hover_ && !contains)
|
||||
{
|
||||
hover_ = false;
|
||||
pressed_ = false;
|
||||
|
||||
MouseOutEventPtr out = new (autogc) MouseOutEvent;
|
||||
out->pos = mouse_evt->pos;
|
||||
HandleEvent(out.Get());
|
||||
auto out = new (autogc) MouseOutEvent;
|
||||
out->pos = mouse_evt->pos;
|
||||
HandleEvent(out);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -290,10 +284,10 @@ bool Actor::HandleEvent(Event* evt)
|
|||
|
||||
auto mouse_up_evt = dynamic_cast<MouseUpEvent*>(evt);
|
||||
|
||||
MouseClickEventPtr click = new (autogc) MouseClickEvent;
|
||||
click->pos = mouse_up_evt->pos;
|
||||
click->button = mouse_up_evt->button;
|
||||
HandleEvent(click.Get());
|
||||
auto click = new (autogc) MouseClickEvent;
|
||||
click->pos = mouse_up_evt->pos;
|
||||
click->button = mouse_up_evt->button;
|
||||
HandleEvent(click);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -77,10 +77,6 @@ public:
|
|||
/// @brief 角色更新回调函数
|
||||
typedef Function<void(Duration)> UpdateCallback;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´˝¨˝ÇÉŤ
|
||||
static ActorPtr Create();
|
||||
|
||||
Actor();
|
||||
|
||||
virtual ~Actor();
|
||||
|
|
|
|||
|
|
@ -24,25 +24,11 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
CanvasPtr Canvas::Create(const Size& size)
|
||||
Canvas::Canvas(const Size& size)
|
||||
{
|
||||
CanvasPtr ptr = new (autogc) Canvas;
|
||||
if (ptr)
|
||||
{
|
||||
try
|
||||
{
|
||||
ptr->ResizeAndClear(size);
|
||||
}
|
||||
catch (std::exception)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
ResizeAndClear(size);
|
||||
}
|
||||
|
||||
Canvas::Canvas() {}
|
||||
|
||||
RenderContextPtr Canvas::GetContext2D() const
|
||||
{
|
||||
return render_ctx_;
|
||||
|
|
@ -58,7 +44,7 @@ void Canvas::OnRender(RenderContext& ctx)
|
|||
|
||||
void Canvas::ResizeAndClear(Size size)
|
||||
{
|
||||
texture_cached_ = new (autogc) Texture;
|
||||
texture_cached_ = MakePtr<Texture>();
|
||||
render_ctx_ = RenderContext::Create(*texture_cached_, size);
|
||||
|
||||
SetSize(render_ctx_->GetSize());
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建画布
|
||||
/// @param size 画布大小
|
||||
static CanvasPtr Create(const Size& size);
|
||||
Canvas(const Size& size);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取2D绘图上下文
|
||||
|
|
@ -62,9 +62,6 @@ public:
|
|||
|
||||
void OnRender(RenderContext& ctx) override;
|
||||
|
||||
private:
|
||||
Canvas();
|
||||
|
||||
private:
|
||||
TexturePtr texture_cached_;
|
||||
RenderContextPtr render_ctx_;
|
||||
|
|
|
|||
|
|
@ -54,10 +54,10 @@ DebugActor::DebugActor()
|
|||
|
||||
comma_locale_ = std::locale(std::locale(), new comma_numpunct);
|
||||
|
||||
background_brush_ = new (autogc) Brush;
|
||||
background_brush_ = MakePtr<Brush>();
|
||||
background_brush_->SetColor(Color::Rgba(0x000000, 0.7f));
|
||||
|
||||
BrushPtr fill_brush = new (autogc) Brush;
|
||||
BrushPtr fill_brush = MakePtr<Brush>();
|
||||
fill_brush->SetColor(Color::White);
|
||||
|
||||
debug_text_style_.font_family = "Arial";
|
||||
|
|
|
|||
|
|
@ -25,38 +25,6 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
GifSpritePtr GifSprite::Create(const String& file_path)
|
||||
{
|
||||
GifSpritePtr ptr = new (autogc) GifSprite;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
GifSpritePtr GifSprite::Create(const Resource& res)
|
||||
{
|
||||
GifSpritePtr ptr = new (autogc) GifSprite;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
GifSpritePtr GifSprite::Create(GifImagePtr gif)
|
||||
{
|
||||
GifSpritePtr ptr = new (autogc) GifSprite;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetGifImage(gif);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
GifSprite::GifSprite()
|
||||
: animating_(false)
|
||||
, next_index_(0)
|
||||
|
|
@ -65,6 +33,24 @@ GifSprite::GifSprite()
|
|||
{
|
||||
}
|
||||
|
||||
GifSprite::GifSprite(const String& file_path)
|
||||
: GifSprite()
|
||||
{
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
GifSprite::GifSprite(const Resource& res)
|
||||
: GifSprite()
|
||||
{
|
||||
Load(res);
|
||||
}
|
||||
|
||||
GifSprite::GifSprite(GifImagePtr gif)
|
||||
: GifSprite()
|
||||
{
|
||||
SetGifImage(gif);
|
||||
}
|
||||
|
||||
bool GifSprite::Load(const String& file_path)
|
||||
{
|
||||
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path);
|
||||
|
|
@ -92,7 +78,7 @@ bool GifSprite::Load(GifImagePtr gif)
|
|||
frame_rt_.Reset();
|
||||
|
||||
Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels()));
|
||||
frame_to_render_ = new (autogc) Texture;
|
||||
frame_to_render_ = MakePtr<Texture>();
|
||||
frame_rt_ = RenderContext::Create(*frame_to_render_, frame_size);
|
||||
|
||||
SetSize(frame_rt_->GetSize());
|
||||
|
|
@ -229,7 +215,7 @@ void GifSprite::SaveComposedFrame()
|
|||
|
||||
if (!saved_frame_)
|
||||
{
|
||||
saved_frame_ = new (autogc) Texture;
|
||||
saved_frame_ = MakePtr<Texture>();
|
||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_render_->GetSizeInPixels());
|
||||
}
|
||||
saved_frame_->CopyFrom(frame_to_render_);
|
||||
|
|
|
|||
|
|
@ -48,22 +48,22 @@ public:
|
|||
/// @brief GIF²¥·Å½áÊø»Øµ÷
|
||||
using DoneCallback = Function<void()>;
|
||||
|
||||
GifSprite();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨GIF¾«Áé
|
||||
/// @param file_path GIFͼƬ·¾¶
|
||||
static GifSpritePtr Create(const String& file_path);
|
||||
GifSprite(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨GIF¾«Áé
|
||||
/// @param res GIFͼƬ×ÊÔ´
|
||||
static GifSpritePtr Create(const Resource& res);
|
||||
GifSprite(const Resource& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨GIF¾«Áé
|
||||
/// @param gif GIFͼƬ
|
||||
static GifSpritePtr Create(GifImagePtr gif);
|
||||
|
||||
GifSprite();
|
||||
GifSprite(GifImagePtr gif);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ¼ÓÔØGIFͼƬ
|
||||
|
|
|
|||
|
|
@ -25,12 +25,6 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
LayerActorPtr LayerActor::Create()
|
||||
{
|
||||
LayerActorPtr ptr = new (autogc) LayerActor;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LayerActor::LayerActor()
|
||||
: swallow_(false)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,10 +39,6 @@ KGE_DECLARE_SMART_PTR(LayerActor);
|
|||
class KGE_API LayerActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief ´´˝¨Íź˛ă
|
||||
static LayerActorPtr Create();
|
||||
|
||||
LayerActor();
|
||||
|
||||
virtual ~LayerActor();
|
||||
|
|
|
|||
|
|
@ -25,40 +25,25 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
ShapeActorPtr ShapeActor::Create(ShapePtr shape)
|
||||
ShapeActor::ShapeActor() {}
|
||||
|
||||
ShapeActor::ShapeActor(ShapePtr shape)
|
||||
{
|
||||
ShapeActorPtr ptr = new (autogc) ShapeActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetShape(shape);
|
||||
}
|
||||
return ptr;
|
||||
SetShape(shape);
|
||||
}
|
||||
|
||||
ShapeActorPtr ShapeActor::Create(ShapePtr shape, const Color& fill_color, const Color& stroke_color)
|
||||
ShapeActor::ShapeActor(ShapePtr shape, const Color& fill_color, const Color& stroke_color)
|
||||
: ShapeActor(shape)
|
||||
{
|
||||
ShapeActorPtr ptr = ShapeActor::Create(shape);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetFillColor(fill_color);
|
||||
ptr->SetStrokeColor(stroke_color);
|
||||
}
|
||||
return ptr;
|
||||
SetFillColor(fill_color);
|
||||
SetStrokeColor(stroke_color);
|
||||
}
|
||||
|
||||
ShapeActorPtr ShapeActor::Create(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush)
|
||||
{
|
||||
ShapeActorPtr ptr = ShapeActor::Create(shape);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetFillBrush(fill_brush);
|
||||
ptr->SetStrokeBrush(stroke_brush);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ShapeActor::ShapeActor()
|
||||
ShapeActor::ShapeActor(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush)
|
||||
: ShapeActor(shape)
|
||||
{
|
||||
SetFillBrush(fill_brush);
|
||||
SetStrokeBrush(stroke_brush);
|
||||
}
|
||||
|
||||
ShapeActor::~ShapeActor() {}
|
||||
|
|
@ -127,18 +112,13 @@ bool ShapeActor::CheckVisibility(RenderContext& ctx) const
|
|||
// LineActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
LineActorPtr LineActor::Create(const Point& begin, const Point& end)
|
||||
{
|
||||
LineActorPtr ptr = new (autogc) LineActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetLine(begin, end);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LineActor::LineActor() {}
|
||||
|
||||
LineActor::LineActor(const Point& begin, const Point& end)
|
||||
{
|
||||
SetLine(begin, end);
|
||||
}
|
||||
|
||||
LineActor::~LineActor() {}
|
||||
|
||||
void LineActor::SetLine(const Point& begin, const Point& end)
|
||||
|
|
@ -155,18 +135,13 @@ void LineActor::SetLine(const Point& begin, const Point& end)
|
|||
// RectActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
RectActorPtr RectActor::Create(const Size& size)
|
||||
{
|
||||
RectActorPtr ptr = new (autogc) RectActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetRectSize(size);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RectActor::RectActor() {}
|
||||
|
||||
RectActor::RectActor(const Size& size)
|
||||
{
|
||||
SetRectSize(size);
|
||||
}
|
||||
|
||||
RectActor::~RectActor() {}
|
||||
|
||||
void RectActor::SetRectSize(const Size& size)
|
||||
|
|
@ -182,18 +157,13 @@ void RectActor::SetRectSize(const Size& size)
|
|||
// RoundedRectActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
RoundedRectActorPtr RoundedRectActor::Create(const Size& size, const Vec2& radius)
|
||||
{
|
||||
RoundedRectActorPtr ptr = new (autogc) RoundedRectActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetRoundedRect(size, radius);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RoundedRectActor::RoundedRectActor() {}
|
||||
|
||||
RoundedRectActor::RoundedRectActor(const Size& size, const Vec2& radius)
|
||||
{
|
||||
SetRoundedRect(size, radius);
|
||||
}
|
||||
|
||||
RoundedRectActor::~RoundedRectActor() {}
|
||||
|
||||
void RoundedRectActor::SetRadius(const Vec2& radius)
|
||||
|
|
@ -220,21 +190,17 @@ void RoundedRectActor::SetRoundedRect(const Size& size, const Vec2& radius)
|
|||
// CircleActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
CircleActorPtr CircleActor::Create(float radius)
|
||||
{
|
||||
CircleActorPtr ptr = new (autogc) CircleActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetRadius(radius);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
CircleActor::CircleActor()
|
||||
: radius_(0.f)
|
||||
{
|
||||
}
|
||||
|
||||
CircleActor::CircleActor(float radius)
|
||||
: radius_(0.f)
|
||||
{
|
||||
SetRadius(radius);
|
||||
}
|
||||
|
||||
CircleActor::~CircleActor() {}
|
||||
|
||||
void CircleActor::SetRadius(float radius)
|
||||
|
|
@ -250,18 +216,13 @@ void CircleActor::SetRadius(float radius)
|
|||
// EllipseActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
EllipseActorPtr EllipseActor::Create(const Vec2& radius)
|
||||
{
|
||||
EllipseActorPtr ptr = new (autogc) EllipseActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetRadius(radius);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
EllipseActor::EllipseActor() {}
|
||||
|
||||
EllipseActor::EllipseActor(const Vec2& radius)
|
||||
{
|
||||
SetRadius(radius);
|
||||
}
|
||||
|
||||
EllipseActor::~EllipseActor() {}
|
||||
|
||||
void EllipseActor::SetRadius(const Vec2& radius)
|
||||
|
|
@ -277,30 +238,25 @@ void EllipseActor::SetRadius(const Vec2& radius)
|
|||
// PolygonActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
PolygonActorPtr PolygonActor::Create(const Vector<Point>& points)
|
||||
{
|
||||
PolygonActorPtr ptr = new (autogc) PolygonActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetVertices(points);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PolygonActor::PolygonActor() {}
|
||||
|
||||
PolygonActor::PolygonActor(const Vector<Point>& points)
|
||||
{
|
||||
SetVertices(points);
|
||||
}
|
||||
|
||||
PolygonActor::~PolygonActor() {}
|
||||
|
||||
void PolygonActor::SetVertices(const Vector<Point>& points)
|
||||
{
|
||||
if (points.size() > 1)
|
||||
{
|
||||
ShapeMakerPtr maker = ShapeMaker::Create();
|
||||
maker->BeginPath(points[0]);
|
||||
maker->AddLines(&points[1], points.size() - 1);
|
||||
maker->EndPath(true);
|
||||
ShapeMaker maker;
|
||||
maker.BeginPath(points[0]);
|
||||
maker.AddLines(&points[1], points.size() - 1);
|
||||
maker.EndPath(true);
|
||||
|
||||
SetShape(maker->GetShape());
|
||||
SetShape(maker.GetShape());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,28 +48,26 @@ KGE_DECLARE_SMART_PTR(PolygonActor);
|
|||
class KGE_API ShapeActor : public Actor
|
||||
{
|
||||
public:
|
||||
ShapeActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建形状角色
|
||||
/// @param shape 形状
|
||||
static ShapeActorPtr Create(ShapePtr shape);
|
||||
ShapeActor(ShapePtr shape);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建形状角色
|
||||
/// @param shape 形状
|
||||
/// @param fill_color 填充颜色
|
||||
/// @param stroke_color 轮廓颜色
|
||||
static ShapeActorPtr Create(ShapePtr shape, const Color& fill_color, const Color& stroke_color);
|
||||
ShapeActor(ShapePtr shape, const Color& fill_color, const Color& stroke_color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建形状角色
|
||||
/// @param shape 形状
|
||||
/// @param fill_brush 填充画刷
|
||||
/// @param stroke_brush 轮廓画刷
|
||||
static ShapeActorPtr Create(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ¹¹ÔìÐÎ×´½ÇÉ«
|
||||
ShapeActor();
|
||||
ShapeActor(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush);
|
||||
|
||||
virtual ~ShapeActor();
|
||||
|
||||
|
|
@ -147,13 +145,13 @@ private:
|
|||
class KGE_API LineActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
LineActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线段角色
|
||||
/// @param begin 线段起点
|
||||
/// @param end 线段终点
|
||||
static LineActorPtr Create(const Point& begin, const Point& end);
|
||||
|
||||
LineActor();
|
||||
LineActor(const Point& begin, const Point& end);
|
||||
|
||||
virtual ~LineActor();
|
||||
|
||||
|
|
@ -191,12 +189,12 @@ private:
|
|||
class KGE_API RectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
RectActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建矩形角色
|
||||
/// @param size 矩形大小
|
||||
static RectActorPtr Create(const Size& size);
|
||||
|
||||
RectActor();
|
||||
RectActor(const Size& size);
|
||||
|
||||
virtual ~RectActor();
|
||||
|
||||
|
|
@ -218,13 +216,13 @@ private:
|
|||
class KGE_API RoundedRectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
RoundedRectActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建圆角矩形角色
|
||||
/// @param size 圆角矩形大小
|
||||
/// @param radius 圆角半径
|
||||
static RoundedRectActorPtr Create(const Size& size, const Vec2& radius);
|
||||
|
||||
RoundedRectActor();
|
||||
RoundedRectActor(const Size& size, const Vec2& radius);
|
||||
|
||||
virtual ~RoundedRectActor();
|
||||
|
||||
|
|
@ -262,12 +260,12 @@ private:
|
|||
class KGE_API CircleActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
CircleActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建圆形角色
|
||||
/// @param radius 圆形半径
|
||||
static CircleActorPtr Create(float radius);
|
||||
|
||||
CircleActor();
|
||||
CircleActor(float radius);
|
||||
|
||||
virtual ~CircleActor();
|
||||
|
||||
|
|
@ -289,12 +287,12 @@ private:
|
|||
class KGE_API EllipseActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
EllipseActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建椭圆角色
|
||||
/// @param radius 椭圆半径
|
||||
static EllipseActorPtr Create(const Vec2& radius);
|
||||
|
||||
EllipseActor();
|
||||
EllipseActor(const Vec2& radius);
|
||||
|
||||
virtual ~EllipseActor();
|
||||
|
||||
|
|
@ -316,12 +314,12 @@ private:
|
|||
class KGE_API PolygonActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
PolygonActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建多边形角色
|
||||
/// @param points 多边形端点集合
|
||||
static PolygonActorPtr Create(const Vector<Point>& points);
|
||||
|
||||
PolygonActor();
|
||||
PolygonActor(const Vector<Point>& points);
|
||||
|
||||
virtual ~PolygonActor();
|
||||
|
||||
|
|
@ -338,7 +336,7 @@ inline void ShapeActor::SetStrokeColor(const Color& color)
|
|||
{
|
||||
if (!stroke_brush_)
|
||||
{
|
||||
stroke_brush_ = new (autogc) Brush;
|
||||
stroke_brush_ = MakePtr<Brush>();
|
||||
}
|
||||
stroke_brush_->SetColor(color);
|
||||
}
|
||||
|
|
@ -347,7 +345,7 @@ inline void ShapeActor::SetFillColor(const Color& color)
|
|||
{
|
||||
if (!fill_brush_)
|
||||
{
|
||||
fill_brush_ = new (autogc) Brush;
|
||||
fill_brush_ = MakePtr<Brush>();
|
||||
}
|
||||
fill_brush_->SetColor(color);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,65 +24,40 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
SpritePtr Sprite::Create(const String& file_path)
|
||||
{
|
||||
SpritePtr ptr = new (autogc) Sprite;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SpritePtr Sprite::Create(const Resource& res)
|
||||
{
|
||||
SpritePtr ptr = new (autogc) Sprite;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SpritePtr Sprite::Create(FramePtr frame)
|
||||
{
|
||||
SpritePtr ptr = new (autogc) Sprite;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetFrame(frame);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SpritePtr Sprite::Create(const String& file_path, const Rect& crop_rect)
|
||||
{
|
||||
SpritePtr ptr = Sprite::Create(file_path);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetCropRect(crop_rect);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SpritePtr Sprite::Create(const Resource& res, const Rect& crop_rect)
|
||||
{
|
||||
SpritePtr ptr = Sprite::Create(res);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetCropRect(crop_rect);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Sprite::Sprite() {}
|
||||
|
||||
Sprite::Sprite(const String& file_path)
|
||||
{
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
Sprite::Sprite(const Resource& res)
|
||||
{
|
||||
Load(res);
|
||||
}
|
||||
|
||||
Sprite::Sprite(FramePtr frame)
|
||||
{
|
||||
SetFrame(frame);
|
||||
}
|
||||
|
||||
Sprite::Sprite(const String& file_path, const Rect& crop_rect)
|
||||
: Sprite(file_path)
|
||||
{
|
||||
SetCropRect(crop_rect);
|
||||
}
|
||||
|
||||
Sprite::Sprite(const Resource& res, const Rect& crop_rect)
|
||||
: Sprite(res)
|
||||
{
|
||||
SetCropRect(crop_rect);
|
||||
}
|
||||
|
||||
Sprite::~Sprite() {}
|
||||
|
||||
bool Sprite::Load(const String& file_path, bool autoresize)
|
||||
{
|
||||
FramePtr frame = Frame::Create(file_path);
|
||||
FramePtr frame = MakePtr<Frame>(file_path);
|
||||
if (frame)
|
||||
{
|
||||
SetFrame(frame, autoresize);
|
||||
|
|
@ -93,7 +68,7 @@ bool Sprite::Load(const String& file_path, bool autoresize)
|
|||
|
||||
bool Sprite::Load(const Resource& res, bool autoresize)
|
||||
{
|
||||
FramePtr frame = Frame::Create(res);
|
||||
FramePtr frame = MakePtr<Frame>(res);
|
||||
if (frame)
|
||||
{
|
||||
SetFrame(frame, autoresize);
|
||||
|
|
|
|||
|
|
@ -38,34 +38,34 @@ KGE_DECLARE_SMART_PTR(Sprite);
|
|||
class KGE_API Sprite : public Actor
|
||||
{
|
||||
public:
|
||||
Sprite();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param file_path 本地图片路径
|
||||
static SpritePtr Create(const String& file_path);
|
||||
Sprite(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param res 图片资源
|
||||
static SpritePtr Create(const Resource& res);
|
||||
Sprite(const Resource& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param frame 图像帧
|
||||
static SpritePtr Create(FramePtr frame);
|
||||
Sprite(FramePtr frame);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param file_path 本地图片路径
|
||||
/// @param crop_rect 裁剪矩形
|
||||
static SpritePtr Create(const String& file_path, const Rect& crop_rect);
|
||||
Sprite(const String& file_path, const Rect& crop_rect);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建精灵
|
||||
/// @param res 图片资源
|
||||
/// @param crop_rect 裁剪矩形
|
||||
static SpritePtr Create(const Resource& res, const Rect& crop_rect);
|
||||
|
||||
Sprite();
|
||||
Sprite(const Resource& res, const Rect& crop_rect);
|
||||
|
||||
virtual ~Sprite();
|
||||
|
||||
|
|
|
|||
|
|
@ -25,12 +25,6 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
StagePtr Stage::Create()
|
||||
{
|
||||
StagePtr ptr = new (autogc) Stage;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Stage::Stage()
|
||||
{
|
||||
SetStage(this);
|
||||
|
|
@ -57,13 +51,13 @@ void Stage::RenderBorder(RenderContext& ctx)
|
|||
|
||||
if (!border_fill_brush_)
|
||||
{
|
||||
border_fill_brush_ = new (autogc) Brush;
|
||||
border_fill_brush_ = MakePtr<Brush>();
|
||||
border_fill_brush_->SetColor(Color(Color::Red, .4f));
|
||||
}
|
||||
|
||||
if (!border_stroke_brush_)
|
||||
{
|
||||
border_stroke_brush_ = new (autogc) Brush;
|
||||
border_stroke_brush_ = MakePtr<Brush>();
|
||||
border_stroke_brush_->SetColor(Color(Color::Red, .8f));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@ class KGE_API Stage : public Actor
|
|||
friend class Director;
|
||||
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 进入舞台时
|
||||
static StagePtr Create();
|
||||
|
||||
Stage();
|
||||
|
||||
virtual ~Stage();
|
||||
|
|
|
|||
|
|
@ -25,24 +25,17 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
TextActorPtr TextActor::Create(const String& text)
|
||||
TextActor::TextActor() {}
|
||||
|
||||
TextActor::TextActor(const String& text)
|
||||
: TextActor(text, TextStyle())
|
||||
{
|
||||
return TextActor::Create(text, TextStyle());
|
||||
}
|
||||
|
||||
TextActorPtr TextActor::Create(const String& text, const TextStyle& style)
|
||||
{
|
||||
TextActorPtr ptr = new (autogc) TextActor;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetStyle(style);
|
||||
ptr->SetText(text);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
TextActor::TextActor()
|
||||
TextActor::TextActor(const String& text, const TextStyle& style)
|
||||
{
|
||||
SetStyle(style);
|
||||
SetText(text);
|
||||
}
|
||||
|
||||
TextActor::~TextActor() {}
|
||||
|
|
@ -65,7 +58,7 @@ void TextActor::SetText(const String& text)
|
|||
{
|
||||
if (!layout_)
|
||||
{
|
||||
layout_ = TextLayout::Create();
|
||||
layout_ = MakePtr<TextLayout>();
|
||||
}
|
||||
layout_->Reset(text, style_);
|
||||
}
|
||||
|
|
@ -215,7 +208,7 @@ void TextActor::SetFillColor(const Color& color)
|
|||
}
|
||||
else
|
||||
{
|
||||
SetFillBrush(Brush::Create(color));
|
||||
SetFillBrush(MakePtr<Brush>(color));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +220,7 @@ void TextActor::SetOutlineColor(const Color& outline_color)
|
|||
}
|
||||
else
|
||||
{
|
||||
SetFillBrush(Brush::Create(outline_color));
|
||||
SetFillBrush(MakePtr<Brush>(outline_color));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,18 +39,18 @@ KGE_DECLARE_SMART_PTR(TextActor);
|
|||
class KGE_API TextActor : public Actor
|
||||
{
|
||||
public:
|
||||
TextActor();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
static TextActorPtr Create(const String& text);
|
||||
TextActor(const String& text);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文本角色
|
||||
/// @param text 文字内容
|
||||
/// @param style 文本样式
|
||||
static TextActorPtr Create(const String& text, const TextStyle& style);
|
||||
|
||||
TextActor();
|
||||
TextActor(const String& text, const TextStyle& style);
|
||||
|
||||
virtual ~TextActor();
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ bool Transition::IsDone()
|
|||
return done_;
|
||||
}
|
||||
|
||||
void Transition::Init(StagePtr prev, StagePtr next)
|
||||
void Transition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
process_ = 0;
|
||||
delta_ = Duration{};
|
||||
|
|
@ -126,19 +126,14 @@ void Transition::Stop()
|
|||
// BoxTransition
|
||||
//-------------------------------------------------------
|
||||
|
||||
BoxTransitionPtr BoxTransition::Create(Duration duration)
|
||||
BoxTransition::BoxTransition(Duration duration)
|
||||
{
|
||||
BoxTransitionPtr ptr = new (autogc) BoxTransition;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
}
|
||||
return ptr;
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
BoxTransition::BoxTransition() {}
|
||||
|
||||
void BoxTransition::Init(StagePtr prev, StagePtr next)
|
||||
void BoxTransition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
Transition::Init(prev, next);
|
||||
|
||||
|
|
@ -167,19 +162,14 @@ void BoxTransition::Update(Duration dt)
|
|||
// EmergeTransition
|
||||
//-------------------------------------------------------
|
||||
|
||||
EmergeTransitionPtr EmergeTransition::Create(Duration duration)
|
||||
EmergeTransition::EmergeTransition(Duration duration)
|
||||
{
|
||||
EmergeTransitionPtr ptr = new (autogc) EmergeTransition;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
}
|
||||
return ptr;
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
EmergeTransition::EmergeTransition() {}
|
||||
|
||||
void EmergeTransition::Init(StagePtr prev, StagePtr next)
|
||||
void EmergeTransition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
Transition::Init(prev, next);
|
||||
|
||||
|
|
@ -199,19 +189,14 @@ void EmergeTransition::Update(Duration dt)
|
|||
// FadeTransition
|
||||
//-------------------------------------------------------
|
||||
|
||||
FadeTransitionPtr FadeTransition::Create(Duration duration)
|
||||
FadeTransition::FadeTransition(Duration duration)
|
||||
{
|
||||
FadeTransitionPtr ptr = new (autogc) FadeTransition;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
}
|
||||
return ptr;
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
FadeTransition::FadeTransition() {}
|
||||
|
||||
void FadeTransition::Init(StagePtr prev, StagePtr next)
|
||||
void FadeTransition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
Transition::Init(prev, next);
|
||||
|
||||
|
|
@ -239,15 +224,10 @@ void FadeTransition::Update(Duration dt)
|
|||
// MoveTransition
|
||||
//-------------------------------------------------------
|
||||
|
||||
MoveTransitionPtr MoveTransition::Create(Duration duration, Type type)
|
||||
MoveTransition::MoveTransition(Duration duration, Type type)
|
||||
: type_(type)
|
||||
{
|
||||
MoveTransitionPtr ptr = new (autogc) MoveTransition;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->type_ = type;
|
||||
ptr->SetDuration(duration);
|
||||
}
|
||||
return ptr;
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
MoveTransition::MoveTransition()
|
||||
|
|
@ -255,7 +235,7 @@ MoveTransition::MoveTransition()
|
|||
{
|
||||
}
|
||||
|
||||
void MoveTransition::Init(StagePtr prev, StagePtr next)
|
||||
void MoveTransition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
Transition::Init(prev, next);
|
||||
|
||||
|
|
@ -328,15 +308,10 @@ void MoveTransition::Reset()
|
|||
// RotationTransition
|
||||
//-------------------------------------------------------
|
||||
|
||||
RotationTransitionPtr RotationTransition::Create(Duration duration, float rotation)
|
||||
RotationTransition::RotationTransition(Duration duration, float rotation)
|
||||
: rotation_(rotation)
|
||||
{
|
||||
RotationTransitionPtr ptr = new (autogc) RotationTransition;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->rotation_ = rotation;
|
||||
ptr->SetDuration(duration);
|
||||
}
|
||||
return ptr;
|
||||
SetDuration(duration);
|
||||
}
|
||||
|
||||
RotationTransition::RotationTransition()
|
||||
|
|
@ -344,7 +319,7 @@ RotationTransition::RotationTransition()
|
|||
{
|
||||
}
|
||||
|
||||
void RotationTransition::Init(StagePtr prev, StagePtr next)
|
||||
void RotationTransition::Init(Stage* prev, Stage* next)
|
||||
{
|
||||
Transition::Init(prev, next);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ protected:
|
|||
* @param[in] prev 转出场景
|
||||
* @param[in] next 转入场景
|
||||
*/
|
||||
virtual void Init(StagePtr prev, StagePtr next);
|
||||
virtual void Init(Stage* prev, Stage* next);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
|
|
@ -95,15 +95,15 @@ protected:
|
|||
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_;
|
||||
bool done_;
|
||||
float process_;
|
||||
Duration duration_;
|
||||
Duration delta_;
|
||||
Size window_size_;
|
||||
StagePtr out_stage_;
|
||||
StagePtr in_stage_;
|
||||
Layer out_layer_;
|
||||
Layer in_layer_;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -119,14 +119,14 @@ public:
|
|||
* @brief 创建淡入淡出过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static FadeTransitionPtr Create(Duration duration);
|
||||
FadeTransition(Duration duration);
|
||||
|
||||
FadeTransition();
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
virtual void Init(Stage* prev, Stage* next) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -142,14 +142,14 @@ public:
|
|||
* @brief 创建渐变过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static EmergeTransitionPtr Create(Duration duration);
|
||||
EmergeTransition(Duration duration);
|
||||
|
||||
EmergeTransition();
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
virtual void Init(Stage* prev, Stage* next) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -165,14 +165,14 @@ public:
|
|||
* @brief 创建盒状过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
static BoxTransitionPtr Create(Duration duration);
|
||||
BoxTransition(Duration duration);
|
||||
|
||||
BoxTransition();
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
virtual void Init(Stage* prev, Stage* next) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -201,14 +201,14 @@ public:
|
|||
* @param duration 动画时长
|
||||
* @param type 位移方式
|
||||
*/
|
||||
static MoveTransitionPtr Create(Duration duration, Type type);
|
||||
MoveTransition(Duration duration, Type type);
|
||||
|
||||
MoveTransition();
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
virtual void Init(Stage* prev, Stage* next) override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
|
|
@ -232,14 +232,14 @@ public:
|
|||
* @param duration 动画时长
|
||||
* @param rotation 旋转度数
|
||||
*/
|
||||
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f);
|
||||
RotationTransition(Duration duration, float rotation = 360.0f);
|
||||
|
||||
RotationTransition();
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
virtual void Init(Stage* prev, Stage* next) override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ void ActionEntity::Reset()
|
|||
loops_done_ = 0;
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionEntity::DoClone(ActionEntityPtr to) const
|
||||
void ActionEntity::DoClone(ActionEntity* to) const
|
||||
{
|
||||
if (to)
|
||||
{
|
||||
|
|
@ -116,7 +116,6 @@ ActionEntityPtr ActionEntity::DoClone(ActionEntityPtr to) const
|
|||
to->SetLoops(this->GetLoops());
|
||||
to->SetName(this->GetName());
|
||||
}
|
||||
return to;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Cloneable.h>
|
||||
#include <kiwano/base/ObjectBase.h>
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/core/IntrusiveList.h>
|
||||
#include <kiwano/math/Math.h>
|
||||
|
|
@ -103,7 +102,7 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const = 0;
|
||||
virtual ActionEntity* Reverse() const = 0;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画的运行状态
|
||||
|
|
@ -183,7 +182,7 @@ protected:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 执行克隆
|
||||
ActionEntityPtr DoClone(ActionEntityPtr to) const;
|
||||
void DoClone(ActionEntity* to) const;
|
||||
|
||||
private:
|
||||
Status status_;
|
||||
|
|
@ -300,6 +299,11 @@ public:
|
|||
return Get();
|
||||
}
|
||||
|
||||
inline operator ActionEntity*() const
|
||||
{
|
||||
return Get();
|
||||
}
|
||||
|
||||
inline operator ActionEntityPtr() const
|
||||
{
|
||||
return ptr;
|
||||
|
|
|
|||
|
|
@ -25,27 +25,24 @@ namespace kiwano
|
|||
|
||||
ActionDelay::ActionDelay(Duration delay)
|
||||
{
|
||||
SetEntity(ActionDelayEntity::Create(delay));
|
||||
SetEntity(MakePtr<ActionDelayEntity>(delay));
|
||||
}
|
||||
|
||||
ActionDelayEntityPtr ActionDelayEntity::Create(Duration delay)
|
||||
ActionDelayEntity::ActionDelayEntity(Duration delay)
|
||||
{
|
||||
ActionDelayEntityPtr ptr = new (autogc) ActionDelayEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDelay(delay);
|
||||
}
|
||||
this->SetDelay(delay);
|
||||
}
|
||||
|
||||
ActionDelayEntity* ActionDelayEntity::Clone() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionDelayEntity(GetDelay());
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionDelayEntity::Clone() const
|
||||
ActionDelayEntity* ActionDelayEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionDelayEntity::Create(GetDelay()));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionDelayEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionDelayEntity::Create(GetDelay()));
|
||||
return Clone();
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -50,15 +50,15 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建延时动画
|
||||
/// @param delay 延时时长
|
||||
static ActionDelayEntityPtr Create(Duration delay);
|
||||
ActionDelayEntity(Duration delay);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionDelayEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionDelayEntity* Reverse() const override;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
|
|
|||
|
|
@ -27,18 +27,7 @@ namespace kiwano
|
|||
|
||||
ActionGroup::ActionGroup(const Vector<ActionEntityPtr>& actions, bool parallel)
|
||||
{
|
||||
SetEntity(ActionGroupEntity::Create(actions, parallel));
|
||||
}
|
||||
|
||||
ActionGroupEntityPtr ActionGroupEntity::Create(const Vector<ActionEntityPtr>& actions, bool parallel)
|
||||
{
|
||||
ActionGroupEntityPtr ptr = new (autogc) ActionGroupEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->parallel_ = parallel;
|
||||
ptr->AddActions(actions);
|
||||
}
|
||||
return ptr;
|
||||
SetEntity(MakePtr<ActionGroupEntity>(actions, parallel));
|
||||
}
|
||||
|
||||
ActionGroupEntity::ActionGroupEntity()
|
||||
|
|
@ -46,9 +35,10 @@ ActionGroupEntity::ActionGroupEntity()
|
|||
{
|
||||
}
|
||||
|
||||
ActionGroupEntity::ActionGroupEntity(bool parallel)
|
||||
ActionGroupEntity::ActionGroupEntity(const Vector<ActionEntityPtr>& actions, bool parallel)
|
||||
: parallel_(parallel)
|
||||
{
|
||||
AddActions(actions);
|
||||
}
|
||||
|
||||
ActionGroupEntity::~ActionGroupEntity() {}
|
||||
|
|
@ -123,7 +113,7 @@ void ActionGroupEntity::AddActions(const Vector<ActionEntityPtr>& actions)
|
|||
AddAction(action);
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionGroupEntity::Clone() const
|
||||
ActionGroupEntity* ActionGroupEntity::Clone() const
|
||||
{
|
||||
Vector<ActionEntityPtr> actions;
|
||||
if (!actions_.IsEmpty())
|
||||
|
|
@ -133,10 +123,12 @@ ActionEntityPtr ActionGroupEntity::Clone() const
|
|||
actions.push_back(action->Clone());
|
||||
}
|
||||
}
|
||||
return DoClone(ActionGroupEntity::Create(actions, parallel_));
|
||||
auto ptr = new (autogc) ActionGroupEntity(actions, parallel_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionGroupEntity::Reverse() const
|
||||
ActionGroupEntity* ActionGroupEntity::Reverse() const
|
||||
{
|
||||
Vector<ActionEntityPtr> actions;
|
||||
if (!actions_.IsEmpty())
|
||||
|
|
@ -146,7 +138,9 @@ ActionEntityPtr ActionGroupEntity::Reverse() const
|
|||
actions.push_back(action->Reverse());
|
||||
}
|
||||
}
|
||||
return DoClone(ActionGroupEntity::Create(actions, parallel_));
|
||||
auto ptr = new (autogc) ActionGroupEntity(actions, parallel_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -47,15 +47,13 @@ public:
|
|||
class KGE_API ActionGroupEntity : public ActionEntity
|
||||
{
|
||||
public:
|
||||
ActionGroupEntity();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param parallel 同步执行
|
||||
static ActionGroupEntityPtr Create(const Vector<ActionEntityPtr>& actions, bool parallel = false);
|
||||
|
||||
ActionGroupEntity();
|
||||
|
||||
ActionGroupEntity(bool parallel);
|
||||
ActionGroupEntity(const Vector<ActionEntityPtr>& actions, bool parallel = false);
|
||||
|
||||
virtual ~ActionGroupEntity();
|
||||
|
||||
|
|
@ -75,11 +73,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionGroupEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionGroupEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
|
|||
|
|
@ -87,14 +87,14 @@ void ActionScheduler::StopAllActions()
|
|||
}
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionScheduler::GetAction(const String& name)
|
||||
ActionEntity* ActionScheduler::GetAction(const String& name)
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
return nullptr;
|
||||
|
||||
for (auto& action : actions_)
|
||||
if (action->IsName(name))
|
||||
return action;
|
||||
return action.Get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 获取指定名称的动画
|
||||
/// @param name 动画名称
|
||||
ActionEntityPtr GetAction(const String& name);
|
||||
ActionEntity* GetAction(const String& name);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取所有动画
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ ActionTweenEntity::ActionTweenEntity()
|
|||
{
|
||||
}
|
||||
|
||||
ActionTweenEntity::ActionTweenEntity(Duration duration, EaseFunc func)
|
||||
ActionTweenEntity::ActionTweenEntity(Duration duration)
|
||||
: dur_(duration)
|
||||
, ease_func_(func)
|
||||
, ease_func_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -129,33 +129,26 @@ void ActionTweenEntity::Update(Actor* target, Duration dt)
|
|||
UpdateTween(target, percent);
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionTweenEntity::DoClone(ActionTweenEntityPtr to) const
|
||||
void ActionTweenEntity::DoClone(ActionTweenEntity* to) const
|
||||
{
|
||||
if (to)
|
||||
{
|
||||
ActionEntity::DoClone(to);
|
||||
to->SetDuration(this->GetDuration());
|
||||
to->SetEaseFunc(this->GetEaseFunc());
|
||||
}
|
||||
return ActionEntity::DoClone(to);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Move Action
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionMoveByEntityPtr ActionMoveByEntity::Create(Duration duration, const Vec2& displacement)
|
||||
ActionMoveByEntity::ActionMoveByEntity(Duration duration, const Vec2& displacement)
|
||||
: ActionTweenEntity(duration)
|
||||
, displacement_(displacement)
|
||||
{
|
||||
ActionMoveByEntityPtr ptr = new (autogc) ActionMoveByEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetDisplacement(displacement);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionMoveByEntity::ActionMoveByEntity() {}
|
||||
|
||||
void ActionMoveByEntity::Init(Actor* target)
|
||||
{
|
||||
if (target)
|
||||
|
|
@ -175,32 +168,31 @@ void ActionMoveByEntity::UpdateTween(Actor* target, float percent)
|
|||
prev_pos_ = new_pos;
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionMoveByEntity::Clone() const
|
||||
ActionMoveByEntity* ActionMoveByEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionMoveByEntity::Create(GetDuration(), displacement_));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionMoveByEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionMoveByEntity::Create(GetDuration(), -displacement_));
|
||||
}
|
||||
|
||||
ActionMoveToEntityPtr ActionMoveToEntity::Create(Duration duration, const Point& distination)
|
||||
{
|
||||
ActionMoveToEntityPtr ptr = new (autogc) ActionMoveToEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetDistination(distination);
|
||||
}
|
||||
auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), displacement_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionMoveToEntity::ActionMoveToEntity() {}
|
||||
|
||||
ActionEntityPtr ActionMoveToEntity::Clone() const
|
||||
ActionMoveByEntity* ActionMoveByEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionMoveToEntity::Create(GetDuration(), distination_));
|
||||
auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), -displacement_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionMoveToEntity::ActionMoveToEntity(Duration duration, const Point& distination)
|
||||
: ActionMoveByEntity(duration, Vec2())
|
||||
, distination_(distination)
|
||||
{
|
||||
}
|
||||
|
||||
ActionMoveToEntity* ActionMoveToEntity::Clone() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionMoveToEntity(GetDuration(), distination_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionMoveToEntity::Init(Actor* target)
|
||||
|
|
@ -213,33 +205,26 @@ void ActionMoveToEntity::Init(Actor* target)
|
|||
// Jump Action
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionJumpByEntityPtr ActionJumpByEntity::Create(Duration duration, const Vec2& displacement, float height, int count)
|
||||
ActionJumpByEntity::ActionJumpByEntity(Duration duration, const Vec2& displacement, float height, int count)
|
||||
: ActionTweenEntity(duration)
|
||||
, height_(height)
|
||||
, jump_count_(count)
|
||||
, displacement_(displacement)
|
||||
{
|
||||
ActionJumpByEntityPtr ptr = new (autogc) ActionJumpByEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetJumpHeight(height);
|
||||
ptr->SetJumpCount(count);
|
||||
ptr->SetDisplacement(displacement);
|
||||
}
|
||||
}
|
||||
|
||||
ActionJumpByEntity* ActionJumpByEntity::Clone() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), displacement_, height_, jump_count_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionJumpByEntity::ActionJumpByEntity()
|
||||
: height_(0.0f)
|
||||
, jump_count_(0)
|
||||
ActionJumpByEntity* ActionJumpByEntity::Reverse() const
|
||||
{
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionJumpByEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionJumpByEntity::Create(GetDuration(), displacement_, height_, jump_count_));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionJumpByEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionJumpByEntity::Create(GetDuration(), -displacement_, height_, jump_count_));
|
||||
auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), -displacement_, height_, jump_count_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionJumpByEntity::Init(Actor* target)
|
||||
|
|
@ -266,24 +251,17 @@ void ActionJumpByEntity::UpdateTween(Actor* target, float percent)
|
|||
prev_pos_ = new_pos;
|
||||
}
|
||||
|
||||
ActionJumpToEntityPtr ActionJumpToEntity::Create(Duration duration, const Point& distination, float height, int count)
|
||||
ActionJumpToEntity::ActionJumpToEntity(Duration duration, const Point& distination, float height, int count)
|
||||
: ActionJumpByEntity(duration, Vec2(), height, count)
|
||||
, distination_(distination)
|
||||
{
|
||||
ActionJumpToEntityPtr ptr = new (autogc) ActionJumpToEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetJumpHeight(height);
|
||||
ptr->SetJumpCount(count);
|
||||
ptr->SetDistination(distination);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionJumpToEntity::ActionJumpToEntity() {}
|
||||
|
||||
ActionEntityPtr ActionJumpToEntity::Clone() const
|
||||
ActionJumpToEntity* ActionJumpToEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionJumpToEntity::Create(GetDuration(), distination_, height_, jump_count_));
|
||||
auto ptr = new (autogc) ActionJumpToEntity(GetDuration(), distination_, height_, jump_count_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionJumpToEntity::Init(Actor* target)
|
||||
|
|
@ -296,21 +274,10 @@ void ActionJumpToEntity::Init(Actor* target)
|
|||
// Scale Action
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionScaleByEntityPtr ActionScaleByEntity::Create(Duration duration, float scale_x, float scale_y)
|
||||
{
|
||||
ActionScaleByEntityPtr ptr = new (autogc) ActionScaleByEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetScaleX(scale_x);
|
||||
ptr->SetScaleY(scale_y);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionScaleByEntity::ActionScaleByEntity()
|
||||
: delta_x_(0.0f)
|
||||
, delta_y_(0.0f)
|
||||
ActionScaleByEntity::ActionScaleByEntity(Duration duration, float scale_x, float scale_y)
|
||||
: ActionTweenEntity(duration)
|
||||
, delta_x_(scale_x)
|
||||
, delta_y_(scale_y)
|
||||
, start_scale_x_(0.f)
|
||||
, start_scale_y_(0.f)
|
||||
{
|
||||
|
|
@ -330,37 +297,32 @@ void ActionScaleByEntity::UpdateTween(Actor* target, float percent)
|
|||
target->SetScale(Vec2{ start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent });
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionScaleByEntity::Clone() const
|
||||
ActionScaleByEntity* ActionScaleByEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionScaleByEntity::Create(GetDuration(), delta_x_, delta_y_));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionScaleByEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionScaleByEntity::Create(GetDuration(), -delta_x_, -delta_y_));
|
||||
}
|
||||
|
||||
ActionScaleToEntityPtr ActionScaleToEntity::Create(Duration duration, float scale_x, float scale_y)
|
||||
{
|
||||
ActionScaleToEntityPtr ptr = new (autogc) ActionScaleToEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetTargetScaleX(scale_x);
|
||||
ptr->SetTargetScaleY(scale_y);
|
||||
}
|
||||
auto ptr = new (autogc) ActionScaleByEntity(GetDuration(), delta_x_, delta_y_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionScaleToEntity::ActionScaleToEntity()
|
||||
: end_scale_x_(0.0f)
|
||||
, end_scale_y_(0.0f)
|
||||
ActionScaleByEntity* ActionScaleByEntity::Reverse() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionScaleByEntity(GetDuration(), -delta_x_, -delta_y_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionScaleToEntity::ActionScaleToEntity(Duration duration, float scale_x, float scale_y)
|
||||
: ActionScaleByEntity(duration, 0, 0)
|
||||
, end_scale_x_(scale_x)
|
||||
, end_scale_y_(scale_y)
|
||||
{
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionScaleToEntity::Clone() const
|
||||
ActionScaleToEntity* ActionScaleToEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionScaleToEntity::Create(GetDuration(), end_scale_x_, end_scale_y_));
|
||||
auto ptr = new (autogc) ActionScaleToEntity(GetDuration(), end_scale_x_, end_scale_y_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionScaleToEntity::Init(Actor* target)
|
||||
|
|
@ -374,21 +336,11 @@ void ActionScaleToEntity::Init(Actor* target)
|
|||
// Opacity Action
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionFadeToEntityPtr ActionFadeToEntity::Create(Duration duration, float opacity)
|
||||
{
|
||||
ActionFadeToEntityPtr ptr = new (autogc) ActionFadeToEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetTargetOpacity(opacity);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionFadeToEntity::ActionFadeToEntity()
|
||||
: delta_val_(0.0f)
|
||||
ActionFadeToEntity::ActionFadeToEntity(Duration duration, float opacity)
|
||||
: ActionTweenEntity(duration)
|
||||
, delta_val_(0.0f)
|
||||
, start_val_(0.f)
|
||||
, end_val_(0.0f)
|
||||
, end_val_(opacity)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -406,29 +358,21 @@ void ActionFadeToEntity::UpdateTween(Actor* target, float percent)
|
|||
target->SetOpacity(start_val_ + delta_val_ * percent);
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionFadeToEntity::Clone() const
|
||||
ActionFadeToEntity* ActionFadeToEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionFadeToEntity::Create(GetDuration(), end_val_));
|
||||
auto ptr = new (autogc) ActionFadeToEntity(GetDuration(), end_val_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Rotate Action
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionRotateByEntityPtr ActionRotateByEntity::Create(Duration duration, float rotation)
|
||||
{
|
||||
ActionRotateByEntityPtr ptr = new (autogc) ActionRotateByEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetRotation(rotation);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionRotateByEntity::ActionRotateByEntity()
|
||||
: start_val_(0.0f)
|
||||
, delta_val_(0.0f)
|
||||
ActionRotateByEntity::ActionRotateByEntity(Duration duration, float rotation)
|
||||
: ActionTweenEntity(duration)
|
||||
, delta_val_(rotation)
|
||||
, start_val_(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -449,35 +393,31 @@ void ActionRotateByEntity::UpdateTween(Actor* target, float percent)
|
|||
target->SetRotation(rotation);
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionRotateByEntity::Clone() const
|
||||
ActionRotateByEntity* ActionRotateByEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionRotateByEntity::Create(GetDuration(), delta_val_));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionRotateByEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionRotateByEntity::Create(GetDuration(), -delta_val_));
|
||||
}
|
||||
|
||||
ActionRotateToEntityPtr ActionRotateToEntity::Create(Duration duration, float rotation)
|
||||
{
|
||||
ActionRotateToEntityPtr ptr = new (autogc) ActionRotateToEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetTargetRotation(rotation);
|
||||
}
|
||||
auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), delta_val_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionRotateToEntity::ActionRotateToEntity()
|
||||
: end_val_(0.0f)
|
||||
ActionRotateByEntity* ActionRotateByEntity::Reverse() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), -delta_val_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionRotateToEntity::ActionRotateToEntity(Duration duration, float rotation)
|
||||
: ActionRotateByEntity(duration, 0)
|
||||
, end_val_(rotation)
|
||||
{
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionRotateToEntity::Clone() const
|
||||
ActionRotateToEntity* ActionRotateToEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionRotateToEntity::Create(GetDuration(), end_val_));
|
||||
auto ptr = new (autogc) ActionRotateToEntity(GetDuration(), end_val_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionRotateToEntity::Init(Actor* target)
|
||||
|
|
@ -490,22 +430,17 @@ void ActionRotateToEntity::Init(Actor* target)
|
|||
// ActionCustomEntity
|
||||
//-------------------------------------------------------
|
||||
|
||||
ActionCustomEntityPtr ActionCustomEntity::Create(Duration duration, ActionCustom::TweenFunc tween_func)
|
||||
ActionCustomEntity::ActionCustomEntity(Duration duration, ActionCustom::TweenFunc tween_func)
|
||||
: ActionTweenEntity(duration)
|
||||
, tween_func_(tween_func)
|
||||
{
|
||||
ActionCustomEntityPtr ptr = new (autogc) ActionCustomEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetTweenFunc(tween_func);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionCustomEntity::ActionCustomEntity() {}
|
||||
|
||||
ActionEntityPtr ActionCustomEntity::Clone() const
|
||||
ActionCustomEntity* ActionCustomEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionCustomEntity::Create(GetDuration(), tween_func_));
|
||||
auto ptr = new (autogc) ActionCustomEntity(GetDuration(), tween_func_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionCustomEntity::Init(Actor* target)
|
||||
|
|
@ -522,72 +457,72 @@ void ActionCustomEntity::UpdateTween(Actor* target, float percent)
|
|||
|
||||
ActionMoveBy::ActionMoveBy(Duration duration, const Vec2& displacement)
|
||||
{
|
||||
SetEntity(ActionMoveByEntity::Create(duration, displacement));
|
||||
SetEntity(MakePtr<ActionMoveByEntity>(duration, displacement));
|
||||
}
|
||||
|
||||
ActionMoveTo::ActionMoveTo(Duration duration, const Point& distination)
|
||||
{
|
||||
SetEntity(ActionMoveToEntity::Create(duration, distination));
|
||||
SetEntity(MakePtr<ActionMoveToEntity>(duration, distination));
|
||||
}
|
||||
|
||||
ActionJumpBy::ActionJumpBy(Duration duration, const Vec2& displacement, float height, int count)
|
||||
{
|
||||
SetEntity(ActionJumpByEntity::Create(duration, displacement, height, count));
|
||||
SetEntity(MakePtr<ActionJumpByEntity>(duration, displacement, height, count));
|
||||
}
|
||||
|
||||
ActionJumpTo::ActionJumpTo(Duration duration, const Point& distination, float height, int count)
|
||||
{
|
||||
SetEntity(ActionJumpToEntity::Create(duration, distination, height, count));
|
||||
SetEntity(MakePtr<ActionJumpToEntity>(duration, distination, height, count));
|
||||
}
|
||||
|
||||
ActionScaleBy::ActionScaleBy(Duration duration, float scale_x, float scale_y)
|
||||
{
|
||||
SetEntity(ActionScaleByEntity::Create(duration, scale_x, scale_y));
|
||||
SetEntity(MakePtr<ActionScaleByEntity>(duration, scale_x, scale_y));
|
||||
}
|
||||
|
||||
ActionScaleBy::ActionScaleBy(Duration duration, Vec2 scale)
|
||||
{
|
||||
SetEntity(ActionScaleByEntity::Create(duration, scale.x, scale.y));
|
||||
SetEntity(MakePtr<ActionScaleByEntity>(duration, scale.x, scale.y));
|
||||
}
|
||||
|
||||
ActionScaleTo::ActionScaleTo(Duration duration, float scale_x, float scale_y)
|
||||
{
|
||||
SetEntity(ActionScaleToEntity::Create(duration, scale_x, scale_y));
|
||||
SetEntity(MakePtr<ActionScaleToEntity>(duration, scale_x, scale_y));
|
||||
}
|
||||
|
||||
ActionScaleTo::ActionScaleTo(Duration duration, Vec2 scale)
|
||||
{
|
||||
SetEntity(ActionScaleToEntity::Create(duration, scale.x, scale.y));
|
||||
SetEntity(MakePtr<ActionScaleToEntity>(duration, scale.x, scale.y));
|
||||
}
|
||||
|
||||
ActionFadeTo::ActionFadeTo(Duration duration, float opacity)
|
||||
{
|
||||
SetEntity(ActionFadeToEntity::Create(duration, opacity));
|
||||
SetEntity(MakePtr<ActionFadeToEntity>(duration, opacity));
|
||||
}
|
||||
|
||||
ActionFadeIn::ActionFadeIn(Duration duration)
|
||||
{
|
||||
SetEntity(ActionFadeToEntity::Create(duration, 1.0f));
|
||||
SetEntity(MakePtr<ActionFadeToEntity>(duration, 1.0f));
|
||||
}
|
||||
|
||||
ActionFadeOut::ActionFadeOut(Duration duration)
|
||||
{
|
||||
SetEntity(ActionFadeToEntity::Create(duration, 0.0f));
|
||||
SetEntity(MakePtr<ActionFadeToEntity>(duration, 0.0f));
|
||||
}
|
||||
|
||||
ActionRotateBy::ActionRotateBy(Duration duration, float rotation)
|
||||
{
|
||||
SetEntity(ActionRotateByEntity::Create(duration, rotation));
|
||||
SetEntity(MakePtr<ActionRotateByEntity>(duration, rotation));
|
||||
}
|
||||
|
||||
ActionRotateTo::ActionRotateTo(Duration duration, float rotation)
|
||||
{
|
||||
SetEntity(ActionRotateToEntity::Create(duration, rotation));
|
||||
SetEntity(MakePtr<ActionRotateToEntity>(duration, rotation));
|
||||
}
|
||||
|
||||
ActionCustom::ActionCustom(Duration duration, TweenFunc tween_func)
|
||||
{
|
||||
SetEntity(ActionCustomEntity::Create(duration, tween_func));
|
||||
SetEntity(MakePtr<ActionCustomEntity>(duration, tween_func));
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -88,14 +88,6 @@ KGE_DECLARE_SMART_PTR(ActionCustomEntity);
|
|||
class KGE_API ActionTweenEntity : public ActionEntity
|
||||
{
|
||||
public:
|
||||
ActionTweenEntity();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionTweenEntity(Duration duration, EaseFunc ease);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画时长
|
||||
Duration GetDuration() const;
|
||||
|
|
@ -113,11 +105,19 @@ public:
|
|||
void SetEaseFunc(const EaseFunc& func);
|
||||
|
||||
protected:
|
||||
ActionTweenEntity();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画
|
||||
/// @param duration 动画时长
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionTweenEntity(Duration duration);
|
||||
|
||||
void Update(Actor* target, Duration dt) override;
|
||||
|
||||
virtual void UpdateTween(Actor* target, float percent) = 0;
|
||||
|
||||
ActionEntityPtr DoClone(ActionTweenEntityPtr to) const;
|
||||
void DoClone(ActionTweenEntity* to) const;
|
||||
|
||||
private:
|
||||
Duration dur_;
|
||||
|
|
@ -132,8 +132,8 @@ public:
|
|||
ActionTween() = default;
|
||||
|
||||
inline ActionTween(ActionTweenEntityPtr ptr)
|
||||
: Action(ptr.Get())
|
||||
{
|
||||
SetEntity(ptr);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -150,14 +150,14 @@ public:
|
|||
/// @brief 获取指针
|
||||
inline ActionTweenEntity* Get() const
|
||||
{
|
||||
return const_cast<ActionTweenEntity*>(static_cast<const ActionTweenEntity*>(ptr.Get()));
|
||||
return static_cast<ActionTweenEntity*>(Action::Get());
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画实体
|
||||
inline void SetEntity(ActionTweenEntityPtr tween_ptr)
|
||||
{
|
||||
this->ptr = static_cast<ActionEntity*>(tween_ptr.Get());
|
||||
Action::SetEntity(tween_ptr.Get());
|
||||
}
|
||||
|
||||
inline ActionTweenEntity* operator->() const
|
||||
|
|
@ -187,9 +187,7 @@ public:
|
|||
/// @brief 创建相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param displacement 位移向量
|
||||
static ActionMoveByEntityPtr Create(Duration duration, const Vec2& displacement);
|
||||
|
||||
ActionMoveByEntity();
|
||||
ActionMoveByEntity(Duration duration, const Vec2& displacement);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取位移向量
|
||||
|
|
@ -201,11 +199,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionMoveByEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionMoveByEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
@ -239,9 +237,7 @@ public:
|
|||
/// @brief 创建位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param distination 目的坐标
|
||||
static ActionMoveToEntityPtr Create(Duration duration, const Point& distination);
|
||||
|
||||
ActionMoveToEntity();
|
||||
ActionMoveToEntity(Duration duration, const Point& distination);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取目的坐标
|
||||
|
|
@ -253,11 +249,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionMoveToEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const override
|
||||
ActionMoveToEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionMoveToEntity");
|
||||
return nullptr;
|
||||
|
|
@ -295,9 +291,7 @@ public:
|
|||
/// @param displacement 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param count 跳跃次数
|
||||
static ActionJumpByEntityPtr Create(Duration duration, const Vec2& displacement, float height, int count = 1);
|
||||
|
||||
ActionJumpByEntity();
|
||||
ActionJumpByEntity(Duration duration, const Vec2& displacement, float height, int count = 1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取跳跃位移
|
||||
|
|
@ -325,11 +319,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionJumpByEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionJumpByEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
@ -369,9 +363,7 @@ public:
|
|||
/// @param distination 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param count 跳跃次数
|
||||
static ActionJumpToEntityPtr Create(Duration duration, const Point& distination, float height, int count = 1);
|
||||
|
||||
ActionJumpToEntity();
|
||||
ActionJumpToEntity(Duration duration, const Point& distination, float height, int count = 1);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取目的坐标
|
||||
|
|
@ -383,11 +375,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionJumpToEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const override
|
||||
ActionJumpToEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionJumpToEntity");
|
||||
return nullptr;
|
||||
|
|
@ -429,9 +421,7 @@ public:
|
|||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
static ActionScaleByEntityPtr Create(Duration duration, float scale_x, float scale_y);
|
||||
|
||||
ActionScaleByEntity();
|
||||
ActionScaleByEntity(Duration duration, float scale_x, float scale_y);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取横向缩放相对变化值
|
||||
|
|
@ -451,11 +441,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionScaleByEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionScaleByEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
@ -498,9 +488,7 @@ public:
|
|||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
static ActionScaleToEntityPtr Create(Duration duration, float scale_x, float scale_y);
|
||||
|
||||
ActionScaleToEntity();
|
||||
ActionScaleToEntity(Duration duration, float scale_x, float scale_y);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取横向缩放目标值
|
||||
|
|
@ -520,11 +508,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionScaleToEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const override
|
||||
ActionScaleToEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionScaleToEntity");
|
||||
return nullptr;
|
||||
|
|
@ -581,9 +569,7 @@ public:
|
|||
/// @brief 创建透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
static ActionFadeToEntityPtr Create(Duration duration, float opacity);
|
||||
|
||||
ActionFadeToEntity();
|
||||
ActionFadeToEntity(Duration duration, float opacity);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取目标透明度
|
||||
|
|
@ -595,11 +581,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionFadeToEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const override
|
||||
ActionFadeToEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionFadeToEntity");
|
||||
return nullptr;
|
||||
|
|
@ -637,9 +623,7 @@ public:
|
|||
/// @brief 创建相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
static ActionRotateByEntityPtr Create(Duration duration, float rotation);
|
||||
|
||||
ActionRotateByEntity();
|
||||
ActionRotateByEntity(Duration duration, float rotation);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取角度相对变化值
|
||||
|
|
@ -651,11 +635,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionRotateByEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionRotateByEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
@ -688,9 +672,7 @@ public:
|
|||
/// @brief 创建旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
static ActionRotateToEntityPtr Create(Duration duration, float rotation);
|
||||
|
||||
ActionRotateToEntity();
|
||||
ActionRotateToEntity(Duration duration, float rotation);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取目标角度
|
||||
|
|
@ -702,11 +684,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionRotateToEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
virtual ActionEntityPtr Reverse() const override
|
||||
ActionRotateToEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionRotateToEntity");
|
||||
return nullptr;
|
||||
|
|
@ -745,9 +727,7 @@ public:
|
|||
/// @brief 创建自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
static ActionCustomEntityPtr Create(Duration duration, ActionCustom::TweenFunc tween_func);
|
||||
|
||||
ActionCustomEntity();
|
||||
ActionCustomEntity(Duration duration, ActionCustom::TweenFunc tween_func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取动画回调函数
|
||||
|
|
@ -759,11 +739,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionCustomEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override
|
||||
ActionCustomEntity* Reverse() const override
|
||||
{
|
||||
KGE_ERRORF("Reverse() not supported in ActionCustomEntity");
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -26,39 +26,31 @@ namespace kiwano
|
|||
|
||||
ActionWalk::ActionWalk(Duration duration, ShapePtr path, bool rotating, float start, float end)
|
||||
{
|
||||
SetEntity(ActionWalkEntity::Create(duration, path, rotating, start, end));
|
||||
SetEntity(MakePtr<ActionWalkEntity>(duration, path, rotating, start, end));
|
||||
}
|
||||
|
||||
ActionWalkEntityPtr ActionWalkEntity::Create(Duration duration, ShapePtr path, bool rotating, float start, float end)
|
||||
ActionWalkEntity::ActionWalkEntity(Duration duration, ShapePtr path, bool rotating, float start, float end)
|
||||
: ActionTweenEntity(duration)
|
||||
, start_(start)
|
||||
, end_(end)
|
||||
, rotating_(rotating)
|
||||
, length_(0.f)
|
||||
, path_(path)
|
||||
{
|
||||
ActionWalkEntityPtr ptr = new (autogc) ActionWalkEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(duration);
|
||||
ptr->SetPath(path);
|
||||
ptr->SetRotating(rotating);
|
||||
ptr->SetStartValue(start);
|
||||
ptr->SetEndValue(end);
|
||||
}
|
||||
}
|
||||
|
||||
ActionWalkEntity* ActionWalkEntity::Clone() const
|
||||
{
|
||||
auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, start_, end_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionWalkEntity::ActionWalkEntity()
|
||||
: start_(0.0f)
|
||||
, end_(1.0f)
|
||||
, rotating_(false)
|
||||
, length_(0.f)
|
||||
ActionWalkEntity* ActionWalkEntity::Reverse() const
|
||||
{
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionWalkEntity::Clone() const
|
||||
{
|
||||
return DoClone(ActionWalkEntity::Create(GetDuration(), path_, rotating_, start_, end_));
|
||||
}
|
||||
|
||||
ActionEntityPtr ActionWalkEntity::Reverse() const
|
||||
{
|
||||
return DoClone(ActionWalkEntity::Create(GetDuration(), path_, rotating_, end_, start_));
|
||||
auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, end_, start_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void ActionWalkEntity::Init(Actor* target)
|
||||
|
|
|
|||
|
|
@ -59,10 +59,7 @@ public:
|
|||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
static ActionWalkEntityPtr Create(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f,
|
||||
float end = 1.f);
|
||||
|
||||
ActionWalkEntity();
|
||||
ActionWalkEntity(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取路线
|
||||
|
|
@ -98,11 +95,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
ActionWalkEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
ActionWalkEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
|
|||
|
|
@ -27,18 +27,7 @@ namespace kiwano
|
|||
|
||||
Animation::Animation(Duration dur, FrameSequencePtr frame_seq)
|
||||
{
|
||||
SetEntity(AnimationEntity::Create(dur, frame_seq));
|
||||
}
|
||||
|
||||
AnimationEntityPtr AnimationEntity::Create(Duration dur, FrameSequencePtr frame_seq)
|
||||
{
|
||||
AnimationEntityPtr ptr = new (autogc) AnimationEntity;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetDuration(dur);
|
||||
ptr->SetFrameSequence(frame_seq);
|
||||
}
|
||||
return ptr;
|
||||
SetEntity(MakePtr<AnimationEntity>(dur, frame_seq));
|
||||
}
|
||||
|
||||
AnimationEntity::AnimationEntity()
|
||||
|
|
@ -46,6 +35,12 @@ AnimationEntity::AnimationEntity()
|
|||
{
|
||||
}
|
||||
|
||||
AnimationEntity::AnimationEntity(Duration dur, FrameSequencePtr frame_seq)
|
||||
: ActionTweenEntity(dur)
|
||||
, frame_seq_(frame_seq)
|
||||
{
|
||||
}
|
||||
|
||||
AnimationEntity::~AnimationEntity() {}
|
||||
|
||||
FrameSequencePtr AnimationEntity::GetFrameSequence() const
|
||||
|
|
@ -90,26 +85,24 @@ void AnimationEntity::UpdateTween(Actor* target, float percent)
|
|||
}
|
||||
}
|
||||
|
||||
ActionEntityPtr AnimationEntity::Clone() const
|
||||
AnimationEntity* AnimationEntity::Clone() const
|
||||
{
|
||||
if (frame_seq_)
|
||||
{
|
||||
return DoClone(AnimationEntity::Create(GetDuration(), frame_seq_));
|
||||
}
|
||||
return nullptr;
|
||||
auto ptr = new (autogc) AnimationEntity(GetDuration(), frame_seq_);
|
||||
DoClone(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ActionEntityPtr AnimationEntity::Reverse() const
|
||||
AnimationEntity* AnimationEntity::Reverse() const
|
||||
{
|
||||
auto ptr = new (autogc) AnimationEntity(GetDuration(), nullptr);
|
||||
DoClone(ptr);
|
||||
|
||||
if (frame_seq_)
|
||||
{
|
||||
FrameSequencePtr frames = frame_seq_->Reverse();
|
||||
if (frames)
|
||||
{
|
||||
return DoClone(AnimationEntity::Create(GetDuration(), frames));
|
||||
}
|
||||
ptr->SetFrameSequence(frames);
|
||||
}
|
||||
return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@ public:
|
|||
class KGE_API AnimationEntity : public ActionTweenEntity
|
||||
{
|
||||
public:
|
||||
AnimationEntity();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建帧动画
|
||||
/// @param dur 动画时长
|
||||
/// @param frame_seq 序列帧
|
||||
static AnimationEntityPtr Create(Duration dur, FrameSequencePtr frame_seq);
|
||||
|
||||
AnimationEntity();
|
||||
AnimationEntity(Duration dur, FrameSequencePtr frame_seq);
|
||||
|
||||
virtual ~AnimationEntity();
|
||||
|
||||
|
|
@ -70,11 +70,11 @@ public:
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
ActionEntityPtr Clone() const override;
|
||||
AnimationEntity* Clone() const override;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的倒转
|
||||
ActionEntityPtr Reverse() const override;
|
||||
AnimationEntity* Reverse() const override;
|
||||
|
||||
protected:
|
||||
void Init(Actor* target) override;
|
||||
|
|
@ -86,4 +86,5 @@ private:
|
|||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
Director::Director()
|
||||
: render_border_enabled_(false)
|
||||
{
|
||||
|
|
@ -49,7 +50,7 @@ void Director::EnterStage(StagePtr stage, TransitionPtr transition)
|
|||
transition_->Stop();
|
||||
}
|
||||
transition_ = transition;
|
||||
transition_->Init(current_stage_, next_stage_);
|
||||
transition_->Init(current_stage_.Get(), next_stage_.Get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +81,7 @@ void Director::PopStage(TransitionPtr transition)
|
|||
transition_->Stop();
|
||||
}
|
||||
transition_ = transition;
|
||||
transition_->Init(current_stage_, next_stage_);
|
||||
transition_->Init(current_stage_.Get(), next_stage_.Get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ void Director::ShowDebugInfo(bool show)
|
|||
if (show)
|
||||
{
|
||||
if (!debug_actor_)
|
||||
debug_actor_ = new (autogc) DebugActor;
|
||||
debug_actor_ = MakePtr<DebugActor>();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
#include <kiwano/macros.h>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Serializable.h>
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/base/RefObject.h>
|
||||
#include <kiwano/base/RefPtr.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,11 +27,6 @@ ObjectPool::ObjectPool()
|
|||
{
|
||||
}
|
||||
|
||||
ObjectPool::~ObjectPool()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void ObjectPool::AddObject(RefObject* obj)
|
||||
{
|
||||
if (obj)
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ class KGE_API ObjectPool : public Singleton<ObjectPool>
|
|||
public:
|
||||
ObjectPool();
|
||||
|
||||
virtual ~ObjectPool();
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 添加对象到内存池
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
// 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/base/RefObject.h>
|
||||
#include <kiwano/core/RefBasePtr.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 默认的智能指针引用计数代理
|
||||
struct DefaultRefPtrRefProxy
|
||||
{
|
||||
static inline void Retain(RefObject* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
ptr->Retain();
|
||||
}
|
||||
|
||||
static inline void Release(RefObject* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
ptr->Release();
|
||||
}
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 引用计数对象智能指针
|
||||
template <typename _Ty>
|
||||
using RefPtr = RefBasePtr<_Ty, DefaultRefPtrRefProxy>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造引用计数对象智能指针
|
||||
template <typename _Ty, typename... _Args>
|
||||
inline RefPtr<_Ty> MakePtr(_Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<RefObject, _Ty>::value, "_Ty must be derived from RefObject");
|
||||
|
||||
RefPtr<_Ty> ptr;
|
||||
|
||||
_Ty** pptr = ptr.GetAddressOfAndRelease();
|
||||
(*pptr) = new _Ty(std::forward<_Args>(args)...);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造引用计数对象智能指针
|
||||
template <typename _Ty>
|
||||
inline RefPtr<_Ty> MakePtr(_Ty* ptr)
|
||||
{
|
||||
static_assert(std::is_base_of<RefObject, _Ty>::value, "_Ty must be derived from RefObject");
|
||||
return RefPtr<_Ty>(ptr);
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
||||
#ifndef KGE_DECLARE_SMART_PTR
|
||||
#define KGE_DECLARE_SMART_PTR(CLASS) \
|
||||
class CLASS; \
|
||||
typedef ::kiwano::RefPtr<CLASS> CLASS##Ptr;
|
||||
#endif
|
||||
|
|
@ -25,23 +25,19 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
ButtonPtr Button::Create(const Callback& click)
|
||||
Button::Button(const Callback& click)
|
||||
: Button(click, nullptr, nullptr, nullptr)
|
||||
{
|
||||
return Button::Create(click, nullptr, nullptr, nullptr);
|
||||
}
|
||||
|
||||
ButtonPtr Button::Create(const Callback& click, const Callback& pressed, const Callback& mouse_over,
|
||||
const Callback& mouse_out)
|
||||
Button::Button(const Callback& click, const Callback& pressed, const Callback& mouse_over, const Callback& mouse_out)
|
||||
: status_(Status::Normal)
|
||||
, click_callback_(click)
|
||||
, pressed_callback_(pressed)
|
||||
, mouse_over_callback_(mouse_over)
|
||||
, mouse_out_callback_(mouse_out)
|
||||
{
|
||||
ButtonPtr ptr = new (autogc) Button;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetClickCallback(click);
|
||||
ptr->SetPressedCallback(pressed);
|
||||
ptr->SetMouseOverCallback(mouse_over);
|
||||
ptr->SetMouseOutCallback(mouse_out);
|
||||
}
|
||||
return ptr;
|
||||
SetName("__KGE_BUTTON__");
|
||||
}
|
||||
|
||||
Button::Button()
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建按钮
|
||||
/// @param click 按钮点击回调函数
|
||||
static ButtonPtr Create(const Callback& click);
|
||||
Button(const Callback& click);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建按钮
|
||||
|
|
@ -53,8 +53,7 @@ public:
|
|||
/// @param pressed 按钮按下回调函数
|
||||
/// @param mouse_over 按钮移入回调函数
|
||||
/// @param mouse_out 按钮移出回调函数
|
||||
static ButtonPtr Create(const Callback& click, const Callback& pressed, const Callback& mouse_over,
|
||||
const Callback& mouse_out);
|
||||
Button(const Callback& click, const Callback& pressed, const Callback& mouse_over, const Callback& mouse_out);
|
||||
|
||||
Button();
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -28,7 +27,7 @@ template <typename _Ty>
|
|||
class Cloneable
|
||||
{
|
||||
public:
|
||||
virtual RefPtr<_Ty> Clone() const = 0;
|
||||
virtual _Ty* Clone() const = 0;
|
||||
|
||||
protected:
|
||||
Cloneable() = default;
|
||||
|
|
|
|||
|
|
@ -22,36 +22,16 @@
|
|||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/base/RefObject.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 默认的智能指针引用计数代理
|
||||
*/
|
||||
struct DefaultRefPtrRefProxy
|
||||
{
|
||||
static inline void Retain(RefObject* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
ptr->Retain();
|
||||
}
|
||||
|
||||
static inline void Release(RefObject* ptr)
|
||||
{
|
||||
if (ptr)
|
||||
ptr->Release();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief ÒýÓüÆÊýÖÇÄÜÖ¸Õë
|
||||
*/
|
||||
template <typename _Ty, typename _ProxyTy = DefaultRefPtrRefProxy>
|
||||
class RefPtr
|
||||
template <typename _Ty, typename _ProxyTy>
|
||||
class RefBasePtr
|
||||
{
|
||||
public:
|
||||
using value_type = _Ty;
|
||||
|
|
@ -60,41 +40,41 @@ public:
|
|||
using reference_type = _Ty&;
|
||||
using const_reference_type = const _Ty&;
|
||||
|
||||
RefPtr() noexcept
|
||||
RefBasePtr() noexcept
|
||||
: ptr_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr(std::nullptr_t) noexcept
|
||||
RefBasePtr(std::nullptr_t) noexcept
|
||||
: ptr_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
RefPtr(pointer_type p)
|
||||
RefBasePtr(pointer_type p)
|
||||
: ptr_(p)
|
||||
{
|
||||
_ProxyTy::Retain(ptr_);
|
||||
}
|
||||
|
||||
RefPtr(const RefPtr& other)
|
||||
RefBasePtr(const RefBasePtr& other)
|
||||
: ptr_(other.ptr_)
|
||||
{
|
||||
_ProxyTy::Retain(ptr_);
|
||||
}
|
||||
|
||||
RefPtr(RefPtr&& other) noexcept
|
||||
RefBasePtr(RefBasePtr&& other) noexcept
|
||||
: ptr_(nullptr)
|
||||
{
|
||||
Swap(other);
|
||||
}
|
||||
|
||||
~RefPtr()
|
||||
~RefBasePtr()
|
||||
{
|
||||
Tidy();
|
||||
}
|
||||
|
||||
template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value, int>::type = 0>
|
||||
RefPtr(const RefPtr<_UTy, _ProxyTy>& other)
|
||||
RefBasePtr(const RefBasePtr<_UTy, _ProxyTy>& other)
|
||||
{
|
||||
ptr_ = dynamic_cast<pointer_type>(other.Get());
|
||||
_ProxyTy::Retain(ptr_);
|
||||
|
|
@ -114,12 +94,12 @@ public:
|
|||
inline void Reset(pointer_type ptr = nullptr)
|
||||
{
|
||||
if (ptr)
|
||||
RefPtr(ptr).Swap(*this);
|
||||
RefBasePtr(ptr).Swap(*this);
|
||||
else
|
||||
Tidy();
|
||||
}
|
||||
|
||||
inline void Swap(RefPtr& other) noexcept
|
||||
inline void Swap(RefBasePtr& other) noexcept
|
||||
{
|
||||
std::swap(ptr_, other.ptr_);
|
||||
}
|
||||
|
|
@ -163,36 +143,36 @@ public:
|
|||
return ptr_ == 0;
|
||||
}
|
||||
|
||||
inline RefPtr& operator=(const RefPtr& other)
|
||||
inline RefBasePtr& operator=(const RefBasePtr& other)
|
||||
{
|
||||
if (other.ptr_ != ptr_)
|
||||
RefPtr(other).Swap(*this);
|
||||
RefBasePtr(other).Swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
inline RefPtr& operator=(RefPtr&& other) noexcept
|
||||
inline RefBasePtr& operator=(RefBasePtr&& other) noexcept
|
||||
{
|
||||
if (other.ptr_ != ptr_)
|
||||
other.Swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
inline RefPtr& operator=(pointer_type p)
|
||||
inline RefBasePtr& operator=(pointer_type p)
|
||||
{
|
||||
if (p != ptr_)
|
||||
RefPtr(p).Swap(*this);
|
||||
RefBasePtr(p).Swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value, int>::type = 0>
|
||||
inline RefPtr& operator=(const RefPtr<_UTy, _ProxyTy>& other)
|
||||
inline RefBasePtr& operator=(const RefBasePtr<_UTy, _ProxyTy>& other)
|
||||
{
|
||||
if (other.Get() != ptr_)
|
||||
RefPtr(dynamic_cast<pointer_type>(other.Get())).Swap(*this);
|
||||
RefBasePtr(dynamic_cast<pointer_type>(other.Get())).Swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
inline RefPtr& operator=(std::nullptr_t)
|
||||
inline RefBasePtr& operator=(std::nullptr_t)
|
||||
{
|
||||
Tidy();
|
||||
return *this;
|
||||
|
|
@ -210,67 +190,67 @@ private:
|
|||
};
|
||||
|
||||
template <class _Ty, class _UTy, class _ProxyTy>
|
||||
inline bool operator==(const RefPtr<_Ty, _ProxyTy>& lhs, const RefPtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator==(const RefBasePtr<_Ty, _ProxyTy>& lhs, const RefBasePtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return lhs.Get() == rhs.Get();
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator==(const RefPtr<_Ty, _ProxyTy>& lhs, _Ty* rhs) noexcept
|
||||
inline bool operator==(const RefBasePtr<_Ty, _ProxyTy>& lhs, _Ty* rhs) noexcept
|
||||
{
|
||||
return lhs.Get() == rhs;
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator==(_Ty* lhs, const RefPtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator==(_Ty* lhs, const RefBasePtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return lhs == rhs.Get();
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator==(const RefPtr<_Ty, _ProxyTy>& lhs, std::nullptr_t) noexcept
|
||||
inline bool operator==(const RefBasePtr<_Ty, _ProxyTy>& lhs, std::nullptr_t) noexcept
|
||||
{
|
||||
return !static_cast<bool>(lhs);
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator==(std::nullptr_t, const RefPtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator==(std::nullptr_t, const RefBasePtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return !static_cast<bool>(rhs);
|
||||
}
|
||||
|
||||
template <class _Ty, class _UTy, class _ProxyTy>
|
||||
inline bool operator!=(const RefPtr<_Ty, _ProxyTy>& lhs, const RefPtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator!=(const RefBasePtr<_Ty, _ProxyTy>& lhs, const RefBasePtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator!=(const RefPtr<_Ty, _ProxyTy>& lhs, _Ty* rhs) noexcept
|
||||
inline bool operator!=(const RefBasePtr<_Ty, _ProxyTy>& lhs, _Ty* rhs) noexcept
|
||||
{
|
||||
return lhs.Get() != rhs;
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator!=(_Ty* lhs, const RefPtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator!=(_Ty* lhs, const RefBasePtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return lhs != rhs.Get();
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator!=(const RefPtr<_Ty, _ProxyTy>& lhs, std::nullptr_t) noexcept
|
||||
inline bool operator!=(const RefBasePtr<_Ty, _ProxyTy>& lhs, std::nullptr_t) noexcept
|
||||
{
|
||||
return static_cast<bool>(lhs);
|
||||
}
|
||||
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline bool operator!=(std::nullptr_t, const RefPtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator!=(std::nullptr_t, const RefBasePtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return static_cast<bool>(rhs);
|
||||
}
|
||||
|
||||
template <class _Ty, class _UTy, class _ProxyTy>
|
||||
inline bool operator<(const RefPtr<_Ty, _ProxyTy>& lhs, const RefPtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
inline bool operator<(const RefBasePtr<_Ty, _ProxyTy>& lhs, const RefBasePtr<_UTy, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
return lhs.Get() < rhs.Get();
|
||||
}
|
||||
|
|
@ -278,27 +258,9 @@ inline bool operator<(const RefPtr<_Ty, _ProxyTy>& lhs, const RefPtr<_UTy, _Prox
|
|||
// template class cannot specialize std::swap,
|
||||
// so implement a swap function in kiwano namespace
|
||||
template <class _Ty, class _ProxyTy>
|
||||
inline void swap(RefPtr<_Ty, _ProxyTy>& lhs, RefPtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
inline void swap(RefBasePtr<_Ty, _ProxyTy>& lhs, RefBasePtr<_Ty, _ProxyTy>& rhs) noexcept
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
|
||||
template <typename _Ty, typename... _Args>
|
||||
inline RefPtr<_Ty> MakePtr(_Args&&... args)
|
||||
{
|
||||
static_assert(std::is_base_of<RefObject, _Ty>::value, "_Ty must be derived from RefObject");
|
||||
|
||||
RefPtr<_Ty> ptr;
|
||||
|
||||
_Ty** pptr = ptr.GetAddressOfAndRelease();
|
||||
(*pptr) = new _Ty(std::forward<_Args>(args)...);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
||||
#ifndef KGE_DECLARE_SMART_PTR
|
||||
#define KGE_DECLARE_SMART_PTR(CLASS) \
|
||||
class CLASS; \
|
||||
typedef ::kiwano::RefPtr<CLASS> CLASS##Ptr;
|
||||
#endif
|
||||
|
|
@ -19,7 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/base/RefObject.h>
|
||||
#include <kiwano/base/RefPtr.h>
|
||||
#include <kiwano/event/EventType.h>
|
||||
#include <kiwano/math/Math.h>
|
||||
|
||||
|
|
@ -74,13 +75,6 @@ private:
|
|||
const EventType type_;
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件特性:判断是否是事件
|
||||
template <typename _Ty>
|
||||
struct IsBaseOfEvent : public std::bool_constant<std::is_base_of<Event, _Ty>::value || std::is_same<Event, _Ty>::value>
|
||||
{
|
||||
};
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 事件特性:判断事件类型是否相同
|
||||
template <typename _Ty>
|
||||
|
|
@ -88,7 +82,7 @@ struct IsSameEventType
|
|||
{
|
||||
inline bool operator()(const Event* evt) const
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_Ty>::value, "_Ty is not an event type.");
|
||||
static_assert(std::is_base_of<Event, _Ty>::value, "_Ty is not an event type.");
|
||||
return evt->GetType() == KGE_EVENT(_Ty);
|
||||
}
|
||||
};
|
||||
|
|
@ -103,7 +97,7 @@ inline const EventType& Event::GetType() const
|
|||
template <typename _Ty>
|
||||
inline bool Event::IsType() const
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_Ty>::value, "_Ty is not an event type.");
|
||||
static_assert(std::is_base_of<Event, _Ty>::value, "_Ty is not an event type.");
|
||||
return IsSameEventType<_Ty>()(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ EventListener* EventDispatcher::AddListener(EventListenerPtr listener)
|
|||
|
||||
EventListener* EventDispatcher::AddListener(const String& name, EventType type, EventListener::Callback callback)
|
||||
{
|
||||
EventListenerPtr listener = EventListener::Create(name, type, callback);
|
||||
return AddListener(listener);
|
||||
auto lis = MakePtr<EventListener>(name, type, callback);
|
||||
return AddListener(lis);
|
||||
}
|
||||
|
||||
EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callback callback)
|
||||
{
|
||||
EventListenerPtr listener = EventListener::Create(type, callback);
|
||||
return AddListener(listener);
|
||||
auto lis = MakePtr<EventListener>(type, callback);
|
||||
return AddListener(lis);
|
||||
}
|
||||
|
||||
void EventDispatcher::StartListeners(const String& name)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public:
|
|||
template <typename _EventTy>
|
||||
EventListener* AddListener(EventListener::Callback callback)
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_EventTy>::value, "_EventTy is not an event type.");
|
||||
static_assert(std::is_base_of<Event, _EventTy>::value, "_EventTy is not an event type.");
|
||||
return AddListener(KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public:
|
|||
template <typename _EventTy>
|
||||
EventListener* AddListener(const String& name, EventListener::Callback callback)
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_EventTy>::value, "_EventTy is not an event type.");
|
||||
static_assert(std::is_base_of<Event, _EventTy>::value, "_EventTy is not an event type.");
|
||||
return AddListener(name, KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,29 +24,6 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
EventListenerPtr EventListener::Create(EventType type, const Callback& callback)
|
||||
{
|
||||
EventListenerPtr ptr = new (autogc) EventListener;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetEventType(type);
|
||||
ptr->SetCallback(callback);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
EventListenerPtr EventListener::Create(const String& name, EventType type, const Callback& callback)
|
||||
{
|
||||
EventListenerPtr ptr = new (autogc) EventListener;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetName(name);
|
||||
ptr->SetEventType(type);
|
||||
ptr->SetCallback(callback);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
EventListener::EventListener()
|
||||
: type_()
|
||||
, callback_()
|
||||
|
|
@ -56,6 +33,19 @@ EventListener::EventListener()
|
|||
{
|
||||
}
|
||||
|
||||
EventListener::EventListener(EventType type, const Callback& callback)
|
||||
: EventListener()
|
||||
{
|
||||
this->SetEventType(type);
|
||||
this->SetCallback(callback);
|
||||
}
|
||||
|
||||
EventListener::EventListener(const String& name, EventType type, const Callback& callback)
|
||||
: EventListener(type, callback)
|
||||
{
|
||||
this->SetName(name);
|
||||
}
|
||||
|
||||
EventListener::~EventListener() {}
|
||||
|
||||
void EventListener::Receive(Event* evt)
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/base/ObjectBase.h>
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/core/IntrusiveList.h>
|
||||
#include <kiwano/base/ObjectBase.h>
|
||||
#include <kiwano/event/Events.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -47,44 +46,21 @@ public:
|
|||
/// @brief 监听器回调函数
|
||||
using Callback = Function<void(Event*)>;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
static EventListenerPtr Create(EventType type, const Callback& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
static EventListenerPtr Create(const String& name, EventType type, const Callback& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy>
|
||||
static inline EventListenerPtr Create(const Callback& callback)
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_EventTy>::value, "_EventTy is not an event type.");
|
||||
return EventListener::Create(KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
template <typename _EventTy>
|
||||
static inline EventListenerPtr Create(const String& name, const Callback& callback)
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_EventTy>::value, "_EventTy is not an event type.");
|
||||
return EventListener::Create(name, KGE_EVENT(_EventTy), callback);
|
||||
}
|
||||
|
||||
EventListener();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
EventListener(EventType type, const Callback& callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建监听器
|
||||
/// @param name 监听器名称
|
||||
/// @param type 监听的事件类型
|
||||
/// @param callback 回调函数
|
||||
EventListener(const String& name, EventType type, const Callback& callback);
|
||||
|
||||
virtual ~EventListener();
|
||||
|
||||
/// \~chinese
|
||||
|
|
@ -142,7 +118,7 @@ public:
|
|||
template <typename _EventTy>
|
||||
inline void SetEventType()
|
||||
{
|
||||
static_assert(kiwano::IsBaseOfEvent<_EventTy>::value, "_EventTy is not an event type.");
|
||||
static_assert(std::is_base_of<Event, _EventTy>::value, "_EventTy is not an event type.");
|
||||
SetEventType(KGE_EVENT(_EventTy));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Defer.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/core/RefBasePtr.hpp>
|
||||
#include <kiwano/core/Time.h>
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ void Application::Run(RunnerPtr runner)
|
|||
running_ = true;
|
||||
is_paused_ = false;
|
||||
runner_ = runner;
|
||||
timer_ = Timer::Create();
|
||||
timer_ = MakePtr<Timer>();
|
||||
|
||||
// Initialize runner
|
||||
runner->InitSettings();
|
||||
|
|
|
|||
|
|
@ -28,45 +28,9 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
RunnerPtr Runner::Create(Settings settings)
|
||||
Runner::Runner(Settings settings)
|
||||
: settings_(settings)
|
||||
{
|
||||
RunnerPtr ptr = new (autogc) Runner;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetSettings(settings);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
RunnerPtr Runner::Create(Settings settings, Function<void()> on_ready, Function<void()> on_destroy)
|
||||
{
|
||||
class CallbackRunner : public Runner
|
||||
{
|
||||
public:
|
||||
void OnReady() override
|
||||
{
|
||||
if (on_ready)
|
||||
on_ready();
|
||||
}
|
||||
|
||||
void OnDestroy() override
|
||||
{
|
||||
if (on_destroy)
|
||||
on_destroy();
|
||||
}
|
||||
|
||||
Function<void()> on_ready;
|
||||
Function<void()> on_destroy;
|
||||
};
|
||||
|
||||
RefPtr<CallbackRunner> ptr = new (autogc) CallbackRunner;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->on_ready = on_ready;
|
||||
ptr->on_destroy = on_destroy;
|
||||
ptr->SetSettings(settings);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Runner::Runner() {}
|
||||
|
|
@ -105,7 +69,7 @@ void Runner::InitSettings()
|
|||
// Create frame ticker
|
||||
if (!settings_.frame_interval.IsZero())
|
||||
{
|
||||
frame_ticker_ = Ticker::Create(settings_.frame_interval, -1);
|
||||
frame_ticker_ = MakePtr<Ticker>(settings_.frame_interval, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,20 +62,13 @@ struct Settings
|
|||
class KGE_API Runner : public ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建程序运行器
|
||||
/// @param main_window 主窗口
|
||||
static RunnerPtr Create(Settings settings);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建程序运行器
|
||||
/// @param main_window 主窗口
|
||||
/// @param on_ready 应用程序初始化完成后执行的回调函数
|
||||
/// @param on_destroy 应用程序销毁时执行的回调函数
|
||||
static RunnerPtr Create(Settings settings, Function<void()> on_ready, Function<void()> on_destroy = nullptr);
|
||||
|
||||
Runner();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建程序运行器
|
||||
/// @param main_window 主窗口
|
||||
Runner(Settings settings);
|
||||
|
||||
virtual ~Runner();
|
||||
|
||||
/// \~chinese
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/RefPtr.hpp>
|
||||
#include <kiwano/core/RefBasePtr.hpp>
|
||||
#include <Unknwnbase.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -43,6 +43,6 @@ struct ComPtrProxy
|
|||
|
||||
// ComPtr<> is a smart pointer for COM
|
||||
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<IUnknown, _Ty>::value, int>::type>
|
||||
using ComPtr = RefPtr<_Ty, ComPtrProxy>;
|
||||
using ComPtr = RefBasePtr<_Ty, ComPtrProxy>;
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ private:
|
|||
|
||||
WindowPtr Window::Create(const WindowConfig& config)
|
||||
{
|
||||
WindowWin32ImplPtr ptr = new (autogc) WindowWin32Impl;
|
||||
WindowWin32ImplPtr ptr = MakePtr<WindowWin32Impl>();
|
||||
if (ptr)
|
||||
{
|
||||
ptr->Init(config);
|
||||
|
|
|
|||
|
|
@ -59,34 +59,22 @@ RadialGradientStyle::RadialGradientStyle(const Point& center, const Vec2& offset
|
|||
{
|
||||
}
|
||||
|
||||
BrushPtr Brush::Create(const Color& color)
|
||||
Brush::Brush(const Color& color)
|
||||
: Brush()
|
||||
{
|
||||
BrushPtr ptr = new (autogc) Brush;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetColor(color);
|
||||
}
|
||||
return ptr;
|
||||
SetColor(color);
|
||||
}
|
||||
|
||||
BrushPtr Brush::Create(const LinearGradientStyle& style)
|
||||
Brush::Brush(const LinearGradientStyle& style)
|
||||
: Brush()
|
||||
{
|
||||
BrushPtr ptr = new (autogc) Brush;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetStyle(style);
|
||||
}
|
||||
return ptr;
|
||||
SetStyle(style);
|
||||
}
|
||||
|
||||
BrushPtr Brush::Create(const RadialGradientStyle& style)
|
||||
Brush::Brush(const RadialGradientStyle& style)
|
||||
: Brush()
|
||||
{
|
||||
BrushPtr ptr = new (autogc) Brush;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetStyle(style);
|
||||
}
|
||||
return ptr;
|
||||
SetStyle(style);
|
||||
}
|
||||
|
||||
Brush::Brush()
|
||||
|
|
|
|||
|
|
@ -92,17 +92,17 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建纯色画刷
|
||||
/// @param color 画刷颜色
|
||||
static BrushPtr Create(const Color& color);
|
||||
Brush(const Color& color);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线性渐变样式
|
||||
/// @param style 线性渐变样式
|
||||
static BrushPtr Create(const LinearGradientStyle& style);
|
||||
Brush(const LinearGradientStyle& style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建径向渐变样式
|
||||
/// @param style 径向渐变样式
|
||||
static BrushPtr Create(const RadialGradientStyle& style);
|
||||
Brush(const RadialGradientStyle& style);
|
||||
|
||||
Brush();
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ void RendererImpl::MakeContextForWindow(WindowPtr window)
|
|||
// Initialize other device resources
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
RenderContextImplPtr ctx = new (autogc) RenderContextImpl;
|
||||
RenderContextImplPtr ctx = MakePtr<RenderContextImpl>();
|
||||
|
||||
hr = ctx->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext());
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
@ -403,7 +403,7 @@ void RendererImpl::CreateGifImageFrame(GifImage::Frame& frame, const GifImage& g
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
frame.texture = new (autogc) Texture;
|
||||
frame.texture = MakePtr<Texture>();
|
||||
NativePtr::Set(frame.texture, bitmap);
|
||||
|
||||
frame.texture->SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
|
||||
|
|
@ -769,7 +769,7 @@ void RendererImpl::CreateShapeSink(ShapeMaker& maker)
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ShapePtr shape = new (autogc) Shape;
|
||||
ShapePtr shape = MakePtr<Shape>();
|
||||
NativePtr::Set(shape, geometry);
|
||||
|
||||
maker.SetShape(shape);
|
||||
|
|
@ -945,7 +945,7 @@ void RendererImpl::CreateStrokeStyle(StrokeStyle& stroke_style)
|
|||
|
||||
RenderContextPtr RendererImpl::CreateTextureRenderContext(Texture& texture, const Size* desired_size)
|
||||
{
|
||||
RenderContextImplPtr ptr = new (autogc) RenderContextImpl;
|
||||
RenderContextImplPtr ptr = MakePtr<RenderContextImpl>();
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
if (!d2d_res_)
|
||||
|
|
|
|||
|
|
@ -24,26 +24,14 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
FontPtr Font::Create(const String& file)
|
||||
Font::Font(const String& file)
|
||||
{
|
||||
FontPtr ptr = new (autogc) Font;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(file);
|
||||
}
|
||||
|
||||
FontPtr Font::Create(const Resource& resource)
|
||||
Font::Font(const Resource& resource)
|
||||
{
|
||||
FontPtr ptr = new (autogc) Font;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(resource))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(resource);
|
||||
}
|
||||
|
||||
Font::Font() {}
|
||||
|
|
|
|||
|
|
@ -44,11 +44,11 @@ class Font : public NativeObject
|
|||
public:
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨×ÖÌå
|
||||
static FontPtr Create(const String& file);
|
||||
Font(const String& file);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨×ÖÌå
|
||||
static FontPtr Create(const Resource& resource);
|
||||
Font(const Resource& resource);
|
||||
|
||||
Font();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,36 +24,19 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
FramePtr Frame::Create(const String& file_path)
|
||||
Frame::Frame(const String& file_path)
|
||||
{
|
||||
FramePtr ptr = new (autogc) Frame;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
FramePtr Frame::Create(const Resource& res)
|
||||
Frame::Frame(const Resource& res)
|
||||
{
|
||||
FramePtr ptr = new (autogc) Frame;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(res);
|
||||
}
|
||||
|
||||
FramePtr Frame::Create(TexturePtr texture)
|
||||
Frame::Frame(TexturePtr texture)
|
||||
{
|
||||
FramePtr ptr = new (autogc) Frame;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetTexture(texture);
|
||||
}
|
||||
return ptr;
|
||||
SetTexture(texture);
|
||||
}
|
||||
|
||||
Frame::Frame() {}
|
||||
|
|
|
|||
|
|
@ -36,17 +36,17 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param file_path 图像路径
|
||||
static FramePtr Create(const String& file_path);
|
||||
Frame(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param res 图像资源
|
||||
static FramePtr Create(const Resource& res);
|
||||
Frame(const Resource& res);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建图像帧
|
||||
/// @param texture 纹理
|
||||
static FramePtr Create(TexturePtr texture);
|
||||
Frame(TexturePtr texture);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构建空图像帧
|
||||
|
|
|
|||
|
|
@ -24,31 +24,15 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
FrameSequencePtr FrameSequence::Create()
|
||||
FrameSequence::FrameSequence(const Vector<FramePtr>& frames)
|
||||
{
|
||||
FrameSequencePtr ptr = new (autogc) FrameSequence;
|
||||
return ptr;
|
||||
AddFrames(frames);
|
||||
}
|
||||
|
||||
FrameSequencePtr FrameSequence::Create(const Vector<FramePtr>& frames)
|
||||
{
|
||||
FrameSequencePtr ptr = new (autogc) FrameSequence;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->AddFrames(frames);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
FrameSequencePtr FrameSequence::Create(FramePtr frame, int cols, int rows, int max_num, float padding_x,
|
||||
FrameSequence::FrameSequence(FramePtr frame, int cols, int rows, int max_num, float padding_x,
|
||||
float padding_y)
|
||||
{
|
||||
FrameSequencePtr ptr = new (autogc) FrameSequence;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||
}
|
||||
return ptr;
|
||||
AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||
}
|
||||
|
||||
FrameSequence::FrameSequence() {}
|
||||
|
|
@ -103,7 +87,7 @@ void FrameSequence::AddFrames(FramePtr frame, int cols, int rows, int max_num, f
|
|||
|
||||
for (int j = 0; j < cols; j++)
|
||||
{
|
||||
FramePtr ptr = new (autogc) Frame;
|
||||
FramePtr ptr = MakePtr<Frame>();
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetTexture(frame->GetTexture());
|
||||
|
|
@ -140,7 +124,7 @@ size_t FrameSequence::GetFramesCount() const
|
|||
|
||||
FrameSequencePtr FrameSequence::Clone() const
|
||||
{
|
||||
auto frame_seq = new (autogc) FrameSequence;
|
||||
auto frame_seq = MakePtr<FrameSequence>();
|
||||
if (frame_seq)
|
||||
{
|
||||
frame_seq->AddFrames(frames_);
|
||||
|
|
@ -150,7 +134,7 @@ FrameSequencePtr FrameSequence::Clone() const
|
|||
|
||||
FrameSequencePtr FrameSequence::Reverse() const
|
||||
{
|
||||
auto frame_seq = new (autogc) FrameSequence;
|
||||
auto frame_seq = MakePtr<FrameSequence>();
|
||||
if (!frames_.empty())
|
||||
{
|
||||
for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter)
|
||||
|
|
|
|||
|
|
@ -34,14 +34,10 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
|
|||
class KGE_API FrameSequence : public ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨ÐòÁÐÖ¡
|
||||
static FrameSequencePtr Create();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建序列帧
|
||||
/// @param frames 图像帧集合
|
||||
static FrameSequencePtr Create(const Vector<FramePtr>& frames);
|
||||
FrameSequence(const Vector<FramePtr>& frames);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 按行列分割图像并创建序列帧
|
||||
|
|
@ -51,7 +47,7 @@ public:
|
|||
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
|
||||
/// @param padding_x X方向间隔
|
||||
/// @param padding_y Y方向间隔
|
||||
static FrameSequencePtr Create(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0,
|
||||
FrameSequence(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0,
|
||||
float padding_y = 0);
|
||||
|
||||
/// \~chinese
|
||||
|
|
|
|||
|
|
@ -25,26 +25,16 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
GifImagePtr GifImage::Create(const String& file_path)
|
||||
GifImage::GifImage(const String& file_path)
|
||||
: GifImage()
|
||||
{
|
||||
GifImagePtr ptr = new (autogc) GifImage;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
GifImagePtr GifImage::Create(const Resource& res)
|
||||
GifImage::GifImage(const Resource& res)
|
||||
: GifImage()
|
||||
{
|
||||
GifImagePtr ptr = new (autogc) GifImage;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(res);
|
||||
}
|
||||
|
||||
GifImage::GifImage()
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ class KGE_API GifImage : public NativeObject
|
|||
public:
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨GIFͼƬ
|
||||
static GifImagePtr Create(const String& file_path);
|
||||
GifImage(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief ´´½¨GIFͼƬ
|
||||
static GifImagePtr Create(const Resource& res);
|
||||
GifImage(const Resource& res);
|
||||
|
||||
GifImage();
|
||||
|
||||
|
|
|
|||
|
|
@ -136,35 +136,35 @@ bool Shape::ContainsPoint(const Point& point, const Matrix3x2* transform) const
|
|||
|
||||
ShapePtr Shape::CreateLine(const Point& begin, const Point& end)
|
||||
{
|
||||
ShapePtr output = new (autogc) Shape;
|
||||
ShapePtr output = MakePtr<Shape>();
|
||||
Renderer::GetInstance().CreateLineShape(*output, begin, end);
|
||||
return output;
|
||||
}
|
||||
|
||||
ShapePtr Shape::CreateRect(const Rect& rect)
|
||||
{
|
||||
ShapePtr output = new (autogc) Shape;
|
||||
ShapePtr output = MakePtr<Shape>();
|
||||
Renderer::GetInstance().CreateRectShape(*output, rect);
|
||||
return output;
|
||||
}
|
||||
|
||||
ShapePtr Shape::CreateRoundedRect(const Rect& rect, const Vec2& radius)
|
||||
{
|
||||
ShapePtr output = new (autogc) Shape;
|
||||
ShapePtr output = MakePtr<Shape>();
|
||||
Renderer::GetInstance().CreateRoundedRectShape(*output, rect, radius);
|
||||
return output;
|
||||
}
|
||||
|
||||
ShapePtr Shape::CreateCircle(const Point& center, float radius)
|
||||
{
|
||||
ShapePtr output = new (autogc) Shape;
|
||||
ShapePtr output = MakePtr<Shape>();
|
||||
Renderer::GetInstance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
|
||||
return output;
|
||||
}
|
||||
|
||||
ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius)
|
||||
{
|
||||
ShapePtr output = new (autogc) Shape;
|
||||
ShapePtr output = MakePtr<Shape>();
|
||||
Renderer::GetInstance().CreateEllipseShape(*output, center, radius);
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,6 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
ShapeMakerPtr ShapeMaker::Create()
|
||||
{
|
||||
ShapeMakerPtr ptr = new (autogc) ShapeMaker;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ShapeMaker::ShapeMaker() {}
|
||||
|
||||
ShapeMaker::~ShapeMaker()
|
||||
|
|
@ -151,8 +145,8 @@ void ShapeMaker::AddArc(const Point& point, const Size& radius, float rotation,
|
|||
|
||||
ShapePtr ShapeMaker::Combine(ShapePtr shape_a, ShapePtr shape_b, CombineMode mode, const Matrix3x2* matrix)
|
||||
{
|
||||
ShapeMakerPtr maker = ShapeMaker::Create();
|
||||
maker->OpenStream();
|
||||
ShapeMaker maker;
|
||||
maker.OpenStream();
|
||||
|
||||
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
|
||||
if (shape_a && shape_b)
|
||||
|
|
@ -170,8 +164,8 @@ ShapePtr ShapeMaker::Combine(ShapePtr shape_a, ShapePtr shape_b, CombineMode mod
|
|||
// not supported
|
||||
#endif
|
||||
|
||||
maker->CloseStream();
|
||||
return maker->GetShape();
|
||||
maker.CloseStream();
|
||||
return maker.GetShape();
|
||||
}
|
||||
|
||||
void ShapeMaker::OpenStream()
|
||||
|
|
|
|||
|
|
@ -46,10 +46,6 @@ enum class CombineMode
|
|||
class KGE_API ShapeMaker : public NativeObject
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建形状生成器
|
||||
static ShapeMakerPtr Create();
|
||||
|
||||
ShapeMaker();
|
||||
|
||||
~ShapeMaker();
|
||||
|
|
|
|||
|
|
@ -24,39 +24,30 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
StrokeStylePtr StrokeStyle::Create(float width, CapStyle cap, LineJoinStyle line_join)
|
||||
StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join)
|
||||
: StrokeStyle(width, cap, line_join, DashStyle::Solid)
|
||||
{
|
||||
return StrokeStyle::Create(width, cap, line_join, DashStyle::Solid);
|
||||
}
|
||||
|
||||
StrokeStylePtr StrokeStyle::Create(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash,
|
||||
float dash_offset)
|
||||
StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset)
|
||||
: StrokeStyle()
|
||||
{
|
||||
StrokeStylePtr ptr = new (autogc) StrokeStyle;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetStrokeWidth(width);
|
||||
ptr->SetCapStyle(cap);
|
||||
ptr->SetLineJoinStyle(line_join);
|
||||
ptr->SetDashStyle(dash);
|
||||
ptr->SetDashOffset(dash_offset);
|
||||
}
|
||||
return ptr;
|
||||
SetStrokeWidth(width);
|
||||
SetCapStyle(cap);
|
||||
SetLineJoinStyle(line_join);
|
||||
SetDashStyle(dash);
|
||||
SetDashOffset(dash_offset);
|
||||
}
|
||||
|
||||
StrokeStylePtr StrokeStyle::Create(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array,
|
||||
size_t dash_size, float dash_offset)
|
||||
StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
|
||||
float dash_offset)
|
||||
: StrokeStyle()
|
||||
{
|
||||
StrokeStylePtr ptr = new (autogc) StrokeStyle;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetStrokeWidth(width);
|
||||
ptr->SetCapStyle(cap);
|
||||
ptr->SetLineJoinStyle(line_join);
|
||||
ptr->SetDashStyle(dash_array, dash_size);
|
||||
ptr->SetDashOffset(dash_offset);
|
||||
}
|
||||
return ptr;
|
||||
SetStrokeWidth(width);
|
||||
SetCapStyle(cap);
|
||||
SetLineJoinStyle(line_join);
|
||||
SetDashStyle(dash_array, dash_size);
|
||||
SetDashOffset(dash_offset);
|
||||
}
|
||||
|
||||
StrokeStyle::StrokeStyle()
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ public:
|
|||
/// @param width 线条宽度
|
||||
/// @param cap 线条端点样式
|
||||
/// @param line_join 线条交点样式
|
||||
static StrokeStylePtr Create(float width, CapStyle cap = CapStyle::Flat,
|
||||
LineJoinStyle line_join = LineJoinStyle::Miter);
|
||||
StrokeStyle(float width, CapStyle cap = CapStyle::Flat, LineJoinStyle line_join = LineJoinStyle::Miter);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
|
|
@ -84,8 +83,7 @@ public:
|
|||
/// @param line_join 线条交点样式
|
||||
/// @param dash 线条虚线样式
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
static StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash,
|
||||
float dash_offset = 0.0f);
|
||||
StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset = 0.0f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
|
|
@ -95,8 +93,8 @@ public:
|
|||
/// @param dash_array 线条虚线的长度与间隙数组
|
||||
/// @param dash_size 线条虚线数组大小
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
static StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array,
|
||||
size_t dash_size, float dash_offset = 0.0f);
|
||||
StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
|
||||
float dash_offset = 0.0f);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建线条样式
|
||||
|
|
@ -107,10 +105,10 @@ public:
|
|||
/// @param dash_array 线条虚线的长度与间隙数组
|
||||
/// @param dash_offset 线条虚线偏移量
|
||||
template <size_t _DashSize>
|
||||
static inline StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join,
|
||||
float (&dash_array)[_DashSize], float dash_offset = 0.0f)
|
||||
StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float (&dash_array)[_DashSize],
|
||||
float dash_offset = 0.0f)
|
||||
: StrokeStyle(width, cap, line_join, dash_array, _DashSize, dash_offset)
|
||||
{
|
||||
return StrokeStyle::Create(width, cap, line_join, dash_array, _DashSize, dash_offset);
|
||||
}
|
||||
|
||||
StrokeStyle();
|
||||
|
|
|
|||
|
|
@ -28,28 +28,18 @@
|
|||
namespace kiwano
|
||||
{
|
||||
|
||||
TextLayoutPtr TextLayout::Create()
|
||||
{
|
||||
TextLayoutPtr ptr = new (autogc) TextLayout;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
TextLayoutPtr TextLayout::Create(const String& content, const TextStyle& style)
|
||||
{
|
||||
TextLayoutPtr ptr = new (autogc) TextLayout;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->Reset(content, style);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
TextLayout::TextLayout()
|
||||
: dirty_flag_(DirtyFlag::Clean)
|
||||
, line_count_(0)
|
||||
{
|
||||
}
|
||||
|
||||
TextLayout::TextLayout(const String& content, const TextStyle& style)
|
||||
: TextLayout()
|
||||
{
|
||||
Reset(content, style);
|
||||
}
|
||||
|
||||
void TextLayout::Reset(const String& content, const TextStyle& style)
|
||||
{
|
||||
content_ = content;
|
||||
|
|
|
|||
|
|
@ -38,19 +38,13 @@ KGE_DECLARE_SMART_PTR(TextLayout);
|
|||
class KGE_API TextLayout : public NativeObject
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 创建文本布局
|
||||
static TextLayoutPtr Create();
|
||||
TextLayout();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建文本布局
|
||||
/// @param content 文字内容
|
||||
/// @param style 文本样式
|
||||
static TextLayoutPtr Create(const String& content, const TextStyle& style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 构造空的文本布局
|
||||
TextLayout();
|
||||
TextLayout(const String& content, const TextStyle& style);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 文本布局是否陈旧
|
||||
|
|
|
|||
|
|
@ -30,26 +30,16 @@ namespace kiwano
|
|||
|
||||
InterpolationMode Texture::default_interpolation_mode_ = InterpolationMode::Linear;
|
||||
|
||||
TexturePtr Texture::Create(const String& file_path)
|
||||
Texture::Texture(const String& file_path)
|
||||
: Texture()
|
||||
{
|
||||
TexturePtr ptr = new (autogc) Texture;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
TexturePtr Texture::Create(const Resource& res)
|
||||
Texture::Texture(const Resource& res)
|
||||
: Texture()
|
||||
{
|
||||
TexturePtr ptr = new (autogc) Texture;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(res))
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
Load(res);
|
||||
}
|
||||
|
||||
Texture::Texture()
|
||||
|
|
|
|||
|
|
@ -56,11 +56,11 @@ class KGE_API Texture : public NativeObject
|
|||
public:
|
||||
/// \~chinese
|
||||
/// @brief 从本地文件创建纹理
|
||||
static TexturePtr Create(const String& file_path);
|
||||
Texture(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 从资源创建纹理
|
||||
static TexturePtr Create(const Resource& res);
|
||||
Texture(const Resource& res);
|
||||
|
||||
Texture();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ RefPtr<_Ty> CreateOrGetCache(_CacheTy& cache, const _PathTy& path, size_t hash)
|
|||
return iter->second;
|
||||
}
|
||||
|
||||
RefPtr<_Ty> texture = new (autogc) _Ty;
|
||||
RefPtr<_Ty> texture = MakePtr<_Ty>();
|
||||
if (texture->Load(path))
|
||||
{
|
||||
cache.insert(std::make_pair(hash, texture));
|
||||
|
|
|
|||
|
|
@ -94,17 +94,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
ConfigIniPtr ConfigIni::Create(const String& file_path)
|
||||
ConfigIni::ConfigIni() {}
|
||||
|
||||
ConfigIni::ConfigIni(const String& file_path)
|
||||
{
|
||||
ConfigIniPtr ptr = new (autogc) ConfigIni;
|
||||
if (ptr)
|
||||
{
|
||||
if (!ptr->Load(file_path))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
Load(file_path);
|
||||
}
|
||||
|
||||
bool ConfigIni::Load(const String& file_path)
|
||||
|
|
|
|||
|
|
@ -32,11 +32,6 @@ KGE_DECLARE_SMART_PTR(ConfigIni);
|
|||
class KGE_API ConfigIni : public ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 加载 ini 文件
|
||||
/// @param file_path 文件路径
|
||||
static ConfigIniPtr Create(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 键值字典
|
||||
typedef UnorderedMap<String, String> ValueMap;
|
||||
|
|
@ -45,6 +40,13 @@ public:
|
|||
/// @brief Section字典
|
||||
typedef UnorderedMap<String, ValueMap> SectionMap;
|
||||
|
||||
ConfigIni();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载 ini 文件
|
||||
/// @param file_path 文件路径
|
||||
ConfigIni(const String& file_path);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 加载 ini 文件
|
||||
/// @param file_path 文件路径
|
||||
|
|
|
|||
|
|
@ -29,15 +29,11 @@ TickEvent::TickEvent()
|
|||
{
|
||||
}
|
||||
|
||||
EventTickerPtr EventTicker::Create(Duration interval, int times)
|
||||
EventTicker::EventTicker() {}
|
||||
|
||||
EventTicker::EventTicker(Duration interval, int tick_count)
|
||||
: Ticker(interval, tick_count)
|
||||
{
|
||||
EventTickerPtr ptr = new (autogc) EventTicker;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetInterval(interval);
|
||||
ptr->SetTotalTickCount(times);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool EventTicker::Tick(Duration dt)
|
||||
|
|
|
|||
|
|
@ -57,11 +57,13 @@ class KGE_API EventTicker
|
|||
, public EventDispatcher
|
||||
{
|
||||
public:
|
||||
EventTicker();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 创建事件报时器
|
||||
/// @param interval 报时间隔
|
||||
/// @param times 报时次数(设 -1 为永久)
|
||||
static EventTickerPtr Create(Duration interval, int times = -1);
|
||||
/// @param tick_count 报时次数(设 -1 为永久)
|
||||
EventTicker(Duration interval, int tick_count = -1);
|
||||
|
||||
using Ticker::Tick;
|
||||
|
||||
|
|
|
|||
|
|
@ -194,10 +194,8 @@ std::ostream& ConsoleColorBrush(std::ostream& os)
|
|||
return os;
|
||||
}
|
||||
|
||||
LogProviderPtr ConsoleLogProvider::Create()
|
||||
ConsoleLogProvider::ConsoleLogProvider()
|
||||
{
|
||||
LogProviderPtr ptr = new ConsoleLogProvider;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
ConsoleLogProvider::~ConsoleLogProvider()
|
||||
|
|
@ -242,14 +240,9 @@ ConsoleLogProvider::ConsoleColor ConsoleLogProvider::GetColor(LogLevel level)
|
|||
return ConsoleColorBrush<0>;
|
||||
}
|
||||
|
||||
LogProviderPtr FileLogProvider::Create(const String& filepath, std::ios_base::openmode mode)
|
||||
FileLogProvider::FileLogProvider(const String& filepath, std::ios_base::openmode mode)
|
||||
{
|
||||
RefPtr<FileLogProvider> ptr = new FileLogProvider;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->ofs_.open(filepath, mode);
|
||||
}
|
||||
return ptr;
|
||||
ofs_.open(filepath, mode);
|
||||
}
|
||||
|
||||
FileLogProvider::~FileLogProvider()
|
||||
|
|
@ -500,10 +493,10 @@ Logger::Logger()
|
|||
, buffer_(1024)
|
||||
, stream_(&buffer_)
|
||||
{
|
||||
LogFormaterPtr formater = new TextFormater;
|
||||
LogFormaterPtr formater = MakePtr<TextFormater>();
|
||||
SetFormater(formater);
|
||||
|
||||
LogProviderPtr provider = ConsoleLogProvider::Create();
|
||||
LogProviderPtr provider = MakePtr<ConsoleLogProvider>();
|
||||
AddProvider(provider);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ protected:
|
|||
class KGE_API ConsoleLogProvider : public LogProvider
|
||||
{
|
||||
public:
|
||||
static LogProviderPtr Create();
|
||||
ConsoleLogProvider();
|
||||
|
||||
virtual ~ConsoleLogProvider();
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ private:
|
|||
class KGE_API FileLogProvider : public LogProvider
|
||||
{
|
||||
public:
|
||||
static LogProviderPtr Create(const String& filepath, std::ios_base::openmode mode = std::ios_base::out);
|
||||
FileLogProvider(const String& filepath, std::ios_base::openmode mode = std::ios_base::out);
|
||||
|
||||
virtual ~FileLogProvider();
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
|||
if (type == "gif")
|
||||
{
|
||||
// GIF image
|
||||
GifImagePtr gif = new (autogc) GifImage;
|
||||
GifImagePtr gif = MakePtr<GifImage>();
|
||||
if (gif && gif->Load(gdata->path + file))
|
||||
{
|
||||
return loader->AddObject(id, gif);
|
||||
|
|
@ -224,7 +224,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
|||
if (!file.empty())
|
||||
{
|
||||
// Simple image
|
||||
FramePtr frame = new (autogc) Frame;
|
||||
FramePtr frame = MakePtr<Frame>();
|
||||
if (frame && frame->Load(gdata->path + file))
|
||||
{
|
||||
return loader->AddObject(id, frame);
|
||||
|
|
@ -246,13 +246,13 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
|||
frames.reserve(files.size());
|
||||
for (const auto& file : files)
|
||||
{
|
||||
FramePtr frame = new (autogc) Frame;
|
||||
FramePtr frame = MakePtr<Frame>();
|
||||
if (frame->Load(gdata->path + file))
|
||||
{
|
||||
frames.push_back(frame);
|
||||
}
|
||||
}
|
||||
FrameSequencePtr frame_seq = FrameSequence::Create(frames);
|
||||
FrameSequencePtr frame_seq = MakePtr<FrameSequence>(frames);
|
||||
if (frame_seq)
|
||||
{
|
||||
return !!loader->AddObject(id, frame_seq);
|
||||
|
|
@ -271,10 +271,10 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
|||
if (rows || cols)
|
||||
{
|
||||
// Frame slices
|
||||
FramePtr frame = new (autogc) Frame;
|
||||
FramePtr frame = MakePtr<Frame>();
|
||||
if (frame && frame->Load(gdata->path + file))
|
||||
{
|
||||
FrameSequencePtr frame_seq = new (autogc) FrameSequence;
|
||||
FrameSequencePtr frame_seq = MakePtr<FrameSequence>();
|
||||
if (frame_seq)
|
||||
{
|
||||
frame_seq->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||
|
|
@ -285,7 +285,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
|||
else
|
||||
{
|
||||
// Simple image
|
||||
FramePtr frame = new (autogc) Frame;
|
||||
FramePtr frame = MakePtr<Frame>();
|
||||
if (frame && frame->Load(gdata->path + file))
|
||||
{
|
||||
return loader->AddObject(id, frame);
|
||||
|
|
@ -300,7 +300,7 @@ bool LoadFontsFromData(ResourceCache* loader, GlobalData* gdata, const String& i
|
|||
if (!gdata)
|
||||
return false;
|
||||
|
||||
FontPtr font = new (autogc) Font;
|
||||
FontPtr font = MakePtr<Font>();
|
||||
if (font && font->Load(gdata->path + file))
|
||||
{
|
||||
return loader->AddObject(id, font);
|
||||
|
|
|
|||
|
|
@ -22,37 +22,32 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
TaskPtr Task::Create(const Callback& cb, TickerPtr ticker)
|
||||
Task::Task(const Callback& cb, TickerPtr ticker)
|
||||
: running_(true)
|
||||
, removeable_(false)
|
||||
, callback_(cb)
|
||||
, ticker_(ticker)
|
||||
{
|
||||
TaskPtr ptr = new (autogc) Task;
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetCallback(cb);
|
||||
ptr->SetTicker(ticker);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
TaskPtr Task::Create(const String& name, const Callback& cb, TickerPtr ticker)
|
||||
Task::Task(const String& name, const Callback& cb, TickerPtr ticker)
|
||||
: Task(cb, ticker)
|
||||
{
|
||||
TaskPtr ptr = Task::Create(cb, ticker);
|
||||
if (ptr)
|
||||
{
|
||||
ptr->SetName(name);
|
||||
}
|
||||
return ptr;
|
||||
SetName(name);
|
||||
}
|
||||
|
||||
TaskPtr Task::Create(const Callback& cb, Duration interval, int times)
|
||||
Task::Task(const Callback& cb, Duration interval, int times)
|
||||
: running_(true)
|
||||
, removeable_(false)
|
||||
, callback_(cb)
|
||||
{
|
||||
TickerPtr ticker = Ticker::Create(interval, times);
|
||||
return Task::Create(cb, ticker);
|
||||
ticker_ = MakePtr<Ticker>(interval, times);
|
||||
}
|
||||
|
||||
TaskPtr Task::Create(const String& name, const Callback& cb, Duration interval, int times)
|
||||
Task::Task(const String& name, const Callback& cb, Duration interval, int times)
|
||||
: Task(cb, interval, times)
|
||||
{
|
||||
TickerPtr ticker = Ticker::Create(interval, times);
|
||||
return Task::Create(name, cb, ticker);
|
||||
SetName(name);
|
||||
}
|
||||
|
||||
Task::Task()
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue