将部分枚举类型替换为强枚举类型

This commit is contained in:
Nomango 2018-04-24 21:22:34 +08:00
parent 52bfa595ad
commit 245a6c6e71
15 changed files with 218 additions and 221 deletions

View File

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

View File

@ -60,7 +60,7 @@ void e2d::Collider::_render()
}
}
int e2d::Collider::getRelationWith(Collider * pCollider) const
e2d::Relation e2d::Collider::getRelationWith(Collider * pCollider) const
{
if (m_pTransformedGeometry && pCollider->m_pTransformedGeometry)
{
@ -74,7 +74,7 @@ int e2d::Collider::getRelationWith(Collider * pCollider) const
&relation
);
return relation;
return Relation(relation);
}
}
return Relation::UNKNOWN;

View File

@ -6,6 +6,10 @@ e2d::TextStyle::TextStyle()
, color(Color::WHITE)
, fontWeight(FontWeight::NORMAL)
, italic(false)
, alignment(TextAlign::LEFT)
, wrapping(false)
, wrappingWidth(0.0)
, lineSpacing(0.0)
, hasUnderline(false)
, hasStrikethrough(false)
, hasOutline(true)
@ -20,18 +24,26 @@ e2d::TextStyle::TextStyle(
Color color,
UINT32 fontWeight,
bool italic,
TextAlign alignment,
bool wrapping,
double wrappingWidth,
double lineSpacing,
bool hasUnderline,
bool hasStrikethrough,
bool hasOutline,
Color outlineColor,
double outlineWidth,
int outlineJoin
LineJoin outlineJoin
)
: fontFamily(fontFamily)
, fontSize(fontSize)
, color(color)
, fontWeight(fontWeight)
, italic(italic)
, alignment(alignment)
, wrapping(wrapping)
, wrappingWidth(wrappingWidth)
, lineSpacing(lineSpacing)
, hasUnderline(hasUnderline)
, hasStrikethrough(hasStrikethrough)
, hasOutline(hasOutline)

View File

@ -114,7 +114,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
if (IsCollideWith(pActiveNode, pPassiveNode))
{
// 判断两碰撞体交集情况
int relation = pActiveCollider->getRelationWith(pPassiveCollider);
Relation relation = pActiveCollider->getRelationWith(pPassiveCollider);
// 忽略 UNKNOWN 和 DISJOINT 情况
if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT)
{

View File

@ -6,7 +6,7 @@
e2d::Button::Button()
: m_Callback(nullptr)
, m_eBtnState(Button::NORMAL)
, m_eBtnState(ButtonState::NORMAL)
, m_bEnable(true)
, m_bIsSelected(false)
, m_pNormal(nullptr)
@ -18,7 +18,7 @@ e2d::Button::Button()
e2d::Button::Button(Node * normal, Function func)
: m_Callback(nullptr)
, m_eBtnState(Button::NORMAL)
, m_eBtnState(ButtonState::NORMAL)
, m_bEnable(true)
, m_bIsSelected(false)
, m_pNormal(nullptr)
@ -32,7 +32,7 @@ e2d::Button::Button(Node * normal, Function func)
e2d::Button::Button(Node * normal, Node * selected, Function func)
: m_Callback(nullptr)
, m_eBtnState(Button::NORMAL)
, m_eBtnState(ButtonState::NORMAL)
, m_bEnable(true)
, m_bIsSelected(false)
, m_pNormal(nullptr)
@ -47,7 +47,7 @@ e2d::Button::Button(Node * normal, Node * selected, Function func)
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Function func)
: m_Callback(nullptr)
, m_eBtnState(Button::NORMAL)
, m_eBtnState(ButtonState::NORMAL)
, m_bEnable(true)
, m_bIsSelected(false)
, m_pNormal(nullptr)
@ -63,7 +63,7 @@ e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Function f
e2d::Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, Function func)
: m_Callback(nullptr)
, m_eBtnState(Button::NORMAL)
, m_eBtnState(ButtonState::NORMAL)
, m_bEnable(true)
, m_bIsSelected(false)
, m_pNormal(nullptr)
@ -210,21 +210,21 @@ void e2d::Button::onFixedUpdate()
{
if (m_pNormal->isPointIn(Input::getMousePos()))
{
_setState(Button::SELECTED);
_setState(ButtonState::SELECTED);
return;
}
}
else if (m_pNormal->isPointIn(Input::getMousePos()))
{
_setState(Button::MOUSEOVER);
_setState(ButtonState::MOUSEOVER);
return;
}
_setState(Button::NORMAL);
_setState(ButtonState::NORMAL);
}
}
void e2d::Button::_setState(BTN_STATE state)
void e2d::Button::_setState(ButtonState state)
{
if (m_eBtnState != state)
{
@ -242,11 +242,11 @@ void e2d::Button::_updateVisiable()
if (m_bEnable)
{
if (m_eBtnState == Button::SELECTED && m_pSelected)
if (m_eBtnState == ButtonState::SELECTED && m_pSelected)
{
m_pSelected->setVisiable(true);
}
else if (m_eBtnState == Button::MOUSEOVER && m_pMouseover)
else if (m_eBtnState == ButtonState::MOUSEOVER && m_pMouseover)
{
m_pMouseover->setVisiable(true);
}

View File

@ -561,7 +561,7 @@ void e2d::Node::setProperty(NodeProperty prop)
this->setSkew(prop.skewAngleX, prop.skewAngleY);
}
void e2d::Node::setCollider(int nColliderType)
void e2d::Node::setCollider(ColliderType nColliderType)
{
switch (nColliderType)
{
@ -960,7 +960,7 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
// 如果存在碰撞体,用碰撞体判断
if (this->m_pCollider && pNode->m_pCollider)
{
int relation = this->m_pCollider->getRelationWith(pNode->m_pCollider);
Relation relation = this->m_pCollider->getRelationWith(pNode->m_pCollider);
if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT))
{

View File

@ -63,7 +63,7 @@ double e2d::Shape::getStrokeWidth() const
return m_fStrokeWidth;
}
int e2d::Shape::getStyle() const
e2d::ShapeStyle e2d::Shape::getStyle() const
{
return m_nStyle;
}
@ -83,7 +83,7 @@ void e2d::Shape::setStrokeWidth(double strokeWidth)
m_fStrokeWidth = static_cast<float>(strokeWidth);
}
void e2d::Shape::setStyle(int style)
void e2d::Shape::setStyle(ShapeStyle style)
{
m_nStyle = style;
}

View File

@ -2,22 +2,14 @@
e2d::Text::Text()
: m_bWrappingEnable(false)
, m_TextStyle()
, m_nAlign(TextAlign::LEFT)
, m_fLineSpacing(0.0f)
, m_fWrappingWidth(0.0f)
: m_TextStyle()
, m_pDWriteTextLayout(nullptr)
, m_pDWriteTextFormat(nullptr)
{
}
e2d::Text::Text(String text)
: m_bWrappingEnable(false)
, m_TextStyle()
, m_nAlign(TextAlign::LEFT)
, m_fLineSpacing(0.0f)
, m_fWrappingWidth(0.0f)
: m_TextStyle()
, m_pDWriteTextLayout(nullptr)
, m_pDWriteTextFormat(nullptr)
, m_sText(text)
@ -26,11 +18,7 @@ e2d::Text::Text(String text)
}
e2d::Text::Text(TextStyle textStyle)
: m_bWrappingEnable(false)
, m_TextStyle(textStyle)
, m_nAlign(TextAlign::LEFT)
, m_fLineSpacing(0.0f)
, m_fWrappingWidth(0.0f)
: m_TextStyle(textStyle)
, m_pDWriteTextLayout(nullptr)
, m_pDWriteTextFormat(nullptr)
{
@ -38,11 +26,7 @@ e2d::Text::Text(TextStyle textStyle)
}
e2d::Text::Text(String text, TextStyle textStyle)
: m_bWrappingEnable(false)
, m_TextStyle(textStyle)
, m_nAlign(TextAlign::LEFT)
, m_fLineSpacing(0.0f)
, m_fWrappingWidth(0.0f)
: m_TextStyle(textStyle)
, m_pDWriteTextLayout(nullptr)
, m_pDWriteTextFormat(nullptr)
, m_sText(text)
@ -57,28 +41,32 @@ e2d::Text::Text(
UINT32 color,
UINT32 fontWeight,
bool italic,
TextAlign alignment,
bool wrapping,
double wrappingWidth,
double lineSpacing,
bool hasUnderline,
bool hasStrikethrough,
bool hasOutline,
UINT32 outlineColor,
UINT32 outlineWidth
)
: m_bWrappingEnable(false)
, m_TextStyle(
: m_TextStyle(
fontFamily,
fontSize,
color,
fontWeight,
italic,
alignment,
wrapping,
wrappingWidth,
lineSpacing,
hasUnderline,
hasStrikethrough,
hasOutline,
outlineColor,
outlineWidth
)
, m_nAlign(TextAlign::LEFT)
, m_fLineSpacing(0.0f)
, m_fWrappingWidth(0.0f)
, m_pDWriteTextLayout(nullptr)
, m_pDWriteTextFormat(nullptr)
, m_sText(text)
@ -132,7 +120,7 @@ double e2d::Text::getOutlineWidth() const
return m_TextStyle.outlineWidth;
}
int e2d::Text::getOutlineJoin() const
e2d::LineJoin e2d::Text::getOutlineJoin() const
{
return m_TextStyle.outlineJoin;
}
@ -191,7 +179,7 @@ void e2d::Text::setFontFamily(String fontFamily)
void e2d::Text::setFontSize(double fontSize)
{
m_TextStyle.fontSize = static_cast<float>(fontSize);
m_TextStyle.fontSize = fontSize;
_reset();
}
@ -212,30 +200,42 @@ void e2d::Text::setItalic(bool value)
_reset();
}
void e2d::Text::setWrapping(bool wrapping)
{
if (m_TextStyle.wrapping != wrapping)
{
m_TextStyle.wrapping = wrapping;
_reset();
}
}
void e2d::Text::setWrappingWidth(double fWrappingWidth)
{
if (m_fWrappingWidth != fWrappingWidth)
if (m_TextStyle.wrappingWidth != fWrappingWidth)
{
m_TextStyle.wrappingWidth = max(fWrappingWidth, 0);
if (m_TextStyle.wrapping)
{
m_fWrappingWidth = max(static_cast<float>(fWrappingWidth), 0);
m_bWrappingEnable = (m_fWrappingWidth > FLT_MIN);
_reset();
}
}
}
void e2d::Text::setLineSpacing(double fLineSpacing)
{
if (m_fLineSpacing != fLineSpacing)
if (m_TextStyle.lineSpacing != fLineSpacing)
{
m_fLineSpacing = static_cast<float>(fLineSpacing);
m_TextStyle.lineSpacing = fLineSpacing;
_reset();
}
}
void e2d::Text::setAlignment(int nAlign)
void e2d::Text::setAlignment(TextAlign align)
{
if (m_nAlign != nAlign)
if (m_TextStyle.alignment != align)
{
m_nAlign = nAlign;
m_TextStyle.alignment = align;
_reset();
}
}
@ -277,7 +277,7 @@ void e2d::Text::setOutlineWidth(double outlineWidth)
m_TextStyle.outlineWidth = outlineWidth;
}
void e2d::Text::setOutlineJoin(int outlineJoin)
void e2d::Text::setOutlineJoin(LineJoin outlineJoin)
{
m_TextStyle.outlineJoin = outlineJoin;
}
@ -331,9 +331,9 @@ void e2d::Text::_createFormat()
if (m_pDWriteTextFormat)
{
// 设置文字对齐方式
m_pDWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(m_nAlign));
m_pDWriteTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(m_TextStyle.alignment));
// 设置行间距
if (m_fLineSpacing == 0.0f)
if (m_TextStyle.lineSpacing == 0.0)
{
m_pDWriteTextFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0);
}
@ -341,12 +341,12 @@ void e2d::Text::_createFormat()
{
m_pDWriteTextFormat->SetLineSpacing(
DWRITE_LINE_SPACING_METHOD_UNIFORM,
m_fLineSpacing,
m_fLineSpacing * 0.8f
static_cast<FLOAT>(m_TextStyle.lineSpacing),
static_cast<FLOAT>(m_TextStyle.lineSpacing) * 0.8f
);
}
// 打开文本自动换行时,设置换行属性
if (m_bWrappingEnable)
if (m_TextStyle.wrapping)
{
m_pDWriteTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_WRAP);
}
@ -379,13 +379,13 @@ void e2d::Text::_createLayout()
// 创建 TextLayout
HRESULT hr;
// 对文本自动换行情况下进行处理
if (m_bWrappingEnable)
if (m_TextStyle.wrapping)
{
hr = Renderer::getIDWriteFactory()->CreateTextLayout(
m_sText,
length,
m_pDWriteTextFormat,
m_fWrappingWidth,
static_cast<FLOAT>(m_TextStyle.wrappingWidth),
0,
&m_pDWriteTextLayout
);

View File

@ -1,7 +1,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::TransitionMove::TransitionMove(double duration, int direct)
e2d::TransitionMove::TransitionMove(double duration, Direct direct)
: Transition(duration)
, m_Direct(direct)
{

View File

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

View File

@ -21,7 +21,7 @@ public:
virtual ~Collider();
// 判断两碰撞体的交集关系
virtual int getRelationWith(
virtual Relation getRelationWith(
Collider * pCollider
) const;

View File

@ -334,23 +334,16 @@ public:
// 文本对齐方式
class TextAlign
{
public:
enum : int
enum class TextAlign : int
{
LEFT, /* 左对齐 */
RIGHT, /* 右对齐 */
CENTER /* 居中对齐 */
};
};
// 键值集合
class KeyCode
{
public:
enum : int
enum class KeyCode : int
{
UP = 0xC8,
LEFT = 0xCB,
@ -409,28 +402,20 @@ public:
NUMPAD3 = 0x51,
NUMPAD0 = 0x52
};
};
// 方向
class Direct
{
public:
enum : int
enum class Direct : int
{
UP, /* 上 */
DOWN, /* 下 */
LEFT, /* 左 */
RIGHT /* 右 */
};
};
// 碰撞体交集关系
class Relation
{
public:
enum : int
// 物体交集关系
enum class Relation : int
{
UNKNOWN = 0, /* 关系不确定 */
DISJOINT = 1, /* 没有交集 */
@ -438,46 +423,33 @@ public:
CONTAINS = 3, /* 完全包含 */
OVERLAP = 4 /* 部分重叠 */
};
};
// 线条相交样式
class LineJoin
{
public:
enum : int
enum class LineJoin : int
{
MITER = 0,
BEVEL = 1,
ROUND = 2
};
};
// 形状样式
class ShapeStyle
{
public:
enum : int
enum class ShapeStyle : int
{
SOLID, /* 填充 */
ROUND, /* 轮廓 */
FILL, /* 轮廓 + 填充 */
};
};
// 碰撞体类别
class ColliderType
{
public:
enum : int
enum class ColliderType : int
{
RECT, /* 矩形 */
CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */
};
};
// 文本样式
@ -488,12 +460,16 @@ struct TextStyle
Color color; // 颜色
UINT32 fontWeight; // 粗细值
bool italic; // 斜体
TextAlign alignment; // 对齐方式
bool wrapping; // 打开自动换行
double wrappingWidth; // 自动换行宽度
double lineSpacing; // 行间距
bool hasUnderline; // 下划线
bool hasStrikethrough; // 删除线
bool hasOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
int outlineJoin; // 描边线相交样式
LineJoin outlineJoin; // 描边线相交样式
/* 构造函数 */
TextStyle();
@ -504,12 +480,16 @@ struct TextStyle
Color color = Color::WHITE,
UINT32 fontWeight = FontWeight::NORMAL,
bool italic = false,
TextAlign alignment = TextAlign::LEFT,
bool wrapping = false,
double wrappingWidth = 0.0,
double lineSpacing = 0.0,
bool hasUnderline = false,
bool hasStrikethrough = false,
bool hasOutline = true,
Color outlineColor = Color(Color::BLACK, 0.5),
double outlineWidth = 1.0,
int outlineJoin = LineJoin::ROUND
LineJoin outlineJoin = LineJoin::ROUND
);
};

View File

@ -326,7 +326,7 @@ public:
// 设置碰撞体
virtual void setCollider(
int nColliderType
ColliderType nColliderType
);
// 设置碰撞体
@ -566,6 +566,10 @@ public:
UINT32 color = Color::WHITE, /* 颜色 */
UINT32 fontWeight = FontWeight::NORMAL, /* 粗细值 */
bool italic = false, /* 斜体 */
TextAlign alignment = TextAlign::LEFT, /* 对齐方式 */
bool wrapping = false, /* 打开自动换行 */
double wrappingWidth = 0.0, /* 自动换行宽度 */
double lineSpacing = 0.0, /* 行间距 */
bool hasUnderline = false, /* 下划线 */
bool hasStrikethrough = false, /* 删除线 */
bool hasOutline = true, /* 显示描边 */
@ -600,7 +604,7 @@ public:
double getOutlineWidth() const;
// 获取描边线相交样式
int getOutlineJoin() const;
LineJoin getOutlineJoin() const;
// 获取文本显示行数
int getLineCount() const;
@ -652,7 +656,12 @@ public:
bool value
);
// 设置文本自动换行的宽度(设置为 0 时关闭自动换行,默认为 0
// 打开或关闭文本自动换行(默认为关闭)
void setWrapping(
bool wrapping
);
// 设置文本自动换行的宽度(默认为 0
void setWrappingWidth(
double fWrappingWidth
);
@ -664,7 +673,7 @@ public:
// 设置对齐方式(默认为 TextAlign::LEFT
void setAlignment(
int nAlign
TextAlign align
);
// 设置下划线(默认值为 false
@ -694,7 +703,7 @@ public:
// 设置描边线相交样式
void setOutlineJoin(
int outlineJoin
LineJoin outlineJoin
);
// 渲染文字
@ -712,10 +721,6 @@ protected:
protected:
String m_sText;
bool m_bWrappingEnable;
float m_fWrappingWidth;
float m_fLineSpacing;
int m_nAlign;
TextStyle m_TextStyle;
IDWriteTextFormat * m_pDWriteTextFormat;
IDWriteTextLayout * m_pDWriteTextLayout;
@ -797,10 +802,10 @@ public:
protected:
// 按钮状态枚举
enum BTN_STATE { NORMAL, MOUSEOVER, SELECTED };
enum class ButtonState { NORMAL, MOUSEOVER, SELECTED };
// 设置按钮状态
virtual void _setState(BTN_STATE state);
virtual void _setState(ButtonState state);
// 刷新按钮显示
virtual void _updateVisiable();
@ -815,7 +820,7 @@ protected:
Node * m_pDisabled;
bool m_bEnable;
bool m_bIsSelected;
BTN_STATE m_eBtnState;
ButtonState m_eBtnState;
Function m_Callback;
};

View File

@ -15,7 +15,7 @@ public:
virtual ~Shape();
// »ñÈ¡Ñùʽ
int getStyle() const;
ShapeStyle getStyle() const;
// »ñÈ¡Ìî³äÑÕÉ«
Color getFillColor() const;
@ -42,7 +42,7 @@ public:
);
// ÉèÖÃÑùʽ
void setStyle(int style);
void setStyle(ShapeStyle style);
// äÖȾÐÎ×´
virtual void onRender() override;
@ -55,7 +55,7 @@ protected:
virtual void _renderFill() = 0;
protected:
int m_nStyle;
ShapeStyle m_nStyle;
float m_fStrokeWidth;
Color m_nLineColor;
Color m_nFillColor;

View File

@ -122,7 +122,7 @@ public:
// 创建移动式的场景切换动画
TransitionMove(
double moveDuration, /* 场景移动动画持续时长 */
int direct = Direct::LEFT /* 场景移动方向 */
Direct direct = Direct::LEFT /* 场景移动方向 */
);
protected:
@ -137,7 +137,7 @@ protected:
virtual void _reset() override;
protected:
int m_Direct;
Direct m_Direct;
Vector m_Vector;
Point m_NextPos;
};