Text部分方法命名改动

This commit is contained in:
Nomango 2018-04-22 14:08:29 +08:00
parent 40ad1c7282
commit 6578751de4
8 changed files with 91 additions and 74 deletions

View File

@ -237,7 +237,7 @@ e2d::Color e2d::Renderer::getBackgroundColor()
void e2d::Renderer::setBackgroundColor(Color color)
{
s_nClearColor = D2D1::ColorF(color.r, color.g, color.b, color.a);
s_nClearColor = color.toColorF();
}
void e2d::Renderer::showFps(bool show)

View File

@ -34,15 +34,15 @@ e2d::Color::Color(double r, double g, double b, double alpha)
e2d::Color::Color(UINT32 rgb)
{
init(rgb, 1);
_init(rgb, 1);
}
e2d::Color::Color(UINT32 rgb, double alpha)
{
init(rgb, alpha);
_init(rgb, alpha);
}
void e2d::Color::init(UINT32 rgb, double alpha)
void e2d::Color::_init(UINT32 rgb, double alpha)
{
r = static_cast<float>((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = static_cast<float>((rgb & sc_greenMask) >> sc_greenShift) / 255.f;

View File

@ -6,9 +6,9 @@ e2d::TextStyle::TextStyle()
, color(Color::WHITE)
, fontWeight(FontWeight::NORMAL)
, italic(false)
, underline(false)
, strikethrough(false)
, showOutline(true)
, hasUnderline(false)
, hasStrikethrough(false)
, hasOutline(true)
, outlineColor(Color::BLACK)
, outlineWidth(1.0)
, outlineJoin(LineJoin::ROUND)
@ -22,7 +22,7 @@ e2d::TextStyle::TextStyle(
bool italic,
bool hasUnderline,
bool hasStrikethrough,
bool showOutline,
bool hasOutline,
Color outlineColor,
double outlineWidth,
int outlineJoin
@ -32,9 +32,9 @@ e2d::TextStyle::TextStyle(
, color(color)
, fontWeight(fontWeight)
, italic(italic)
, underline(hasUnderline)
, strikethrough(hasStrikethrough)
, showOutline(showOutline)
, hasUnderline(hasUnderline)
, hasStrikethrough(hasStrikethrough)
, hasOutline(hasOutline)
, outlineColor(outlineColor)
, outlineWidth(outlineWidth)
, outlineJoin(outlineJoin)

View File

@ -32,14 +32,14 @@ CustomTextRenderer::~CustomTextRenderer()
STDMETHODIMP_(void) CustomTextRenderer::SetTextStyle(
CONST D2D1_COLOR_F &fillColor,
BOOL showOutline,
BOOL hasOutline,
CONST D2D1_COLOR_F &outlineColor,
FLOAT outlineWidth,
D2D1_LINE_JOIN outlineJoin
)
{
sFillColor_ = fillColor;
bShowOutline_ = showOutline;
bShowOutline_ = hasOutline;
sOutlineColor_ = outlineColor;
fOutlineWidth = 2 * outlineWidth;
nOutlineJoin_ = outlineJoin;

View File

@ -59,7 +59,7 @@ e2d::Text::Text(
bool italic,
bool hasUnderline,
bool hasStrikethrough,
bool showOutline,
bool hasOutline,
UINT32 outlineColor,
UINT32 outlineWidth
)
@ -72,7 +72,7 @@ e2d::Text::Text(
italic,
hasUnderline,
hasStrikethrough,
showOutline,
hasOutline,
outlineColor,
outlineWidth
)
@ -156,9 +156,19 @@ bool e2d::Text::isItalic() const
return m_TextStyle.italic;
}
bool e2d::Text::isShowOutline() const
bool e2d::Text::hasStrikethrough() const
{
return m_TextStyle.showOutline;
return m_TextStyle.hasStrikethrough;
}
bool e2d::Text::hasUnderline() const
{
return m_TextStyle.hasUnderline;
}
bool e2d::Text::hasOutline() const
{
return m_TextStyle.hasOutline;
}
void e2d::Text::setText(String text)
@ -232,9 +242,9 @@ void e2d::Text::setAlignment(int nAlign)
void e2d::Text::setUnderline(bool hasUnderline)
{
if (m_TextStyle.underline != hasUnderline)
if (m_TextStyle.hasUnderline != hasUnderline)
{
m_TextStyle.underline = hasUnderline;
m_TextStyle.hasUnderline = hasUnderline;
if (!m_pDWriteTextFormat)
_createFormat();
_createLayout();
@ -243,18 +253,18 @@ void e2d::Text::setUnderline(bool hasUnderline)
void e2d::Text::setStrikethrough(bool hasStrikethrough)
{
if (m_TextStyle.strikethrough != hasStrikethrough)
if (m_TextStyle.hasStrikethrough != hasStrikethrough)
{
m_TextStyle.strikethrough = hasStrikethrough;
m_TextStyle.hasStrikethrough = hasStrikethrough;
if (!m_pDWriteTextFormat)
_createFormat();
_createLayout();
}
}
void e2d::Text::showOutline(bool showOutline)
void e2d::Text::setOutline(bool hasOutline)
{
m_TextStyle.showOutline = showOutline;
m_TextStyle.hasOutline = hasOutline;
}
void e2d::Text::setOutlineColor(Color outlineColor)
@ -284,7 +294,7 @@ void e2d::Text::onRender()
auto pTextRenderer = Renderer::getCustomTextRenderer();
pTextRenderer->SetTextStyle(
m_TextStyle.color.toColorF(),
m_TextStyle.showOutline,
m_TextStyle.hasOutline,
m_TextStyle.outlineColor.toColorF(),
static_cast<FLOAT>(m_TextStyle.outlineWidth),
D2D1_LINE_JOIN(m_TextStyle.outlineJoin)
@ -409,11 +419,11 @@ void e2d::Text::_createLayout()
// Ìí¼ÓÏ»®ÏߺÍɾ³ýÏß
DWRITE_TEXT_RANGE range = { 0, length };
if (m_TextStyle.underline)
if (m_TextStyle.hasUnderline)
{
m_pDWriteTextLayout->SetUnderline(true, range);
}
if (m_TextStyle.strikethrough)
if (m_TextStyle.hasStrikethrough)
{
m_pDWriteTextLayout->SetStrikethrough(true, range);
}

View File

@ -210,10 +210,31 @@ private:
class Color
{
public:
float r;
float g;
float b;
float a;
Color();
Color(
double r,
double g,
double b
);
Color(
double r,
double g,
double b,
double alpha
);
Color(
UINT32 rgb
);
Color(
UINT32 rgb,
double alpha
);
D2D1_COLOR_F toColorF() const;
public:
enum RGB_VALUE : UINT32
@ -282,37 +303,17 @@ public:
YELLOW_GREEN = 0x9ACD32
};
public:
Color();
Color(
double r,
double g,
double b
);
Color(
double r,
double g,
double b,
double alpha
);
Color(
UINT32 rgb
);
Color(
protected:
void _init(
UINT32 rgb,
double alpha
);
void init(
UINT32 rgb,
double alpha
);
D2D1_COLOR_F toColorF() const;
protected:
float r;
float g;
float b;
float a;
};
@ -493,17 +494,17 @@ public:
// 文本样式
struct TextStyle
{
String fontFamily; // 字体
double fontSize; // 字号
Color color; // 颜色
UINT32 fontWeight; // 粗细值
bool italic; // 斜体
bool underline; // 下划线
bool strikethrough; // 删除线
bool showOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
int outlineJoin; // 描边线相交样式
String fontFamily; // 字体
double fontSize; // 字号
Color color; // 颜色
UINT32 fontWeight; // 粗细值
bool italic; // 斜体
bool hasUnderline; // 下划线
bool hasStrikethrough; // 删除线
bool hasOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
int outlineJoin; // 描边线相交样式
/* 构造函数 */
TextStyle();
@ -516,7 +517,7 @@ struct TextStyle
bool italic = false,
bool hasUnderline = false,
bool hasStrikethrough = false,
bool showOutline = true,
bool hasOutline = true,
Color outlineColor = Color::BLACK,
double outlineWidth = 1.0,
int outlineJoin = LineJoin::ROUND

View File

@ -28,7 +28,7 @@ namespace e2d
STDMETHOD_(void, SetTextStyle)(
CONST D2D1_COLOR_F &fillColor,
BOOL showOutline,
BOOL hasOutline,
CONST D2D1_COLOR_F &outlineColor,
FLOAT outlineWidth,
D2D1_LINE_JOIN outlineJoin

View File

@ -569,7 +569,7 @@ public:
bool italic = false, /* 斜体 */
bool hasUnderline = false, /* 下划线 */
bool hasStrikethrough = false, /* 删除线 */
bool showOutline = true, /* ÏÔʾÃè±ß */
bool hasOutline = true, /* 显示描边 */
UINT32 outlineColor = Color::BLACK, /* 描边颜色 */
UINT32 outlineWidth = 1.0 /* 描边线宽 */
);
@ -609,8 +609,14 @@ public:
// 是否是斜体
bool isItalic() const;
// 是否显示删除线
bool hasStrikethrough() const;
// 是否显示下划线
bool hasUnderline() const;
// 是否显示描边
bool isShowOutline() const;
bool hasOutline() const;
// 设置文本
void setText(
@ -673,8 +679,8 @@ public:
);
// 设置是否显示描边
void showOutline(
bool showOutline
void setOutline(
bool hasOutline
);
// 设置描边颜色