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

@ -1428,10 +1428,43 @@ void Control::PaintBorder(IRenderContext* pRender)
dwBorderColor = GlobalManager::GetTextColor(m_strBorderColor); dwBorderColor = GlobalManager::GetTextColor(m_strBorderColor);
} }
if(dwBorderColor != 0) { if (dwBorderColor != 0) {
//判断是否需要画圆角矩阵 if (m_rcBorderSize.left > 0 || m_rcBorderSize.top > 0 || m_rcBorderSize.right > 0 || m_rcBorderSize.bottom > 0) {
if ((m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0) && m_nBorderSize > 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; UiRect rcDraw = m_rcItem;
int nDeltaValue = m_nBorderSize / 2; int nDeltaValue = m_nBorderSize / 2;
rcDraw.top += nDeltaValue; rcDraw.top += nDeltaValue;
@ -1444,60 +1477,11 @@ void Control::PaintBorder(IRenderContext* pRender)
if (m_nBorderSize % 2 != 0) { if (m_nBorderSize % 2 != 0) {
rcDraw.right -= 1; rcDraw.right -= 1;
} }
pRender->DrawRoundRect(rcDraw, m_cxyBorderRound, m_nBorderSize, dwBorderColor);
} if (m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0)
else 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); pRender->DrawRect(rcDraw, m_nBorderSize, dwBorderColor);
}
} }
} }
} }

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

@ -189,23 +189,23 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
const UiRect& rcImageDest, const UiRect& rcImageSource, const UiRect& rcCorners, BYTE uFade /*= 255*/, bool xtiled /*= false*/, bool ytiled /*= false*/) const UiRect& rcImageDest, const UiRect& rcImageSource, const UiRect& rcCorners, BYTE uFade /*= 255*/, bool xtiled /*= false*/, bool ytiled /*= false*/)
{ {
UiRect rcTestTemp; UiRect rcTestTemp;
if( !::IntersectRect(&rcTestTemp, &rcImageDest, &rcPaint) ) return; if (!::IntersectRect(&rcTestTemp, &rcImageDest, &rcPaint)) return;
ASSERT(::GetObjectType(m_hDC)==OBJ_DC || ::GetObjectType(m_hDC)==OBJ_MEMDC); ASSERT(::GetObjectType(m_hDC) == OBJ_DC || ::GetObjectType(m_hDC) == OBJ_MEMDC);
if( hBitmap == NULL ) return; if (hBitmap == NULL) return;
HDC hCloneDC = ::CreateCompatibleDC(m_hDC); HDC hCloneDC = ::CreateCompatibleDC(m_hDC);
HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hCloneDC, hBitmap); HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hCloneDC, hBitmap);
int stretchBltMode = ::SetStretchBltMode(m_hDC, HALFTONE); int stretchBltMode = ::SetStretchBltMode(m_hDC, HALFTONE);
UiRect rcTemp; UiRect rcTemp;
UiRect rcSource; UiRect rcSource;
UiRect rcDest; UiRect rcDest;
UiRect rcDpiCorner = rcCorners; UiRect rcDpiCorner = rcCorners;
DpiManager::GetInstance()->ScaleRect(rcDpiCorner); DpiManager::GetInstance()->ScaleRect(rcDpiCorner);
// middle // middle
rcDest.left = rcImageDest.left + rcDpiCorner.left; rcDest.left = rcImageDest.left + rcDpiCorner.left;
rcDest.top = rcImageDest.top + rcDpiCorner.top; rcDest.top = rcImageDest.top + rcDpiCorner.top;
rcDest.right = rcImageDest.right - rcDpiCorner.right; rcDest.right = rcImageDest.right - rcDpiCorner.right;
@ -214,31 +214,31 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.top = rcImageSource.top + rcCorners.top; rcSource.top = rcImageSource.top + rcCorners.top;
rcSource.right = rcImageSource.right - rcCorners.right; rcSource.right = rcImageSource.right - rcCorners.right;
rcSource.bottom = rcImageSource.bottom - rcCorners.bottom; rcSource.bottom = rcImageSource.bottom - rcCorners.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
if( !xtiled && !ytiled ) { if (!xtiled && !ytiled) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
else if( xtiled && ytiled ) { else if (xtiled && ytiled) {
LONG lWidth = rcImageSource.right - rcImageSource.left - rcCorners.left - rcCorners.right; LONG lWidth = rcImageSource.right - rcImageSource.left - rcCorners.left - rcCorners.right;
LONG lHeight = rcImageSource.bottom - rcImageSource.top - rcCorners.top - rcCorners.bottom; LONG lHeight = rcImageSource.bottom - rcImageSource.top - rcCorners.top - rcCorners.bottom;
int iTimesX = (rcDest.right - rcDest.left + lWidth - 1) / lWidth; int iTimesX = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
int iTimesY = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight; int iTimesY = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
for( int j = 0; j < iTimesY; ++j ) { for (int j = 0; j < iTimesY; ++j) {
LONG lDestTop = rcDest.top + lHeight * j; LONG lDestTop = rcDest.top + lHeight * j;
LONG lDestBottom = rcDest.top + lHeight * (j + 1); LONG lDestBottom = rcDest.top + lHeight * (j + 1);
LONG lDrawHeight = lHeight; LONG lDrawHeight = lHeight;
if( lDestBottom > rcDest.bottom ) { if (lDestBottom > rcDest.bottom) {
lDrawHeight -= lDestBottom - rcDest.bottom; lDrawHeight -= lDestBottom - rcDest.bottom;
lDestBottom = rcDest.bottom; lDestBottom = rcDest.bottom;
} }
for( int i = 0; i < iTimesX; ++i ) { for (int i = 0; i < iTimesX; ++i) {
LONG lDestLeft = rcDest.left + lWidth * i; LONG lDestLeft = rcDest.left + lWidth * i;
LONG lDestRight = rcDest.left + lWidth * (i + 1); LONG lDestRight = rcDest.left + lWidth * (i + 1);
LONG lDrawWidth = lWidth; LONG lDrawWidth = lWidth;
if( lDestRight > rcDest.right ) { if (lDestRight > rcDest.right) {
lDrawWidth -= lDestRight - rcDest.right; lDrawWidth -= lDestRight - rcDest.right;
lDestRight = rcDest.right; lDestRight = rcDest.right;
} }
rcDest.left = rcDest.left + lWidth * i; rcDest.left = rcDest.left + lWidth * i;
rcDest.top = rcDest.top + lHeight * j; rcDest.top = rcDest.top + lHeight * j;
rcDest.right = rcDest.left + lDestRight - lDestLeft; rcDest.right = rcDest.left + lDestRight - lDestLeft;
@ -247,21 +247,21 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.top = rcImageSource.top + rcCorners.top; rcSource.top = rcImageSource.top + rcCorners.top;
rcSource.right = rcSource.left + lDrawWidth; rcSource.right = rcSource.left + lDrawWidth;
rcSource.bottom = rcSource.top + lDrawHeight; rcSource.bottom = rcSource.top + lDrawHeight;
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
} }
else if( xtiled ) { else if (xtiled) {
LONG lWidth = rcImageSource.right - rcImageSource.left - rcCorners.left - rcCorners.right; LONG lWidth = rcImageSource.right - rcImageSource.left - rcCorners.left - rcCorners.right;
int iTimes = (rcDest.right - rcDest.left + lWidth - 1) / lWidth; int iTimes = (rcDest.right - rcDest.left + lWidth - 1) / lWidth;
for( int i = 0; i < iTimes; ++i ) { for (int i = 0; i < iTimes; ++i) {
LONG lDestLeft = rcDest.left + lWidth * i; LONG lDestLeft = rcDest.left + lWidth * i;
LONG lDestRight = rcDest.left + lWidth * (i + 1); LONG lDestRight = rcDest.left + lWidth * (i + 1);
LONG lDrawWidth = lWidth; LONG lDrawWidth = lWidth;
if( lDestRight > rcDest.right ) { if (lDestRight > rcDest.right) {
lDrawWidth -= lDestRight - rcDest.right; lDrawWidth -= lDestRight - rcDest.right;
lDestRight = rcDest.right; lDestRight = rcDest.right;
} }
rcDest.left = lDestLeft; rcDest.left = lDestLeft;
rcDest.top = rcDest.top; rcDest.top = rcDest.top;
rcDest.right = lDestRight; rcDest.right = lDestRight;
@ -271,19 +271,19 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.right = rcSource.left + lDrawWidth; rcSource.right = rcSource.left + lDrawWidth;
rcSource.bottom = rcImageSource.bottom - rcCorners.bottom; rcSource.bottom = rcImageSource.bottom - rcCorners.bottom;
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
else { // ytiled else { // ytiled
LONG lHeight = rcImageSource.bottom - rcImageSource.top - rcCorners.top - rcCorners.bottom; LONG lHeight = rcImageSource.bottom - rcImageSource.top - rcCorners.top - rcCorners.bottom;
int iTimes = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight; int iTimes = (rcDest.bottom - rcDest.top + lHeight - 1) / lHeight;
for( int i = 0; i < iTimes; ++i ) { for (int i = 0; i < iTimes; ++i) {
LONG lDestTop = rcDest.top + lHeight * i; LONG lDestTop = rcDest.top + lHeight * i;
LONG lDestBottom = rcDest.top + lHeight * (i + 1); LONG lDestBottom = rcDest.top + lHeight * (i + 1);
LONG lDrawHeight = lHeight; LONG lDrawHeight = lHeight;
if( lDestBottom > rcDest.bottom ) { if (lDestBottom > rcDest.bottom) {
lDrawHeight -= lDestBottom - rcDest.bottom; lDrawHeight -= lDestBottom - rcDest.bottom;
lDestBottom = rcDest.bottom; lDestBottom = rcDest.bottom;
} }
rcDest.left = rcDest.left; rcDest.left = rcDest.left;
rcDest.top = rcDest.top + lHeight * i; rcDest.top = rcDest.top + lHeight * i;
rcDest.right = rcDest.left + rcDest.right; rcDest.right = rcDest.left + rcDest.right;
@ -293,55 +293,55 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.right = rcImageSource.right - rcCorners.right; rcSource.right = rcImageSource.right - rcCorners.right;
rcSource.bottom = rcSource.top + lDrawHeight; rcSource.bottom = rcSource.top + lDrawHeight;
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
} }
// left-top // left-top
if( rcCorners.left > 0 && rcCorners.top > 0 ) { if (rcCorners.left > 0 && rcCorners.top > 0) {
rcDest.left = rcImageDest.left; rcDest.left = rcImageDest.left;
rcDest.top = rcImageDest.top; rcDest.top = rcImageDest.top;
rcDest.right = rcImageDest.left + rcDpiCorner.left; rcDest.right = rcImageDest.left + rcDpiCorner.left;
rcDest.bottom = rcImageDest.top + rcDpiCorner.top; rcDest.bottom = rcImageDest.top + rcDpiCorner.top;
rcSource.left = rcImageSource.left; rcSource.left = rcImageSource.left;
rcSource.top = rcImageSource.top; rcSource.top = rcImageSource.top;
rcSource.right = rcImageSource.left + rcCorners.left; rcSource.right = rcImageSource.left + rcCorners.left;
rcSource.bottom = rcImageSource.top + rcCorners.top; rcSource.bottom = rcImageSource.top + rcCorners.top;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// top // top
if( rcCorners.top > 0 ) { if (rcCorners.top > 0) {
rcDest.left = rcImageDest.left + rcDpiCorner.left; rcDest.left = rcImageDest.left + rcDpiCorner.left;
rcDest.top = rcImageDest.top; rcDest.top = rcImageDest.top;
rcDest.right = rcImageDest.right - rcDpiCorner.right; rcDest.right = rcImageDest.right - rcDpiCorner.right;
rcDest.bottom = rcImageDest.top + rcDpiCorner.top; rcDest.bottom = rcImageDest.top + rcDpiCorner.top;
rcSource.left = rcImageSource.left + rcCorners.left; rcSource.left = rcImageSource.left + rcCorners.left;
rcSource.top = rcImageSource.top; rcSource.top = rcImageSource.top;
rcSource.right = rcImageSource.right - rcCorners.right; rcSource.right = rcImageSource.right - rcCorners.right;
rcSource.bottom = rcImageSource.top + rcCorners.top; rcSource.bottom = rcImageSource.top + rcCorners.top;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// right-top // right-top
if( rcCorners.right > 0 && rcCorners.top > 0 ) { if (rcCorners.right > 0 && rcCorners.top > 0) {
rcDest.left = rcImageDest.right - rcDpiCorner.right; rcDest.left = rcImageDest.right - rcDpiCorner.right;
rcDest.top = rcImageDest.top; rcDest.top = rcImageDest.top;
rcDest.right = rcImageDest.right; rcDest.right = rcImageDest.right;
rcDest.bottom = rcImageDest.top + rcDpiCorner.top; rcDest.bottom = rcImageDest.top + rcDpiCorner.top;
rcSource.left = rcImageSource.right - rcCorners.right; rcSource.left = rcImageSource.right - rcCorners.right;
rcSource.top = rcImageSource.top; rcSource.top = rcImageSource.top;
rcSource.right = rcImageSource.right; rcSource.right = rcImageSource.right;
rcSource.bottom = rcImageSource.top + rcCorners.top; rcSource.bottom = rcImageSource.top + rcCorners.top;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// left // left
if( rcCorners.left > 0 ) { if (rcCorners.left > 0) {
rcDest.left = rcImageDest.left; rcDest.left = rcImageDest.left;
rcDest.top = rcImageDest.top + rcDpiCorner.top; rcDest.top = rcImageDest.top + rcDpiCorner.top;
rcDest.right = rcImageDest.left + rcDpiCorner.left; rcDest.right = rcImageDest.left + rcDpiCorner.left;
rcDest.bottom = rcImageDest.bottom - rcDpiCorner.bottom; rcDest.bottom = rcImageDest.bottom - rcDpiCorner.bottom;
@ -349,54 +349,54 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.top = rcImageSource.top + rcCorners.top; rcSource.top = rcImageSource.top + rcCorners.top;
rcSource.right = rcImageSource.left + rcCorners.left; rcSource.right = rcImageSource.left + rcCorners.left;
rcSource.bottom = rcImageSource.bottom - rcCorners.bottom; rcSource.bottom = rcImageSource.bottom - rcCorners.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// right // right
if( rcCorners.right > 0 ) { if (rcCorners.right > 0) {
rcDest.left = rcImageDest.right - rcDpiCorner.right; rcDest.left = rcImageDest.right - rcDpiCorner.right;
rcDest.top = rcImageDest.top + rcDpiCorner.top; rcDest.top = rcImageDest.top + rcDpiCorner.top;
rcDest.right = rcImageDest.right; rcDest.right = rcImageDest.right;
rcDest.bottom = rcImageDest.bottom - rcDpiCorner.bottom; rcDest.bottom = rcImageDest.bottom - rcDpiCorner.bottom;
rcSource.left = rcImageSource.right - rcCorners.right; rcSource.left = rcImageSource.right - rcCorners.right;
rcSource.top = rcImageSource.top + rcCorners.top; rcSource.top = rcImageSource.top + rcCorners.top;
rcSource.right = rcImageSource.right; rcSource.right = rcImageSource.right;
rcSource.bottom = rcImageSource.bottom - rcCorners.bottom; rcSource.bottom = rcImageSource.bottom - rcCorners.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// left-bottom // left-bottom
if( rcCorners.left > 0 && rcCorners.bottom > 0 ) { if (rcCorners.left > 0 && rcCorners.bottom > 0) {
rcDest.left = rcImageDest.left; rcDest.left = rcImageDest.left;
rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom; rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom;
rcDest.right = rcImageDest.left + rcDpiCorner.left; rcDest.right = rcImageDest.left + rcDpiCorner.left;
rcDest.bottom = rcImageDest.bottom; rcDest.bottom = rcImageDest.bottom;
rcSource.left = rcImageSource.left; rcSource.left = rcImageSource.left;
rcSource.top = rcImageSource.bottom - rcCorners.bottom; rcSource.top = rcImageSource.bottom - rcCorners.bottom;
rcSource.right = rcImageSource.left + rcCorners.left; rcSource.right = rcImageSource.left + rcCorners.left;
rcSource.bottom = rcImageSource.bottom; rcSource.bottom = rcImageSource.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// bottom // bottom
if( rcCorners.bottom > 0 ) { if (rcCorners.bottom > 0) {
rcDest.left = rcImageDest.left + rcDpiCorner.left; rcDest.left = rcImageDest.left + rcDpiCorner.left;
rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom; rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom;
rcDest.right = rcImageDest.right - rcDpiCorner.right; rcDest.right = rcImageDest.right - rcDpiCorner.right;
rcDest.bottom = rcImageDest.bottom; rcDest.bottom = rcImageDest.bottom;
rcSource.left = rcImageSource.left + rcCorners.left; rcSource.left = rcImageSource.left + rcCorners.left;
rcSource.top = rcImageSource.bottom - rcCorners.bottom; rcSource.top = rcImageSource.bottom - rcCorners.bottom;
rcSource.right = rcImageSource.right - rcCorners.right; rcSource.right = rcImageSource.right - rcCorners.right;
rcSource.bottom = rcImageSource.bottom; rcSource.bottom = rcImageSource.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
// right-bottom // right-bottom
if( rcCorners.right > 0 && rcCorners.bottom > 0 ) { if (rcCorners.right > 0 && rcCorners.bottom > 0) {
rcDest.left = rcImageDest.right - rcDpiCorner.right; rcDest.left = rcImageDest.right - rcDpiCorner.right;
rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom; rcDest.top = rcImageDest.bottom - rcDpiCorner.bottom;
rcDest.right = rcImageDest.right; rcDest.right = rcImageDest.right;
@ -405,14 +405,14 @@ void RenderContext_GdiPlus::DrawImage(const UiRect& rcPaint, HBITMAP hBitmap, bo
rcSource.top = rcImageSource.bottom - rcCorners.bottom; rcSource.top = rcImageSource.bottom - rcCorners.bottom;
rcSource.right = rcImageSource.right; rcSource.right = rcImageSource.right;
rcSource.bottom = rcImageSource.bottom; rcSource.bottom = rcImageSource.bottom;
if( ::IntersectRect(&rcTemp, &rcPaint, &rcDest) ) { if (::IntersectRect(&rcTemp, &rcPaint, &rcDest)) {
DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade); DrawFunction(m_hDC, m_bTransparent, rcDest, hCloneDC, rcSource, bAlphaChannel, uFade);
} }
} }
::SetStretchBltMode(m_hDC, stretchBltMode); ::SetStretchBltMode(m_hDC, stretchBltMode);
::SelectObject(hCloneDC, hOldBitmap); ::SelectObject(hCloneDC, hOldBitmap);
::DeleteDC(hCloneDC); ::DeleteDC(hCloneDC);
} }
void RenderContext_GdiPlus::DrawColor(const UiRect& rc, DWORD dwColor, BYTE uFade) void RenderContext_GdiPlus::DrawColor(const UiRect& rc, DWORD dwColor, BYTE uFade)
@ -442,7 +442,7 @@ void RenderContext_GdiPlus::DrawColor(const UiRect& rc, const std::wstring& colo
DrawColor(rc, dwColor, uFade); DrawColor(rc, dwColor, uFade);
} }
void RenderContext_GdiPlus::DrawLine( const UiRect& rc, int nSize, DWORD dwPenColor) void RenderContext_GdiPlus::DrawLine(const UiRect& rc, int nSize, DWORD dwPenColor)
{ {
Gdiplus::Graphics graphics(m_hDC); Gdiplus::Graphics graphics(m_hDC);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize); Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
@ -471,39 +471,36 @@ 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; // 裁剪区域不能作画,导致边框有时不全,往里收缩一个像素
_rc.left += 1; // UiRect rcInflate = rc;
_rc.top += 1; // rcInflate.Inflate({ -1, -1, -1, -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);
} }
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);
if( strText.empty() ) return; if (strText.empty()) return;
Gdiplus::Graphics graphics( m_hDC ); Gdiplus::Graphics graphics(m_hDC);
Gdiplus::Font font(m_hDC, GlobalManager::GetFont(strFontId)); Gdiplus::Font font(m_hDC, GlobalManager::GetFont(strFontId));
Gdiplus::RectF rcPaint((Gdiplus::REAL)rc.left, (Gdiplus::REAL)rc.top, (Gdiplus::REAL)(rc.right - rc.left), (Gdiplus::REAL)(rc.bottom - rc.top)); Gdiplus::RectF rcPaint((Gdiplus::REAL)rc.left, (Gdiplus::REAL)rc.top, (Gdiplus::REAL)(rc.right - rc.left), (Gdiplus::REAL)(rc.bottom - rc.top));
int alpha = dwTextColor >> 24; int alpha = dwTextColor >> 24;

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;