Skip to content

Commit

Permalink
修改RenderEngine为Gdi+渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
redrains committed Apr 25, 2016
1 parent 435a5aa commit dbb827b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 731 deletions.
71 changes: 41 additions & 30 deletions DuiLib/Core/UIRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void CRenderClip::GenerateRoundClip(HDC hDC, RECT rc, RECT rcItem, int width, in
::GetClipBox(hDC, &rcClip);
clip.hOldRgn = ::CreateRectRgnIndirect(&rcClip);
clip.hRgn = ::CreateRectRgnIndirect(&rc);
HRGN hRgnItem = ::CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right + 1, rcItem.bottom + 1, width, height);
HRGN hRgnItem = ::CreateRoundRectRgn(rcItem.left, rcItem.top, rcItem.right + 1, rcItem.bottom + 1, width*2, height*2);
::CombineRgn(clip.hRgn, clip.hRgn, hRgnItem, RGN_AND);
::ExtSelectClipRgn(hDC, clip.hRgn, RGN_AND);
clip.hDC = hDC;
Expand Down Expand Up @@ -763,39 +763,53 @@ void CRenderEngine::DrawLine( HDC hDC, const RECT& rc, int nSize, DWORD dwPenCol
{
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);

LOGPEN lg;
lg.lopnColor = RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor));
lg.lopnStyle = nStyle;
lg.lopnWidth.x = nSize;
HPEN hPen = CreatePenIndirect(&lg);
HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
POINT ptTemp = { 0 };
::MoveToEx(hDC, rc.left, rc.top, &ptTemp);
::LineTo(hDC, rc.right, rc.bottom);
::SelectObject(hDC, hOldPen);
::DeleteObject(hPen);
Gdiplus::Graphics graphics(hDC);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
pen.SetDashStyle((Gdiplus::DashStyle)nStyle);
graphics.DrawLine(&pen, Gdiplus::Point(rc.left, rc.top), Gdiplus::Point(rc.right, rc.bottom));
}

void CRenderEngine::DrawRect(HDC hDC, const RECT& rc, int nSize, DWORD dwPenColor)
{
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor)));
HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
::SelectObject(hDC, hOldPen);
::DeleteObject(hPen);
ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC);
Gdiplus::Graphics graphics(hDC);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
pen.SetAlignment(Gdiplus::PenAlignmentInset);

graphics.DrawRectangle(&pen, rc.left, rc.top, rc.right-rc.left-1, rc.bottom-rc.top-1);
}

void CRenderEngine::DrawRoundRect(HDC hDC, const RECT& rc, int nSize, int width, int height, DWORD dwPenColor)
{
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, nSize, RGB(GetBValue(dwPenColor), GetGValue(dwPenColor), GetRValue(dwPenColor)));
HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
::RoundRect(hDC, rc.left, rc.top, rc.right, rc.bottom, width, height);
::SelectObject(hDC, hOldPen);
::DeleteObject(hPen);
ASSERT(::GetObjectType(hDC) == OBJ_DC || ::GetObjectType(hDC) == OBJ_MEMDC);
Gdiplus::Graphics graphics(hDC);
Gdiplus::Pen pen(Gdiplus::Color(dwPenColor), (Gdiplus::REAL)nSize);
pen.SetAlignment(Gdiplus::PenAlignmentInset);

Gdiplus::GraphicsPath path;
// 把圆角矩形分成直线、弧的组合,依次加到路径中
//
path.AddLine(Gdiplus::Point(rc.left, rc.bottom - height), Gdiplus::Point(rc.left, rc.top + height));
//左上
path.AddArc(rc.left, rc.top, width * 2, height * 2, (Gdiplus::REAL)180, (Gdiplus::REAL)90);

//
path.AddLine(Gdiplus::Point(rc.left + width, rc.top), Gdiplus::Point(rc.right - width, rc.top));
//右上
path.AddArc(rc.right - width * 2-1, rc.top, width * 2, height * 2, (Gdiplus::REAL)270, (Gdiplus::REAL)90);

//
path.AddLine(Gdiplus::Point(rc.right-1, rc.top + height), Gdiplus::Point(rc.right-1, rc.bottom - height));
//右下
path.AddArc(rc.right - width * 2-1, rc.bottom - height * 2-1, width * 2, height * 2, (Gdiplus::REAL)0, (Gdiplus::REAL)90);

//
path.AddLine(Gdiplus::Point(rc.right - width, rc.bottom-1), Gdiplus::Point(rc.left + width, rc.bottom-1));
//左下
path.AddArc(rc.left, rc.bottom - height * 2-1, width * 2, height * 2, (Gdiplus::REAL)90, (Gdiplus::REAL)90);

graphics.DrawPath(&pen, &path);

}

void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle)
Expand Down Expand Up @@ -866,8 +880,7 @@ void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTS
else
{
graphics.DrawString(pstrText, -1, &font, rectF, &stringFormat, &brush);
}

}
}
else
{
Expand All @@ -876,9 +889,7 @@ void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTS
HFONT hOldFont = (HFONT)::SelectObject(hDC, pManager->GetFont(iFont));
::DrawText(hDC, pstrText, -1, &rc, uStyle | DT_NOPREFIX);
::SelectObject(hDC, hOldFont);

}

}

void CRenderEngine::DrawHtmlText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, RECT* prcLinks, CDuiString* sLinks, int& nLinkRects, UINT uStyle)
Expand Down
65 changes: 0 additions & 65 deletions DuiLib/DuiLib.vcproj.REDRAIN-PC.Redrain.user

This file was deleted.

Loading

0 comments on commit dbb827b

Please sign in to comment.