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) 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) 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) e2d::Color::Color(UINT32 rgb)
{ {
init(rgb, 1); _init(rgb, 1);
} }
e2d::Color::Color(UINT32 rgb, double alpha) 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; r = static_cast<float>((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = static_cast<float>((rgb & sc_greenMask) >> sc_greenShift) / 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) , color(Color::WHITE)
, fontWeight(FontWeight::NORMAL) , fontWeight(FontWeight::NORMAL)
, italic(false) , italic(false)
, underline(false) , hasUnderline(false)
, strikethrough(false) , hasStrikethrough(false)
, showOutline(true) , hasOutline(true)
, outlineColor(Color::BLACK) , outlineColor(Color::BLACK)
, outlineWidth(1.0) , outlineWidth(1.0)
, outlineJoin(LineJoin::ROUND) , outlineJoin(LineJoin::ROUND)
@ -22,7 +22,7 @@ e2d::TextStyle::TextStyle(
bool italic, bool italic,
bool hasUnderline, bool hasUnderline,
bool hasStrikethrough, bool hasStrikethrough,
bool showOutline, bool hasOutline,
Color outlineColor, Color outlineColor,
double outlineWidth, double outlineWidth,
int outlineJoin int outlineJoin
@ -32,9 +32,9 @@ e2d::TextStyle::TextStyle(
, color(color) , color(color)
, fontWeight(fontWeight) , fontWeight(fontWeight)
, italic(italic) , italic(italic)
, underline(hasUnderline) , hasUnderline(hasUnderline)
, strikethrough(hasStrikethrough) , hasStrikethrough(hasStrikethrough)
, showOutline(showOutline) , hasOutline(hasOutline)
, outlineColor(outlineColor) , outlineColor(outlineColor)
, outlineWidth(outlineWidth) , outlineWidth(outlineWidth)
, outlineJoin(outlineJoin) , outlineJoin(outlineJoin)

View File

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

View File

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

View File

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

View File

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

View File

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