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) m_nActionIndex(0)
{ {
this->add(vActions); 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) 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); 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) for (const auto &image : vImages)
{ {

View File

@ -142,23 +142,25 @@ void Input::__updateDeviceState()
ScreenToClient(Window::getHWnd(), &s_MousePosition); 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 true;
return false; 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 true;
return false; 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 true;
return false; return false;
} }

View File

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

View File

@ -602,7 +602,7 @@ void e2d::Node::addCollider(String collliderName)
m_vColliders.insert(hash); 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) 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) for (const auto &node : vNodes)
{ {
@ -932,7 +932,7 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
// 如果存在形状,用形状判断 // 如果存在形状,用形状判断
if (this->m_pShape && pNode->m_pShape) 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) && if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT)) (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) 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) if (m_pTransformedShape && pShape->m_pTransformedShape)
{ {
@ -79,10 +79,10 @@ int e2d::Shape::getRelationWith(Shape * pShape) const
&relation &relation
); );
return relation; return Relation(relation);
} }
} }
return 0; return Relation::UNKNOWN;
} }
void e2d::Shape::_transform() void e2d::Shape::_transform()

View File

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

View File

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

View File

@ -195,7 +195,7 @@ private:
class Color class Color
{ {
public: public:
enum COMMON_VALUE enum : UINT32
{ {
ALICE_BLUE = 0xF0F8FF, ALICE_BLUE = 0xF0F8FF,
AQUA = 0x00FFFF, AQUA = 0x00FFFF,
@ -262,11 +262,12 @@ public:
}; };
}; };
// 字体粗细值 // 字体粗细值
class FontWeight class FontWeight
{ {
public: public:
enum COMMON_VALUE enum : UINT32
{ {
THIN = 100, THIN = 100,
EXTRA_LIGHT = 200, EXTRA_LIGHT = 200,
@ -290,96 +291,84 @@ public:
// 文本对齐方式 // 文本对齐方式
class TextAlign enum class TextAlign : int
{ {
public: LEFT, /* 左对齐 */
enum COMMON_VALUE RIGHT, /* 右对齐 */
{ CENTER /* 居中对齐 */
LEFT, /* 左对齐 */
RIGHT, /* 右对齐 */
CENTER /* 居中对齐 */
};
}; };
// 键值集合 // 键值集合
class KeyCode enum class KeyCode : int
{ {
public: UP = 0xC8,
enum VALUE LEFT = 0xCB,
{ RIGHT = 0xCD,
UP = 0xC8, DOWN = 0xD0,
LEFT = 0xCB, ENTER = 0x1C,
RIGHT = 0xCD, SPACE = 0x39,
DOWN = 0xD0, ESC = 0x01,
ENTER = 0x1C, BACK = 0x0E,
SPACE = 0x39, TAB = 0x0F,
ESC = 0x01, PAUSE = 0xC5,
BACK = 0x0E, Q = 0x10,
TAB = 0x0F, W = 0x11,
PAUSE = 0xC5, E = 0x12,
Q = 0x10, R = 0x13,
W = 0x11, T = 0x14,
E = 0x12, Y = 0x15,
R = 0x13, U = 0x16,
T = 0x14, I = 0x17,
Y = 0x15, O = 0x18,
U = 0x16, P = 0x19,
I = 0x17, A = 0x1E,
O = 0x18, S = 0x1F,
P = 0x19, D = 0x20,
A = 0x1E, F = 0x21,
S = 0x1F, G = 0x22,
D = 0x20, H = 0x23,
F = 0x21, J = 0x24,
G = 0x22, K = 0x25,
H = 0x23, L = 0x26,
J = 0x24, Z = 0x2C,
K = 0x25, X = 0x2D,
L = 0x26, C = 0x2E,
Z = 0x2C, V = 0x2F,
X = 0x2D, B = 0x30,
C = 0x2E, N = 0x31,
V = 0x2F, M = 0x32,
B = 0x30, NUM1 = 0x02,
N = 0x31, NUM2 = 0x03,
M = 0x32, NUM3 = 0x04,
NUM1 = 0x02, NUM4 = 0x05,
NUM2 = 0x03, NUM5 = 0x06,
NUM3 = 0x04, NUM6 = 0x07,
NUM4 = 0x05, NUM7 = 0x08,
NUM5 = 0x06, NUM8 = 0x09,
NUM6 = 0x07, NUM9 = 0x0A,
NUM7 = 0x08, NUM0 = 0x0B,
NUM8 = 0x09, NUMPAD7 = 0x47,
NUM9 = 0x0A, NUMPAD8 = 0x48,
NUM0 = 0x0B, NUMPAD9 = 0x49,
NUMPAD7 = 0x47, NUMPAD4 = 0x4B,
NUMPAD8 = 0x48, NUMPAD5 = 0x4C,
NUMPAD9 = 0x49, NUMPAD6 = 0x4D,
NUMPAD4 = 0x4B, NUMPAD1 = 0x4F,
NUMPAD5 = 0x4C, NUMPAD2 = 0x50,
NUMPAD6 = 0x4D, NUMPAD3 = 0x51,
NUMPAD1 = 0x4F, NUMPAD0 = 0x52
NUMPAD2 = 0x50,
NUMPAD3 = 0x51,
NUMPAD0 = 0x52
};
}; };
// 形状交集关系 // 形状交集关系
class Relation enum class Relation : int
{ {
public: UNKNOWN = 0, /* 关系不确定 */
enum VALUE DISJOINT = 1, /* 没有交集 */
{ IS_CONTAINED = 2, /* 完全被包含 */
UNKNOWN = 0, /* 关系不确定 */ CONTAINS = 3, /* 完全包含 */
DISJOINT = 1, /* 没有交集 */ OVERLAP = 4 /* 部分重叠 */
IS_CONTAINED = 2, /* 完全被包含 */
CONTAINS = 3, /* 完全包含 */
OVERLAP = 4 /* 部分重叠 */
};
}; };
@ -541,12 +530,9 @@ public:
virtual void onExit() {} virtual void onExit() {}
// 重写这个函数,它将在碰撞发生时自动执行 // 重写这个函数,它将在碰撞发生时自动执行
virtual void onCollide( virtual void onCollide() {}
Node * pActiveNode, /* 主动发生碰撞的节点 */
Node * pPassiveNode /* 被动发生碰撞的节点 */
) {}
// 重写这个函数,它将在关闭窗口时执行 // 重写这个函数,它将在关闭窗口时执行(返回 false 将阻止窗口关闭)
virtual bool onCloseWindow() { return true; } virtual bool onCloseWindow() { return true; }
// 重写这个函数,它将在每一帧画面刷新时执行 // 重写这个函数,它将在每一帧画面刷新时执行
@ -603,7 +589,7 @@ class Shape :
public: public:
// 形状类别 // 形状类别
enum TYPE enum class TYPE : int
{ {
RECTANGLE, /* 矩形 */ RECTANGLE, /* 矩形 */
CIRCLE, /* 圆形 */ CIRCLE, /* 圆形 */
@ -616,7 +602,7 @@ public:
virtual ~Shape(); virtual ~Shape();
// 判断两形状的交集关系 // 判断两形状的交集关系
virtual int getRelationWith( virtual Relation getRelationWith(
Shape * pShape Shape * pShape
) const; ) const;

View File

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

View File

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