Update Button
This commit is contained in:
parent
920256886e
commit
a3d425b008
|
|
@ -9,6 +9,7 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\action\ActionWalk.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\action\ActionWalk.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\action\ActionTween.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\action\ActionTween.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
|
<ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" />
|
||||||
|
<ClInclude Include="..\..\src\kiwano\2d\Button.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\common.h" />
|
||||||
|
|
@ -82,8 +83,6 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\renderer\win32\FontCollectionLoader.h" />
|
<ClInclude Include="..\..\src\kiwano\renderer\win32\FontCollectionLoader.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\renderer\win32\helper.h" />
|
<ClInclude Include="..\..\src\kiwano\renderer\win32\helper.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\renderer\win32\TextRenderer.h" />
|
<ClInclude Include="..\..\src\kiwano\renderer\win32\TextRenderer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\ui\Button.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano\ui\Menu.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\LocalStorage.h" />
|
<ClInclude Include="..\..\src\kiwano\utils\LocalStorage.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" />
|
<ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano\utils\UserData.h" />
|
<ClInclude Include="..\..\src\kiwano\utils\UserData.h" />
|
||||||
|
|
@ -96,6 +95,7 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\action\ActionWalk.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\action\ActionWalk.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\action\ActionTween.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\action\ActionTween.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\action\Animation.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\action\Animation.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\kiwano\2d\Button.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\DebugActor.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Frame.cpp" />
|
<ClCompile Include="..\..\src\kiwano\2d\Frame.cpp" />
|
||||||
|
|
@ -149,8 +149,6 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\renderer\win32\D3D11DeviceResources.cpp" />
|
<ClCompile Include="..\..\src\kiwano\renderer\win32\D3D11DeviceResources.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\renderer\win32\FontCollectionLoader.cpp" />
|
<ClCompile Include="..\..\src\kiwano\renderer\win32\FontCollectionLoader.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\renderer\win32\TextRenderer.cpp" />
|
<ClCompile Include="..\..\src\kiwano\renderer\win32\TextRenderer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\ui\Button.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano\ui\Menu.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\LocalStorage.cpp" />
|
<ClCompile Include="..\..\src\kiwano\utils\LocalStorage.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" />
|
<ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" />
|
<ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@
|
||||||
<Filter Include="utils">
|
<Filter Include="utils">
|
||||||
<UniqueIdentifier>{68eac919-ee87-4030-a033-c251731928f5}</UniqueIdentifier>
|
<UniqueIdentifier>{68eac919-ee87-4030-a033-c251731928f5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="ui">
|
|
||||||
<UniqueIdentifier>{07b6d541-4a1b-472a-aae0-daf9d082fe84}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="platform">
|
<Filter Include="platform">
|
||||||
<UniqueIdentifier>{c2654ccc-59f6-4c17-bb6b-99b07fc78702}</UniqueIdentifier>
|
<UniqueIdentifier>{c2654ccc-59f6-4c17-bb6b-99b07fc78702}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
|
@ -36,12 +33,6 @@
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\kiwano\ui\Button.h">
|
|
||||||
<Filter>ui</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\ui\Menu.h">
|
|
||||||
<Filter>ui</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
|
<ClInclude Include="..\..\src\kiwano\2d\Canvas.h">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -288,14 +279,11 @@
|
||||||
<ClInclude Include="..\..\src\kiwano\core\event\WindowEvent.h">
|
<ClInclude Include="..\..\src\kiwano\core\event\WindowEvent.h">
|
||||||
<Filter>core\event</Filter>
|
<Filter>core\event</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano\2d\Button.h">
|
||||||
|
<Filter>2d</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano\ui\Button.cpp">
|
|
||||||
<Filter>ui</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\ui\Menu.cpp">
|
|
||||||
<Filter>ui</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||||
<Filter>2d</Filter>
|
<Filter>2d</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -485,5 +473,8 @@
|
||||||
<ClCompile Include="..\..\src\kiwano\core\event\WindowEvent.cpp">
|
<ClCompile Include="..\..\src\kiwano\core\event\WindowEvent.cpp">
|
||||||
<Filter>core\event</Filter>
|
<Filter>core\event</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\kiwano\2d\Button.cpp">
|
||||||
|
<Filter>2d</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -115,23 +115,23 @@ public:
|
||||||
|
|
||||||
virtual _Ret invoke(_Args... args) const override
|
virtual _Ret invoke(_Args... args) const override
|
||||||
{
|
{
|
||||||
return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...);
|
return (ptr_->*func_)(::std::forward<_Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline callable<_Ret, _Args...>* make(void* ptr, _FuncType func)
|
static inline callable<_Ret, _Args...>* make(_Ty* ptr, _FuncType func)
|
||||||
{
|
{
|
||||||
return new (::std::nothrow) proxy_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
|
return new (::std::nothrow) proxy_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
proxy_mem_callable(void* ptr, _FuncType func)
|
proxy_mem_callable(_Ty* ptr, _FuncType func)
|
||||||
: ptr_(ptr)
|
: ptr_(ptr)
|
||||||
, func_(func)
|
, func_(func)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void* ptr_;
|
_Ty* ptr_;
|
||||||
_FuncType func_;
|
_FuncType func_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -144,23 +144,23 @@ public:
|
||||||
|
|
||||||
virtual _Ret invoke(_Args... args) const override
|
virtual _Ret invoke(_Args... args) const override
|
||||||
{
|
{
|
||||||
return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...);
|
return (ptr_->*func_)(::std::forward<_Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline callable<_Ret, _Args...>* make(void* ptr, _FuncType func)
|
static inline callable<_Ret, _Args...>* make(_Ty* ptr, _FuncType func)
|
||||||
{
|
{
|
||||||
return new (::std::nothrow) proxy_const_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
|
return new (::std::nothrow) proxy_const_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
proxy_const_mem_callable(void* ptr, _FuncType func)
|
proxy_const_mem_callable(_Ty* ptr, _FuncType func)
|
||||||
: ptr_(ptr)
|
: ptr_(ptr)
|
||||||
, func_(func)
|
, func_(func)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void* ptr_;
|
_Ty* ptr_;
|
||||||
_FuncType func_;
|
_FuncType func_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ namespace kiwano
|
||||||
* @brief 񙮵
|
* @brief 񙮵
|
||||||
*/
|
*/
|
||||||
class KGE_API Sound
|
class KGE_API Sound
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class AudioEngine;
|
friend class AudioEngine;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace kiwano
|
||||||
* @brief 音频播放器
|
* @brief 音频播放器
|
||||||
*/
|
*/
|
||||||
class KGE_API SoundPlayer
|
class KGE_API SoundPlayer
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SoundPlayer();
|
SoundPlayer();
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace kiwano
|
||||||
* @brief HTTPÇëÇó
|
* @brief HTTPÇëÇó
|
||||||
*/
|
*/
|
||||||
class KGE_API HttpRequest
|
class KGE_API HttpRequest
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ namespace kiwano
|
||||||
* @brief HTTPÏìÓ¦
|
* @brief HTTPÏìÓ¦
|
||||||
*/
|
*/
|
||||||
class KGE_API HttpResponse
|
class KGE_API HttpResponse
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HttpResponse(HttpRequestPtr request);
|
HttpResponse(HttpRequestPtr request);
|
||||||
|
|
|
||||||
|
|
@ -36,25 +36,12 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Body::Body(b2Body* body, Actor* actor)
|
|
||||||
: Body()
|
|
||||||
{
|
|
||||||
SetB2Body(body);
|
|
||||||
SetActor(actor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Body::Body(World* world, Actor* actor)
|
|
||||||
: Body()
|
|
||||||
{
|
|
||||||
Init(world, actor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Body::~Body()
|
Body::~Body()
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Body::Init(World* world, Actor* actor)
|
bool Body::InitBody(World* world, Actor* actor)
|
||||||
{
|
{
|
||||||
KGE_ASSERT(world);
|
KGE_ASSERT(world);
|
||||||
|
|
||||||
|
|
@ -64,9 +51,14 @@ namespace kiwano
|
||||||
b2BodyDef def;
|
b2BodyDef def;
|
||||||
b2Body* b2body = world->GetB2World()->CreateBody(&def);
|
b2Body* b2body = world->GetB2World()->CreateBody(&def);
|
||||||
|
|
||||||
SetB2Body(b2body);
|
if (b2body)
|
||||||
SetActor(actor);
|
{
|
||||||
UpdateFromActor();
|
SetB2Body(b2body);
|
||||||
|
SetActor(actor);
|
||||||
|
UpdateFromActor();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param)
|
Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param)
|
||||||
|
|
@ -253,7 +245,7 @@ namespace kiwano
|
||||||
|
|
||||||
void Body::Destroy()
|
void Body::Destroy()
|
||||||
{
|
{
|
||||||
if (world_ && body_)
|
if (world_)
|
||||||
{
|
{
|
||||||
world_->RemoveBody(this);
|
world_->RemoveBody(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace kiwano
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体
|
/// @brief 物体
|
||||||
class KGE_API Body
|
class KGE_API Body
|
||||||
: public virtual RefCounter
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
@ -53,16 +53,20 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
Body();
|
Body();
|
||||||
Body(b2Body* body, Actor* actor);
|
|
||||||
Body(World* world, Actor* actor);
|
|
||||||
Body(World* world, ActorPtr actor);
|
|
||||||
virtual ~Body();
|
virtual ~Body();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化
|
/// @brief 初始化
|
||||||
/// @param[in] world 物理世界
|
/// @param[in] world 物理世界
|
||||||
/// @param[in] actor 绑定的角色
|
/// @param[in] actor 绑定的角色
|
||||||
void Init(World* world, Actor* actor);
|
bool InitBody(World* world, ActorPtr actor);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 初始化
|
||||||
|
/// @param[in] world 物理世界
|
||||||
|
/// @param[in] actor 绑定的角色
|
||||||
|
bool InitBody(World* world, Actor* actor);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 添加夹具
|
/// @brief 添加夹具
|
||||||
|
|
@ -319,62 +323,62 @@ namespace kiwano
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
inline Body::Body(World* world, ActorPtr actor) : Body(world, actor.get()) {}
|
inline bool Body::InitBody(World* world, ActorPtr actor) { return InitBody(world, actor.get()); }
|
||||||
|
|
||||||
inline FixtureList Body::GetFixtureList() const { KGE_ASSERT(body_); return FixtureList(Fixture(body_->GetFixtureList())); }
|
inline FixtureList Body::GetFixtureList() const { KGE_ASSERT(body_); return FixtureList(Fixture(body_->GetFixtureList())); }
|
||||||
|
|
||||||
inline ContactEdgeList Body::GetContactList() const { KGE_ASSERT(body_); return ContactEdgeList(ContactEdge(body_->GetContactList())); }
|
inline ContactEdgeList Body::GetContactList() const { KGE_ASSERT(body_); return ContactEdgeList(ContactEdge(body_->GetContactList())); }
|
||||||
|
|
||||||
inline uint16_t Body::GetCategoryBits() const { return category_bits_; }
|
inline uint16_t Body::GetCategoryBits() const { return category_bits_; }
|
||||||
|
|
||||||
inline uint16_t Body::GetMaskBits() const { return mask_bits_; }
|
inline uint16_t Body::GetMaskBits() const { return mask_bits_; }
|
||||||
|
|
||||||
inline int16_t Body::GetGroupIndex() const { return group_index_; }
|
inline int16_t Body::GetGroupIndex() const { return group_index_; }
|
||||||
|
|
||||||
inline float Body::GetBodyRotation() const { KGE_ASSERT(body_); return math::Radian2Degree(body_->GetAngle()); }
|
inline float Body::GetBodyRotation() const { KGE_ASSERT(body_); return math::Radian2Degree(body_->GetAngle()); }
|
||||||
|
|
||||||
inline void Body::SetBodyRotation(float angle) { SetBodyTransform(GetBodyPosition(), angle); }
|
inline void Body::SetBodyRotation(float angle) { SetBodyTransform(GetBodyPosition(), angle); }
|
||||||
|
|
||||||
inline void Body::SetBodyPosition(Point const& pos) { SetBodyTransform(pos, GetBodyRotation()); }
|
inline void Body::SetBodyPosition(Point const& pos) { SetBodyTransform(pos, GetBodyRotation()); }
|
||||||
|
|
||||||
inline float Body::GetMass() const { KGE_ASSERT(body_); return body_->GetMass(); }
|
inline float Body::GetMass() const { KGE_ASSERT(body_); return body_->GetMass(); }
|
||||||
|
|
||||||
inline float Body::GetInertia() const { KGE_ASSERT(body_); return body_->GetInertia(); }
|
inline float Body::GetInertia() const { KGE_ASSERT(body_); return body_->GetInertia(); }
|
||||||
|
|
||||||
inline Body::Type Body::GetType() const { KGE_ASSERT(body_); return Type(body_->GetType()); }
|
inline Body::Type Body::GetType() const { KGE_ASSERT(body_); return Type(body_->GetType()); }
|
||||||
|
|
||||||
inline void Body::SetType(Type type) { KGE_ASSERT(body_); body_->SetType(static_cast<b2BodyType>(type)); }
|
inline void Body::SetType(Type type) { KGE_ASSERT(body_); body_->SetType(static_cast<b2BodyType>(type)); }
|
||||||
|
|
||||||
inline float Body::GetGravityScale() const { KGE_ASSERT(body_); return body_->GetGravityScale(); }
|
inline float Body::GetGravityScale() const { KGE_ASSERT(body_); return body_->GetGravityScale(); }
|
||||||
|
|
||||||
inline void Body::SetGravityScale(float scale) { KGE_ASSERT(body_); body_->SetGravityScale(scale); }
|
inline void Body::SetGravityScale(float scale) { KGE_ASSERT(body_); body_->SetGravityScale(scale); }
|
||||||
|
|
||||||
inline bool Body::IsIgnoreRotation() const { KGE_ASSERT(body_); return body_->IsFixedRotation(); }
|
inline bool Body::IsIgnoreRotation() const { KGE_ASSERT(body_); return body_->IsFixedRotation(); }
|
||||||
|
|
||||||
inline void Body::SetIgnoreRotation(bool flag) { KGE_ASSERT(body_); body_->SetFixedRotation(flag); }
|
inline void Body::SetIgnoreRotation(bool flag) { KGE_ASSERT(body_); body_->SetFixedRotation(flag); }
|
||||||
|
|
||||||
inline bool Body::IsBullet() const { KGE_ASSERT(body_); return body_->IsBullet(); }
|
inline bool Body::IsBullet() const { KGE_ASSERT(body_); return body_->IsBullet(); }
|
||||||
|
|
||||||
inline void Body::SetBullet(bool flag) { KGE_ASSERT(body_); body_->SetBullet(flag); }
|
inline void Body::SetBullet(bool flag) { KGE_ASSERT(body_); body_->SetBullet(flag); }
|
||||||
|
|
||||||
inline bool Body::IsAwake() const { KGE_ASSERT(body_); return body_->IsAwake(); }
|
inline bool Body::IsAwake() const { KGE_ASSERT(body_); return body_->IsAwake(); }
|
||||||
|
|
||||||
inline void Body::SetAwake(bool flag) { KGE_ASSERT(body_); body_->SetAwake(flag); }
|
inline void Body::SetAwake(bool flag) { KGE_ASSERT(body_); body_->SetAwake(flag); }
|
||||||
|
|
||||||
inline bool Body::IsSleepingAllowed() const { KGE_ASSERT(body_); return body_->IsSleepingAllowed(); }
|
inline bool Body::IsSleepingAllowed() const { KGE_ASSERT(body_); return body_->IsSleepingAllowed(); }
|
||||||
|
|
||||||
inline void Body::SetSleepingAllowed(bool flag) { KGE_ASSERT(body_); body_->SetSleepingAllowed(flag); }
|
inline void Body::SetSleepingAllowed(bool flag) { KGE_ASSERT(body_); body_->SetSleepingAllowed(flag); }
|
||||||
|
|
||||||
inline bool Body::IsActive() const { KGE_ASSERT(body_); return body_->IsActive(); }
|
inline bool Body::IsActive() const { KGE_ASSERT(body_); return body_->IsActive(); }
|
||||||
|
|
||||||
inline void Body::SetActive(bool flag) { KGE_ASSERT(body_); body_->SetActive(flag); }
|
inline void Body::SetActive(bool flag) { KGE_ASSERT(body_); body_->SetActive(flag); }
|
||||||
|
|
||||||
inline Actor* Body::GetActor() const { return actor_; }
|
inline Actor* Body::GetActor() const { return actor_; }
|
||||||
|
|
||||||
inline void Body::SetActor(Actor* actor) { actor_ = actor; }
|
inline void Body::SetActor(Actor* actor) { actor_ = actor; }
|
||||||
|
|
||||||
inline b2Body* Body::GetB2Body() const { return body_; }
|
inline b2Body* Body::GetB2Body() const { return body_; }
|
||||||
|
|
||||||
inline World* Body::GetWorld() const { return world_; }
|
inline World* Body::GetWorld() const { return world_; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,28 +36,17 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Joint::Joint(b2Joint* joint)
|
|
||||||
: Joint()
|
|
||||||
{
|
|
||||||
SetB2Joint(joint);
|
|
||||||
}
|
|
||||||
|
|
||||||
Joint::Joint(World* world, b2JointDef* joint_def)
|
|
||||||
: Joint()
|
|
||||||
{
|
|
||||||
Init(world, joint_def);
|
|
||||||
}
|
|
||||||
|
|
||||||
Joint::~Joint()
|
Joint::~Joint()
|
||||||
{
|
{
|
||||||
if (world_)
|
Destroy();
|
||||||
{
|
|
||||||
world_->RemoveJoint(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joint::Init(World* world, b2JointDef* joint_def)
|
bool Joint::InitJoint(World* world, b2JointDef* joint_def)
|
||||||
{
|
{
|
||||||
|
KGE_ASSERT(world);
|
||||||
|
|
||||||
|
Destroy();
|
||||||
|
|
||||||
world_ = world;
|
world_ = world;
|
||||||
if (world_)
|
if (world_)
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +54,10 @@ namespace kiwano
|
||||||
|
|
||||||
b2Joint* joint = world_->GetB2World()->CreateJoint(joint_def);
|
b2Joint* joint = world_->GetB2World()->CreateJoint(joint_def);
|
||||||
SetB2Joint(joint);
|
SetB2Joint(joint);
|
||||||
|
|
||||||
|
return joint != nullptr;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BodyPtr Joint::GetBodyA() const
|
BodyPtr Joint::GetBodyA() const
|
||||||
|
|
@ -93,6 +85,14 @@ namespace kiwano
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Joint::Destroy()
|
||||||
|
{
|
||||||
|
if (world_)
|
||||||
|
{
|
||||||
|
world_->RemoveJoint(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// DistanceJoint
|
// DistanceJoint
|
||||||
//
|
//
|
||||||
|
|
@ -103,15 +103,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DistanceJoint::DistanceJoint(World* world, b2DistanceJointDef* def)
|
bool DistanceJoint::InitJoint(World* world, DistanceJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DistanceJoint::DistanceJoint(World* world, DistanceJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -120,8 +112,9 @@ namespace kiwano
|
||||||
def.frequencyHz = param.frequency_hz;
|
def.frequencyHz = param.frequency_hz;
|
||||||
def.dampingRatio = param.damping_ratio;
|
def.dampingRatio = param.damping_ratio;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2DistanceJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2DistanceJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DistanceJoint::SetLength(float length)
|
void DistanceJoint::SetLength(float length)
|
||||||
|
|
@ -146,15 +139,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FrictionJoint::FrictionJoint(World* world, b2FrictionJointDef* def)
|
bool FrictionJoint::InitJoint(World* world, FrictionJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FrictionJoint::FrictionJoint(World* world, FrictionJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -163,8 +148,9 @@ namespace kiwano
|
||||||
def.maxForce = param.max_force;
|
def.maxForce = param.max_force;
|
||||||
def.maxTorque = world->Stage2World(param.max_torque);
|
def.maxTorque = world->Stage2World(param.max_torque);
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2FrictionJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2FrictionJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrictionJoint::SetMaxForce(float length)
|
void FrictionJoint::SetMaxForce(float length)
|
||||||
|
|
@ -201,15 +187,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GearJoint::GearJoint(World* world, b2GearJointDef* def)
|
bool GearJoint::InitJoint(World* world, GearJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GearJoint::GearJoint(World* world, GearJoint::Param param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.joint_a && param.joint_b);
|
KGE_ASSERT(param.joint_a && param.joint_b);
|
||||||
|
|
||||||
|
|
@ -218,8 +196,9 @@ namespace kiwano
|
||||||
def.joint2 = param.joint_b->GetB2Joint();
|
def.joint2 = param.joint_b->GetB2Joint();
|
||||||
def.ratio = param.ratio;
|
def.ratio = param.ratio;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2GearJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2GearJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GearJoint::SetRatio(float ratio)
|
void GearJoint::SetRatio(float ratio)
|
||||||
|
|
@ -244,15 +223,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MotorJoint::MotorJoint(World* world, b2MotorJointDef* def)
|
bool MotorJoint::InitJoint(World* world, MotorJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
MotorJoint::MotorJoint(World* world, MotorJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -262,8 +233,9 @@ namespace kiwano
|
||||||
def.maxTorque = world->Stage2World(param.max_torque);
|
def.maxTorque = world->Stage2World(param.max_torque);
|
||||||
def.correctionFactor = param.correction_factor;
|
def.correctionFactor = param.correction_factor;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2MotorJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2MotorJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorJoint::SetMaxForce(float length)
|
void MotorJoint::SetMaxForce(float length)
|
||||||
|
|
@ -300,15 +272,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PrismaticJoint::PrismaticJoint(World* world, b2PrismaticJointDef* def)
|
bool PrismaticJoint::InitJoint(World* world, PrismaticJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PrismaticJoint::PrismaticJoint(World* world, PrismaticJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -321,8 +285,9 @@ namespace kiwano
|
||||||
def.maxMotorForce = param.max_motor_force;
|
def.maxMotorForce = param.max_motor_force;
|
||||||
def.motorSpeed = world->Stage2World(param.motor_speed);
|
def.motorSpeed = world->Stage2World(param.motor_speed);
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2PrismaticJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2PrismaticJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
float PrismaticJoint::GetJointTranslation() const
|
float PrismaticJoint::GetJointTranslation() const
|
||||||
|
|
@ -365,15 +330,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PulleyJoint::PulleyJoint(World* world, b2PulleyJointDef* def)
|
bool PulleyJoint::InitJoint(World* world, PulleyJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PulleyJoint::PulleyJoint(World* world, PulleyJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -381,8 +338,9 @@ namespace kiwano
|
||||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.ground_anchor_a), world->Stage2World(param.ground_anchor_b),
|
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.ground_anchor_a), world->Stage2World(param.ground_anchor_b),
|
||||||
world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b), param.ratio);
|
world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b), param.ratio);
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2PulleyJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2PulleyJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point PulleyJoint::GetGroundAnchorA() const
|
Point PulleyJoint::GetGroundAnchorA() const
|
||||||
|
|
@ -437,15 +395,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RevoluteJoint::RevoluteJoint(World* world, b2RevoluteJointDef* def)
|
bool RevoluteJoint::InitJoint(World* world, RevoluteJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RevoluteJoint::RevoluteJoint(World* world, RevoluteJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -458,8 +408,9 @@ namespace kiwano
|
||||||
def.maxMotorTorque = world->Stage2World(param.max_motor_torque);
|
def.maxMotorTorque = world->Stage2World(param.max_motor_torque);
|
||||||
def.motorSpeed = math::Degree2Radian(param.motor_speed);
|
def.motorSpeed = math::Degree2Radian(param.motor_speed);
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2RevoluteJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2RevoluteJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
float RevoluteJoint::GetJointAngle() const
|
float RevoluteJoint::GetJointAngle() const
|
||||||
|
|
@ -514,15 +465,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
RopeJoint::RopeJoint(World* world, b2RopeJointDef* def)
|
bool RopeJoint::InitJoint(World* world, RopeJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RopeJoint::RopeJoint(World* world, RopeJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -533,8 +476,9 @@ namespace kiwano
|
||||||
def.localAnchorB = world->Stage2World(param.local_anchor_b);
|
def.localAnchorB = world->Stage2World(param.local_anchor_b);
|
||||||
def.maxLength = world->Stage2World(param.max_length);
|
def.maxLength = world->Stage2World(param.max_length);
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2RopeJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2RopeJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RopeJoint::SetMaxLength(float length)
|
void RopeJoint::SetMaxLength(float length)
|
||||||
|
|
@ -559,15 +503,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WeldJoint::WeldJoint(World* world, b2WeldJointDef* def)
|
bool WeldJoint::InitJoint(World* world, WeldJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
WeldJoint::WeldJoint(World* world, WeldJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -576,8 +512,9 @@ namespace kiwano
|
||||||
def.frequencyHz = param.frequency_hz;
|
def.frequencyHz = param.frequency_hz;
|
||||||
def.dampingRatio = param.damping_ratio;
|
def.dampingRatio = param.damping_ratio;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2WeldJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2WeldJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -591,15 +528,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
WheelJoint::WheelJoint(World* world, b2WheelJointDef* def)
|
bool WheelJoint::InitJoint(World* world, WheelJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
WheelJoint::WheelJoint(World* world, WheelJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -611,8 +540,9 @@ namespace kiwano
|
||||||
def.frequencyHz = param.frequency_hz;
|
def.frequencyHz = param.frequency_hz;
|
||||||
def.dampingRatio = param.damping_ratio;
|
def.dampingRatio = param.damping_ratio;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2WheelJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2WheelJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
float WheelJoint::GetJointTranslation() const
|
float WheelJoint::GetJointTranslation() const
|
||||||
|
|
@ -649,15 +579,7 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseJoint::MouseJoint(World* world, b2MouseJointDef* def)
|
bool MouseJoint::InitJoint(World* world, MouseJoint::Param const& param)
|
||||||
: Joint(world, def)
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseJoint::MouseJoint(World* world, MouseJoint::Param const& param)
|
|
||||||
: Joint()
|
|
||||||
, raw_joint_(nullptr)
|
|
||||||
{
|
{
|
||||||
KGE_ASSERT(param.body_a && param.body_b);
|
KGE_ASSERT(param.body_a && param.body_b);
|
||||||
|
|
||||||
|
|
@ -669,8 +591,9 @@ namespace kiwano
|
||||||
def.frequencyHz = param.frequency_hz;
|
def.frequencyHz = param.frequency_hz;
|
||||||
def.dampingRatio = param.damping_ratio;
|
def.dampingRatio = param.damping_ratio;
|
||||||
|
|
||||||
Init(world, &def);
|
Joint::InitJoint(world, &def);
|
||||||
raw_joint_ = static_cast<b2MouseJoint*>(GetB2Joint());
|
raw_joint_ = static_cast<b2MouseJoint*>(GetB2Joint());
|
||||||
|
return raw_joint_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseJoint::SetMaxForce(float length)
|
void MouseJoint::SetMaxForce(float length)
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ namespace kiwano
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 关节
|
/// @brief 关节
|
||||||
class KGE_API Joint
|
class KGE_API Joint
|
||||||
: public virtual RefCounter
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
@ -87,13 +87,12 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
Joint();
|
Joint();
|
||||||
Joint(b2Joint* joint);
|
|
||||||
Joint(World* world, b2JointDef* joint_def);
|
|
||||||
virtual ~Joint();
|
virtual ~Joint();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 初始化关节
|
/// @brief 初始化关节
|
||||||
void Init(World* world, b2JointDef* joint_def);
|
bool InitJoint(World* world, b2JointDef* joint_def);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节连接的物体A
|
/// @brief 获取关节连接的物体A
|
||||||
|
|
@ -107,6 +106,10 @@ namespace kiwano
|
||||||
/// @brief 获取物理世界
|
/// @brief 获取物理世界
|
||||||
World* GetWorld() const;
|
World* GetWorld() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 销毁关节
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
b2Joint* GetB2Joint() const;
|
b2Joint* GetB2Joint() const;
|
||||||
void SetB2Joint(b2Joint* joint);
|
void SetB2Joint(b2Joint* joint);
|
||||||
|
|
||||||
|
|
@ -160,8 +163,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
DistanceJoint();
|
DistanceJoint();
|
||||||
DistanceJoint(World* world, b2DistanceJointDef* def);
|
|
||||||
DistanceJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节长度
|
/// @brief 设置关节长度
|
||||||
|
|
@ -229,8 +234,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
FrictionJoint();
|
FrictionJoint();
|
||||||
FrictionJoint(World* world, b2FrictionJointDef* def);
|
|
||||||
FrictionJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大摩擦力
|
/// @brief 设置最大摩擦力
|
||||||
|
|
@ -263,8 +270,8 @@ namespace kiwano
|
||||||
/// @brief 齿轮关节参数
|
/// @brief 齿轮关节参数
|
||||||
struct Param : public Joint::ParamBase
|
struct Param : public Joint::ParamBase
|
||||||
{
|
{
|
||||||
JointPtr joint_a; ///< 关节A(旋转关节/平移关节)
|
Joint* joint_a; ///< 关节A(旋转关节/平移关节)
|
||||||
JointPtr joint_b; ///< 关节B(旋转关节/平移关节)
|
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
||||||
float ratio; ///< 齿轮传动比
|
float ratio; ///< 齿轮传动比
|
||||||
|
|
||||||
Param(
|
Param(
|
||||||
|
|
@ -288,8 +295,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
GearJoint();
|
GearJoint();
|
||||||
GearJoint(World* world, b2GearJointDef* def);
|
|
||||||
GearJoint(World* world, Param param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设定齿轮传动比
|
/// @brief 设定齿轮传动比
|
||||||
|
|
@ -343,8 +352,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
MotorJoint();
|
MotorJoint();
|
||||||
MotorJoint(World* world, b2MotorJointDef* def);
|
|
||||||
MotorJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置最大摩擦力
|
/// @brief 设置最大摩擦力
|
||||||
|
|
@ -426,8 +437,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
PrismaticJoint();
|
PrismaticJoint();
|
||||||
PrismaticJoint(World* world, b2PrismaticJointDef* def);
|
|
||||||
PrismaticJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取参考角
|
/// @brief 获取参考角
|
||||||
|
|
@ -537,8 +550,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
PulleyJoint();
|
PulleyJoint();
|
||||||
PulleyJoint(World* world, b2PulleyJointDef* def);
|
|
||||||
PulleyJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 物体A对应的滑轮的位置
|
/// @brief 物体A对应的滑轮的位置
|
||||||
|
|
@ -628,8 +643,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
RevoluteJoint();
|
RevoluteJoint();
|
||||||
RevoluteJoint(World* world, b2RevoluteJointDef* def);
|
|
||||||
RevoluteJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取参考角
|
/// @brief 获取参考角
|
||||||
|
|
@ -731,8 +748,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
RopeJoint();
|
RopeJoint();
|
||||||
RopeJoint(World* world, b2RopeJointDef* def);
|
|
||||||
RopeJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设置关节最大长度
|
/// @brief 设置关节最大长度
|
||||||
|
|
@ -786,8 +805,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
WeldJoint();
|
WeldJoint();
|
||||||
WeldJoint(World* world, b2WeldJointDef* def);
|
|
||||||
WeldJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取物体B相对于物体A的角度
|
/// @brief 获取物体B相对于物体A的角度
|
||||||
|
|
@ -869,8 +890,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
WheelJoint();
|
WheelJoint();
|
||||||
WheelJoint(World* world, b2WheelJointDef* def);
|
|
||||||
WheelJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关节当前的平移距离
|
/// @brief 获取关节当前的平移距离
|
||||||
|
|
@ -970,8 +993,10 @@ namespace kiwano
|
||||||
};
|
};
|
||||||
|
|
||||||
MouseJoint();
|
MouseJoint();
|
||||||
MouseJoint(World* world, b2MouseJointDef* def);
|
|
||||||
MouseJoint(World* world, Param const& param);
|
/// \~chinese
|
||||||
|
/// @brief 初始化关节
|
||||||
|
bool InitJoint(World* world, Param const& param);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 设定最大摩擦力 [N]
|
/// @brief 设定最大摩擦力 [N]
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,10 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Actor::~Actor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Actor::Update(Duration dt)
|
void Actor::Update(Duration dt)
|
||||||
{
|
{
|
||||||
UpdateActions(this, dt);
|
UpdateActions(this, dt);
|
||||||
|
|
@ -176,35 +180,47 @@ namespace kiwano
|
||||||
if (!visible_)
|
if (!visible_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActorPtr prev;
|
// Dispatch to children those are greater than 0 in Z-Order
|
||||||
for (auto child = children_.last_item(); child; child = prev)
|
Actor* child = children_.last_item().get();
|
||||||
|
while (child)
|
||||||
{
|
{
|
||||||
prev = child->prev_item();
|
if (child->GetZOrder() < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
child->Dispatch(evt);
|
child->Dispatch(evt);
|
||||||
|
child = child->prev_item().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HandleEvent(evt);
|
||||||
|
|
||||||
|
while (child)
|
||||||
|
{
|
||||||
|
child->Dispatch(evt);
|
||||||
|
child = child->prev_item().get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Actor::HandleEvent(Event& evt)
|
||||||
|
{
|
||||||
|
EventDispatcher::Dispatch(evt);
|
||||||
|
|
||||||
if (responsible_)
|
if (responsible_)
|
||||||
{
|
{
|
||||||
if (evt.IsType<MouseMoveEvent>())
|
if (evt.IsType<MouseMoveEvent>())
|
||||||
{
|
{
|
||||||
auto& mouse_evt = evt.SafeCast<MouseMoveEvent>();
|
auto& mouse_evt = evt.SafeCast<MouseMoveEvent>();
|
||||||
if (!mouse_evt.target && ContainsPoint(mouse_evt.pos))
|
bool contains = ContainsPoint(mouse_evt.pos);
|
||||||
|
if (!hover_ && contains)
|
||||||
{
|
{
|
||||||
mouse_evt.target = this;
|
hover_ = true;
|
||||||
|
|
||||||
if (!hover_)
|
MouseHoverEvent hover;
|
||||||
{
|
hover.pos = mouse_evt.pos;
|
||||||
hover_ = true;
|
hover.left_btn_down = mouse_evt.left_btn_down;
|
||||||
|
hover.right_btn_down = mouse_evt.right_btn_down;
|
||||||
MouseHoverEvent hover;
|
EventDispatcher::Dispatch(hover);
|
||||||
hover.pos = mouse_evt.pos;
|
|
||||||
hover.left_btn_down = mouse_evt.left_btn_down;
|
|
||||||
hover.right_btn_down = mouse_evt.right_btn_down;
|
|
||||||
hover.target = this;
|
|
||||||
EventDispatcher::Dispatch(hover);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (hover_)
|
else if (hover_ && !contains)
|
||||||
{
|
{
|
||||||
hover_ = false;
|
hover_ = false;
|
||||||
pressed_ = false;
|
pressed_ = false;
|
||||||
|
|
@ -213,7 +229,6 @@ namespace kiwano
|
||||||
out.pos = mouse_evt.pos;
|
out.pos = mouse_evt.pos;
|
||||||
out.left_btn_down = mouse_evt.left_btn_down;
|
out.left_btn_down = mouse_evt.left_btn_down;
|
||||||
out.right_btn_down = mouse_evt.right_btn_down;
|
out.right_btn_down = mouse_evt.right_btn_down;
|
||||||
out.target = this;
|
|
||||||
EventDispatcher::Dispatch(out);
|
EventDispatcher::Dispatch(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -221,27 +236,22 @@ namespace kiwano
|
||||||
if (evt.IsType<MouseDownEvent>() && hover_)
|
if (evt.IsType<MouseDownEvent>() && hover_)
|
||||||
{
|
{
|
||||||
pressed_ = true;
|
pressed_ = true;
|
||||||
evt.SafeCast<MouseDownEvent>().target = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.IsType<MouseUpEvent>() && pressed_)
|
if (evt.IsType<MouseUpEvent>() && pressed_)
|
||||||
{
|
{
|
||||||
pressed_ = false;
|
pressed_ = false;
|
||||||
|
|
||||||
auto mouse_up_evt = evt.SafeCast<MouseUpEvent>();
|
auto& mouse_up_evt = evt.SafeCast<MouseUpEvent>();
|
||||||
mouse_up_evt.target = this;
|
|
||||||
|
|
||||||
MouseClickEvent click;
|
MouseClickEvent click;
|
||||||
click.pos = mouse_up_evt.pos;
|
click.pos = mouse_up_evt.pos;
|
||||||
click.left_btn_down = mouse_up_evt.left_btn_down;
|
click.left_btn_down = mouse_up_evt.left_btn_down;
|
||||||
click.right_btn_down = mouse_up_evt.right_btn_down;
|
click.right_btn_down = mouse_up_evt.right_btn_down;
|
||||||
click.target = this;
|
|
||||||
click.button = mouse_up_evt.button;
|
click.button = mouse_up_evt.button;
|
||||||
EventDispatcher::Dispatch(click);
|
EventDispatcher::Dispatch(click);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDispatcher::Dispatch(evt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix3x2 const & Actor::GetTransformMatrix() const
|
Matrix3x2 const & Actor::GetTransformMatrix() const
|
||||||
|
|
|
||||||
|
|
@ -19,14 +19,13 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/core/common.h>
|
#include <kiwano/math/math.h>
|
||||||
#include <kiwano/core/time.h>
|
#include <kiwano/core/time.h>
|
||||||
#include <kiwano/core/ObjectBase.h>
|
#include <kiwano/core/ObjectBase.h>
|
||||||
#include <kiwano/math/math.h>
|
|
||||||
#include <kiwano/2d/Transform.h>
|
|
||||||
#include <kiwano/2d/action/ActionManager.h>
|
|
||||||
#include <kiwano/core/TimerManager.h>
|
#include <kiwano/core/TimerManager.h>
|
||||||
#include <kiwano/core/EventDispatcher.h>
|
#include <kiwano/core/EventDispatcher.h>
|
||||||
|
#include <kiwano/2d/Transform.h>
|
||||||
|
#include <kiwano/2d/action/ActionManager.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -52,11 +51,11 @@ namespace kiwano
|
||||||
* @details 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
* @details 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||||
*/
|
*/
|
||||||
class KGE_API Actor
|
class KGE_API Actor
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
, public TimerManager
|
, public TimerManager
|
||||||
, public ActionManager
|
, public ActionManager
|
||||||
, public EventDispatcher
|
, public EventDispatcher
|
||||||
, public IntrusiveListItem<ActorPtr>
|
, protected IntrusiveListItem<ActorPtr>
|
||||||
{
|
{
|
||||||
friend class Director;
|
friend class Director;
|
||||||
friend class Transition;
|
friend class Transition;
|
||||||
|
|
@ -73,6 +72,8 @@ namespace kiwano
|
||||||
|
|
||||||
Actor();
|
Actor();
|
||||||
|
|
||||||
|
virtual ~Actor();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 更新角色
|
/// @brief 更新角色
|
||||||
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
/// @details 每帧画面刷新前调用该函数,重载该函数以实现角色的更新处理
|
||||||
|
|
@ -117,34 +118,6 @@ namespace kiwano
|
||||||
/// @brief 获取 y 坐标
|
/// @brief 获取 y 坐标
|
||||||
float GetPositionY() const;
|
float GetPositionY() const;
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取缩放比例
|
|
||||||
Point const& GetScale() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取横向缩放比例
|
|
||||||
float GetScaleX() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取纵向缩放比例
|
|
||||||
float GetScaleY() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取错切角度
|
|
||||||
Point const& GetSkew() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取横向错切角度
|
|
||||||
float GetSkewX() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取纵向错切角度
|
|
||||||
float GetSkewY() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取旋转角度
|
|
||||||
float GetRotation() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取宽度
|
/// @brief 获取宽度
|
||||||
float GetWidth() const;
|
float GetWidth() const;
|
||||||
|
|
@ -189,6 +162,34 @@ namespace kiwano
|
||||||
/// @brief 获取显示透明度
|
/// @brief 获取显示透明度
|
||||||
float GetDisplayedOpacity() const;
|
float GetDisplayedOpacity() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取旋转角度
|
||||||
|
float GetRotation() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取缩放比例
|
||||||
|
Point const& GetScale() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取横向缩放比例
|
||||||
|
float GetScaleX() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取纵向缩放比例
|
||||||
|
float GetScaleY() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取错切角度
|
||||||
|
Point const& GetSkew() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取横向错切角度
|
||||||
|
float GetSkewX() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取纵向错切角度
|
||||||
|
float GetSkewY() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取变换
|
/// @brief 获取变换
|
||||||
Transform GetTransform() const;
|
Transform GetTransform() const;
|
||||||
|
|
@ -362,10 +363,6 @@ namespace kiwano
|
||||||
/// @brief 从父角色移除
|
/// @brief 从父角色移除
|
||||||
void RemoveFromParent();
|
void RemoveFromParent();
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 判断点是否在角色内
|
|
||||||
virtual bool ContainsPoint(const Point& point) const;
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 暂停角色更新
|
/// @brief 暂停角色更新
|
||||||
void PauseUpdating();
|
void PauseUpdating();
|
||||||
|
|
@ -386,6 +383,10 @@ namespace kiwano
|
||||||
/// @brief 获取更新时的回调函数
|
/// @brief 获取更新时的回调函数
|
||||||
UpdateCallback GetCallbackOnUpdate() const;
|
UpdateCallback GetCallbackOnUpdate() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 判断点是否在角色内
|
||||||
|
virtual bool ContainsPoint(const Point& point) const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 渲染角色边界
|
/// @brief 渲染角色边界
|
||||||
void ShowBorder(bool show);
|
void ShowBorder(bool show);
|
||||||
|
|
@ -435,6 +436,10 @@ namespace kiwano
|
||||||
/// @brief 设置节点所在舞台
|
/// @brief 设置节点所在舞台
|
||||||
void SetStage(Stage* stage);
|
void SetStage(Stage* stage);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 处理事件
|
||||||
|
void HandleEvent(Event& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool visible_;
|
bool visible_;
|
||||||
bool update_pausing_;
|
bool update_pausing_;
|
||||||
|
|
|
||||||
|
|
@ -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/ui/Button.h>
|
#include <kiwano/2d/Button.h>
|
||||||
#include <kiwano/2d/Stage.h>
|
#include <kiwano/2d/Stage.h>
|
||||||
#include <kiwano/platform/Window.h>
|
#include <kiwano/platform/Window.h>
|
||||||
|
|
||||||
|
|
@ -26,16 +26,8 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
Button::Button()
|
Button::Button()
|
||||||
: enabled_(true)
|
: enabled_(true)
|
||||||
, is_selected_(false)
|
|
||||||
, click_callback_(nullptr)
|
|
||||||
, status_(Status::Normal)
|
, status_(Status::Normal)
|
||||||
{
|
{
|
||||||
SetResponsible(true);
|
|
||||||
|
|
||||||
AddListener<MouseHoverEvent>(Closure(this, &Button::UpdateStatus));
|
|
||||||
AddListener<MouseOutEvent>(Closure(this, &Button::UpdateStatus));
|
|
||||||
AddListener<MouseDownEvent>(Closure(this, &Button::UpdateStatus));
|
|
||||||
AddListener<MouseUpEvent>(Closure(this, &Button::UpdateStatus));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(const Callback& click)
|
Button::Button(const Callback& click)
|
||||||
|
|
@ -99,50 +91,119 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
if (status_ != status)
|
if (status_ != status)
|
||||||
{
|
{
|
||||||
status_ = status;
|
Status old_status = status_;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::UpdateStatus(Event& evt)
|
if (status == Status::Normal)
|
||||||
{
|
|
||||||
KGE_ASSERT(evt.IsType<MouseEvent>());
|
|
||||||
|
|
||||||
if (enabled_ && (evt.SafeCast<MouseEvent>().target == this))
|
|
||||||
{
|
|
||||||
if (evt.IsType<MouseHoverEvent>())
|
|
||||||
{
|
{
|
||||||
SetStatus(Status::Hover);
|
|
||||||
Window::instance().SetCursor(CursorType::Hand);
|
|
||||||
|
|
||||||
if (mouse_over_callback_)
|
|
||||||
mouse_over_callback_(this);
|
|
||||||
}
|
|
||||||
else if (evt.IsType<MouseOutEvent>())
|
|
||||||
{
|
|
||||||
SetStatus(Status::Normal);
|
|
||||||
Window::instance().SetCursor(CursorType::Arrow);
|
Window::instance().SetCursor(CursorType::Arrow);
|
||||||
|
|
||||||
if (mouse_out_callback_)
|
if (mouse_out_callback_)
|
||||||
mouse_out_callback_(this);
|
mouse_out_callback_(this);
|
||||||
}
|
}
|
||||||
else if (evt.IsType<MouseDownEvent>() && status_ == Status::Hover)
|
else if (status == Status::Hover)
|
||||||
{
|
{
|
||||||
SetStatus(Status::Pressed);
|
Window::instance().SetCursor(CursorType::Hand);
|
||||||
|
|
||||||
|
if (old_status == Status::Pressed)
|
||||||
|
{
|
||||||
|
if (released_callback_)
|
||||||
|
released_callback_(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mouse_over_callback_)
|
||||||
|
mouse_over_callback_(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (status == Status::Pressed)
|
||||||
|
{
|
||||||
if (pressed_callback_)
|
if (pressed_callback_)
|
||||||
pressed_callback_(this);
|
pressed_callback_(this);
|
||||||
}
|
}
|
||||||
else if (evt.IsType<MouseUpEvent>() && status_ == Status::Pressed)
|
|
||||||
{
|
|
||||||
SetStatus(Status::Hover);
|
|
||||||
|
|
||||||
if (released_callback_)
|
status_ = status;
|
||||||
released_callback_(this);
|
|
||||||
|
|
||||||
if (click_callback_)
|
|
||||||
click_callback_(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button::Status Button::GetStatus() const
|
||||||
|
{
|
||||||
|
return status_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::UpdateStatus(Event& evt)
|
||||||
|
{
|
||||||
|
if (!enabled_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (evt.IsType<MouseHoverEvent>())
|
||||||
|
{
|
||||||
|
SetStatus(Status::Hover);
|
||||||
|
}
|
||||||
|
else if (evt.IsType<MouseOutEvent>())
|
||||||
|
{
|
||||||
|
SetStatus(Status::Normal);
|
||||||
|
}
|
||||||
|
else if (evt.IsType<MouseDownEvent>() && status_ == Status::Hover)
|
||||||
|
{
|
||||||
|
SetStatus(Status::Pressed);
|
||||||
|
}
|
||||||
|
else if (evt.IsType<MouseUpEvent>() && status_ == Status::Pressed)
|
||||||
|
{
|
||||||
|
SetStatus(Status::Hover);
|
||||||
|
}
|
||||||
|
else if (evt.IsType<MouseClickEvent>())
|
||||||
|
{
|
||||||
|
if (click_callback_)
|
||||||
|
click_callback_(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpriteButton::SpriteButton()
|
||||||
|
: SpriteButton(nullptr, nullptr, nullptr, nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteButton::SpriteButton(Callback const& click)
|
||||||
|
: SpriteButton(click, nullptr, nullptr, nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpriteButton::SpriteButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out)
|
||||||
|
: Button(click, pressed, mouse_over, mouse_out)
|
||||||
|
{
|
||||||
|
SetResponsible(true);
|
||||||
|
|
||||||
|
EventListener::Callback handler = Closure(this, &SpriteButton::UpdateStatus);
|
||||||
|
AddListener<MouseHoverEvent>(handler);
|
||||||
|
AddListener<MouseOutEvent>(handler);
|
||||||
|
AddListener<MouseDownEvent>(handler);
|
||||||
|
AddListener<MouseUpEvent>(handler);
|
||||||
|
AddListener<MouseClickEvent>(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TextButton::TextButton()
|
||||||
|
: TextButton(nullptr, nullptr, nullptr, nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TextButton::TextButton(Callback const& click)
|
||||||
|
: TextButton(click, nullptr, nullptr, nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TextButton::TextButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out)
|
||||||
|
: Button(click, pressed, mouse_over, mouse_out)
|
||||||
|
{
|
||||||
|
SetResponsible(true);
|
||||||
|
|
||||||
|
EventListener::Callback handler = Closure(this, &TextButton::UpdateStatus);
|
||||||
|
AddListener<MouseHoverEvent>(handler);
|
||||||
|
AddListener<MouseOutEvent>(handler);
|
||||||
|
AddListener<MouseDownEvent>(handler);
|
||||||
|
AddListener<MouseUpEvent>(handler);
|
||||||
|
AddListener<MouseClickEvent>(handler);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -20,17 +20,20 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Sprite.h>
|
#include <kiwano/2d/Sprite.h>
|
||||||
|
#include <kiwano/2d/TextActor.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
KGE_DECLARE_SMART_PTR(Button);
|
KGE_DECLARE_SMART_PTR(Button);
|
||||||
|
KGE_DECLARE_SMART_PTR(SpriteButton);
|
||||||
|
KGE_DECLARE_SMART_PTR(TextButton);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 按钮
|
* @brief 按钮
|
||||||
*/
|
*/
|
||||||
class KGE_API Button
|
class KGE_API Button
|
||||||
: public Sprite
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
@ -45,7 +48,7 @@ namespace kiwano
|
||||||
explicit Button(Callback const& click);
|
explicit Button(Callback const& click);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取按钮状态是启用还是禁用
|
/// @brief 构造按钮
|
||||||
/// @param click 按钮点击回调函数
|
/// @param click 按钮点击回调函数
|
||||||
/// @param pressed 按钮按下回调函数
|
/// @param pressed 按钮按下回调函数
|
||||||
/// @param mouse_over 按钮移入回调函数
|
/// @param mouse_over 按钮移入回调函数
|
||||||
|
|
@ -82,16 +85,30 @@ namespace kiwano
|
||||||
/// @brief 设置鼠标移出按钮时的回调函数
|
/// @brief 设置鼠标移出按钮时的回调函数
|
||||||
void SetMouseOutCallback(const Callback& func);
|
void SetMouseOutCallback(const Callback& func);
|
||||||
|
|
||||||
private:
|
/// \~chinese
|
||||||
enum class Status { Normal, Hover, Pressed };
|
/// @brief 按钮状态
|
||||||
|
enum class Status
|
||||||
|
{
|
||||||
|
Normal, ///< 普通
|
||||||
|
Hover, ///< 鼠标在按钮内
|
||||||
|
Pressed ///< 被按下
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 设置按钮状态
|
||||||
void SetStatus(Status status);
|
void SetStatus(Status status);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取按钮状态
|
||||||
|
Status GetStatus() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 更新按钮状态
|
||||||
void UpdateStatus(Event& evt);
|
void UpdateStatus(Event& evt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool enabled_;
|
bool enabled_;
|
||||||
bool is_selected_;
|
|
||||||
Status status_;
|
Status status_;
|
||||||
Callback click_callback_;
|
Callback click_callback_;
|
||||||
Callback pressed_callback_;
|
Callback pressed_callback_;
|
||||||
|
|
@ -99,4 +116,52 @@ namespace kiwano
|
||||||
Callback mouse_over_callback_;
|
Callback mouse_over_callback_;
|
||||||
Callback mouse_out_callback_;
|
Callback mouse_out_callback_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 精灵按钮
|
||||||
|
class SpriteButton
|
||||||
|
: public Sprite
|
||||||
|
, public Button
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SpriteButton();
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造精灵按钮
|
||||||
|
/// @param click 按钮点击回调函数
|
||||||
|
explicit SpriteButton(Callback const& click);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造精灵按钮
|
||||||
|
/// @param click 按钮点击回调函数
|
||||||
|
/// @param pressed 按钮按下回调函数
|
||||||
|
/// @param mouse_over 按钮移入回调函数
|
||||||
|
/// @param mouse_out 按钮移出回调函数
|
||||||
|
SpriteButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 文字按钮
|
||||||
|
class TextButton
|
||||||
|
: public TextActor
|
||||||
|
, public Button
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextButton();
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造文字按钮
|
||||||
|
/// @param click 按钮点击回调函数
|
||||||
|
explicit TextButton(Callback const& click);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 构造文字按钮
|
||||||
|
/// @param click 按钮点击回调函数
|
||||||
|
/// @param pressed 按钮按下回调函数
|
||||||
|
/// @param mouse_over 按钮移入回调函数
|
||||||
|
/// @param mouse_out 按钮移出回调函数
|
||||||
|
TextButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -42,8 +42,6 @@ namespace kiwano
|
||||||
return "\03";
|
return "\03";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::locale comma_locale(std::locale(), new comma_numpunct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugActor::DebugActor()
|
DebugActor::DebugActor()
|
||||||
|
|
@ -53,20 +51,21 @@ namespace kiwano
|
||||||
SetResponsible(true);
|
SetResponsible(true);
|
||||||
SetCascadeOpacityEnabled(true);
|
SetCascadeOpacityEnabled(true);
|
||||||
|
|
||||||
|
comma_locale_ = std::locale(std::locale(), new comma_numpunct);
|
||||||
|
|
||||||
background_brush_ = new Brush;
|
background_brush_ = new Brush;
|
||||||
background_brush_->SetColor(Color(0.0f, 0.0f, 0.0f, 0.7f));
|
background_brush_->SetColor(Color(0.0f, 0.0f, 0.0f, 0.7f));
|
||||||
|
|
||||||
debug_text_ = new TextActor;
|
BrushPtr fill_brush = new Brush;
|
||||||
debug_text_->SetPosition(Point{ 10, 10 });
|
fill_brush->SetColor(Color::White);
|
||||||
this->AddChild(debug_text_);
|
|
||||||
|
|
||||||
TextStyle style;
|
TextStyle style;
|
||||||
style.font_family = L"Arial";
|
style.font_family = L"Arial";
|
||||||
style.font_size = 16.f;
|
style.font_size = 16.f;
|
||||||
style.font_weight = FontWeight::Normal;
|
style.font_weight = FontWeight::Normal;
|
||||||
style.line_spacing = 20.f;
|
style.line_spacing = 20.f;
|
||||||
debug_text_->SetStyle(style);
|
style.fill_brush = fill_brush;
|
||||||
debug_text_->SetFillColor(Color::White);
|
debug_text_.SetStyle(style);
|
||||||
|
|
||||||
AddListener<MouseHoverEvent>([=](Event&) { SetOpacity(0.4f); });
|
AddListener<MouseHoverEvent>([=](Event&) { SetOpacity(0.4f); });
|
||||||
AddListener<MouseOutEvent>([=](Event&) { SetOpacity(1.f); });
|
AddListener<MouseOutEvent>([=](Event&) { SetOpacity(1.f); });
|
||||||
|
|
@ -80,6 +79,8 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
rt->SetCurrentBrush(background_brush_);
|
rt->SetCurrentBrush(background_brush_);
|
||||||
rt->FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f });
|
rt->FillRoundedRectangle(GetBounds(), Vec2{ 5.f, 5.f });
|
||||||
|
|
||||||
|
rt->DrawTextLayout(debug_text_, Point(10, 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugActor::OnUpdate(Duration dt)
|
void DebugActor::OnUpdate(Duration dt)
|
||||||
|
|
@ -95,7 +96,7 @@ namespace kiwano
|
||||||
StringStream ss;
|
StringStream ss;
|
||||||
|
|
||||||
// For formatting integers with commas
|
// For formatting integers with commas
|
||||||
(void)ss.imbue(comma_locale);
|
(void)ss.imbue(comma_locale_);
|
||||||
|
|
||||||
ss << "Fps: " << frame_time_.size() << std::endl;
|
ss << "Fps: " << frame_time_.size() << std::endl;
|
||||||
|
|
||||||
|
|
@ -124,16 +125,18 @@ namespace kiwano
|
||||||
ss << pmc.PrivateUsage / 1024 << "Kb";
|
ss << pmc.PrivateUsage / 1024 << "Kb";
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_text_->SetText(ss.str());
|
debug_text_.SetText(ss.str());
|
||||||
|
debug_text_.Update();
|
||||||
|
|
||||||
if (debug_text_->GetWidth() > GetWidth() - 20)
|
Size layout_size = debug_text_.GetLayoutSize();
|
||||||
|
if (layout_size.x > GetWidth() - 20)
|
||||||
{
|
{
|
||||||
SetWidth(20 + debug_text_->GetWidth());
|
SetWidth(20 + layout_size.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug_text_->GetHeight() > GetHeight() - 20)
|
if (layout_size.y > GetHeight() - 20)
|
||||||
{
|
{
|
||||||
SetHeight(20 + debug_text_->GetHeight());
|
SetHeight(20 + layout_size.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <kiwano/2d/Actor.h>
|
#include <kiwano/2d/Actor.h>
|
||||||
#include <kiwano/2d/TextActor.h>
|
#include <kiwano/renderer/TextLayout.h>
|
||||||
#include <kiwano/renderer/Color.h>
|
|
||||||
#include <kiwano/renderer/Brush.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
@ -51,8 +49,9 @@ namespace kiwano
|
||||||
bool CheckVisibilty(RenderTarget* rt) const override;
|
bool CheckVisibilty(RenderTarget* rt) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::locale comma_locale_;
|
||||||
BrushPtr background_brush_;
|
BrushPtr background_brush_;
|
||||||
TextActorPtr debug_text_;
|
TextLayout debug_text_;
|
||||||
Vector<Time> frame_time_;
|
Vector<Time> frame_time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
||||||
* @brief ͼÏñÖ¡
|
* @brief ͼÏñÖ¡
|
||||||
*/
|
*/
|
||||||
class KGE_API Frame
|
class KGE_API Frame
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace kiwano
|
||||||
* @brief ÐòÁÐÖ¡
|
* @brief ÐòÁÐÖ¡
|
||||||
*/
|
*/
|
||||||
class KGE_API FrameSequence
|
class KGE_API FrameSequence
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,10 @@ namespace kiwano
|
||||||
/// @brief 获取文本布局
|
/// @brief 获取文本布局
|
||||||
const TextLayout& GetLayout() const;
|
const TextLayout& GetLayout() const;
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 获取文本布局大小
|
||||||
|
Size GetLayoutSize() const;
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取填充画刷
|
/// @brief 获取填充画刷
|
||||||
BrushPtr GetFillBrush() const;
|
BrushPtr GetFillBrush() const;
|
||||||
|
|
@ -201,6 +205,11 @@ namespace kiwano
|
||||||
return text_layout_;
|
return text_layout_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Size TextActor::GetLayoutSize() const
|
||||||
|
{
|
||||||
|
return text_layout_.GetLayoutSize();
|
||||||
|
}
|
||||||
|
|
||||||
inline BrushPtr TextActor::GetFillBrush() const
|
inline BrushPtr TextActor::GetFillBrush() const
|
||||||
{
|
{
|
||||||
return text_layout_.GetFillBrush();
|
return text_layout_.GetFillBrush();
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace kiwano
|
||||||
* @brief 舞台过渡动画
|
* @brief 舞台过渡动画
|
||||||
*/
|
*/
|
||||||
class KGE_API Transition
|
class KGE_API Transition
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class Director;
|
friend class Director;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ namespace kiwano
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 动画
|
/// @brief 动画
|
||||||
class KGE_API Action
|
class KGE_API Action
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
, protected IntrusiveListItem<ActionPtr>
|
, protected IntrusiveListItem<ActionPtr>
|
||||||
{
|
{
|
||||||
friend class ActionManager;
|
friend class ActionManager;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace kiwano
|
||||||
/// task->Start();
|
/// task->Start();
|
||||||
/// @endcode
|
/// @endcode
|
||||||
class AsyncTask
|
class AsyncTask
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace kiwano
|
||||||
* @brief 事件监听器
|
* @brief 事件监听器
|
||||||
*/
|
*/
|
||||||
class KGE_API EventListener
|
class KGE_API EventListener
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
, protected IntrusiveListItem<EventListenerPtr>
|
, protected IntrusiveListItem<EventListenerPtr>
|
||||||
{
|
{
|
||||||
friend class EventDispatcher;
|
friend class EventDispatcher;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace kiwano
|
||||||
* @brief 基础对象
|
* @brief 基础对象
|
||||||
*/
|
*/
|
||||||
class KGE_API ObjectBase
|
class KGE_API ObjectBase
|
||||||
: public virtual RefCounter
|
: public RefCounter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace kiwano
|
||||||
/// @brief 定时器
|
/// @brief 定时器
|
||||||
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
/// @details 定时器用于每隔一段时间执行一次回调函数,且可以指定执行总次数
|
||||||
class KGE_API Timer
|
class KGE_API Timer
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
, protected IntrusiveListItem<TimerPtr>
|
, protected IntrusiveListItem<TimerPtr>
|
||||||
{
|
{
|
||||||
friend class TimerManager;
|
friend class TimerManager;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ namespace kiwano
|
||||||
, pos()
|
, pos()
|
||||||
, left_btn_down(false)
|
, left_btn_down(false)
|
||||||
, right_btn_down(false)
|
, right_btn_down(false)
|
||||||
, target(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
class Actor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \addtogroup Events
|
* \addtogroup Events
|
||||||
* @{
|
* @{
|
||||||
|
|
@ -41,7 +39,6 @@ namespace kiwano
|
||||||
Point pos; ///< 鼠标位置
|
Point pos; ///< 鼠标位置
|
||||||
bool left_btn_down; ///< 鼠标左键是否按下
|
bool left_btn_down; ///< 鼠标左键是否按下
|
||||||
bool right_btn_down; ///< 鼠标右键是否按下
|
bool right_btn_down; ///< 鼠标右键是否按下
|
||||||
Actor* target; ///< Äżąę
|
|
||||||
|
|
||||||
MouseEvent(EventType const& type);
|
MouseEvent(EventType const& type);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
#include <kiwano/2d/GifSprite.h>
|
#include <kiwano/2d/GifSprite.h>
|
||||||
#include <kiwano/2d/TextActor.h>
|
#include <kiwano/2d/TextActor.h>
|
||||||
#include <kiwano/2d/Canvas.h>
|
#include <kiwano/2d/Canvas.h>
|
||||||
|
#include <kiwano/2d/Button.h>
|
||||||
#include <kiwano/2d/ShapeActor.h>
|
#include <kiwano/2d/ShapeActor.h>
|
||||||
#include <kiwano/2d/DebugActor.h>
|
#include <kiwano/2d/DebugActor.h>
|
||||||
|
|
||||||
|
|
@ -122,11 +123,3 @@
|
||||||
#include <kiwano/utils/UserData.h>
|
#include <kiwano/utils/UserData.h>
|
||||||
#include <kiwano/utils/LocalStorage.h>
|
#include <kiwano/utils/LocalStorage.h>
|
||||||
#include <kiwano/utils/ResourceCache.h>
|
#include <kiwano/utils/ResourceCache.h>
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// ui
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <kiwano/ui/Button.h>
|
|
||||||
#include <kiwano/ui/Menu.h>
|
|
||||||
|
|
|
||||||
|
|
@ -181,11 +181,14 @@ namespace kiwano
|
||||||
|
|
||||||
void Director::HandleEvent(Event& evt)
|
void Director::HandleEvent(Event& evt)
|
||||||
{
|
{
|
||||||
if (debug_actor_)
|
|
||||||
debug_actor_->Dispatch(evt);
|
|
||||||
|
|
||||||
if (current_stage_)
|
if (current_stage_)
|
||||||
current_stage_->Dispatch(evt);
|
current_stage_->Dispatch(evt);
|
||||||
|
|
||||||
|
if (next_stage_)
|
||||||
|
next_stage_->Dispatch(evt);
|
||||||
|
|
||||||
|
if (debug_actor_)
|
||||||
|
debug_actor_->Dispatch(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,25 +84,23 @@ namespace kiwano
|
||||||
{
|
{
|
||||||
auto solid_brush = dynamic_cast<ID2D1SolidColorBrush*>(raw_.get());
|
auto solid_brush = dynamic_cast<ID2D1SolidColorBrush*>(raw_.get());
|
||||||
KGE_ASSERT(solid_brush != nullptr);
|
KGE_ASSERT(solid_brush != nullptr);
|
||||||
|
|
||||||
solid_brush->SetColor(DX::ConvertToColorF(color));
|
solid_brush->SetColor(DX::ConvertToColorF(color));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Renderer::instance().CreateSolidBrush(*this, color);
|
Renderer::instance().CreateSolidBrush(*this, color);
|
||||||
type_ = Type::SolidColor;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Brush::SetStyle(LinearGradientStyle const& style)
|
void Brush::SetStyle(LinearGradientStyle const& style)
|
||||||
{
|
{
|
||||||
Renderer::instance().CreateLinearGradientBrush(*this, style.begin, style.end, style.stops, style.extend_mode);
|
Renderer::instance().CreateLinearGradientBrush(*this, style.begin, style.end, style.stops, style.extend_mode);
|
||||||
type_ = Type::LinearGradient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Brush::SetStyle(RadialGradientStyle const& style)
|
void Brush::SetStyle(RadialGradientStyle const& style)
|
||||||
{
|
{
|
||||||
Renderer::instance().CreateRadialGradientBrush(*this, style.center, style.offset, style.radius, style.stops, style.extend_mode);
|
Renderer::instance().CreateRadialGradientBrush(*this, style.center, style.offset, style.radius, style.stops, style.extend_mode);
|
||||||
type_ = Type::RadialGradient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Brush::SetBrush(ComPtr<ID2D1Brush> brush, Type type)
|
void Brush::SetBrush(ComPtr<ID2D1Brush> brush, Type type)
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ namespace kiwano
|
||||||
* @brief »Ë¢
|
* @brief »Ë¢
|
||||||
*/
|
*/
|
||||||
class KGE_API Brush
|
class KGE_API Brush
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class RenderTarget;
|
friend class RenderTarget;
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace kiwano
|
||||||
* @brief ×ÖÌå
|
* @brief ×ÖÌå
|
||||||
*/
|
*/
|
||||||
class Font
|
class Font
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace kiwano
|
||||||
* @brief GIFͼÏñ
|
* @brief GIFͼÏñ
|
||||||
*/
|
*/
|
||||||
class KGE_API GifImage
|
class KGE_API GifImage
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace kiwano
|
||||||
/// @brief 渲染目标
|
/// @brief 渲染目标
|
||||||
/// @details 渲染目标将完成基础图元的绘制,并将绘制结果输出到特定的目标中(如窗口或纹理)
|
/// @details 渲染目标将完成基础图元的绘制,并将绘制结果输出到特定的目标中(如窗口或纹理)
|
||||||
class KGE_API RenderTarget
|
class KGE_API RenderTarget
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -870,15 +870,15 @@ namespace kiwano
|
||||||
hr = E_UNEXPECTED;
|
hr = E_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComPtr<ID2D1SolidColorBrush> output;
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
|
ComPtr<ID2D1SolidColorBrush> output;
|
||||||
hr = d2d_res_->GetDeviceContext()->CreateSolidColorBrush(DX::ConvertToColorF(color), &output);
|
hr = d2d_res_->GetDeviceContext()->CreateSolidColorBrush(DX::ConvertToColorF(color), &output);
|
||||||
}
|
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
brush.SetBrush(output, Brush::Type::SolidColor);
|
brush.SetBrush(output, Brush::Type::SolidColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
win32::ThrowIfFailed(hr);
|
win32::ThrowIfFailed(hr);
|
||||||
|
|
@ -894,7 +894,7 @@ namespace kiwano
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
ID2D1GradientStopCollection* collection = nullptr;
|
ComPtr<ID2D1GradientStopCollection> collection;
|
||||||
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
||||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
||||||
UINT32(stops.size()),
|
UINT32(stops.size()),
|
||||||
|
|
@ -911,7 +911,7 @@ namespace kiwano
|
||||||
DX::ConvertToPoint2F(begin),
|
DX::ConvertToPoint2F(begin),
|
||||||
DX::ConvertToPoint2F(end)
|
DX::ConvertToPoint2F(end)
|
||||||
),
|
),
|
||||||
collection,
|
collection.get(),
|
||||||
&output
|
&output
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -936,7 +936,7 @@ namespace kiwano
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
ID2D1GradientStopCollection* collection = nullptr;
|
ComPtr<ID2D1GradientStopCollection> collection;
|
||||||
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
hr = d2d_res_->GetDeviceContext()->CreateGradientStopCollection(
|
||||||
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
reinterpret_cast<const D2D1_GRADIENT_STOP*>(&stops[0]),
|
||||||
UINT32(stops.size()),
|
UINT32(stops.size()),
|
||||||
|
|
@ -955,7 +955,7 @@ namespace kiwano
|
||||||
radius.x,
|
radius.x,
|
||||||
radius.y
|
radius.y
|
||||||
),
|
),
|
||||||
collection,
|
collection.get(),
|
||||||
&output
|
&output
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace kiwano
|
||||||
* @brief 纹理
|
* @brief 纹理
|
||||||
*/
|
*/
|
||||||
class KGE_API Texture
|
class KGE_API Texture
|
||||||
: public ObjectBase
|
: public virtual ObjectBase
|
||||||
{
|
{
|
||||||
friend class RenderTarget;
|
friend class RenderTarget;
|
||||||
friend class TextureRenderTarget;
|
friend class TextureRenderTarget;
|
||||||
|
|
|
||||||
|
|
@ -1,91 +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.
|
|
||||||
|
|
||||||
#include <kiwano/ui/Menu.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
|
||||||
{
|
|
||||||
Menu::Menu()
|
|
||||||
: enabled_(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Menu::IsEnable() const
|
|
||||||
{
|
|
||||||
return enabled_;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Menu::GetButtonCount() const
|
|
||||||
{
|
|
||||||
return buttons_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::SetEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (enabled_ != enabled)
|
|
||||||
{
|
|
||||||
enabled_ = enabled;
|
|
||||||
|
|
||||||
for (auto& button : buttons_)
|
|
||||||
{
|
|
||||||
button->SetEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menu::AddButton(ButtonPtr button)
|
|
||||||
{
|
|
||||||
if (button)
|
|
||||||
{
|
|
||||||
this->AddChild(button);
|
|
||||||
buttons_.push_back(button);
|
|
||||||
button->SetEnabled(enabled_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Menu::RemoveButton(ButtonPtr button)
|
|
||||||
{
|
|
||||||
if (buttons_.empty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->RemoveChild(button);
|
|
||||||
|
|
||||||
if (button)
|
|
||||||
{
|
|
||||||
auto iter = std::find(buttons_.begin(), buttons_.end(), button);
|
|
||||||
if (iter != buttons_.end())
|
|
||||||
{
|
|
||||||
// ÒÆ³ý°´Å¥Ç°£¬½«ËüÆôÓÃ
|
|
||||||
button->SetEnabled(true);
|
|
||||||
buttons_.erase(iter);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<ButtonPtr> const& Menu::GetAllButtons() const
|
|
||||||
{
|
|
||||||
return buttons_;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +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/ui/Button.h>
|
|
||||||
|
|
||||||
namespace kiwano
|
|
||||||
{
|
|
||||||
KGE_DECLARE_SMART_PTR(Menu);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \~chinese
|
|
||||||
* @brief 菜单,用于管理多个按钮
|
|
||||||
*/
|
|
||||||
class KGE_API Menu
|
|
||||||
: public Actor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Menu();
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取菜单是否禁用
|
|
||||||
bool IsEnable() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取菜单中的按钮数量
|
|
||||||
size_t GetButtonCount() const;
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 设置菜单启用或禁用
|
|
||||||
void SetEnabled(bool enabled);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 添加按钮
|
|
||||||
void AddButton(ButtonPtr button);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 移除按钮
|
|
||||||
bool RemoveButton(ButtonPtr button);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 获取所有按钮
|
|
||||||
Vector<ButtonPtr> const& GetAllButtons() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool enabled_;
|
|
||||||
Vector<ButtonPtr> buttons_;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue