【增加borderround实现】

This commit is contained in:
xuhuajie-NetEase 2019-08-01 11:56:05 +08:00
parent e7cd6125da
commit 7c8332bf9f
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,6 +1429,25 @@ void Control::PaintBorder(IRenderContext* pRender)
} }
if(dwBorderColor != 0) { if(dwBorderColor != 0) {
//判断是否需要画圆角矩阵
if ((m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0) && 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->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) { if (m_rcBorderSize.left > 0 || m_rcBorderSize.top > 0 || m_rcBorderSize.right > 0 || m_rcBorderSize.bottom > 0) {
UiRect rcBorder; UiRect rcBorder;
if (m_rcBorderSize.left > 0) { if (m_rcBorderSize.left > 0) {
@ -1479,7 +1498,7 @@ void Control::PaintBorder(IRenderContext* pRender)
} }
pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor); 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;