Adjust the method of drawing rounded borders

Signed-off-by: jiajia_deng <2894220@gmail.com>
This commit is contained in:
jiajia_deng 2019-08-02 10:53:50 +08:00
parent ad9ef19e01
commit bb82e1cb93
8 changed files with 191 additions and 218 deletions

View File

@ -52,5 +52,5 @@ Enter the `NIM_Duilib_Framework/samples` directoryOpen `samples.sln` with Vis
## Communication ## Communication
- Question: Read the [Documentation](docs/SUMMARY.md) and [Samples code](samples/README.md) to help you. - Question: Read the [Documentation](docs/SUMMARY.md) and [Samples code](samples/README.md) to help you.
- Report: File a bug in GitHub issues - Report: File a bug in GitHub issues.
- Suggestion: Request a new feature in Github issues. - Suggestion: Request a new feature in Github issues.

View File

@ -34,12 +34,10 @@
<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" bordersize="1" bordercolor="red" borderround="5,5"> <VListBox class="list" name="list" padding="5,3,5,3">
</VListBox> </VListBox>
<!-- TreeView --> <!-- TreeView -->
<TreeView class="list" name="tree" padding="5,3,5,3" margin="20"> <TreeView class="list" name="tree" padding="5,3,5,3" margin="20">
</TreeView> </TreeView>
</HBox> </HBox>
<Control class="splitline_hor_level1"/> <Control class="splitline_hor_level1"/>

View File

@ -207,9 +207,6 @@
<Project>{0149ba6e-3c0a-426d-aa0a-0b9ec7742f19}</Project> <Project>{0149ba6e-3c0a-426d-aa0a-0b9ec7742f19}</Project>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\..\bin\resources.zip" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -55,7 +55,4 @@
<Filter>资源文件</Filter> <Filter>资源文件</Filter>
</Image> </Image>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="..\..\bin\resources.zip" />
</ItemGroup>
</Project> </Project>

View File

@ -1429,25 +1429,6 @@ 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) {
@ -1496,11 +1477,14 @@ void Control::PaintBorder(IRenderContext* pRender)
if (m_nBorderSize % 2 != 0) { if (m_nBorderSize % 2 != 0) {
rcDraw.right -= 1; rcDraw.right -= 1;
} }
if (m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0)
pRender->DrawRoundRect(rcDraw, m_cxyBorderRound, m_nBorderSize, dwBorderColor);
else
pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor); pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor);
} }
} }
} }
}
void Control::SetAlpha(int alpha) void Control::SetAlpha(int alpha)
{ {

View File

@ -204,7 +204,7 @@ 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 DrawRoundRect(const UiRect& rc, const CSize& roundSize, 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;

View File

@ -471,30 +471,27 @@ void RenderContext_GdiPlus::DrawRect(const UiRect& rc, int nSize, DWORD dwPenCol
} }
void RenderContext_GdiPlus::DrawRoundRect(const UiRect& rc, const SIZE& round, int nSize, DWORD dwPenColor) void RenderContext_GdiPlus::DrawRoundRect(const UiRect& rc, const CSize& roundSize, int nSize, DWORD dwPenColor)
{ {
Gdiplus::Graphics graphics(m_hDC); Gdiplus::Graphics graphics(m_hDC);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize); Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
// 裁剪区域不能作画,导致边框有时不全,往里收缩一个像素 // 裁剪区域不能作画,导致边框有时不全,往里收缩一个像素
UiRect _rc = rc; // UiRect rcInflate = rc;
_rc.left += 1; // rcInflate.Inflate({ -1, -1, -1, -1 });
_rc.top += 1;
_rc.right -= 1;
_rc.bottom -= 1;
//͸Ã÷»­Ë¢
Gdiplus::SolidBrush brShadow(Gdiplus::Color(0,0, 0, 0));
Gdiplus::GraphicsPath pPath; Gdiplus::GraphicsPath pPath;
pPath.AddArc(_rc.left, _rc.top, round.cx, round.cy, 180, 90); pPath.AddArc(rc.left, rc.top, roundSize.cx, roundSize.cy, 180, 90);
pPath.AddLine(_rc.left + round.cx, _rc.top, _rc.right - round.cx, _rc.top); pPath.AddLine(rc.left + roundSize.cx, rc.top, rc.right - roundSize.cx, rc.top);
pPath.AddArc(_rc.right - round.cx, _rc.top, round.cx, round.cy, 270, 90); pPath.AddArc(rc.right - roundSize.cx, rc.top, roundSize.cx, roundSize.cy, 270, 90);
pPath.AddLine(_rc.right, _rc.top + round.cy, _rc.right, _rc.bottom - round.cy); pPath.AddLine(rc.right, rc.top + roundSize.cy, rc.right, rc.bottom - roundSize.cy);
pPath.AddArc(_rc.right - round.cx, _rc.bottom - round.cy, round.cx, round.cy, 0, 90); pPath.AddArc(rc.right - roundSize.cx, rc.bottom - roundSize.cy, roundSize.cx, roundSize.cy, 0, 90);
pPath.AddLine(_rc.right - round.cx, _rc.bottom, _rc.left + round.cx, _rc.bottom); pPath.AddLine(rc.right - roundSize.cx, rc.bottom, rc.left + roundSize.cx, rc.bottom);
pPath.AddArc(_rc.left, _rc.bottom - round.cy, round.cx, round.cy, 90, 90); pPath.AddArc(rc.left, rc.bottom - roundSize.cy, roundSize.cx, roundSize.cy, 90, 90);
pPath.AddLine(_rc.left, _rc.bottom - round.cy, _rc.left, _rc.top + round.cy); pPath.AddLine(rc.left, rc.bottom - roundSize.cy, rc.left, rc.top + roundSize.cy);
pPath.CloseFigure(); pPath.CloseFigure();
graphics.FillPath(&brShadow, &pPath);
graphics.DrawPath(&pen, &pPath); graphics.DrawPath(&pen, &pPath);
} }

View File

@ -51,7 +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 DrawRoundRect(const UiRect& rc, const CSize& roundSize, 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;