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_STATIC = YES
EXTRACT_LOCAL_CLASSES = NO EXTRACT_LOCAL_CLASSES = NO
HIDE_UNDOC_MEMBERS = YES HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO HIDE_UNDOC_CLASSES = NO
SHOW_INCLUDE_FILES = YES SHOW_INCLUDE_FILES = YES
@ -61,12 +61,8 @@ PREDEFINED = KGE_API=
# This tag requires that the tag SEARCH_INCLUDES is set to YES. # This tag requires that the tag SEARCH_INCLUDES is set to YES.
SEARCH_INCLUDES = YES SEARCH_INCLUDES = YES
INCLUDE_PATH = src/ INCLUDE_PATH =
INCLUDE_FILE_PATTERNS = *.h \ INCLUDE_FILE_PATTERNS =
*.hh \
*.hxx \
*.hpp \
*.h++
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# Configuration options related to the HTML output # 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\action\Animation.h" />
<ClInclude Include="..\..\src\kiwano\2d\Frame.h" /> <ClInclude Include="..\..\src\kiwano\2d\Frame.h" />
<ClInclude Include="..\..\src\kiwano\2d\GifSprite.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\Event.h" />
<ClInclude Include="..\..\src\kiwano\core\Library.h" /> <ClInclude Include="..\..\src\kiwano\core\Library.h" />
<ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp" /> <ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp" />
<ClInclude Include="..\..\src\kiwano\core\win32\helper.h" /> <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\kiwano.h" />
<ClInclude Include="..\..\src\kiwano\config.h" /> <ClInclude Include="..\..\src\kiwano\config.h" />
<ClInclude Include="..\..\src\kiwano\macros.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\Canvas.h" />
<ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" /> <ClInclude Include="..\..\src\kiwano\2d\DebugActor.h" />
<ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" /> <ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h" />
@ -28,7 +27,7 @@
<ClInclude Include="..\..\src\kiwano\2d\Actor.h" /> <ClInclude Include="..\..\src\kiwano\2d\Actor.h" />
<ClInclude Include="..\..\src\kiwano\2d\Stage.h" /> <ClInclude Include="..\..\src\kiwano\2d\Stage.h" />
<ClInclude Include="..\..\src\kiwano\2d\Sprite.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\TextStyle.hpp" />
<ClInclude Include="..\..\src\kiwano\2d\Transform.h" /> <ClInclude Include="..\..\src\kiwano\2d\Transform.h" />
<ClInclude Include="..\..\src\kiwano\2d\Transition.h" /> <ClInclude Include="..\..\src\kiwano\2d\Transition.h" />
@ -102,7 +101,7 @@
<ClCompile Include="..\..\src\kiwano\2d\Actor.cpp" /> <ClCompile Include="..\..\src\kiwano\2d\Actor.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" /> <ClCompile Include="..\..\src\kiwano\2d\Stage.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Sprite.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\Transform.cpp" />
<ClCompile Include="..\..\src\kiwano\2d\Transition.cpp" /> <ClCompile Include="..\..\src\kiwano\2d\Transition.cpp" />
<ClCompile Include="..\..\src\kiwano\core\AsyncTask.cpp" /> <ClCompile Include="..\..\src\kiwano\core\AsyncTask.cpp" />

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,83 +26,131 @@
namespace kiwano namespace kiwano
{ {
// GIF 精灵 KGE_DECLARE_SMART_PTR(GifSprite);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief GIF
*/
class KGE_API GifSprite class KGE_API GifSprite
: public Actor : public Actor
{ {
public: public:
/// \~chinese
/// @brief GIF播放循环结束回调
using LoopDoneCallback = Function<void(int)>; using LoopDoneCallback = Function<void(int)>;
/// \~chinese
/// @brief GIF播放结束回调
using DoneCallback = Function<void()>; using DoneCallback = Function<void()>;
GifSprite(); GifSprite();
GifSprite( /// \~chinese
String const& file_path /// @brief 构造GIF精灵
); /// @param file_path GIF图片路径
GifSprite(String const& file_path);
GifSprite( /// \~chinese
Resource const& res /// @brief 构造GIF精灵
); /// @param res GIF图片资源
GifSprite(Resource const& res);
GifSprite( /// \~chinese
GifImage gif /// @brief 构造GIF精灵
); /// @param gif GIF图片
GifSprite(GifImage gif);
bool Load( /// \~chinese
String const& file_path /// @brief 加载GIF图片
); /// @param file_path GIF图片路径
bool Load(String const& file_path);
bool Load( /// \~chinese
Resource const& res /// @brief 加载GIF图片
); /// @param res GIF图片资源
bool Load(Resource const& res);
bool Load( /// \~chinese
GifImage gif /// @brief 加载GIF图片
); /// @param gif GIF图片
bool Load(GifImage gif);
// 设置 GIF 动画循环次数 /// \~chinese
inline void SetLoopCount(int loops) { total_loop_count_ = loops; } /// @brief 设置 GIF 动画循环次数
void SetLoopCount(int loops);
// 设置 GIF 动画每次循环结束回调函数 /// \~chinese
inline void SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; } /// @brief 设置 GIF 动画每次循环结束回调函数
void SetLoopDoneCallback(LoopDoneCallback const& cb);
// 设置 GIF 动画结束回调函数 /// \~chinese
inline void SetDoneCallback(DoneCallback const& cb) { done_cb_ = cb; } /// @brief 设置 GIF 动画结束回调函数
void SetDoneCallback(DoneCallback const& cb);
// 设置 GIF 图像 /// \~chinese
/// @brief 设置 GIF 图像
void SetGifImage(GifImage const& gif); void SetGifImage(GifImage const& gif);
// 重新播放动画 /// \~chinese
/// @brief 重新播放 GIF 动画
void RestartAnimation(); 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; void OnRender(RenderTarget* rt) override;
protected: private:
void Update(Duration dt) override; 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(); void ComposeNextFrame();
/// \~chinese
/// @brief 解析当前图像帧
void DisposeCurrentFrame(); void DisposeCurrentFrame();
/// \~chinese
/// @brief 覆盖下一帧
void OverlayNextFrame(); void OverlayNextFrame();
/// \~chinese
/// @brief 保存合成后的图像帧
void SaveComposedFrame(); void SaveComposedFrame();
/// \~chinese
/// @brief 恢复已保存的图像帧
void RestoreSavedFrame(); void RestoreSavedFrame();
/// \~chinese
/// @brief 清空当前图像区域
void ClearCurrentFrameArea(); void ClearCurrentFrameArea();
protected: private:
bool animating_; bool animating_;
int total_loop_count_; int total_loop_count_;
int loop_count_; int loop_count_;
@ -115,4 +163,22 @@ namespace kiwano
Texture saved_frame_; Texture saved_frame_;
TextureRenderTarget frame_rt_; 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 #pragma once
#include <kiwano/2d/Actor.h> #include <kiwano/2d/Actor.h>
#include <kiwano/2d/..\renderer\LayerArea.h> #include <kiwano/renderer/LayerArea.h>
#include <kiwano/2d/..\renderer\RenderTarget.h> #include <kiwano/renderer/RenderTarget.h>
namespace kiwano namespace kiwano
{ {
KGE_DECLARE_SMART_PTR(Layer);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Layer class KGE_API Layer
: public Actor : public Actor
{ {
@ -33,40 +44,80 @@ namespace kiwano
virtual ~Layer(); virtual ~Layer();
// 重载下列函数以获取图层事件 /// \~chinese
virtual void OnMouseButtonDown(MouseButton::Value btn, Point const& p) {} /// @brief 是否开启消息吞没
virtual void OnMouseButtonUp(MouseButton::Value btn, Point const& p) {} bool IsSwallowEventsEnabled() const;
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
inline bool IsSwallowEventsEnabled() const { return swallow_; } /// @brief 设置消息吞没功能
/// @param enabled 是否启用
void SetSwallowEvents(bool enabled);
// 吞没消息 /// \~chinese
inline void SetSwallowEvents(bool enabled) { swallow_ = enabled; } /// @brief 设置裁剪区域
/// @param clip_rect 裁剪矩形
// 设置裁剪区域
void SetClipRect(Rect const& clip_rect); void SetClipRect(Rect const& clip_rect);
// 设置图层透明度 /// \~chinese
/// @brief 设置图层透明度
/// @param opacity 透明度
void SetOpacity(float opacity) override; void SetOpacity(float opacity) override;
// 设置几何蒙层 /// \~chinese
/// @brief 设置几何蒙层
/// @param mask 蒙层的几何形状
void SetMaskGeometry(Geometry const& mask); void SetMaskGeometry(Geometry const& mask);
// 设置几何蒙层的二维变换 /// \~chinese
/// @brief 设置几何蒙层的二维变换
/// @param transform 应用于蒙层的二维变换
void SetMaskTransform(Matrix3x2 const& transform); void SetMaskTransform(Matrix3x2 const& transform);
// 设置图层区域 /// \~chinese
inline void SetArea(LayerArea const& area) { area_ = area; } /// @brief 设置图层区域
/// @param area 图层区域属性
void SetArea(LayerArea const& area);
// 获取图层区域 /// \~chinese
inline LayerArea const& GetArea() const { return area_; } /// @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; void Dispatch(Event& evt) override;
protected: protected:
@ -74,8 +125,19 @@ namespace kiwano
void HandleMessages(Event& evt); void HandleMessages(Event& evt);
protected: private:
bool swallow_; bool swallow_;
LayerArea area_; 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() void PathActor::ClearPath()
{ {
geo_.SetGeometry(nullptr); SetGeometry(Geometry());
} }
} }

View File

@ -25,61 +25,89 @@
namespace kiwano 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 class KGE_API ShapeActor
: public Actor : public Actor
{ {
public: public:
ShapeActor(); ShapeActor();
ShapeActor( ShapeActor(Geometry const& geometry);
Geometry const& geometry
);
virtual ~ShapeActor(); virtual ~ShapeActor();
// 获取填充颜色 /// \~chinese
inline Color GetFillColor() const { return fill_color_; } /// @brief 获取填充颜色
Color GetFillColor() const;
// 获取线条颜色 /// \~chinese
inline Color GetStrokeColor() const { return stroke_color_; } /// @brief 获取线条颜色
Color GetStrokeColor() const;
// 获取线条宽度 /// \~chinese
inline float GetStrokeWidth() const { return stroke_width_; } /// @brief 获取线条宽度
float GetStrokeWidth() const;
// 获取线条样式 /// \~chinese
inline StrokeStyle SetStrokeStyle() const { return stroke_style_; } /// @brief 获取线条样式
StrokeStyle SetStrokeStyle() const;
// 获取形状 /// \~chinese
inline Geometry GetGeometry() const { return geo_; } /// @brief 获取形状
Geometry GetGeometry() const;
// 获取边界 /// \~chinese
/// @brief 获取边界
Rect GetBounds() const override; Rect GetBounds() const override;
// 获取外切包围盒 /// \~chinese
/// @brief 获取外切包围盒
Rect GetBoundingBox() const override; Rect GetBoundingBox() const override;
// 判断点是否在形状内 /// \~chinese
/// @brief 判断点是否在形状内
bool ContainsPoint(const Point& point) const override; bool ContainsPoint(const Point& point) const override;
// 设置填充颜色 /// \~chinese
/// @brief 设置填充颜色
void SetFillColor(const Color& color); void SetFillColor(const Color& color);
// 设置线条颜色 /// \~chinese
/// @brief 设置线条颜色
void SetStrokeColor(const Color& color); void SetStrokeColor(const Color& color);
// 设置线条宽度 /// \~chinese
/// @brief 设置线条宽度,默认为 1.0
void SetStrokeWidth(float width); void SetStrokeWidth(float width);
// 设置线条样式 /// \~chinese
/// @brief 设置线条样式
void SetStrokeStyle(StrokeStyle stroke_style); void SetStrokeStyle(StrokeStyle stroke_style);
// 设置形状 /// \~chinese
/// @brief 设置几何形状
void SetGeometry(Geometry const& geometry); void SetGeometry(Geometry const& geometry);
void OnRender(RenderTarget* rt) override; void OnRender(RenderTarget* rt) override;
protected: private:
Color fill_color_; Color fill_color_;
Color stroke_color_; Color stroke_color_;
float stroke_width_; float stroke_width_;
@ -89,170 +117,210 @@ namespace kiwano
}; };
// 直线角色 /// \~chinese
/// @brief 线段图形角色
class KGE_API LineActor class KGE_API LineActor
: public ShapeActor : public ShapeActor
{ {
public: public:
LineActor(); LineActor();
LineActor( /// \~chinese
Point const& begin, /// @brief 线段图形角色
Point const& end /// @param begin 线段起点
); /// @param end 线段终点
LineActor(Point const& begin, Point const& end);
virtual ~LineActor(); virtual ~LineActor();
inline Point const& GetBeginPoint() const { return begin_; } /// \~chinese
/// @brief 获取线段起点
inline Point const& GetEndPoint() const { return end_; } Point const& GetBeginPoint() const;
inline void SetBeginPoint(Point const& begin) /// \~chinese
{ /// @brief 获取线段终点
SetLine(begin, end_); Point const& GetEndPoint() const;
}
inline void SetEndPoint(Point const& end) /// \~chinese
{ /// @brief 设置线段起点
SetLine(begin_, end); /// @param begin 线段起点
} void SetBeginPoint(Point const& begin);
void SetLine( /// \~chinese
Point const& begin, /// @brief 设置线段终点
Point const& end /// @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 begin_;
Point end_; Point end_;
}; };
// 矩形角色 /// \~chinese
/// @brief 矩形角色
class KGE_API RectActor class KGE_API RectActor
: public ShapeActor : public ShapeActor
{ {
public: public:
RectActor(); RectActor();
RectActor( /// \~chinese
Size const& size /// @brief 构造矩形角色
); /// @param size 矩形大小
RectActor(Size const& size);
virtual ~RectActor(); 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); void SetRectSize(Size const& size);
protected: private:
Size rect_size_; Size rect_size_;
}; };
// 圆角矩形角色
/// \~chinese
/// @brief 圆角矩形角色
class KGE_API RoundRectActor class KGE_API RoundRectActor
: public ShapeActor : public ShapeActor
{ {
public: public:
RoundRectActor(); RoundRectActor();
RoundRectActor( /// \~chinese
Size const& size, /// @brief 构造圆角矩形角色
Vec2 const& radius /// @param size 圆角矩形大小
); /// @param radius 圆角半径
RoundRectActor(Size const& size, Vec2 const& radius);
virtual ~RoundRectActor(); 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( /// \~chinese
Vec2 const& radius /// @brief 设置圆角半径
); /// @param radius 圆角半径
void SetRadius(Vec2 const& radius);
void SetRectSize( /// \~chinese
Size const& size /// @brief 设置圆角矩形大小
); /// @param size 圆角矩形大小
void SetRectSize(Size const& size);
void SetRoundedRect( /// \~chinese
Size const& size, /// @brief 设置圆角矩形
Vec2 const& radius /// @param size 圆角矩形大小
); /// @param radius 圆角半径
void SetRoundedRect(Size const& size, Vec2 const& radius);
protected: private:
Size rect_size_; Size rect_size_;
Vec2 radius_; Vec2 radius_;
}; };
// 圆形角色 /// \~chinese
/// @brief 圆形角色
class KGE_API CircleActor class KGE_API CircleActor
: public ShapeActor : public ShapeActor
{ {
public: public:
CircleActor(); CircleActor();
CircleActor( /// \~chinese
float radius /// @brief 构造圆形角色
); /// @param radius 圆形半径
CircleActor(float radius);
virtual ~CircleActor(); virtual ~CircleActor();
inline float GetRadius() const { return radius_; } /// \~chinese
/// @brief 获取圆形半径
float GetRadius() const;
/// \~chinese
/// @brief 设置圆形半径
/// @param radius 圆形半径
void SetRadius(float radius); void SetRadius(float radius);
protected: private:
float radius_; float radius_;
}; };
// 椭圆角色 /// \~chinese
/// @brief 椭圆角色
class KGE_API EllipseActor class KGE_API EllipseActor
: public ShapeActor : public ShapeActor
{ {
public: public:
EllipseActor(); EllipseActor();
EllipseActor( /// \~chinese
Vec2 const& radius /// @brief 构造椭圆角色
); /// @param radius 椭圆半径
EllipseActor(Vec2 const& radius);
virtual ~EllipseActor(); virtual ~EllipseActor();
Vec2 GetRadius() const { return radius_; } /// \~chinese
/// @brief 获取椭圆半径
Vec2 GetRadius() const;
void SetRadius( /// \~chinese
Vec2 const& radius /// @brief 设置椭圆半径
); /// @param radius 椭圆半径
void SetRadius(Vec2 const& radius);
protected: private:
Vec2 radius_; Vec2 radius_;
}; };
// 多边形角色 /// \~chinese
/// @brief 多边形角色
class KGE_API PolygonActor class KGE_API PolygonActor
: public ShapeActor : public ShapeActor
{ {
public: public:
PolygonActor(); PolygonActor();
PolygonActor( /// \~chinese
Vector<Point> const& points /// @brief 构造多边形角色
); /// @param points 多边形端点集合
PolygonActor(Vector<Point> const& points);
virtual ~PolygonActor(); virtual ~PolygonActor();
void SetVertices( /// \~chinese
Vector<Point> const& points /// @brief 设置多边形端点
); /// @param points 多边形端点集合
void SetVertices(Vector<Point> const& points);
}; };
// 路径角色 /// \~chinese
/// @brief 路径图形角色
class KGE_API PathActor class KGE_API PathActor
: public ShapeActor : public ShapeActor
{ {
@ -261,47 +329,70 @@ namespace kiwano
virtual ~PathActor(); virtual ~PathActor();
// 开始添加路径 /// \~chinese
void BeginPath( /// @brief 开始添加路径
Point const& begin_pos = Point{} /* 起始点 */ /// @param begin_pos 起始点
); void BeginPath(Point const& begin_pos = Point());
// 结束路径 /// \~chinese
void EndPath( /// @brief 结束添加路径
bool closed = true /* 路径是否闭合 */ /// @param closed 路径是否闭合
); void EndPath(bool closed = true);
// 添加一条线段 /// \~chinese
void AddLine( /// @brief 添加一条线段
Point const& point /* 端点 */ /// @param point 线段端点
); void AddLine(Point const& point);
// 添加多条线段 /// \~chinese
void AddLines( /// @brief 添加多条线段
Vector<Point> const& points /// @param points 线段端点集合
); void AddLines(Vector<Point> const& points);
// 添加一条三次方贝塞尔曲线 /// \~chinese
void AddBezier( /// @brief 添加一条三次方贝塞尔曲线
Point const& point1, /* 贝塞尔曲线的第一个控制点 */ /// @param point1 贝塞尔曲线的第一个控制点
Point const& point2, /* 贝塞尔曲线的第二个控制点 */ /// @param point2 贝塞尔曲线的第二个控制点
Point const& point3 /* 贝塞尔曲线的终点 */ /// @param point3 贝塞尔曲线的终点
); void AddBezier(Point const& point1, Point const& point2, Point const& point3);
// 添加弧线 /// \~chinese
void AddArc( /// @brief 添加弧线
Point const& point, /* 终点 */ /// @param point 椭圆圆心
Size const& radius, /* 椭圆半径 */ /// @param radius 椭圆半径
float rotation, /* 椭圆旋转角度 */ /// @param rotation 椭圆旋转角度
bool clockwise = true, /* 顺时针 or 逆时针 */ /// @param clockwise 顺时针 or 逆时针
bool is_small = true /* 是否取小于 180° 的弧 */ /// @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(); void ClearPath();
protected: private:
GeometrySink sink_; 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 namespace kiwano
{ {
// ¾«Áé KGE_DECLARE_SMART_PTR(Sprite);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
*/
class KGE_API Sprite class KGE_API Sprite
: public Actor : public Actor
{ {
public: public:
Sprite(); Sprite();
explicit Sprite( /// \~chinese
String const& file_path /// @brief 从本地图片构造精灵
); /// @param file_path 本地图片路径
explicit Sprite(String const& file_path);
Sprite( /// \~chinese
String const& file_path, /// @brief 从图片资源构造精灵
Rect const& crop_rect /* ²Ã¼ô¾ØÐÎ */ /// @param res 图片资源
); explicit Sprite(Resource const& res);
explicit Sprite( /// \~chinese
Resource const& res /// @brief 从图像帧构造精灵
); /// @param[in] frame 图像帧
explicit Sprite(FramePtr frame);
Sprite( /// \~chinese
Resource const& res, /// @brief 从本地图片构造精灵并裁剪
Rect const& crop_rect /* ²Ã¼ô¾ØÐÎ */ /// @param file_path 本地图片路径
); /// @param crop_rect 裁剪矩形
Sprite(String const& file_path, Rect const& crop_rect);
explicit Sprite( /// \~chinese
FramePtr frame /// @brief 从图片资源构造精灵并裁剪
); /// @param res 图片资源
/// @param crop_rect 裁剪矩形
Sprite(Resource const& res, Rect const& crop_rect);
virtual ~Sprite(); virtual ~Sprite();
// ¼ÓÔØÍ¼Ïñ /// \~chinese
bool Load( /// @brief 加载本地图片
String const& file_path /// @param file_path 本地图片路径
); bool Load(String const& file_path);
// ¼ÓÔØÍ¼Ïñ×ÊÔ´ /// \~chinese
bool Load( /// @brief 加载图像资源
Resource const& res /// @param res 图片资源
); bool Load(Resource const& res);
// ²Ã¼ô¾ØÐÎ /// \~chinese
void SetCropRect( /// @brief 使用矩形区域裁剪精灵
const Rect& crop_rect /// @param crop_rect 裁剪矩形
); void SetCropRect(const Rect& crop_rect);
// »ñȡ֡ͼÏñ /// \~chinese
inline FramePtr GetFrame() const { return frame_; } /// @brief 获取帧图像
FramePtr GetFrame() const;
// ÉèÖÃ֡ͼÏñ /// \~chinese
/// @brief 设置图像帧
/// @param[in] frame 图像帧
void SetFrame(FramePtr frame); void SetFrame(FramePtr frame);
// äÖȾ¾«Áé
void OnRender(RenderTarget* rt) override; void OnRender(RenderTarget* rt) override;
protected: private:
FramePtr frame_; FramePtr frame_;
}; };
/** @} */
inline FramePtr Sprite::GetFrame() const { return frame_; }
} }

View File

@ -23,7 +23,19 @@
namespace kiwano namespace kiwano
{ {
// 舞台 KGE_DECLARE_SMART_PTR(Stage);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief
* @details
* @see kiwano::Actor kiwano::Director
*/
class KGE_API Stage class KGE_API Stage
: public Actor : public Actor
{ {
@ -35,10 +47,17 @@ namespace kiwano
virtual ~Stage(); virtual ~Stage();
// 进入舞台 /// \~chinese
/// @brief 进入舞台时
/// @details 重载该函数以处理进入舞台前的行为
virtual void OnEnter(); virtual void OnEnter();
// 退出舞台 /// \~chinese
/// @brief 退出舞台时
/// @details 重载该函数以处理退出舞台前的行为
virtual void OnExit(); 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#include <kiwano/2d/Text.h> #include <kiwano/2d/TextActor.h>
#include <kiwano/core/Logger.h> #include <kiwano/core/Logger.h>
#include <kiwano/renderer/Renderer.h> #include <kiwano/renderer/Renderer.h>
@ -30,17 +30,17 @@ namespace kiwano
TextStyle text_default_style; TextStyle text_default_style;
} }
void kiwano::Text::SetDefaultFont(Font const & font) void kiwano::TextActor::SetDefaultFont(Font const & font)
{ {
text_default_font = font; text_default_font = font;
} }
void kiwano::Text::SetDefaultStyle(TextStyle const & style) void kiwano::TextActor::SetDefaultStyle(TextStyle const & style)
{ {
text_default_style = style; text_default_style = style;
} }
Text::Text() TextActor::TextActor()
: font_(text_default_font) : font_(text_default_font)
, layout_dirty_(false) , layout_dirty_(false)
, format_dirty_(false) , format_dirty_(false)
@ -48,22 +48,22 @@ namespace kiwano
text_layout_.SetTextStyle(text_default_style); text_layout_.SetTextStyle(text_default_style);
} }
Text::Text(String const& text) TextActor::TextActor(String const& text)
: Text(text, text_default_font, text_default_style) : TextActor(text, text_default_font, text_default_style)
{ {
} }
Text::Text(String const& text, const Font & font) TextActor::TextActor(String const& text, const Font & font)
: Text(text, font, text_default_style) : TextActor(text, font, text_default_style)
{ {
} }
Text::Text(String const& text, const TextStyle & style) TextActor::TextActor(String const& text, const TextStyle & style)
: Text(text, text_default_font, 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) : font_(font)
, text_(text) , text_(text)
, layout_dirty_(true) , layout_dirty_(true)
@ -72,29 +72,29 @@ namespace kiwano
text_layout_.SetTextStyle(style); text_layout_.SetTextStyle(style);
} }
Text::~Text() TextActor::~TextActor()
{ {
} }
void Text::SetText(String const& text) void TextActor::SetText(String const& text)
{ {
text_ = text; text_ = text;
layout_dirty_ = true; layout_dirty_ = true;
} }
void Text::SetStyle(const TextStyle& style) void TextActor::SetStyle(const TextStyle& style)
{ {
text_layout_.SetTextStyle(style); text_layout_.SetTextStyle(style);
layout_dirty_ = true; layout_dirty_ = true;
} }
void Text::SetFont(const Font & font) void TextActor::SetFont(const Font & font)
{ {
font_ = font; font_ = font;
format_dirty_ = true; format_dirty_ = true;
} }
void Text::SetFontFamily(String const& family) void TextActor::SetFontFamily(String const& family)
{ {
if (font_.family != 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) 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) if (font_.weight != weight)
{ {
@ -121,7 +121,7 @@ namespace kiwano
} }
} }
void Text::SetItalic(bool italic) void TextActor::SetItalic(bool italic)
{ {
if (font_.italic != 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) 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) 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) 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) 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) 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;
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; 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; 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; 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; text_layout_.GetTextStyle().outline_stroke = outline_stroke;
} }
void Text::OnRender(RenderTarget* rt) void TextActor::OnRender(RenderTarget* rt)
{ {
UpdateLayout(); UpdateLayout();
@ -212,7 +212,7 @@ namespace kiwano
} }
} }
void Text::UpdateLayout() void TextActor::UpdateLayout()
{ {
if (format_dirty_) 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. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/2d/include-forwards.h> #include <kiwano/renderer/Color.h>
#include <kiwano/renderer/StrokeStyle.h> #include <kiwano/renderer/StrokeStyle.h>
namespace kiwano namespace kiwano
{ {
// 文本对齐方式 /**
* \~chinese
* @brief
*/
enum class TextAlign enum class TextAlign
{ {
Left, /* 左对齐 */ Left, ///< 左对齐
Right, /* 右对齐 */ Right, ///< 右对齐
Center /* 居中对齐 */ Center ///< 居中对齐
}; };
// 文本样式 /**
* \~chinese
* @brief
*/
class KGE_API TextStyle class KGE_API TextStyle
{ {
public: public:
Color color; // 颜色 Color color; ///< 颜色
TextAlign alignment; // 对齐方式 TextAlign alignment; ///< 对齐方式
float wrap_width; // 自动换行宽度 float wrap_width; ///< 自动换行宽度
float line_spacing; // 行间距 float line_spacing; ///< 行间距
bool underline; // 下划线 bool underline; ///< 下划线
bool strikethrough; // 删除线 bool strikethrough; ///< 删除线
bool outline; // 显示描边 bool outline; ///< 描边
Color outline_color; // 描边颜色 Color outline_color; ///< 描边颜色
float outline_width; // 描边线宽 float outline_width; ///< 描边线宽
StrokeStyle outline_stroke; // 描边线相交样式 StrokeStyle outline_stroke; ///< 描边线相交样式
public: 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( TextStyle(
Color color = Color::White, Color color = Color::White,
TextAlign alignment = TextAlign::Left, TextAlign alignment = TextAlign::Left,
float wrap_width = 0.f, float wrap_width = 0.f,
float line_spacing = 0.f, float line_spacing = 0.f,
bool underline = false, bool underline = false,
bool strikethrough = false, bool strikethrough = false,
bool outline = false, bool outline = false,
Color outline_color = Color(Color::Black, 0.5), Color outline_color = Color(Color::Black, 0.5),
float outline_width = 1.f, float outline_width = 1.f,
StrokeStyle outline_stroke = StrokeStyle::Round StrokeStyle outline_stroke = StrokeStyle::Round
) )
: color(color) : color(color)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ namespace kiwano
ActionPtr ActionWalk::Clone() const 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) if (clone)
{ {
clone->SetPath(path_); clone->SetPath(path_);
@ -50,7 +50,7 @@ namespace kiwano
ActionPtr ActionWalk::Reverse() const 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) if (reverse)
{ {
reverse->SetPath(path_); reverse->SetPath(path_);
@ -58,7 +58,7 @@ namespace kiwano
return reverse; return reverse;
} }
void ActionWalk::Init(ActorPtr target) void ActionWalk::Init(Actor* target)
{ {
if (!path_) if (!path_)
{ {
@ -70,7 +70,7 @@ namespace kiwano
length_ = path_.GetLength(); 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); float distance = length_ * std::min(std::max((end_ - start_) * percent + start_, 0.f), 1.f);

View File

@ -24,83 +24,100 @@
namespace kiwano namespace kiwano
{ {
// 路线行走动作 KGE_DECLARE_SMART_PTR(ActionWalk);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 路径行走动画
class KGE_API ActionWalk class KGE_API ActionWalk
: public ActionTween : public ActionTween
{ {
public: public:
ActionWalk( /// \~chinese
Duration duration, /* 持续时长 */ /// @brief 构造路径行走动画
bool rotating = false, /* 沿路线切线方向旋转 */ /// @param duration 持续时长
float start = 0.f, /* 起点 */ /// @param rotating 是否沿路径切线方向旋转
float end = 1.f, /* 终点 */ /// @param start 路径起点(百分比)
EaseFunc func = nullptr /* 速度变化 */ /// @param end 路径终点(百分比)
); /// @param func 动画速度缓动函数
ActionWalk(Duration duration, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
ActionWalk( /// \~chinese
Duration duration, /* 持续时长 */ /// @brief 构造路径行走动画
Geometry const& path, /* 路线 */ /// @param duration 持续时长
bool rotating = false, /* 沿路线切线方向旋转 */ /// @param path 路径几何形状
float start = 0.f, /* 起点 */ /// @param rotating 是否沿路径切线方向旋转
float end = 1.f, /* 终点 */ /// @param start 路径起点(百分比)
EaseFunc func = nullptr /* 速度变化 */ /// @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; ActionPtr Clone() const override;
// 获取该动作的倒转 /// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
// 开始添加路线 /// \~chinese
/// @brief 开始添加路线
void BeginPath(); void BeginPath();
// 结束路线 /// \~chinese
void EndPath( /// @brief 结束路线
bool closed = false /* 路线是否闭合 */ /// @param closed 路线是否闭合
); void EndPath(bool closed = false);
// 添加一条线段 /// \~chinese
void AddLine( /// @brief 添加一条线段
Point const& point /* 端点 */ /// @param point 线段端点
); void AddLine(Point const& point);
// 添加多条线段 /// \~chinese
void AddLines( /// @brief 添加多条线段
Vector<Point> const& points /// @param points 端点集合
); void AddLines(Vector<Point> const& points);
// 添加一条三次方贝塞尔曲线 /// \~chinese
void AddBezier( /// @brief 添加一条三次方贝塞尔曲线
Point const& point1, /* 贝塞尔曲线的第一个控制点 */ /// @brief 添加一条三次方贝塞尔曲线
Point const& point2, /* 贝塞尔曲线的第二个控制点 */ /// @param point1 贝塞尔曲线的第一个控制点
Point const& point3 /* 贝塞尔曲线的终点 */ /// @param point2 贝塞尔曲线的第二个控制点
); /// @param point3 贝塞尔曲线的终点
void AddBezier(Point const& point1, Point const& point2, Point const& point3);
// 添加弧线 /// \~chinese
void AddArc( /// @brief 添加弧线
Point const& point, /* 终点 */ /// @param point 椭圆圆心
Size const& radius, /* 椭圆半径 */ /// @param radius 椭圆半径
float rotation, /* 椭圆旋转角度 */ /// @param rotation 椭圆旋转角度
bool clockwise = true, /* 顺时针 or 逆时针 */ /// @param clockwise 顺时针 or 逆时针
bool is_small = true /* 是否取小于 180° 的弧 */ /// @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(); void ClearPath();
// 获取路线 /// \~chinese
inline Geometry const& GetPath() const { return path_; } /// @brief 获取路线
Geometry const& GetPath() const;
// 设置路径 /// \~chinese
inline void SetPath(Geometry const& path) { path_ = path; } /// @brief 设置路径几何形状
void SetPath(Geometry const& path);
protected: 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_; bool rotating_;
float start_; float start_;
float end_; float end_;
@ -109,4 +126,10 @@ namespace kiwano
Geometry path_; Geometry path_;
GeometrySink sink_; 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_; 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!"); KGE_ASSERT(frame_seq_ && "Animation::Init() failed: FrameSequence is NULL!");
if (!frame_seq_ || frame_seq_->GetFrames().empty()) if (!frame_seq_ || frame_seq_->GetFrames().empty())
@ -59,7 +59,7 @@ namespace kiwano
return; return;
} }
auto sprite_target = dynamic_cast<Sprite*>(target.get()); auto sprite_target = dynamic_cast<Sprite*>(target);
KGE_ASSERT(sprite_target && "Animation only supports Sprites!"); KGE_ASSERT(sprite_target && "Animation only supports Sprites!");
if (sprite_target && frame_seq_) 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_) if (sprite_target && frame_seq_)
{ {
@ -86,7 +86,7 @@ namespace kiwano
{ {
if (frame_seq_) if (frame_seq_)
{ {
return new (std::nothrow) Animation(dur_, frame_seq_, ease_func_); return new (std::nothrow) Animation(GetDuration(), frame_seq_, GetEaseFunc());
} }
return nullptr; return nullptr;
} }
@ -98,7 +98,7 @@ namespace kiwano
FrameSequencePtr frames = frame_seq_->Reverse(); FrameSequencePtr frames = frame_seq_->Reverse();
if (frames) if (frames)
{ {
return new (std::nothrow) Animation(dur_, frames, ease_func_); return new (std::nothrow) Animation(GetDuration(), frames, GetEaseFunc());
} }
} }
return nullptr; return nullptr;

View File

@ -20,44 +20,59 @@
#pragma once #pragma once
#include <kiwano/2d/action/ActionTween.h> #include <kiwano/2d/action/ActionTween.h>
#include <kiwano/2d/FrameSequence.h>
namespace kiwano namespace kiwano
{ {
// 帧动画 KGE_DECLARE_SMART_PTR(Animation);
/**
* \addtogroup Actions
* @{
*/
/// \~chinese
/// @brief 帧动画
class KGE_API Animation class KGE_API Animation
: public ActionTween : public ActionTween
{ {
public: public:
Animation(); Animation();
Animation( /// \~chinese
Duration duration, /* 动画时长 */ /// @brief 构建帧动画
FrameSequencePtr frame_seq, /* 序列帧 */ /// @param duration 动画时长
EaseFunc func = nullptr /* 速度变化 */ /// @param[in] frame_seq 序列帧
); /// @param func 动画速度缓动函数
Animation(Duration duration, FrameSequencePtr frame_seq, EaseFunc func = nullptr);
virtual ~Animation(); virtual ~Animation();
// 获取动画 /// \~chinese
/// @brief 获取序列帧
FrameSequencePtr GetFrameSequence() const; FrameSequencePtr GetFrameSequence() const;
// 设置动画 /// \~chinese
void SetFrameSequence( /// @brief 设置序列帧
FrameSequencePtr frames /// @param[in] frame_seq 序列帧
); void SetFrameSequence(FrameSequencePtr frame_seq);
// 获取该动作的拷贝对象 /// \~chinese
/// @brief 获取该动画的拷贝对象
ActionPtr Clone() const override; ActionPtr Clone() const override;
// 获取该动作的倒转 /// \~chinese
/// @brief 获取该动画的倒转
ActionPtr Reverse() const override; ActionPtr Reverse() const override;
protected: 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_; 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 启动异步任务 /// @brief 启动异步任务
void Start(); void Start();
protected: private:
void TaskThread(); void TaskThread();
void Complete(); void Complete();
protected: private:
std::thread thread_; std::thread thread_;
std::mutex func_mutex_; std::mutex func_mutex_;
Queue<AsyncTaskFunc> thread_func_queue_; Queue<AsyncTaskFunc> thread_func_queue_;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,13 +28,6 @@
#include <kiwano/macros.h> #include <kiwano/macros.h>
//
// common
//
#include <kiwano/common/common.h>
// //
// math // math
// //
@ -47,6 +40,24 @@
#include <kiwano/math/Matrix.hpp> #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 // renderer
// //
@ -62,23 +73,6 @@
#include <kiwano/renderer/Renderer.h> #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 // 2d
// //
@ -106,7 +100,7 @@
#include <kiwano/2d/Layer.h> #include <kiwano/2d/Layer.h>
#include <kiwano/2d/Sprite.h> #include <kiwano/2d/Sprite.h>
#include <kiwano/2d/GifSprite.h> #include <kiwano/2d/GifSprite.h>
#include <kiwano/2d/Text.h> #include <kiwano/2d/TextActor.h>
#include <kiwano/2d/Canvas.h> #include <kiwano/2d/Canvas.h>
#include <kiwano/2d/ShapeActor.h> #include <kiwano/2d/ShapeActor.h>
#include <kiwano/2d/DebugActor.h> #include <kiwano/2d/DebugActor.h>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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