remove Create functions

This commit is contained in:
Nomango 2020-07-22 21:08:48 +08:00
parent c0f90d235a
commit 5a877ccf7b
107 changed files with 944 additions and 1597 deletions

View File

@ -18,6 +18,7 @@
<ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" /> <ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" />
<ClInclude Include="..\..\src\kiwano\base\ObjectPool.h" /> <ClInclude Include="..\..\src\kiwano\base\ObjectPool.h" />
<ClInclude Include="..\..\src\kiwano\base\RefObject.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\Allocator.h" />
<ClInclude Include="..\..\src\kiwano\core\Any.h" /> <ClInclude Include="..\..\src\kiwano\core\Any.h" />
<ClInclude Include="..\..\src\kiwano\core\Cloneable.h" /> <ClInclude Include="..\..\src\kiwano\core\Cloneable.h" />
@ -52,7 +53,7 @@
<ClInclude Include="..\..\src\kiwano\2d\TextActor.h" /> <ClInclude Include="..\..\src\kiwano\2d\TextActor.h" />
<ClInclude Include="..\..\src\kiwano\2d\Transition.h" /> <ClInclude Include="..\..\src\kiwano\2d\Transition.h" />
<ClInclude Include="..\..\src\kiwano\core\Resource.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\Constants.h" />
<ClInclude Include="..\..\src\kiwano\math\EaseFunctions.h" /> <ClInclude Include="..\..\src\kiwano\math\EaseFunctions.h" />
<ClInclude Include="..\..\src\kiwano\math\Math.h" /> <ClInclude Include="..\..\src\kiwano\math\Math.h" />

View File

@ -348,10 +348,13 @@
<ClInclude Include="..\..\src\kiwano\2d\action\Action.h"> <ClInclude Include="..\..\src\kiwano\2d\action\Action.h">
<Filter>2d\action</Filter> <Filter>2d\action</Filter>
</ClInclude> </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> <Filter>core</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\kiwano\base\RefObject.h"> <ClInclude Include="..\..\src\kiwano\base\RefPtr.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

View File

@ -27,26 +27,16 @@ namespace kiwano
{ {
namespace audio namespace audio
{ {
SoundPtr Sound::Create(const String& file_path) Sound::Sound(const String& file_path)
: Sound()
{ {
SoundPtr ptr = new (autogc) Sound; Load(file_path);
if (ptr)
{
if (!ptr->Load(file_path))
return nullptr;
}
return ptr;
} }
SoundPtr Sound::Create(const Resource& res) Sound::Sound(const Resource& res)
: Sound()
{ {
SoundPtr ptr = new (autogc) Sound; Load(res);
if (ptr)
{
if (!ptr->Load(res))
return nullptr;
}
return ptr;
} }
Sound::Sound() Sound::Sound()

View File

@ -50,12 +50,12 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建音频对象 /// @brief 创建音频对象
/// @param res 本地音频文件路径 /// @param res 本地音频文件路径
static SoundPtr Create(const String& file_path); Sound(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 创建音频对象 /// @brief 创建音频对象
/// @param res 音频资源 /// @param res 音频资源
static SoundPtr Create(const Resource& res); Sound(const Resource& res);
Sound(); Sound();

View File

@ -25,12 +25,6 @@ namespace kiwano
namespace audio namespace audio
{ {
SoundPlayerPtr SoundPlayer::Create()
{
SoundPlayerPtr ptr = new (autogc) SoundPlayer;
return ptr;
}
SoundPlayer::SoundPlayer() SoundPlayer::SoundPlayer()
: volume_(1.f) : volume_(1.f)
{ {
@ -47,7 +41,7 @@ size_t SoundPlayer::Load(const String& file_path)
if (sound_cache_.end() != sound_cache_.find(hash)) if (sound_cache_.end() != sound_cache_.find(hash))
return hash; return hash;
SoundPtr sound = new (autogc) Sound; SoundPtr sound = MakePtr<Sound>();
if (sound) if (sound)
{ {
if (sound->Load(file_path)) 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)) if (sound_cache_.end() != sound_cache_.find(hash_code))
return hash_code; return hash_code;
SoundPtr sound = new (autogc) Sound; SoundPtr sound = MakePtr<Sound>();
if (sound) if (sound)
{ {

View File

@ -40,10 +40,6 @@ KGE_DECLARE_SMART_PTR(SoundPlayer);
class KGE_API SoundPlayer : public ObjectBase class KGE_API SoundPlayer : public ObjectBase
{ {
public: public:
/// \~chinese
/// @brief 创建音频播放器
static SoundPlayerPtr Create();
SoundPlayer(); SoundPlayer();
~SoundPlayer(); ~SoundPlayer();

View File

@ -25,27 +25,17 @@ namespace kiwano
namespace imgui 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() ImGuiLayer::ImGuiLayer()
{ {
SetSwallowEvents(true); SetSwallowEvents(true);
} }
ImGuiLayer::ImGuiLayer(const String& name, const ImGuiPipeline& item)
: ImGuiLayer()
{
AddItem(name, item);
}
ImGuiLayer::~ImGuiLayer() {} ImGuiLayer::~ImGuiLayer() {}
void ImGuiLayer::OnRender(RenderContext& ctx) void ImGuiLayer::OnRender(RenderContext& ctx)

View File

@ -38,17 +38,13 @@ using ImGuiPipeline = Function<void()>;
class ImGuiLayer : public LayerActor class ImGuiLayer : public LayerActor
{ {
public: public:
/// \~chinese ImGuiLayer();
/// @brief ´´½¨ImGuiͼ²ã
static ImGuiLayerPtr Create();
/// \~chinese /// \~chinese
/// @brief ´´½¨ImGuiͼ²ã /// @brief ´´½¨ImGuiͼ²ã
/// @param name ÔªËØÃû³Æ /// @param name ÔªËØÃû³Æ
/// @param item ¹ÜµÀ /// @param item ¹ÜµÀ
static ImGuiLayerPtr Create(const String& name, const ImGuiPipeline& item); ImGuiLayer(const String& name, const ImGuiPipeline& item);
ImGuiLayer();
virtual ~ImGuiLayer(); virtual ~ImGuiLayer();

View File

@ -253,7 +253,7 @@ void HttpModule::NetworkThread()
return; return;
} }
HttpResponsePtr response = new (autogc) HttpResponse(request); HttpResponsePtr response = MakePtr<HttpResponse>(request);
Perform(request, response); Perform(request, response);
response_mutex_.lock(); response_mutex_.lock();

View File

@ -26,42 +26,23 @@ namespace kiwano
namespace network 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; SetData(data);
if (ptr)
{
ptr->SetUrl(url);
ptr->SetType(type);
ptr->SetData(data);
ptr->SetResponseCallback(callback);
}
return ptr;
} }
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; SetJsonData(json);
if (ptr)
{
ptr->SetUrl(url);
ptr->SetType(type);
ptr->SetJsonData(json);
ptr->SetResponseCallback(callback);
}
return ptr;
} }
void HttpRequest::SetJsonData(const Json& json) void HttpRequest::SetJsonData(const Json& json)

View File

@ -63,7 +63,7 @@ public:
/// @param url 请求地址 /// @param url 请求地址
/// @param type 请求类型 /// @param type 请求类型
/// @param callback 响应回调函数 /// @param callback 响应回调函数
static HttpRequestPtr Create(const String& url, HttpType type, const ResponseCallback& callback); HttpRequest(const String& url, HttpType type, const ResponseCallback& callback);
/// \~chinese /// \~chinese
/// @brief 创建HTTP请求 /// @brief 创建HTTP请求
@ -71,7 +71,7 @@ public:
/// @param type 请求类型 /// @param type 请求类型
/// @param data 请求数据 /// @param data 请求数据
/// @param callback 响应回调函数 /// @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 /// \~chinese
/// @brief 创建HTTP请求 /// @brief 创建HTTP请求
@ -79,12 +79,10 @@ public:
/// @param type 请求类型 /// @param type 请求类型
/// @param json 请求的JSON数据 /// @param json 请求的JSON数据
/// @param callback 响应回调函数 /// @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();
HttpRequest(HttpType type);
/// \~chinese /// \~chinese
/// @brief 设置请求地址 /// @brief 设置请求地址
void SetUrl(const String& url); 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) inline void HttpRequest::SetUrl(const String& url)
{ {
url_ = url; url_ = url;

View File

@ -29,7 +29,7 @@ namespace physics
FixturePtr Fixture::CreateCircle(const Param& param, float radius, const Point& offset) FixturePtr Fixture::CreateCircle(const Param& param, float radius, const Point& offset)
{ {
FixturePtr ptr = new (autogc) Fixture; FixturePtr ptr = MakePtr<Fixture>();
if (ptr) if (ptr)
{ {
auto shape = std::make_unique<b2CircleShape>(); 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 Fixture::CreateRect(const Param& param, const Size& size, const Point& offset, float rotation)
{ {
FixturePtr ptr = new (autogc) Fixture; FixturePtr ptr = MakePtr<Fixture>();
if (ptr) if (ptr)
{ {
b2Vec2 b2size = global::LocalToWorld(size); 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 Fixture::CreatePolygon(const Param& param, const Vector<Point>& vertexs)
{ {
FixturePtr ptr = new (autogc) Fixture; FixturePtr ptr = MakePtr<Fixture>();
if (ptr) if (ptr)
{ {
Vector<b2Vec2> b2vertexs; 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 Fixture::CreateEdge(const Param& param, const Point& p1, const Point& p2)
{ {
FixturePtr ptr = new (autogc) Fixture; FixturePtr ptr = MakePtr<Fixture>();
if (ptr) if (ptr)
{ {
b2Vec2 start = global::LocalToWorld(p1); 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 Fixture::CreateChain(const Param& param, const Vector<Point>& vertices, bool loop)
{ {
FixturePtr ptr = new (autogc) Fixture; FixturePtr ptr = MakePtr<Fixture>();
if (ptr) if (ptr)
{ {
Vector<b2Vec2> b2vertices; Vector<b2Vec2> b2vertices;

View File

@ -107,18 +107,9 @@ void Joint::Destroy()
// DistanceJoint // DistanceJoint
// //
DistanceJointPtr DistanceJoint::Create(const Param& param) DistanceJoint::DistanceJoint(const Param& param)
{ : param_(param)
DistanceJointPtr ptr = new (autogc) DistanceJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
DistanceJoint::DistanceJoint()
: raw_joint_(nullptr)
{ {
} }
@ -154,18 +145,9 @@ float DistanceJoint::GetLength() const
// FrictionJoint // FrictionJoint
// //
FrictionJointPtr FrictionJoint::Create(const Param& param) FrictionJoint::FrictionJoint(const Param& param)
{ : param_(param)
FrictionJointPtr ptr = new (autogc) FrictionJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
FrictionJoint::FrictionJoint()
: raw_joint_(nullptr)
{ {
} }
@ -212,18 +194,9 @@ float FrictionJoint::GetMaxTorque() const
// GearJoint // GearJoint
// //
GearJointPtr GearJoint::Create(const Param& param) GearJoint::GearJoint(const Param& param)
{ : param_(param)
GearJointPtr ptr = new (autogc) GearJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
GearJoint::GearJoint()
: raw_joint_(nullptr)
{ {
} }
@ -258,18 +231,9 @@ float GearJoint::GetRatio() const
// MotorJoint // MotorJoint
// //
MotorJointPtr MotorJoint::Create(const Param& param) MotorJoint::MotorJoint(const Param& param)
{ : param_(param)
MotorJointPtr ptr = new (autogc) MotorJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
MotorJoint::MotorJoint()
: raw_joint_(nullptr)
{ {
} }
@ -317,18 +281,9 @@ float MotorJoint::GetMaxTorque() const
// PrismaticJoint // PrismaticJoint
// //
PrismaticJointPtr PrismaticJoint::Create(const Param& param) PrismaticJoint::PrismaticJoint(const Param& param)
{ : param_(param)
PrismaticJointPtr ptr = new (autogc) PrismaticJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
PrismaticJoint::PrismaticJoint()
: raw_joint_(nullptr)
{ {
} }
@ -386,18 +341,9 @@ void PrismaticJoint::SetLimits(float lower, float upper)
// PulleyJoint // PulleyJoint
// //
PulleyJointPtr PulleyJoint::Create(const Param& param) PulleyJoint::PulleyJoint(const Param& param)
{ : param_(param)
PulleyJointPtr ptr = new (autogc) PulleyJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
PulleyJoint::PulleyJoint()
: raw_joint_(nullptr)
{ {
} }
@ -462,18 +408,9 @@ float PulleyJoint::GetCurrentLengthB() const
// RevoluteJoint // RevoluteJoint
// //
RevoluteJointPtr RevoluteJoint::Create(const Param& param) RevoluteJoint::RevoluteJoint(const Param& param)
{ : param_(param)
RevoluteJointPtr ptr = new (autogc) RevoluteJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
RevoluteJoint::RevoluteJoint()
: raw_joint_(nullptr)
{ {
} }
@ -542,18 +479,9 @@ float RevoluteJoint::GetMaxMotorTorque() const
// RopeJoint // RopeJoint
// //
RopeJointPtr RopeJoint::Create(const Param& param) RopeJoint::RopeJoint(const Param& param)
{ : param_(param)
RopeJointPtr ptr = new (autogc) RopeJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
RopeJoint::RopeJoint()
: raw_joint_(nullptr)
{ {
} }
@ -590,18 +518,9 @@ float RopeJoint::GetMaxLength() const
// WeldJoint // WeldJoint
// //
WeldJointPtr WeldJoint::Create(const Param& param) WeldJoint::WeldJoint(const Param& param)
{ : param_(param)
WeldJointPtr ptr = new (autogc) WeldJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
WeldJoint::WeldJoint()
: raw_joint_(nullptr)
{ {
} }
@ -624,18 +543,9 @@ bool WeldJoint::Init(PhysicWorld* world)
// WheelJoint // WheelJoint
// //
WheelJointPtr WheelJoint::Create(const Param& param) WheelJoint::WheelJoint(const Param& param)
{ : param_(param)
WheelJointPtr ptr = new (autogc) WheelJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
WheelJoint::WheelJoint()
: raw_joint_(nullptr)
{ {
} }
@ -686,18 +596,9 @@ float WheelJoint::GetMaxMotorTorque() const
// MouseJoint // MouseJoint
// //
MouseJointPtr MouseJoint::Create(const Param& param) MouseJoint::MouseJoint(const Param& param)
{ : param_(param)
MouseJointPtr ptr = new (autogc) MouseJoint; , raw_joint_(nullptr)
if (ptr)
{
ptr->param_ = param;
}
return ptr;
}
MouseJoint::MouseJoint()
: raw_joint_(nullptr)
{ {
} }

View File

@ -161,9 +161,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建固定距离关节 /// @brief 创建固定距离关节
/// @param param 关节参数 /// @param param 关节参数
static DistanceJointPtr Create(const Param& param); DistanceJoint(const Param& param);
DistanceJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -226,9 +224,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建摩擦关节 /// @brief 创建摩擦关节
/// @param param 关节参数 /// @param param 关节参数
static FrictionJointPtr Create(const Param& param); FrictionJoint(const Param& param);
FrictionJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -285,9 +281,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建齿轮关节 /// @brief 创建齿轮关节
/// @param param 关节参数 /// @param param 关节参数
static GearJointPtr Create(const Param& param); GearJoint(const Param& param);
GearJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -336,9 +330,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建马达关节 /// @brief 创建马达关节
/// @param param 关节参数 /// @param param 关节参数
static MotorJointPtr Create(const Param& param); MotorJoint(const Param& param);
MotorJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -405,9 +397,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建平移关节 /// @brief 创建平移关节
/// @param param 关节参数 /// @param param 关节参数
static PrismaticJointPtr Create(const Param& param); PrismaticJoint(const Param& param);
PrismaticJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -509,9 +499,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建滑轮关节 /// @brief 创建滑轮关节
/// @param param 关节参数 /// @param param 关节参数
static PulleyJointPtr Create(const Param& param); PulleyJoint(const Param& param);
PulleyJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -588,9 +576,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建旋转关节 /// @brief 创建旋转关节
/// @param param 关节参数 /// @param param 关节参数
static RevoluteJointPtr Create(const Param& param); RevoluteJoint(const Param& param);
RevoluteJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -687,9 +673,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建绳关节 /// @brief 创建绳关节
/// @param param 关节参数 /// @param param 关节参数
static RopeJointPtr Create(const Param& param); RopeJoint(const Param& param);
RopeJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -738,9 +722,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建焊接关节 /// @brief 创建焊接关节
/// @param param 关节参数 /// @param param 关节参数
static WeldJointPtr Create(const Param& param); WeldJoint(const Param& param);
WeldJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -809,9 +791,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建轮关节 /// @brief 创建轮关节
/// @param param 关节参数 /// @param param 关节参数
static WheelJointPtr Create(const Param& param); WheelJoint(const Param& param);
WheelJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节
@ -911,9 +891,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建鼠标关节 /// @brief 创建鼠标关节
/// @param param 关节参数 /// @param param 关节参数
static MouseJointPtr Create(const Param& param); MouseJoint(const Param& param);
MouseJoint();
/// \~chinese /// \~chinese
/// @brief 初始化关节 /// @brief 初始化关节

View File

@ -28,37 +28,20 @@ namespace kiwano
namespace physics namespace physics
{ {
PhysicBodyPtr PhysicBody::Create(PhysicWorldPtr world, Type type) PhysicBody::PhysicBody(PhysicWorld* 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()
: body_(nullptr) : body_(nullptr)
, world_(nullptr) , world_(world)
, type_(Type::Static) , type_(Type::Static)
, category_bits_(0x0001) , category_bits_(0x0001)
, mask_bits_(0xFFFF) , mask_bits_(0xFFFF)
, group_index_(0) , group_index_(0)
{ {
SetName(KGE_PHYSIC_COMP_NAME); SetName(KGE_PHYSIC_COMP_NAME);
if (Init(world))
{
world->AddBody(this);
}
} }
PhysicBody::~PhysicBody() {} PhysicBody::~PhysicBody() {}
@ -88,11 +71,6 @@ void PhysicBody::DestroyComponent()
} }
} }
bool PhysicBody::Init(PhysicWorldPtr world)
{
return Init(world.Get());
}
bool PhysicBody::Init(PhysicWorld* world) bool PhysicBody::Init(PhysicWorld* world)
{ {
KGE_ASSERT(body_ == nullptr); KGE_ASSERT(body_ == nullptr);

View File

@ -54,23 +54,10 @@ public:
/// @brief 初始化物体 /// @brief 初始化物体
/// @param world 物理世界 /// @param world 物理世界
/// @param type 物体类型 /// @param type 物体类型
static PhysicBodyPtr Create(PhysicWorldPtr world, Type type); PhysicBody(PhysicWorld* world, Type type);
/// \~chinese
/// @brief 初始化物体
/// @param world 物理世界
/// @param type 物体类型
static PhysicBodyPtr Create(PhysicWorld* world, Type type);
PhysicBody();
virtual ~PhysicBody(); virtual ~PhysicBody();
/// \~chinese
/// @brief 初始化物体
/// @param[in] world 物理世界
bool Init(PhysicWorldPtr world);
/// \~chinese /// \~chinese
/// @brief 初始化物体 /// @brief 初始化物体
/// @param[in] world 物理世界 /// @param[in] world 物理世界

View File

@ -31,11 +31,11 @@ class PhysicWorld::DebugDrawer : public b2Draw
public: public:
DebugDrawer(const Size& size) DebugDrawer(const Size& size)
{ {
canvas_ = Canvas::Create(size); canvas_ = MakePtr<Canvas>(size);
ctx_ = canvas_->GetContext2D(); ctx_ = canvas_->GetContext2D();
fill_brush_ = Brush::Create(Color::White); fill_brush_ = MakePtr<Brush>(Color::White);
line_brush_ = Brush::Create(Color::White); line_brush_ = MakePtr<Brush>(Color::White);
b2Draw::SetFlags(b2Draw::e_shapeBit | b2Draw::e_jointBit | b2Draw::e_jointBit | b2Draw::e_centerOfMassBit); 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; SetGravity(gravity);
return ptr;
}
PhysicWorldPtr PhysicWorld::Create(const Vec2& gravity)
{
PhysicWorldPtr ptr = new (autogc) PhysicWorld;
if (ptr)
{
ptr->SetGravity(gravity);
}
return ptr;
} }
PhysicWorld::PhysicWorld() PhysicWorld::PhysicWorld()

View File

@ -47,16 +47,12 @@ class KGE_API PhysicWorld : public Component
friend class Joint; friend class Joint;
public: public:
/// \~chinese PhysicWorld();
/// @brief 创建物理世界
static PhysicWorldPtr Create();
/// \~chinese /// \~chinese
/// @brief 创建物理世界 /// @brief 创建物理世界
/// @param gravity 重力 /// @param gravity 重力
static PhysicWorldPtr Create(const Vec2& gravity); PhysicWorld(const Vec2& gravity);
PhysicWorld();
virtual ~PhysicWorld(); virtual ~PhysicWorld();

View File

@ -39,12 +39,6 @@ void Actor::SetDefaultAnchor(float anchor_x, float anchor_y)
default_anchor_y = anchor_y; default_anchor_y = anchor_y;
} }
ActorPtr Actor::Create()
{
ActorPtr ptr = new (autogc) Actor;
return ptr;
}
Actor::Actor() Actor::Actor()
: ComponentManager(this) : ComponentManager(this)
, visible_(true) , visible_(true)
@ -264,18 +258,18 @@ bool Actor::HandleEvent(Event* evt)
{ {
hover_ = true; hover_ = true;
MouseHoverEventPtr hover = new (autogc) MouseHoverEvent; auto hover = new (autogc) MouseHoverEvent;
hover->pos = mouse_evt->pos; hover->pos = mouse_evt->pos;
HandleEvent(hover.Get()); HandleEvent(hover);
} }
else if (hover_ && !contains) else if (hover_ && !contains)
{ {
hover_ = false; hover_ = false;
pressed_ = false; pressed_ = false;
MouseOutEventPtr out = new (autogc) MouseOutEvent; auto out = new (autogc) MouseOutEvent;
out->pos = mouse_evt->pos; out->pos = mouse_evt->pos;
HandleEvent(out.Get()); HandleEvent(out);
} }
} }
@ -290,10 +284,10 @@ bool Actor::HandleEvent(Event* evt)
auto mouse_up_evt = dynamic_cast<MouseUpEvent*>(evt); auto mouse_up_evt = dynamic_cast<MouseUpEvent*>(evt);
MouseClickEventPtr click = new (autogc) MouseClickEvent; auto click = new (autogc) MouseClickEvent;
click->pos = mouse_up_evt->pos; click->pos = mouse_up_evt->pos;
click->button = mouse_up_evt->button; click->button = mouse_up_evt->button;
HandleEvent(click.Get()); HandleEvent(click);
} }
} }
return true; return true;

View File

@ -77,10 +77,6 @@ public:
/// @brief 角色更新回调函数 /// @brief 角色更新回调函数
typedef Function<void(Duration)> UpdateCallback; typedef Function<void(Duration)> UpdateCallback;
/// \~chinese
/// @brief ´´˝¨˝ÇÉŤ
static ActorPtr Create();
Actor(); Actor();
virtual ~Actor(); virtual ~Actor();

View File

@ -24,25 +24,11 @@
namespace kiwano namespace kiwano
{ {
CanvasPtr Canvas::Create(const Size& size) Canvas::Canvas(const Size& size)
{ {
CanvasPtr ptr = new (autogc) Canvas; ResizeAndClear(size);
if (ptr)
{
try
{
ptr->ResizeAndClear(size);
}
catch (std::exception)
{
return nullptr;
}
}
return ptr;
} }
Canvas::Canvas() {}
RenderContextPtr Canvas::GetContext2D() const RenderContextPtr Canvas::GetContext2D() const
{ {
return render_ctx_; return render_ctx_;
@ -58,7 +44,7 @@ void Canvas::OnRender(RenderContext& ctx)
void Canvas::ResizeAndClear(Size size) void Canvas::ResizeAndClear(Size size)
{ {
texture_cached_ = new (autogc) Texture; texture_cached_ = MakePtr<Texture>();
render_ctx_ = RenderContext::Create(*texture_cached_, size); render_ctx_ = RenderContext::Create(*texture_cached_, size);
SetSize(render_ctx_->GetSize()); SetSize(render_ctx_->GetSize());

View File

@ -45,7 +45,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建画布 /// @brief 创建画布
/// @param size 画布大小 /// @param size 画布大小
static CanvasPtr Create(const Size& size); Canvas(const Size& size);
/// \~chinese /// \~chinese
/// @brief 获取2D绘图上下文 /// @brief 获取2D绘图上下文
@ -62,9 +62,6 @@ public:
void OnRender(RenderContext& ctx) override; void OnRender(RenderContext& ctx) override;
private:
Canvas();
private: private:
TexturePtr texture_cached_; TexturePtr texture_cached_;
RenderContextPtr render_ctx_; RenderContextPtr render_ctx_;

View File

@ -54,10 +54,10 @@ DebugActor::DebugActor()
comma_locale_ = std::locale(std::locale(), new comma_numpunct); 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)); background_brush_->SetColor(Color::Rgba(0x000000, 0.7f));
BrushPtr fill_brush = new (autogc) Brush; BrushPtr fill_brush = MakePtr<Brush>();
fill_brush->SetColor(Color::White); fill_brush->SetColor(Color::White);
debug_text_style_.font_family = "Arial"; debug_text_style_.font_family = "Arial";

View File

@ -25,38 +25,6 @@
namespace kiwano 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() GifSprite::GifSprite()
: animating_(false) : animating_(false)
, next_index_(0) , 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) bool GifSprite::Load(const String& file_path)
{ {
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path); GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path);
@ -92,7 +78,7 @@ bool GifSprite::Load(GifImagePtr gif)
frame_rt_.Reset(); frame_rt_.Reset();
Size frame_size = Size(float(gif_->GetWidthInPixels()), float(gif_->GetHeightInPixels())); 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); frame_rt_ = RenderContext::Create(*frame_to_render_, frame_size);
SetSize(frame_rt_->GetSize()); SetSize(frame_rt_->GetSize());
@ -229,7 +215,7 @@ void GifSprite::SaveComposedFrame()
if (!saved_frame_) if (!saved_frame_)
{ {
saved_frame_ = new (autogc) Texture; saved_frame_ = MakePtr<Texture>();
frame_rt_->CreateTexture(*saved_frame_, frame_to_render_->GetSizeInPixels()); frame_rt_->CreateTexture(*saved_frame_, frame_to_render_->GetSizeInPixels());
} }
saved_frame_->CopyFrom(frame_to_render_); saved_frame_->CopyFrom(frame_to_render_);

View File

@ -48,22 +48,22 @@ public:
/// @brief GIF²¥·Å½áÊø»Øµ÷ /// @brief GIF²¥·Å½áÊø»Øµ÷
using DoneCallback = Function<void()>; using DoneCallback = Function<void()>;
GifSprite();
/// \~chinese /// \~chinese
/// @brief ´´½¨GIF¾«Áé /// @brief ´´½¨GIF¾«Áé
/// @param file_path GIFͼƬ·¾¶ /// @param file_path GIFͼƬ·¾¶
static GifSpritePtr Create(const String& file_path); GifSprite(const String& file_path);
/// \~chinese /// \~chinese
/// @brief ´´½¨GIF¾«Áé /// @brief ´´½¨GIF¾«Áé
/// @param res GIFͼƬ×ÊÔ´ /// @param res GIFͼƬ×ÊÔ´
static GifSpritePtr Create(const Resource& res); GifSprite(const Resource& res);
/// \~chinese /// \~chinese
/// @brief ´´½¨GIF¾«Áé /// @brief ´´½¨GIF¾«Áé
/// @param gif GIFͼƬ /// @param gif GIFͼƬ
static GifSpritePtr Create(GifImagePtr gif); GifSprite(GifImagePtr gif);
GifSprite();
/// \~chinese /// \~chinese
/// @brief ¼ÓÔØGIFͼƬ /// @brief ¼ÓÔØGIFͼƬ

View File

@ -25,12 +25,6 @@
namespace kiwano namespace kiwano
{ {
LayerActorPtr LayerActor::Create()
{
LayerActorPtr ptr = new (autogc) LayerActor;
return ptr;
}
LayerActor::LayerActor() LayerActor::LayerActor()
: swallow_(false) : swallow_(false)
{ {

View File

@ -39,10 +39,6 @@ KGE_DECLARE_SMART_PTR(LayerActor);
class KGE_API LayerActor : public Actor class KGE_API LayerActor : public Actor
{ {
public: public:
/// \~chinese
/// @brief ´´˝¨Íź˛ă
static LayerActorPtr Create();
LayerActor(); LayerActor();
virtual ~LayerActor(); virtual ~LayerActor();

View File

@ -25,40 +25,25 @@
namespace kiwano namespace kiwano
{ {
ShapeActorPtr ShapeActor::Create(ShapePtr shape) ShapeActor::ShapeActor() {}
ShapeActor::ShapeActor(ShapePtr shape)
{ {
ShapeActorPtr ptr = new (autogc) ShapeActor; SetShape(shape);
if (ptr)
{
ptr->SetShape(shape);
}
return ptr;
} }
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); SetFillColor(fill_color);
if (ptr) SetStrokeColor(stroke_color);
{
ptr->SetFillColor(fill_color);
ptr->SetStrokeColor(stroke_color);
}
return ptr;
} }
ShapeActorPtr ShapeActor::Create(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush) ShapeActor::ShapeActor(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush)
{ : ShapeActor(shape)
ShapeActorPtr ptr = ShapeActor::Create(shape);
if (ptr)
{
ptr->SetFillBrush(fill_brush);
ptr->SetStrokeBrush(stroke_brush);
}
return ptr;
}
ShapeActor::ShapeActor()
{ {
SetFillBrush(fill_brush);
SetStrokeBrush(stroke_brush);
} }
ShapeActor::~ShapeActor() {} ShapeActor::~ShapeActor() {}
@ -127,18 +112,13 @@ bool ShapeActor::CheckVisibility(RenderContext& ctx) const
// LineActor // 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() {}
LineActor::LineActor(const Point& begin, const Point& end)
{
SetLine(begin, end);
}
LineActor::~LineActor() {} LineActor::~LineActor() {}
void LineActor::SetLine(const Point& begin, const Point& end) void LineActor::SetLine(const Point& begin, const Point& end)
@ -155,18 +135,13 @@ void LineActor::SetLine(const Point& begin, const Point& end)
// RectActor // RectActor
//------------------------------------------------------- //-------------------------------------------------------
RectActorPtr RectActor::Create(const Size& size)
{
RectActorPtr ptr = new (autogc) RectActor;
if (ptr)
{
ptr->SetRectSize(size);
}
return ptr;
}
RectActor::RectActor() {} RectActor::RectActor() {}
RectActor::RectActor(const Size& size)
{
SetRectSize(size);
}
RectActor::~RectActor() {} RectActor::~RectActor() {}
void RectActor::SetRectSize(const Size& size) void RectActor::SetRectSize(const Size& size)
@ -182,18 +157,13 @@ void RectActor::SetRectSize(const Size& size)
// RoundedRectActor // 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() {}
RoundedRectActor::RoundedRectActor(const Size& size, const Vec2& radius)
{
SetRoundedRect(size, radius);
}
RoundedRectActor::~RoundedRectActor() {} RoundedRectActor::~RoundedRectActor() {}
void RoundedRectActor::SetRadius(const Vec2& radius) void RoundedRectActor::SetRadius(const Vec2& radius)
@ -220,21 +190,17 @@ void RoundedRectActor::SetRoundedRect(const Size& size, const Vec2& radius)
// CircleActor // CircleActor
//------------------------------------------------------- //-------------------------------------------------------
CircleActorPtr CircleActor::Create(float radius)
{
CircleActorPtr ptr = new (autogc) CircleActor;
if (ptr)
{
ptr->SetRadius(radius);
}
return ptr;
}
CircleActor::CircleActor() CircleActor::CircleActor()
: radius_(0.f) : radius_(0.f)
{ {
} }
CircleActor::CircleActor(float radius)
: radius_(0.f)
{
SetRadius(radius);
}
CircleActor::~CircleActor() {} CircleActor::~CircleActor() {}
void CircleActor::SetRadius(float radius) void CircleActor::SetRadius(float radius)
@ -250,18 +216,13 @@ void CircleActor::SetRadius(float radius)
// EllipseActor // EllipseActor
//------------------------------------------------------- //-------------------------------------------------------
EllipseActorPtr EllipseActor::Create(const Vec2& radius)
{
EllipseActorPtr ptr = new (autogc) EllipseActor;
if (ptr)
{
ptr->SetRadius(radius);
}
return ptr;
}
EllipseActor::EllipseActor() {} EllipseActor::EllipseActor() {}
EllipseActor::EllipseActor(const Vec2& radius)
{
SetRadius(radius);
}
EllipseActor::~EllipseActor() {} EllipseActor::~EllipseActor() {}
void EllipseActor::SetRadius(const Vec2& radius) void EllipseActor::SetRadius(const Vec2& radius)
@ -277,30 +238,25 @@ void EllipseActor::SetRadius(const Vec2& radius)
// PolygonActor // PolygonActor
//------------------------------------------------------- //-------------------------------------------------------
PolygonActorPtr PolygonActor::Create(const Vector<Point>& points)
{
PolygonActorPtr ptr = new (autogc) PolygonActor;
if (ptr)
{
ptr->SetVertices(points);
}
return ptr;
}
PolygonActor::PolygonActor() {} PolygonActor::PolygonActor() {}
PolygonActor::PolygonActor(const Vector<Point>& points)
{
SetVertices(points);
}
PolygonActor::~PolygonActor() {} PolygonActor::~PolygonActor() {}
void PolygonActor::SetVertices(const Vector<Point>& points) void PolygonActor::SetVertices(const Vector<Point>& points)
{ {
if (points.size() > 1) if (points.size() > 1)
{ {
ShapeMakerPtr maker = ShapeMaker::Create(); ShapeMaker maker;
maker->BeginPath(points[0]); maker.BeginPath(points[0]);
maker->AddLines(&points[1], points.size() - 1); maker.AddLines(&points[1], points.size() - 1);
maker->EndPath(true); maker.EndPath(true);
SetShape(maker->GetShape()); SetShape(maker.GetShape());
} }
} }

View File

@ -48,28 +48,26 @@ KGE_DECLARE_SMART_PTR(PolygonActor);
class KGE_API ShapeActor : public Actor class KGE_API ShapeActor : public Actor
{ {
public: public:
ShapeActor();
/// \~chinese /// \~chinese
/// @brief 创建形状角色 /// @brief 创建形状角色
/// @param shape 形状 /// @param shape 形状
static ShapeActorPtr Create(ShapePtr shape); ShapeActor(ShapePtr shape);
/// \~chinese /// \~chinese
/// @brief 创建形状角色 /// @brief 创建形状角色
/// @param shape 形状 /// @param shape 形状
/// @param fill_color 填充颜色 /// @param fill_color 填充颜色
/// @param stroke_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 /// \~chinese
/// @brief 创建形状角色 /// @brief 创建形状角色
/// @param shape 形状 /// @param shape 形状
/// @param fill_brush 填充画刷 /// @param fill_brush 填充画刷
/// @param stroke_brush 轮廓画刷 /// @param stroke_brush 轮廓画刷
static ShapeActorPtr Create(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush); ShapeActor(ShapePtr shape, BrushPtr fill_brush, BrushPtr stroke_brush);
/// \~chinese
/// @brief ¹¹ÔìÐÎ×´½ÇÉ«
ShapeActor();
virtual ~ShapeActor(); virtual ~ShapeActor();
@ -147,13 +145,13 @@ private:
class KGE_API LineActor : public ShapeActor class KGE_API LineActor : public ShapeActor
{ {
public: public:
LineActor();
/// \~chinese /// \~chinese
/// @brief 创建线段角色 /// @brief 创建线段角色
/// @param begin 线段起点 /// @param begin 线段起点
/// @param end 线段终点 /// @param end 线段终点
static LineActorPtr Create(const Point& begin, const Point& end); LineActor(const Point& begin, const Point& end);
LineActor();
virtual ~LineActor(); virtual ~LineActor();
@ -191,12 +189,12 @@ private:
class KGE_API RectActor : public ShapeActor class KGE_API RectActor : public ShapeActor
{ {
public: public:
RectActor();
/// \~chinese /// \~chinese
/// @brief 创建矩形角色 /// @brief 创建矩形角色
/// @param size 矩形大小 /// @param size 矩形大小
static RectActorPtr Create(const Size& size); RectActor(const Size& size);
RectActor();
virtual ~RectActor(); virtual ~RectActor();
@ -218,13 +216,13 @@ private:
class KGE_API RoundedRectActor : public ShapeActor class KGE_API RoundedRectActor : public ShapeActor
{ {
public: public:
RoundedRectActor();
/// \~chinese /// \~chinese
/// @brief 创建圆角矩形角色 /// @brief 创建圆角矩形角色
/// @param size 圆角矩形大小 /// @param size 圆角矩形大小
/// @param radius 圆角半径 /// @param radius 圆角半径
static RoundedRectActorPtr Create(const Size& size, const Vec2& radius); RoundedRectActor(const Size& size, const Vec2& radius);
RoundedRectActor();
virtual ~RoundedRectActor(); virtual ~RoundedRectActor();
@ -262,12 +260,12 @@ private:
class KGE_API CircleActor : public ShapeActor class KGE_API CircleActor : public ShapeActor
{ {
public: public:
CircleActor();
/// \~chinese /// \~chinese
/// @brief 创建圆形角色 /// @brief 创建圆形角色
/// @param radius 圆形半径 /// @param radius 圆形半径
static CircleActorPtr Create(float radius); CircleActor(float radius);
CircleActor();
virtual ~CircleActor(); virtual ~CircleActor();
@ -289,12 +287,12 @@ private:
class KGE_API EllipseActor : public ShapeActor class KGE_API EllipseActor : public ShapeActor
{ {
public: public:
EllipseActor();
/// \~chinese /// \~chinese
/// @brief 创建椭圆角色 /// @brief 创建椭圆角色
/// @param radius 椭圆半径 /// @param radius 椭圆半径
static EllipseActorPtr Create(const Vec2& radius); EllipseActor(const Vec2& radius);
EllipseActor();
virtual ~EllipseActor(); virtual ~EllipseActor();
@ -316,12 +314,12 @@ private:
class KGE_API PolygonActor : public ShapeActor class KGE_API PolygonActor : public ShapeActor
{ {
public: public:
PolygonActor();
/// \~chinese /// \~chinese
/// @brief 创建多边形角色 /// @brief 创建多边形角色
/// @param points 多边形端点集合 /// @param points 多边形端点集合
static PolygonActorPtr Create(const Vector<Point>& points); PolygonActor(const Vector<Point>& points);
PolygonActor();
virtual ~PolygonActor(); virtual ~PolygonActor();
@ -338,7 +336,7 @@ inline void ShapeActor::SetStrokeColor(const Color& color)
{ {
if (!stroke_brush_) if (!stroke_brush_)
{ {
stroke_brush_ = new (autogc) Brush; stroke_brush_ = MakePtr<Brush>();
} }
stroke_brush_->SetColor(color); stroke_brush_->SetColor(color);
} }
@ -347,7 +345,7 @@ inline void ShapeActor::SetFillColor(const Color& color)
{ {
if (!fill_brush_) if (!fill_brush_)
{ {
fill_brush_ = new (autogc) Brush; fill_brush_ = MakePtr<Brush>();
} }
fill_brush_->SetColor(color); fill_brush_->SetColor(color);
} }

View File

@ -24,65 +24,40 @@
namespace kiwano 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() {}
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() {} Sprite::~Sprite() {}
bool Sprite::Load(const String& file_path, bool autoresize) bool Sprite::Load(const String& file_path, bool autoresize)
{ {
FramePtr frame = Frame::Create(file_path); FramePtr frame = MakePtr<Frame>(file_path);
if (frame) if (frame)
{ {
SetFrame(frame, autoresize); SetFrame(frame, autoresize);
@ -93,7 +68,7 @@ bool Sprite::Load(const String& file_path, bool autoresize)
bool Sprite::Load(const Resource& res, bool autoresize) bool Sprite::Load(const Resource& res, bool autoresize)
{ {
FramePtr frame = Frame::Create(res); FramePtr frame = MakePtr<Frame>(res);
if (frame) if (frame)
{ {
SetFrame(frame, autoresize); SetFrame(frame, autoresize);

View File

@ -38,34 +38,34 @@ KGE_DECLARE_SMART_PTR(Sprite);
class KGE_API Sprite : public Actor class KGE_API Sprite : public Actor
{ {
public: public:
Sprite();
/// \~chinese /// \~chinese
/// @brief 创建精灵 /// @brief 创建精灵
/// @param file_path 本地图片路径 /// @param file_path 本地图片路径
static SpritePtr Create(const String& file_path); Sprite(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 创建精灵 /// @brief 创建精灵
/// @param res 图片资源 /// @param res 图片资源
static SpritePtr Create(const Resource& res); Sprite(const Resource& res);
/// \~chinese /// \~chinese
/// @brief 创建精灵 /// @brief 创建精灵
/// @param frame 图像帧 /// @param frame 图像帧
static SpritePtr Create(FramePtr frame); Sprite(FramePtr frame);
/// \~chinese /// \~chinese
/// @brief 创建精灵 /// @brief 创建精灵
/// @param file_path 本地图片路径 /// @param file_path 本地图片路径
/// @param crop_rect 裁剪矩形 /// @param crop_rect 裁剪矩形
static SpritePtr Create(const String& file_path, const Rect& crop_rect); Sprite(const String& file_path, const Rect& crop_rect);
/// \~chinese /// \~chinese
/// @brief 创建精灵 /// @brief 创建精灵
/// @param res 图片资源 /// @param res 图片资源
/// @param crop_rect 裁剪矩形 /// @param crop_rect 裁剪矩形
static SpritePtr Create(const Resource& res, const Rect& crop_rect); Sprite(const Resource& res, const Rect& crop_rect);
Sprite();
virtual ~Sprite(); virtual ~Sprite();

View File

@ -25,12 +25,6 @@
namespace kiwano namespace kiwano
{ {
StagePtr Stage::Create()
{
StagePtr ptr = new (autogc) Stage;
return ptr;
}
Stage::Stage() Stage::Stage()
{ {
SetStage(this); SetStage(this);
@ -57,13 +51,13 @@ void Stage::RenderBorder(RenderContext& ctx)
if (!border_fill_brush_) if (!border_fill_brush_)
{ {
border_fill_brush_ = new (autogc) Brush; border_fill_brush_ = MakePtr<Brush>();
border_fill_brush_->SetColor(Color(Color::Red, .4f)); border_fill_brush_->SetColor(Color(Color::Red, .4f));
} }
if (!border_stroke_brush_) if (!border_stroke_brush_)
{ {
border_stroke_brush_ = new (autogc) Brush; border_stroke_brush_ = MakePtr<Brush>();
border_stroke_brush_->SetColor(Color(Color::Red, .8f)); border_stroke_brush_->SetColor(Color(Color::Red, .8f));
} }

View File

@ -43,10 +43,6 @@ class KGE_API Stage : public Actor
friend class Director; friend class Director;
public: public:
/// \~chinese
/// @brief 进入舞台时
static StagePtr Create();
Stage(); Stage();
virtual ~Stage(); virtual ~Stage();

View File

@ -25,24 +25,17 @@
namespace kiwano 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) TextActor::TextActor(const String& text, const TextStyle& style)
{
TextActorPtr ptr = new (autogc) TextActor;
if (ptr)
{
ptr->SetStyle(style);
ptr->SetText(text);
}
return ptr;
}
TextActor::TextActor()
{ {
SetStyle(style);
SetText(text);
} }
TextActor::~TextActor() {} TextActor::~TextActor() {}
@ -65,7 +58,7 @@ void TextActor::SetText(const String& text)
{ {
if (!layout_) if (!layout_)
{ {
layout_ = TextLayout::Create(); layout_ = MakePtr<TextLayout>();
} }
layout_->Reset(text, style_); layout_->Reset(text, style_);
} }
@ -215,7 +208,7 @@ void TextActor::SetFillColor(const Color& color)
} }
else else
{ {
SetFillBrush(Brush::Create(color)); SetFillBrush(MakePtr<Brush>(color));
} }
} }
@ -227,7 +220,7 @@ void TextActor::SetOutlineColor(const Color& outline_color)
} }
else else
{ {
SetFillBrush(Brush::Create(outline_color)); SetFillBrush(MakePtr<Brush>(outline_color));
} }
} }

View File

@ -39,18 +39,18 @@ KGE_DECLARE_SMART_PTR(TextActor);
class KGE_API TextActor : public Actor class KGE_API TextActor : public Actor
{ {
public: public:
TextActor();
/// \~chinese /// \~chinese
/// @brief 创建文本角色 /// @brief 创建文本角色
/// @param text 文字内容 /// @param text 文字内容
static TextActorPtr Create(const String& text); TextActor(const String& text);
/// \~chinese /// \~chinese
/// @brief 创建文本角色 /// @brief 创建文本角色
/// @param text 文字内容 /// @param text 文字内容
/// @param style 文本样式 /// @param style 文本样式
static TextActorPtr Create(const String& text, const TextStyle& style); TextActor(const String& text, const TextStyle& style);
TextActor();
virtual ~TextActor(); virtual ~TextActor();

View File

@ -51,7 +51,7 @@ bool Transition::IsDone()
return done_; return done_;
} }
void Transition::Init(StagePtr prev, StagePtr next) void Transition::Init(Stage* prev, Stage* next)
{ {
process_ = 0; process_ = 0;
delta_ = Duration{}; delta_ = Duration{};
@ -126,19 +126,14 @@ void Transition::Stop()
// BoxTransition // BoxTransition
//------------------------------------------------------- //-------------------------------------------------------
BoxTransitionPtr BoxTransition::Create(Duration duration) BoxTransition::BoxTransition(Duration duration)
{ {
BoxTransitionPtr ptr = new (autogc) BoxTransition; SetDuration(duration);
if (ptr)
{
ptr->SetDuration(duration);
}
return ptr;
} }
BoxTransition::BoxTransition() {} BoxTransition::BoxTransition() {}
void BoxTransition::Init(StagePtr prev, StagePtr next) void BoxTransition::Init(Stage* prev, Stage* next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -167,19 +162,14 @@ void BoxTransition::Update(Duration dt)
// EmergeTransition // EmergeTransition
//------------------------------------------------------- //-------------------------------------------------------
EmergeTransitionPtr EmergeTransition::Create(Duration duration) EmergeTransition::EmergeTransition(Duration duration)
{ {
EmergeTransitionPtr ptr = new (autogc) EmergeTransition; SetDuration(duration);
if (ptr)
{
ptr->SetDuration(duration);
}
return ptr;
} }
EmergeTransition::EmergeTransition() {} EmergeTransition::EmergeTransition() {}
void EmergeTransition::Init(StagePtr prev, StagePtr next) void EmergeTransition::Init(Stage* prev, Stage* next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -199,19 +189,14 @@ void EmergeTransition::Update(Duration dt)
// FadeTransition // FadeTransition
//------------------------------------------------------- //-------------------------------------------------------
FadeTransitionPtr FadeTransition::Create(Duration duration) FadeTransition::FadeTransition(Duration duration)
{ {
FadeTransitionPtr ptr = new (autogc) FadeTransition; SetDuration(duration);
if (ptr)
{
ptr->SetDuration(duration);
}
return ptr;
} }
FadeTransition::FadeTransition() {} FadeTransition::FadeTransition() {}
void FadeTransition::Init(StagePtr prev, StagePtr next) void FadeTransition::Init(Stage* prev, Stage* next)
{ {
Transition::Init(prev, next); Transition::Init(prev, next);
@ -239,15 +224,10 @@ void FadeTransition::Update(Duration dt)
// MoveTransition // MoveTransition
//------------------------------------------------------- //-------------------------------------------------------
MoveTransitionPtr MoveTransition::Create(Duration duration, Type type) MoveTransition::MoveTransition(Duration duration, Type type)
: type_(type)
{ {
MoveTransitionPtr ptr = new (autogc) MoveTransition; SetDuration(duration);
if (ptr)
{
ptr->type_ = type;
ptr->SetDuration(duration);
}
return ptr;
} }
MoveTransition::MoveTransition() 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); Transition::Init(prev, next);
@ -328,15 +308,10 @@ void MoveTransition::Reset()
// RotationTransition // RotationTransition
//------------------------------------------------------- //-------------------------------------------------------
RotationTransitionPtr RotationTransition::Create(Duration duration, float rotation) RotationTransition::RotationTransition(Duration duration, float rotation)
: rotation_(rotation)
{ {
RotationTransitionPtr ptr = new (autogc) RotationTransition; SetDuration(duration);
if (ptr)
{
ptr->rotation_ = rotation;
ptr->SetDuration(duration);
}
return ptr;
} }
RotationTransition::RotationTransition() 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); Transition::Init(prev, next);

View File

@ -66,7 +66,7 @@ protected:
* @param[in] prev * @param[in] prev
* @param[in] next * @param[in] next
*/ */
virtual void Init(StagePtr prev, StagePtr next); virtual void Init(Stage* prev, Stage* next);
/** /**
* \~chinese * \~chinese
@ -95,15 +95,15 @@ protected:
virtual void Reset() {} virtual void Reset() {}
protected: protected:
bool done_; bool done_;
float process_; float process_;
Duration duration_; Duration duration_;
Duration delta_; Duration delta_;
Size window_size_; Size window_size_;
StagePtr out_stage_; StagePtr out_stage_;
StagePtr in_stage_; StagePtr in_stage_;
Layer out_layer_; Layer out_layer_;
Layer in_layer_; Layer in_layer_;
}; };
/** /**
@ -119,14 +119,14 @@ public:
* @brief * @brief
* @param duration * @param duration
*/ */
static FadeTransitionPtr Create(Duration duration); FadeTransition(Duration duration);
FadeTransition(); FadeTransition();
protected: protected:
void Update(Duration dt) override; 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 * @brief
* @param duration * @param duration
*/ */
static EmergeTransitionPtr Create(Duration duration); EmergeTransition(Duration duration);
EmergeTransition(); EmergeTransition();
protected: protected:
void Update(Duration dt) override; 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 * @brief
* @param duration * @param duration
*/ */
static BoxTransitionPtr Create(Duration duration); BoxTransition(Duration duration);
BoxTransition(); BoxTransition();
protected: protected:
void Update(Duration dt) override; 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 duration
* @param type * @param type
*/ */
static MoveTransitionPtr Create(Duration duration, Type type); MoveTransition(Duration duration, Type type);
MoveTransition(); MoveTransition();
protected: protected:
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override; virtual void Init(Stage* prev, Stage* next) override;
void Reset() override; void Reset() override;
@ -232,14 +232,14 @@ public:
* @param duration * @param duration
* @param rotation * @param rotation
*/ */
static RotationTransitionPtr Create(Duration duration, float rotation = 360.0f); RotationTransition(Duration duration, float rotation = 360.0f);
RotationTransition(); RotationTransition();
protected: protected:
void Update(Duration dt) override; void Update(Duration dt) override;
virtual void Init(StagePtr prev, StagePtr next) override; virtual void Init(Stage* prev, Stage* next) override;
void Reset() override; void Reset() override;

View File

@ -106,7 +106,7 @@ void ActionEntity::Reset()
loops_done_ = 0; loops_done_ = 0;
} }
ActionEntityPtr ActionEntity::DoClone(ActionEntityPtr to) const void ActionEntity::DoClone(ActionEntity* to) const
{ {
if (to) if (to)
{ {
@ -116,7 +116,6 @@ ActionEntityPtr ActionEntity::DoClone(ActionEntityPtr to) const
to->SetLoops(this->GetLoops()); to->SetLoops(this->GetLoops());
to->SetName(this->GetName()); to->SetName(this->GetName());
} }
return to;
} }
} // namespace kiwano } // namespace kiwano

View File

@ -22,7 +22,6 @@
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/core/Cloneable.h> #include <kiwano/core/Cloneable.h>
#include <kiwano/base/ObjectBase.h> #include <kiwano/base/ObjectBase.h>
#include <kiwano/core/RefPtr.hpp>
#include <kiwano/core/Time.h> #include <kiwano/core/Time.h>
#include <kiwano/core/IntrusiveList.h> #include <kiwano/core/IntrusiveList.h>
#include <kiwano/math/Math.h> #include <kiwano/math/Math.h>
@ -103,7 +102,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取动画的倒转 /// @brief 获取动画的倒转
virtual ActionEntityPtr Reverse() const = 0; virtual ActionEntity* Reverse() const = 0;
/// \~chinese /// \~chinese
/// @brief 获取动画的运行状态 /// @brief 获取动画的运行状态
@ -183,7 +182,7 @@ protected:
/// \~chinese /// \~chinese
/// @brief 执行克隆 /// @brief 执行克隆
ActionEntityPtr DoClone(ActionEntityPtr to) const; void DoClone(ActionEntity* to) const;
private: private:
Status status_; Status status_;
@ -300,6 +299,11 @@ public:
return Get(); return Get();
} }
inline operator ActionEntity*() const
{
return Get();
}
inline operator ActionEntityPtr() const inline operator ActionEntityPtr() const
{ {
return ptr; return ptr;

View File

@ -25,27 +25,24 @@ namespace kiwano
ActionDelay::ActionDelay(Duration delay) 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; this->SetDelay(delay);
if (ptr) }
{
ptr->SetDelay(delay); ActionDelayEntity* ActionDelayEntity::Clone() const
} {
auto ptr = new (autogc) ActionDelayEntity(GetDelay());
DoClone(ptr);
return ptr; return ptr;
} }
ActionEntityPtr ActionDelayEntity::Clone() const ActionDelayEntity* ActionDelayEntity::Reverse() const
{ {
return DoClone(ActionDelayEntity::Create(GetDelay())); return Clone();
}
ActionEntityPtr ActionDelayEntity::Reverse() const
{
return DoClone(ActionDelayEntity::Create(GetDelay()));
} }
} // namespace kiwano } // namespace kiwano

View File

@ -50,15 +50,15 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建延时动画 /// @brief 创建延时动画
/// @param delay 延时时长 /// @param delay 延时时长
static ActionDelayEntityPtr Create(Duration delay); ActionDelayEntity(Duration delay);
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionDelayEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionDelayEntity* Reverse() const override;
}; };
/** @} */ /** @} */

View File

@ -27,18 +27,7 @@ namespace kiwano
ActionGroup::ActionGroup(const Vector<ActionEntityPtr>& actions, bool parallel) ActionGroup::ActionGroup(const Vector<ActionEntityPtr>& actions, bool parallel)
{ {
SetEntity(ActionGroupEntity::Create(actions, parallel)); SetEntity(MakePtr<ActionGroupEntity>(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;
} }
ActionGroupEntity::ActionGroupEntity() ActionGroupEntity::ActionGroupEntity()
@ -46,9 +35,10 @@ ActionGroupEntity::ActionGroupEntity()
{ {
} }
ActionGroupEntity::ActionGroupEntity(bool parallel) ActionGroupEntity::ActionGroupEntity(const Vector<ActionEntityPtr>& actions, bool parallel)
: parallel_(parallel) : parallel_(parallel)
{ {
AddActions(actions);
} }
ActionGroupEntity::~ActionGroupEntity() {} ActionGroupEntity::~ActionGroupEntity() {}
@ -123,7 +113,7 @@ void ActionGroupEntity::AddActions(const Vector<ActionEntityPtr>& actions)
AddAction(action); AddAction(action);
} }
ActionEntityPtr ActionGroupEntity::Clone() const ActionGroupEntity* ActionGroupEntity::Clone() const
{ {
Vector<ActionEntityPtr> actions; Vector<ActionEntityPtr> actions;
if (!actions_.IsEmpty()) if (!actions_.IsEmpty())
@ -133,10 +123,12 @@ ActionEntityPtr ActionGroupEntity::Clone() const
actions.push_back(action->Clone()); 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; Vector<ActionEntityPtr> actions;
if (!actions_.IsEmpty()) if (!actions_.IsEmpty())
@ -146,7 +138,9 @@ ActionEntityPtr ActionGroupEntity::Reverse() const
actions.push_back(action->Reverse()); actions.push_back(action->Reverse());
} }
} }
return DoClone(ActionGroupEntity::Create(actions, parallel_)); auto ptr = new (autogc) ActionGroupEntity(actions, parallel_);
DoClone(ptr);
return ptr;
} }
} // namespace kiwano } // namespace kiwano

View File

@ -47,15 +47,13 @@ public:
class KGE_API ActionGroupEntity : public ActionEntity class KGE_API ActionGroupEntity : public ActionEntity
{ {
public: public:
ActionGroupEntity();
/// \~chinese /// \~chinese
/// @brief 创建动画组合 /// @brief 创建动画组合
/// @param actions 动画集合 /// @param actions 动画集合
/// @param parallel 同步执行 /// @param parallel 同步执行
static ActionGroupEntityPtr Create(const Vector<ActionEntityPtr>& actions, bool parallel = false); ActionGroupEntity(const Vector<ActionEntityPtr>& actions, bool parallel = false);
ActionGroupEntity();
ActionGroupEntity(bool parallel);
virtual ~ActionGroupEntity(); virtual ~ActionGroupEntity();
@ -75,11 +73,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionGroupEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionGroupEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;

View File

@ -87,14 +87,14 @@ void ActionScheduler::StopAllActions()
} }
} }
ActionEntityPtr ActionScheduler::GetAction(const String& name) ActionEntity* ActionScheduler::GetAction(const String& name)
{ {
if (actions_.IsEmpty()) if (actions_.IsEmpty())
return nullptr; return nullptr;
for (auto& action : actions_) for (auto& action : actions_)
if (action->IsName(name)) if (action->IsName(name))
return action; return action.Get();
return nullptr; return nullptr;
} }

View File

@ -55,7 +55,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取指定名称的动画 /// @brief 获取指定名称的动画
/// @param name 动画名称 /// @param name 动画名称
ActionEntityPtr GetAction(const String& name); ActionEntity* GetAction(const String& name);
/// \~chinese /// \~chinese
/// @brief 获取所有动画 /// @brief 获取所有动画

View File

@ -95,9 +95,9 @@ ActionTweenEntity::ActionTweenEntity()
{ {
} }
ActionTweenEntity::ActionTweenEntity(Duration duration, EaseFunc func) ActionTweenEntity::ActionTweenEntity(Duration duration)
: dur_(duration) : dur_(duration)
, ease_func_(func) , ease_func_(nullptr)
{ {
} }
@ -129,33 +129,26 @@ void ActionTweenEntity::Update(Actor* target, Duration dt)
UpdateTween(target, percent); UpdateTween(target, percent);
} }
ActionEntityPtr ActionTweenEntity::DoClone(ActionTweenEntityPtr to) const void ActionTweenEntity::DoClone(ActionTweenEntity* to) const
{ {
if (to) if (to)
{ {
ActionEntity::DoClone(to);
to->SetDuration(this->GetDuration()); to->SetDuration(this->GetDuration());
to->SetEaseFunc(this->GetEaseFunc()); to->SetEaseFunc(this->GetEaseFunc());
} }
return ActionEntity::DoClone(to);
} }
//------------------------------------------------------- //-------------------------------------------------------
// Move Action // 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) void ActionMoveByEntity::Init(Actor* target)
{ {
if (target) if (target)
@ -175,32 +168,31 @@ void ActionMoveByEntity::UpdateTween(Actor* target, float percent)
prev_pos_ = new_pos; prev_pos_ = new_pos;
} }
ActionEntityPtr ActionMoveByEntity::Clone() const ActionMoveByEntity* ActionMoveByEntity::Clone() const
{ {
return DoClone(ActionMoveByEntity::Create(GetDuration(), displacement_)); auto ptr = new (autogc) ActionMoveByEntity(GetDuration(), displacement_);
} DoClone(ptr);
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);
}
return ptr; return ptr;
} }
ActionMoveToEntity::ActionMoveToEntity() {} ActionMoveByEntity* ActionMoveByEntity::Reverse() const
ActionEntityPtr ActionMoveToEntity::Clone() 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) void ActionMoveToEntity::Init(Actor* target)
@ -213,33 +205,26 @@ void ActionMoveToEntity::Init(Actor* target)
// Jump Action // 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)
{ ActionJumpByEntity* ActionJumpByEntity::Clone() const
ptr->SetDuration(duration); {
ptr->SetJumpHeight(height); auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), displacement_, height_, jump_count_);
ptr->SetJumpCount(count); DoClone(ptr);
ptr->SetDisplacement(displacement);
}
return ptr; return ptr;
} }
ActionJumpByEntity::ActionJumpByEntity() ActionJumpByEntity* ActionJumpByEntity::Reverse() const
: height_(0.0f)
, jump_count_(0)
{ {
} auto ptr = new (autogc) ActionJumpByEntity(GetDuration(), -displacement_, height_, jump_count_);
DoClone(ptr);
ActionEntityPtr ActionJumpByEntity::Clone() const return ptr;
{
return DoClone(ActionJumpByEntity::Create(GetDuration(), displacement_, height_, jump_count_));
}
ActionEntityPtr ActionJumpByEntity::Reverse() const
{
return DoClone(ActionJumpByEntity::Create(GetDuration(), -displacement_, height_, jump_count_));
} }
void ActionJumpByEntity::Init(Actor* target) void ActionJumpByEntity::Init(Actor* target)
@ -266,24 +251,17 @@ void ActionJumpByEntity::UpdateTween(Actor* target, float percent)
prev_pos_ = new_pos; 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() {} ActionJumpToEntity* ActionJumpToEntity::Clone() const
ActionEntityPtr 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) void ActionJumpToEntity::Init(Actor* target)
@ -296,21 +274,10 @@ void ActionJumpToEntity::Init(Actor* target)
// Scale Action // Scale Action
//------------------------------------------------------- //-------------------------------------------------------
ActionScaleByEntityPtr ActionScaleByEntity::Create(Duration duration, float scale_x, float scale_y) ActionScaleByEntity::ActionScaleByEntity(Duration duration, float scale_x, float scale_y)
{ : ActionTweenEntity(duration)
ActionScaleByEntityPtr ptr = new (autogc) ActionScaleByEntity; , delta_x_(scale_x)
if (ptr) , delta_y_(scale_y)
{
ptr->SetDuration(duration);
ptr->SetScaleX(scale_x);
ptr->SetScaleY(scale_y);
}
return ptr;
}
ActionScaleByEntity::ActionScaleByEntity()
: delta_x_(0.0f)
, delta_y_(0.0f)
, start_scale_x_(0.f) , start_scale_x_(0.f)
, start_scale_y_(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 }); 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_)); auto ptr = new (autogc) ActionScaleByEntity(GetDuration(), delta_x_, delta_y_);
} DoClone(ptr);
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);
}
return ptr; return ptr;
} }
ActionScaleToEntity::ActionScaleToEntity() ActionScaleByEntity* ActionScaleByEntity::Reverse() const
: end_scale_x_(0.0f) {
, end_scale_y_(0.0f) 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) void ActionScaleToEntity::Init(Actor* target)
@ -374,21 +336,11 @@ void ActionScaleToEntity::Init(Actor* target)
// Opacity Action // Opacity Action
//------------------------------------------------------- //-------------------------------------------------------
ActionFadeToEntityPtr ActionFadeToEntity::Create(Duration duration, float opacity) ActionFadeToEntity::ActionFadeToEntity(Duration duration, float opacity)
{ : ActionTweenEntity(duration)
ActionFadeToEntityPtr ptr = new (autogc) ActionFadeToEntity; , delta_val_(0.0f)
if (ptr)
{
ptr->SetDuration(duration);
ptr->SetTargetOpacity(opacity);
}
return ptr;
}
ActionFadeToEntity::ActionFadeToEntity()
: delta_val_(0.0f)
, start_val_(0.f) , 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); 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 // Rotate Action
//------------------------------------------------------- //-------------------------------------------------------
ActionRotateByEntityPtr ActionRotateByEntity::Create(Duration duration, float rotation) ActionRotateByEntity::ActionRotateByEntity(Duration duration, float rotation)
{ : ActionTweenEntity(duration)
ActionRotateByEntityPtr ptr = new (autogc) ActionRotateByEntity; , delta_val_(rotation)
if (ptr) , start_val_(0.0f)
{
ptr->SetDuration(duration);
ptr->SetRotation(rotation);
}
return ptr;
}
ActionRotateByEntity::ActionRotateByEntity()
: start_val_(0.0f)
, delta_val_(0.0f)
{ {
} }
@ -449,35 +393,31 @@ void ActionRotateByEntity::UpdateTween(Actor* target, float percent)
target->SetRotation(rotation); target->SetRotation(rotation);
} }
ActionEntityPtr ActionRotateByEntity::Clone() const ActionRotateByEntity* ActionRotateByEntity::Clone() const
{ {
return DoClone(ActionRotateByEntity::Create(GetDuration(), delta_val_)); auto ptr = new (autogc) ActionRotateByEntity(GetDuration(), delta_val_);
} DoClone(ptr);
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);
}
return ptr; return ptr;
} }
ActionRotateToEntity::ActionRotateToEntity() ActionRotateByEntity* ActionRotateByEntity::Reverse() const
: end_val_(0.0f) {
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) void ActionRotateToEntity::Init(Actor* target)
@ -490,22 +430,17 @@ void ActionRotateToEntity::Init(Actor* target)
// ActionCustomEntity // 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() {} ActionCustomEntity* ActionCustomEntity::Clone() const
ActionEntityPtr 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) void ActionCustomEntity::Init(Actor* target)
@ -522,72 +457,72 @@ void ActionCustomEntity::UpdateTween(Actor* target, float percent)
ActionMoveBy::ActionMoveBy(Duration duration, const Vec2& displacement) ActionMoveBy::ActionMoveBy(Duration duration, const Vec2& displacement)
{ {
SetEntity(ActionMoveByEntity::Create(duration, displacement)); SetEntity(MakePtr<ActionMoveByEntity>(duration, displacement));
} }
ActionMoveTo::ActionMoveTo(Duration duration, const Point& distination) 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) 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) 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) 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) 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) 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) 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) ActionFadeTo::ActionFadeTo(Duration duration, float opacity)
{ {
SetEntity(ActionFadeToEntity::Create(duration, opacity)); SetEntity(MakePtr<ActionFadeToEntity>(duration, opacity));
} }
ActionFadeIn::ActionFadeIn(Duration duration) ActionFadeIn::ActionFadeIn(Duration duration)
{ {
SetEntity(ActionFadeToEntity::Create(duration, 1.0f)); SetEntity(MakePtr<ActionFadeToEntity>(duration, 1.0f));
} }
ActionFadeOut::ActionFadeOut(Duration duration) ActionFadeOut::ActionFadeOut(Duration duration)
{ {
SetEntity(ActionFadeToEntity::Create(duration, 0.0f)); SetEntity(MakePtr<ActionFadeToEntity>(duration, 0.0f));
} }
ActionRotateBy::ActionRotateBy(Duration duration, float rotation) ActionRotateBy::ActionRotateBy(Duration duration, float rotation)
{ {
SetEntity(ActionRotateByEntity::Create(duration, rotation)); SetEntity(MakePtr<ActionRotateByEntity>(duration, rotation));
} }
ActionRotateTo::ActionRotateTo(Duration duration, float rotation) ActionRotateTo::ActionRotateTo(Duration duration, float rotation)
{ {
SetEntity(ActionRotateToEntity::Create(duration, rotation)); SetEntity(MakePtr<ActionRotateToEntity>(duration, rotation));
} }
ActionCustom::ActionCustom(Duration duration, TweenFunc tween_func) ActionCustom::ActionCustom(Duration duration, TweenFunc tween_func)
{ {
SetEntity(ActionCustomEntity::Create(duration, tween_func)); SetEntity(MakePtr<ActionCustomEntity>(duration, tween_func));
} }
} // namespace kiwano } // namespace kiwano

View File

@ -88,14 +88,6 @@ KGE_DECLARE_SMART_PTR(ActionCustomEntity);
class KGE_API ActionTweenEntity : public ActionEntity class KGE_API ActionTweenEntity : public ActionEntity
{ {
public: public:
ActionTweenEntity();
/// \~chinese
/// @brief 补间动画
/// @param duration 动画时长
/// @param func 动画速度缓动函数
ActionTweenEntity(Duration duration, EaseFunc ease);
/// \~chinese /// \~chinese
/// @brief 获取动画时长 /// @brief 获取动画时长
Duration GetDuration() const; Duration GetDuration() const;
@ -113,11 +105,19 @@ public:
void SetEaseFunc(const EaseFunc& func); void SetEaseFunc(const EaseFunc& func);
protected: protected:
ActionTweenEntity();
/// \~chinese
/// @brief 补间动画
/// @param duration 动画时长
/// @param func 动画速度缓动函数
ActionTweenEntity(Duration duration);
void Update(Actor* target, Duration dt) override; void Update(Actor* target, Duration dt) override;
virtual void UpdateTween(Actor* target, float percent) = 0; virtual void UpdateTween(Actor* target, float percent) = 0;
ActionEntityPtr DoClone(ActionTweenEntityPtr to) const; void DoClone(ActionTweenEntity* to) const;
private: private:
Duration dur_; Duration dur_;
@ -132,8 +132,8 @@ public:
ActionTween() = default; ActionTween() = default;
inline ActionTween(ActionTweenEntityPtr ptr) inline ActionTween(ActionTweenEntityPtr ptr)
: Action(ptr.Get())
{ {
SetEntity(ptr);
} }
/// \~chinese /// \~chinese
@ -150,14 +150,14 @@ public:
/// @brief 获取指针 /// @brief 获取指针
inline ActionTweenEntity* Get() const inline ActionTweenEntity* Get() const
{ {
return const_cast<ActionTweenEntity*>(static_cast<const ActionTweenEntity*>(ptr.Get())); return static_cast<ActionTweenEntity*>(Action::Get());
} }
/// \~chinese /// \~chinese
/// @brief 设置动画实体 /// @brief 设置动画实体
inline void SetEntity(ActionTweenEntityPtr tween_ptr) inline void SetEntity(ActionTweenEntityPtr tween_ptr)
{ {
this->ptr = static_cast<ActionEntity*>(tween_ptr.Get()); Action::SetEntity(tween_ptr.Get());
} }
inline ActionTweenEntity* operator->() const inline ActionTweenEntity* operator->() const
@ -187,9 +187,7 @@ public:
/// @brief 创建相对位移动画 /// @brief 创建相对位移动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param displacement 位移向量 /// @param displacement 位移向量
static ActionMoveByEntityPtr Create(Duration duration, const Vec2& displacement); ActionMoveByEntity(Duration duration, const Vec2& displacement);
ActionMoveByEntity();
/// \~chinese /// \~chinese
/// @brief 获取位移向量 /// @brief 获取位移向量
@ -201,11 +199,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionMoveByEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionMoveByEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -239,9 +237,7 @@ public:
/// @brief 创建位移动画 /// @brief 创建位移动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param distination 目的坐标 /// @param distination 目的坐标
static ActionMoveToEntityPtr Create(Duration duration, const Point& distination); ActionMoveToEntity(Duration duration, const Point& distination);
ActionMoveToEntity();
/// \~chinese /// \~chinese
/// @brief 获取目的坐标 /// @brief 获取目的坐标
@ -253,11 +249,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionMoveToEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
virtual ActionEntityPtr Reverse() const override ActionMoveToEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionMoveToEntity"); KGE_ERRORF("Reverse() not supported in ActionMoveToEntity");
return nullptr; return nullptr;
@ -295,9 +291,7 @@ public:
/// @param displacement 跳跃位移向量 /// @param displacement 跳跃位移向量
/// @param height 跳跃高度 /// @param height 跳跃高度
/// @param count 跳跃次数 /// @param count 跳跃次数
static ActionJumpByEntityPtr Create(Duration duration, const Vec2& displacement, float height, int count = 1); ActionJumpByEntity(Duration duration, const Vec2& displacement, float height, int count = 1);
ActionJumpByEntity();
/// \~chinese /// \~chinese
/// @brief 获取跳跃位移 /// @brief 获取跳跃位移
@ -325,11 +319,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionJumpByEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionJumpByEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -369,9 +363,7 @@ public:
/// @param distination 目的坐标 /// @param distination 目的坐标
/// @param height 跳跃高度 /// @param height 跳跃高度
/// @param count 跳跃次数 /// @param count 跳跃次数
static ActionJumpToEntityPtr Create(Duration duration, const Point& distination, float height, int count = 1); ActionJumpToEntity(Duration duration, const Point& distination, float height, int count = 1);
ActionJumpToEntity();
/// \~chinese /// \~chinese
/// @brief 获取目的坐标 /// @brief 获取目的坐标
@ -383,11 +375,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionJumpToEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
virtual ActionEntityPtr Reverse() const override ActionJumpToEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionJumpToEntity"); KGE_ERRORF("Reverse() not supported in ActionJumpToEntity");
return nullptr; return nullptr;
@ -429,9 +421,7 @@ public:
/// @param duration 动画时长 /// @param duration 动画时长
/// @param scale_x 横向缩放相对变化值 /// @param scale_x 横向缩放相对变化值
/// @param scale_y 纵向缩放相对变化值 /// @param scale_y 纵向缩放相对变化值
static ActionScaleByEntityPtr Create(Duration duration, float scale_x, float scale_y); ActionScaleByEntity(Duration duration, float scale_x, float scale_y);
ActionScaleByEntity();
/// \~chinese /// \~chinese
/// @brief 获取横向缩放相对变化值 /// @brief 获取横向缩放相对变化值
@ -451,11 +441,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionScaleByEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionScaleByEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -498,9 +488,7 @@ public:
/// @param duration 动画时长 /// @param duration 动画时长
/// @param scale_x 横向缩放目标值 /// @param scale_x 横向缩放目标值
/// @param scale_y 纵向缩放目标值 /// @param scale_y 纵向缩放目标值
static ActionScaleToEntityPtr Create(Duration duration, float scale_x, float scale_y); ActionScaleToEntity(Duration duration, float scale_x, float scale_y);
ActionScaleToEntity();
/// \~chinese /// \~chinese
/// @brief 获取横向缩放目标值 /// @brief 获取横向缩放目标值
@ -520,11 +508,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionScaleToEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
virtual ActionEntityPtr Reverse() const override ActionScaleToEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionScaleToEntity"); KGE_ERRORF("Reverse() not supported in ActionScaleToEntity");
return nullptr; return nullptr;
@ -581,9 +569,7 @@ public:
/// @brief 创建透明度渐变动画 /// @brief 创建透明度渐变动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param opacity 目标透明度 /// @param opacity 目标透明度
static ActionFadeToEntityPtr Create(Duration duration, float opacity); ActionFadeToEntity(Duration duration, float opacity);
ActionFadeToEntity();
/// \~chinese /// \~chinese
/// @brief 获取目标透明度 /// @brief 获取目标透明度
@ -595,11 +581,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionFadeToEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
virtual ActionEntityPtr Reverse() const override ActionFadeToEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionFadeToEntity"); KGE_ERRORF("Reverse() not supported in ActionFadeToEntity");
return nullptr; return nullptr;
@ -637,9 +623,7 @@ public:
/// @brief 创建相对旋转动画 /// @brief 创建相对旋转动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param rotation 角度相对变化值 /// @param rotation 角度相对变化值
static ActionRotateByEntityPtr Create(Duration duration, float rotation); ActionRotateByEntity(Duration duration, float rotation);
ActionRotateByEntity();
/// \~chinese /// \~chinese
/// @brief 获取角度相对变化值 /// @brief 获取角度相对变化值
@ -651,11 +635,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionRotateByEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionRotateByEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -688,9 +672,7 @@ public:
/// @brief 创建旋转动画 /// @brief 创建旋转动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param rotation 目标角度 /// @param rotation 目标角度
static ActionRotateToEntityPtr Create(Duration duration, float rotation); ActionRotateToEntity(Duration duration, float rotation);
ActionRotateToEntity();
/// \~chinese /// \~chinese
/// @brief 获取目标角度 /// @brief 获取目标角度
@ -702,11 +684,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionRotateToEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
virtual ActionEntityPtr Reverse() const override ActionRotateToEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionRotateToEntity"); KGE_ERRORF("Reverse() not supported in ActionRotateToEntity");
return nullptr; return nullptr;
@ -745,9 +727,7 @@ public:
/// @brief 创建自定义动画 /// @brief 创建自定义动画
/// @param duration 动画时长 /// @param duration 动画时长
/// @param tween_func 动画回调函数 /// @param tween_func 动画回调函数
static ActionCustomEntityPtr Create(Duration duration, ActionCustom::TweenFunc tween_func); ActionCustomEntity(Duration duration, ActionCustom::TweenFunc tween_func);
ActionCustomEntity();
/// \~chinese /// \~chinese
/// @brief 获取动画回调函数 /// @brief 获取动画回调函数
@ -759,11 +739,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionCustomEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override ActionCustomEntity* Reverse() const override
{ {
KGE_ERRORF("Reverse() not supported in ActionCustomEntity"); KGE_ERRORF("Reverse() not supported in ActionCustomEntity");
return nullptr; return nullptr;

View File

@ -26,39 +26,31 @@ namespace kiwano
ActionWalk::ActionWalk(Duration duration, ShapePtr path, bool rotating, float start, float end) 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)
{ ActionWalkEntity* ActionWalkEntity::Clone() const
ptr->SetDuration(duration); {
ptr->SetPath(path); auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, start_, end_);
ptr->SetRotating(rotating); DoClone(ptr);
ptr->SetStartValue(start);
ptr->SetEndValue(end);
}
return ptr; return ptr;
} }
ActionWalkEntity::ActionWalkEntity() ActionWalkEntity* ActionWalkEntity::Reverse() const
: start_(0.0f)
, end_(1.0f)
, rotating_(false)
, length_(0.f)
{ {
} auto ptr = new (autogc) ActionWalkEntity(GetDuration(), path_, rotating_, end_, start_);
DoClone(ptr);
ActionEntityPtr ActionWalkEntity::Clone() const return ptr;
{
return DoClone(ActionWalkEntity::Create(GetDuration(), path_, rotating_, start_, end_));
}
ActionEntityPtr ActionWalkEntity::Reverse() const
{
return DoClone(ActionWalkEntity::Create(GetDuration(), path_, rotating_, end_, start_));
} }
void ActionWalkEntity::Init(Actor* target) void ActionWalkEntity::Init(Actor* target)

View File

@ -59,10 +59,7 @@ public:
/// @param rotating 是否沿路径切线方向旋转 /// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比) /// @param start 路径起点(百分比)
/// @param end 路径终点(百分比) /// @param end 路径终点(百分比)
static ActionWalkEntityPtr Create(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, ActionWalkEntity(Duration duration, ShapePtr path, bool rotating = false, float start = 0.f, float end = 1.f);
float end = 1.f);
ActionWalkEntity();
/// \~chinese /// \~chinese
/// @brief 获取路线 /// @brief 获取路线
@ -98,11 +95,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; ActionWalkEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; ActionWalkEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;

View File

@ -27,18 +27,7 @@ namespace kiwano
Animation::Animation(Duration dur, FrameSequencePtr frame_seq) Animation::Animation(Duration dur, FrameSequencePtr frame_seq)
{ {
SetEntity(AnimationEntity::Create(dur, frame_seq)); SetEntity(MakePtr<AnimationEntity>(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;
} }
AnimationEntity::AnimationEntity() AnimationEntity::AnimationEntity()
@ -46,6 +35,12 @@ AnimationEntity::AnimationEntity()
{ {
} }
AnimationEntity::AnimationEntity(Duration dur, FrameSequencePtr frame_seq)
: ActionTweenEntity(dur)
, frame_seq_(frame_seq)
{
}
AnimationEntity::~AnimationEntity() {} AnimationEntity::~AnimationEntity() {}
FrameSequencePtr AnimationEntity::GetFrameSequence() const 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_) auto ptr = new (autogc) AnimationEntity(GetDuration(), frame_seq_);
{ DoClone(ptr);
return DoClone(AnimationEntity::Create(GetDuration(), frame_seq_)); return ptr;
}
return nullptr;
} }
ActionEntityPtr AnimationEntity::Reverse() const AnimationEntity* AnimationEntity::Reverse() const
{ {
auto ptr = new (autogc) AnimationEntity(GetDuration(), nullptr);
DoClone(ptr);
if (frame_seq_) if (frame_seq_)
{ {
FrameSequencePtr frames = frame_seq_->Reverse(); FrameSequencePtr frames = frame_seq_->Reverse();
if (frames) ptr->SetFrameSequence(frames);
{
return DoClone(AnimationEntity::Create(GetDuration(), frames));
}
} }
return nullptr; return ptr;
} }
} // namespace kiwano } // namespace kiwano

View File

@ -49,13 +49,13 @@ public:
class KGE_API AnimationEntity : public ActionTweenEntity class KGE_API AnimationEntity : public ActionTweenEntity
{ {
public: public:
AnimationEntity();
/// \~chinese /// \~chinese
/// @brief 创建帧动画 /// @brief 创建帧动画
/// @param dur 动画时长 /// @param dur 动画时长
/// @param frame_seq 序列帧 /// @param frame_seq 序列帧
static AnimationEntityPtr Create(Duration dur, FrameSequencePtr frame_seq); AnimationEntity(Duration dur, FrameSequencePtr frame_seq);
AnimationEntity();
virtual ~AnimationEntity(); virtual ~AnimationEntity();
@ -70,11 +70,11 @@ public:
/// \~chinese /// \~chinese
/// @brief 获取该动画的拷贝对象 /// @brief 获取该动画的拷贝对象
ActionEntityPtr Clone() const override; AnimationEntity* Clone() const override;
/// \~chinese /// \~chinese
/// @brief 获取该动画的倒转 /// @brief 获取该动画的倒转
ActionEntityPtr Reverse() const override; AnimationEntity* Reverse() const override;
protected: protected:
void Init(Actor* target) override; void Init(Actor* target) override;
@ -86,4 +86,5 @@ private:
}; };
/** @} */ /** @} */
} // namespace kiwano } // namespace kiwano

View File

@ -26,6 +26,7 @@
namespace kiwano namespace kiwano
{ {
Director::Director() Director::Director()
: render_border_enabled_(false) : render_border_enabled_(false)
{ {
@ -49,7 +50,7 @@ void Director::EnterStage(StagePtr stage, TransitionPtr transition)
transition_->Stop(); transition_->Stop();
} }
transition_ = transition; 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_->Stop();
} }
transition_ = transition; 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 (show)
{ {
if (!debug_actor_) if (!debug_actor_)
debug_actor_ = new (autogc) DebugActor; debug_actor_ = MakePtr<DebugActor>();
} }
else else
{ {

View File

@ -22,8 +22,8 @@
#include <kiwano/macros.h> #include <kiwano/macros.h>
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/core/Serializable.h> #include <kiwano/core/Serializable.h>
#include <kiwano/core/RefPtr.hpp>
#include <kiwano/base/RefObject.h> #include <kiwano/base/RefObject.h>
#include <kiwano/base/RefPtr.h>
namespace kiwano namespace kiwano
{ {

View File

@ -27,11 +27,6 @@ ObjectPool::ObjectPool()
{ {
} }
ObjectPool::~ObjectPool()
{
Clear();
}
void ObjectPool::AddObject(RefObject* obj) void ObjectPool::AddObject(RefObject* obj)
{ {
if (obj) if (obj)

View File

@ -37,8 +37,6 @@ class KGE_API ObjectPool : public Singleton<ObjectPool>
public: public:
ObjectPool(); ObjectPool();
virtual ~ObjectPool();
/** /**
* \~chinese * \~chinese
* @brief * @brief

79
src/kiwano/base/RefPtr.h Normal file
View File

@ -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

View File

@ -25,23 +25,19 @@
namespace kiwano 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, Button::Button(const Callback& click, const Callback& pressed, const Callback& mouse_over, const Callback& mouse_out)
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; SetName("__KGE_BUTTON__");
if (ptr)
{
ptr->SetClickCallback(click);
ptr->SetPressedCallback(pressed);
ptr->SetMouseOverCallback(mouse_over);
ptr->SetMouseOutCallback(mouse_out);
}
return ptr;
} }
Button::Button() Button::Button()

View File

@ -45,7 +45,7 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建按钮 /// @brief 创建按钮
/// @param click 按钮点击回调函数 /// @param click 按钮点击回调函数
static ButtonPtr Create(const Callback& click); Button(const Callback& click);
/// \~chinese /// \~chinese
/// @brief 创建按钮 /// @brief 创建按钮
@ -53,8 +53,7 @@ public:
/// @param pressed 按钮按下回调函数 /// @param pressed 按钮按下回调函数
/// @param mouse_over 按钮移入回调函数 /// @param mouse_over 按钮移入回调函数
/// @param mouse_out 按钮移出回调函数 /// @param mouse_out 按钮移出回调函数
static ButtonPtr Create(const Callback& click, const Callback& pressed, const Callback& mouse_over, Button(const Callback& click, const Callback& pressed, const Callback& mouse_over, const Callback& mouse_out);
const Callback& mouse_out);
Button(); Button();

View File

@ -19,7 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/core/RefPtr.hpp>
namespace kiwano namespace kiwano
{ {
@ -28,7 +27,7 @@ template <typename _Ty>
class Cloneable class Cloneable
{ {
public: public:
virtual RefPtr<_Ty> Clone() const = 0; virtual _Ty* Clone() const = 0;
protected: protected:
Cloneable() = default; Cloneable() = default;

View File

@ -22,36 +22,16 @@
#include <utility> #include <utility>
#include <type_traits> #include <type_traits>
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/base/RefObject.h>
namespace kiwano 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 * \~chinese
* @brief ÒýÓüÆÊýÖÇÄÜÖ¸Õë * @brief ÒýÓüÆÊýÖÇÄÜÖ¸Õë
*/ */
template <typename _Ty, typename _ProxyTy = DefaultRefPtrRefProxy> template <typename _Ty, typename _ProxyTy>
class RefPtr class RefBasePtr
{ {
public: public:
using value_type = _Ty; using value_type = _Ty;
@ -60,41 +40,41 @@ public:
using reference_type = _Ty&; using reference_type = _Ty&;
using const_reference_type = const _Ty&; using const_reference_type = const _Ty&;
RefPtr() noexcept RefBasePtr() noexcept
: ptr_(nullptr) : ptr_(nullptr)
{ {
} }
RefPtr(std::nullptr_t) noexcept RefBasePtr(std::nullptr_t) noexcept
: ptr_(nullptr) : ptr_(nullptr)
{ {
} }
RefPtr(pointer_type p) RefBasePtr(pointer_type p)
: ptr_(p) : ptr_(p)
{ {
_ProxyTy::Retain(ptr_); _ProxyTy::Retain(ptr_);
} }
RefPtr(const RefPtr& other) RefBasePtr(const RefBasePtr& other)
: ptr_(other.ptr_) : ptr_(other.ptr_)
{ {
_ProxyTy::Retain(ptr_); _ProxyTy::Retain(ptr_);
} }
RefPtr(RefPtr&& other) noexcept RefBasePtr(RefBasePtr&& other) noexcept
: ptr_(nullptr) : ptr_(nullptr)
{ {
Swap(other); Swap(other);
} }
~RefPtr() ~RefBasePtr()
{ {
Tidy(); Tidy();
} }
template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value, int>::type = 0> 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()); ptr_ = dynamic_cast<pointer_type>(other.Get());
_ProxyTy::Retain(ptr_); _ProxyTy::Retain(ptr_);
@ -114,12 +94,12 @@ public:
inline void Reset(pointer_type ptr = nullptr) inline void Reset(pointer_type ptr = nullptr)
{ {
if (ptr) if (ptr)
RefPtr(ptr).Swap(*this); RefBasePtr(ptr).Swap(*this);
else else
Tidy(); Tidy();
} }
inline void Swap(RefPtr& other) noexcept inline void Swap(RefBasePtr& other) noexcept
{ {
std::swap(ptr_, other.ptr_); std::swap(ptr_, other.ptr_);
} }
@ -163,36 +143,36 @@ public:
return ptr_ == 0; return ptr_ == 0;
} }
inline RefPtr& operator=(const RefPtr& other) inline RefBasePtr& operator=(const RefBasePtr& other)
{ {
if (other.ptr_ != ptr_) if (other.ptr_ != ptr_)
RefPtr(other).Swap(*this); RefBasePtr(other).Swap(*this);
return (*this); return (*this);
} }
inline RefPtr& operator=(RefPtr&& other) noexcept inline RefBasePtr& operator=(RefBasePtr&& other) noexcept
{ {
if (other.ptr_ != ptr_) if (other.ptr_ != ptr_)
other.Swap(*this); other.Swap(*this);
return (*this); return (*this);
} }
inline RefPtr& operator=(pointer_type p) inline RefBasePtr& operator=(pointer_type p)
{ {
if (p != ptr_) if (p != ptr_)
RefPtr(p).Swap(*this); RefBasePtr(p).Swap(*this);
return (*this); return (*this);
} }
template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value, int>::type = 0> 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_) if (other.Get() != ptr_)
RefPtr(dynamic_cast<pointer_type>(other.Get())).Swap(*this); RefBasePtr(dynamic_cast<pointer_type>(other.Get())).Swap(*this);
return (*this); return (*this);
} }
inline RefPtr& operator=(std::nullptr_t) inline RefBasePtr& operator=(std::nullptr_t)
{ {
Tidy(); Tidy();
return *this; return *this;
@ -210,67 +190,67 @@ private:
}; };
template <class _Ty, class _UTy, class _ProxyTy> 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(); return lhs.Get() == rhs.Get();
} }
template <class _Ty, class _ProxyTy> 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; return lhs.Get() == rhs;
} }
template <class _Ty, class _ProxyTy> 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(); return lhs == rhs.Get();
} }
template <class _Ty, class _ProxyTy> 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); return !static_cast<bool>(lhs);
} }
template <class _Ty, class _ProxyTy> 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); return !static_cast<bool>(rhs);
} }
template <class _Ty, class _UTy, class _ProxyTy> 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); return !(lhs == rhs);
} }
template <class _Ty, class _ProxyTy> 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; return lhs.Get() != rhs;
} }
template <class _Ty, class _ProxyTy> 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(); return lhs != rhs.Get();
} }
template <class _Ty, class _ProxyTy> 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); return static_cast<bool>(lhs);
} }
template <class _Ty, class _ProxyTy> 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); return static_cast<bool>(rhs);
} }
template <class _Ty, class _UTy, class _ProxyTy> 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(); 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, // template class cannot specialize std::swap,
// so implement a swap function in kiwano namespace // so implement a swap function in kiwano namespace
template <class _Ty, class _ProxyTy> 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); 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 } // namespace kiwano
#ifndef KGE_DECLARE_SMART_PTR
#define KGE_DECLARE_SMART_PTR(CLASS) \
class CLASS; \
typedef ::kiwano::RefPtr<CLASS> CLASS##Ptr;
#endif

View File

@ -19,7 +19,8 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/core/RefPtr.hpp> #include <kiwano/base/RefObject.h>
#include <kiwano/base/RefPtr.h>
#include <kiwano/event/EventType.h> #include <kiwano/event/EventType.h>
#include <kiwano/math/Math.h> #include <kiwano/math/Math.h>
@ -74,13 +75,6 @@ private:
const EventType type_; 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 /// \~chinese
/// @brief 事件特性:判断事件类型是否相同 /// @brief 事件特性:判断事件类型是否相同
template <typename _Ty> template <typename _Ty>
@ -88,7 +82,7 @@ struct IsSameEventType
{ {
inline bool operator()(const Event* evt) const 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); return evt->GetType() == KGE_EVENT(_Ty);
} }
}; };
@ -103,7 +97,7 @@ inline const EventType& Event::GetType() const
template <typename _Ty> template <typename _Ty>
inline bool Event::IsType() const 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); return IsSameEventType<_Ty>()(this);
} }

View File

@ -58,14 +58,14 @@ EventListener* EventDispatcher::AddListener(EventListenerPtr listener)
EventListener* EventDispatcher::AddListener(const String& name, EventType type, EventListener::Callback callback) EventListener* EventDispatcher::AddListener(const String& name, EventType type, EventListener::Callback callback)
{ {
EventListenerPtr listener = EventListener::Create(name, type, callback); auto lis = MakePtr<EventListener>(name, type, callback);
return AddListener(listener); return AddListener(lis);
} }
EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callback callback) EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callback callback)
{ {
EventListenerPtr listener = EventListener::Create(type, callback); auto lis = MakePtr<EventListener>(type, callback);
return AddListener(listener); return AddListener(lis);
} }
void EventDispatcher::StartListeners(const String& name) void EventDispatcher::StartListeners(const String& name)

View File

@ -59,7 +59,7 @@ public:
template <typename _EventTy> template <typename _EventTy>
EventListener* AddListener(EventListener::Callback callback) 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); return AddListener(KGE_EVENT(_EventTy), callback);
} }
@ -71,7 +71,7 @@ public:
template <typename _EventTy> template <typename _EventTy>
EventListener* AddListener(const String& name, EventListener::Callback callback) 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); return AddListener(name, KGE_EVENT(_EventTy), callback);
} }

View File

@ -24,29 +24,6 @@
namespace kiwano 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() EventListener::EventListener()
: type_() : type_()
, callback_() , 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() {} EventListener::~EventListener() {}
void EventListener::Receive(Event* evt) void EventListener::Receive(Event* evt)

View File

@ -20,9 +20,8 @@
#pragma once #pragma once
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/base/ObjectBase.h>
#include <kiwano/core/RefPtr.hpp>
#include <kiwano/core/IntrusiveList.h> #include <kiwano/core/IntrusiveList.h>
#include <kiwano/base/ObjectBase.h>
#include <kiwano/event/Events.h> #include <kiwano/event/Events.h>
namespace kiwano namespace kiwano
@ -47,44 +46,21 @@ public:
/// @brief 监听器回调函数 /// @brief 监听器回调函数
using Callback = Function<void(Event*)>; 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(); 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(); virtual ~EventListener();
/// \~chinese /// \~chinese
@ -142,7 +118,7 @@ public:
template <typename _EventTy> template <typename _EventTy>
inline void SetEventType() 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)); SetEventType(KGE_EVENT(_EventTy));
} }

View File

@ -46,7 +46,7 @@
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/core/Defer.h> #include <kiwano/core/Defer.h>
#include <kiwano/core/Resource.h> #include <kiwano/core/Resource.h>
#include <kiwano/core/RefPtr.hpp> #include <kiwano/core/RefBasePtr.hpp>
#include <kiwano/core/Time.h> #include <kiwano/core/Time.h>
// //

View File

@ -52,7 +52,7 @@ void Application::Run(RunnerPtr runner)
running_ = true; running_ = true;
is_paused_ = false; is_paused_ = false;
runner_ = runner; runner_ = runner;
timer_ = Timer::Create(); timer_ = MakePtr<Timer>();
// Initialize runner // Initialize runner
runner->InitSettings(); runner->InitSettings();

View File

@ -28,45 +28,9 @@
namespace kiwano 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() {} Runner::Runner() {}
@ -105,7 +69,7 @@ void Runner::InitSettings()
// Create frame ticker // Create frame ticker
if (!settings_.frame_interval.IsZero()) if (!settings_.frame_interval.IsZero())
{ {
frame_ticker_ = Ticker::Create(settings_.frame_interval, -1); frame_ticker_ = MakePtr<Ticker>(settings_.frame_interval, -1);
} }
} }

View File

@ -62,20 +62,13 @@ struct Settings
class KGE_API Runner : public ObjectBase class KGE_API Runner : public ObjectBase
{ {
public: 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(); Runner();
/// \~chinese
/// @brief 创建程序运行器
/// @param main_window 主窗口
Runner(Settings settings);
virtual ~Runner(); virtual ~Runner();
/// \~chinese /// \~chinese

View File

@ -21,7 +21,7 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <kiwano/core/Common.h> #include <kiwano/core/Common.h>
#include <kiwano/core/RefPtr.hpp> #include <kiwano/core/RefBasePtr.hpp>
#include <Unknwnbase.h> #include <Unknwnbase.h>
namespace kiwano namespace kiwano
@ -43,6 +43,6 @@ struct ComPtrProxy
// ComPtr<> is a smart pointer for COM // ComPtr<> is a smart pointer for COM
template <typename _Ty, typename = typename std::enable_if<std::is_base_of<IUnknown, _Ty>::value, int>::type> 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 } // namespace kiwano

View File

@ -90,7 +90,7 @@ private:
WindowPtr Window::Create(const WindowConfig& config) WindowPtr Window::Create(const WindowConfig& config)
{ {
WindowWin32ImplPtr ptr = new (autogc) WindowWin32Impl; WindowWin32ImplPtr ptr = MakePtr<WindowWin32Impl>();
if (ptr) if (ptr)
{ {
ptr->Init(config); ptr->Init(config);

View File

@ -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; SetColor(color);
if (ptr)
{
ptr->SetColor(color);
}
return ptr;
} }
BrushPtr Brush::Create(const LinearGradientStyle& style) Brush::Brush(const LinearGradientStyle& style)
: Brush()
{ {
BrushPtr ptr = new (autogc) Brush; SetStyle(style);
if (ptr)
{
ptr->SetStyle(style);
}
return ptr;
} }
BrushPtr Brush::Create(const RadialGradientStyle& style) Brush::Brush(const RadialGradientStyle& style)
: Brush()
{ {
BrushPtr ptr = new (autogc) Brush; SetStyle(style);
if (ptr)
{
ptr->SetStyle(style);
}
return ptr;
} }
Brush::Brush() Brush::Brush()

View File

@ -92,17 +92,17 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建纯色画刷 /// @brief 创建纯色画刷
/// @param color 画刷颜色 /// @param color 画刷颜色
static BrushPtr Create(const Color& color); Brush(const Color& color);
/// \~chinese /// \~chinese
/// @brief 创建线性渐变样式 /// @brief 创建线性渐变样式
/// @param style 线性渐变样式 /// @param style 线性渐变样式
static BrushPtr Create(const LinearGradientStyle& style); Brush(const LinearGradientStyle& style);
/// \~chinese /// \~chinese
/// @brief 创建径向渐变样式 /// @brief 创建径向渐变样式
/// @param style 径向渐变样式 /// @param style 径向渐变样式
static BrushPtr Create(const RadialGradientStyle& style); Brush(const RadialGradientStyle& style);
Brush(); Brush();

View File

@ -97,7 +97,7 @@ void RendererImpl::MakeContextForWindow(WindowPtr window)
// Initialize other device resources // Initialize other device resources
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
RenderContextImplPtr ctx = new (autogc) RenderContextImpl; RenderContextImplPtr ctx = MakePtr<RenderContextImpl>();
hr = ctx->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext()); hr = ctx->CreateDeviceResources(d2d_res_->GetFactory(), d2d_res_->GetDeviceContext());
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -403,7 +403,7 @@ void RendererImpl::CreateGifImageFrame(GifImage::Frame& frame, const GifImage& g
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
frame.texture = new (autogc) Texture; frame.texture = MakePtr<Texture>();
NativePtr::Set(frame.texture, bitmap); NativePtr::Set(frame.texture, bitmap);
frame.texture->SetSize({ bitmap->GetSize().width, bitmap->GetSize().height }); frame.texture->SetSize({ bitmap->GetSize().width, bitmap->GetSize().height });
@ -769,7 +769,7 @@ void RendererImpl::CreateShapeSink(ShapeMaker& maker)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
ShapePtr shape = new (autogc) Shape; ShapePtr shape = MakePtr<Shape>();
NativePtr::Set(shape, geometry); NativePtr::Set(shape, geometry);
maker.SetShape(shape); maker.SetShape(shape);
@ -945,7 +945,7 @@ void RendererImpl::CreateStrokeStyle(StrokeStyle& stroke_style)
RenderContextPtr RendererImpl::CreateTextureRenderContext(Texture& texture, const Size* desired_size) RenderContextPtr RendererImpl::CreateTextureRenderContext(Texture& texture, const Size* desired_size)
{ {
RenderContextImplPtr ptr = new (autogc) RenderContextImpl; RenderContextImplPtr ptr = MakePtr<RenderContextImpl>();
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (!d2d_res_) if (!d2d_res_)

View File

@ -24,26 +24,14 @@
namespace kiwano namespace kiwano
{ {
FontPtr Font::Create(const String& file) Font::Font(const String& file)
{ {
FontPtr ptr = new (autogc) Font; Load(file);
if (ptr)
{
if (!ptr->Load(file))
return nullptr;
}
return ptr;
} }
FontPtr Font::Create(const Resource& resource) Font::Font(const Resource& resource)
{ {
FontPtr ptr = new (autogc) Font; Load(resource);
if (ptr)
{
if (!ptr->Load(resource))
return nullptr;
}
return ptr;
} }
Font::Font() {} Font::Font() {}

View File

@ -44,11 +44,11 @@ class Font : public NativeObject
public: public:
/// \~chinese /// \~chinese
/// @brief ´´½¨×ÖÌå /// @brief ´´½¨×ÖÌå
static FontPtr Create(const String& file); Font(const String& file);
/// \~chinese /// \~chinese
/// @brief ´´½¨×ÖÌå /// @brief ´´½¨×ÖÌå
static FontPtr Create(const Resource& resource); Font(const Resource& resource);
Font(); Font();

View File

@ -24,36 +24,19 @@
namespace kiwano namespace kiwano
{ {
FramePtr Frame::Create(const String& file_path) Frame::Frame(const String& file_path)
{ {
FramePtr ptr = new (autogc) Frame; Load(file_path);
if (ptr)
{
if (!ptr->Load(file_path))
return nullptr;
}
return ptr;
} }
FramePtr Frame::Create(const Resource& res) Frame::Frame(const Resource& res)
{ {
FramePtr ptr = new (autogc) Frame; Load(res);
if (ptr)
{
if (!ptr->Load(res))
return nullptr;
}
return ptr;
} }
FramePtr Frame::Create(TexturePtr texture) Frame::Frame(TexturePtr texture)
{ {
FramePtr ptr = new (autogc) Frame; SetTexture(texture);
if (ptr)
{
ptr->SetTexture(texture);
}
return ptr;
} }
Frame::Frame() {} Frame::Frame() {}

View File

@ -36,17 +36,17 @@ public:
/// \~chinese /// \~chinese
/// @brief 创建图像帧 /// @brief 创建图像帧
/// @param file_path 图像路径 /// @param file_path 图像路径
static FramePtr Create(const String& file_path); Frame(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 创建图像帧 /// @brief 创建图像帧
/// @param res 图像资源 /// @param res 图像资源
static FramePtr Create(const Resource& res); Frame(const Resource& res);
/// \~chinese /// \~chinese
/// @brief 创建图像帧 /// @brief 创建图像帧
/// @param texture 纹理 /// @param texture 纹理
static FramePtr Create(TexturePtr texture); Frame(TexturePtr texture);
/// \~chinese /// \~chinese
/// @brief 构建空图像帧 /// @brief 构建空图像帧

View File

@ -24,31 +24,15 @@
namespace kiwano namespace kiwano
{ {
FrameSequencePtr FrameSequence::Create() FrameSequence::FrameSequence(const Vector<FramePtr>& frames)
{ {
FrameSequencePtr ptr = new (autogc) FrameSequence; AddFrames(frames);
return ptr;
} }
FrameSequencePtr FrameSequence::Create(const Vector<FramePtr>& frames) FrameSequence::FrameSequence(FramePtr frame, int cols, int rows, int max_num, float padding_x,
{
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,
float padding_y) float padding_y)
{ {
FrameSequencePtr ptr = new (autogc) FrameSequence; AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
if (ptr)
{
ptr->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
}
return ptr;
} }
FrameSequence::FrameSequence() {} 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++) for (int j = 0; j < cols; j++)
{ {
FramePtr ptr = new (autogc) Frame; FramePtr ptr = MakePtr<Frame>();
if (ptr) if (ptr)
{ {
ptr->SetTexture(frame->GetTexture()); ptr->SetTexture(frame->GetTexture());
@ -140,7 +124,7 @@ size_t FrameSequence::GetFramesCount() const
FrameSequencePtr FrameSequence::Clone() const FrameSequencePtr FrameSequence::Clone() const
{ {
auto frame_seq = new (autogc) FrameSequence; auto frame_seq = MakePtr<FrameSequence>();
if (frame_seq) if (frame_seq)
{ {
frame_seq->AddFrames(frames_); frame_seq->AddFrames(frames_);
@ -150,7 +134,7 @@ FrameSequencePtr FrameSequence::Clone() const
FrameSequencePtr FrameSequence::Reverse() const FrameSequencePtr FrameSequence::Reverse() const
{ {
auto frame_seq = new (autogc) FrameSequence; auto frame_seq = MakePtr<FrameSequence>();
if (!frames_.empty()) if (!frames_.empty())
{ {
for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter) for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter)

View File

@ -34,14 +34,10 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
class KGE_API FrameSequence : public ObjectBase class KGE_API FrameSequence : public ObjectBase
{ {
public: public:
/// \~chinese
/// @brief ´´½¨ÐòÁÐÖ¡
static FrameSequencePtr Create();
/// \~chinese /// \~chinese
/// @brief 创建序列帧 /// @brief 创建序列帧
/// @param frames 图像帧集合 /// @param frames 图像帧集合
static FrameSequencePtr Create(const Vector<FramePtr>& frames); FrameSequence(const Vector<FramePtr>& frames);
/// \~chinese /// \~chinese
/// @brief 按行列分割图像并创建序列帧 /// @brief 按行列分割图像并创建序列帧
@ -51,7 +47,7 @@ public:
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧 /// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
/// @param padding_x X方向间隔 /// @param padding_x X方向间隔
/// @param padding_y Y方向间隔 /// @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); float padding_y = 0);
/// \~chinese /// \~chinese

View File

@ -25,26 +25,16 @@
namespace kiwano namespace kiwano
{ {
GifImagePtr GifImage::Create(const String& file_path) GifImage::GifImage(const String& file_path)
: GifImage()
{ {
GifImagePtr ptr = new (autogc) GifImage; Load(file_path);
if (ptr)
{
if (!ptr->Load(file_path))
return nullptr;
}
return ptr;
} }
GifImagePtr GifImage::Create(const Resource& res) GifImage::GifImage(const Resource& res)
: GifImage()
{ {
GifImagePtr ptr = new (autogc) GifImage; Load(res);
if (ptr)
{
if (!ptr->Load(res))
return nullptr;
}
return ptr;
} }
GifImage::GifImage() GifImage::GifImage()

View File

@ -40,11 +40,11 @@ class KGE_API GifImage : public NativeObject
public: public:
/// \~chinese /// \~chinese
/// @brief ´´½¨GIFͼƬ /// @brief ´´½¨GIFͼƬ
static GifImagePtr Create(const String& file_path); GifImage(const String& file_path);
/// \~chinese /// \~chinese
/// @brief ´´½¨GIFͼƬ /// @brief ´´½¨GIFͼƬ
static GifImagePtr Create(const Resource& res); GifImage(const Resource& res);
GifImage(); GifImage();

View File

@ -136,35 +136,35 @@ bool Shape::ContainsPoint(const Point& point, const Matrix3x2* transform) const
ShapePtr Shape::CreateLine(const Point& begin, const Point& end) ShapePtr Shape::CreateLine(const Point& begin, const Point& end)
{ {
ShapePtr output = new (autogc) Shape; ShapePtr output = MakePtr<Shape>();
Renderer::GetInstance().CreateLineShape(*output, begin, end); Renderer::GetInstance().CreateLineShape(*output, begin, end);
return output; return output;
} }
ShapePtr Shape::CreateRect(const Rect& rect) ShapePtr Shape::CreateRect(const Rect& rect)
{ {
ShapePtr output = new (autogc) Shape; ShapePtr output = MakePtr<Shape>();
Renderer::GetInstance().CreateRectShape(*output, rect); Renderer::GetInstance().CreateRectShape(*output, rect);
return output; return output;
} }
ShapePtr Shape::CreateRoundedRect(const Rect& rect, const Vec2& radius) ShapePtr Shape::CreateRoundedRect(const Rect& rect, const Vec2& radius)
{ {
ShapePtr output = new (autogc) Shape; ShapePtr output = MakePtr<Shape>();
Renderer::GetInstance().CreateRoundedRectShape(*output, rect, radius); Renderer::GetInstance().CreateRoundedRectShape(*output, rect, radius);
return output; return output;
} }
ShapePtr Shape::CreateCircle(const Point& center, float radius) 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 }); Renderer::GetInstance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
return output; return output;
} }
ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius) ShapePtr Shape::CreateEllipse(const Point& center, const Vec2& radius)
{ {
ShapePtr output = new (autogc) Shape; ShapePtr output = MakePtr<Shape>();
Renderer::GetInstance().CreateEllipseShape(*output, center, radius); Renderer::GetInstance().CreateEllipseShape(*output, center, radius);
return output; return output;
} }

View File

@ -28,12 +28,6 @@
namespace kiwano namespace kiwano
{ {
ShapeMakerPtr ShapeMaker::Create()
{
ShapeMakerPtr ptr = new (autogc) ShapeMaker;
return ptr;
}
ShapeMaker::ShapeMaker() {} ShapeMaker::ShapeMaker() {}
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) ShapePtr ShapeMaker::Combine(ShapePtr shape_a, ShapePtr shape_b, CombineMode mode, const Matrix3x2* matrix)
{ {
ShapeMakerPtr maker = ShapeMaker::Create(); ShapeMaker maker;
maker->OpenStream(); maker.OpenStream();
#if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX #if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
if (shape_a && shape_b) if (shape_a && shape_b)
@ -170,8 +164,8 @@ ShapePtr ShapeMaker::Combine(ShapePtr shape_a, ShapePtr shape_b, CombineMode mod
// not supported // not supported
#endif #endif
maker->CloseStream(); maker.CloseStream();
return maker->GetShape(); return maker.GetShape();
} }
void ShapeMaker::OpenStream() void ShapeMaker::OpenStream()

View File

@ -46,10 +46,6 @@ enum class CombineMode
class KGE_API ShapeMaker : public NativeObject class KGE_API ShapeMaker : public NativeObject
{ {
public: public:
/// \~chinese
/// @brief 创建形状生成器
static ShapeMakerPtr Create();
ShapeMaker(); ShapeMaker();
~ShapeMaker(); ~ShapeMaker();

View File

@ -24,39 +24,30 @@
namespace kiwano 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, StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset)
float dash_offset) : StrokeStyle()
{ {
StrokeStylePtr ptr = new (autogc) StrokeStyle; SetStrokeWidth(width);
if (ptr) SetCapStyle(cap);
{ SetLineJoinStyle(line_join);
ptr->SetStrokeWidth(width); SetDashStyle(dash);
ptr->SetCapStyle(cap); SetDashOffset(dash_offset);
ptr->SetLineJoinStyle(line_join);
ptr->SetDashStyle(dash);
ptr->SetDashOffset(dash_offset);
}
return ptr;
} }
StrokeStylePtr StrokeStyle::Create(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, StrokeStyle::StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
size_t dash_size, float dash_offset) float dash_offset)
: StrokeStyle()
{ {
StrokeStylePtr ptr = new (autogc) StrokeStyle; SetStrokeWidth(width);
if (ptr) SetCapStyle(cap);
{ SetLineJoinStyle(line_join);
ptr->SetStrokeWidth(width); SetDashStyle(dash_array, dash_size);
ptr->SetCapStyle(cap); SetDashOffset(dash_offset);
ptr->SetLineJoinStyle(line_join);
ptr->SetDashStyle(dash_array, dash_size);
ptr->SetDashOffset(dash_offset);
}
return ptr;
} }
StrokeStyle::StrokeStyle() StrokeStyle::StrokeStyle()

View File

@ -74,8 +74,7 @@ public:
/// @param width 线条宽度 /// @param width 线条宽度
/// @param cap 线条端点样式 /// @param cap 线条端点样式
/// @param line_join 线条交点样式 /// @param line_join 线条交点样式
static StrokeStylePtr Create(float width, CapStyle cap = CapStyle::Flat, StrokeStyle(float width, CapStyle cap = CapStyle::Flat, LineJoinStyle line_join = LineJoinStyle::Miter);
LineJoinStyle line_join = LineJoinStyle::Miter);
/// \~chinese /// \~chinese
/// @brief 创建线条样式 /// @brief 创建线条样式
@ -84,8 +83,7 @@ public:
/// @param line_join 线条交点样式 /// @param line_join 线条交点样式
/// @param dash 线条虚线样式 /// @param dash 线条虚线样式
/// @param dash_offset 线条虚线偏移量 /// @param dash_offset 线条虚线偏移量
static StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, DashStyle dash, float dash_offset = 0.0f);
float dash_offset = 0.0f);
/// \~chinese /// \~chinese
/// @brief 创建线条样式 /// @brief 创建线条样式
@ -95,8 +93,8 @@ public:
/// @param dash_array 线条虚线的长度与间隙数组 /// @param dash_array 线条虚线的长度与间隙数组
/// @param dash_size 线条虚线数组大小 /// @param dash_size 线条虚线数组大小
/// @param dash_offset 线条虚线偏移量 /// @param dash_offset 线条虚线偏移量
static StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, const float* dash_array, size_t dash_size,
size_t dash_size, float dash_offset = 0.0f); float dash_offset = 0.0f);
/// \~chinese /// \~chinese
/// @brief 创建线条样式 /// @brief 创建线条样式
@ -107,10 +105,10 @@ public:
/// @param dash_array 线条虚线的长度与间隙数组 /// @param dash_array 线条虚线的长度与间隙数组
/// @param dash_offset 线条虚线偏移量 /// @param dash_offset 线条虚线偏移量
template <size_t _DashSize> template <size_t _DashSize>
static inline StrokeStylePtr Create(float width, CapStyle cap, LineJoinStyle line_join, StrokeStyle(float width, CapStyle cap, LineJoinStyle line_join, float (&dash_array)[_DashSize],
float (&dash_array)[_DashSize], float dash_offset = 0.0f) 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(); StrokeStyle();

View File

@ -28,28 +28,18 @@
namespace kiwano 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() TextLayout::TextLayout()
: dirty_flag_(DirtyFlag::Clean) : dirty_flag_(DirtyFlag::Clean)
, line_count_(0) , line_count_(0)
{ {
} }
TextLayout::TextLayout(const String& content, const TextStyle& style)
: TextLayout()
{
Reset(content, style);
}
void TextLayout::Reset(const String& content, const TextStyle& style) void TextLayout::Reset(const String& content, const TextStyle& style)
{ {
content_ = content; content_ = content;

View File

@ -38,19 +38,13 @@ KGE_DECLARE_SMART_PTR(TextLayout);
class KGE_API TextLayout : public NativeObject class KGE_API TextLayout : public NativeObject
{ {
public: public:
/// \~chinese TextLayout();
/// @brief 创建文本布局
static TextLayoutPtr Create();
/// \~chinese /// \~chinese
/// @brief 创建文本布局 /// @brief 创建文本布局
/// @param content 文字内容 /// @param content 文字内容
/// @param style 文本样式 /// @param style 文本样式
static TextLayoutPtr Create(const String& content, const TextStyle& style); TextLayout(const String& content, const TextStyle& style);
/// \~chinese
/// @brief 构造空的文本布局
TextLayout();
/// \~chinese /// \~chinese
/// @brief 文本布局是否陈旧 /// @brief 文本布局是否陈旧

View File

@ -30,26 +30,16 @@ namespace kiwano
InterpolationMode Texture::default_interpolation_mode_ = InterpolationMode::Linear; 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; Load(file_path);
if (ptr)
{
if (!ptr->Load(file_path))
return nullptr;
}
return ptr;
} }
TexturePtr Texture::Create(const Resource& res) Texture::Texture(const Resource& res)
: Texture()
{ {
TexturePtr ptr = new (autogc) Texture; Load(res);
if (ptr)
{
if (!ptr->Load(res))
return nullptr;
}
return ptr;
} }
Texture::Texture() Texture::Texture()

View File

@ -56,11 +56,11 @@ class KGE_API Texture : public NativeObject
public: public:
/// \~chinese /// \~chinese
/// @brief 从本地文件创建纹理 /// @brief 从本地文件创建纹理
static TexturePtr Create(const String& file_path); Texture(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 从资源创建纹理 /// @brief 从资源创建纹理
static TexturePtr Create(const Resource& res); Texture(const Resource& res);
Texture(); Texture();

View File

@ -33,7 +33,7 @@ RefPtr<_Ty> CreateOrGetCache(_CacheTy& cache, const _PathTy& path, size_t hash)
return iter->second; return iter->second;
} }
RefPtr<_Ty> texture = new (autogc) _Ty; RefPtr<_Ty> texture = MakePtr<_Ty>();
if (texture->Load(path)) if (texture->Load(path))
{ {
cache.insert(std::make_pair(hash, texture)); cache.insert(std::make_pair(hash, texture));

View File

@ -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; Load(file_path);
if (ptr)
{
if (!ptr->Load(file_path))
{
return nullptr;
}
}
return ptr;
} }
bool ConfigIni::Load(const String& file_path) bool ConfigIni::Load(const String& file_path)

View File

@ -32,11 +32,6 @@ KGE_DECLARE_SMART_PTR(ConfigIni);
class KGE_API ConfigIni : public ObjectBase class KGE_API ConfigIni : public ObjectBase
{ {
public: public:
/// \~chinese
/// @brief 加载 ini 文件
/// @param file_path 文件路径
static ConfigIniPtr Create(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 键值字典 /// @brief 键值字典
typedef UnorderedMap<String, String> ValueMap; typedef UnorderedMap<String, String> ValueMap;
@ -45,6 +40,13 @@ public:
/// @brief Section字典 /// @brief Section字典
typedef UnorderedMap<String, ValueMap> SectionMap; typedef UnorderedMap<String, ValueMap> SectionMap;
ConfigIni();
/// \~chinese
/// @brief 加载 ini 文件
/// @param file_path 文件路径
ConfigIni(const String& file_path);
/// \~chinese /// \~chinese
/// @brief 加载 ini 文件 /// @brief 加载 ini 文件
/// @param file_path 文件路径 /// @param file_path 文件路径

View File

@ -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) bool EventTicker::Tick(Duration dt)

View File

@ -57,11 +57,13 @@ class KGE_API EventTicker
, public EventDispatcher , public EventDispatcher
{ {
public: public:
EventTicker();
/// \~chinese /// \~chinese
/// @brief 创建事件报时器 /// @brief 创建事件报时器
/// @param interval 报时间隔 /// @param interval 报时间隔
/// @param times 报时次数(设 -1 为永久) /// @param tick_count 报时次数(设 -1 为永久)
static EventTickerPtr Create(Duration interval, int times = -1); EventTicker(Duration interval, int tick_count = -1);
using Ticker::Tick; using Ticker::Tick;

View File

@ -194,10 +194,8 @@ std::ostream& ConsoleColorBrush(std::ostream& os)
return os; return os;
} }
LogProviderPtr ConsoleLogProvider::Create() ConsoleLogProvider::ConsoleLogProvider()
{ {
LogProviderPtr ptr = new ConsoleLogProvider;
return ptr;
} }
ConsoleLogProvider::~ConsoleLogProvider() ConsoleLogProvider::~ConsoleLogProvider()
@ -242,14 +240,9 @@ ConsoleLogProvider::ConsoleColor ConsoleLogProvider::GetColor(LogLevel level)
return ConsoleColorBrush<0>; 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; ofs_.open(filepath, mode);
if (ptr)
{
ptr->ofs_.open(filepath, mode);
}
return ptr;
} }
FileLogProvider::~FileLogProvider() FileLogProvider::~FileLogProvider()
@ -500,10 +493,10 @@ Logger::Logger()
, buffer_(1024) , buffer_(1024)
, stream_(&buffer_) , stream_(&buffer_)
{ {
LogFormaterPtr formater = new TextFormater; LogFormaterPtr formater = MakePtr<TextFormater>();
SetFormater(formater); SetFormater(formater);
LogProviderPtr provider = ConsoleLogProvider::Create(); LogProviderPtr provider = MakePtr<ConsoleLogProvider>();
AddProvider(provider); AddProvider(provider);
} }

View File

@ -175,7 +175,7 @@ protected:
class KGE_API ConsoleLogProvider : public LogProvider class KGE_API ConsoleLogProvider : public LogProvider
{ {
public: public:
static LogProviderPtr Create(); ConsoleLogProvider();
virtual ~ConsoleLogProvider(); virtual ~ConsoleLogProvider();
@ -199,7 +199,7 @@ private:
class KGE_API FileLogProvider : public LogProvider class KGE_API FileLogProvider : public LogProvider
{ {
public: 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(); virtual ~FileLogProvider();

View File

@ -214,7 +214,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
if (type == "gif") if (type == "gif")
{ {
// GIF image // GIF image
GifImagePtr gif = new (autogc) GifImage; GifImagePtr gif = MakePtr<GifImage>();
if (gif && gif->Load(gdata->path + file)) if (gif && gif->Load(gdata->path + file))
{ {
return loader->AddObject(id, gif); return loader->AddObject(id, gif);
@ -224,7 +224,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
if (!file.empty()) if (!file.empty())
{ {
// Simple image // Simple image
FramePtr frame = new (autogc) Frame; FramePtr frame = MakePtr<Frame>();
if (frame && frame->Load(gdata->path + file)) if (frame && frame->Load(gdata->path + file))
{ {
return loader->AddObject(id, frame); return loader->AddObject(id, frame);
@ -246,13 +246,13 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
frames.reserve(files.size()); frames.reserve(files.size());
for (const auto& file : files) for (const auto& file : files)
{ {
FramePtr frame = new (autogc) Frame; FramePtr frame = MakePtr<Frame>();
if (frame->Load(gdata->path + file)) if (frame->Load(gdata->path + file))
{ {
frames.push_back(frame); frames.push_back(frame);
} }
} }
FrameSequencePtr frame_seq = FrameSequence::Create(frames); FrameSequencePtr frame_seq = MakePtr<FrameSequence>(frames);
if (frame_seq) if (frame_seq)
{ {
return !!loader->AddObject(id, frame_seq); return !!loader->AddObject(id, frame_seq);
@ -271,10 +271,10 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
if (rows || cols) if (rows || cols)
{ {
// Frame slices // Frame slices
FramePtr frame = new (autogc) Frame; FramePtr frame = MakePtr<Frame>();
if (frame && frame->Load(gdata->path + file)) if (frame && frame->Load(gdata->path + file))
{ {
FrameSequencePtr frame_seq = new (autogc) FrameSequence; FrameSequencePtr frame_seq = MakePtr<FrameSequence>();
if (frame_seq) if (frame_seq)
{ {
frame_seq->AddFrames(frame, cols, rows, max_num, padding_x, padding_y); 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 else
{ {
// Simple image // Simple image
FramePtr frame = new (autogc) Frame; FramePtr frame = MakePtr<Frame>();
if (frame && frame->Load(gdata->path + file)) if (frame && frame->Load(gdata->path + file))
{ {
return loader->AddObject(id, frame); return loader->AddObject(id, frame);
@ -300,7 +300,7 @@ bool LoadFontsFromData(ResourceCache* loader, GlobalData* gdata, const String& i
if (!gdata) if (!gdata)
return false; return false;
FontPtr font = new (autogc) Font; FontPtr font = MakePtr<Font>();
if (font && font->Load(gdata->path + file)) if (font && font->Load(gdata->path + file))
{ {
return loader->AddObject(id, font); return loader->AddObject(id, font);

View File

@ -22,37 +22,32 @@
namespace kiwano 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); SetName(name);
if (ptr)
{
ptr->SetName(name);
}
return ptr;
} }
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); ticker_ = MakePtr<Ticker>(interval, times);
return Task::Create(cb, ticker);
} }
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); SetName(name);
return Task::Create(name, cb, ticker);
} }
Task::Task() Task::Task()

Some files were not shown because too many files have changed in this diff Show More