/** * Event: OnPaint * * Render the Notification Window */ LRESULT NotificationWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PAINTSTRUCT ps; BeginPaint(&ps); { MyGdiplusHelper gdi_plus_autostart; { // get draw area RECT clientRect; ::GetClientRect(m_hWnd, &clientRect); // create Gdiplus Graphics object Gdiplus::Graphics graphics(m_hWnd, FALSE); graphics.SetClip(Gdiplus::Rect(clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top)); // draw a background Gdiplus::SolidBrush backgroundBrush(Gdiplus::Color(DEFAULT_ALPHA, 255, 255, 255)); graphics.FillRectangle(&backgroundBrush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); // shrink draw area int inset = 4; clientRect.left += inset; clientRect.top += inset; clientRect.right -= inset; clientRect.bottom -= inset; // whack a logo TODO //Bitmap* bitmap = new Bitmap(m_icon.c_str(), FALSE); int bitmapWidth = 0;//bitmap->GetWidth(); int bitmapHeight = 15;//bitmap->GetHeight(); //graphics->DrawImage(bitmap, clientRect.left, clientRect.top, //bitmapWidth, bitmapHeight); // draw a separator Gdiplus::Pen blackPen(Gdiplus::Color(0, 0, 0), 1.0f); graphics.DrawLine(&blackPen, clientRect.left, clientRect.top + bitmapHeight + inset, clientRect.right, clientRect.top + bitmapHeight + inset); // setup text properties Gdiplus::Font titleFont(L"Verdana", 10, Gdiplus::FontStyleBold); Gdiplus::Font textFont(L"Verdana", 10, Gdiplus::FontStyleRegular); Gdiplus::RectF titleRect((float)clientRect.left + inset + bitmapWidth, (float)clientRect.top, (float)clientRect.right, 20.0f); Gdiplus::RectF textRect((float)clientRect.left, (float)clientRect.top + bitmapHeight + (inset * 2), (float)clientRect.right, (float)clientRect.bottom - bitmapHeight - (inset * 2)); Gdiplus::StringFormat format; format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter); format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); // draw the message graphics.DrawString(m_title.c_str(), (int)m_title.length(), &titleFont, titleRect, &format, &blackBrush); graphics.DrawString(m_message.c_str(), (int)m_message.length(), &textFont, textRect, &format, &blackBrush); } } EndPaint(&ps); bHandled = TRUE; return 0; }
bool CanvasGDIP::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines) { Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat; Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic(); // Set trimming and format temporarily. const Gdiplus::StringTrimming stringTrimming = stringFormat.GetTrimming(); stringFormat.SetTrimming(Gdiplus::StringTrimmingNone); const INT stringFormatFlags = stringFormat.GetFormatFlags(); stringFormat.SetFormatFlags(Gdiplus::StringFormatFlagsNoClip); if (m_AccurateText) { tStringFormat.SetTrimming(stringFormat.GetTrimming()); tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags()); tStringFormat.SetAlignment(stringFormat.GetAlignment()); tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment()); } INT linesFilled = 0; const Gdiplus::Status status = m_Graphics->MeasureString( str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect, m_AccurateText ? &tStringFormat : &stringFormat, &rect, nullptr, &linesFilled); lines = linesFilled; // Restore old options. stringFormat.SetTrimming(stringTrimming); stringFormat.SetFormatFlags(stringFormatFlags); return status == Gdiplus::Ok; }
void CanvasGDIP::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush) { Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat; Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic(); if (m_AccurateText) { tStringFormat.SetTrimming(stringFormat.GetTrimming()); tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags()); tStringFormat.SetAlignment(stringFormat.GetAlignment()); tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment()); } m_Graphics->DrawString( str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect, m_AccurateText ? &tStringFormat : &stringFormat, &brush); }
bool CanvasGDIP::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect) { Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat; Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic(); if (m_AccurateText) { tStringFormat.SetTrimming(stringFormat.GetTrimming()); tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags()); tStringFormat.SetAlignment(stringFormat.GetAlignment()); tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment()); } const Gdiplus::Status status = m_Graphics->MeasureString( str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect, m_AccurateText ? &tStringFormat : &stringFormat, &rect); return status == Gdiplus::Ok; }
void TextElement::DrawTextVector(RenderContext& ctx) { Gdiplus::RectF textrect; if (!RectFFromStyle(GetStyle(), textrect) || !m_font || m_text.empty()) return; ctx.pGraphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality); Gdiplus::FontFamily family(L"Tahoma"); Gdiplus::StringFormat format; format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit); format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter); Gdiplus::GraphicsPath path; path.AddString(m_text.c_str(), -1, &family, Gdiplus::FontStyleBold, 12, textrect, &format); Gdiplus::Pen pen(Gdiplus::Color(192, 0, 0, 0), 0.0); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255)); ctx.pGraphics->FillPath(&brush, &path); ctx.pGraphics->DrawPath(&pen, &path); }
CSize CXTextGdiPlus::Measure( HDC dc, INT nWidthLimit ) { Gdiplus::Graphics graph(dc); graph.SetTextRenderingHint(m_Rendering); Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName)); Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel); Gdiplus::StringFormat stringformat; stringformat.SetAlignment(m_AlignmentH); stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ? Gdiplus::StringAlignmentNear : m_AlignmentV); stringformat.SetFormatFlags(m_FormatFlags); stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB)); Gdiplus::RectF rfTargetRect(0, 0, nWidthLimit > 0 ? nWidthLimit : INFINITY, INFINITY); CStringW strTextToDraw(XLibST2W(m_strText)); Gdiplus::RectF rfBoundRect(0, 0, 0, 0); graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect); return CSize(ceil(rfBoundRect.Width), ceil(rfBoundRect.Height)); }
void TextElement::DrawTextNormal(RenderContext& ctx) { Gdiplus::RectF textrect; if (!RectFFromStyle(GetStyle(), textrect) || !m_font || m_text.empty()) return; m_rect.X = textrect.X; m_rect.Y = textrect.Y; m_rect.Width = textrect.Width; m_rect.Height = textrect.Height; Gdiplus::Bitmap bmpTemp(textrect.Width, textrect.Height, PixelFormat32bppARGB); Gdiplus::Graphics gfxTemp(&bmpTemp); gfxTemp.Clear(Gdiplus::Color(255, 0, 0, 0)); Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255)); Gdiplus::StringFormat format; format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit); InitTextStyles(gfxTemp, format, GetStyle()); Gdiplus::RectF rect2(0, 0, textrect.Width, textrect.Height); gfxTemp.DrawString(m_text.c_str(), m_text.length(), m_font.get(), rect2, &format, &brush); Gdiplus::BitmapData bmpdataTemp; Gdiplus::Rect textrect2(0, 0, textrect.Width, textrect.Height); bmpTemp.LockBits(&textrect2, Gdiplus::ImageLockModeRead, bmpTemp.GetPixelFormat(), &bmpdataTemp); Gdiplus::PixelFormat pform = ctx.pBitmap->GetPixelFormat(); Gdiplus::BitmapData bmpdataCtx; Gdiplus::Rect textrect3(textrect.X, textrect.Y, textrect.Width, textrect.Height); ctx.pBitmap->LockBits(&textrect3, Gdiplus::ImageLockModeWrite | Gdiplus::ImageLockModeRead, ctx.pBitmap->GetPixelFormat(), &bmpdataCtx); // HACKHACK: blend the alpha channel manually (!!!) { #pragma pack(1) struct Pixel { unsigned char Blue; unsigned char Green; unsigned char Red; unsigned char Alpha; }; #pragma pack() Pixel* pBackground = (Pixel*)bmpdataCtx.Scan0; Pixel* pText = (Pixel*)bmpdataTemp.Scan0; for (UINT y = 0; y < bmpdataTemp.Height; y++) { for (UINT x = 0; x < bmpdataTemp.Width; x++) { UINT indexBG = y * (bmpdataCtx.Stride / sizeof(UINT)) + x; UINT indexText = y * (bmpdataTemp.Stride / sizeof(UINT)) + x; // if (pText[indexText].Red = 0xFF && pText[indexText].Blue == 0xFF && pText[indexText].Green == 0xFF) // pBackground[indexBG].Alpha = 255; pBackground[indexBG].Red = min(255, (UINT)pBackground[indexBG].Red + (UINT)pText[indexText].Red); pBackground[indexBG].Blue = min(255, (UINT)pBackground[indexBG].Blue + (UINT)pText[indexText].Blue); pBackground[indexBG].Green = min(255, (UINT)pBackground[indexBG].Green + (UINT)pText[indexText].Green); } } } ctx.pBitmap->UnlockBits(&bmpdataCtx); bmpTemp.UnlockBits(&bmpdataTemp); }
BOOL CXTextGdiPlus::RefreashBufferDC(HDC hDCSrc) { ReleaseBufferDC(); m_dcBuffer = ::CreateCompatibleDC(hDCSrc); m_hBufferOldBmp = ::SelectObject(m_dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(m_rcDst.Width(), m_rcDst.Height())); Gdiplus::Graphics graph(m_dcBuffer); graph.SetTextRenderingHint(m_Rendering); Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName)); Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel); Gdiplus::StringFormat stringformat; stringformat.SetAlignment(m_AlignmentH); stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ? Gdiplus::StringAlignmentNear : m_AlignmentV); stringformat.SetFormatFlags(m_FormatFlags); stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord); Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB)); Gdiplus::RectF rfTargetRect(0, 0, m_rcDst.Width(), m_rcDst.Height()); CStringW strTextToDraw(XLibST2W(m_strText)); // When centering texts vertically, gdi+ will put the texts a litter higher, // so we'll handle vertically centering ourselves. if (m_AlignmentV == Gdiplus::StringAlignmentCenter) { Gdiplus::RectF rfBoundRect(0, 0, 0, 0); graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect); UINT nBufferWidth = rfTargetRect.Width, nBufferHeight = ceil(rfBoundRect.Height); UINT32 *pBufferBmp = NULL; HDC dcBuffer = ::CreateCompatibleDC(m_dcBuffer); HGDIOBJ hOldBmp = ::SelectObject(dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(nBufferWidth, nBufferHeight, (BYTE **)&pBufferBmp)); Gdiplus::Graphics graBuffer(dcBuffer); graBuffer.SetTextRenderingHint(m_Rendering); graBuffer.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush); CRect rcStrictBound(0, 0, nBufferWidth, nBufferHeight); BOOL bTopFound = FALSE, bBottomFound = FALSE; for (UINT line = 0; line < nBufferHeight; line++) { for (UINT col = 0; col < nBufferWidth; col++) { // bottom bits. if (!bBottomFound && *(pBufferBmp + line * nBufferWidth + col) != 0) { bBottomFound = TRUE; rcStrictBound.bottom -= line; } // top bits. if (!bTopFound && *(pBufferBmp + (nBufferHeight - line - 1) * nBufferWidth + col) != 0) { bTopFound = TRUE; rcStrictBound.top += line; } if (bBottomFound && bTopFound) break; } if (bBottomFound && bTopFound) break; } CRect rcTarget(0, (m_rcDst.Height() - rcStrictBound.Height()) / 2, 0, 0); rcTarget.right = rcTarget.left + rcStrictBound.Width(); rcTarget.bottom = rcTarget.top + rcStrictBound.Height(); Util::BitBlt(dcBuffer, rcStrictBound, m_dcBuffer, rcTarget); ::DeleteObject(::SelectObject(dcBuffer, hOldBmp)); ::DeleteDC(dcBuffer); } else graph.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush); return TRUE; }
BOOL CBSObject::DrawText(HDC hDC, const LPRECT lpRect, const CString& strText, HFONT hFont, COLORREF clrText, UINT uiFormat) { BOOL bResult = FALSE; #ifdef OSK HFONT hFontOld = (HFONT)::SelectObject(hDC, hFont); COLORREF clrTextOld = ::SetTextColor(hDC, clrText); int nBkModeOld = ::SetBkMode(hDC, TRANSPARENT); if (::DrawText(hDC, strText, strText.GetLength(), lpRect, uiFormat)) { bResult = TRUE; } if (hFontOld) { ::SelectObject(hDC, hFontOld); } ::SetTextColor(hDC, clrTextOld); ::SetBkMode(hDC, nBkModeOld); #else Gdiplus::Graphics graphics(hDC); Gdiplus::SolidBrush brush(Gdiplus::Color(255, GetRValue(clrText), GetGValue(clrText), GetBValue(clrText))); Gdiplus::Font font(hDC, hFont); Gdiplus::RectF rect(lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top); graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit); Gdiplus::StringFormat strformat; if (uiFormat & DT_TOP) { strformat.SetLineAlignment(Gdiplus::StringAlignmentNear); } if (uiFormat & DT_VCENTER) { strformat.SetLineAlignment(Gdiplus::StringAlignmentCenter); } if (uiFormat & DT_BOTTOM) { strformat.SetLineAlignment(Gdiplus::StringAlignmentFar); } if (uiFormat & DT_LEFT) { strformat.SetAlignment(Gdiplus::StringAlignmentNear); } if (uiFormat & DT_CENTER) { strformat.SetAlignment(Gdiplus::StringAlignmentCenter); } if (uiFormat & DT_RIGHT) { strformat.SetAlignment(Gdiplus::StringAlignmentFar); } if ((uiFormat & DT_WORDBREAK) == 0) { strformat.SetFormatFlags(Gdiplus::StringFormatFlagsNoWrap); } if (uiFormat & DT_SINGLELINE) { } if (uiFormat & DT_WORD_ELLIPSIS) { strformat.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter); } if (uiFormat & DT_NOCLIP) { strformat.SetFormatFlags(Gdiplus::StringFormatFlagsNoClip); } graphics.DrawString(strText, -1, &font, rect, &strformat, &brush); #endif return bResult; }
void CClipMonView::OnDraw( CDC *pDC) { CRect rcClient; TxGetClientRect(rcClient); Graphics gc(pDC->GetSafeHdc()); SolidBrush bkBrush(m_drawParam.bkColor); Rect rCet = CRect2Rect(rcClient); gc.FillRectangle(&bkBrush, rCet); CSize szView = GetScrollViewSize(); CRect rcView(0, 0, szView.cx, szView.cy); rcView.OffsetRect(rcClient.left, rcClient.top); if (rcView.IsRectEmpty()) { return; } rcView.OffsetRect(-GetScrollPos(SB_HORZ), -GetScrollPos(SB_VERT)); GraphicsContainer container = gc.BeginContainer(); Rect rClip = CRect2Rect(rcClient); gc.SetClip(rClip); if (m_bUseBkBuffer) { CRect rcBuffToDraw(0,0,rcClient.Width(), rcClient.Height()); rcBuffToDraw.OffsetRect(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT)); if (!IsInRect(rcBuffToDraw, m_rcViewBkBuffer)) { TRACE("\nbufferRedraw %d, %d", rcBuffToDraw.bottom, m_rcViewBkBuffer.bottom); ReDrawBkBuffer(); } //draw bkbuffer m_BkBufferlock.Lock(); rcBuffToDraw.OffsetRect(-m_rcViewBkBuffer.left, -m_rcViewBkBuffer.top); gc.DrawImage(m_pBmpBackBuffer, rClip, rcBuffToDraw.left, rcBuffToDraw.top, rcBuffToDraw.Width(), rcBuffToDraw.Height(), UnitPixel); m_BkBufferlock.Unlock(); } else { int nBegin = (rcClient.top - rcView.top) / m_drawParam.nItemHeight; int nCount = rcClient.Height() /m_drawParam.nItemHeight +1; VECTMPITEM vData; g_monDataMgr.GetRangeData(nBegin, nCount, vData); nCount = vData.size(); CTxListHeader& headerCtrl = GetListHeader(); int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight); Gdiplus::StringFormat fmt; fmt.SetAlignment(StringAlignmentNear); fmt.SetLineAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisCharacter); fmt.SetFormatFlags(StringFormatFlagsLineLimit); Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0); Rect rRowBk(rcClient.left, nTopPos, rcClient.Width(), m_drawParam.nItemHeight); for (int i = 0; i < nCount; i++) { ARGB clr = 0xff000000; ARGB clrBk = 0xffffffff; vData[i].GetMonColor(clr, clrBk); bkBrush.SetColor(clrBk); gc.FillRectangle(&bkBrush, rRowBk); int nLeftPos = rcView.left; CRect rcItem(nLeftPos,nTopPos, 0, nTopPos + m_drawParam.nItemHeight); for (int cIdx = 0; cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++) { if (rcItem.left > rcClient.right) { break; } rcItem.right = rcItem.left + headerCtrl.GetHeaderWidth(cIdx); if (rcItem.right >= rcClient.left) { CString strText = vData[i].GetValue((ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType)); GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt); //GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0xff000000,0,0,0,0,&fmt); //draw separate line gc.DrawLine(&pen, rcItem.right-1, rcItem.top, rcItem.right-1, rcItem.bottom); } rcItem.OffsetRect(rcItem.Width(), 0); } gc.DrawLine(&pen, rcClient.left, rcItem.bottom-1, rcClient.right, rcItem.bottom-1); nTopPos += m_drawParam.nItemHeight; rRowBk.Offset(0, m_drawParam.nItemHeight); } } //calc In Bound Item gc.EndContainer(container); ReDrawRemainTime(pDC); }
void CClipMonView::ReDrawRemainTime(CDC* pDC) { CRect rcClient; TxGetClientRect(rcClient); if (m_scBar[SB_VERT].IsShowing()) { rcClient.DeflateRect(0,0,m_scBar[SB_VERT].GetBarWidth(), 0); } if (m_scBar[SB_HORZ].IsShowing()) { rcClient.DeflateRect(0,0, 0, m_scBar[SB_HORZ].GetBarWidth()); } // Rect rCet = CRect2Rect(rcClient); // gc.FillRectangle(&bkBrush, rCet); CSize szView = GetScrollViewSize(); CRect rcView(0, 0, szView.cx, szView.cy); rcView.OffsetRect(rcClient.left, rcClient.top); if (rcView.IsRectEmpty()) { return; } rcView.OffsetRect(-GetScrollPos(SB_HORZ), -GetScrollPos(SB_VERT)); int nBegin = (rcClient.top - rcView.top) / m_drawParam.nItemHeight; int nCount = rcClient.Height() /m_drawParam.nItemHeight +1; VECTMPITEM vData; g_monDataMgr.GetRangeData(nBegin, nCount, vData); nCount = vData.size(); if (nCount <= 0) { return; } CTxListHeader& headerCtrl = GetListHeader(); int nLeftPos = rcView.left; int nRightPos = 0; for (int cIdx = 0; cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++) { ENUM_MONTYPE nMonType = (ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType); if (nMonType == MONTYPE_TIMEREMAIN) { nRightPos = nLeftPos + headerCtrl.GetHeaderWidth(cIdx); break; } else { nLeftPos += headerCtrl.GetHeaderWidth(cIdx); } } if (nRightPos < rcClient.left || nLeftPos > rcClient.right) { return; } CPoint ptOffSetBmp; int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight); ptOffSetBmp.x = nLeftPos < 0? -nLeftPos:0; ptOffSetBmp.y = nTopPos < rcClient.top? rcClient.top - nTopPos: 0; CRect rcRemainTimeClient(nLeftPos, rcClient.top, nRightPos-1, rcClient.bottom); Graphics gc(m_pBmpRemainTime); SolidBrush bkBrush(m_drawParam.bkColor); GraphicsContainer container = gc.BeginContainer(); int nClipHeight = m_drawParam.nItemHeight*nCount; if (nClipHeight < rcClient.Height()) { nClipHeight = rcClient.Height(); } Rect rClip(0,0, rcRemainTimeClient.Width(), nClipHeight); gc.SetClip(rClip); Rect rDes(nLeftPos, nTopPos, rClip.Width, rClip.Height); gc.FillRectangle(&bkBrush, rClip); Gdiplus::StringFormat fmt; fmt.SetAlignment(StringAlignmentCenter); fmt.SetLineAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisCharacter); fmt.SetFormatFlags(StringFormatFlagsLineLimit); Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0); Rect rRowBk(0, 0, rcRemainTimeClient.Width(), m_drawParam.nItemHeight); CRect rcItem(0,0, rRowBk.Width,rRowBk.Height); for (int i = 0; i < nCount; i++) { ARGB clr = 0xff000000; ARGB clrBk = 0xffffffff; vData[i].GetMonColor(clr, clrBk); bkBrush.SetColor(clrBk); gc.FillRectangle(&bkBrush, rRowBk); CString strText = vData[i].GetValue(MONTYPE_TIMEREMAIN); GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt); //GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0xff000000,0,0,0,0,&fmt); gc.DrawLine(&pen, rcItem.left, rcItem.bottom-1, rcItem.right, rcItem.bottom-1); nTopPos += m_drawParam.nItemHeight; rcItem.OffsetRect(0, m_drawParam.nItemHeight); rRowBk.Offset(0, m_drawParam.nItemHeight); } gc.EndContainer(container); Graphics gcDes(pDC->GetSafeHdc()); CRect rcDesClip(rcRemainTimeClient); Rect rDesClip = CRect2Rect(rcDesClip); gcDes.SetClip(rDesClip); gcDes.DrawImage(m_pBmpRemainTime, rDesClip, ptOffSetBmp.x, ptOffSetBmp.y, (INT)rDesClip.Width, (INT)rDesClip.Height, UnitPixel); }
void CClipMonView::ReDrawBkBuffer() { if (!m_bUseBkBuffer) { return; } CSize szView = GetScrollViewSize(); if (szView.cx == 0 || szView.cy == 0) { return; } CRect rcClient; TxGetClientRect(rcClient); CRect rcViewShowBuffer(rcClient); rcViewShowBuffer.MoveToXY(0,0); rcViewShowBuffer.OffsetRect(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT)); CRect rcBk(0,0, m_szbmpBackBuffer.cx, m_szbmpBackBuffer.cy); rcBk = GetCenterRect(rcViewShowBuffer, rcBk); if (rcBk.left < 0) { rcBk.MoveToX(0); } if (rcBk.top < 0) { rcBk.MoveToY(0); } m_rcViewBkBuffer = rcBk; m_BkBufferlock.Lock(); ASSERT(m_pBmpBackBuffer != NULL); Graphics gc(m_pBmpBackBuffer); SolidBrush bkBrush(m_drawParam.bkColor); Rect rCet = CRect2Rect(CRect(0,0, rcBk.Width(), rcBk.Height())); gc.FillRectangle(&bkBrush, rCet); CRect rcView(0, 0, szView.cx, szView.cy); //calc In Bound Item int nBegin = (rcBk.top - rcView.top) / m_drawParam.nItemHeight; int nCount = rcBk.Height() /m_drawParam.nItemHeight +1; VECTMPITEM vData; g_monDataMgr.GetRangeData(nBegin, nCount, vData); nCount = vData.size(); if (nCount == 0) { return; } CTxListHeader& headerCtrl = GetListHeader(); int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight)- rcBk.top; Gdiplus::StringFormat fmt; fmt.SetAlignment(StringAlignmentCenter); fmt.SetLineAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisCharacter); fmt.SetFormatFlags(StringFormatFlagsLineLimit|StringFormatFlagsNoWrap); Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0); Rect rRowBk(0, nTopPos, rcBk.Width(), m_drawParam.nItemHeight); for (int i = 0; i < nCount; i++) { ARGB clr = 0xff000000; ARGB clrBk = 0xffffffff; vData[i].GetMonColor(clr, clrBk); bkBrush.SetColor(clrBk); gc.FillRectangle(&bkBrush, rRowBk); int nLeftPos = 0-rcBk.left; CRect rcItem(nLeftPos,nTopPos, 0, nTopPos + m_drawParam.nItemHeight); for (int cIdx = 0; cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++) { if (rcItem.left > rcBk.right) { break; } rcItem.right = rcItem.left + headerCtrl.GetHeaderWidth(cIdx); if (rcItem.right >= rcBk.left) { ENUM_MONTYPE nMonType = (ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType); if (nMonType != MONTYPE_TIMEREMAIN) { CString strText = vData[i].GetValue(nMonType); GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt); //GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0x22000000,0,0,0,0,&fmt); } //draw separate line gc.DrawLine(&pen, rcItem.right-1, rcItem.top, rcItem.right-1, rcItem.bottom); } rcItem.OffsetRect(rcItem.Width(), 0); } gc.DrawLine(&pen, rcBk.left, rcItem.bottom-1, rcBk.right, rcItem.bottom-1); nTopPos += m_drawParam.nItemHeight; rRowBk.Offset(0, m_drawParam.nItemHeight); } m_BkBufferlock.Unlock(); }
void StringFormat::SetFormatFlags(StringFormatFlags sf) { Gdiplus::StringFormat* gdiSf = reinterpret_cast<Gdiplus::StringFormat*>(_private); gdiSf->SetFormatFlags(sf); }