update Shape

This commit is contained in:
Nomango 2018-04-01 00:04:33 +08:00
parent dee2010e7c
commit 486ca4f848
12 changed files with 174 additions and 140 deletions

View File

@ -1,12 +1,12 @@
#include "..\eactions.h"
e2d::ActionSequence::ActionSequence() :
m_nActionIndex(0)
e2d::ActionSequence::ActionSequence()
: m_nActionIndex(0)
{
}
e2d::ActionSequence::ActionSequence(const std::initializer_list<Action*>& vActions) :
m_nActionIndex(0)
e2d::ActionSequence::ActionSequence(const std::initializer_list<Action*>& vActions)
: m_nActionIndex(0)
{
this->add(vActions);
}

View File

@ -13,6 +13,15 @@ e2d::Animation::Animation(double interval)
}
e2d::Animation::Animation(const std::initializer_list<Image*>& vImages)
: m_nFrameIndex(0)
, m_fInterval(1)
{
this->add(vImages);
}
e2d::Animation::Animation(double interval, const std::initializer_list<Image*>& vImages)
: m_nFrameIndex(0)
, m_fInterval(interval)
{
this->add(vImages);
}

View File

@ -53,6 +53,14 @@ void e2d::Scene::add(Node * child, int order /* = 0 */)
m_pRoot->addChild(child, order);
}
void e2d::Scene::add(const std::initializer_list<Node*>& vNodes, int order)
{
for (const auto &node : vNodes)
{
this->add(node, order);
}
}
bool e2d::Scene::remove(Node * child)
{
return m_pRoot->removeChild(child);

View File

@ -4,7 +4,7 @@
#include "..\etools.h"
// 形状集合
static std::vector<e2d::Shape*> s_vShapes;
static std::vector<e2d::ShapeBase*> s_vShapes;
// 监听器容器
static std::vector<e2d::CollisionListener*> s_vListeners;
// 碰撞触发状态
@ -40,7 +40,7 @@ void e2d::CollisionManager::__update()
}
}
void e2d::CollisionManager::__updateShape(e2d::Shape * pActiveShape)
void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape)
{
// 判断碰撞触发是否打开
if (!s_bCollisionEnable)
@ -206,17 +206,25 @@ std::vector<e2d::CollisionListener*> e2d::CollisionManager::getAll()
return s_vListeners;
}
e2d::Node * e2d::CollisionManager::getNode1()
e2d::Node* e2d::CollisionManager::isCausedBy(Node * pNode)
{
return s_pActiveNode;
if (s_pActiveNode == pNode)
return s_pPassiveNode;
if (s_pPassiveNode == pNode)
return s_pActiveNode;
return nullptr;
}
e2d::Node * e2d::CollisionManager::getNode2()
e2d::Node* e2d::CollisionManager::isCausedBy(String name)
{
return s_pPassiveNode;
if (s_pActiveNode->getName() == name)
return s_pActiveNode;
if (s_pPassiveNode->getName() == name)
return s_pPassiveNode;
return nullptr;
}
void e2d::CollisionManager::__addShape(Shape * pShape)
void e2d::CollisionManager::__addShape(ShapeBase * pShape)
{
if (pShape)
{
@ -230,7 +238,7 @@ void e2d::CollisionManager::__addShape(Shape * pShape)
}
}
void e2d::CollisionManager::__removeShape(Shape * pShape)
void e2d::CollisionManager::__removeShape(ShapeBase * pShape)
{
if (pShape)
{

View File

@ -378,7 +378,7 @@ double e2d::Node::getOpacity() const
return m_fRealOpacity;
}
e2d::Shape * e2d::Node::getShape() const
e2d::ShapeBase * e2d::Node::getShape() const
{
return m_pShape;
}
@ -547,25 +547,25 @@ void e2d::Node::setSize(Size size)
this->setSize(size.width, size.height);
}
void e2d::Node::setShape(Shape::TYPE type)
void e2d::Node::setShape(Shape type)
{
switch (type)
{
case Shape::TYPE::RECTANGLE:
case Shape::RECTANGLE:
{
auto rect = new ShapeRectangle(this);
this->setShape(rect);
break;
}
case Shape::TYPE::CIRCLE:
case Shape::CIRCLE:
{
auto rect = new ShapeCircle(this);
this->setShape(rect);
break;
}
case Shape::TYPE::ELLIPSE:
case Shape::ELLIPSE:
{
auto rect = new ShapeEllipse(this);
this->setShape(rect);
@ -577,7 +577,7 @@ void e2d::Node::setShape(Shape::TYPE type)
}
}
void e2d::Node::setShape(Shape * pShape)
void e2d::Node::setShape(ShapeBase * pShape)
{
// 删除旧的形状
CollisionManager::__removeShape(m_pShape);

View File

@ -2,7 +2,7 @@
#include "..\emanagers.h"
#include "..\enodes.h"
e2d::Shape::Shape()
e2d::ShapeBase::ShapeBase()
: m_bIsVisiable(true)
, m_nColor(Color::RED)
, m_fOpacity(1)
@ -13,42 +13,42 @@ e2d::Shape::Shape()
{
}
e2d::Shape::~Shape()
e2d::ShapeBase::~ShapeBase()
{
SafeReleaseInterface(&m_pTransformedShape);
}
e2d::Node * e2d::Shape::getParentNode() const
e2d::Node * e2d::ShapeBase::getParentNode() const
{
return m_pParentNode;
}
void e2d::Shape::setEnable(bool bEnable)
void e2d::ShapeBase::setEnable(bool bEnable)
{
m_bEnable = bEnable;
}
void e2d::Shape::setVisiable(bool bVisiable)
void e2d::ShapeBase::setVisiable(bool bVisiable)
{
m_bIsVisiable = bVisiable;
}
void e2d::Shape::setColor(UINT32 color)
void e2d::ShapeBase::setColor(UINT32 color)
{
m_nColor = color;
}
void e2d::Shape::setOpacity(double opacity)
void e2d::ShapeBase::setOpacity(double opacity)
{
m_fOpacity = min(max(static_cast<float>(opacity), 0), 1);
}
void e2d::Shape::setAutoResize(bool bEnable)
void e2d::ShapeBase::setAutoResize(bool bEnable)
{
m_bAutoResize = bEnable;
}
void e2d::Shape::_render()
void e2d::ShapeBase::_render()
{
if (m_pTransformedShape && m_bEnable)
{
@ -65,7 +65,7 @@ void e2d::Shape::_render()
}
}
e2d::Relation e2d::Shape::getRelationWith(Shape * pShape) const
e2d::Relation e2d::ShapeBase::getRelationWith(ShapeBase * pShape) const
{
if (m_pTransformedShape && pShape->m_pTransformedShape)
{
@ -85,7 +85,7 @@ e2d::Relation e2d::Shape::getRelationWith(Shape * pShape) const
return Relation::UNKNOWN;
}
void e2d::Shape::_transform()
void e2d::ShapeBase::_transform()
{
if (m_pParentNode && m_bEnable)
{

View File

@ -517,7 +517,13 @@ public:
// ´´½¨Ö¡¶¯»­
Animation(
const std::initializer_list<Image*>& vImages
const std::initializer_list<Image*>& vImages /* 关键帧数组 */
);
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
const std::initializer_list<Image*>& vImages /* 关键帧数组 */
);
virtual ~Animation();
@ -763,12 +769,7 @@ namespace e2d
inline e2d::ActionSequence * e2d::action::Sequence(const std::initializer_list<Action*>& vActions)
{
auto action = new (std::nothrow) ActionSequence();
if (action)
{
action->add(vActions);
}
return action;
return new (std::nothrow) ActionSequence(vActions);
}
inline e2d::ActionDelay * e2d::action::Delay(double duration)
@ -783,12 +784,7 @@ namespace e2d
inline e2d::Animation * e2d::action::Animate(double interval, const std::initializer_list<Image*>& vFrames)
{
auto animation = new (std::nothrow) Animation(interval);
if (animation)
{
animation->add(vFrames);
}
return animation;
return new (std::nothrow) Animation(interval, vFrames);
}
inline e2d::ActionFunc * e2d::action::Func(Function func)

View File

@ -372,6 +372,15 @@ enum class Relation : int
};
// 形状类别
enum class Shape : int
{
RECTANGLE, /* 矩形 */
CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */
};
// 文本样式
struct Font
{
@ -545,8 +554,14 @@ public:
// 添加节点到场景
void add(
Node * child,
int zOrder = 0
Node * child, /* 要添加的节点 */
int zOrder = 0 /* 渲染顺序 */
);
// 添加节点到场景
virtual void add(
const std::initializer_list<Node*>& vNodes, /* 节点数组 */
int order = 0 /* 渲染顺序 */
);
// 删除子节点
@ -578,86 +593,6 @@ protected:
};
class CollisionManager;
// 形状
class Shape :
public Object
{
friend CollisionManager;
friend Node;
public:
// 形状类别
enum class TYPE : int
{
RECTANGLE, /* 矩形 */
CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */
};
public:
Shape();
virtual ~Shape();
// 判断两形状的交集关系
virtual Relation getRelationWith(
Shape * pShape
) const;
// 获取父节点
Node * getParentNode() const;
// 启用或关闭该形状
virtual void setEnable(
bool bEnable
);
// 设置形状的可见性
void setVisiable(
bool bVisiable
);
// 设置绘制颜色
void setColor(
UINT32 color
);
// 设置绘制透明度
void setOpacity(
double opacity
);
// 设置大小跟随
void setAutoResize(
bool bEnable
);
// 获取 ID2D1Geometry 对象
virtual ID2D1Geometry * getD2dGeometry() const = 0;
protected:
// 转换形状
virtual void _transform();
// 重设大小
virtual void _resize() = 0;
// 渲染形状
virtual void _render();
protected:
bool m_bEnable;
bool m_bIsVisiable;
bool m_bAutoResize;
UINT32 m_nColor;
float m_fOpacity;
Node * m_pParentNode;
ID2D1TransformedGeometry * m_pTransformedShape;
};
// String 类模板函数定义
template<typename T>
inline e2d::String e2d::String::toString(T value)

View File

@ -12,6 +12,7 @@ class Node;
class Timer;
class Action;
class Music;
class ShapeBase;
class Transition;
class InputListener;
class CollisionListener;
@ -354,7 +355,7 @@ private:
class CollisionManager
{
friend Node;
friend Shape;
friend ShapeBase;
friend CollisionListener;
public:
@ -401,11 +402,15 @@ public:
// 获取全部监听器
static std::vector<CollisionListener*> getAll();
// 获取发生碰撞的节点 1
static Node* getNode1();
// 判断碰撞是否由该节点引发(如果是,返回与其相撞的节点指针,否则返回空)
static Node* isCausedBy(
Node * pNode
);
// 获取发生碰撞的节点 2
static Node* getNode2();
// 判断发生碰撞的节点名称是否相同(若相同返回其指针,否则返回空)
static Node* isCausedBy(
String name
);
private:
// 添加碰撞监听
@ -418,17 +423,17 @@ private:
// 更新形状
static void __updateShape(
Shape * pActiveShape
ShapeBase * pActiveShape
);
// 添加形状
static void __addShape(
Shape * pShape
ShapeBase * pShape
);
// 删除已绑定的形状
static void __removeShape(
Shape * pShape
ShapeBase * pShape
);
};

View File

@ -7,13 +7,14 @@ namespace e2d
class Action;
class Transition;
class ShapeBase;
class CollisionManager;
class Node :
public Object
{
friend Scene;
friend Shape;
friend ShapeBase;
friend Transition;
friend CollisionManager;
@ -116,7 +117,7 @@ public:
virtual double getOpacity() const;
// 获取节点形状
virtual Shape * getShape() const;
virtual ShapeBase * getShape() const;
// 获取父节点
virtual Node * getParent() const;
@ -312,12 +313,12 @@ public:
// 设置节点形状
virtual void setShape(
Shape::TYPE type
Shape type
);
// 设置节点形状
virtual void setShape(
Shape * pShape
ShapeBase * pShape
);
// 添加可碰撞节点的名称
@ -455,7 +456,7 @@ protected:
bool m_bDisplayedInScene;
bool m_bSortChildrenNeeded;
bool m_bTransformNeeded;
Shape * m_pShape;
ShapeBase * m_pShape;
Scene * m_pParentScene;
Node * m_pParent;
D2D1::Matrix3x2F m_MatriInitial;

View File

@ -6,9 +6,80 @@ namespace e2d
{
class CollisionManager;
// 形状
class ShapeBase :
public Object
{
friend CollisionManager;
friend Node;
public:
ShapeBase();
virtual ~ShapeBase();
// 判断两形状的交集关系
virtual Relation getRelationWith(
ShapeBase * pShape
) const;
// 获取父节点
Node * getParentNode() const;
// 启用或关闭该形状
virtual void setEnable(
bool bEnable
);
// 设置形状的可见性
void setVisiable(
bool bVisiable
);
// 设置绘制颜色
void setColor(
UINT32 color
);
// 设置绘制透明度
void setOpacity(
double opacity
);
// 设置大小跟随
void setAutoResize(
bool bEnable
);
// 获取 ID2D1Geometry 对象
virtual ID2D1Geometry * getD2dGeometry() const = 0;
protected:
// 转换形状
virtual void _transform();
// 重设大小
virtual void _resize() = 0;
// 渲染形状
virtual void _render();
protected:
bool m_bEnable;
bool m_bIsVisiable;
bool m_bAutoResize;
UINT32 m_nColor;
float m_fOpacity;
Node * m_pParentNode;
ID2D1TransformedGeometry * m_pTransformedShape;
};
// 矩形
class ShapeRectangle :
public Shape
public ShapeBase
{
public:
// 创建一个默认矩形
@ -51,7 +122,7 @@ protected:
// 圆形
class ShapeCircle :
public Shape
public ShapeBase
{
public:
// 创建一个默认圆形
@ -90,7 +161,7 @@ protected:
// 椭圆形
class ShapeEllipse :
public Shape
public ShapeBase
{
public:
// 创建一个默认椭圆

View File

@ -8,6 +8,7 @@ namespace e2d
class TimerManager;
class MusicManager;
class InputManager;
class CollisionManager;
// 随机数产生器
class Random