update enum constants

This commit is contained in:
Nomango 2018-03-31 22:34:18 +08:00
parent 2daa4d49ad
commit dee2010e7c
12 changed files with 143 additions and 130 deletions

View File

@ -5,7 +5,7 @@ e2d::ActionSequence::ActionSequence() :
{
}
e2d::ActionSequence::ActionSequence(std::initializer_list<Action*>& vActions) :
e2d::ActionSequence::ActionSequence(const std::initializer_list<Action*>& vActions) :
m_nActionIndex(0)
{
this->add(vActions);
@ -82,7 +82,7 @@ void e2d::ActionSequence::add(Action * action)
}
}
void e2d::ActionSequence::add(std::initializer_list<Action*>& vActions)
void e2d::ActionSequence::add(const std::initializer_list<Action*>& vActions)
{
for (const auto &action : vActions)
{

View File

@ -12,7 +12,7 @@ e2d::Animation::Animation(double interval)
{
}
e2d::Animation::Animation(std::initializer_list<Image*>& vImages)
e2d::Animation::Animation(const std::initializer_list<Image*>& vImages)
{
this->add(vImages);
}
@ -77,7 +77,7 @@ void e2d::Animation::add(Image * frame)
}
}
void e2d::Animation::add(std::initializer_list<Image*>& vImages)
void e2d::Animation::add(const std::initializer_list<Image*>& vImages)
{
for (const auto &image : vImages)
{

View File

@ -142,23 +142,25 @@ void Input::__updateDeviceState()
ScreenToClient(Window::getHWnd(), &s_MousePosition);
}
bool Input::isKeyDown(int nKeyCode)
bool Input::isKeyDown(KeyCode nKeyCode)
{
if (s_KeyBuffer[nKeyCode] & 0x80)
if (s_KeyBuffer[static_cast<int>(nKeyCode)] & 0x80)
return true;
return false;
}
bool Input::isKeyPress(int nKeyCode)
bool Input::isKeyPress(KeyCode nKeyCode)
{
if ((s_KeyBuffer[nKeyCode] & 0x80) && !(s_KeyRecordBuffer[nKeyCode] & 0x80))
if ((s_KeyBuffer[static_cast<int>(nKeyCode)] & 0x80) &&
!(s_KeyRecordBuffer[static_cast<int>(nKeyCode)] & 0x80))
return true;
return false;
}
bool Input::isKeyRelease(int nKeyCode)
bool Input::isKeyRelease(KeyCode nKeyCode)
{
if (!(s_KeyBuffer[nKeyCode] & 0x80) && (s_KeyRecordBuffer[nKeyCode] & 0x80))
if (!(s_KeyBuffer[static_cast<int>(nKeyCode)] & 0x80) &&
(s_KeyRecordBuffer[static_cast<int>(nKeyCode)] & 0x80))
return true;
return false;
}

View File

@ -9,6 +9,9 @@ static std::vector<e2d::Shape*> s_vShapes;
static std::vector<e2d::CollisionListener*> s_vListeners;
// 碰撞触发状态
static bool s_bCollisionEnable = false;
// ·¢ÉúÅöײµÄ½Úµã
static e2d::Node * s_pActiveNode = nullptr;
static e2d::Node * s_pPassiveNode = nullptr;
void e2d::CollisionManager::setEnable(bool bEnable)
@ -18,6 +21,9 @@ void e2d::CollisionManager::setEnable(bool bEnable)
void e2d::CollisionManager::__update()
{
if (s_vListeners.size() == 0)
return;
for (size_t i = 0; i < s_vListeners.size(); i++)
{
auto pListener = s_vListeners[i];
@ -72,19 +78,23 @@ void e2d::CollisionManager::__updateShape(e2d::Shape * pActiveShape)
if (IsCollideWith(pActiveNode, pPassiveNode->getHashName()))
{
// 判断两形状交集情况
int relation = pActiveShape->getRelationWith(pPassiveShape);
Relation relation = pActiveShape->getRelationWith(pPassiveShape);
// 忽略 UNKNOWN 和 DISJOINT 情况
if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT)
{
pActiveNode->onCollide(pPassiveNode, relation);
pPassiveNode->onCollide(pActiveNode, pPassiveShape->getRelationWith(pActiveShape));
pCurrentScene->onCollide(pActiveNode, pPassiveNode);
s_pActiveNode = pActiveNode;
s_pPassiveNode = pPassiveNode;
pActiveNode->onCollide(pPassiveNode);
pPassiveNode->onCollide(pActiveNode);
pCurrentScene->onCollide();
CollisionManager::__update();
}
}
}
}
}
s_pActiveNode = nullptr;
s_pPassiveNode = nullptr;
}
void e2d::CollisionManager::__add(CollisionListener * pListener)
@ -196,6 +206,16 @@ std::vector<e2d::CollisionListener*> e2d::CollisionManager::getAll()
return s_vListeners;
}
e2d::Node * e2d::CollisionManager::getNode1()
{
return s_pActiveNode;
}
e2d::Node * e2d::CollisionManager::getNode2()
{
return s_pPassiveNode;
}
void e2d::CollisionManager::__addShape(Shape * pShape)
{
if (pShape)

View File

@ -602,7 +602,7 @@ void e2d::Node::addCollider(String collliderName)
m_vColliders.insert(hash);
}
void e2d::Node::addCollider(std::initializer_list<String>& vCollliderName)
void e2d::Node::addCollider(const std::initializer_list<String>& vCollliderName)
{
for (const auto &name : vCollliderName)
{
@ -656,7 +656,7 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
}
}
void e2d::Node::addChild(std::initializer_list<Node*>& vNodes, int order)
void e2d::Node::addChild(const std::initializer_list<Node*>& vNodes, int order)
{
for (const auto &node : vNodes)
{
@ -932,7 +932,7 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
// 如果存在形状,用形状判断
if (this->m_pShape && pNode->m_pShape)
{
int relation = this->m_pShape->getRelationWith(pNode->m_pShape);
Relation relation = this->m_pShape->getRelationWith(pNode->m_pShape);
if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT))
{

View File

@ -164,7 +164,7 @@ void e2d::Text::setLineSpacing(double fLineSpacing)
}
}
void e2d::Text::setAlignment(UINT32 nAlign)
void e2d::Text::setAlignment(TextAlign nAlign)
{
if (m_nAlign != nAlign)
{

View File

@ -65,7 +65,7 @@ void e2d::Shape::_render()
}
}
int e2d::Shape::getRelationWith(Shape * pShape) const
e2d::Relation e2d::Shape::getRelationWith(Shape * pShape) const
{
if (m_pTransformedShape && pShape->m_pTransformedShape)
{
@ -79,10 +79,10 @@ int e2d::Shape::getRelationWith(Shape * pShape) const
&relation
);
return relation;
return Relation(relation);
}
}
return 0;
return Relation::UNKNOWN;
}
void e2d::Shape::_transform()

View File

@ -402,7 +402,7 @@ public:
// 创建顺序动作
ActionSequence(
std::initializer_list<Action*>& vActions /* 动作数组 */
const std::initializer_list<Action*>& vActions /* 动作数组 */
);
virtual ~ActionSequence();
@ -414,7 +414,7 @@ public:
// 在结尾添加多个动作
void add(
std::initializer_list<Action*>& vActions /* 动作数组 */
const std::initializer_list<Action*>& vActions /* 动作数组 */
);
// 获取该动作的拷贝对象
@ -517,7 +517,7 @@ public:
// 创建帧动画
Animation(
std::initializer_list<Image*>& vImages
const std::initializer_list<Image*>& vImages
);
virtual ~Animation();
@ -529,7 +529,7 @@ public:
// 添加多个关键帧
void add(
std::initializer_list<Image*>& vImages /* 关键帧数组 */
const std::initializer_list<Image*>& vImages /* 关键帧数组 */
);
// 设置每一帧的时间间隔
@ -670,7 +670,7 @@ namespace e2d
// 创建顺序动作
ActionSequence* Sequence(
std::initializer_list<Action*>& vActions /* 动作数组 */
const std::initializer_list<Action*>& vActions /* 动作数组 */
);
// 创建延时动作
@ -687,7 +687,7 @@ namespace e2d
// 创建特定帧间隔的帧动画
Animation* Animate(
double interval, /* 帧间隔(秒) */
std::initializer_list<Image*>& vFrames /* 关键帧数组 */
const std::initializer_list<Image*>& vFrames /* 关键帧数组 */
);
// 创建执行函数对象的动作
@ -761,7 +761,7 @@ namespace e2d
return new (std::nothrow) ActionTwo(pActionFirst, pActionSecond, bAtSameTime);
}
inline e2d::ActionSequence * e2d::action::Sequence(std::initializer_list<Action*>& vActions)
inline e2d::ActionSequence * e2d::action::Sequence(const std::initializer_list<Action*>& vActions)
{
auto action = new (std::nothrow) ActionSequence();
if (action)
@ -781,7 +781,7 @@ namespace e2d
return new (std::nothrow) ActionLoop(action, times);
}
inline e2d::Animation * e2d::action::Animate(double interval, std::initializer_list<Image*>& vFrames)
inline e2d::Animation * e2d::action::Animate(double interval, const std::initializer_list<Image*>& vFrames)
{
auto animation = new (std::nothrow) Animation(interval);
if (animation)

View File

@ -152,17 +152,17 @@ class Input
public:
// 检测键盘某按键是否正被按下
static bool isKeyDown(
int nKeyCode
KeyCode nKeyCode
);
// 检测键盘某按键是否被点击
static bool isKeyPress(
int nKeyCode
KeyCode nKeyCode
);
// 检测键盘某按键是否正在松开
static bool isKeyRelease(
int nKeyCode
KeyCode nKeyCode
);
// 检测鼠标左键是否正被按下

View File

@ -195,7 +195,7 @@ private:
class Color
{
public:
enum COMMON_VALUE
enum : UINT32
{
ALICE_BLUE = 0xF0F8FF,
AQUA = 0x00FFFF,
@ -262,11 +262,12 @@ public:
};
};
// 字体粗细值
class FontWeight
{
public:
enum COMMON_VALUE
enum : UINT32
{
THIN = 100,
EXTRA_LIGHT = 200,
@ -290,23 +291,16 @@ public:
// 文本对齐方式
class TextAlign
{
public:
enum COMMON_VALUE
enum class TextAlign : int
{
LEFT, /* 左对齐 */
RIGHT, /* 右对齐 */
CENTER /* 居中对齐 */
};
};
// 键值集合
class KeyCode
{
public:
enum VALUE
enum class KeyCode : int
{
UP = 0xC8,
LEFT = 0xCB,
@ -365,14 +359,10 @@ public:
NUMPAD3 = 0x51,
NUMPAD0 = 0x52
};
};
// 形状交集关系
class Relation
{
public:
enum VALUE
enum class Relation : int
{
UNKNOWN = 0, /* 关系不确定 */
DISJOINT = 1, /* 没有交集 */
@ -380,7 +370,6 @@ public:
CONTAINS = 3, /* 完全包含 */
OVERLAP = 4 /* 部分重叠 */
};
};
// 文本样式
@ -541,12 +530,9 @@ public:
virtual void onExit() {}
// 重写这个函数,它将在碰撞发生时自动执行
virtual void onCollide(
Node * pActiveNode, /* 主动发生碰撞的节点 */
Node * pPassiveNode /* 被动发生碰撞的节点 */
) {}
virtual void onCollide() {}
// 重写这个函数,它将在关闭窗口时执行
// 重写这个函数,它将在关闭窗口时执行(返回 false 将阻止窗口关闭)
virtual bool onCloseWindow() { return true; }
// 重写这个函数,它将在每一帧画面刷新时执行
@ -603,7 +589,7 @@ class Shape :
public:
// 形状类别
enum TYPE
enum class TYPE : int
{
RECTANGLE, /* 矩形 */
CIRCLE, /* 圆形 */
@ -616,7 +602,7 @@ public:
virtual ~Shape();
// 判断两形状的交集关系
virtual int getRelationWith(
virtual Relation getRelationWith(
Shape * pShape
) const;

View File

@ -401,6 +401,12 @@ public:
// 获取全部监听器
static std::vector<CollisionListener*> getAll();
// 获取发生碰撞的节点 1
static Node* getNode1();
// 获取发生碰撞的节点 2
static Node* getNode2();
private:
// 添加碰撞监听
static void __add(

View File

@ -39,8 +39,7 @@ public:
// 碰撞处理
virtual void onCollide(
Node* pCollisionNode, /* 发生碰撞的节点 */
int nRelation /* 碰撞关系,取值为 Relation::VALUE 中的一种 */
Node* pNode /* 发生碰撞的节点 */
) {}
// 获取节点显示状态
@ -328,7 +327,7 @@ public:
// 添加多个可碰撞节点的名称
virtual void addCollider(
std::initializer_list<String>& vCollliderName /* 名称数组 */
const std::initializer_list<String>& vCollliderName /* 名称数组 */
);
// 移除可碰撞节点的名称
@ -344,7 +343,7 @@ public:
// 添加多个子节点
virtual void addChild(
std::initializer_list<Node*>& vNodes, /* 节点数组 */
const std::initializer_list<Node*>& vNodes, /* 节点数组 */
int order = 0 /* 渲染顺序 */
);
@ -623,7 +622,7 @@ public:
// 设置对齐方式(默认为 TextAlign::LEFT
void setAlignment(
UINT32 nAlign
TextAlign nAlign
);
// 设置下划线(默认值为 false
@ -654,8 +653,8 @@ protected:
bool m_bWrappingEnable;
float m_fWrappingWidth;
Font m_Font;
UINT32 m_nAlign;
float m_fLineSpacing;
TextAlign m_nAlign;
IDWriteTextFormat * m_pDWriteTextFormat;
IDWriteTextLayout * m_pDWriteTextLayout;
};