Merge pull request #98 from xuhuajie-NetEase/development

【增加borderround实现】
This commit is contained in:
Dylan 2019-08-01 13:43:48 +08:00 committed by GitHub
commit 0ac3aa5b23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 683 additions and 640 deletions

View File

@ -34,7 +34,7 @@
<Option class="circle_option_2" group="option_group" text="option3" margin="0,3,0,10"/> <Option class="circle_option_2" group="option_group" text="option3" margin="0,3,0,10"/>
</VBox> </VBox>
<!-- List --> <!-- List -->
<VListBox class="list" name="list" padding="5,3,5,3"> <VListBox class="list" name="list" padding="5,3,5,3" bordersize="1" bordercolor="red" borderround="5,5">
</VListBox> </VListBox>
<!-- TreeView --> <!-- TreeView -->

View File

@ -1429,42 +1429,9 @@ void Control::PaintBorder(IRenderContext* pRender)
} }
if(dwBorderColor != 0) { if(dwBorderColor != 0) {
if(m_rcBorderSize.left > 0 || m_rcBorderSize.top > 0 || m_rcBorderSize.right > 0 || m_rcBorderSize.bottom > 0) { //判断是否需要画圆角矩阵
UiRect rcBorder; if ((m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0) && m_nBorderSize > 0)
if(m_rcBorderSize.left > 0) { {
rcBorder = m_rcItem;
rcBorder.right = rcBorder.left = m_rcItem.left + m_rcBorderSize.left / 2;
if (m_rcBorderSize.left == 1) {
rcBorder.bottom -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.left, dwBorderColor);
}
if(m_rcBorderSize.top > 0) {
rcBorder = m_rcItem;
rcBorder.bottom = rcBorder.top = m_rcItem.top + m_rcBorderSize.top / 2;
if (m_rcBorderSize.top == 1) {
rcBorder.right -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.top, dwBorderColor);
}
if(m_rcBorderSize.right > 0) {
rcBorder = m_rcItem;
rcBorder.left = rcBorder.right = m_rcItem.right - (m_rcBorderSize.right + 1) / 2;
if (m_rcBorderSize.right == 1) {
rcBorder.bottom -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.right, dwBorderColor);
}
if(m_rcBorderSize.bottom > 0) {
rcBorder = m_rcItem;
rcBorder.top = rcBorder.bottom = m_rcItem.bottom - (m_rcBorderSize.bottom + 1) / 2;
if (m_rcBorderSize.bottom == 1) {
rcBorder.right -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.bottom, dwBorderColor);
}
}
else if(m_nBorderSize > 0) {
UiRect rcDraw = m_rcItem; UiRect rcDraw = m_rcItem;
int nDeltaValue = m_nBorderSize / 2; int nDeltaValue = m_nBorderSize / 2;
rcDraw.top += nDeltaValue; rcDraw.top += nDeltaValue;
@ -1477,9 +1444,61 @@ void Control::PaintBorder(IRenderContext* pRender)
if (m_nBorderSize % 2 != 0) { if (m_nBorderSize % 2 != 0) {
rcDraw.right -= 1; rcDraw.right -= 1;
} }
pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor); pRender->DrawRoundRect(rcDraw, m_cxyBorderRound, m_nBorderSize, dwBorderColor);
}
else
{
if (m_rcBorderSize.left > 0 || m_rcBorderSize.top > 0 || m_rcBorderSize.right > 0 || m_rcBorderSize.bottom > 0) {
UiRect rcBorder;
if (m_rcBorderSize.left > 0) {
rcBorder = m_rcItem;
rcBorder.right = rcBorder.left = m_rcItem.left + m_rcBorderSize.left / 2;
if (m_rcBorderSize.left == 1) {
rcBorder.bottom -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.left, dwBorderColor);
}
if (m_rcBorderSize.top > 0) {
rcBorder = m_rcItem;
rcBorder.bottom = rcBorder.top = m_rcItem.top + m_rcBorderSize.top / 2;
if (m_rcBorderSize.top == 1) {
rcBorder.right -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.top, dwBorderColor);
}
if (m_rcBorderSize.right > 0) {
rcBorder = m_rcItem;
rcBorder.left = rcBorder.right = m_rcItem.right - (m_rcBorderSize.right + 1) / 2;
if (m_rcBorderSize.right == 1) {
rcBorder.bottom -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.right, dwBorderColor);
}
if (m_rcBorderSize.bottom > 0) {
rcBorder = m_rcItem;
rcBorder.top = rcBorder.bottom = m_rcItem.bottom - (m_rcBorderSize.bottom + 1) / 2;
if (m_rcBorderSize.bottom == 1) {
rcBorder.right -= 1;
}
pRender->DrawLine(rcBorder, m_rcBorderSize.bottom, dwBorderColor);
}
}
else if (m_nBorderSize > 0) {
UiRect rcDraw = m_rcItem;
int nDeltaValue = m_nBorderSize / 2;
rcDraw.top += nDeltaValue;
rcDraw.bottom -= nDeltaValue;
if (m_nBorderSize % 2 != 0) {
rcDraw.bottom -= 1;
}
rcDraw.left += nDeltaValue;
rcDraw.right -= nDeltaValue;
if (m_nBorderSize % 2 != 0) {
rcDraw.right -= 1;
}
pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor);
}
} }
} }
} }

View File

@ -204,6 +204,8 @@ public:
virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) = 0; virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) = 0;
virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) = 0; virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) = 0;
virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) = 0; virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) = 0;
virtual void DrawRoundRect(const UiRect& rc, const SIZE& round, int nSize, DWORD dwPenColor) = 0;
virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) = 0; virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) = 0;
virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) = 0; virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) = 0;

View File

@ -470,6 +470,27 @@ void RenderContext_GdiPlus::DrawRect(const UiRect& rc, int nSize, DWORD dwPenCol
graphics.DrawRectangle(&pen, rc.left, rc.top, rc.GetWidth(), rc.GetHeight()); graphics.DrawRectangle(&pen, rc.left, rc.top, rc.GetWidth(), rc.GetHeight());
} }
void RenderContext_GdiPlus::DrawRoundRect(const UiRect& rc, const SIZE& round, int nSize, DWORD dwPenColor)
{
Gdiplus::Graphics graphics(m_hDC);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
Gdiplus::SolidBrush brShadow(Gdiplus::Color(255, 255, 255));
Gdiplus::GraphicsPath m_pPath;
m_pPath.AddArc(rc.left, rc.top, round.cx * 2, round.cy * 2, 180, 90);
m_pPath.AddLine(rc.left + round.cx, rc.top, rc.right - round.cx * 2, rc.top);
m_pPath.AddArc(rc.left + rc.GetWidth() - round.cx * 2, rc.top, round.cx * 2, round.cy * 2, 270, 90);
m_pPath.AddLine(rc.right, rc.top + round.cy * 2, rc.right, rc.top + rc.GetHeight() - round.cy * 2);
m_pPath.AddArc(rc.left + rc.GetWidth() - round.cx * 2, rc.top + rc.GetHeight() - round.cy * 2, round.cx * 2, round.cy * 2, 0, 90);
m_pPath.AddLine(rc.right - round.cx * 2, rc.bottom, rc.left + round.cx * 2, rc.bottom);
m_pPath.AddArc(rc.left, rc.bottom - round.cy * 2, round.cx * 2, round.cy * 2, 90, 90);
m_pPath.AddLine(rc.left, rc.bottom - round.cy * 2, rc.left, rc.top + round.cy * 2);
m_pPath.CloseFigure();
graphics.FillPath(&brShadow, &m_pPath);
graphics.DrawPath(&pen, &m_pPath);
}
void RenderContext_GdiPlus::DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade /*= 255*/, bool bLineLimit /*= false*/) void RenderContext_GdiPlus::DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade /*= 255*/, bool bLineLimit /*= false*/)
{ {
ASSERT(::GetObjectType(m_hDC)==OBJ_DC || ::GetObjectType(m_hDC)==OBJ_MEMDC); ASSERT(::GetObjectType(m_hDC)==OBJ_DC || ::GetObjectType(m_hDC)==OBJ_MEMDC);

View File

@ -51,6 +51,7 @@ public:
virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) override; virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) override;
virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) override; virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) override;
virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) override; virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) override;
virtual void DrawRoundRect(const UiRect& rc, const SIZE& round, int nSize, DWORD dwPenColor) override;
virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) override; virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) override;
virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) override; virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) override;