Magic_Game/src/kiwano/2d/Component.h

140 lines
3.0 KiB
C
Raw Normal View History

2020-02-18 12:53:18 +08:00
// 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/core/Time.h>
2020-05-24 11:26:21 +08:00
#include <kiwano/base/ObjectBase.h>
2020-02-18 12:53:18 +08:00
#include <kiwano/core/IntrusiveList.h>
2020-02-23 14:56:14 +08:00
#include <kiwano/render/RenderContext.h>
2020-02-18 12:53:18 +08:00
namespace kiwano
{
class Actor;
class Event;
KGE_DECLARE_SMART_PTR(Component);
2020-04-16 10:06:36 +08:00
/**
* \~chinese
* \defgroup Component <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
/**
* \addtogroup Component
* @{
*/
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
2020-02-18 12:53:18 +08:00
typedef IntrusiveList<ComponentPtr> ComponentList;
/**
* \~chinese
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-02-18 12:53:18 +08:00
*/
class KGE_API Component
: public ObjectBase
2020-02-18 12:53:18 +08:00
, protected IntrusiveListValue<ComponentPtr>
{
friend class Actor;
friend IntrusiveList<ComponentPtr>;
public:
/// \~chinese
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool IsEnable() const;
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
void SetEnabled(bool enabled);
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD>󶨵Ľ<F3B6A8B5>ɫ
2020-02-18 12:53:18 +08:00
Actor* GetBoundActor() const;
/// \~chinese
/// @brief <20>ӽ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>Ƴ<EFBFBD>
void RemoveFromActor();
2020-02-18 12:53:18 +08:00
protected:
Component();
virtual ~Component();
/// \~chinese
/// @brief <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void InitComponent(Actor* actor);
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void DestroyComponent();
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
virtual void OnUpdate(Duration dt);
2020-02-23 14:56:14 +08:00
/// \~chinese
/// @brief <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
2020-02-23 14:56:14 +08:00
virtual void OnRender(RenderContext& ctx);
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD>¼<EFBFBD>
2020-02-18 12:53:18 +08:00
virtual void HandleEvent(Event* evt);
private:
bool enabled_;
2020-02-18 12:53:18 +08:00
Actor* actor_;
};
2020-04-16 10:06:36 +08:00
/** @} */
inline bool Component::IsEnable() const
{
return enabled_;
}
inline void Component::SetEnabled(bool enabled)
{
enabled_ = enabled;
}
2020-02-18 12:53:18 +08:00
inline Actor* Component::GetBoundActor() const
{
return actor_;
}
inline void Component::OnUpdate(Duration dt)
{
KGE_NOT_USED(dt);
}
2020-02-23 14:56:14 +08:00
inline void Component::OnRender(RenderContext& ctx)
{
KGE_NOT_USED(ctx);
}
inline void Component::HandleEvent(Event* evt)
2020-02-18 12:53:18 +08:00
{
2020-02-23 14:56:14 +08:00
KGE_NOT_USED(evt);
2020-02-18 12:53:18 +08:00
}
} // namespace kiwano