void CLayoutManager::Draw(CDC* pDC) { CSize szForm = GetForm()->GetInitSize(); CRect rcPaint(0, 0, szForm.cx, szForm.cy); CControlUI* pForm = m_Manager.GetRoot(); pForm->DoPaint(pDC->GetSafeHdc(), rcPaint); CContainerUI* pContainer = static_cast<CContainerUI*>(pForm->GetInterface(_T("Container"))); ASSERT(pContainer); DrawAuxBorder(pDC, pContainer->GetItemAt(0)); DrawGrid(pDC, rcPaint); }
void CControlUI::DoPaint(HDC hDC, const RECT& rcPaint) { if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; // 绘制循序:背景颜色->背景图->状态图->文本->边框if( m_cxyBorderRound.cx > 0 || m_cxyBorderRound.cy > 0 ) { CRenderClip roundClip; CRenderClip::GenerateRoundClip(hDC, m_rcPaint, m_rcItem, m_cxyBorderRound.cx, m_cxyBorderRound.cy, roundClip); PaintBkColor(hDC); PaintBkImage(hDC); PaintStatusImage(hDC); PaintText(hDC); PaintBorder(hDC); } else { PaintBkColor(hDC); PaintBkImage(hDC); PaintStatusImage(hDC); PaintText(hDC); PaintBorder(hDC); } }
void CControlUI::PaintText(HDC hDC) { return; }
void CLabelUI::PaintText(HDC hDC) { if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor(); if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor(); RECT rc = m_rcItem; rc.left += m_rcTextPadding.left; rc.right -= m_rcTextPadding.right; rc.top += m_rcTextPadding.top; rc.bottom -= m_rcTextPadding.bottom; if(!GetEnabledEffect()) { if( m_sText.IsEmpty() ) return; int nLinks = 0; if( IsEnabled() ) { if( m_bShowHtml ) CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); elseCRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \ m_iFont, DT_SINGLELINE |m_uTextStyle); } else { if( m_bShowHtml ) CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle); elseCRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \ m_iFont, DT_SINGLELINE |m_uTextStyle); } } else { …… } }
void CRenderEngine::DrawText(HDC hDC, CPaintManagerUI* pManager, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, int iFont, UINT uStyle) { ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC); if( pstrText == NULL || pManager == NULL ) return; ::SetBkMode(hDC, TRANSPARENT); ::SetTextColor(hDC, RGB(GetBValue(dwTextColor), GetGValue(dwTextColor), GetRValue(dwTextColor))); HFONT hOldFont = (HFONT)::SelectObject(hDC, pManager->GetFont(iFont)); ::DrawText(hDC, pstrText, -1, &rc, uStyle | DT_NOPREFIX); ::SelectObject(hDC, hOldFont); }
void CLabelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) { if( _tcscmp(pstrName, _T("align")) == 0 ) { if( _tcsstr(pstrValue, _T("left")) != NULL ) { m_uTextStyle &= ~(DT_CENTER | DT_RIGHT | DT_VCENTER | DT_SINGLELINE); m_uTextStyle |= DT_LEFT; }if( _tcsstr(pstrValue, _T("center")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_RIGHT ); m_uTextStyle |= DT_CENTER; } if( _tcsstr(pstrValue, _T("right")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_CENTER | DT_VCENTER | DT_SINGLELINE); m_uTextStyle |= DT_RIGHT; }if( _tcsstr(pstrValue, _T("top")) != NULL ) { m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER | DT_VCENTER); m_uTextStyle |= (DT_TOP | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_BOTTOM ); m_uTextStyle |= (DT_CENTER | DT_VCENTER | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("bottom")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_VCENTER | DT_VCENTER); m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE); } }
void CLabelUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) { if( _tcscmp(pstrName, _T("align")) == 0 ) { if( _tcsstr(pstrValue, _T("left")) != NULL ) { m_uTextStyle &= ~(DT_CENTER | DT_RIGHT/* | DT_VCENTER | DT_SINGLELINE*/); m_uTextStyle |= DT_LEFT | DT_VCENTER | DT_SINGLELINE; } if( _tcsstr(pstrValue, _T("center")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_RIGHT ); m_uTextStyle |= DT_CENTER; } if( _tcsstr(pstrValue, _T("right")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_CENTER/* | DT_VCENTER | DT_SINGLELINE*/); m_uTextStyle |= DT_RIGHT | DT_VCENTER | DT_SINGLELINE; } if( _tcsstr(pstrValue, _T("top")) != NULL ) { m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER | DT_VCENTER); m_uTextStyle |= (DT_TOP | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_BOTTOM ); m_uTextStyle |= (DT_CENTER | DT_VCENTER | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("bottom")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_VCENTER | DT_VCENTER); m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE); } }
void CUIProperties::ShowLabelProperty(CControlUI* pControl) { ShowControlProperty(pControl); ASSERT(pControl); CLabelUI* pLabel=static_cast<CLabelUI*>(pControl->GetInterface(_T("Label"))); ASSERT(pLabel); CMFCPropertyGridProperty* pPropLabel=m_wndPropList.FindItemByData(classLabel,FALSE); ASSERT(pPropLabel); //align UINT uStyle=pLabel->GetTextStyle(); CString strStyle; if(uStyle&DT_CENTER) strStyle=_T("Center"); elseif(uStyle&DT_LEFT) strStyle=_T("Left"); elseif(uStyle&DT_RIGHT) strStyle=_T("Right"); elseif(uStyle&DT_TOP) strStyle=_T("Top"); elseif(uStyle&DT_BOTTOM) strStyle=_T("Bottom");
void CUIProperties::ShowLabelProperty(CControlUI* pControl) { ShowControlProperty(pControl); ASSERT(pControl); CLabelUI* pLabel=static_cast<CLabelUI*>(pControl->GetInterface(_T("Label"))); ASSERT(pLabel); CMFCPropertyGridProperty* pPropLabel=m_wndPropList.FindItemByData(classLabel,FALSE); ASSERT(pPropLabel); //align UINT uStyle=pLabel->GetTextStyle(); CString strStyle; if(uStyle&DT_CENTER) strStyle=_T("Center"); elseif((~uStyle) & (~DT_LEFT)) strStyle=_T("Left"); elseif(uStyle&DT_RIGHT) strStyle=_T("Right"); elseif(uStyle&DT_TOP) strStyle=_T("Top"); elseif(uStyle&DT_BOTTOM) strStyle=_T("Bottom");
void CLayoutManager::SaveProperties(CControlUI* pControl, TiXmlElement* pParentNode …… case classLabel: case classText: SaveLabelProperty(pControl, pNode); break; ……
版权声明:本文为博主原创文章,未经博主允许不得转载。