Add docs for Actors & Actions

This commit is contained in:
Nomango 2019-12-23 18:05:08 +08:00
parent 13cbca8f49
commit 5ba5e4525c
96 changed files with 2317 additions and 1698 deletions

View File

@ -19,7 +19,7 @@ EXTRACT_PRIVATE = NO
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = NO
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
SHOW_INCLUDE_FILES = YES
@ -61,12 +61,8 @@ PREDEFINED = KGE_API=
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
SEARCH_INCLUDES = YES
INCLUDE_PATH = src/
INCLUDE_FILE_PATTERNS = *.h \
*.hh \
*.hxx \
*.hpp \
*.h++
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
#---------------------------------------------------------------------------
# Configuration options related to the HTML output

View File

@ -11,15 +11,14 @@
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
<ClInclude Include="..\..\src\kiwano\2d\Frame.h" />
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" />
<ClInclude Include="..\..\src\kiwano\core\common.h" />
<ClInclude Include="..\..\src\kiwano\core\Event.h" />
<ClInclude Include="..\..\src\kiwano\core\Library.h" />
<ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp" />
<ClInclude Include="..\..\src\kiwano\core\win32\helper.h" />
<ClInclude Include="..\..\src\kiwano\common\common.h" />
<ClInclude Include="..\..\src\kiwano\kiwano.h" />
<ClInclude Include="..\..\src\kiwano\config.h" />
<ClInclude Include="..\..\src\kiwano\macros.h" />
<ClInclude Include="..\..\src\kiwano\2d\include-forwards.h" />
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h" />
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
@ -28,7 +27,7 @@
<ClInclude Include="..\..\src\kiwano\2d\Actor.h" />
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h" />
<ClInclude Include="..\..\src\kiwano\2d\Text.h" />
<ClInclude Include="..\..\src\kiwano\2d\TextActor.h" />
<ClInclude Include="..\..\src\kiwano\2d\TextStyle.hpp" />
<ClInclude Include="..\..\src\kiwano\2d\Transform.h" />
<ClInclude Include="..\..\src\kiwano\2d\Transition.h" />
@ -102,7 +101,7 @@
<ClCompile Include="..\..\src\kiwano\2d\Actor.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Text.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\TextActor.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Transform.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Transition.cpp" />
<ClCompile Include="..\..\src\kiwano\core\AsyncTask.cpp" />

View File

@ -25,9 +25,6 @@
<Filter Include="2d\action">
<UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier>
</Filter>
<Filter Include="common">
<UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier>
</Filter>
<Filter Include="renderer\win32">
<UniqueIdentifier>{30333461-e9bc-4709-84bd-ce6e0e1a3079}</UniqueIdentifier>
</Filter>
@ -45,18 +42,12 @@
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\include-forwards.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\Layer.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\Sprite.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\Text.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\TextStyle.hpp">
<Filter>2d</Filter>
</ClInclude>
@ -150,9 +141,6 @@
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\common\common.h">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h">
<Filter>2d</Filter>
</ClInclude>
@ -276,6 +264,12 @@
<ClInclude Include="..\..\src\kiwano\platform\Director.h">
<Filter>platform</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\2d\TextActor.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\..\src\kiwano\core\common.h">
<Filter>core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\kiwano\ui\Button.cpp">
@ -293,9 +287,6 @@
<ClCompile Include="..\..\src\kiwano\2d\Sprite.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\Text.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\Transition.cpp">
<Filter>2d</Filter>
</ClCompile>
@ -458,5 +449,8 @@
<ClCompile Include="..\..\src\kiwano\platform\Director.cpp">
<Filter>platform</Filter>
</ClCompile>
<ClCompile Include="..\..\src\kiwano\2d\TextActor.cpp">
<Filter>2d</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/Component.h>
#include <kiwano/core/win32/ComPtr.hpp>
#include <kiwano-audio/Transcoder.h>
@ -52,12 +52,12 @@ namespace kiwano
void DestroyComponent() override;
protected:
private:
AudioEngine();
~AudioEngine();
protected:
private:
IXAudio2* x_audio2_;
IXAudio2MasteringVoice* mastering_voice_;
};

View File

@ -84,7 +84,7 @@ namespace kiwano
float volume /* 1 为原始音量, 大于 1 为放大音量, 0 为最小音量 */
);
protected:
private:
bool opened_;
bool playing_;
Transcoder transcoder_;

View File

@ -93,7 +93,7 @@ namespace kiwano
// 헌뇜뻠닸
void ClearCache();
protected:
private:
float volume_;
using SoundMap = Map<size_t, SoundPtr>;

View File

@ -23,7 +23,7 @@
#endif
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/Resource.h>
#include <kiwano/core/Logger.h>
#include <kiwano/core/win32/ComPtr.hpp>

View File

@ -54,7 +54,7 @@ namespace kiwano
public:
void OnRender(RenderTarget* rt) override;
protected:
private:
Map<String, ImGuiPipeline> pipelines_;
};
}

View File

@ -1,6 +1,6 @@
// Copyright (C) 2019 Nomango
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/platform/Window.h>
#include <kiwano/platform/Input.h>
#include <kiwano/renderer/Renderer.h>

View File

@ -19,8 +19,8 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/core/common.h>
#include <kiwano/core/Component.h>
#include <kiwano/common/common.h>
namespace kiwano
{

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/Component.h>
#include <mutex>
#include <condition_variable>

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/SmartPtr.hpp>
@ -73,7 +73,7 @@ namespace kiwano
void SetResponseCallback(ResponseCallback const& callback);
ResponseCallback const& GetResponseCallback() const;
protected:
private:
Type type_;
String url_;
String data_;

View File

@ -56,7 +56,7 @@ namespace kiwano
String const& GetError() const;
void SetError(String const& error_buffer);
protected:
private:
bool succeed_;
long response_code_;
HttpRequestPtr request_;

View File

@ -161,10 +161,10 @@ namespace kiwano
void UpdateActor();
void UpdateFromActor();
protected:
private:
void UpdateFixtureFilter(b2Fixture* fixture);
protected:
private:
Actor* actor_;
World* world_;
b2Body* body_;

View File

@ -72,7 +72,7 @@ namespace kiwano
const b2Contact* GetB2Contact() const { return contact_; }
void SetB2Contact(b2Contact* contact) { contact_ = contact; }
protected:
private:
b2Contact* contact_;
};
@ -104,7 +104,7 @@ namespace kiwano
const b2ContactEdge* GetB2ContactEdge() const { return edge_; }
void SetB2ContactEdge(b2ContactEdge* edge) { edge_ = edge; }
protected:
private:
b2ContactEdge* edge_;
};

View File

@ -26,8 +26,13 @@ namespace kiwano
{
namespace physics
{
/**
* \addtogroup Events
* @{
*/
/// \~chinese
/// @brief 接触开始事件
/// @brief 物理接触开始事件
class KGE_API ContactBeginEvent
: public Event
{
@ -41,7 +46,7 @@ namespace kiwano
};
/// \~chinese
/// @brief 接触结束事件
/// @brief 物理接触结束事件
class KGE_API ContactEndEvent
: public Event
{
@ -53,5 +58,7 @@ namespace kiwano
ContactEndEvent();
ContactEndEvent(Contact const& contact);
};
/** @} */
}
}

View File

@ -91,7 +91,7 @@ namespace kiwano
const b2Fixture* GetB2Fixture() const { return fixture_; }
void SetB2Fixture(b2Fixture* fixture) { fixture_ = fixture; }
protected:
private:
b2Fixture* fixture_;
};
}

View File

@ -126,14 +126,14 @@ namespace kiwano
void DistanceJoint::SetLength(float length)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetLength(world_->Stage2World(length));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetLength(GetWorld()->Stage2World(length));
}
float DistanceJoint::GetLength() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetLength());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetLength());
}
//
@ -181,14 +181,14 @@ namespace kiwano
void FrictionJoint::SetMaxTorque(float length)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetMaxTorque(world_->Stage2World(length));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetMaxTorque(GetWorld()->Stage2World(length));
}
float FrictionJoint::GetMaxTorque() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetMaxTorque());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetMaxTorque());
}
//
@ -279,14 +279,14 @@ namespace kiwano
void MotorJoint::SetMaxTorque(float length)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetMaxTorque(world_->Stage2World(length));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetMaxTorque(GetWorld()->Stage2World(length));
}
float MotorJoint::GetMaxTorque() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetMaxTorque());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetMaxTorque());
}
//
@ -326,32 +326,32 @@ namespace kiwano
float PrismaticJoint::GetJointTranslation() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetJointTranslation());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetJointTranslation());
}
float PrismaticJoint::GetJointSpeed() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetJointSpeed());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetJointSpeed());
}
float PrismaticJoint::GetLowerLimit() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetLowerLimit());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetLowerLimit());
}
float PrismaticJoint::GetUpperLimit() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetUpperLimit());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetUpperLimit());
}
void PrismaticJoint::SetLimits(float lower, float upper)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetLimits(world_->Stage2World(lower), world_->Stage2World(upper));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetLimits(GetWorld()->Stage2World(lower), GetWorld()->Stage2World(upper));
}
//
@ -386,14 +386,14 @@ namespace kiwano
Point PulleyJoint::GetGroundAnchorA() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetGroundAnchorA());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetGroundAnchorA());
}
Point PulleyJoint::GetGroundAnchorB() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetGroundAnchorB());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetGroundAnchorB());
}
float PulleyJoint::GetRatio() const
@ -404,26 +404,26 @@ namespace kiwano
float PulleyJoint::GetLengthA() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetLengthA());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetLengthA());
}
float PulleyJoint::GetLengthB() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetLengthB());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetLengthB());
}
float PulleyJoint::GetCurrentLengthA() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetCurrentLengthA());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetCurrentLengthA());
}
float PulleyJoint::GetCurrentLengthB() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetCurrentLengthB());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetCurrentLengthB());
}
//
@ -463,44 +463,44 @@ namespace kiwano
float RevoluteJoint::GetJointAngle() const
{
KGE_ASSERT(raw_joint_ && world_);
KGE_ASSERT(raw_joint_ && GetWorld());
return math::Radian2Degree(raw_joint_->GetJointAngle());
}
float RevoluteJoint::GetJointSpeed() const
{
KGE_ASSERT(raw_joint_ && world_);
KGE_ASSERT(raw_joint_ && GetWorld());
return math::Radian2Degree(raw_joint_->GetJointSpeed());
}
float RevoluteJoint::GetLowerLimit() const
{
KGE_ASSERT(raw_joint_ && world_);
KGE_ASSERT(raw_joint_ && GetWorld());
return math::Radian2Degree(raw_joint_->GetLowerLimit());
}
float RevoluteJoint::GetUpperLimit() const
{
KGE_ASSERT(raw_joint_ && world_);
KGE_ASSERT(raw_joint_ && GetWorld());
return math::Radian2Degree(raw_joint_->GetUpperLimit());
}
void RevoluteJoint::SetLimits(float lower, float upper)
{
KGE_ASSERT(raw_joint_ && world_);
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetLimits(math::Degree2Radian(lower), math::Degree2Radian(upper));
}
void RevoluteJoint::SetMaxMotorTorque(float torque)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetMaxMotorTorque(world_->Stage2World(torque));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetMaxMotorTorque(GetWorld()->Stage2World(torque));
}
float RevoluteJoint::GetMaxMotorTorque() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetMaxMotorTorque());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetMaxMotorTorque());
}
//
@ -538,14 +538,14 @@ namespace kiwano
void RopeJoint::SetMaxLength(float length)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetMaxLength(world_->Stage2World(length));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetMaxLength(GetWorld()->Stage2World(length));
}
float RopeJoint::GetMaxLength() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetMaxLength());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetMaxLength());
}
//
@ -615,26 +615,26 @@ namespace kiwano
float WheelJoint::GetJointTranslation() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetJointTranslation());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetJointTranslation());
}
float WheelJoint::GetJointLinearSpeed() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetJointLinearSpeed());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetJointLinearSpeed());
}
void WheelJoint::SetMaxMotorTorque(float torque)
{
KGE_ASSERT(raw_joint_ && world_);
raw_joint_->SetMaxMotorTorque(world_->Stage2World(torque));
KGE_ASSERT(raw_joint_ && GetWorld());
raw_joint_->SetMaxMotorTorque(GetWorld()->Stage2World(torque));
}
float WheelJoint::GetMaxMotorTorque() const
{
KGE_ASSERT(raw_joint_ && world_);
return world_->World2Stage(raw_joint_->GetMaxMotorTorque());
KGE_ASSERT(raw_joint_ && GetWorld());
return GetWorld()->World2Stage(raw_joint_->GetMaxMotorTorque());
}
//

View File

@ -86,7 +86,7 @@ namespace kiwano
World* GetWorld() { return world_; }
const World* GetWorld() const { return world_; }
protected:
private:
b2Joint* joint_;
World* world_;
Type type_;
@ -147,7 +147,7 @@ namespace kiwano
void SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
float GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
protected:
private:
b2DistanceJoint* raw_joint_;
};
@ -199,7 +199,7 @@ namespace kiwano
void SetMaxTorque(float torque);
float GetMaxTorque() const;
protected:
private:
b2FrictionJoint* raw_joint_;
};
@ -243,7 +243,7 @@ namespace kiwano
void SetRatio(float ratio);
float GetRatio() const;
protected:
private:
b2GearJoint* raw_joint_;
};
@ -295,7 +295,7 @@ namespace kiwano
void SetMaxTorque(float torque);
float GetMaxTorque() const;
protected:
private:
b2MotorJoint* raw_joint_;
};
@ -381,7 +381,7 @@ namespace kiwano
void SetMaxMotorForce(float force) { KGE_ASSERT(raw_joint_); raw_joint_->SetMaxMotorForce(force); }
float GetMaxMotorForce() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetMaxMotorForce(); }
protected:
private:
b2PrismaticJoint* raw_joint_;
};
@ -444,7 +444,7 @@ namespace kiwano
float GetCurrentLengthA() const;
float GetCurrentLengthB() const;
protected:
private:
b2PulleyJoint* raw_joint_;
};
@ -526,7 +526,7 @@ namespace kiwano
void SetMaxMotorTorque(float torque);
float GetMaxMotorTorque() const;
protected:
private:
b2RevoluteJoint* raw_joint_;
};
@ -573,7 +573,7 @@ namespace kiwano
void SetMaxLength(float length);
float GetMaxLength() const;
protected:
private:
b2RopeJoint* raw_joint_;
};
@ -625,7 +625,7 @@ namespace kiwano
void SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
float GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
protected:
private:
b2WeldJoint* raw_joint_;
};
@ -707,7 +707,7 @@ namespace kiwano
void SetSpringDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetSpringDampingRatio(ratio); }
float GetSpringDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetSpringDampingRatio(); }
protected:
private:
b2WheelJoint* raw_joint_;
};
@ -768,7 +768,7 @@ namespace kiwano
void SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
float GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
protected:
private:
b2MouseJoint* raw_joint_;
};
}

View File

@ -40,7 +40,7 @@ namespace kiwano
virtual void FitWorld(World* world) {}
protected:
private:
b2Shape* shape_;
};
@ -57,7 +57,7 @@ namespace kiwano
void FitWorld(World* world) override;
protected:
private:
float radius_;
Point offset_;
b2CircleShape circle_;
@ -76,7 +76,7 @@ namespace kiwano
void FitWorld(World* world) override;
protected:
private:
float rotation_;
Vec2 box_size_;
Point offset_;
@ -96,7 +96,7 @@ namespace kiwano
void FitWorld(World* world) override;
protected:
private:
Vector<Point> vertexs_;
b2PolygonShape polygon_;
};
@ -114,7 +114,7 @@ namespace kiwano
void FitWorld(World* world) override;
protected:
private:
Point p_[2];
b2EdgeShape edge_;
};
@ -132,7 +132,7 @@ namespace kiwano
void FitWorld(World* world) override;
protected:
private:
bool loop_;
Vector<Point> vertexs_;
b2ChainShape chain_;

View File

@ -19,7 +19,10 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/core/common.h>
#include <kiwano/core/time.h>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/math/math.h>
#include <kiwano/2d/Transform.h>
#include <kiwano/2d/action/ActionManager.h>
#include <kiwano/core/TimerManager.h>
@ -27,10 +30,27 @@
namespace kiwano
{
class Stage;
class Director;
class RenderTarget;
// 角色
KGE_DECLARE_SMART_PTR(Actor);
/**
* \~chinese
* \defgroup Actors
*/
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
* @details
*/
class KGE_API Actor
: public ObjectBase
, public TimerManager
@ -48,330 +68,330 @@ namespace kiwano
Actor();
// 更新角色
/// \~chinese
/// @brief 更新角色
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
/// @param dt 距上一次更新的时间间隔
virtual void OnUpdate(Duration dt);
// 渲染角色
/// \~chinese
/// @brief 渲染角色
/// @details 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
/// @param rt 渲染目标
virtual void OnRender(RenderTarget* rt);
// 获取显示状态
/// \~chinese
/// @brief 获取显示状态
bool IsVisible() const;
// 获取响应状态
/// \~chinese
/// @brief 获取响应状态
bool IsResponsible() const;
// 是否启用级联透明度
/// \~chinese
/// @brief 是否启用级联透明度
bool IsCascadeOpacityEnabled() const;
// 获取名称的 Hash 值
/// \~chinese
/// @brief 获取名称的 Hash 值
size_t GetHashName() const;
// 获取 Z 轴顺序
/// \~chinese
/// @brief 获取 Z 轴顺序
int GetZOrder() const;
// 获取坐标
/// \~chinese
/// @brief 获取坐标
Point const& GetPosition() const;
// 获取 x 坐标
/// \~chinese
/// @brief 获取 x 坐标
float GetPositionX() const;
// 获取 y 坐标
/// \~chinese
/// @brief 获取 y 坐标
float GetPositionY() const;
// 获取缩放比例
/// \~chinese
/// @brief 获取缩放比例
Point const& GetScale() const;
// 获取横向缩放比例
/// \~chinese
/// @brief 获取横向缩放比例
float GetScaleX() const;
// 获取纵向缩放比例
/// \~chinese
/// @brief 获取纵向缩放比例
float GetScaleY() const;
// 获取错切角度
/// \~chinese
/// @brief 获取错切角度
Point const& GetSkew() const;
// 获取横向错切角度
/// \~chinese
/// @brief 获取横向错切角度
float GetSkewX() const;
// 获取纵向错切角度
/// \~chinese
/// @brief 获取纵向错切角度
float GetSkewY() const;
// 获取旋转角度
/// \~chinese
/// @brief 获取旋转角度
float GetRotation() const;
// 获取宽度
/// \~chinese
/// @brief 获取宽度
float GetWidth() const;
// 获取高度
/// \~chinese
/// @brief 获取高度
float GetHeight() const;
// 获取大小
/// \~chinese
/// @brief 获取大小
Size const& GetSize() const;
// 获取缩放后的宽度
/// \~chinese
/// @brief 获取缩放后的宽度
float GetScaledWidth() const;
// 获取缩放后的高度
/// \~chinese
/// @brief 获取缩放后的高度
float GetScaledHeight() const;
// 获取缩放后的大小
/// \~chinese
/// @brief 获取缩放后的大小
Size GetScaledSize() const;
// 获取锚点
/// \~chinese
/// @brief 获取锚点
Point const& GetAnchor() const;
// 获取 x 方向锚点
/// \~chinese
/// @brief 获取 x 方向锚点
float GetAnchorX() const;
// 获取 y 方向锚点
/// \~chinese
/// @brief 获取 y 方向锚点
float GetAnchorY() const;
// 获取透明度
/// \~chinese
/// @brief 获取透明度
float GetOpacity() const;
// 获取显示透明度
/// \~chinese
/// @brief 获取显示透明度
float GetDisplayedOpacity() const;
// 获取变换
/// \~chinese
/// @brief 获取变换
Transform GetTransform() const;
// 获取父角色
/// \~chinese
/// @brief 获取父角色
Actor* GetParent() const;
// 获取所在舞台
/// \~chinese
/// @brief 获取所在舞台
Stage* GetStage() const;
// 获取边框
/// \~chinese
/// @brief 获取边框
virtual Rect GetBounds() const;
// 获取外切包围盒
/// \~chinese
/// @brief 获取外切包围盒
virtual Rect GetBoundingBox() const;
// 获取二维变换矩阵
/// \~chinese
/// @brief 获取二维变换矩阵
Matrix3x2 const& GetTransformMatrix() const;
// 获取二维变换的逆矩阵
/// \~chinese
/// @brief 获取二维变换的逆矩阵
Matrix3x2 const& GetTransformInverseMatrix() const;
// 设置是否显示
void SetVisible(
bool val
);
/// \~chinese
/// @brief 设置角色是否可见
void SetVisible(bool val);
// 设置名称
void SetName(
String const& name
);
/// \~chinese
/// @brief 设置名称
void SetName(String const& name);
// 设置坐标
virtual void SetPosition(
Point const& point
);
/// \~chinese
/// @brief 设置坐标
virtual void SetPosition(Point const& point);
// 设置坐标
void SetPosition(
float x,
float y
);
/// \~chinese
/// @brief 设置坐标
void SetPosition(float x, float y);
// 设置横坐标
void SetPositionX(
float x
);
/// \~chinese
/// @brief 设置横坐标
void SetPositionX(float x);
// 设置纵坐标
void SetPositionY(
float y
);
/// \~chinese
/// @brief 设置纵坐标
void SetPositionY(float y);
// 移动坐标
void Move(
Vec2 const& v
);
/// \~chinese
/// @brief 移动坐标
void Move(Vec2 const& v);
// 移动坐标
void Move(
float vx,
float vy
);
/// \~chinese
/// @brief 移动坐标
void Move(float vx, float vy);
// 设置缩放比例
// 默认为 (1.0, 1.0)
virtual void SetScale(
Vec2 const& scale
);
/// \~chinese
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
virtual void SetScale(Vec2 const& scale);
// 设置缩放比例
// 默认为 (1.0, 1.0)
void SetScale(
float scalex,
float scaley
);
/// \~chinese
/// @brief 设置缩放比例,默认为 (1.0, 1.0)
void SetScale(float scalex, float scaley);
// 设置错切角度
// 默认为 (0, 0)
virtual void SetSkew(
Vec2 const& skew
);
/// \~chinese
/// @brief 设置错切角度,默认为 (0, 0)
virtual void SetSkew(Vec2 const& skew);
// 设置错切角度
// 默认为 (0, 0)
void SetSkew(
float skewx,
float skewy
);
/// \~chinese
/// @brief 设置错切角度,默认为 (0, 0)
void SetSkew(float skewx, float skewy);
// 设置旋转角度
// 默认为 0
virtual void SetRotation(
float rotation
);
/// \~chinese
/// @brief 设置旋转角度,默认为 0
virtual void SetRotation(float rotation);
// 设置锚点位置
// 默认为 (0, 0), 范围 [0, 1]
virtual void SetAnchor(
Vec2 const& anchor
);
/// \~chinese
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
virtual void SetAnchor(Vec2 const& anchor);
// 设置锚点位置
// 默认为 (0, 0), 范围 [0, 1]
void SetAnchor(
float anchorx,
float anchory
);
/// \~chinese
/// @brief 设置锚点位置,默认为 (0, 0), 范围 [0, 1]
void SetAnchor(float anchorx, float anchory);
// 修改宽度
virtual void SetWidth(
float width
);
/// \~chinese
/// @brief 修改宽度
virtual void SetWidth(float width);
// 修改高度
virtual void SetHeight(
float height
);
/// \~chinese
/// @brief 修改高度
virtual void SetHeight(float height);
// 修改大小
virtual void SetSize(
Size const& size
);
/// \~chinese
/// @brief 修改大小
virtual void SetSize(Size const& size);
// 修改大小
void SetSize(
float width,
float height
);
/// \~chinese
/// @brief 修改大小
void SetSize(float width, float height);
// 设置透明度
// 默认为 1.0, 范围 [0, 1]
virtual void SetOpacity(
float opacity
);
/// \~chinese
/// @brief 设置透明度,默认为 1.0, 范围 [0, 1]
virtual void SetOpacity(float opacity);
// 启用或禁用级联透明度
void SetCascadeOpacityEnabled(
bool enabled
);
/// \~chinese
/// @brief 启用或禁用级联透明度
void SetCascadeOpacityEnabled(bool enabled);
// 设置二维仿射变换
void SetTransform(
Transform const& transform
);
/// \~chinese
/// @brief 设置二维仿射变换
void SetTransform(Transform const& transform);
// 设置 Z 轴顺序
// 默认为 0
void SetZOrder(
int zorder
);
/// \~chinese
/// @brief 设置 Z 轴顺序,默认为 0
void SetZOrder(int zorder);
// 是否可响应 (鼠标 Hover | Out | Click 消息)
// 默认为 false
void SetResponsible(
bool enable
);
/// \~chinese
/// @brief 设置角色是否可响应,默认为 false
/// @details 可响应的角色会收到鼠标的 Hover | Out | Click 消息
void SetResponsible(bool enable);
// 添加子角色
void AddChild(
ActorPtr child,
int zorder = 0
);
/// \~chinese
/// @brief 添加子角色
void AddChild(ActorPtr child, int zorder = 0);
// 添加子角色
void AddChild(
Actor* child,
int zorder = 0
);
/// \~chinese
/// @brief 添加子角色
void AddChild(Actor* child, int zorder = 0);
// 添加多个子角色
void AddChildren(
Vector<ActorPtr> const& children
);
/// \~chinese
/// @brief 添加多个子角色
void AddChildren(Vector<ActorPtr> const& children);
// 获取名称相同的子角色
Actor* GetChild(
String const& name
) const;
/// \~chinese
/// @brief 获取名称相同的子角色
Actor* GetChild(String const& name) const;
// 获取所有名称相同的子角色
Vector<ActorPtr> GetChildren(
String const& name
) const;
/// \~chinese
/// @brief 获取所有名称相同的子角色
Vector<ActorPtr> GetChildren(String const& name) const;
// 获取全部子角色
/// \~chinese
/// @brief 获取全部子角色
Children& GetAllChildren();
// 获取全部子角色
/// \~chinese
/// @brief 获取全部子角色
Children const& GetAllChildren() const;
// 移除子角色
void RemoveChild(
ActorPtr child
);
/// \~chinese
/// @brief 移除子角色
void RemoveChild(ActorPtr child);
// 移除子角色
void RemoveChild(
Actor* child
);
/// \~chinese
/// @brief 移除子角色
void RemoveChild(Actor* child);
// 移除所有名称相同的子角色
void RemoveChildren(
String const& child_name
);
/// \~chinese
/// @brief 移除所有名称相同的子角色
void RemoveChildren(String const& child_name);
// 移除所有角色
/// \~chinese
/// @brief 移除所有角色
void RemoveAllChildren();
// 从父角色移除
/// \~chinese
/// @brief 从父角色移除
void RemoveFromParent();
// 判断点是否在角色内
/// \~chinese
/// @brief 判断点是否在角色内
virtual bool ContainsPoint(const Point& point) const;
// 暂停角色更新
/// \~chinese
/// @brief 暂停角色更新
void PauseUpdating();
// 继续角色更新
/// \~chinese
/// @brief 继续角色更新
void ResumeUpdating();
// 角色更新是否暂停
/// \~chinese
/// @brief 角色更新是否暂停
bool IsUpdatePausing() const;
// 设置更新时的回调函数
/// \~chinese
/// @brief 设置更新时的回调函数
void SetCallbackOnUpdate(UpdateCallback const& cb);
// 获取更新时的回调函数
/// \~chinese
/// @brief 获取更新时的回调函数
UpdateCallback GetCallbackOnUpdate() const;
// 渲染角色边界
/// \~chinese
/// @brief 渲染角色边界
void ShowBorder(bool show);
// 事件分发
/// \~chinese
/// @brief 分发事件
void Dispatch(Event& evt) override;
// 设置默认锚点
static void SetDefaultAnchor(
float anchor_x,
float anchor_y
);
/// \~chinese
/// @brief 设置默认锚点
static void SetDefaultAnchor(float anchor_x, float anchor_y);
protected:
virtual void Update(Duration dt);
@ -421,6 +441,9 @@ namespace kiwano
mutable Matrix3x2 transform_matrix_inverse_;
};
/** @} */
inline void Actor::OnUpdate(Duration dt)
{
KGE_NOT_USED(dt);

View File

@ -254,13 +254,17 @@ namespace kiwano
}
}
void Canvas::DrawText(String const& text, Point const& point)
void Canvas::DrawTextLayout(String const& text, Point const& point)
{
if (text.empty())
return;
TextLayout layout(text, text_font_, text_style_);
DrawTextLayout(layout, point);
}
void Canvas::DrawTextLayout(TextLayout const& layout, Point const& point)
{
rt_.DrawTextLayout(layout, point);
}
@ -289,7 +293,7 @@ namespace kiwano
geo_sink_.AddBezier(point1, point2, point3);
}
void Canvas::AddArc(Point const & point, Point const & radius, float rotation, bool clockwise, bool is_small)
void Canvas::AddArc(Point const & point, Size const & radius, float rotation, bool clockwise, bool is_small)
{
geo_sink_.AddArc(point, radius, rotation, clockwise, is_small);
}

View File

@ -22,224 +22,251 @@
#include <kiwano/2d/Actor.h>
#include <kiwano/renderer/RenderTarget.h>
#ifdef DrawText
# undef DrawText
#endif
namespace kiwano
{
// 画布
KGE_DECLARE_SMART_PTR(Canvas);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Canvas
: public Actor
{
public:
/// \~chinese
/// @brief 构建空画布
Canvas();
virtual ~Canvas();
// 开始绘图
/// \~chinese
/// @brief 开始绘图
void BeginDraw();
// 结束绘图
/// \~chinese
/// @brief 结束绘图
void EndDraw();
// 画直线
void DrawLine(
Point const& begin,
Point const& end
);
/// \~chinese
/// @brief 画线段
/// @param begin 线段起点
/// @param end 线段终点
void DrawLine(Point const& begin, Point const& end);
// 画圆形边框
void DrawCircle(
Point const& center,
float radius
);
/// \~chinese
/// @brief 画圆形边框
/// @param center 圆形原点
/// @param radius 圆形半径
void DrawCircle(Point const& center, float radius);
// 画椭圆形边框
void DrawEllipse(
Point const& center,
Vec2 const& radius
);
/// \~chinese
/// @brief 画椭圆形边框
/// @param center 椭圆原点
/// @param radius 椭圆半径
void DrawEllipse(Point const& center, Vec2 const& radius);
// 画矩形边框
void DrawRect(
Rect const& rect
);
/// \~chinese
/// @brief 画矩形边框
/// @param rect 矩形
void DrawRect(Rect const& rect);
// 画圆角矩形边框
void DrawRoundedRect(
Rect const& rect,
Vec2 const& radius
);
/// \~chinese
/// @brief 画圆角矩形边框
/// @param rect 矩形
/// @param radius 矩形圆角半径
void DrawRoundedRect(Rect const& rect, Vec2 const& radius);
// 填充圆形
void FillCircle(
Point const& center,
float radius
);
/// \~chinese
/// @brief 填充圆形
/// @param center 圆形原点
/// @param radius 圆形半径
void FillCircle(Point const& center, float radius);
// 填充椭圆形
void FillEllipse(
Point const& center,
Vec2 const& radius
);
/// \~chinese
/// @brief 填充椭圆形
/// @param center 椭圆原点
/// @param radius 椭圆半径
void FillEllipse(Point const& center, Vec2 const& radius);
// 填充矩形
void FillRect(
Rect const& rect
);
/// \~chinese
/// @brief 填充矩形
/// @param rect 矩形
void FillRect(Rect const& rect);
// 填充圆角矩形
void FillRoundedRect(
Rect const& rect,
Vec2 const& radius
);
/// \~chinese
/// @brief 填充圆角矩形
/// @param rect 矩形
/// @param radius 矩形圆角半径
void FillRoundedRect(Rect const& rect, Vec2 const& radius);
// 画图
void DrawTexture(
Texture const& texture,
const Rect* src_rect = nullptr,
const Rect* dest_rect = nullptr
);
/// \~chinese
/// @brief 绘制纹理
/// @param texture 纹理
/// @param src_rect 纹理裁剪区域
/// @param dest_rect 绘制目标区域
void DrawTexture(Texture const& texture, const Rect* src_rect = nullptr, const Rect* dest_rect = nullptr);
// 画文字
void DrawText(
String const& text, /* 文字 */
Point const& point /* 文字位置 */
);
/// \~chinese
/// @brief 绘制文字布局
/// @param text 文字
/// @param point 绘制文字的位置
void DrawTextLayout(String const& text, Point const& point);
// 开始绘制路径
void BeginPath(
Point const& begin_pos /* 路径起始点 */
);
/// \~chinese
/// @brief 绘制文字布局
/// @param layout 文字布局
/// @param point 绘制布局的位置
void DrawTextLayout(TextLayout const& layout, Point const& point);
// 结束路径
void EndPath(
bool closed = true /* 路径是否闭合 */
);
/// \~chinese
/// @brief 开始绘制路径
/// @param begin_pos 路径起始点
void BeginPath(Point const& begin_pos);
// 添加一条线段
void AddLine(
Point const& point /* 端点 */
);
/// \~chinese
/// @brief 结束路径
/// @param closed 路径是否闭合
void EndPath(bool closed = true);
// 添加多条线段
void AddLines(
Vector<Point> const& points
);
/// \~chinese
/// @brief 添加一条线段
/// @param point 端点
void AddLine(Point const& point);
// 添加一条三次方贝塞尔曲线
void AddBezier(
Point const& point1, /* 贝塞尔曲线的第一个控制点 */
Point const& point2, /* 贝塞尔曲线的第二个控制点 */
Point const& point3 /* 贝塞尔曲线的终点 */
);
/// \~chinese
/// @brief 添加多条线段
/// @param points 端点集合
void AddLines(Vector<Point> const& points);
// 添加弧线
void AddArc(
Point const& point, /* 终点 */
Point const& radius, /* 椭圆半径 */
float rotation, /* 椭圆旋转角度 */
bool clockwise = true, /* 顺时针 or 逆时针 */
bool is_small = true /* 是否取小于 180° 的弧 */
);
/// \~chinese
/// @brief 添加一条三次方贝塞尔曲线
/// @param point1 贝塞尔曲线的第一个控制点
/// @param point2 贝塞尔曲线的第二个控制点
/// @param point3 贝塞尔曲线的终点
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
// 路径描边
/// \~chinese
/// @brief 添加弧线
/// @param point 终点
/// @param radius 椭圆半径
/// @param rotation 椭圆旋转角度
/// @param clockwise 顺时针 or 逆时针
/// @param is_small 是否取小于 180° 的弧
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
/// \~chinese
/// @brief 以描边的方式绘制路径
void StrokePath();
// 路径填充
/// \~chinese
/// @brief 以填充的方式绘制路径
void FillPath();
// 清空画布
/// \~chinese
/// @brief 清空画布
void Clear();
// 清空画布
void Clear(
Color const& clear_color
);
/// \~chinese
/// @brief 清空画布
/// @param clear_color 清空颜色
void Clear(Color const& clear_color);
// 设置填充颜色
void SetFillColor(
Color const& color
);
/// \~chinese
/// @brief 设置填充颜色
/// @param color 填充颜色
void SetFillColor(Color const& color);
// 设置轮廓颜色
void SetStrokeColor(
Color const& color
);
/// \~chinese
/// @brief 设置轮廓颜色
/// @param color 轮廓颜色
void SetStrokeColor(Color const& color);
// 设置轮廓宽度
void SetStrokeWidth(
float width
);
/// \~chinese
/// @brief 设置轮廓宽度
/// @param width 轮廓宽度
void SetStrokeWidth(float width);
// 设置轮廓样式
void SetStrokeStyle(
StrokeStyle stroke_style
);
/// \~chinese
/// @brief 设置轮廓样式
/// @param stroke_style 轮廓样式
void SetStrokeStyle(StrokeStyle stroke_style);
// 设置文字字体
void SetTextFont(
Font const& font
);
/// \~chinese
/// @brief 设置文字字体
/// @param font 文字字体
void SetTextFont(Font const& font);
// 设置文字画刷样式
void SetTextStyle(
TextStyle const& text_style
);
/// \~chinese
/// @brief 设置文字画刷样式
/// @param text_style 文字画刷样式
void SetTextStyle(TextStyle const& text_style);
// 设置画笔透明度
void SetBrushOpacity(
float opacity
);
/// \~chinese
/// @brief 设置画笔透明度
/// @param opacity 透明度,范围 [0.0 - 1.0]
void SetBrushOpacity(float opacity);
// 画笔二维变换
void SetBrushTransform(
Transform const& transform
);
/// \~chinese
/// @brief 设置画笔二维变换
/// @param transform 二维变换
void SetBrushTransform(Transform const& transform);
// 画笔二维变换
void SetBrushTransform(
Matrix3x2 const& transform
);
/// \~chinese
/// @brief 设置画笔二维变换矩阵
/// @param transform 二维变换矩阵
void SetBrushTransform(Matrix3x2 const& transform);
// 设置图层
void PushLayerArea(
LayerArea& area
);
/// \~chinese
/// @brief 添加一个图层
/// @param area 图层区域
void PushLayerArea(LayerArea& area);
// 弹出图层
/// \~chinese
/// @brief 删除最近添加的图层
void PopLayerArea();
// 设置裁剪区域
void PushClipRect(
Rect const& clip_rect
);
/// \~chinese
/// @brief 添加一个裁剪区域
/// @param clip_rect 裁剪矩形
void PushClipRect(Rect const& clip_rect);
// 弹出裁剪区域
/// \~chinese
/// @brief 删除最近添加的裁剪区域
void PopClipRect();
// 获取填充颜色
/// \~chinese
/// @brief 获取填充颜色
Color GetFillColor() const;
// 获取轮廓颜色
/// \~chinese
/// @brief 获取轮廓颜色
Color GetStrokeColor() const;
// 获取轮廓宽度
/// \~chinese
/// @brief 获取轮廓宽度
float GetStrokeWidth() const;
// 获取画笔透明度
/// \~chinese
/// @brief 获取画笔透明度
float GetBrushOpacity() const;
// 导出为图片
/// \~chinese
/// @brief 导出纹理
Texture ExportToTexture() const;
void OnRender(RenderTarget* rt) override;
protected:
private:
void UpdateCache() const;
protected:
private:
float stroke_width_;
Color fill_color_;
Color stroke_color_;
@ -252,4 +279,7 @@ namespace kiwano
mutable Texture texture_cached_;
mutable TextureRenderTarget rt_;
};
/** @} */
}

View File

@ -19,7 +19,6 @@
// THE SOFTWARE.
#include <kiwano/2d/DebugActor.h>
#include <kiwano/2d/Text.h>
#include <kiwano/renderer/Renderer.h>
#include <psapi.h>
@ -31,7 +30,7 @@ namespace kiwano
{
class comma_numpunct : public std::numpunct<wchar_t>
{
protected:
private:
virtual wchar_t do_thousands_sep() const override
{
return L',';
@ -42,6 +41,8 @@ namespace kiwano
return "\03";
}
};
std::locale comma_locale(std::locale(), new comma_numpunct);
}
DebugActor::DebugActor()
@ -52,7 +53,7 @@ namespace kiwano
SetResponsible(true);
SetCascadeOpacityEnabled(true);
debug_text_ = new Text;
debug_text_ = new TextActor;
debug_text_->SetPosition(Point{ 10, 10 });
this->AddChild(debug_text_);
@ -94,11 +95,8 @@ namespace kiwano
StringStream ss;
{
// For formatting integers with commas
static std::locale comma_locale(std::locale(), new comma_numpunct);
(void)ss.imbue(comma_locale);
}
// For formatting integers with commas
(void)ss.imbue(comma_locale);
ss << "Fps: " << frame_time_.size() << std::endl;

View File

@ -20,9 +20,20 @@
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/TextActor.h>
#include <kiwano/renderer/Color.h>
namespace kiwano
{
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API DebugActor
: public Actor
{
@ -35,9 +46,12 @@ namespace kiwano
void OnUpdate(Duration dt) override;
protected:
Color background_color_;
TextPtr debug_text_;
private:
Color background_color_;
TextActorPtr debug_text_;
Vector<Time> frame_time_;
};
/** @} */
}

View File

@ -24,63 +24,103 @@
namespace kiwano
{
// 帧图像
KGE_DECLARE_SMART_PTR(Frame);
/**
* \~chinese
* @brief
*/
class KGE_API Frame
: public ObjectBase
{
public:
/// \~chinese
/// @brief 构建空图像帧
Frame();
/// \~chinese
/// @brief 构建图像帧
/// @param file_path 图像路径
explicit Frame(
String const& file_path
);
/// \~chinese
/// @brief 构建图像帧
/// @param res 图像资源
explicit Frame(
Resource const& res
);
/// \~chinese
/// @brief 构建图像帧
/// @param texture 纹理
explicit Frame(
Texture const& texture
);
/// \~chinese
/// @brief 加载图像
/// @param file_path 图像路径
bool Load(
String const& file_path
);
/// \~chinese
/// @brief 加载图像
/// @param res 图像资源
bool Load(
Resource const& res
);
// 裁剪矩形
/// \~chinese
/// @brief 裁剪图像帧为矩形
/// @param crop_rect 裁剪矩形定义
void SetCropRect(
Rect const& crop_rect /* 裁剪矩形 */
Rect const& crop_rect
);
// 设置纹理
/// \~chinese
/// @brief 设置纹理
/// @param texture 纹理
void SetTexture(
Texture const& texture
);
// 获取宽度
float GetWidth() const { return crop_rect_.GetWidth(); }
/// \~chinese
/// @brief 获取宽度
float GetWidth() const;
// 获取高度
float GetHeight() const { return crop_rect_.GetHeight(); }
/// \~chinese
/// @brief 获取高度
float GetHeight() const;
// 获取大小
Size GetSize() const { return crop_rect_.GetSize(); }
/// \~chinese
/// @brief 获取大小
Size GetSize() const;
// 获取裁剪位置
Point GetCropPoint() const { return crop_rect_.GetLeftTop(); }
/// \~chinese
/// @brief 获取裁剪位置
Point GetCropPoint() const;
// 获取裁剪矩形
inline Rect const& GetCropRect() const { return crop_rect_; }
/// \~chinese
/// @brief 获取裁剪矩形
Rect const& GetCropRect() const;
// 获取纹理
inline Texture const& GetTexture() const { return texture_; }
/// \~chinese
/// @brief 获取纹理
Texture const& GetTexture() const;
protected:
private:
Texture texture_;
Rect crop_rect_;
};
inline float Frame::GetWidth() const { return crop_rect_.GetWidth(); }
inline float Frame::GetHeight() const { return crop_rect_.GetHeight(); }
inline Size Frame::GetSize() const { return crop_rect_.GetSize(); }
inline Point Frame::GetCropPoint() const { return crop_rect_.GetLeftTop(); }
inline Rect const& Frame::GetCropRect() const { return crop_rect_; }
inline Texture const& Frame::GetTexture() const { return texture_; }
}

View File

@ -19,7 +19,6 @@
// THE SOFTWARE.
#include <kiwano/2d/FrameSequence.h>
#include <kiwano/2d/Frame.h>
#include <kiwano/core/Logger.h>
namespace kiwano

View File

@ -19,46 +19,61 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/core/common.h>
#include <kiwano/core/time.h>
#include <kiwano/2d/Frame.h>
namespace kiwano
{
// 序列帧
KGE_DECLARE_SMART_PTR(FrameSequence);
/**
* \~chinese
* @brief
*/
class KGE_API FrameSequence
: public ObjectBase
{
public:
/// \~chinese
/// @brief 构建空序列帧
FrameSequence();
explicit FrameSequence(
Vector<FramePtr> const& frames /* 帧序列 */
);
/// \~chinese
/// @brief 构建序列帧
/// @param frames 图像帧集合
explicit FrameSequence(Vector<FramePtr> const& frames);
virtual ~FrameSequence();
// 添加关键帧
void AddFrame(
FramePtr frame
);
/// \~chinese
/// @brief 添加关键帧
/// @param frame 图像帧
void AddFrame(FramePtr frame);
// 添加多个关键帧
void AddFrames(
Vector<FramePtr> const& frames
);
/// \~chinese
/// @brief 添加多个关键帧
/// @param frames 图像帧集合
void AddFrames(Vector<FramePtr> const& frames);
// 获取关键帧
/// \~chinese
/// @brief 获取关键帧
/// @param index 图像帧下标
FramePtr GetFrame(size_t index) const;
// 获取关键帧
/// \~chinese
/// @brief 获取所有关键帧
Vector<FramePtr> const& GetFrames() const;
// 获取帧动画的拷贝对象
/// \~chinese
/// @brief 获取序列帧的拷贝对象
FrameSequencePtr Clone() const;
// 获取帧动画的倒转
/// \~chinese
/// @brief 获取序列帧的倒转
FrameSequencePtr Reverse() const;
protected:
private:
Vector<FramePtr> frames_;
};
}

View File

@ -26,83 +26,131 @@
namespace kiwano
{
// GIF 精灵
KGE_DECLARE_SMART_PTR(GifSprite);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief GIF
*/
class KGE_API GifSprite
: public Actor
{
public:
/// \~chinese
/// @brief GIF播放循环结束回调
using LoopDoneCallback = Function<void(int)>;
/// \~chinese
/// @brief GIF播放结束回调
using DoneCallback = Function<void()>;
GifSprite();
GifSprite(
String const& file_path
);
/// \~chinese
/// @brief 构造GIF精灵
/// @param file_path GIF图片路径
GifSprite(String const& file_path);
GifSprite(
Resource const& res
);
/// \~chinese
/// @brief 构造GIF精灵
/// @param res GIF图片资源
GifSprite(Resource const& res);
GifSprite(
GifImage gif
);
/// \~chinese
/// @brief 构造GIF精灵
/// @param gif GIF图片
GifSprite(GifImage gif);
bool Load(
String const& file_path
);
/// \~chinese
/// @brief 加载GIF图片
/// @param file_path GIF图片路径
bool Load(String const& file_path);
bool Load(
Resource const& res
);
/// \~chinese
/// @brief 加载GIF图片
/// @param res GIF图片资源
bool Load(Resource const& res);
bool Load(
GifImage gif
);
/// \~chinese
/// @brief 加载GIF图片
/// @param gif GIF图片
bool Load(GifImage gif);
// 设置 GIF 动画循环次数
inline void SetLoopCount(int loops) { total_loop_count_ = loops; }
/// \~chinese
/// @brief 设置 GIF 动画循环次数
void SetLoopCount(int loops);
// 设置 GIF 动画每次循环结束回调函数
inline void SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; }
/// \~chinese
/// @brief 设置 GIF 动画每次循环结束回调函数
void SetLoopDoneCallback(LoopDoneCallback const& cb);
// 设置 GIF 动画结束回调函数
inline void SetDoneCallback(DoneCallback const& cb) { done_cb_ = cb; }
/// \~chinese
/// @brief 设置 GIF 动画结束回调函数
void SetDoneCallback(DoneCallback const& cb);
// 设置 GIF 图像
/// \~chinese
/// @brief 设置 GIF 图像
void SetGifImage(GifImage const& gif);
// 重新播放动画
/// \~chinese
/// @brief 重新播放 GIF 动画
void RestartAnimation();
inline LoopDoneCallback GetLoopDoneCallback() const { return loop_cb_; }
/// \~chinese
/// @brief 获取 GIF 动画循环结束回调
LoopDoneCallback GetLoopDoneCallback() const;
inline DoneCallback GetDoneCallback() const { return done_cb_; }
/// \~chinese
/// @brief 获取 GIF 动画播放结束回调
DoneCallback GetDoneCallback() const;
inline GifImage const& GetGifImage() const { return gif_; }
/// \~chinese
/// @brief 获取 GIF 图片
GifImage const& GetGifImage() const;
void OnRender(RenderTarget* rt) override;
protected:
private:
void Update(Duration dt) override;
inline bool IsLastFrame() const { return (next_index_ == 0); }
/// \~chinese
/// @brief 是否是最后一帧
bool IsLastFrame() const;
inline bool EndOfAnimation() const { return IsLastFrame() && loop_count_ == total_loop_count_ + 1; }
/// \~chinese
/// @brief 动画是否已结束
bool EndOfAnimation() const;
/// \~chinese
/// @brief 合成下一帧
void ComposeNextFrame();
/// \~chinese
/// @brief 解析当前图像帧
void DisposeCurrentFrame();
/// \~chinese
/// @brief 覆盖下一帧
void OverlayNextFrame();
/// \~chinese
/// @brief 保存合成后的图像帧
void SaveComposedFrame();
/// \~chinese
/// @brief 恢复已保存的图像帧
void RestoreSavedFrame();
/// \~chinese
/// @brief 清空当前图像区域
void ClearCurrentFrameArea();
protected:
private:
bool animating_;
int total_loop_count_;
int loop_count_;
@ -115,4 +163,22 @@ namespace kiwano
Texture saved_frame_;
TextureRenderTarget frame_rt_;
};
/** @} */
inline void GifSprite::SetLoopCount(int loops) { total_loop_count_ = loops; }
inline void GifSprite::SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; }
inline void GifSprite::SetDoneCallback(DoneCallback const& cb) { done_cb_ = cb; }
inline GifSprite::LoopDoneCallback GifSprite::GetLoopDoneCallback() const { return loop_cb_; }
inline GifSprite::DoneCallback GifSprite::GetDoneCallback() const { return done_cb_; }
inline GifImage const& GifSprite::GetGifImage() const { return gif_; }
inline bool GifSprite::IsLastFrame() const { return (next_index_ == 0); }
inline bool GifSprite::EndOfAnimation() const { return IsLastFrame() && loop_count_ == total_loop_count_ + 1; }
}

View File

@ -20,11 +20,22 @@
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/..\renderer\LayerArea.h>
#include <kiwano/2d/..\renderer\RenderTarget.h>
#include <kiwano/renderer/LayerArea.h>
#include <kiwano/renderer/RenderTarget.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(Layer);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Layer
: public Actor
{
@ -33,40 +44,80 @@ namespace kiwano
virtual ~Layer();
// 重载下列函数以获取图层事件
virtual void OnMouseButtonDown(MouseButton::Value btn, Point const& p) {}
virtual void OnMouseButtonUp(MouseButton::Value btn, Point const& p) {}
virtual void OnMouseMoved(Point const& p) {}
virtual void OnMouseWheel(float wheel) {}
virtual void OnKeyDown(int key) {}
virtual void OnKeyUp(int key) {}
virtual void OnChar(char c) {}
/// \~chinese
/// @brief 是否开启消息吞没
bool IsSwallowEventsEnabled() const;
// 是否开启消息吞没
inline bool IsSwallowEventsEnabled() const { return swallow_; }
/// \~chinese
/// @brief 设置消息吞没功能
/// @param enabled 是否启用
void SetSwallowEvents(bool enabled);
// 吞没消息
inline void SetSwallowEvents(bool enabled) { swallow_ = enabled; }
// 设置裁剪区域
/// \~chinese
/// @brief 设置裁剪区域
/// @param clip_rect 裁剪矩形
void SetClipRect(Rect const& clip_rect);
// 设置图层透明度
/// \~chinese
/// @brief 设置图层透明度
/// @param opacity 透明度
void SetOpacity(float opacity) override;
// 设置几何蒙层
/// \~chinese
/// @brief 设置几何蒙层
/// @param mask 蒙层的几何形状
void SetMaskGeometry(Geometry const& mask);
// 设置几何蒙层的二维变换
/// \~chinese
/// @brief 设置几何蒙层的二维变换
/// @param transform 应用于蒙层的二维变换
void SetMaskTransform(Matrix3x2 const& transform);
// 设置图层区域
inline void SetArea(LayerArea const& area) { area_ = area; }
/// \~chinese
/// @brief 设置图层区域
/// @param area 图层区域属性
void SetArea(LayerArea const& area);
// 获取图层区域
inline LayerArea const& GetArea() const { return area_; }
/// \~chinese
/// @brief 获取图层区域
LayerArea const& GetArea() const;
/// \~chinese
/// @brief 重载该函数以处理鼠标按下消息
/// @param btn 鼠标按键键值
/// @param pos 鼠标位置
virtual void OnMouseButtonDown(MouseButton::Value btn, Point const& pos) {}
/// \~chinese
/// @brief 重载该函数以处理鼠标抬起消息
/// @param btn 鼠标按键键值
/// @param pos 鼠标位置
virtual void OnMouseButtonUp(MouseButton::Value btn, Point const& pos) {}
/// \~chinese
/// @brief 重载该函数以处理鼠标移动消息
/// @param pos 鼠标位置
virtual void OnMouseMoved(Point const& pos) {}
/// \~chinese
/// @brief 重载该函数以处理鼠标滚轮消息
virtual void OnMouseWheel(float wheel) {}
/// \~chinese
/// @brief 重载该函数以处理键盘按键按下消息
/// @param key 键盘按键键值
virtual void OnKeyDown(KeyCode::Value key) {}
/// \~chinese
/// @brief 重载该函数以处理键盘按键抬起消息
/// @param key 键盘按键键值
virtual void OnKeyUp(KeyCode::Value key) {}
/// \~chinese
/// @brief 重载该函数以处理键盘字符消息
/// @param c 字符
virtual void OnChar(char c) {}
public:
void Dispatch(Event& evt) override;
protected:
@ -74,8 +125,19 @@ namespace kiwano
void HandleMessages(Event& evt);
protected:
private:
bool swallow_;
LayerArea area_;
};
/** @} */
inline bool Layer::IsSwallowEventsEnabled() const { return swallow_; }
inline void Layer::SetSwallowEvents(bool enabled) { swallow_ = enabled; }
inline void Layer::SetArea(LayerArea const& area) { area_ = area; }
inline LayerArea const& Layer::GetArea() const { return area_; }
}

View File

@ -345,7 +345,7 @@ namespace kiwano
void PathActor::ClearPath()
{
geo_.SetGeometry(nullptr);
SetGeometry(Geometry());
}
}

View File

@ -25,61 +25,89 @@
namespace kiwano
{
// 二维图形角色
KGE_DECLARE_SMART_PTR(ShapeActor);
KGE_DECLARE_SMART_PTR(LineActor);
KGE_DECLARE_SMART_PTR(RectActor);
KGE_DECLARE_SMART_PTR(RoundRectActor);
KGE_DECLARE_SMART_PTR(CircleActor);
KGE_DECLARE_SMART_PTR(EllipseActor);
KGE_DECLARE_SMART_PTR(PolygonActor);
KGE_DECLARE_SMART_PTR(PathActor);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API ShapeActor
: public Actor
{
public:
ShapeActor();
ShapeActor(
Geometry const& geometry
);
ShapeActor(Geometry const& geometry);
virtual ~ShapeActor();
// 获取填充颜色
inline Color GetFillColor() const { return fill_color_; }
/// \~chinese
/// @brief 获取填充颜色
Color GetFillColor() const;
// 获取线条颜色
inline Color GetStrokeColor() const { return stroke_color_; }
/// \~chinese
/// @brief 获取线条颜色
Color GetStrokeColor() const;
// 获取线条宽度
inline float GetStrokeWidth() const { return stroke_width_; }
/// \~chinese
/// @brief 获取线条宽度
float GetStrokeWidth() const;
// 获取线条样式
inline StrokeStyle SetStrokeStyle() const { return stroke_style_; }
/// \~chinese
/// @brief 获取线条样式
StrokeStyle SetStrokeStyle() const;
// 获取形状
inline Geometry GetGeometry() const { return geo_; }
/// \~chinese
/// @brief 获取形状
Geometry GetGeometry() const;
// 获取边界
/// \~chinese
/// @brief 获取边界
Rect GetBounds() const override;
// 获取外切包围盒
/// \~chinese
/// @brief 获取外切包围盒
Rect GetBoundingBox() const override;
// 判断点是否在形状内
/// \~chinese
/// @brief 判断点是否在形状内
bool ContainsPoint(const Point& point) const override;
// 设置填充颜色
/// \~chinese
/// @brief 设置填充颜色
void SetFillColor(const Color& color);
// 设置线条颜色
/// \~chinese
/// @brief 设置线条颜色
void SetStrokeColor(const Color& color);
// 设置线条宽度
/// \~chinese
/// @brief 设置线条宽度,默认为 1.0
void SetStrokeWidth(float width);
// 设置线条样式
/// \~chinese
/// @brief 设置线条样式
void SetStrokeStyle(StrokeStyle stroke_style);
// 设置形状
/// \~chinese
/// @brief 设置几何形状
void SetGeometry(Geometry const& geometry);
void OnRender(RenderTarget* rt) override;
protected:
private:
Color fill_color_;
Color stroke_color_;
float stroke_width_;
@ -89,170 +117,210 @@ namespace kiwano
};
// 直线角色
/// \~chinese
/// @brief 线段图形角色
class KGE_API LineActor
: public ShapeActor
{
public:
LineActor();
LineActor(
Point const& begin,
Point const& end
);
/// \~chinese
/// @brief 线段图形角色
/// @param begin 线段起点
/// @param end 线段终点
LineActor(Point const& begin, Point const& end);
virtual ~LineActor();
inline Point const& GetBeginPoint() const { return begin_; }
inline Point const& GetEndPoint() const { return end_; }
/// \~chinese
/// @brief 获取线段起点
Point const& GetBeginPoint() const;
inline void SetBeginPoint(Point const& begin)
{
SetLine(begin, end_);
}
/// \~chinese
/// @brief 获取线段终点
Point const& GetEndPoint() const;
inline void SetEndPoint(Point const& end)
{
SetLine(begin_, end);
}
/// \~chinese
/// @brief 设置线段起点
/// @param begin 线段起点
void SetBeginPoint(Point const& begin);
void SetLine(
Point const& begin,
Point const& end
);
/// \~chinese
/// @brief 设置线段终点
/// @param end 线段终点
void SetEndPoint(Point const& end);
protected:
/// \~chinese
/// @brief 设置矩形大小
/// @param begin 线段起点
/// @param end 线段终点
void SetLine(Point const& begin, Point const& end);
private:
Point begin_;
Point end_;
};
// 矩形角色
/// \~chinese
/// @brief 矩形角色
class KGE_API RectActor
: public ShapeActor
{
public:
RectActor();
RectActor(
Size const& size
);
/// \~chinese
/// @brief 构造矩形角色
/// @param size 矩形大小
RectActor(Size const& size);
virtual ~RectActor();
inline Size const& GetRectSize() const { return rect_size_; }
/// \~chinese
/// @brief 获取矩形大小
Size const& GetRectSize() const;
/// \~chinese
/// @brief 设置矩形大小
/// @param size 矩形大小
void SetRectSize(Size const& size);
protected:
private:
Size rect_size_;
};
// 圆角矩形角色
/// \~chinese
/// @brief 圆角矩形角色
class KGE_API RoundRectActor
: public ShapeActor
{
public:
RoundRectActor();
RoundRectActor(
Size const& size,
Vec2 const& radius
);
/// \~chinese
/// @brief 构造圆角矩形角色
/// @param size 圆角矩形大小
/// @param radius 圆角半径
RoundRectActor(Size const& size, Vec2 const& radius);
virtual ~RoundRectActor();
inline Vec2 GetRadius() const { return radius_; }
/// \~chinese
/// @brief 获取圆角半径
Vec2 GetRadius() const;
inline Size GetRectSize() const { return GetSize(); }
/// \~chinese
/// @brief 获取圆角矩形大小
Size GetRectSize() const;
void SetRadius(
Vec2 const& radius
);
/// \~chinese
/// @brief 设置圆角半径
/// @param radius 圆角半径
void SetRadius(Vec2 const& radius);
void SetRectSize(
Size const& size
);
/// \~chinese
/// @brief 设置圆角矩形大小
/// @param size 圆角矩形大小
void SetRectSize(Size const& size);
void SetRoundedRect(
Size const& size,
Vec2 const& radius
);
/// \~chinese
/// @brief 设置圆角矩形
/// @param size 圆角矩形大小
/// @param radius 圆角半径
void SetRoundedRect(Size const& size, Vec2 const& radius);
protected:
private:
Size rect_size_;
Vec2 radius_;
};
// 圆形角色
/// \~chinese
/// @brief 圆形角色
class KGE_API CircleActor
: public ShapeActor
{
public:
CircleActor();
CircleActor(
float radius
);
/// \~chinese
/// @brief 构造圆形角色
/// @param radius 圆形半径
CircleActor(float radius);
virtual ~CircleActor();
inline float GetRadius() const { return radius_; }
/// \~chinese
/// @brief 获取圆形半径
float GetRadius() const;
/// \~chinese
/// @brief 设置圆形半径
/// @param radius 圆形半径
void SetRadius(float radius);
protected:
private:
float radius_;
};
// 椭圆角色
/// \~chinese
/// @brief 椭圆角色
class KGE_API EllipseActor
: public ShapeActor
{
public:
EllipseActor();
EllipseActor(
Vec2 const& radius
);
/// \~chinese
/// @brief 构造椭圆角色
/// @param radius 椭圆半径
EllipseActor(Vec2 const& radius);
virtual ~EllipseActor();
Vec2 GetRadius() const { return radius_; }
/// \~chinese
/// @brief 获取椭圆半径
Vec2 GetRadius() const;
void SetRadius(
Vec2 const& radius
);
/// \~chinese
/// @brief 设置椭圆半径
/// @param radius 椭圆半径
void SetRadius(Vec2 const& radius);
protected:
private:
Vec2 radius_;
};
// 多边形角色
/// \~chinese
/// @brief 多边形角色
class KGE_API PolygonActor
: public ShapeActor
{
public:
PolygonActor();
PolygonActor(
Vector<Point> const& points
);
/// \~chinese
/// @brief 构造多边形角色
/// @param points 多边形端点集合
PolygonActor(Vector<Point> const& points);
virtual ~PolygonActor();
void SetVertices(
Vector<Point> const& points
);
/// \~chinese
/// @brief 设置多边形端点
/// @param points 多边形端点集合
void SetVertices(Vector<Point> const& points);
};
// 路径角色
/// \~chinese
/// @brief 路径图形角色
class KGE_API PathActor
: public ShapeActor
{
@ -261,47 +329,70 @@ namespace kiwano
virtual ~PathActor();
// 开始添加路径
void BeginPath(
Point const& begin_pos = Point{} /* 起始点 */
);
/// \~chinese
/// @brief 开始添加路径
/// @param begin_pos 起始点
void BeginPath(Point const& begin_pos = Point());
// 结束路径
void EndPath(
bool closed = true /* 路径是否闭合 */
);
/// \~chinese
/// @brief 结束添加路径
/// @param closed 路径是否闭合
void EndPath(bool closed = true);
// 添加一条线段
void AddLine(
Point const& point /* 端点 */
);
/// \~chinese
/// @brief 添加一条线段
/// @param point 线段端点
void AddLine(Point const& point);
// 添加多条线段
void AddLines(
Vector<Point> const& points
);
/// \~chinese
/// @brief 添加多条线段
/// @param points 线段端点集合
void AddLines(Vector<Point> const& points);
// 添加一条三次方贝塞尔曲线
void AddBezier(
Point const& point1, /* 贝塞尔曲线的第一个控制点 */
Point const& point2, /* 贝塞尔曲线的第二个控制点 */
Point const& point3 /* 贝塞尔曲线的终点 */
);
/// \~chinese
/// @brief 添加一条三次方贝塞尔曲线
/// @param point1 贝塞尔曲线的第一个控制点
/// @param point2 贝塞尔曲线的第二个控制点
/// @param point3 贝塞尔曲线的终点
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
// 添加弧线
void AddArc(
Point const& point, /* 终点 */
Size const& radius, /* 椭圆半径 */
float rotation, /* 椭圆旋转角度 */
bool clockwise = true, /* 顺时针 or 逆时针 */
bool is_small = true /* 是否取小于 180° 的弧 */
);
/// \~chinese
/// @brief 添加弧线
/// @param point 椭圆圆心
/// @param radius 椭圆半径
/// @param rotation 椭圆旋转角度
/// @param clockwise 顺时针 or 逆时针
/// @param is_small 是否取小于 180° 的弧
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
// 清除路径
/// \~chinese
/// @brief 清除路径
void ClearPath();
protected:
private:
GeometrySink sink_;
};
/** @} */
inline Color ShapeActor::GetFillColor() const { return fill_color_; }
inline Color ShapeActor::GetStrokeColor() const { return stroke_color_; }
inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; }
inline StrokeStyle ShapeActor::SetStrokeStyle() const { return stroke_style_; }
inline Geometry ShapeActor::GetGeometry() const { return geo_; }
inline Point const& LineActor::GetBeginPoint() const { return begin_; }
inline Point const& LineActor::GetEndPoint() const { return end_; }
inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); }
inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); }
inline Size const& RectActor::GetRectSize() const { return rect_size_; }
inline Vec2 RoundRectActor::GetRadius() const { return radius_; }
inline Size RoundRectActor::GetRectSize() const { return GetSize(); }
inline float CircleActor::GetRadius() const { return radius_; }
inline Vec2 EllipseActor::GetRadius() const { return radius_; }
}

View File

@ -24,62 +24,84 @@
namespace kiwano
{
// ¾«Áé
KGE_DECLARE_SMART_PTR(Sprite);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Sprite
: public Actor
{
public:
Sprite();
explicit Sprite(
String const& file_path
);
/// \~chinese
/// @brief 从本地图片构造精灵
/// @param file_path 本地图片路径
explicit Sprite(String const& file_path);
Sprite(
String const& file_path,
Rect const& crop_rect /* ²Ã¼ô¾ØÐÎ */
);
/// \~chinese
/// @brief 从图片资源构造精灵
/// @param res 图片资源
explicit Sprite(Resource const& res);
explicit Sprite(
Resource const& res
);
/// \~chinese
/// @brief 从图像帧构造精灵
/// @param[in] frame 图像帧
explicit Sprite(FramePtr frame);
Sprite(
Resource const& res,
Rect const& crop_rect /* ²Ã¼ô¾ØÐÎ */
);
/// \~chinese
/// @brief 从本地图片构造精灵并裁剪
/// @param file_path 本地图片路径
/// @param crop_rect 裁剪矩形
Sprite(String const& file_path, Rect const& crop_rect);
explicit Sprite(
FramePtr frame
);
/// \~chinese
/// @brief 从图片资源构造精灵并裁剪
/// @param res 图片资源
/// @param crop_rect 裁剪矩形
Sprite(Resource const& res, Rect const& crop_rect);
virtual ~Sprite();
// ¼ÓÔØÍ¼Ïñ
bool Load(
String const& file_path
);
/// \~chinese
/// @brief 加载本地图片
/// @param file_path 本地图片路径
bool Load(String const& file_path);
// ¼ÓÔØÍ¼Ïñ×ÊÔ´
bool Load(
Resource const& res
);
/// \~chinese
/// @brief 加载图像资源
/// @param res 图片资源
bool Load(Resource const& res);
// ²Ã¼ô¾ØÐÎ
void SetCropRect(
const Rect& crop_rect
);
/// \~chinese
/// @brief 使用矩形区域裁剪精灵
/// @param crop_rect 裁剪矩形
void SetCropRect(const Rect& crop_rect);
// »ñȡ֡ͼÏñ
inline FramePtr GetFrame() const { return frame_; }
/// \~chinese
/// @brief 获取帧图像
FramePtr GetFrame() const;
// ÉèÖÃ֡ͼÏñ
/// \~chinese
/// @brief 设置图像帧
/// @param[in] frame 图像帧
void SetFrame(FramePtr frame);
// äÖȾ¾«Áé
void OnRender(RenderTarget* rt) override;
protected:
private:
FramePtr frame_;
};
/** @} */
inline FramePtr Sprite::GetFrame() const { return frame_; }
}

View File

@ -23,7 +23,19 @@
namespace kiwano
{
// 舞台
KGE_DECLARE_SMART_PTR(Stage);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
* @details
* @see kiwano::Actor kiwano::Director
*/
class KGE_API Stage
: public Actor
{
@ -35,10 +47,17 @@ namespace kiwano
virtual ~Stage();
// 进入舞台
/// \~chinese
/// @brief 进入舞台时
/// @details 重载该函数以处理进入舞台前的行为
virtual void OnEnter();
// 退出舞台
/// \~chinese
/// @brief 退出舞台时
/// @details 重载该函数以处理退出舞台前的行为
virtual void OnExit();
};
/** @} */
}

View File

@ -1,175 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/renderer/TextLayout.h>
namespace kiwano
{
// 文本
class KGE_API Text
: public Actor
{
public:
Text();
explicit Text(
String const& text /* 文字内容 */
);
Text(
String const& text, /* 文字内容 */
const Font& font /* 字体 */
);
Text(
String const& text, /* 文字内容 */
const TextStyle& style /* 文本样式 */
);
Text(
String const& text, /* 文字内容 */
const Font& font, /* 字体 */
const TextStyle& style /* 文本样式 */
);
virtual ~Text();
// 获取文本
inline String const& GetText() const { return text_; }
// 获取字体
inline Font GetFont() const { return font_; }
// 获取文本样式
inline TextStyle GetStyle() const { return text_layout_.GetTextStyle(); }
// 获取文本布局
inline TextLayout GetLayout() const { return text_layout_; }
// 设置文本
void SetText(
String const& text
);
// 设置文本样式
void SetStyle(
const TextStyle& style
);
// 设置字体
void SetFont(
const Font& font
);
// 设置字体族
void SetFontFamily(
String const& family
);
// 设置字号(默认值为 18
void SetFontSize(
float size
);
// 设置字体粗细值(默认值为 FontWeight::Normal
void SetFontWeight(
uint32_t weight
);
// 设置文字颜色(默认值为 Color::White
void SetColor(
Color const& color
);
// 设置文字斜体(默认值为 false
void SetItalic(
bool italic
);
// 设置文本自动换行的宽度(默认为 0
void SetWrapWidth(
float wrap_width
);
// 设置行间距(默认为 0
void SetLineSpacing(
float line_spacing
);
// 设置对齐方式(默认为 TextAlign::Left
void SetAlignment(
TextAlign align
);
// 设置下划线(默认值为 false
void SetUnderline(
bool underline
);
// 设置删除线(默认值为 false
void SetStrikethrough(
bool strikethrough
);
// 设置是否显示描边
void SetOutline(
bool outline
);
// 设置描边颜色
void SetOutlineColor(
Color const& outline_color
);
// 设置描边线宽
void SetOutlineWidth(
float outline_width
);
// 设置描边线相交样式
void SetOutlineStroke(
StrokeStyle outline_stroke
);
// 更新文本布局
void UpdateLayout();
// 设置默认字体
static void SetDefaultFont(
Font const& font
);
// 设置默认文字样式
static void SetDefaultStyle(
TextStyle const& style
);
void OnRender(RenderTarget* rt) override;
protected:
bool format_dirty_;
bool layout_dirty_;
TextLayout text_layout_;
String text_;
Font font_;
};
}

View File

@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <kiwano/2d/Text.h>
#include <kiwano/2d/TextActor.h>
#include <kiwano/core/Logger.h>
#include <kiwano/renderer/Renderer.h>
@ -30,17 +30,17 @@ namespace kiwano
TextStyle text_default_style;
}
void kiwano::Text::SetDefaultFont(Font const & font)
void kiwano::TextActor::SetDefaultFont(Font const & font)
{
text_default_font = font;
}
void kiwano::Text::SetDefaultStyle(TextStyle const & style)
void kiwano::TextActor::SetDefaultStyle(TextStyle const & style)
{
text_default_style = style;
}
Text::Text()
TextActor::TextActor()
: font_(text_default_font)
, layout_dirty_(false)
, format_dirty_(false)
@ -48,22 +48,22 @@ namespace kiwano
text_layout_.SetTextStyle(text_default_style);
}
Text::Text(String const& text)
: Text(text, text_default_font, text_default_style)
TextActor::TextActor(String const& text)
: TextActor(text, text_default_font, text_default_style)
{
}
Text::Text(String const& text, const Font & font)
: Text(text, font, text_default_style)
TextActor::TextActor(String const& text, const Font & font)
: TextActor(text, font, text_default_style)
{
}
Text::Text(String const& text, const TextStyle & style)
: Text(text, text_default_font, style)
TextActor::TextActor(String const& text, const TextStyle & style)
: TextActor(text, text_default_font, style)
{
}
Text::Text(String const& text, const Font & font, const TextStyle & style)
TextActor::TextActor(String const& text, const Font & font, const TextStyle & style)
: font_(font)
, text_(text)
, layout_dirty_(true)
@ -72,29 +72,29 @@ namespace kiwano
text_layout_.SetTextStyle(style);
}
Text::~Text()
TextActor::~TextActor()
{
}
void Text::SetText(String const& text)
void TextActor::SetText(String const& text)
{
text_ = text;
layout_dirty_ = true;
}
void Text::SetStyle(const TextStyle& style)
void TextActor::SetStyle(const TextStyle& style)
{
text_layout_.SetTextStyle(style);
layout_dirty_ = true;
}
void Text::SetFont(const Font & font)
void TextActor::SetFont(const Font & font)
{
font_ = font;
format_dirty_ = true;
}
void Text::SetFontFamily(String const& family)
void TextActor::SetFontFamily(String const& family)
{
if (font_.family != family)
{
@ -103,7 +103,7 @@ namespace kiwano
}
}
void Text::SetFontSize(float size)
void TextActor::SetFontSize(float size)
{
if (font_.size != size)
{
@ -112,7 +112,7 @@ namespace kiwano
}
}
void Text::SetFontWeight(uint32_t weight)
void TextActor::SetFontWeight(uint32_t weight)
{
if (font_.weight != weight)
{
@ -121,7 +121,7 @@ namespace kiwano
}
}
void Text::SetItalic(bool italic)
void TextActor::SetItalic(bool italic)
{
if (font_.italic != italic)
{
@ -130,7 +130,7 @@ namespace kiwano
}
}
void Text::SetWrapWidth(float wrap_width)
void TextActor::SetWrapWidth(float wrap_width)
{
if (text_layout_.GetTextStyle().wrap_width != wrap_width)
{
@ -139,7 +139,7 @@ namespace kiwano
}
}
void Text::SetLineSpacing(float line_spacing)
void TextActor::SetLineSpacing(float line_spacing)
{
if (text_layout_.GetTextStyle().line_spacing != line_spacing)
{
@ -148,7 +148,7 @@ namespace kiwano
}
}
void Text::SetAlignment(TextAlign align)
void TextActor::SetAlignment(TextAlign align)
{
if (text_layout_.GetTextStyle().alignment != align)
{
@ -157,7 +157,7 @@ namespace kiwano
}
}
void Text::SetUnderline(bool underline)
void TextActor::SetUnderline(bool underline)
{
if (text_layout_.GetTextStyle().underline != underline)
{
@ -166,7 +166,7 @@ namespace kiwano
}
}
void Text::SetStrikethrough(bool strikethrough)
void TextActor::SetStrikethrough(bool strikethrough)
{
if (text_layout_.GetTextStyle().strikethrough != strikethrough)
{
@ -175,33 +175,33 @@ namespace kiwano
}
}
void Text::SetColor(Color const& color)
void TextActor::SetColor(Color const& color)
{
text_layout_.GetTextStyle().color = color;
text_layout_.GetTextStyle().color = color;
}
void Text::SetOutline(bool outline)
void TextActor::SetOutline(bool outline)
{
text_layout_.GetTextStyle().outline = outline;
}
void Text::SetOutlineColor(Color const&outline_color)
void TextActor::SetOutlineColor(Color const&outline_color)
{
text_layout_.GetTextStyle().outline_color = outline_color;
}
void Text::SetOutlineWidth(float outline_width)
void TextActor::SetOutlineWidth(float outline_width)
{
text_layout_.GetTextStyle().outline_width = outline_width;
}
void Text::SetOutlineStroke(StrokeStyle outline_stroke)
void TextActor::SetOutlineStroke(StrokeStyle outline_stroke)
{
text_layout_.GetTextStyle().outline_stroke = outline_stroke;
}
void Text::OnRender(RenderTarget* rt)
void TextActor::OnRender(RenderTarget* rt)
{
UpdateLayout();
@ -212,7 +212,7 @@ namespace kiwano
}
}
void Text::UpdateLayout()
void TextActor::UpdateLayout()
{
if (format_dirty_)
{

191
src/kiwano/2d/TextActor.h Normal file
View File

@ -0,0 +1,191 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/Actor.h>
#include <kiwano/renderer/Color.h>
#include <kiwano/renderer/TextLayout.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(TextActor);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API TextActor
: public Actor
{
public:
/// \~chinese
/// @brief 构建空的文本角色
TextActor();
/// \~chinese
/// @brief 构建空的文本角色
/// @param text 文字内容
explicit TextActor(const String& text);
/// \~chinese
/// @brief 构建空的文本角色
/// @param text 文字内容
/// @param font 字体
TextActor(const String& text, const Font& font);
/// \~chinese
/// @brief 构建空的文本角色
/// @param text 文字内容
/// @param style 文本样式
TextActor(const String& text, const TextStyle& style);
/// \~chinese
/// @brief 构建空的文本角色
/// @param text 文字内容
/// @param font 字体
/// @param style 文本样式
TextActor(const String& text, const Font& font, const TextStyle& style);
virtual ~TextActor();
/// \~chinese
/// @brief 获取文本
String const& GetText() const;
/// \~chinese
/// @brief 获取字体
Font GetFont() const;
/// \~chinese
/// @brief 获取文本样式
TextStyle GetStyle() const;
/// \~chinese
/// @brief 获取文本布局
TextLayout GetLayout() const;
/// \~chinese
/// @brief 设置文本
void SetText(String const& text);
/// \~chinese
/// @brief 设置文本样式
void SetStyle(const TextStyle& style);
/// \~chinese
/// @brief 设置字体
void SetFont(const Font& font);
/// \~chinese
/// @brief 设置字体族
void SetFontFamily(String const& family);
/// \~chinese
/// @brief 设置字号(默认值为 18
void SetFontSize(
float size
);
/// \~chinese
/// @brief 设置字体粗细值(默认值为 FontWeight::Normal
void SetFontWeight(uint32_t weight);
/// \~chinese
/// @brief 设置文字颜色(默认值为 Color::White
void SetColor(Color const& color);
/// \~chinese
/// @brief 设置文字斜体(默认值为 false
void SetItalic(bool italic);
/// \~chinese
/// @brief 设置文本自动换行的宽度(默认为 0
void SetWrapWidth(float wrap_width);
/// \~chinese
/// @brief 设置行间距(默认为 0
void SetLineSpacing(float line_spacing);
/// \~chinese
/// @brief 设置对齐方式(默认为 TextAlign::Left
void SetAlignment(TextAlign align);
/// \~chinese
/// @brief 设置下划线(默认值为 false
void SetUnderline(bool underline);
/// \~chinese
/// @brief 设置删除线(默认值为 false
void SetStrikethrough(bool strikethrough);
/// \~chinese
/// @brief 设置是否显示描边
void SetOutline(bool outline);
/// \~chinese
/// @brief 设置描边颜色
void SetOutlineColor(Color const& outline_color);
/// \~chinese
/// @brief 设置描边线宽
void SetOutlineWidth(float outline_width);
/// \~chinese
/// @brief 设置描边线相交样式
void SetOutlineStroke(StrokeStyle outline_stroke);
/// \~chinese
/// @brief 更新文本布局
void UpdateLayout();
/// \~chinese
/// @brief 设置默认字体
static void SetDefaultFont(Font const& font);
/// \~chinese
/// @brief 设置默认文字样式
static void SetDefaultStyle(TextStyle const& style);
void OnRender(RenderTarget* rt) override;
private:
bool format_dirty_;
bool layout_dirty_;
TextLayout text_layout_;
String text_;
Font font_;
};
/** @} */
inline String const& TextActor::GetText() const { return text_; }
inline Font TextActor::GetFont() const { return font_; }
inline TextStyle TextActor::GetStyle() const { return text_layout_.GetTextStyle(); }
inline TextLayout TextActor::GetLayout() const { return text_layout_; }
}

View File

@ -19,45 +19,65 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/renderer/Color.h>
#include <kiwano/renderer/StrokeStyle.h>
namespace kiwano
{
// 文本对齐方式
/**
* \~chinese
* @brief
*/
enum class TextAlign
{
Left, /* 左对齐 */
Right, /* 右对齐 */
Center /* 居中对齐 */
Left, ///< 左对齐
Right, ///< 右对齐
Center ///< 居中对齐
};
// 文本样式
/**
* \~chinese
* @brief
*/
class KGE_API TextStyle
{
public:
Color color; // 颜色
TextAlign alignment; // 对齐方式
float wrap_width; // 自动换行宽度
float line_spacing; // 行间距
bool underline; // 下划线
bool strikethrough; // 删除线
bool outline; // 显示描边
Color outline_color; // 描边颜色
float outline_width; // 描边线宽
StrokeStyle outline_stroke; // 描边线相交样式
Color color; ///< 颜色
TextAlign alignment; ///< 对齐方式
float wrap_width; ///< 自动换行宽度
float line_spacing; ///< 行间距
bool underline; ///< 下划线
bool strikethrough; ///< 删除线
bool outline; ///< 描边
Color outline_color; ///< 描边颜色
float outline_width; ///< 描边线宽
StrokeStyle outline_stroke; ///< 描边线相交样式
public:
/**
* \~chinese
* @brief
* @param color
* @param alignment
* @param wrap_width
* @param line_spacing
* @param underline 线
* @param strikethrough 线
* @param outline
* @param outline_color
* @param outline_width 线
* @param outline_stroke 线
*/
TextStyle(
Color color = Color::White,
TextAlign alignment = TextAlign::Left,
float wrap_width = 0.f,
float line_spacing = 0.f,
float line_spacing = 0.f,
bool underline = false,
bool strikethrough = false,
bool outline = false,
Color outline_color = Color(Color::Black, 0.5),
float outline_width = 1.f,
float outline_width = 1.f,
StrokeStyle outline_stroke = StrokeStyle::Round
)
: color(color)

View File

@ -23,17 +23,23 @@
namespace kiwano
{
/**
* \~chinese
* @brief
*/
class Transform
{
public:
float rotation; // Ðýת
Point position; // ×ø±ê
Point scale; // Ëõ·Å
Point skew; // ´íÇнǶÈ
float rotation; ///< 旋转
Point position; ///< 坐标
Point scale; ///< 缩放
Point skew; ///< 错切角度
public:
Transform();
/// \~chinese
/// @brief 将二维放射变换转换为矩阵
Matrix3x2 ToMatrix() const;
bool operator== (const Transform& rhs) const;

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/renderer/LayerArea.h>
namespace kiwano
@ -27,34 +27,77 @@ namespace kiwano
class Director;
class RenderTarget;
// 舞台过渡
KGE_DECLARE_SMART_PTR(Transition);
KGE_DECLARE_SMART_PTR(FadeTransition);
KGE_DECLARE_SMART_PTR(EmergeTransition);
KGE_DECLARE_SMART_PTR(BoxTransition);
KGE_DECLARE_SMART_PTR(MoveTransition);
KGE_DECLARE_SMART_PTR(RotationTransition);
/**
* \~chinese
* @brief
*/
class KGE_API Transition
: public ObjectBase
{
friend class Director;
public:
/**
* \~chinese
* @brief
* @param duration
*/
explicit Transition(
Duration duration
);
virtual ~Transition();
/**
* \~chinese
* @brief
*/
bool IsDone();
protected:
/**
* \~chinese
* @brief
* @param[in] prev
* @param[in] next
*/
virtual void Init(
StagePtr prev,
StagePtr next
);
/**
* \~chinese
* @brief
* @param dt
*/
virtual void Update(Duration dt);
/**
* \~chinese
* @brief
* @param[in] rt
*/
virtual void Render(RenderTarget* rt);
/**
* \~chinese
* @brief
*/
virtual void Stop();
virtual void Reset() { };
/**
* \~chinese
* @brief
*/
virtual void Reset() {}
protected:
bool done_;
@ -69,17 +112,25 @@ namespace kiwano
};
// 淡入淡出过渡
/**
* \~chinese
* @brief
* @details
*/
class FadeTransition
: public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
explicit FadeTransition(
Duration duration /* 动画持续时长 */
Duration duration
);
protected:
// 更新动画
void Update(Duration dt) override;
virtual void Init(
@ -89,13 +140,22 @@ namespace kiwano
};
// 渐变过渡
/**
* \~chinese
* @brief
* @details
*/
class EmergeTransition
: public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
explicit EmergeTransition(
Duration duration /* 动画持续时长 */
Duration duration
);
protected:
@ -108,13 +168,22 @@ namespace kiwano
};
// 盒状过渡
/**
* \~chinese
* @brief
* @details
*/
class BoxTransition
: public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
*/
explicit BoxTransition(
Duration duration /* 动画持续时长 */
Duration duration
);
protected:
@ -127,22 +196,36 @@ namespace kiwano
};
// 位移过渡
/**
* \~chinese
* @brief
* @details
*/
class MoveTransition
: public Transition
{
public:
/**
* \~chinese
* @brief
*/
enum class Type : int
{
Up, /* 上移 */
Down, /* 下移 */
Left, /* 左移 */
Right /* 右移 */
Up, ///< 上移
Down, ///< 下移
Left, ///< 左移
Right ///< 右移
};
/**
* \~chinese
* @brief
* @param duration
* @param type
*/
explicit MoveTransition(
Duration duration, /* 动画持续时长 */
Type type /* 移动方式 */
Duration duration,
Type type
);
protected:
@ -155,21 +238,31 @@ namespace kiwano
void Reset() override;
protected:
private:
Type type_;
Point pos_delta_;
Point start_pos_;
};
// 旋转过渡
/**
* \~chinese
* @brief
* @details
*/
class RotationTransition
: public Transition
{
public:
/**
* \~chinese
* @brief
* @param duration
* @param rotation
*/
explicit RotationTransition(
Duration duration, /* 动画持续时长 */
float rotation = 360 /* 旋转度数 */
Duration duration,
float rotation = 360
);
protected:
@ -182,7 +275,7 @@ namespace kiwano
void Reset() override;
protected:
private:
float rotation_;
};
}

View File

@ -36,16 +36,16 @@ namespace kiwano
{
}
void Action::Init(ActorPtr target)
void Action::Init(Actor* target)
{
}
void Action::Update(ActorPtr target, Duration dt)
void Action::Update(Actor* target, Duration dt)
{
Complete(target);
}
void Action::UpdateStep(ActorPtr target, Duration dt)
void Action::UpdateStep(Actor* target, Duration dt)
{
elapsed_ += dt;
@ -81,7 +81,7 @@ namespace kiwano
}
}
void Action::Complete(ActorPtr target)
void Action::Complete(Actor* target)
{
if (cb_loop_done_)
cb_loop_done_();
@ -99,7 +99,7 @@ namespace kiwano
++loops_done_;
}
void Action::Restart(ActorPtr target)
void Action::Restart(Actor* target)
{
status_ = Status::NotStarted;
elapsed_ = 0;

View File

@ -19,14 +19,31 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/core/common.h>
#include <kiwano/core/time.h>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/math/math.h>
namespace kiwano
{
using ActionCallback = Function<void()>;
class Actor;
class ActionManager;
KGE_DECLARE_SMART_PTR(Action);
/**
* \~chinese
* \defgroup Actions
*/
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 动画
class KGE_API Action
: public ObjectBase
, protected IntrusiveListItem<ActionPtr>
@ -36,80 +53,129 @@ namespace kiwano
friend IntrusiveList<ActionPtr>;
public:
/// \~chinese
/// @brief 动画结束时的回调函数
using DoneCallback = Function<void()>;
Action();
virtual ~Action();
// 继续动作
/// \~chinese
/// @brief 继续动画
void Resume();
// 暂停动作
/// \~chinese
/// @brief 暂停动画
void Pause();
// 停止动作
/// \~chinese
/// @brief 停止动画
void Stop();
// 设置动作延时
/// \~chinese
/// @brief 设置动画延时
void SetDelay(Duration delay);
// 设置循环次数 (-1 为永久循环)
/// \~chinese
/// @brief 设置循环次数
/// @param loops 循环次数,-1 为永久循环
void SetLoops(int loops);
// 动作结束时移除目标角色
/// \~chinese
/// @brief 动画结束时移除目标角色
void RemoveTargetWhenDone();
// 设置动作结束时的回调函数
void SetDoneCallback(ActionCallback const& cb);
/// \~chinese
/// @brief 设置动画结束时的回调函数
void SetDoneCallback(DoneCallback const& cb);
// 设置动作循环结束时的回调函数
void SetLoopDoneCallback(ActionCallback const& cb);
/// \~chinese
/// @brief 设置动画循环结束时的回调函数
void SetLoopDoneCallback(DoneCallback const& cb);
// 获取动作的拷贝
/// \~chinese
/// @brief 获取动画的拷贝
virtual ActionPtr Clone() const = 0;
// 获取动作的倒转
/// \~chinese
/// @brief 获取动画的倒转
virtual ActionPtr Reverse() const = 0;
/// \~chinese
/// @brief 获取动画的运行状态
bool IsRunning() const;
/// \~chinese
/// @brief 获取动画的循环次数
int GetLoops() const;
/// \~chinese
/// @brief 获取动画的延时
Duration GetDelay() const;
ActionCallback GetDoneCallback() const;
/// \~chinese
/// @brief 获取动画结束时的回调函数
DoneCallback GetDoneCallback() const;
ActionCallback GetLoopDoneCallback() const;
/// \~chinese
/// @brief 获取动画循环结束时的回调函数
DoneCallback GetLoopDoneCallback() const;
protected:
virtual void Init(ActorPtr target);
/// \~chinese
/// @brief 初始化动画
virtual void Init(Actor* target);
virtual void Update(ActorPtr target, Duration dt);
/// \~chinese
/// @brief 更新动画
virtual void Update(Actor* target, Duration dt);
void UpdateStep(ActorPtr target, Duration dt);
/// \~chinese
/// @brief 更新一个时间步
void UpdateStep(Actor* target, Duration dt);
void Complete(ActorPtr target);
/// \~chinese
/// @brief 完成动画
void Complete(Actor* target);
void Restart(ActorPtr target);
/// \~chinese
/// @brief 重新开始动画
void Restart(Actor* target);
/// \~chinese
/// @brief 动画状态
enum class Status
{
NotStarted,
Delayed,
Started,
Done,
Removeable
NotStarted, ///< 未开始
Delayed, ///< 等待延时
Started, ///< 已开始
Done, ///< 已结束
Removeable ///< 可移除
};
/// \~chinese
/// @brief 获取动画状态
Status GetStatus() const;
/// \~chinese
/// @brief 获取消逝时间
Duration GetElapsed() const;
/// \~chinese
/// @brief 获取完成的循环次数
int GetLoopsDone() const;
/// \~chinese
/// @brief 结束动画
void Done();
/// \~chinese
/// @brief 是否已结束
bool IsDone() const;
/// \~chinese
/// @brief 是否可移除
bool IsRemoveable() const;
private:
@ -120,10 +186,12 @@ namespace kiwano
int loops_done_;
Duration delay_;
Duration elapsed_;
ActionCallback cb_done_;
ActionCallback cb_loop_done_;
DoneCallback cb_done_;
DoneCallback cb_loop_done_;
};
/** @} */
inline void Action::Resume()
{
@ -155,12 +223,12 @@ namespace kiwano
detach_target_ = true;
}
inline void Action::SetDoneCallback(ActionCallback const& cb)
inline void Action::SetDoneCallback(DoneCallback const& cb)
{
cb_done_ = cb;
}
inline void Action::SetLoopDoneCallback(ActionCallback const& cb)
inline void Action::SetLoopDoneCallback(DoneCallback const& cb)
{
cb_loop_done_ = cb;
}
@ -210,12 +278,12 @@ namespace kiwano
return loops_done_;
}
inline ActionCallback Action::GetDoneCallback() const
inline Action::DoneCallback Action::GetDoneCallback() const
{
return cb_done_;
}
inline ActionCallback Action::GetLoopDoneCallback() const
inline Action::DoneCallback Action::GetLoopDoneCallback() const
{
return cb_loop_done_;
}

View File

@ -23,19 +23,32 @@
namespace kiwano
{
// 延时动作
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 延时动画
class KGE_API ActionDelay
: public Action
{
public:
/// \~chinese
/// @brief 构建延时动画
/// @param delay 延时时长
ActionDelay(
Duration delay /* 持续时长 */
Duration delay
);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
};
/** @} */
}

View File

@ -43,7 +43,7 @@ namespace kiwano
{
}
void ActionGroup::Init(ActorPtr target)
void ActionGroup::Init(Actor* target)
{
if (actions_.empty())
{
@ -64,7 +64,7 @@ namespace kiwano
}
}
void ActionGroup::Update(ActorPtr target, Duration dt)
void ActionGroup::Update(Actor* target, Duration dt)
{
if (sequence_)
{

View File

@ -23,7 +23,15 @@
namespace kiwano
{
// 动作组
KGE_DECLARE_SMART_PTR(ActionGroup);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 动画组合
class KGE_API ActionGroup
: public Action
{
@ -32,78 +40,49 @@ namespace kiwano
ActionGroup();
explicit ActionGroup(
Vector<ActionPtr> const& actions,
bool sequence = true // 按顺序执行或同时执行
);
/// \~chinese
/// @brief 动画组合
/// @param actions 动画集合
/// @param sequence 动画按顺序依次执行或同时执行
explicit ActionGroup(Vector<ActionPtr> const& actions, bool sequence = true);
virtual ~ActionGroup();
// 添加动作
void Add(
ActionPtr action
);
/// \~chinese
/// @brief 添加动画
/// @param action 动画
void Add(ActionPtr action);
// 添加多个动作
void Add(
Vector<ActionPtr> const& actions
);
/// \~chinese
/// @brief 添加多个动画
/// @param actions 动画集合
void Add(Vector<ActionPtr> const& actions);
// 获取所有动作
inline ActionList const& GetActions() { return actions_; }
/// \~chinese
/// @brief 获取所有动画
ActionList const& GetActions() const;
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
// 初始化动作
void Init(ActorPtr target) override;
void Init(Actor* target) override;
// 更新动作
void Update(ActorPtr target, Duration dt) override;
void Update(Actor* target, Duration dt) override;
protected:
private:
bool sequence_;
ActionPtr current_;
ActionList actions_;
};
/** @} */
#pragma warning(push)
#pragma warning(disable : 4996)
// 顺序动作
class KGE_API ActionSequence
: public ActionGroup
{
public:
KGE_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead")
inline ActionSequence() : ActionGroup() {}
KGE_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead")
inline explicit ActionSequence(Vector<ActionPtr> const& actions) : ActionGroup(actions, true) {}
virtual ~ActionSequence() {}
};
// 同步动作
class KGE_API ActionSpawn
: public ActionGroup
{
public:
KGE_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead")
inline ActionSpawn() : ActionGroup() { sequence_ = false; }
KGE_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead")
inline explicit ActionSpawn(Vector<ActionPtr> const& actions) : ActionGroup(actions, false) {}
virtual ~ActionSpawn() {}
};
#pragma warning(pop)
inline ActionGroup::ActionList const& ActionGroup::GetActions() const { return actions_; }
}

View File

@ -27,64 +27,93 @@
namespace kiwano
{
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 动画辅助类
struct ActionHelper
{
// 设置循环次数
using DoneCallback = Action::DoneCallback;
/// \~chinese
/// @brief 设置循环次数
inline ActionHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); }
// 设置动作延迟
/// \~chinese
/// @brief 设置动画延迟
inline ActionHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); }
// 设置动作结束回调函数
inline ActionHelper& SetDoneCallback(ActionCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
/// \~chinese
/// @brief 设置动画结束回调函数
inline ActionHelper& SetDoneCallback(DoneCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
// 设置动作循环结束时的回调函数
inline ActionHelper& SetLoopDoneCallback(ActionCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
/// \~chinese
/// @brief 设置动画循环结束时的回调函数
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
// 动作结束时移除目标角色
/// \~chinese
/// @brief 动画结束时移除目标角色
inline ActionHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); }
// 设置名称
/// \~chinese
/// @brief 设置名称
inline ActionHelper& SetName(String const& name) { core->SetName(name); return (*this); }
// 获取指针
/// \~chinese
/// @brief 获取指针
inline ActionPtr Get() const { return core; }
inline ActionHelper(ActionPtr core) : core(core) {}
inline operator ActionPtr() const { return core; }
protected:
private:
ActionPtr core;
};
/// \~chinese
/// @brief 补间动画辅助类
struct TweenHelper
{
// 设置动画持续时长
using DoneCallback = Action::DoneCallback;
/// \~chinese
/// @brief 设置动画持续时长
inline TweenHelper& SetDuration(Duration dur) { core->SetDuration(dur); return (*this); }
// 设置循环次数
inline TweenHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); }
/// \~chinese
/// @brief 设置循环次数
inline TweenHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); }
// 设置缓动函数
/// \~chinese
/// @brief 设置缓动函数
inline TweenHelper& SetEaseFunc(EaseFunc ease) { core->SetEaseFunc(ease); return (*this); }
// 设置动作延迟
/// \~chinese
/// @brief 设置动画延迟
inline TweenHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); }
// 设置动作结束回调函数
inline TweenHelper& SetDoneCallback(ActionCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
/// \~chinese
/// @brief 设置动画结束回调函数
inline TweenHelper& SetDoneCallback(DoneCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
// 设置动作循环结束时的回调函数
inline TweenHelper& SetLoopDoneCallback(ActionCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
/// \~chinese
/// @brief 设置动画循环结束时的回调函数
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
// 动作结束时移除目标角色
/// \~chinese
/// @brief 动画结束时移除目标角色
inline TweenHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); }
// 设置名称
/// \~chinese
/// @brief 设置名称
inline TweenHelper& SetName(String const& name) { core->SetName(name); return (*this); }
// 获取指针
/// \~chinese
/// @brief 获取指针
inline ActionTweenPtr Get() const { return core; }
inline TweenHelper(ActionTweenPtr core) : core(core) {}
@ -93,188 +122,203 @@ namespace kiwano
inline operator ActionTweenPtr() const { return core; }
protected:
private:
ActionTweenPtr core;
};
// Tween actions helper
/// \~chinese
/// @brief 动画构造器
struct Tween
{
public:
/// \~chinese
/// @brief 构造相对位移动画
/// @param duration 动画时长
/// @param vector 移动向量
static inline TweenHelper
MoveBy(Duration dur, Point const& vector)
{
return TweenHelper(new kiwano::ActionMoveBy(dur, vector));
}
/// \~chinese
/// @brief 构造位移动画
/// @param duration 动画时长
/// @param pos 目的坐标
static inline TweenHelper
MoveTo(Duration dur, Point const& pos)
{
return TweenHelper(new kiwano::ActionMoveTo(dur, pos));
}
/// \~chinese
/// @brief 构造相对跳跃动画
/// @param duration 动画时长
/// @param vec 跳跃位移向量
/// @param height 跳跃高度
/// @param jumps 跳跃次数
static inline TweenHelper
JumpBy(
Duration dur,
Point const& pos, /* 目的坐标 */
float height, /* 跳跃高度 */
int jumps = 1) /* 跳跃次数 */
JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
{
return TweenHelper(new kiwano::ActionJumpBy(dur, pos, height, jumps));
return TweenHelper(new kiwano::ActionJumpBy(duration, vec, height, jumps));
}
/// \~chinese
/// @brief 构造跳跃动画
/// @param duration 动画时长
/// @param pos 目的坐标
/// @param height 跳跃高度
/// @param jumps 跳跃次数
static inline TweenHelper
JumpTo(
Duration dur,
Point const& pos, /* 目的坐标 */
float height, /* 跳跃高度 */
int jumps = 1) /* 跳跃次数 */
JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
{
return TweenHelper(new kiwano::ActionJumpTo(dur, pos, height, jumps));
}
static inline TweenHelper
ScaleBy(Duration dur, float scale)
{
return TweenHelper(new kiwano::ActionScaleBy(dur, scale));
return TweenHelper(new kiwano::ActionJumpTo(duration, pos, height, jumps));
}
/// \~chinese
/// @brief 构造相对缩放动画
/// @param duration 动画时长
/// @param scale_x 横向缩放相对变化值
/// @param scale_y 纵向缩放相对变化值
static inline TweenHelper
ScaleBy(Duration dur, float scale_x, float scale_y)
{
return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y));
}
static inline TweenHelper
ScaleTo(Duration dur, float scale)
{
return TweenHelper(new kiwano::ActionScaleTo(dur, scale));
}
/// \~chinese
/// @brief 构造缩放动画
/// @param duration 动画时长
/// @param scale_x 横向缩放目标值
/// @param scale_y 纵向缩放目标值
static inline TweenHelper
ScaleTo(Duration dur, float scale_x, float scale_y)
{
return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y));
}
/// \~chinese
/// @brief 构造透明度渐变动画
/// @param duration 动画时长
/// @param opacity 目标透明度
static inline TweenHelper
FadeTo(Duration dur, float opacity)
{
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
}
/// \~chinese
/// @brief 构造淡入动画
/// @param duration 动画时长
static inline TweenHelper
FadeIn(Duration dur)
{
return TweenHelper(new kiwano::ActionFadeIn(dur));
}
/// \~chinese
/// @brief 构造淡出动画
/// @param duration 动画时长
static inline TweenHelper
FadeOut(Duration dur)
{
return TweenHelper(new kiwano::ActionFadeOut(dur));
}
/// \~chinese
/// @brief 构造相对旋转动画
/// @param duration 动画时长
/// @param rotation 角度相对变化值
static inline TweenHelper
RotateBy(Duration dur, float rotation)
{
return TweenHelper(new kiwano::ActionRotateBy(dur, rotation));
}
/// \~chinese
/// @brief 构造旋转动画
/// @param duration 动画时长
/// @param rotation 目标角度
static inline TweenHelper
RotateTo(Duration dur, float rotation)
{
return TweenHelper(new kiwano::ActionRotateTo(dur, rotation));
}
/// \~chinese
/// @brief 构造路径行走动画
/// @param duration 持续时长
/// @param path 路径几何形状
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
static inline TweenHelper
Walk(
Duration duration, /* 持续时长 */
Geometry const& geo, /* 路线 */
bool rotating = false, /* 沿路线切线方向旋转 */
float start = 0.f, /* 起点 */
float end = 1.f, /* 终点 */
EaseFunc func = nullptr /* 速度变化 */
)
Walk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f)
{
return TweenHelper(new kiwano::ActionWalk(duration, geo, rotating, start, end, func));
return TweenHelper(new kiwano::ActionWalk(duration, path, rotating, start, end));
}
/// \~chinese
/// @brief 构造路径行走动画
/// @param duration 持续时长
/// @param sink 几何形状生成器
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
static inline TweenHelper
Walk(
Duration duration, /* 持续时长 */
GeometrySink& sink, /* 路线生成器 */
bool rotating = false, /* 沿路线切线方向旋转 */
float start = 0.f, /* 起点 */
float end = 1.f, /* 终点 */
EaseFunc func = nullptr /* 速度变化 */
)
Walk(Duration duration, GeometrySink& sink, bool rotating = false, float start = 0.f, float end = 1.f)
{
return TweenHelper(new kiwano::ActionWalk(duration, sink.GetGeometry(), rotating, start, end, func));
return TweenHelper(new kiwano::ActionWalk(duration, sink.GetGeometry(), rotating, start, end));
}
/// \~chinese
/// @brief 构建帧动画
/// @param duration 动画时长
/// @param[in] frame_seq 序列帧
static inline TweenHelper
Animation(Duration dur, FrameSequencePtr frames)
{
return TweenHelper(new kiwano::Animation(dur, frames));
}
/// \~chinese
/// @brief 构造自定义动画
/// @param duration 动画时长
/// @param tween_func 动画回调函数
static inline TweenHelper
Custom(Duration dur, ActionCustom::TweenFunc tween_func)
{
return TweenHelper(new kiwano::ActionCustom(dur, tween_func));
}
/// \~chinese
/// @brief 构建延时动画
/// @param delay 延时时长
static inline ActionHelper
Delay(Duration delay)
{
return ActionHelper(new kiwano::ActionDelay(delay));
}
/// \~chinese
/// @brief 动画组合
/// @param actions 动画集合
/// @param sequence 动画按顺序依次执行或同时执行
static inline ActionHelper
Group(Vector<ActionPtr> const& actions, bool sequence = true)
{
return ActionHelper(new kiwano::ActionGroup(actions, sequence));
}
/// \~chinese
/// @brief 同步动画组合
/// @param actions 动画集合
static inline ActionHelper
Multiple(Vector<ActionPtr> const& actions)
{
return ActionHelper(new kiwano::ActionGroup(actions, false));
}
#pragma warning(push)
#pragma warning(disable : 4996)
KGE_DEPRECATED("Tween::OpacityBy has been removed, use Tween::FadeTo instead")
static inline TweenHelper
OpacityBy(float opacity)
{
KGE_ASSERT("Tween::OpacityBy has been removed, use Tween::FadeTo instead");
return TweenHelper(nullptr);
}
KGE_DEPRECATED("Tween::OpacityTo is deprecated, use Tween::FadeTo instead")
static inline TweenHelper
OpacityTo(Duration dur, float opacity)
{
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
}
KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead")
static inline ActionHelper
Sequence(Vector<ActionPtr> const& actions)
{
return ActionHelper(new kiwano::ActionGroup(actions, true));
}
KGE_DEPRECATED("Tween::Spawn is deprecated, use Tween::Multiple instead")
static inline ActionHelper
Spawn(Vector<ActionPtr> const& actions)
{
return ActionHelper(new kiwano::ActionGroup(actions, false));
}
#pragma warning(pop)
};
/** @} */
}

View File

@ -24,7 +24,7 @@
namespace kiwano
{
void ActionManager::UpdateActions(ActorPtr target, Duration dt)
void ActionManager::UpdateActions(Actor* target, Duration dt)
{
if (actions_.empty() || !target)
return;
@ -66,6 +66,7 @@ namespace kiwano
for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
if (action->IsName(name))
return action;
return nullptr;
}

View File

@ -23,41 +23,49 @@
namespace kiwano
{
/**
* \addtogroup Actions
* @{
*/
class KGE_API ActionManager
{
using Actions = IntrusiveList<ActionPtr>;
public:
// 添加动
// 添加动
Action* AddAction(
ActionPtr action
);
// 添加动作
// 添加动画
Action* AddAction(
Action* action
);
// 获取动
// 获取动
Action* GetAction(
String const& name
);
// 继续所有暂停动
// 继续所有暂停动
void ResumeAllActions();
// 暂停所有动
// 暂停所有动
void PauseAllActions();
// 停止所有动
// 停止所有动
void StopAllActions();
// 获取所有动
// 获取所有动
Actions const& GetAllActions() const;
protected:
void UpdateActions(ActorPtr target, Duration dt);
void UpdateActions(Actor* target, Duration dt);
protected:
private:
Actions actions_;
};
/** @} */
}

View File

@ -27,12 +27,12 @@ namespace kiwano
// Ease Functions
//-------------------------------------------------------
inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
KGE_API EaseFunc Ease::Linear = math::Linear;
KGE_API EaseFunc Ease::EaseIn = MakeEaseIn(2.f);
@ -97,7 +97,7 @@ namespace kiwano
return dur_;
}
void ActionTween::Update(ActorPtr target, Duration dt)
void ActionTween::Update(Actor* target, Duration dt)
{
float percent;
@ -135,13 +135,13 @@ namespace kiwano
// Move Action
//-------------------------------------------------------
ActionMoveBy::ActionMoveBy(Duration duration, Point const& vector, EaseFunc func)
ActionMoveBy::ActionMoveBy(Duration duration, Vec2 const& vector, EaseFunc func)
: ActionTween(duration, func)
{
delta_pos_ = vector;
}
void ActionMoveBy::Init(ActorPtr target)
void ActionMoveBy::Init(Actor* target)
{
if (target)
{
@ -149,7 +149,7 @@ namespace kiwano
}
}
void ActionMoveBy::UpdateTween(ActorPtr target, float percent)
void ActionMoveBy::UpdateTween(Actor* target, float percent)
{
Point diff = target->GetPosition() - prev_pos_;
start_pos_ = start_pos_ + diff;
@ -162,12 +162,12 @@ namespace kiwano
ActionPtr ActionMoveBy::Clone() const
{
return new (std::nothrow) ActionMoveBy(dur_, delta_pos_, ease_func_);
return new (std::nothrow) ActionMoveBy(GetDuration(), delta_pos_, GetEaseFunc());
}
ActionPtr ActionMoveBy::Reverse() const
{
return new (std::nothrow) ActionMoveBy(dur_, -delta_pos_, ease_func_);
return new (std::nothrow) ActionMoveBy(GetDuration(), -delta_pos_, GetEaseFunc());
}
ActionMoveTo::ActionMoveTo(Duration duration, Point const& pos, EaseFunc func)
@ -178,10 +178,10 @@ namespace kiwano
ActionPtr ActionMoveTo::Clone() const
{
return new (std::nothrow) ActionMoveTo(dur_, end_pos_, ease_func_);
return new (std::nothrow) ActionMoveTo(GetDuration(), end_pos_, GetEaseFunc());
}
void ActionMoveTo::Init(ActorPtr target)
void ActionMoveTo::Init(Actor* target)
{
ActionMoveBy::Init(target);
delta_pos_ = end_pos_ - start_pos_;
@ -192,7 +192,7 @@ namespace kiwano
// Jump Action
//-------------------------------------------------------
ActionJumpBy::ActionJumpBy(Duration duration, Point const& vec, float height, int jumps, EaseFunc func)
ActionJumpBy::ActionJumpBy(Duration duration, Vec2 const& vec, float height, int jumps, EaseFunc func)
: ActionTween(duration, func)
, delta_pos_(vec)
, height_(height)
@ -202,15 +202,15 @@ namespace kiwano
ActionPtr ActionJumpBy::Clone() const
{
return new (std::nothrow) ActionJumpBy(dur_, delta_pos_, height_, jumps_, ease_func_);
return new (std::nothrow) ActionJumpBy(GetDuration(), delta_pos_, height_, jumps_, GetEaseFunc());
}
ActionPtr ActionJumpBy::Reverse() const
{
return new (std::nothrow) ActionJumpBy(dur_, -delta_pos_, height_, jumps_, ease_func_);
return new (std::nothrow) ActionJumpBy(GetDuration(), -delta_pos_, height_, jumps_, GetEaseFunc());
}
void ActionJumpBy::Init(ActorPtr target)
void ActionJumpBy::Init(Actor* target)
{
if (target)
{
@ -218,7 +218,7 @@ namespace kiwano
}
}
void ActionJumpBy::UpdateTween(ActorPtr target, float percent)
void ActionJumpBy::UpdateTween(Actor* target, float percent)
{
float frac = fmod(percent * jumps_, 1.f);
float x = delta_pos_.x * percent;
@ -242,10 +242,10 @@ namespace kiwano
ActionPtr ActionJumpTo::Clone() const
{
return new (std::nothrow) ActionJumpTo(dur_, end_pos_, height_, jumps_, ease_func_);
return new (std::nothrow) ActionJumpTo(GetDuration(), end_pos_, height_, jumps_, GetEaseFunc());
}
void ActionJumpTo::Init(ActorPtr target)
void ActionJumpTo::Init(Actor* target)
{
ActionJumpBy::Init(target);
delta_pos_ = end_pos_ - start_pos_;
@ -256,11 +256,6 @@ namespace kiwano
// Scale Action
//-------------------------------------------------------
ActionScaleBy::ActionScaleBy(Duration duration, float scale, EaseFunc func)
: ActionScaleBy(duration, scale, scale, func)
{
}
ActionScaleBy::ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func)
: ActionTween(duration, func)
, delta_x_(scale_x)
@ -270,7 +265,7 @@ namespace kiwano
{
}
void ActionScaleBy::Init(ActorPtr target)
void ActionScaleBy::Init(Actor* target)
{
if (target)
{
@ -279,26 +274,19 @@ namespace kiwano
}
}
void ActionScaleBy::UpdateTween(ActorPtr target, float percent)
void ActionScaleBy::UpdateTween(Actor* target, float percent)
{
target->SetScale(Vec2{ start_scale_x_ + delta_x_ * percent, start_scale_y_ + delta_y_ * percent });
}
ActionPtr ActionScaleBy::Clone() const
{
return new (std::nothrow) ActionScaleBy(dur_, delta_x_, delta_y_, ease_func_);
return new (std::nothrow) ActionScaleBy(GetDuration(), delta_x_, delta_y_, GetEaseFunc());
}
ActionPtr ActionScaleBy::Reverse() const
{
return new (std::nothrow) ActionScaleBy(dur_, -delta_x_, -delta_y_, ease_func_);
}
ActionScaleTo::ActionScaleTo(Duration duration, float scale, EaseFunc func)
: ActionScaleBy(duration, 0, 0, func)
{
end_scale_x_ = scale;
end_scale_y_ = scale;
return new (std::nothrow) ActionScaleBy(GetDuration(), -delta_x_, -delta_y_, GetEaseFunc());
}
ActionScaleTo::ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func)
@ -310,10 +298,10 @@ namespace kiwano
ActionPtr ActionScaleTo::Clone() const
{
return new (std::nothrow) ActionScaleTo(dur_, end_scale_x_, end_scale_y_, ease_func_);
return new (std::nothrow) ActionScaleTo(GetDuration(), end_scale_x_, end_scale_y_, GetEaseFunc());
}
void ActionScaleTo::Init(ActorPtr target)
void ActionScaleTo::Init(Actor* target)
{
ActionScaleBy::Init(target);
delta_x_ = end_scale_x_ - start_scale_x_;
@ -333,7 +321,7 @@ namespace kiwano
{
}
void ActionFadeTo::Init(ActorPtr target)
void ActionFadeTo::Init(Actor* target)
{
if (target)
{
@ -342,14 +330,14 @@ namespace kiwano
}
}
void ActionFadeTo::UpdateTween(ActorPtr target, float percent)
void ActionFadeTo::UpdateTween(Actor* target, float percent)
{
target->SetOpacity(start_val_ + delta_val_ * percent);
}
ActionPtr ActionFadeTo::Clone() const
{
return new (std::nothrow) ActionFadeTo(dur_, end_val_, ease_func_);
return new (std::nothrow) ActionFadeTo(GetDuration(), end_val_, GetEaseFunc());
}
ActionFadeIn::ActionFadeIn(Duration duration, EaseFunc func)
@ -374,7 +362,7 @@ namespace kiwano
{
}
void ActionRotateBy::Init(ActorPtr target)
void ActionRotateBy::Init(Actor* target)
{
if (target)
{
@ -382,7 +370,7 @@ namespace kiwano
}
}
void ActionRotateBy::UpdateTween(ActorPtr target, float percent)
void ActionRotateBy::UpdateTween(Actor* target, float percent)
{
float rotation = start_val_ + delta_val_ * percent;
if (rotation > 360.f)
@ -393,12 +381,12 @@ namespace kiwano
ActionPtr ActionRotateBy::Clone() const
{
return new (std::nothrow) ActionRotateBy(dur_, delta_val_, ease_func_);
return new (std::nothrow) ActionRotateBy(GetDuration(), delta_val_, GetEaseFunc());
}
ActionPtr ActionRotateBy::Reverse() const
{
return new (std::nothrow) ActionRotateBy(dur_, -delta_val_, ease_func_);
return new (std::nothrow) ActionRotateBy(GetDuration(), -delta_val_, GetEaseFunc());
}
ActionRotateTo::ActionRotateTo(Duration duration, float rotation, EaseFunc func)
@ -409,10 +397,10 @@ namespace kiwano
ActionPtr ActionRotateTo::Clone() const
{
return new (std::nothrow) ActionRotateTo(dur_, end_val_, ease_func_);
return new (std::nothrow) ActionRotateTo(GetDuration(), end_val_, GetEaseFunc());
}
void ActionRotateTo::Init(ActorPtr target)
void ActionRotateTo::Init(Actor* target)
{
ActionRotateBy::Init(target);
delta_val_ = end_val_ - start_val_;
@ -431,16 +419,16 @@ namespace kiwano
ActionPtr ActionCustom::Clone() const
{
return new ActionCustom(dur_, tween_func_);
return new ActionCustom(GetDuration(), tween_func_);
}
void ActionCustom::Init(ActorPtr target)
void ActionCustom::Init(Actor* target)
{
if (!tween_func_)
this->Done();
}
void ActionCustom::UpdateTween(ActorPtr target, float percent)
void ActionCustom::UpdateTween(Actor* target, float percent)
{
if (tween_func_)
tween_func_(target, percent);

View File

@ -24,26 +24,28 @@
namespace kiwano
{
// 缓动函数
/// \~chinese
/// @brief 缓动函数
using EaseFunc = Function<float(float)>;
// 缓动函数枚举
// See https://easings.net for more information
/// \~chinese
/// @brief 缓动函数枚举
/// @details 查看 https://easings.net 获取更多信息
struct Ease
{
static KGE_API EaseFunc Linear; // 线性
static KGE_API EaseFunc EaseIn; // 由慢变快
static KGE_API EaseFunc EaseOut; // 由快变慢
static KGE_API EaseFunc EaseInOut; // 由慢变快, 再由快变慢
static KGE_API EaseFunc ExpoIn; // 由慢变极快
static KGE_API EaseFunc ExpoOut; // 由极快变慢
static KGE_API EaseFunc ExpoInOut; // 由慢至极快, 再由极快边慢
static KGE_API EaseFunc ElasticIn; // 自起点赋予弹性
static KGE_API EaseFunc ElasticOut; // 自终点赋予弹性
static KGE_API EaseFunc ElasticInOut; // 再起点和终点赋予弹性
static KGE_API EaseFunc BounceIn; // 自起点赋予反弹力
static KGE_API EaseFunc BounceOut; // 自终点赋予反弹力
static KGE_API EaseFunc BounceInOut; // 在起点和终点赋予反弹力
static KGE_API EaseFunc Linear; ///< 线性
static KGE_API EaseFunc EaseIn; ///< 由慢变快
static KGE_API EaseFunc EaseOut; ///< 由快变慢
static KGE_API EaseFunc EaseInOut; ///< 由慢变快, 再由快变慢
static KGE_API EaseFunc ExpoIn; ///< 由慢变极快
static KGE_API EaseFunc ExpoOut; ///< 由极快变慢
static KGE_API EaseFunc ExpoInOut; ///< 由慢至极快, 再由极快边慢
static KGE_API EaseFunc ElasticIn; ///< 自起点赋予弹性
static KGE_API EaseFunc ElasticOut; ///< 自终点赋予弹性
static KGE_API EaseFunc ElasticInOut; ///< 再起点和终点赋予弹性
static KGE_API EaseFunc BounceIn; ///< 自起点赋予反弹力
static KGE_API EaseFunc BounceOut; ///< 自终点赋予反弹力
static KGE_API EaseFunc BounceInOut; ///< 在起点和终点赋予反弹力
static KGE_API EaseFunc BackIn;
static KGE_API EaseFunc BackOut;
static KGE_API EaseFunc BackInOut;
@ -65,84 +67,119 @@ namespace kiwano
};
// 补间动画
KGE_DECLARE_SMART_PTR(ActionTween);
KGE_DECLARE_SMART_PTR(ActionMoveBy);
KGE_DECLARE_SMART_PTR(ActionMoveTo);
KGE_DECLARE_SMART_PTR(ActionJumpBy);
KGE_DECLARE_SMART_PTR(ActionJumpTo);
KGE_DECLARE_SMART_PTR(ActionScaleBy);
KGE_DECLARE_SMART_PTR(ActionScaleTo);
KGE_DECLARE_SMART_PTR(ActionFadeTo);
KGE_DECLARE_SMART_PTR(ActionFadeIn);
KGE_DECLARE_SMART_PTR(ActionFadeOut);
KGE_DECLARE_SMART_PTR(ActionRotateBy);
KGE_DECLARE_SMART_PTR(ActionRotateTo);
KGE_DECLARE_SMART_PTR(ActionCustom);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 补间动画
class KGE_API ActionTween
: public Action
{
public:
ActionTween();
ActionTween(
Duration duration,
EaseFunc func
);
// 自定义缓动函数
void SetEaseFunc(
EaseFunc const& func
);
EaseFunc const& GetEaseFunc() const;
/// \~chinese
/// @brief 补间动画
/// @param duration 动画时长
/// @param func 动画速度缓动函数
ActionTween(Duration duration, EaseFunc func);
/// \~chinese
/// @brief 获取动画时长
Duration GetDuration() const;
/// \~chinese
/// @brief 设置动画时长
void SetDuration(Duration duration);
protected:
void Update(ActorPtr target, Duration dt) override;
/// \~chinese
/// @brief 获取动画速度缓动函数
EaseFunc const& GetEaseFunc() const;
virtual void UpdateTween(ActorPtr target, float percent) = 0;
/// \~chinese
/// @brief 设置动画速度缓动函数
void SetEaseFunc(EaseFunc const& func);
protected:
void Update(Actor* target, Duration dt) override;
virtual void UpdateTween(Actor* target, float percent) = 0;
private:
Duration dur_;
EaseFunc ease_func_;
};
// 相对位移动作
/// \~chinese
/// @brief 相对位移动画
class KGE_API ActionMoveBy
: public ActionTween
{
public:
ActionMoveBy(
Duration duration, /* 持续时长 */
Point const& vector, /* 移动距离 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造相对位移动画
/// @param duration 动画时长
/// @param vector 移动向量
/// @param func 动画速度缓动函数
ActionMoveBy(Duration duration, Vec2 const& vector, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
Point start_pos_;
Point prev_pos_;
Point delta_pos_;
Vec2 delta_pos_;
};
// 位移动作
/// \~chinese
/// @brief 位移动画
class KGE_API ActionMoveTo
: public ActionMoveBy
{
public:
ActionMoveTo(
Duration duration, /* 持续时长 */
Point const& pos, /* 目的坐标 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造位移动画
/// @param duration 动画时长
/// @param pos 目的坐标
/// @param func 动画速度缓动函数
ActionMoveTo(Duration duration, Point const& pos, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
virtual ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionMoveTo");
@ -150,36 +187,40 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
protected:
private:
Point end_pos_;
};
// 相对跳跃动作
/// \~chinese
/// @brief 相对跳跃动画
class KGE_API ActionJumpBy
: public ActionTween
{
public:
ActionJumpBy(
Duration duration, /* 持续时长 */
Point const& vec, /* 跳跃距离 */
float height, /* 跳跃高度 */
int jumps = 1, /* 跳跃次数 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造相对跳跃动画
/// @param duration 动画时长
/// @param vec 跳跃位移向量
/// @param height 跳跃高度
/// @param jumps 跳跃次数
/// @param func 动画速度缓动函数
ActionJumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
Point start_pos_;
@ -190,23 +231,27 @@ namespace kiwano
};
// 跳跃动作
/// \~chinese
/// @brief 跳跃动画
class KGE_API ActionJumpTo
: public ActionJumpBy
{
public:
ActionJumpTo(
Duration duration, /* 持续时长 */
Point const& pos, /* 目的坐标 */
float height, /* 跳跃高度 */
int jumps = 1, /* 跳跃次数 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造跳跃动画
/// @param duration 动画时长
/// @param pos 目的坐标
/// @param height 跳跃高度
/// @param jumps 跳跃次数
/// @param func 动画速度缓动函数
ActionJumpTo(Duration duration, Point const& pos, float height, int jumps = 1, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
virtual ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionJumpTo");
@ -214,41 +259,39 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
protected:
private:
Point end_pos_;
};
// 相对缩放动作
/// \~chinese
/// @brief 相对缩放动画
class KGE_API ActionScaleBy
: public ActionTween
{
public:
ActionScaleBy(
Duration duration, /* 持续时长 */
float scale, /* 相对变化值 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造相对缩放动画
/// @param duration 动画时长
/// @param scale_x 横向缩放相对变化值
/// @param scale_y 纵向缩放相对变化值
/// @param func 动画速度缓动函数
ActionScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
ActionScaleBy(
Duration duration, /* 持续时长 */
float scale_x, /* 横向缩放相对变化值 */
float scale_y, /* 纵向缩放相对变化值 */
EaseFunc func = nullptr /* 速度变化 */
);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
float start_scale_x_;
@ -258,28 +301,26 @@ namespace kiwano
};
// 缩放动作
/// \~chinese
/// @brief 缩放动画
class KGE_API ActionScaleTo
: public ActionScaleBy
{
public:
ActionScaleTo(
Duration duration, /* 持续时长 */
float scale, /* 目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造缩放动画
/// @param duration 动画时长
/// @param scale_x 横向缩放目标值
/// @param scale_y 纵向缩放目标值
/// @param func 动画速度缓动函数
ActionScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func = nullptr);
ActionScaleTo(
Duration duration, /* 持续时长 */
float scale_x, /* 横向缩放目标值 */
float scale_y, /* 纵向缩放目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
virtual ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionScaleTo");
@ -287,29 +328,33 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
protected:
private:
float end_scale_x_;
float end_scale_y_;
};
// 透明度渐变动作
/// \~chinese
/// @brief 透明度渐变动画
class KGE_API ActionFadeTo
: public ActionTween
{
public:
ActionFadeTo(
Duration duration, /* 持续时长 */
float opacity, /* 目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造透明度渐变动画
/// @param duration 动画时长
/// @param opacity 目标透明度
/// @param func 动画速度缓动函数
ActionFadeTo(Duration duration, float opacity, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
virtual ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionFadeTo");
@ -317,64 +362,70 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
private:
float start_val_;
float delta_val_;
float end_val_;
};
// 淡入动作
/// \~chinese
/// @brief 淡入动画
class KGE_API ActionFadeIn
: public ActionFadeTo
{
public:
// 创建淡入动作
explicit ActionFadeIn(
Duration duration, /* 持续时长 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造淡入动画
/// @param duration 动画时长
/// @param func 动画速度缓动函数
explicit ActionFadeIn(Duration duration, EaseFunc func = nullptr);
};
// 淡出动作
/// \~chinese
/// @brief 淡出动画
class KGE_API ActionFadeOut
: public ActionFadeTo
{
public:
// 创建淡出动作
explicit ActionFadeOut(
Duration duration, /* 持续时长 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造淡出动画
/// @param duration 动画时长
/// @param func 动画速度缓动函数
explicit ActionFadeOut(Duration duration, EaseFunc func = nullptr);
};
// 相对旋转动作
/// \~chinese
/// @brief 相对旋转动画
class KGE_API ActionRotateBy
: public ActionTween
{
public:
ActionRotateBy(
Duration duration, /* 持续时长 */
float rotation, /* 相对变化值 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造相对旋转动画
/// @param duration 动画时长
/// @param rotation 角度相对变化值
/// @param func 动画速度缓动函数
ActionRotateBy(Duration duration, float rotation, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
float start_val_;
@ -382,21 +433,25 @@ namespace kiwano
};
// 旋转动作
/// \~chinese
/// @brief 旋转动画
class KGE_API ActionRotateTo
: public ActionRotateBy
{
public:
ActionRotateTo(
Duration duration, /* 持续时长 */
float rotation, /* 目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造旋转动画
/// @param duration 动画时长
/// @param rotation 目标角度
/// @param func 动画速度缓动函数
ActionRotateTo(Duration duration, float rotation, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
virtual ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionRotateTo");
@ -404,30 +459,37 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
protected:
private:
float end_val_;
};
// 自定义动作
/// \~chinese
/// @brief 自定义动画
class KGE_API ActionCustom
: public ActionTween
{
public:
using TweenFunc = Function<void(ActorPtr, float)>;
/// \~chinese
/// @brief 动画回调函数
/// @details 在动画更新时回调该函数第一个参数是执行动画的目标第二个参数是动画进度0.0 - 1.0
using TweenFunc = Function<void(Actor*, float)>;
ActionCustom(
Duration duration, /* 持续时长 */
TweenFunc tween_func, /* 过程函数 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造自定义动画
/// @param duration 动画时长
/// @param tween_func 动画回调函数
/// @param func 动画速度缓动函数
ActionCustom(Duration duration, TweenFunc tween_func, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override
{
KGE_ERROR(L"Reverse() not supported in ActionCustom");
@ -435,12 +497,14 @@ namespace kiwano
}
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
private:
TweenFunc tween_func_;
};
/** @} */
}

View File

@ -40,7 +40,7 @@ namespace kiwano
ActionPtr ActionWalk::Clone() const
{
ActionWalkPtr clone = new ActionWalk(dur_, rotating_, start_, end_, ease_func_);
ActionWalkPtr clone = new ActionWalk(GetDuration(), rotating_, start_, end_, GetEaseFunc());
if (clone)
{
clone->SetPath(path_);
@ -50,7 +50,7 @@ namespace kiwano
ActionPtr ActionWalk::Reverse() const
{
ActionWalkPtr reverse = new ActionWalk(dur_, rotating_, end_, start_, ease_func_);
ActionWalkPtr reverse = new ActionWalk(GetDuration(), rotating_, end_, start_, GetEaseFunc());
if (reverse)
{
reverse->SetPath(path_);
@ -58,7 +58,7 @@ namespace kiwano
return reverse;
}
void ActionWalk::Init(ActorPtr target)
void ActionWalk::Init(Actor* target)
{
if (!path_)
{
@ -70,7 +70,7 @@ namespace kiwano
length_ = path_.GetLength();
}
void ActionWalk::UpdateTween(ActorPtr target, float percent)
void ActionWalk::UpdateTween(Actor* target, float percent)
{
float distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f);

View File

@ -24,83 +24,100 @@
namespace kiwano
{
// 路线行走动作
KGE_DECLARE_SMART_PTR(ActionWalk);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 路径行走动画
class KGE_API ActionWalk
: public ActionTween
{
public:
ActionWalk(
Duration duration, /* 持续时长 */
bool rotating = false, /* 沿路线切线方向旋转 */
float start = 0.f, /* 起点 */
float end = 1.f, /* 终点 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造路径行走动画
/// @param duration 持续时长
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
/// @param func 动画速度缓动函数
ActionWalk(Duration duration, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
ActionWalk(
Duration duration, /* 持续时长 */
Geometry const& path, /* 路线 */
bool rotating = false, /* 沿路线切线方向旋转 */
float start = 0.f, /* 起点 */
float end = 1.f, /* 终点 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构造路径行走动画
/// @param duration 持续时长
/// @param path 路径几何形状
/// @param rotating 是否沿路径切线方向旋转
/// @param start 路径起点(百分比)
/// @param end 路径终点(百分比)
/// @param func 动画速度缓动函数
ActionWalk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
// 开始添加路线
/// \~chinese
/// @brief 开始添加路线
void BeginPath();
// 结束路线
void EndPath(
bool closed = false /* 路线是否闭合 */
);
/// \~chinese
/// @brief 结束路线
/// @param closed 路线是否闭合
void EndPath(bool closed = false);
// 添加一条线段
void AddLine(
Point const& point /* 端点 */
);
/// \~chinese
/// @brief 添加一条线段
/// @param point 线段端点
void AddLine(Point const& point);
// 添加多条线段
void AddLines(
Vector<Point> const& points
);
/// \~chinese
/// @brief 添加多条线段
/// @param points 端点集合
void AddLines(Vector<Point> const& points);
// 添加一条三次方贝塞尔曲线
void AddBezier(
Point const& point1, /* 贝塞尔曲线的第一个控制点 */
Point const& point2, /* 贝塞尔曲线的第二个控制点 */
Point const& point3 /* 贝塞尔曲线的终点 */
);
/// \~chinese
/// @brief 添加一条三次方贝塞尔曲线
/// @brief 添加一条三次方贝塞尔曲线
/// @param point1 贝塞尔曲线的第一个控制点
/// @param point2 贝塞尔曲线的第二个控制点
/// @param point3 贝塞尔曲线的终点
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
// 添加弧线
void AddArc(
Point const& point, /* 终点 */
Size const& radius, /* 椭圆半径 */
float rotation, /* 椭圆旋转角度 */
bool clockwise = true, /* 顺时针 or 逆时针 */
bool is_small = true /* 是否取小于 180° 的弧 */
);
/// \~chinese
/// @brief 添加弧线
/// @param point 椭圆圆心
/// @param radius 椭圆半径
/// @param rotation 椭圆旋转角度
/// @param clockwise 顺时针 or 逆时针
/// @param is_small 是否取小于 180° 的弧
void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
// 清除路径
/// \~chinese
/// @brief 清除路径
void ClearPath();
// 获取路线
inline Geometry const& GetPath() const { return path_; }
/// \~chinese
/// @brief 获取路线
Geometry const& GetPath() const;
// 设置路径
inline void SetPath(Geometry const& path) { path_ = path; }
/// \~chinese
/// @brief 设置路径几何形状
void SetPath(Geometry const& path);
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
private:
bool rotating_;
float start_;
float end_;
@ -109,4 +126,10 @@ namespace kiwano
Geometry path_;
GeometrySink sink_;
};
/** @} */
inline Geometry const& ActionWalk::GetPath() const { return path_; }
inline void ActionWalk::SetPath(Geometry const& path) { path_ = path; }
}

View File

@ -45,12 +45,12 @@ namespace kiwano
return frame_seq_;
}
void Animation::SetFrameSequence(FrameSequencePtr frames)
void Animation::SetFrameSequence(FrameSequencePtr frame_seq)
{
frame_seq_ = frames;
frame_seq_ = frame_seq;
}
void Animation::Init(ActorPtr target)
void Animation::Init(Actor* target)
{
KGE_ASSERT(frame_seq_ && "Animation::Init() failed: FrameSequence is NULL!");
if (!frame_seq_ || frame_seq_->GetFrames().empty())
@ -59,7 +59,7 @@ namespace kiwano
return;
}
auto sprite_target = dynamic_cast<Sprite*>(target.get());
auto sprite_target = dynamic_cast<Sprite*>(target);
KGE_ASSERT(sprite_target && "Animation only supports Sprites!");
if (sprite_target && frame_seq_)
@ -68,9 +68,9 @@ namespace kiwano
}
}
void Animation::UpdateTween(ActorPtr target, float percent)
void Animation::UpdateTween(Actor* target, float percent)
{
auto sprite_target = dynamic_cast<Sprite*>(target.get());
auto sprite_target = dynamic_cast<Sprite*>(target);
if (sprite_target && frame_seq_)
{
@ -86,7 +86,7 @@ namespace kiwano
{
if (frame_seq_)
{
return new (std::nothrow) Animation(dur_, frame_seq_, ease_func_);
return new (std::nothrow) Animation(GetDuration(), frame_seq_, GetEaseFunc());
}
return nullptr;
}
@ -98,7 +98,7 @@ namespace kiwano
FrameSequencePtr frames = frame_seq_->Reverse();
if (frames)
{
return new (std::nothrow) Animation(dur_, frames, ease_func_);
return new (std::nothrow) Animation(GetDuration(), frames, GetEaseFunc());
}
}
return nullptr;

View File

@ -20,44 +20,59 @@
#pragma once
#include <kiwano/2d/action/ActionTween.h>
#include <kiwano/2d/FrameSequence.h>
namespace kiwano
{
// 帧动画
KGE_DECLARE_SMART_PTR(Animation);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 帧动画
class KGE_API Animation
: public ActionTween
{
public:
Animation();
Animation(
Duration duration, /* 动画时长 */
FrameSequencePtr frame_seq, /* 序列帧 */
EaseFunc func = nullptr /* 速度变化 */
);
/// \~chinese
/// @brief 构建帧动画
/// @param duration 动画时长
/// @param[in] frame_seq 序列帧
/// @param func 动画速度缓动函数
Animation(Duration duration, FrameSequencePtr frame_seq, EaseFunc func = nullptr);
virtual ~Animation();
// 获取动画
/// \~chinese
/// @brief 获取序列帧
FrameSequencePtr GetFrameSequence() const;
// 设置动画
void SetFrameSequence(
FrameSequencePtr frames
);
/// \~chinese
/// @brief 设置序列帧
/// @param[in] frame_seq 序列帧
void SetFrameSequence(FrameSequencePtr frame_seq);
// 获取该动作的拷贝对象
/// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override;
// 获取该动作的倒转
/// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override;
protected:
void Init(ActorPtr target) override;
void Init(Actor* target) override;
void UpdateTween(ActorPtr target, float percent) override;
void UpdateTween(Actor* target, float percent) override;
protected:
private:
FrameSequencePtr frame_seq_;
};
/** @} */
}

View File

@ -1,78 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/time.h>
#include <kiwano/core/RefCounter.hpp>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/math/math.h>
#include <kiwano/renderer/Color.h>
namespace kiwano
{
KGE_DECLARE_SMART_PTR(Frame);
KGE_DECLARE_SMART_PTR(FrameSequence);
KGE_DECLARE_SMART_PTR(Actor);
KGE_DECLARE_SMART_PTR(Stage);
KGE_DECLARE_SMART_PTR(Layer);
KGE_DECLARE_SMART_PTR(Sprite);
KGE_DECLARE_SMART_PTR(GifSprite);
KGE_DECLARE_SMART_PTR(Text);
KGE_DECLARE_SMART_PTR(Canvas);
KGE_DECLARE_SMART_PTR(ShapeActor);
KGE_DECLARE_SMART_PTR(LineActor);
KGE_DECLARE_SMART_PTR(RectActor);
KGE_DECLARE_SMART_PTR(RoundRectActor);
KGE_DECLARE_SMART_PTR(CircleActor);
KGE_DECLARE_SMART_PTR(EllipseActor);
KGE_DECLARE_SMART_PTR(PolygonActor);
KGE_DECLARE_SMART_PTR(PathActor);
KGE_DECLARE_SMART_PTR(Action);
KGE_DECLARE_SMART_PTR(ActionTween);
KGE_DECLARE_SMART_PTR(ActionMoveBy);
KGE_DECLARE_SMART_PTR(ActionMoveTo);
KGE_DECLARE_SMART_PTR(ActionJumpBy);
KGE_DECLARE_SMART_PTR(ActionJumpTo);
KGE_DECLARE_SMART_PTR(ActionScaleBy);
KGE_DECLARE_SMART_PTR(ActionScaleTo);
KGE_DECLARE_SMART_PTR(ActionFadeTo);
KGE_DECLARE_SMART_PTR(ActionFadeIn);
KGE_DECLARE_SMART_PTR(ActionFadeOut);
KGE_DECLARE_SMART_PTR(ActionRotateBy);
KGE_DECLARE_SMART_PTR(ActionRotateTo);
KGE_DECLARE_SMART_PTR(ActionWalk);
KGE_DECLARE_SMART_PTR(Animation);
KGE_DECLARE_SMART_PTR(ActionGroup);
KGE_DECLARE_SMART_PTR(ActionSpawn);
KGE_DECLARE_SMART_PTR(Transition);
KGE_DECLARE_SMART_PTR(FadeTransition);
KGE_DECLARE_SMART_PTR(EmergeTransition);
KGE_DECLARE_SMART_PTR(BoxTransition);
KGE_DECLARE_SMART_PTR(MoveTransition);
KGE_DECLARE_SMART_PTR(RotationTransition);
KGE_DECLARE_SMART_PTR(Button);
KGE_DECLARE_SMART_PTR(Menu);
}

View File

@ -73,12 +73,12 @@ namespace kiwano
/// @brief 启动异步任务
void Start();
protected:
private:
void TaskThread();
void Complete();
protected:
private:
std::thread thread_;
std::mutex func_mutex_;
Queue<AsyncTaskFunc> thread_func_queue_;

View File

@ -21,7 +21,7 @@
#pragma once
#include <typeinfo>
#include <typeindex>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/math/math.h>
#include <kiwano/core/keys.h>
@ -145,7 +145,7 @@ namespace kiwano
return const_cast<_Ty&>(const_cast<const Event*>(this)->SafeCast<_Ty>());
}
protected:
private:
const EventType type_;
};

View File

@ -101,7 +101,7 @@ namespace kiwano
virtual void Dispatch(Event& evt);
protected:
private:
Listeners listeners_;
};
}

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/Event.h>
@ -88,7 +88,7 @@ namespace kiwano
void SetEventType(EventType const& type);
protected:
private:
bool running_;
EventType type_;
Callback callback_;

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{

View File

@ -24,7 +24,7 @@
#include <sstream>
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#ifndef KGE_LOG
# ifdef KGE_DEBUG

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/RefCounter.hpp>
#include <kiwano/core/SmartPtr.hpp>

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{
@ -46,7 +46,7 @@ namespace kiwano
virtual ~RefCounter() {}
protected:
private:
long ref_count_;
};
}

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{

View File

@ -19,8 +19,8 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/core/common.h>
#include <kiwano/core/RefCounter.hpp>
#include <kiwano/common/common.h>
namespace kiwano
{

View File

@ -57,12 +57,12 @@ namespace kiwano
// 任务是否正在执行
bool IsRunning() const;
protected:
private:
void Update(Duration dt, bool& remove_after_update);
void Reset();
protected:
private:
bool running_;
int run_times_;
int total_times_;

View File

@ -71,7 +71,7 @@ namespace kiwano
protected:
void UpdateTimers(Duration dt);
protected:
private:
Timers timers_;
};
}

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{
@ -57,22 +57,18 @@ namespace kiwano
/// \~chinese
/// @brief 获取毫秒数
/// @return 毫秒数
long Milliseconds() const;
/// \~chinese
/// @brief 获取秒数
/// @return 秒数
float Seconds() const;
/// \~chinese
/// @brief 获取分钟数
/// @return 分钟数
float Minutes() const;
/// \~chinese
/// @brief 获取小时数
/// @return 小时数
float Hours() const;
/// \~chinese
@ -102,7 +98,6 @@ namespace kiwano
/// \~chinese
/// @brief 转为字符串
/// @return 格式化后的字符串
String ToString() const;
/// \~chinese
@ -188,7 +183,6 @@ namespace kiwano
/// \~chinese
/// @brief 获取当前时间
/// @return 当前时间
static Time Now() noexcept;
const Duration operator -(const Time&) const;

View File

@ -20,7 +20,7 @@
#pragma once
#include <type_traits>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <Unknwnbase.h>
namespace kiwano

View File

@ -28,13 +28,6 @@
#include <kiwano/macros.h>
//
// common
//
#include <kiwano/common/common.h>
//
// math
//
@ -47,6 +40,24 @@
#include <kiwano/math/Matrix.hpp>
//
// core
//
#include <kiwano/core/common.h>
#include <kiwano/core/time.h>
#include <kiwano/core/Logger.h>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/Event.h>
#include <kiwano/core/EventListener.h>
#include <kiwano/core/EventDispatcher.h>
#include <kiwano/core/Timer.h>
#include <kiwano/core/TimerManager.h>
#include <kiwano/core/AsyncTask.h>
#include <kiwano/core/Resource.h>
//
// renderer
//
@ -62,23 +73,6 @@
#include <kiwano/renderer/Renderer.h>
//
// core
//
#include <kiwano/core/time.h>
#include <kiwano/core/Logger.h>
#include <kiwano/core/SmartPtr.hpp>
#include <kiwano/core/ObjectBase.h>
#include <kiwano/core/Event.h>
#include <kiwano/core/EventListener.h>
#include <kiwano/core/EventDispatcher.h>
#include <kiwano/core/Timer.h>
#include <kiwano/core/TimerManager.h>
#include <kiwano/core/AsyncTask.h>
#include <kiwano/core/Resource.h>
//
// 2d
//
@ -106,7 +100,7 @@
#include <kiwano/2d/Layer.h>
#include <kiwano/2d/Sprite.h>
#include <kiwano/2d/GifSprite.h>
#include <kiwano/2d/Text.h>
#include <kiwano/2d/TextActor.h>
#include <kiwano/2d/Canvas.h>
#include <kiwano/2d/ShapeActor.h>
#include <kiwano/2d/DebugActor.h>

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/math/constants.h>
#include <kiwano/math/ease.h>
#include <kiwano/math/scalar.h>

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/core/time.h>
#include <kiwano/core/Component.h>
#include <kiwano/core/Event.h>
@ -84,9 +84,7 @@ namespace kiwano
* @param config
* @attention 使
*/
void Init(
Config const& config = Config()
);
void Init(Config const& config = Config());
/**
* \~chinese
@ -134,9 +132,7 @@ namespace kiwano
* @brief
* @param[in] component
*/
void Use(
ComponentBase* component
);
void Use(ComponentBase* component);
/**
* \~chinese
@ -145,9 +141,7 @@ namespace kiwano
* @param scale_factor
* @warning
*/
void SetTimeScale(
float scale_factor
);
void SetTimeScale(float scale_factor);
/**
* \~chinese
@ -163,18 +157,16 @@ namespace kiwano
* @details 线 Kiwano
* @param func
*/
static void PreformInMainThread(
Function<void()> func
);
static void PreformInMainThread(Function<void()> func);
protected:
private:
void Render();
void Update();
static LRESULT CALLBACK WndProc(HWND, UINT32, WPARAM, LPARAM);
protected:
private:
bool end_;
bool inited_;
float time_scale_;

View File

@ -19,14 +19,18 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/2d/include-forwards.h>
#include <kiwano/core/Component.h>
#include <kiwano/2d/Actor.h>
#include <kiwano/2d/Stage.h>
#include <kiwano/2d/Transition.h>
namespace kiwano
{
/**
* \~chinese
* @brief
* @brief
* @details
* @see kiwano::Stage
*/
class KGE_API Director
: public Singleton<Director>
@ -50,7 +54,7 @@ namespace kiwano
/**
* \~chinese
* @brief
* @brief
* @param[in] stage
* @param[in] transition
*/
@ -61,7 +65,7 @@ namespace kiwano
/**
* \~chinese
* @brief 退
* @brief 退
* @param[in] transition
*/
void PopStage(
@ -106,12 +110,12 @@ namespace kiwano
void HandleEvent(Event& evt) override;
protected:
private:
Director();
virtual ~Director();
protected:
private:
bool render_border_enabled_;
Stack<StagePtr> stages_;
StagePtr current_stage_;

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/math/math.h>
#include <kiwano/core/keys.h>
#include <kiwano/core/Component.h>
@ -46,9 +46,7 @@ namespace kiwano
* @return
* @see kiwano::KeyCode kiwano::MouseButton
*/
bool IsDown(
int key_or_btn
);
bool IsDown(int key_or_btn);
/**
* \~chinese
@ -57,9 +55,7 @@ namespace kiwano
* @return
* @see kiwano::KeyCode kiwano::MouseButton
*/
bool WasPressed(
int key_or_btn
);
bool WasPressed(int key_or_btn);
/**
* \~chinese
@ -68,9 +64,7 @@ namespace kiwano
* @return
* @see kiwano::KeyCode kiwano::MouseButton
*/
bool WasReleased(
int key_or_btn
);
bool WasReleased(int key_or_btn);
/**
* \~chinese
@ -108,12 +102,12 @@ namespace kiwano
void Destroy();
protected:
private:
Input();
~Input();
protected:
private:
static const int KEY_NUM = 256;
bool want_update_;

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
#include <kiwano/math/math.h>
namespace kiwano
@ -170,7 +170,7 @@ namespace kiwano
void Destroy();
protected:
private:
Window();
~Window();

View File

@ -157,7 +157,7 @@ namespace kiwano
inline ComPtr<ID2D1Brush> const& GetBrush() const { return raw_; }
protected:
private:
Type type_;
float opacity_;
ComPtr<ID2D1Brush> raw_;

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{

View File

@ -58,7 +58,7 @@ namespace kiwano
inline void SetFontCollection(ComPtr<IDWriteFontCollection> collection) { collection_ = collection; }
protected:
private:
ComPtr<IDWriteFontCollection> collection_;
};
}

View File

@ -123,7 +123,7 @@ namespace kiwano
inline operator bool() const { return IsValid(); }
protected:
private:
ComPtr<ID2D1Geometry> geo_;
};
@ -198,7 +198,7 @@ namespace kiwano
void Init();
protected:
private:
ComPtr<ID2D1PathGeometry> path_geo_;
ComPtr<ID2D1GeometrySink> sink_;
};

View File

@ -69,10 +69,10 @@ namespace kiwano
inline void SetDecoder(ComPtr<IWICBitmapDecoder> decoder) { decoder_ = decoder; }
protected:
private:
HRESULT GetGlobalMetadata();
protected:
private:
uint32_t frames_count_;
uint32_t width_in_pixels_;
uint32_t height_in_pixels_;

View File

@ -58,7 +58,7 @@ namespace kiwano
inline void SetLayer(ComPtr<ID2D1Layer> layer) { layer_ = layer; }
protected:
private:
Rect area_;
float opacity_;
Geometry mask_;

View File

@ -69,6 +69,9 @@ namespace kiwano
if (SUCCEEDED(hr))
{
SetAntialiasMode(antialias_);
SetTextAntialiasMode(text_antialias_);
current_brush_ = default_brush_;
}
@ -714,10 +717,10 @@ namespace kiwano
{
HRESULT hr = E_FAIL;
if (render_target_)
if (GetRenderTarget())
{
ComPtr<ID2D1BitmapRenderTarget> bitmap_rt;
hr = render_target_->QueryInterface<ID2D1BitmapRenderTarget>(&bitmap_rt);
hr = GetRenderTarget()->QueryInterface<ID2D1BitmapRenderTarget>(&bitmap_rt);
if (SUCCEEDED(hr))
{

View File

@ -218,7 +218,7 @@ namespace kiwano
void DiscardDeviceResources();
protected:
private:
float opacity_;
bool antialias_;
bool fast_global_transform_;

View File

@ -159,7 +159,7 @@ namespace kiwano
if (SUCCEEDED(hr))
{
render_target_->SaveDrawingState(drawing_state_block_.get());
GetRenderTarget()->SaveDrawingState(drawing_state_block_.get());
BeginDraw();
}
@ -179,7 +179,7 @@ namespace kiwano
{
EndDraw();
render_target_->RestoreDrawingState(drawing_state_block_.get());
GetRenderTarget()->RestoreDrawingState(drawing_state_block_.get());
}
if (SUCCEEDED(hr))
@ -219,12 +219,6 @@ namespace kiwano
d2d_res_->GetDeviceContext(),
d2d_res_
);
if (SUCCEEDED(hr))
{
SetAntialiasMode(antialias_);
SetTextAntialiasMode(text_antialias_);
}
return hr;
}

View File

@ -22,11 +22,13 @@
namespace kiwano
{
// ÏßÌõÑùʽ
/// \~chinese
/// @brief 线条样式
/// @details 线条样式表示渲染目标在绘制线条时,如何处理两条线相交部分
enum class StrokeStyle
{
Miter = 0, /* бÇÐ */
Bevel = 1, /* б½Ç */
Round = 2 /* Ô²½Ç */
Miter = 0, ///< 斜切样式
Bevel = 1, ///< 斜角样式
Round = 2 ///< 圆角样式
};
}

View File

@ -19,6 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/math/math.h>
#include <kiwano/renderer/Font.h>
#include <kiwano/2d/TextStyle.hpp>
@ -39,7 +40,7 @@ namespace kiwano
inline void SetTextFormat(ComPtr<IDWriteTextFormat> format) { text_format_ = format; }
protected:
private:
ComPtr<IDWriteTextFormat> text_format_;
};
@ -73,7 +74,7 @@ namespace kiwano
inline operator bool() const { return static_cast<bool>(text_layout_); }
protected:
private:
TextStyle style_;
TextFormat text_format_;
mutable ComPtr<IDWriteTextLayout> text_layout_;

View File

@ -110,7 +110,7 @@ namespace kiwano
// »ñÈ¡ÏñËØ¸ñʽ
D2D1_PIXEL_FORMAT GetPixelFormat() const;
protected:
private:
ComPtr<ID2D1Bitmap> bitmap_;
InterpolationMode interpolation_mode_;

View File

@ -42,12 +42,12 @@ namespace kiwano
void Clear();
protected:
private:
TextureCache();
virtual ~TextureCache();
protected:
private:
using TextureMap = UnorderedMap<size_t, Texture>;
TextureMap texture_cache_;

View File

@ -94,7 +94,7 @@ namespace kiwano
void** ppvObject
);
protected:
private:
unsigned long ref_count_;
float dpi_;
};

View File

@ -23,6 +23,8 @@
namespace kiwano
{
KGE_DECLARE_SMART_PTR(Button);
class KGE_API Button
: public Sprite
{

View File

@ -23,6 +23,8 @@
namespace kiwano
{
KGE_DECLARE_SMART_PTR(Menu);
// 꽉데
class KGE_API Menu
: public Actor

View File

@ -20,7 +20,7 @@
#pragma once
#include <kiwano/macros.h>
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{
@ -123,7 +123,7 @@ namespace kiwano
String const& default_value = String()
) const;
protected:
private:
String file_path_;
String field_name_;
};

View File

@ -19,12 +19,9 @@
// THE SOFTWARE.
#include <fstream>
#include <kiwano/utils/ResourceCache.h>
#include <kiwano/platform/FileSystem.h>
#include <kiwano/core/Logger.h>
#include <kiwano/2d/Frame.h>
#include <kiwano/2d/FrameSequence.h>
#include <kiwano/platform/FileSystem.h>
#include <kiwano/renderer/GifImage.h>
#include <kiwano/renderer/FontCollection.h>

View File

@ -20,7 +20,8 @@
#pragma once
#include <kiwano/core/Resource.h>
#include <kiwano/2d/include-forwards.h>
#include <kiwano/2d/Frame.h>
#include <kiwano/2d/FrameSequence.h>
#include <kiwano/renderer/GifImage.h>
#include <3rd-party/tinyxml2/tinyxml2.h>
@ -100,12 +101,12 @@ namespace kiwano
return const_cast<_Ty*>(dynamic_cast<const _Ty*>((*iter).second.get()));
}
protected:
private:
ResourceCache();
virtual ~ResourceCache();
protected:
private:
UnorderedMap<String, ObjectBasePtr> object_cache_;
UnorderedMap<String, GifImage> gif_cache_;
UnorderedMap<String, FontCollection> font_collection_cache_;

View File

@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
#include <kiwano/common/common.h>
#include <kiwano/core/common.h>
namespace kiwano
{