// 绘制按钮 void CDUIButton::DrawButton( Gdiplus::Graphics& graphics) { // 获取按钮图片信息 UINT iCount = m_nImageCount; int iButtonIndex = 0; if(m_bDisabled && iCount >= 4) iButtonIndex = 3; else if(m_bPressed && iCount >= 3)iButtonIndex = 2; else if(m_bHovering && iCount >= 2)iButtonIndex = 1; else iButtonIndex = 0; // 在指定位置绘制按钮 int iWidth = m_pImage->GetWidth()/iCount; int iHeight = m_pImage->GetHeight(); RectF grect; grect.X=(Gdiplus::REAL)m_rcRect.left; grect.Y=(Gdiplus::REAL)m_rcRect.top; grect.Width = (Gdiplus::REAL)m_rcRect.Width(); grect.Height = (Gdiplus::REAL)m_rcRect.Height(); graphics.DrawImage(m_pImage, grect, (Gdiplus::REAL)iWidth*iButtonIndex,0,(Gdiplus::REAL)iWidth,(Gdiplus::REAL)iHeight, UnitPixel); StringFormat stringFormat; if (m_pIcon) { PointF ptIcon(m_ptIcon.x,m_ptIcon.y); graphics.DrawImage(m_pIcon,ptIcon); grect.X=(Gdiplus::REAL)m_ptIcon.x + m_pIcon->GetWidth() + 2; grect.Width = (Gdiplus::REAL)m_rcRect.Width() - m_pIcon->GetWidth() - 2; stringFormat.SetFormatFlags( StringFormatFlagsDirectionVertical); stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentNear); } else { //stringFormat.SetFormatFlags( StringFormatFlagsDirectionVertical); stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); } if (!m_strCaption.IsEmpty()) { //绘制文字 FontFamily fontFamily(L"宋体"); Gdiplus::Font font(&fontFamily, 10, FontStyleRegular, UnitPoint); CStringW strTitle(m_strCaption); SolidBrush brush((ARGB)Color::White); if (m_bDisabled) { brush.SetColor((ARGB)Color::Gray); } graphics.DrawString(strTitle, strTitle.GetLength(), &font,grect,&stringFormat, &brush); } }
void CRenderUtility::DrawText( HDC hDC,LPCTSTR lpszText,RECT& rctSrc,COLORREF color/*= RGB(0,0,0)*/, LPCTSTR lpszFontFamily /*=L"΢ÈíÑźÚ"*/,int nFontSize /*= 12*/,DWORD dwAlignStyle /*= SS_CENTER*/,DWORD dwFontStyle /*= FontStyleRegular*/, int nAlpha /*= 255*/ ) { if(0 == nAlpha || NULL == lpszText) return; Graphics graphics(hDC); FontFamily fontFamily(lpszFontFamily); FontStyle fontStyle = (FontStyle)dwFontStyle; Gdiplus::Font font(&fontFamily,(float)nFontSize,fontStyle,UnitPixel); RectF rcText((float)rctSrc.left,(float)rctSrc.top,(float)RECT_WIDTH(rctSrc),(float)RECT_HEIGHT(rctSrc)); SolidBrush brush(Color(nAlpha,GetRValue(color),GetGValue(color),GetBValue(color))); StringFormat txtFormat; if(dwAlignStyle & SS_CENTERIMAGE) { txtFormat.SetLineAlignment(StringAlignmentCenter); } if(dwAlignStyle & SS_CENTER){ txtFormat.SetAlignment(StringAlignmentCenter); } else if(dwAlignStyle & SS_RIGHT){ txtFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); txtFormat.SetAlignment(StringAlignmentNear); } graphics.DrawString(lpszText,-1,&font,rcText,&txtFormat,&brush); }
int CNotification::CalculateWidth(int defaultSize) { CString s; GetWindowText(s); CDIB dib; dib.Resize(1, 1); if(!dib.Ready()) { return defaultSize; } Graphics g(dib.dc); g.SetCompositingMode(CompositingModeSourceOver); g.SetSmoothingMode(SmoothingModeAntiAlias); RectF rf(0, 0, 0, 0); Font font(L"Arial", defaultSize * 0.6f, FontStyleRegular, UnitPixel); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentCenter); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); g.MeasureString(s.GetBuffer(), s.GetLength(), &font, rf, stringFormat, &rf); delete stringFormat; defaultSize += (int)rf.Width - defaultSize / 2; return defaultSize; }
void LeftAxesGrid::Draw() { Font font(L"Arial", (REAL)chart.fontHeight, FontStyleBold); Color color(chart.colorAxes); Pen pen(color, 2); SolidBrush fontColor(chart.colorAxes); StringFormat format; format.SetAlignment(StringAlignmentNear); double height; double minAA = ((int)minA * 1000) / 1000; double maxAA = ((int)maxA * 1000) / 1000; int maxLen = 0; chart.offsetAxesLeft = 7 + chart.GetCountDigit(minAA, maxAA, height, font, maxLen); int x = chart.rect.left + chart.offsetAxesLeft; int bottom = chart.rect.bottom - chart.offsetAxesBottom; chart.g->DrawLine(&pen, x, chart.rect.top + chart.offsetAxesTop, x, bottom); // char buf[32]; wchar_t wbuf[32]; PointF origin; RectF rect; double deltaTick = 0; double deltaDigit = 0; double digit = 0; double minTick = 0; OffsetAxes( int(height * 2.5) , chart.rect.bottom - chart.rect.top - chart.offsetAxesBottom - chart.offsetAxesTop , chart.minAxesY , chart.maxAxesY , deltaDigit , deltaTick , digit , minTick ); minA = digit; double offs = chart.offsetGridY = chart.rect.bottom - chart.offsetAxesBottom + minTick; chart.deltaDigitY = deltaDigit; chart.deltaTickY = deltaTick; while(bottom < offs) { offs -= deltaTick; digit += deltaDigit; } origin.X = (REAL)chart.rect.left; int len; digit += deltaDigit; int int_d = 0; while(offs > chart.rect.top + chart.offsetAxesTop + deltaTick / 2) { chart.g->DrawLine(&pen, (REAL)x - 5, (REAL)offs, (REAL)x, (REAL)offs); _itow((int)digit, wbuf, 10); len = wcslen(wbuf); chart.g->MeasureString(wbuf, len, &font, origin, &format, &rect); origin.Y = REAL(offs - deltaTick); chart.g->DrawString(wbuf, len, &font, origin, &fontColor); offs -= deltaTick; digit += deltaDigit; } maxA = digit; }
static REAL DrawMessage(Graphics &g, const WCHAR *msg, REAL y, REAL dx, Color color) { ScopedMem<WCHAR> s(str::Dup(msg)); Font f(L"Impact", 16, FontStyleRegular); RectF maxbox(0, y, dx, 0); RectF bbox; g.MeasureString(s, -1, &f, maxbox, &bbox); bbox.X += (dx - bbox.Width) / 2.f; StringFormat sft; sft.SetAlignment(StringAlignmentCenter); if (trans::IsCurrLangRtl()) sft.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); #if DRAW_MSG_TEXT_SHADOW { bbox.X--; bbox.Y++; SolidBrush b(Color(0xff, 0xff, 0xff)); g.DrawString(s, -1, &f, bbox, &sft, &b); bbox.X++; bbox.Y--; } #endif SolidBrush b(color); g.DrawString(s, -1, &f, bbox, &sft, &b); return bbox.Height; }
//----------------------------------------------------------------------------------- void LeftAxes::Draw() { Font font(L"Arial", (REAL)chart.fontHeight, FontStyleBold); Color color(chart.colorAxes); Pen pen(color, 2); SolidBrush fontColor(chart.colorAxes); StringFormat format; format.SetAlignment(StringAlignmentNear); double height; int maxLen = 0; chart.offsetAxesLeft = 10 + chart.GetCountDigit(chart.minAxesY, chart.maxAxesY, height, font, maxLen); maxLen += 2; int x = chart.rect.left + chart.offsetAxesLeft; int bottom = chart.rect.bottom - chart.offsetAxesBottom; chart.g->DrawLine(&pen, x, chart.rect.top + chart.offsetAxesTop, x, bottom); char buf[32]; wchar_t wbuf[32]; PointF origin; RectF rect; double deltaTick = 0; double deltaDigit = 0; double digit = 0; double minTick = 0; OffsetAxes( int(height * 2) , chart.rect.bottom - chart.rect.top - chart.offsetAxesBottom - chart.offsetAxesTop , chart.minAxesY , chart.maxAxesY , deltaDigit , deltaTick , digit , minTick ); double offs = chart.offsetGridY = chart.rect.bottom - chart.offsetAxesBottom + minTick; chart.deltaTickY = deltaTick; chart.deltaDigitY = deltaDigit; while(bottom < offs) { offs -= deltaTick; digit += deltaDigit; } origin.X = (REAL)chart.rect.left; int len; while(offs > chart.rect.top + chart.offsetAxesTop) { chart.g->DrawLine(&pen, (REAL)x - 5, (REAL)offs, (REAL)x, (REAL)offs); gcvt(digit, 5, buf); mbstowcs(wbuf, buf, 32); len = wcslen(wbuf); if(len <= maxLen) { chart.g->MeasureString(wbuf, len, &font, origin, &format, &rect); origin.Y = REAL(offs - deltaTick + deltaTick/2); chart.g->DrawString(wbuf, len, &font, origin, &fontColor); } offs -= deltaTick; digit += deltaDigit; } }
void CCheckButton::DrawControl(CDC &dc, CRect rcUpdate) { int nWidth = m_rc.Width(); int nHeight = m_rc.Height(); if(!m_bUpdate) { UpdateMemDC(dc, nWidth * 6, nHeight); Graphics graphics(m_memDC); CRect rcTemp(0, 0, nWidth, nHeight); for(int i = 0; i < 6; i++) { m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY); graphics.DrawImage(m_pImage, Rect(rcTemp.left, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy), i * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); rcTemp.OffsetRect(nWidth, 0); } if(!m_strTitle.IsEmpty()) { m_memDC.SetBkMode(TRANSPARENT); rcTemp.SetRect(0, 0, nWidth, nHeight); FontFamily fontFamily(m_strFont.AllocSysString()); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); Size size = GetTextBounds(font, strFormat, m_strTitle); CPoint point = GetOriginPoint(nWidth - m_sizeImage.cx - 3, nHeight, size.Width, size.Height, m_uAlignment, m_uVAlignment); for(int i = 0; i < 6; i++) { SolidBrush solidBrush(enBSDisable == i ? Color(128, 128, 128) : m_clrText); RectF rect(m_sizeImage.cx + 3 + point.x + i * nWidth, point.y, nWidth - m_sizeImage.cx - 3 - point.x, size.Height); graphics.DrawString(m_strTitle.AllocSysString(), (INT)wcslen(m_strTitle.AllocSysString()), &font, rect, &strFormat, &solidBrush); // 画焦点框(虚线框) if(m_bIsFocus) { Pen pen(Color(128, 128, 128), 1); pen.SetDashStyle(DashStyleDot); RectF rectFocus(point.x + i * nWidth, point.y, m_sizeImage.cx + 6 + size.Width, size.Height); graphics.DrawRectangle(&pen, rectFocus); } } } } dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY); }
void GPDrawShadowTextSimple( Graphics&gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ ) { Gdiplus::Font& gcfont = fontIn; Rect rcText = CRect2Rect(rcIn); StringFormat fmt; fmt.SetAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisWord); fmt.SetLineAlignment(StringAlignmentCenter); StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn; GraphicsContainer gcContainer = gc.BeginContainer(); gc.SetSmoothingMode(SmoothingModeAntiAlias); CComBSTR btrTxtIn(strTxtIn); SolidBrush textbrush(ARGB2Color(shadowBrushClrIn)); RectF rfText = Rect2RectF(rcText); if (shadowBrushClrIn != 0) { rfText.Offset(1.0, 1.0); gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush); } textbrush.SetColor(ARGB2Color(BrushClrIn)); gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush); gc.EndContainer(gcContainer); }
int drawSpeed(Graphics *gra, int posX, int posY){ // 速度表示部の背景を白くする SolidBrush b(Color(180,255,255,255)); backGra->FillRectangle(&b, posX, posY, 200, 14); // フォント設定 Font font(L"MS Pゴシック",10); // 文字色 SolidBrush strBrush(Color::Black); // 文字列作成 char tmp[256]; sprintf(tmp, "R:%.1fkbps S:%.1fkbps", BYTES_TO_KBPS(stats.getPerSecond(Stats::BYTESIN)-stats.getPerSecond(Stats::LOCALBYTESIN)), BYTES_TO_KBPS(stats.getPerSecond(Stats::BYTESOUT)-stats.getPerSecond(Stats::LOCALBYTESOUT))); _bstr_t bstr(tmp); // 文字表示範囲指定 StringFormat format; format.SetAlignment(StringAlignmentCenter); RectF r((REAL)posX, (REAL)posY, (REAL)200, (REAL)14); // 文字描画 gra->DrawString(bstr, -1, &font, r, &format, &strBrush); return posY + 15; }
// 计算显示的字符串总高度应该是多高 int CDuiText::GetVirtualHeight() { BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); ::SysFreeString(bsFont); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces); int nWidth = m_rc.Width(); if(m_bScrollV) { nWidth -= 8; } Size size = GetTextBounds(font, strFormat, nWidth, m_strTitle); // 滚动条只有在需要的总高度大于文本框的高度时候才会显示 m_pControScrollV->SetVisible(size.Height > m_rc.Height()); ((CDuiScrollVertical*)m_pControScrollV)->SetScrollMaxRange(size.Height); return size.Height; }
void BottomAxesMeters::Draw() { Font font(L"Arial", (REAL)chart.fontHeight, FontStyleBold); Color color(chart.colorAxes); Pen pen(color, 2); SolidBrush fontColor(chart.colorAxes); StringFormat format; format.SetAlignment(StringAlignmentCenter); double height; int y = chart.rect.bottom - chart.offsetAxesBottom; //chart.g->DrawLine(&pen, chart.rect.left + chart.offsetAxesLeft, y, chart.rect.right - chart.offsetAxesRight, y); chart.g->DrawLine(&pen, chart.offsetAxesLeft, y, chart.rect.right - chart.offsetAxesRight, y); char buf[32]; wchar_t wbuf[32]; PointF origin; RectF rect; double length = chart.rect.right - chart.rect.left - chart.offsetAxesLeft - chart.offsetAxesRight; double deltaTick = 0; double deltaDigit = 0; double digit = 0; double minTick = 0; int maxLen = 0; OffsetAxes( int(2.5 * chart.GetCountDigit(minA, maxA, height, font, maxLen)) , chart.rect.right - chart.rect.left - chart.offsetAxesLeft - chart.offsetAxesRight , minBorder , maxBorder , deltaDigit , deltaTick , digit , minTick ); minA = digit; chart.deltaTickX = deltaTick; chart.deltaDigitX = deltaDigit; //double offs = chart.offsetGridX = chart.rect.left + chart.offsetAxesLeft - minTick + deltaTick; double offs = chart.offsetAxesLeft; deltaTickDigit = deltaTick / deltaDigit; offsMin = chart.rect.left + chart.offsetAxesLeft; offsMax = chart.rect.right - chart.offsetAxesRight; y = chart.rect.bottom - chart.offsetAxesBottom; digit += deltaDigit; origin.Y = REAL(y + 5); while(offs < offsMax) { chart.g->DrawLine(&pen, int(offs), y, int(offs), y + 7); gcvt(digit, 5, buf); mbstowcs(wbuf, buf, 32); size_t len = wcslen(wbuf); chart.g->MeasureString(wbuf, len, &font, origin, &format, &rect); origin.X = REAL(offs + (deltaTick - rect.Width) / 2); chart.g->DrawString(wbuf, len, &font, origin, &fontColor); offs += deltaTick; digit += deltaDigit; } maxA = digit; }
void DrawString( Graphics *graphics, int x, int y, const wstring &str) { StringFormat format; format.SetAlignment(StringAlignmentCenter); graphics->DrawString( str.c_str(), -1, g_font, PointF((REAL)x, (REAL)y), &format, g_yellowBrush); }
void CElcNonWndButton::Draw(PVOID pvGraphics) { if (!pvGraphics) return; Rect rect(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height()); // draw background image if (m_background.background.pImage) { thePainter.DrawImage(pvGraphics, &m_background.background, &rect, m_state, 1, NULL); } // draw icon if (m_icon.pImage) { thePainter.DrawImage(pvGraphics, &m_icon, &rect, m_state, 1, NULL); } if (!m_strText.IsEmpty()) { LOGFONT lf = {0}; m_ftText.GetLogFont(&lf); FontFamily family(lf.lfFaceName); Font ftText(&family, 9); StringFormat stringfmt; stringfmt.SetAlignment(StringAlignmentCenter); stringfmt.SetLineAlignment(StringAlignmentCenter); stringfmt.SetHotkeyPrefix(HotkeyPrefixHide); Color crText; crText.SetFromCOLORREF(m_background.crTextNormal); RectF rcText; rcText.X = (REAL)m_rect.left; rcText.Y = (REAL)m_rect.top + 4; rcText.Width = (REAL)m_rect.Width(); rcText.Height = (REAL)m_rect.Height(); ((Graphics *)pvGraphics)->DrawString(m_strText, -1, &ftText, rcText, &stringfmt, &SolidBrush(crText)); } }
void CPropSelUser::drawSkin(void) { if(!imgDialog) return; CDC *pdc=this->GetWindowDC(); if(!pdc)return; CRect rc; this->GetWindowRect(&rc); Graphics g(pdc->m_hDC); int topHeight=32;//GetSystemMetrics(SM_CYFRAME)+GetSystemMetrics(SM_CYSIZE)+6; g.DrawImage(imgDialog,RectF(0.0f,0.0f,10.0f,topHeight),0.0f,0.0f,10.0f,topHeight,UnitPixel); g.DrawImage(imgDialog,RectF(10.0f,0.0f,rc.Width()-20,topHeight),9.0f,0.0f,1.0f,topHeight,UnitPixel); g.DrawImage(imgDialog,RectF((REAL)rc.Width()-10,0.0f,10.0f,topHeight),imgDialog->GetWidth()-10,0.0f,10.0f,topHeight,UnitPixel); m_bkColor=pdc->GetPixel(9,topHeight-1); m_txtColor^=m_bkColor; int bottomHeight=10; g.DrawImage(imgDialog,RectF(0.0f,topHeight,10.0f,rc.Height()-topHeight-bottomHeight),0.0f,topHeight,10.0f,imgDialog->GetHeight()-topHeight-bottomHeight,UnitPixel); g.DrawImage(imgDialog,RectF(rc.Width()-10.0f,topHeight,10.0f,rc.Height()-topHeight-bottomHeight), imgDialog->GetWidth()-10,topHeight,10.0f,1,UnitPixel); g.DrawImage(imgDialog,RectF(0,rc.Height()-bottomHeight,imgDialog->GetWidth()-5,bottomHeight),0,imgDialog->GetHeight()-bottomHeight,10,bottomHeight,UnitPixel); g.DrawImage(imgDialog,RectF(10,rc.Height()-bottomHeight,rc.Width()-20,bottomHeight),10,imgDialog->GetHeight()-bottomHeight,1,bottomHeight,UnitPixel); g.DrawImage(imgDialog,RectF(rc.Width()-10,rc.Height()-bottomHeight,10,bottomHeight),imgDialog->GetWidth()-10,imgDialog->GetHeight()-bottomHeight,10,bottomHeight,UnitPixel); CString s="宋体"; Font font(s.AllocSysString(),12,0,UnitPixel); SolidBrush brush(Color(255,255,255)); s.Format("请选择道具 [%s] 使用对象,当前游戏中有 %d 个可用用户对象",propItemName,maxUser); g.DrawString(s.AllocSysString(),-1,&font,PointF(5,5),0,&brush); StringFormat sf; sf.SetAlignment(StringAlignmentCenter); m_bnClose.Invalidate(FALSE); brush.SetColor(Color(0,0,0)); Pen pen(&brush);//20081128 REAL x,y,w,h; //20081128,计算具体图片的位置 for(int i=0;i<maxUser;i++) { x=userRect[i].left+(66-userImg[i]->GetWidth())/2; y=userRect[i].top+(105-userImg[i]->GetHeight())/2; w=userImg[i]->GetWidth(); h=userImg[i]->GetHeight(); g.DrawImage(userImg[i],x,y,w,h);//画头像,替换原来的画头像代码 //画选择区域边框 g.DrawRectangle(&pen,userRect[i].left , userRect[i].top , userRect[i].Width() , userRect[i].Height()); g.DrawString(userName[i].AllocSysString() ,-1 ,&font , RectF(userRect[i].left,userRect[i].bottom+5,userRect[i].Width(),30),&sf,&brush); } g.ReleaseHDC(pdc->m_hDC); }
void UILabel::onPaintText(Graphics& graphics, Rect rect) { StringFormat stringFormat; stringFormat.SetTrimming(m_font.m_trimming); stringFormat.SetAlignment(m_font.m_horizen); stringFormat.SetLineAlignment(m_font.m_vertical); Font font(m_font.m_family, m_font.m_size, m_font.m_style, m_font.m_unit); SolidBrush brush(getTrueColor(m_font.m_color)); graphics.DrawString(m_font.m_text, -1, &font, m_font.m_rect, &stringFormat, &brush); }
// 绘制汽车 void Car::draw(Graphics* pGraphics) { // 计算坐标 RectF rcDest; Image *pImg = nullptr; switch (m_direction) { case UPWARD: rcDest.X = m_location.x * 50; rcDest.Width = 50; rcDest.Y = m_location.y * 50; rcDest.Height = 100; pImg = (*m_imgArray)[0]; break; case DOWNWARD: rcDest.X = m_location.x * 50; rcDest.Width = 50; rcDest.Y = (m_location.y - 1) * 50; rcDest.Height = 100; pImg = (*m_imgArray)[1]; break; case LEFT: rcDest.X = m_location.x * 50; rcDest.Width = 100; rcDest.Y = m_location.y * 50; rcDest.Height = 50; pImg = (*m_imgArray)[2]; break; case RIGHT: rcDest.X = (m_location.x - 1) * 50; rcDest.Width = 100; rcDest.Y = m_location.y * 50; rcDest.Height = 50; pImg = (*m_imgArray)[3]; break; } // 绘制图形 pGraphics->DrawImage(pImg, rcDest); // 绘制编号 WCHAR string[4] = { '\0' }; swprintf_s(string, 4, L"%d", m_cardNum); FontFamily fontFamily(L"Arial"); Gdiplus::Font font(&fontFamily, 16, FontStyleBold, UnitPoint); StringFormat stringFormat; SolidBrush solidBrush(Color(0, 0, 0)); stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); pGraphics->DrawString(string, -1, &font, rcDest, &stringFormat, &solidBrush); }
void GPDrawShadowText( Graphics& gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB PenClrIn , ARGB shadowPenClrIn /*= 0xff000000*/, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ ) { Gdiplus::Font& gcfont = fontIn; FontFamily fmy; gcfont.GetFamily(&fmy); int nfontStyle = gcfont.GetStyle(); REAL dFontSize = gcfont.GetSize(); Rect rcText = CRect2Rect(rcIn); StringFormat fmt; fmt.SetAlignment(StringAlignmentCenter); fmt.SetTrimming(StringTrimmingEllipsisWord); fmt.SetLineAlignment(StringAlignmentCenter); StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn; GraphicsContainer gcContainer = gc.BeginContainer(); gc.SetSmoothingMode(SmoothingModeAntiAlias); CComBSTR btrTxtIn(strTxtIn); GraphicsPath textPath; textPath.AddString(btrTxtIn, -1, &fmy, nfontStyle, dFontSize, rcText, &fmtUse); Matrix mx; mx.Translate(nOffXIn, nOffYIn); textPath.Transform(&mx); Pen textPen(ARGB2Color(shadowPenClrIn), 1); SolidBrush textbrush(ARGB2Color(shadowBrushClrIn)); textPen.SetLineJoin(LineJoinRound); if (shadowBrushClrIn != 0) { gc.FillPath(&textbrush, &textPath); } if (shadowPenClrIn != 0) { gc.DrawPath(&textPen, &textPath); } mx.Invert(); textPath.Transform(&mx); textPen.SetColor(ARGB2Color(PenClrIn)); textbrush.SetColor(ARGB2Color(BrushClrIn)); if (BrushClrIn != 0) { gc.FillPath(&textbrush, &textPath); } if (PenClrIn != 0) { gc.DrawPath(&textPen, &textPath); } gc.EndContainer(gcContainer); }
void CListBoxEx::DrawText(Graphics *pG, CRect rcItem, CString strText, Color clrText) { FontFamily fontptroll(L"Arial"); Gdiplus::Font font(&fontptroll, m_fSizeText, FontStyleRegular, UnitPixel); StringFormat formatAlign; formatAlign.SetAlignment((Gdiplus::StringAlignment)m_nTextAlign1); // Left / Center / Right formatAlign.SetLineAlignment((Gdiplus::StringAlignment)m_nTextAlign2); // Top / Middle / Bottom SolidBrush brs(clrText); RectF rcfCaption((float)rcItem.left+m_nOffsetTextX, (float)rcItem.top+m_nOffsetTextY, (float)rcItem.Width()-20,(float)rcItem.Height()); pG->DrawString(strText,strText.GetLength(),&font,rcfCaption,&formatAlign,&brs); }
void Draw1C::DrawString(wchar_t *string, short x, short y, short w, short h, int h_align, int v_align, wchar_t *font, int font_size, int font_style, DrawColor color) { Graphics g(canvas); SolidBrush b(Color(color.a, color.r, color.g, color.b)); RectF r(x, y, w, h); Font f(font, (REAL)font_size, font_style); StringFormat sf; sf.SetAlignment((StringAlignment)h_align); sf.SetLineAlignment((StringAlignment)v_align); g.DrawString(string, -1, &f, r, &sf, &b); }
void CEventColonization::Draw(Graphics* g, CGraphicPool* graphicPool) const { CEventScreen::Draw(g, graphicPool); CString fontName = ""; Gdiplus::REAL fontSize = 0.0; StringFormat fontFormat; SolidBrush fontBrush(static_cast<Gdiplus::ARGB>(Color::White)); CBotEDoc* pDoc = resources::pDoc; AssertBotE(pDoc); CMajor* pMajor = dynamic_cast<CMajor*>(pDoc->GetRaceCtrl()->GetRace(m_sRace)); AssertBotE(pMajor); CFontLoader::CreateGDIFont(pMajor, 5, fontName, fontSize); fontFormat.SetAlignment(StringAlignmentCenter); fontFormat.SetLineAlignment(StringAlignmentCenter); fontFormat.SetFormatFlags(StringFormatFlagsNoWrap); Gdiplus::Color color; CFontLoader::GetGDIFontColor(pMajor, 3, color); fontBrush.SetColor(color); g->DrawString(CComBSTR(m_strHeadline), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(0,0,1280,96), &fontFormat, &fontBrush); CFontLoader::CreateGDIFont(pMajor, 3, fontName, fontSize); fontFormat.SetAlignment(StringAlignmentCenter); fontFormat.SetLineAlignment(StringAlignmentCenter); fontFormat.SetFormatFlags(!StringFormatFlagsNoWrap); g->DrawString(CComBSTR(m_strText), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(100,96,1080,128), &fontFormat, &fontBrush); // Buttons zeichnen CFontLoader::GetGDIFontColor(pMajor, 2, color); fontBrush.SetColor(color); for (int i = 0; i < m_Buttons.GetSize(); i++) m_Buttons.GetAt(i)->DrawButton(*g, graphicPool, Gdiplus::Font(CComBSTR(fontName), fontSize), fontBrush); }
void ProcessDateTime::SetStringFormat(StringFormat &format) { UINT formatFlags; formatFlags = Gdiplus::StringFormatFlagsNoFitBlackBox | Gdiplus::StringFormatFlagsMeasureTrailingSpaces; format.SetFormatFlags(formatFlags); format.SetTrimming(Gdiplus::StringTrimmingWord); format.SetAlignment(Gdiplus::StringAlignmentNear); }
void CSkinList::Draw(CDIB &tmp) { CRect r; GetClientRect(&r); tmp.Resize(r.Width(), r.Height()); if(!tmp.Ready()) { return; } RectF rf(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height()); RectF rx; Graphics g(tmp.dc); g.SetCompositingMode(CompositingModeSourceOver); if(bckg->Ready()) { tmp.Draw(tmp.Rect(), 0, 0, bckg, DrawFlagsReflectDest); } if(dib->Ready()) { g.DrawImage(dib->bmp, 0.0f, r.Height() * 0.36f); Font font(L"Arial", 9.0f); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentCenter); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); CString s; s.Format(L"%s\n%s", skin->name.GetBuffer(), skin->description.GetBuffer()); RectF rx(0, 0, (REAL)dib->Width(), r.Height() * 0.36f); rx.Y++; SolidBrush brush(0xfff0f0f0); g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush); rx.Y--; brush.SetColor(0xff000000); g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush); delete stringFormat; } }
int MusicUtils::TestStringCx(const wchar_t *szText) { //CDC tdc; //tdc.CreateCompatibleDC(CDC::FromHandle(::GetDC(0))); //HBITMAP hbitmap = CreateCompatibleBitmap(tdc.m_hDC,600,15); //tdc.SelectObject(hbitmap); //return tdc.GetOutputTextExtent(szText).cx; GraphicsPath path; FontFamily fontfamily; Font font(L"宋体",14); font.GetFamily(&fontfamily); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); path.AddString(szText,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat); RectF rcBound; path.GetBounds(&rcBound); return rcBound.Width; }
// *************************************************************** // DrawGridText() // *************************************************************** void TilesDrawer::DrawGridText(TileCore* tile, RectF& screenRect) { CString str; str.Format("x=%d; y=%d", tile->tileX(), tile->tileY()); WCHAR* wStr = Utility::StringToWideChar(str); Font* font = Utility::GetGdiPlusFont("Arial", 14); SolidBrush brush(Color::Orange); StringFormat format; format.SetAlignment(StringAlignmentCenter); format.SetLineAlignment(StringAlignmentCenter); _graphics->DrawString(wStr, wcslen(wStr), font, screenRect, &format, &brush); delete font; delete wStr; }
void CLinkButton::DrawControl(CDC &dc, CRect rcUpdate) { int nWidth = m_rc.Width(); int nHeight = m_rc.Height(); if(!m_bUpdate) { UpdateMemDC(dc, nWidth * 4, nHeight); for(int i = 0; i < 4; i++) { m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY); } Color clrText[4] = {m_clrTextNormal, m_clrTextHover, m_clrTextDown, m_clrTextDisable}; Graphics graphics(m_memDC); BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); ::SysFreeString(bsFont); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); Size sizeText = GetTextBounds(font, strFormat, m_strTitle); CPoint point = GetOriginPoint(nWidth, nHeight, sizeText.Width, sizeText.Height, GetGDIAlignment(m_uAlignment), GetGDIVAlignment(m_uVAlignment)); m_rcText.SetRect(m_rc.left, m_rc.top + point.y, m_rc.left + sizeText.Width, m_rc.top + point.y + sizeText.Height); for(int i = 0; i < 4; i++) { SolidBrush solidBrush(clrText[i]); RectF rect((Gdiplus::REAL)(i * nWidth), (Gdiplus::REAL)point.y, (Gdiplus::REAL)nWidth, (Gdiplus::REAL)sizeText.Height); BSTR bsTitle = m_strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush); ::SysFreeString(bsTitle); } } dc.BitBlt(m_rc.left,m_rc.top, m_rc.Width(), m_rc.Height(), &m_memDC, m_enButtonState * nWidth, 0, SRCCOPY); }
// UI Node 출력. Point Display(sNode *node, const Point &parentPos, const Point &pos) { const Rect NodeSize(0,0,60,50); const Point NodeGap(40, 20); if (!node) return parentPos+Point(NodeSize.Width, NodeSize.Height); Rect r = NodeSize; r.Offset(pos); g_graphics->DrawRectangle(g_pen, r); if ((parentPos.X != -1) && (parentPos.Y != -1)) { Point lineOffset(r.Width/2, r.Height); g_graphics->DrawLine(g_pen, parentPos+lineOffset, pos+lineOffset+Point(0,-r.Height)); } // Initialize arguments. Font myFont(L"Arial", 12); StringFormat format; format.SetAlignment(StringAlignmentCenter); SolidBrush blackBrush(Color(255, 0, 0, 0)); // Draw string. g_graphics->DrawString( node->name.c_str(), -1, &myFont, RectF((REAL)r.X, (REAL)r.Y, (REAL)r.Width, (REAL)r.Height), &format, &blackBrush); // 자식 노드 출력. const Point leftNodePos = pos+Point(0, NodeSize.Height+NodeGap.Y); const Point cPos1 = Display(node->child1, pos, leftNodePos); Point rightNodePos = pos+Point(NodeSize.Width+NodeGap.X, NodeSize.Height+NodeGap.Y); if (cPos1.X > rightNodePos.X) rightNodePos.X = cPos1.X + NodeGap.X; const Point cPos2 = Display(node->child2, pos, rightNodePos); if (cPos2.X < cPos1.X) return cPos1; return cPos2; }
void CToolRegularRuler::DrawRulerMarks(Graphics& graph) { int nNumber = 0; int nbegin = m_rcHot.left + 10; int nend = m_rcHot.right - 10; CString strNumber; Font fontNumber(L"Arial", 10); SolidBrush brush(Color::Black); StringFormat format; format.SetAlignment(StringAlignmentCenter); Pen penDraw(Color::Black, 1); PointF ptBegin((float)nbegin, m_rcHot.top + 1.0f); PointF ptEnd = ptBegin; graph.SetTextRenderingHint(TextRenderingHintAntiAlias); for(int i = nbegin; i < nend; i+= 10) { ptEnd.X = (float)i; ptBegin.X = (float)i; if((i - nbegin) % 100 == 0) { ptEnd.Y = ptBegin.Y + 30; graph.DrawLine(&penDraw, ptBegin, ptEnd); nNumber = (i - nbegin) / 100; strNumber.Format(_T("%d"), nNumber); graph.DrawString(strNumber, strNumber.GetLength(), &fontNumber, ptEnd, &format, &brush); } else if((i - nbegin) % 50 == 0) { ptEnd.Y = ptBegin.Y + 20; graph.DrawLine(&penDraw, ptBegin, ptEnd); } else { ptEnd.Y = ptBegin.Y + 10; graph.DrawLine(&penDraw, ptBegin, ptEnd); } } }
int CLMenu::GetMaxItemWidth() { int w = 0; HDC dc = CreateCompatibleDC(0); Graphics g(dc); RectF r; Font font(L"Arial", FONT_SIZE); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentNear); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); POSITION p = items.GetHeadPosition(); while(p) { r.X = 0; r.Y = 0; r.Width = 0; r.Height = 0; CLMenuItem *item = items.GetAt(p); if(item->visible) { g.MeasureString(item->text.GetBuffer(), item->text.GetLength(), &font, r, &r); if(r.Width > w) { w = (int)r.Width; } } items.GetNext(p); } delete stringFormat; DeleteObject(dc); return w; }
int CInstallDesktopTipWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here Status status = GdiplusStartup(&ms_GdiToken, &ms_GdiStartupInput, NULL); ATLASSERT(status == Ok); LoadBkgImage(); // °ÑͼƬÀÉìµ½´°¿Ú´óС m_BufferMemBitmap = CreateDefaultDIBSection(WND_X, WND_Y); m_BufferMemDC = ::CreateCompatibleDC(NULL); ::SelectObject(m_BufferMemDC, m_BufferMemBitmap); StretchBltX(m_BufferMemDC, 0, 0, WND_X, WND_Y, m_ImageMemDC, 0, 0, m_ImageWidth, m_ImageHeight, CRect(0, 0, 0, 0)); FontFamily* fontFamily = new FontFamily(L"΢ÈíÑźÚ"); Font* font = new Gdiplus::Font(fontFamily, 18.0f, FontStyleRegular, UnitPixel); LPCTSTR lpszString = L"»¶ÓÄúʹÓÃÓеÀ´Êµä£¡"; CRect rc; GetClientRect(&rc); Gdiplus::RectF rectF((REAL)rc.left, (REAL)rc.top, (REAL)rc.Width(), (REAL)rc.Height()); StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); Gdiplus::Color strColor(254, 0, 0, 0); SolidBrush solidBrush(strColor); Graphics graphics(m_BufferMemDC); graphics.DrawString(lpszString, -1, font, rectF, &stringFormat, &solidBrush); return 0; }
void CZoneView::DrawLabel(CDC* pDC, const std::vector<CElement*>& selection, CElement* highlight) const { //Propriétés de la chaine de caractère FontFamily fontFamily(L"Times New Roman"); Font maxfont(&fontFamily, 12, FontStyleRegular, UnitPixel); StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); SolidBrush brush(Color::Firebrick); RectF enclosingRectF(enclosingRect->X + 0.1*GRID_CELL_LENGTH, enclosingRect->Y + 0.1*GRID_CELL_LENGTH, enclosingRect->Width, enclosingRect->Height); //Dessin avec translation + symétrie axiale d'axe des abscisses Graphics g = pDC->GetSafeHdc(); g.TranslateTransform(0, position.Y * 2); Matrix matrix; matrix.SetElements(1, 0, 0, -1, 0, 0); g.MultiplyTransform(&matrix); g.DrawString(label, -1, &maxfont, enclosingRectF, &stringFormat, &brush); g.ResetTransform(); }