// 绘制按钮 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); } }
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; }
// 计算显示的字符串总高度应该是多高 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; }
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 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 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); }
void TextRenderGdiplus::Draw(const WCHAR *s, size_t sLen, RectF& bb, bool isRtl) { PointF pos; bb.GetLocation(&pos); if (!isRtl) { gfx->DrawString(s, (INT)sLen, currFont->font, pos, nullptr, textColorBrush); } else { StringFormat rtl; rtl.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); pos.X += bb.Width; gfx->DrawString(s, (INT)sLen, currFont->font, pos, &rtl, textColorBrush); } }
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 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); }
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; }
// 获取文字需要的显示区域(使用非换行的默认格式) Size GetTextBounds(const Font& font,const CString& strText) { StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); GraphicsPath path; FontFamily fontfamily; font.GetFamily(&fontfamily); BSTR bsText = strText.AllocSysString(); path.AddString(bsText,-1,&fontfamily,font.GetStyle(),font.GetSize(),PointF(0,0),&strFormat); ::SysFreeString(bsText); RectF rcBound; path.GetBounds(&rcBound); REAL rHeight = font.GetHeight(0.0f); return Size((int)(rcBound.Width > (int)rcBound.Width ? rcBound.Width + 1 : rcBound.Width), (int)(rHeight > (int)rHeight ? rHeight + 4 : rHeight + 1)); //return Size((int)(rcBound.Width > (int)rcBound.Width ? rcBound.Width + 1 : rcBound.Width), // (int)(rcBound.Height > (int)rcBound.Height ? rcBound.Height + 2 : rcBound.Height + 1)); }
int CDuiMenu::AddMenu(CString strText, UINT uMenuID, CString strImage, BOOL bSelect, int nIndex) { CControlBase * pControlBase = NULL; 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( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); Size size = GetTextBounds(font, strFormat, strText); if(size.Width > m_nWidth - m_nLeft - 4) { m_nWidth = size.Width + m_nLeft + 4; } pControlBase = new CMenuItem(GetSafeHwnd(),this, uMenuID, CRect(0, 0, 0, 0), strText, m_nLeft, bSelect); ((CControlBaseFont*)pControlBase)->SetFont(m_strFont, m_nFontWidth, m_fontStyle); if(!strImage.IsEmpty()) { ((CMenuItem *)pControlBase)->SetBitmap(strImage); } if(nIndex >= 0 && nIndex < (int)m_vecControl.size()) { m_vecControl.insert(m_vecControl.begin() + nIndex, pControlBase); } else { m_vecControl.push_back(pControlBase); } SetMenuPoint(); return m_vecControl.size(); }
void CDuiGridCtrl::DrawControl(CDC &dc, CRect rcUpdate) { // 列表画图方法: // 1.列表的虚拟高度为每一行高度*行数 // 2.列表显示的top坐标由scroll控件记录 // 3.重画时候,根据top坐标位置计算出显示的第一行的序号,根据显示高度计算出显示的最后一行的序号 // 4.根据计算出的显示的行,画相应的内容到内存dc中 // 5.计算出显示的top坐标进行内存dc的拷贝 int nTotalColumnWidth = GetTotalColumnWidth(); // 总的列宽度 int nViewWidth = m_rc.Width() - m_nScrollWidth; // 减去滚动条的显示区域宽度 CDuiScrollHorizontal* pScrollH = (CDuiScrollHorizontal*)m_pControScrollH; int nCurPosH = pScrollH->GetScrollCurrentPos(); // 当前left位置 int nMaxRangeH = pScrollH->GetScrollMaxRange(); int nContentWidth = (nTotalColumnWidth > nViewWidth) ? nTotalColumnWidth : nViewWidth; // 内容部分的宽度(如果总的列宽小于显示区域宽度,则使用显示区域宽度) m_nVirtualLeft = (nMaxRangeH > 0) ? (int)((double)nCurPosH*(nContentWidth-nViewWidth)/nMaxRangeH) : 0; // 当前滚动条位置对应的虚拟的left位置 int nHeightAll = m_vecRowInfo.size()*m_nRowHeight; // 总的虚拟高度 //m_rc.Height(); CDuiScrollVertical* pScrollV = (CDuiScrollVertical*)m_pControScrollV; int nCurPosV = pScrollV->GetScrollCurrentPos(); // 当前top位置 int nMaxRangeV = pScrollV->GetScrollMaxRange(); m_nVirtualTop = (nMaxRangeV > 0) ? (int)((double)nCurPosV*(nHeightAll-m_rc.Height())/nMaxRangeV) : 0; // 当前滚动条位置对应的虚拟的top位置 if(m_nVirtualTop < 0) { m_nVirtualTop = 0; pScrollV->SetScrollCurrentPos(0); } m_nFirstViewRow = m_nVirtualTop / m_nRowHeight; // 显示的第一行序号 m_nLastViewRow = (m_nVirtualTop + m_rc.Height() - m_nHeaderHeight) / m_nRowHeight; // 显示的最后一行序号 if(m_nLastViewRow >= (int)m_vecRowInfo.size()) { m_nLastViewRow = m_vecRowInfo.size() - 1; } if(m_nLastViewRow < 0) { m_nLastViewRow = 0; } int nHeightView = (m_nLastViewRow - m_nFirstViewRow +1) * m_nRowHeight; // 显示涉及到的虚拟高度 int nYViewPos = m_nVirtualTop - (m_nFirstViewRow * m_nRowHeight); // 内存dc显示到屏幕时候的top位置 if(nYViewPos < 0) { nYViewPos = 0; } if(!m_bUpdate) { UpdateMemDC(dc, nTotalColumnWidth, nHeightView); Graphics graphics(m_memDC); m_memDC.BitBlt(m_nVirtualLeft, 0, nViewWidth, nHeightView, &dc, m_rc.left, m_rc.top, WHITENESS); // 画白色背景 DrawVerticalTransition(m_memDC, dc, CRect(m_nVirtualLeft, nYViewPos, nViewWidth+m_nVirtualLeft, m_rc.Height()+nYViewPos-m_nHeaderHeight), // 背景透明度 m_rc, m_nBkTransparent, m_nBkTransparent); BSTR bsFontTitle = m_strFontTitle.AllocSysString(); FontFamily fontFamilyTitle(bsFontTitle); Font fontTitle(&fontFamilyTitle, (REAL)m_nFontTitleWidth, m_fontTitleStyle, UnitPixel); ::SysFreeString(bsFontTitle); BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); ::SysFreeString(bsFont); SolidBrush solidBrush(m_clrText); // 正常文字画刷 SolidBrush solidBrushH(m_clrTextHover); // 热点文字画刷 SolidBrush solidBrushD(m_clrTextDown); // 当前行画刷 SolidBrush solidBrushT(m_clrTitle); // 标题文字画刷 SolidBrush solidBrushS(m_clrSeperator); // 分割线画刷 graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); // 设置普通文字的水平和垂直对齐方式 DUI_STRING_ALIGN_DEFINE(); strFormat.SetTrimming(StringTrimmingEllipsisWord); // 以单词为单位去尾,略去部分使用省略号 //strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces); if(!m_bTextWrap) { strFormat.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行 } // 标题字段采用中间对齐 StringFormat strFormatHeader; strFormatHeader.SetAlignment(StringAlignmentCenter); // 中间对齐 strFormatHeader.SetLineAlignment(StringAlignmentCenter); // 中间对齐 if(!m_bTextWrap) { strFormatHeader.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行 } // 画标题行 if((m_nHeaderHeight > 0) && (m_vecColumnInfo.size() > 0)) { // 画单元格内容 int nPosItemX = 0; for(size_t j = 0; j < m_vecColumnInfo.size(); j++) { GridColumnInfo &columnInfo = m_vecColumnInfo.at(j); int nWidth = columnInfo.nWidth; if(j == 0) { nWidth += m_nLeftPos; } RectF rect((Gdiplus::REAL)nPosItemX, 0, (Gdiplus::REAL)nWidth, (Gdiplus::REAL)(m_nHeaderHeight-1)); // 画列标题 CString strTitle = columnInfo.strTitle; BSTR bsTitle = strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormatHeader, &solidBrushT); ::SysFreeString(bsTitle); nPosItemX += nWidth; } } if(m_vecRowInfo.size() > 0) { for(int i = m_nFirstViewRow; i <= m_nLastViewRow && i < (int)m_vecRowInfo.size(); i++) { GridRowInfo &rowInfo = m_vecRowInfo.at(i); SolidBrush solidBrushRow(rowInfo.clrText); // 行定义的颜色 int nXPos = 0; int nVI = i - m_nFirstViewRow; // 鼠标移动到行时候显示的背景颜色(如果设置为全0,则不显示行背景颜色) if((m_nHoverRow == i) && (m_clrRowHover.GetValue() != Color(0, 0, 0, 0).GetValue())) { SolidBrush brush(m_clrRowHover); graphics.FillRectangle(&brush, 0, m_nHeaderHeight + nVI*m_nRowHeight, nContentWidth, m_nRowHeight); } // 画检查框 int nCheckImgY = 3; if((m_sizeCheckBox.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nCheckImgY = (m_nRowHeight - m_sizeCheckBox.cy) / 2 + 1; } if((rowInfo.nCheck != -1) && (m_pImageCheckBox != NULL)) { int nCheckImageIndex = ((m_nHoverRow == i) ? ((rowInfo.nCheck==1) ? 4 : 1) : ((rowInfo.nCheck==1) ? 2 : 0)); graphics.DrawImage(m_pImageCheckBox, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nCheckImgY, m_sizeCheckBox.cx, m_sizeCheckBox.cy), nCheckImageIndex * m_sizeCheckBox.cx, 0, m_sizeCheckBox.cx, m_sizeCheckBox.cy, UnitPixel); rowInfo.rcCheck.SetRect(nXPos, i*m_nRowHeight + nCheckImgY, nXPos + m_sizeCheckBox.cx, i*m_nRowHeight + nCheckImgY + m_sizeCheckBox.cy); nXPos += (m_sizeCheckBox.cx + 3); } // 画行左边图片 int nImgY = 3; if(rowInfo.pImage != NULL) { if((rowInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1; } // 使用行数据指定的图片 graphics.DrawImage(rowInfo.pImage, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy), 0, 0, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy, UnitPixel); nXPos += (rowInfo.sizeImage.cx + 3); }else if((rowInfo.nImageIndex != -1) && (m_pImage != NULL)) { if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1; } // 使用索引图片 graphics.DrawImage(m_pImage, Rect(nXPos, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy), rowInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); nXPos += (m_sizeImage.cx + 3); } // 画行右边图片 int nRightImageWidth = 0; nImgY = 3; if(rowInfo.pRightImage != NULL) { if((rowInfo.sizeRightImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - rowInfo.sizeRightImage.cy) / 2 + 1; } // 使用行数据指定的图片 graphics.DrawImage(rowInfo.pRightImage, Rect(nContentWidth-rowInfo.sizeRightImage.cx-1, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy), 0, 0, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy, UnitPixel); nRightImageWidth = rowInfo.sizeRightImage.cx + 1; }else if((rowInfo.nRightImageIndex != -1) && (m_pImage != NULL)) { if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1; } // 使用索引图片 graphics.DrawImage(m_pImage, Rect(nContentWidth-m_sizeImage.cx-1, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy), rowInfo.nRightImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); nRightImageWidth = m_sizeImage.cx + 1; } // 画单元格内容 int nPosItemX = (m_nLeftPos != 0) ? m_nLeftPos : nXPos; for(size_t j = 0; j < rowInfo.vecItemInfo.size(); j++) { GridColumnInfo &columnInfo = m_vecColumnInfo.at(j); GridItemInfo &itemInfo = rowInfo.vecItemInfo.at(j); BOOL bSingleLine = (itemInfo.strContent.IsEmpty() || !itemInfo.strLink.IsEmpty()); RectF rect((Gdiplus::REAL)nPosItemX, (Gdiplus::REAL)(m_nHeaderHeight + nVI*m_nRowHeight + 1), (Gdiplus::REAL)((j == 0) ? (itemInfo.rcItem.Width() - nPosItemX): itemInfo.rcItem.Width()), (Gdiplus::REAL)(bSingleLine ? (m_nRowHeight - 2) : (m_nRowHeight / 2 - 2))); if((int)(rect.GetRight()) > nContentWidth) { // 最后一列需要减去滚动条宽度 rect.Width -= m_nScrollWidth; } // 画单元格图片 int nItemImageX = 0; int nImgY = 3; if(itemInfo.pImage != NULL) { if((itemInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1; } // 使用单元格指定的图片 graphics.DrawImage(itemInfo.pImage, Rect(nPosItemX+nItemImageX, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy), 0, 0, itemInfo.sizeImage.cx, itemInfo.sizeImage.cy, UnitPixel); nItemImageX += (itemInfo.sizeImage.cx + 3); }else if((itemInfo.nImageIndex != -1) && (m_pImage != NULL)) { if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1; } // 使用索引图片 graphics.DrawImage(m_pImage, Rect(nPosItemX+nItemImageX, m_nHeaderHeight + nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy), itemInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); nItemImageX += (m_sizeImage.cx + 3); } rect.Offset((Gdiplus::REAL)nItemImageX, 0); rect.Width -= (Gdiplus::REAL)nItemImageX; // 画单元格标题或链接内容 SolidBrush solidBrushItem(m_clrText); if((m_nHoverRow == i) && (m_clrTextHover.GetValue() != Color(0, 0, 0, 0).GetValue())) // 设置了鼠标移动颜色,则使用 { solidBrushItem.SetColor(m_clrTextHover); }else if((m_nDownRow == i) && (m_clrTextDown.GetValue() != Color(0, 0, 0, 0).GetValue())) // 设置了鼠标按下颜色,则使用 { solidBrushItem.SetColor(m_clrTextDown); }else if(itemInfo.clrText.GetValue() != Color(0, 0, 0, 0).GetValue()) // 设置了单元格颜色,则使用 { solidBrushItem.SetColor(itemInfo.clrText); }else if(rowInfo.bRowColor) // 设置了行颜色,则使用 { solidBrushItem.SetColor(rowInfo.clrText); } CString strItemTitle = itemInfo.strTitle; // 计算是否需要显示tip itemInfo.bNeedTitleTip = rect.Width < GetTextBounds(font, strItemTitle).Width; itemInfo.bNeedContentTip = rect.Width < GetTextBounds(font, itemInfo.strContent).Width; if(!itemInfo.strLink.IsEmpty()) { strItemTitle = itemInfo.strLink; if((m_nHoverRow == i) && (rowInfo.nHoverItem == j)) { solidBrushItem.SetColor(m_clrTextHover); }else { solidBrushItem.SetColor((itemInfo.clrText.GetValue() != Color(0, 0, 0, 0).GetValue()) ? itemInfo.clrText : m_clrText); } } // 设置单元格文字对齐方式,使用列的对齐方式 StringFormat strFormatColumn; UINT uAlignment = m_uAlignment; if(columnInfo.uAlignment != 0xFFFFUL) { uAlignment = columnInfo.uAlignment; } if(uAlignment == Align_Left) { strFormatColumn.SetAlignment(StringAlignmentNear); }else if(uAlignment == Align_Center) { strFormatColumn.SetAlignment(StringAlignmentCenter); }else if(uAlignment == Align_Right) { strFormatColumn.SetAlignment(StringAlignmentFar); } UINT uVAlignment = m_uVAlignment; if(columnInfo.uVAlignment != 0xFFFFUL) { uVAlignment = columnInfo.uVAlignment; } if(uVAlignment == VAlign_Top) { strFormatColumn.SetLineAlignment(StringAlignmentNear); }else if(uVAlignment == VAlign_Middle) { strFormatColumn.SetLineAlignment(StringAlignmentCenter); }else if(uVAlignment == VAlign_Bottom) { strFormatColumn.SetLineAlignment(StringAlignmentFar); } if(!m_bTextWrap) { strFormatColumn.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行 } // 根据bUseTitleFont决定用标题字体还是普通字体 BSTR bsItemTitle = strItemTitle.AllocSysString(); graphics.DrawString(bsItemTitle, (INT)wcslen(bsItemTitle), itemInfo.bUseTitleFont ? &fontTitle : &font, rect, &strFormatColumn, itemInfo.bUseTitleFont ? &solidBrushT : &solidBrushItem); ::SysFreeString(bsItemTitle); // 画单元格内容 if(!bSingleLine) { rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2); rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4; BSTR bsItemContent = itemInfo.strContent.AllocSysString(); graphics.DrawString(bsItemContent, (INT)wcslen(bsItemContent), &font, rect, &strFormatColumn, &solidBrushItem); ::SysFreeString(bsItemContent); } // 设置单元格子控件的位置 for(size_t k = 0; k < itemInfo.vecControl.size(); k++) { CControlBase* pControl = itemInfo.vecControl.at(k); if(pControl) { CRect rcParent = CRect(nPosItemX, m_nHeaderHeight + nVI*m_nRowHeight + 1, (int)(rect.X+rect.Width), (nVI+1)*m_nRowHeight - 1); if((int)(rect.GetRight()) > nContentWidth) { // 最后一列需要减去滚动条宽度 rcParent.right -= m_nScrollWidth; } rcParent.OffsetRect(m_rc.left - m_nVirtualLeft, m_rc.top - (nYViewPos + m_nHeaderHeight)); pControl->SetPositionWithParent(rcParent); CRect rcControl = pControl->GetRect(); // 只有当前在显示范围内的控件设置为可见 if( (rcControl.top < m_rc.top) || (rcControl.bottom > m_rc.bottom) || (rcControl.left < m_rc.left) || (rcControl.right > m_rc.right) ) { pControl->SetVisible(FALSE); }else { pControl->SetVisible(TRUE); } } } if(j == 0) { // 为了使第二列开始是对齐的,所以第二列开始位置按照第一列的宽度计算 nPosItemX = itemInfo.rcItem.right; }else { nPosItemX += itemInfo.rcItem.Width(); } } // 画分隔线(采用拉伸模式) if(m_pImageSeperator != NULL) { // 使用拉伸模式画图 graphics.DrawImage(m_pImageSeperator, RectF(0, (Gdiplus::REAL)(m_nHeaderHeight + (nVI+1)*m_nRowHeight), (Gdiplus::REAL)(nContentWidth-2), (Gdiplus::REAL)m_sizeSeperator.cy), 0, 0, (Gdiplus::REAL)m_sizeSeperator.cx, (Gdiplus::REAL)m_sizeSeperator.cy, UnitPixel); }else if(m_clrSeperator.GetValue() != Color(0, 0, 0, 0).GetValue()) { // 未指定图片,并且分隔线显色不是全0,则画矩形 graphics.FillRectangle(&solidBrushS, 0, m_nHeaderHeight + (nVI+1)*m_nRowHeight, nContentWidth-2, 1); } } // 把不在显示范围内的单元格的控件都设置为不可见 for(int i = 0; i < (int)m_vecRowInfo.size(); i++) { if((i < m_nFirstViewRow) || (i > m_nLastViewRow)) { GridRowInfo &rowInfo = m_vecRowInfo.at(i); for(size_t j = 0; j < rowInfo.vecItemInfo.size(); j++) { GridItemInfo &itemInfo = rowInfo.vecItemInfo.at(j); for(size_t k = 0; k < itemInfo.vecControl.size(); k++) { CControlBase* pControl = itemInfo.vecControl.at(k); if(pControl) { pControl->SetVisible(FALSE); } } } } } } } // 输出到界面DC,使用与的方式合并背景 // 标题行输出 if(m_nHeaderHeight > 0) { dc.BitBlt(m_rc.left,m_rc.top, nViewWidth, m_nHeaderHeight, &m_memDC, m_nVirtualLeft, 0, SRCCOPY);//SRCAND); } // 内容部分输出 int nContentHeight = m_rc.Height() - m_nHeaderHeight; if(nTotalColumnWidth > m_rc.Width()) { nContentHeight -= m_nScrollWidth; } dc.BitBlt(m_rc.left,m_rc.top + m_nHeaderHeight, nViewWidth, nContentHeight, &m_memDC, m_nVirtualLeft, nYViewPos + m_nHeaderHeight, SRCCOPY);//SRCAND); }
void CNotification::LayerDraw(CDIB *dib) { if(!dib) { dib = CNotification::dib; } CRect rect; GetWindowRect(&rect); dib->Resize(rect.Width(), rect.Height()); if(!dib->Ready()) { return; } RectF rf(0.0f, 0.0f, (REAL)dib->Width(), (REAL)dib->Height()); rf.Width -= SHADOW_SIZE; rf.Height -= SHADOW_SIZE; Graphics g(dib->dc); g.SetCompositingMode(CompositingModeSourceOver); g.SetSmoothingMode(SmoothingModeAntiAlias); GraphicsPath *path = new GraphicsPath(); float radius = rf.Height; path->AddArc(rf.X + rf.Width - radius, rf.Y + rf.Height - radius, radius - 1, radius - 1, 0, 90); path->AddArc(rf.X, rf.Y + rf.Height - radius, radius - 1, radius - 1, 90, 90); path->AddArc(rf.X, rf.Y, radius - 1, radius - 1, 180, 90); path->AddArc(rf.X + rf.Width - radius, rf.Y, radius - 1, radius - 1, 270, 90); path->CloseFigure(); g.TranslateTransform(SHADOW_SIZE, SHADOW_SIZE); g.ScaleTransform((rf.Width - SHADOW_SIZE) / rf.Width, (rf.Height - SHADOW_SIZE) / rf.Height); SolidBrush brush2(0xf0000000); g.FillPath(&brush2, path); g.ResetTransform(); dib->Blur(dib->Rect(), CRect(0, 0, 0, 0), SHADOW_SIZE); brush2.SetColor(0xffffffff); g.FillPath(&brush2, path); rf.X += rf.Height * 0.1f; rf.Y += rf.Height * 0.1f; rf.Width -= rf.Height * 0.2f; rf.Height -= rf.Height * 0.2f; radius = rf.Height; path->Reset(); path->AddArc(rf.X + rf.Width - radius, rf.Y + rf.Height - radius, radius - 1, radius - 1, 0, 90); path->AddArc(rf.X, rf.Y + rf.Height - radius, radius - 1, radius - 1, 90, 90); path->AddArc(rf.X, rf.Y, radius - 1, radius - 1, 180, 90); path->AddArc(rf.X + rf.Width - radius, rf.Y, radius - 1, radius - 1, 270, 90); path->CloseFigure(); LinearGradientBrush brush(rf, 0xff6fa6de, 0xff1e6cbb, LinearGradientModeVertical); g.FillPath(&brush, path); delete path; Font font(L"Arial", rect.Height() * 0.6f, FontStyleRegular, UnitPixel); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentCenter); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); CString s; GetWindowText(s); g.DrawString(s.GetBuffer(), s.GetLength(), &font, rf, stringFormat, &brush2); delete stringFormat; }
void CDuiEdit::DrawControl(CDC &dc, CRect rcUpdate) { Graphics graphics(dc); DrawImageFrame(graphics, m_pImage, m_rc, m_EditState * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, 4); if(m_pLeftImage) { CRect rc; rc.left = m_rc.left + 2; rc.top = m_rc.top + (m_rc.Height() - m_sizeLeftImage.cy) / 2; rc.right = rc.left + m_sizeLeftImage.cx; rc.bottom = rc.top + m_sizeLeftImage.cy; if(m_nLeftImageCount > m_buttonState) { graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), (Gdiplus::REAL)(m_buttonState * m_sizeLeftImage.cx), 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel); }else { graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), 0, 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel); } } if(m_pSmallImage) { CRect rc; rc.left = m_rc.right - m_sizeSmallImage.cx - 2; rc.top = m_rc.top + (m_rc.Height() - m_sizeSmallImage.cy) / 2; rc.right = rc.left + m_sizeSmallImage.cx; rc.bottom = rc.top + m_sizeSmallImage.cy; if(m_nSmallImageCount > m_buttonState) { graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), (Gdiplus::REAL)(m_buttonState * m_sizeSmallImage.cx), 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel); }else { graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()), 0, 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel); } } BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); SolidBrush solidBrush(m_clrText); SolidBrush solidBrushTip(m_clrTooltip); graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); ::SysFreeString(bsFont); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); // 水平方向左对齐 if(!m_bMultiLine) { // 单行文字 strFormat.SetLineAlignment(StringAlignmentCenter); // 垂直方向中间对齐 strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); }else { strFormat.SetLineAlignment(StringAlignmentNear); // 垂直方向上对齐 } RectF rect((Gdiplus::REAL)m_rcText.left, (Gdiplus::REAL)(m_rcText.top+2), (Gdiplus::REAL)m_rcText.Width(), (Gdiplus::REAL)(m_rcText.Height()-2)); if(!m_strTitle.IsEmpty()) { // 文字非空 CString strTitle = m_strTitle; if(m_bPassWord) { int nlen = strTitle.GetLength(); strTitle = ""; for(int i = 0; i < nlen; i++) { strTitle += '*'; } } BSTR bsTitle = strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush); ::SysFreeString(bsTitle); }else if(!m_strTooltip.IsEmpty()) { // 如果没有文字,但设置了tooltip,则显示tooltip BSTR bsTooltip = m_strTooltip.AllocSysString(); graphics.DrawString(bsTooltip, (INT)wcslen(bsTooltip), &font, rect, &strFormat, &solidBrushTip); ::SysFreeString(bsTooltip); } }
void CDuiListCtrl::DrawControl(CDC &dc, CRect rcUpdate) { // 列表画图方法: // 1.列表的虚拟高度为每一行高度*行数 // 2.列表显示的top坐标由scroll控件记录 // 3.重画时候,根据top坐标位置计算出显示的第一行的序号,根据显示高度计算出显示的最后一行的序号 // 4.根据计算出的显示的行,画相应的内容到内存dc中 // 5.计算出显示的top坐标进行内存dc的拷贝 int nWidth = m_rc.Width() - m_nScrollWidth; // 减去滚动条的宽度 int nHeightAll = (int)m_vecRowInfo.size()*m_nRowHeight; // 总的虚拟高度 //m_rc.Height(); CScrollV* pScrollV = (CScrollV*)m_pControScrollV; int nCurPos = pScrollV->GetScrollCurrentPos(); // 当前top位置 int nMaxRange = pScrollV->GetScrollMaxRange(); m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0; // 当前滚动条位置对应的虚拟的top位置 if(m_nVirtualTop < 0) { m_nVirtualTop = 0; pScrollV->SetScrollCurrentPos(0); } m_nFirstViewRow = m_nVirtualTop / m_nRowHeight; // 显示的第一行序号 m_nLastViewRow = (m_nVirtualTop + m_rc.Height()) / m_nRowHeight; // 显示的最后一行序号 if(m_nLastViewRow >= (int)m_vecRowInfo.size()) { m_nLastViewRow = (int)m_vecRowInfo.size() - 1; } if(m_nLastViewRow < 0) { m_nLastViewRow = 0; } int nHeightView = (m_nLastViewRow - m_nFirstViewRow +1) * m_nRowHeight; // 显示涉及到的虚拟高度 int nYViewPos = m_nVirtualTop - (m_nFirstViewRow * m_nRowHeight); // 内存dc显示到屏幕时候的top位置 if(nYViewPos < 0) { nYViewPos = 0; } if(!m_bUpdate) { UpdateMemDC(dc, nWidth, nHeightView); Graphics graphics(m_memDC); m_memDC.BitBlt(0, 0, nWidth, nHeightView, &dc, m_rc.left ,m_rc.top, WHITENESS); // 画白色背景 DrawVerticalTransition(m_memDC, dc, CRect(0, nYViewPos, nWidth, m_rc.Height()+nYViewPos), // 背景透明度 m_rc, m_nBkTransparent, m_nBkTransparent); BSTR bsFontTitle = m_strFontTitle.AllocSysString(); FontFamily fontFamilyTitle(bsFontTitle); Font fontTitle(&fontFamilyTitle, (REAL)m_nFontTitleWidth, m_fontTitleStyle, UnitPixel); ::SysFreeString(bsFontTitle); BSTR bsFont = m_strFont.AllocSysString(); FontFamily fontFamily(bsFont); Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel); ::SysFreeString(bsFont); SolidBrush solidBrush(m_clrText); // 正常文字画刷 SolidBrush solidBrushH(m_clrTextHover); // 热点文字画刷 SolidBrush solidBrushD(m_clrTextDown); // 当前行画刷 SolidBrush solidBrushT(m_clrTitle); // 标题文字画刷 SolidBrush solidBrushS(m_clrSeperator); // 分割线画刷 graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit ); // 普通文字的对齐方式 StringFormat strFormat; strFormat.SetAlignment(StringAlignmentNear); // 左对齐 if(m_uVAlignment == VAlign_Top) { strFormat.SetLineAlignment(StringAlignmentNear); // 上对其 }else if(m_uVAlignment == VAlign_Middle) { strFormat.SetLineAlignment(StringAlignmentCenter); // 中间对齐 }else if(m_uVAlignment == VAlign_Bottom) { strFormat.SetLineAlignment(StringAlignmentFar); // 下对齐 } strFormat.SetTrimming(StringTrimmingEllipsisWord); // 以单词为单位去尾,略去部分使用省略号 //strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces); if(!m_bTextWrap) { strFormat.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行 } // 时间字段采用右对齐 StringFormat strFormatRight; strFormatRight.SetAlignment(StringAlignmentFar); // 右对齐 if(m_uVAlignment == VAlign_Top) { strFormatRight.SetLineAlignment(StringAlignmentNear); // 上对其 }else if(m_uVAlignment == VAlign_Middle) { strFormatRight.SetLineAlignment(StringAlignmentCenter); // 中间对齐 }else if(m_uVAlignment == VAlign_Bottom) { strFormatRight.SetLineAlignment(StringAlignmentFar); // 下对齐 } //strFormatRight.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces); if(!m_bTextWrap) { strFormatRight.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行 } if(m_vecRowInfo.size() > 0) { for(int i = m_nFirstViewRow; i <= m_nLastViewRow && i < (int)m_vecRowInfo.size(); i++) { ListRowInfo &rowInfo = m_vecRowInfo.at(i); SolidBrush solidBrushRow(rowInfo.clrText); // 行定义的颜色 int nXPos = 0; int nVI = i - m_nFirstViewRow; // 鼠标移动到行时候显示的背景颜色 if(m_nHoverRow == i) { SolidBrush brush(m_clrRowHover); graphics.FillRectangle(&brush, 0, nVI*m_nRowHeight, nWidth, m_nRowHeight); } // 画检查框 int nCheckImgY = 3; if((m_sizeCheckBox.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nCheckImgY = (m_nRowHeight - m_sizeCheckBox.cy) / 2 + 1; } if((rowInfo.nCheck != -1) && (m_pImageCheckBox != NULL)) { int nCheckImageIndex = ((m_nHoverRow == i) ? ((rowInfo.nCheck==1) ? 4 : 1) : ((rowInfo.nCheck==1) ? 2 : 0)); graphics.DrawImage(m_pImageCheckBox, Rect(nXPos, nVI*m_nRowHeight + nCheckImgY, m_sizeCheckBox.cx, m_sizeCheckBox.cy), nCheckImageIndex * m_sizeCheckBox.cx, 0, m_sizeCheckBox.cx, m_sizeCheckBox.cy, UnitPixel); rowInfo.rcCheck.SetRect(nXPos, i*m_nRowHeight + nCheckImgY, nXPos + m_sizeCheckBox.cx, i*m_nRowHeight + nCheckImgY + m_sizeCheckBox.cy); nXPos += (m_sizeCheckBox.cx + 3); } // 画行左边图片 int nImgY = 3; if(rowInfo.pImage != NULL) { if((rowInfo.sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - rowInfo.sizeImage.cy) / 2 + 1; } // 使用行数据指定的图片 graphics.DrawImage(rowInfo.pImage, Rect(nXPos, nVI*m_nRowHeight + nImgY, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy), 0, 0, rowInfo.sizeImage.cx, rowInfo.sizeImage.cy, UnitPixel); nXPos += (rowInfo.sizeImage.cx + 3); }else if((rowInfo.nImageIndex != -1) && (m_pImage != NULL)) { if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1; } // 使用索引图片 graphics.DrawImage(m_pImage, Rect(nXPos, nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy), rowInfo.nImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); nXPos += (m_sizeImage.cx + 3); } // 画行右边图片 int nRightImageWidth = 0; nImgY = 3; if(rowInfo.pRightImage != NULL) { if((rowInfo.sizeRightImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - rowInfo.sizeRightImage.cy) / 2 + 1; } // 使用行数据指定的图片 graphics.DrawImage(rowInfo.pRightImage, Rect(nWidth-rowInfo.sizeRightImage.cx-1, nVI*m_nRowHeight + nImgY, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy), 0, 0, rowInfo.sizeRightImage.cx, rowInfo.sizeRightImage.cy, UnitPixel); nRightImageWidth = rowInfo.sizeRightImage.cx + 1; }else if((rowInfo.nRightImageIndex != -1) && (m_pImage != NULL)) { if((m_sizeImage.cy*2 > m_nRowHeight) || (m_uVAlignment == VAlign_Middle)) { nImgY = (m_nRowHeight - m_sizeImage.cy) / 2 + 1; } // 使用索引图片 graphics.DrawImage(m_pImage, Rect(nWidth-m_sizeImage.cx-1, nVI*m_nRowHeight + nImgY, m_sizeImage.cx, m_sizeImage.cy), rowInfo.nRightImageIndex*m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); nRightImageWidth = m_sizeImage.cx + 1; } // 画内容 RectF rect((Gdiplus::REAL)nXPos, (Gdiplus::REAL)(nVI*m_nRowHeight + 1), (Gdiplus::REAL)(nWidth-20), (Gdiplus::REAL)(m_bSingleLine ? (m_nRowHeight - 2) : (m_nRowHeight / 2 - 2)) ); if(!rowInfo.strTime.IsEmpty()) { Size size = GetTextBounds(font, rowInfo.strTime); rect.Width -= (size.Width + 5); } // 链接文字 int nLinkWidth = 0; if(!rowInfo.strLink2.IsEmpty()) { Size sizeLink = GetTextBounds(font, strFormatRight, rowInfo.strLink2); nLinkWidth += (sizeLink.Width + 10); RectF rectLink((Gdiplus::REAL)(nWidth-nLinkWidth-nRightImageWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + (m_nRowHeight - sizeLink.Height)/2), (Gdiplus::REAL)(sizeLink.Width+8), (Gdiplus::REAL)sizeLink.Height); rowInfo.rcLink2.SetRect((int)rectLink.X,(int)rectLink.Y,(int)(rectLink.X+sizeLink.Width),(int)(rectLink.Y+rectLink.Height)); rowInfo.rcLink2.OffsetRect(0, m_nFirstViewRow*m_nRowHeight); if(((m_nHoverRow == i) || (m_nDownRow == i)) && (rowInfo.nHoverLink == 1)) { BSTR bsLink2 = rowInfo.strLink2.AllocSysString(); graphics.DrawString(bsLink2, (INT)wcslen(bsLink2), &font, rectLink, &strFormatRight, &solidBrushH); ::SysFreeString(bsLink2); }else { BSTR bsLink2 = rowInfo.strLink2.AllocSysString(); graphics.DrawString(bsLink2, (INT)wcslen(bsLink2), &font, rectLink, &strFormatRight, &solidBrush); ::SysFreeString(bsLink2); } } if(!rowInfo.strLink1.IsEmpty()) { Size sizeLink = GetTextBounds(font, strFormatRight, rowInfo.strLink1); nLinkWidth += (sizeLink.Width + 10); RectF rectLink((Gdiplus::REAL)(nWidth-nLinkWidth-nRightImageWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + (m_nRowHeight - sizeLink.Height)/2), (Gdiplus::REAL)(sizeLink.Width+8), (Gdiplus::REAL)sizeLink.Height); rowInfo.rcLink1.SetRect((int)rectLink.X,(int)rectLink.Y,(int)(rectLink.X+sizeLink.Width),(int)(rectLink.Y+rectLink.Height)); rowInfo.rcLink1.OffsetRect(0, m_nFirstViewRow*m_nRowHeight); if(((m_nHoverRow == i) || (m_nDownRow == i)) && (rowInfo.nHoverLink == 0)) { BSTR bsLink1 = rowInfo.strLink1.AllocSysString(); graphics.DrawString(bsLink1, (INT)wcslen(bsLink1), &font, rectLink, &strFormatRight, &solidBrushH); ::SysFreeString(bsLink1); }else { BSTR bsLink1 = rowInfo.strLink1.AllocSysString(); graphics.DrawString(bsLink1, (INT)wcslen(bsLink1), &font, rectLink, &strFormatRight, &solidBrush); ::SysFreeString(bsLink1); } } rect.Width -= nLinkWidth; // 计算是否需要显示tip rowInfo.bNeedTitleTip = rect.Width < GetTextBounds(font, rowInfo.strTitle).Width; rowInfo.bNeedContentTip = rect.Width < GetTextBounds(font, rowInfo.strContent).Width; Size sizeTime = GetTextBounds(font, strFormatRight, rowInfo.strTime); int nTimeWidth = sizeTime.Width + 10; RectF rectTime((Gdiplus::REAL)(nWidth-nRightImageWidth-2-nTimeWidth-nLinkWidth), (Gdiplus::REAL)(nVI*m_nRowHeight + 1), (Gdiplus::REAL)nTimeWidth, (Gdiplus::REAL)(m_bSingleLine ? m_nRowHeight : (m_nRowHeight / 2)) ); if(m_nHoverRow == i) { // 画标题行 BSTR bsTitle = rowInfo.strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, rect, &strFormat, &solidBrushH); ::SysFreeString(bsTitle); // 画时间 if(!rowInfo.strTime.IsEmpty()) { BSTR bsTime = rowInfo.strTime.AllocSysString(); graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, rectTime, &strFormatRight, &solidBrushH); ::SysFreeString(bsTime); } // 画内容行 if(!m_bSingleLine) { rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2); rect.Width = (Gdiplus::REAL)nWidth-20; rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4; BSTR bsContent = rowInfo.strContent.AllocSysString(); graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, rect, &strFormat, &solidBrushH); ::SysFreeString(bsContent); } }else if(m_nDownRow == i) { // 画标题行 BSTR bsTitle = rowInfo.strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, rect, &strFormat, &solidBrushD); ::SysFreeString(bsTitle); // 画时间 if(!rowInfo.strTime.IsEmpty()) { BSTR bsTime = rowInfo.strTime.AllocSysString(); graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, rectTime, &strFormatRight, &solidBrushD); ::SysFreeString(bsTime); } // 画内容行 if(!m_bSingleLine) { rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2); rect.Width = (Gdiplus::REAL)nWidth-20; rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4; BSTR bsContent = rowInfo.strContent.AllocSysString(); graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, rect, &strFormat, &solidBrushD); ::SysFreeString(bsContent); } }else { // 画标题行 BSTR bsTitle = rowInfo.strTitle.AllocSysString(); graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &fontTitle, rect, &strFormat, rowInfo.bRowColor ? &solidBrushRow : &solidBrushT); ::SysFreeString(bsTitle); // 画时间 if(!rowInfo.strTime.IsEmpty()) { BSTR bsTime = rowInfo.strTime.AllocSysString(); graphics.DrawString(bsTime, (INT)wcslen(bsTime), &font, rectTime, &strFormatRight, rowInfo.bRowColor ? &solidBrushRow : &solidBrush); ::SysFreeString(bsTime); } // 画内容行 if(!m_bSingleLine) { rect.Offset(0, (Gdiplus::REAL)m_nRowHeight / 2 + 2); rect.Width = (Gdiplus::REAL)nWidth-20; rect.Height = (Gdiplus::REAL)m_nRowHeight / 2 - 4; BSTR bsContent = rowInfo.strContent.AllocSysString(); graphics.DrawString(bsContent, (INT)wcslen(bsContent), &font, rect, &strFormat, rowInfo.bRowColor ? &solidBrushRow : &solidBrush); ::SysFreeString(bsContent); } } // 画分隔线(采用拉伸模式) if(m_pImageSeperator != NULL) { // 使用拉伸模式属性画图 graphics.DrawImage(m_pImageSeperator, RectF(0, (Gdiplus::REAL)((nVI+1)*m_nRowHeight), (Gdiplus::REAL)(nWidth-2), (Gdiplus::REAL)m_sizeSeperator.cy), 0, 0, (Gdiplus::REAL)m_sizeSeperator.cx, (Gdiplus::REAL)m_sizeSeperator.cy, UnitPixel); // 使用平铺方式填充矩形(暂不使用这种方式) //TextureBrush tileBrush(m_pImageSeperator, WrapModeTile); //graphics.FillRectangle(&tileBrush, RectF(0, (nVI+1)*m_nRowHeight, nWidth-2, m_sizeSeperator.cy)); }else { // 未指定图片,则画矩形 graphics.FillRectangle(&solidBrushS, 0, (nVI+1)*m_nRowHeight, nWidth-2, 1); } } } } // 输出到界面DC,使用与的方式合并背景 dc.BitBlt(m_rc.left,m_rc.top, nWidth, m_rc.Height(), &m_memDC, 0, nYViewPos, SRCCOPY);//SRCAND); }
void CIntelBottomView::OnDraw(CDC* dc) { CBotEDoc* pDoc = resources::pDoc; AssertBotE(pDoc); if (!pDoc->m_bDataReceived) return; CMajor* pMajor = m_pPlayersRace; AssertBotE(pMajor); if (!pMajor) return; // TODO: add draw code here // Doublebuffering wird initialisiert CMyMemDC pDC(dc); CRect client; GetClientRect(&client); // Graphicsobjekt, in welches gezeichnet wird anlegen Graphics g(pDC->GetSafeHdc()); g.Clear(static_cast<Gdiplus::ARGB>(Color::Black)); g.SetSmoothingMode(SmoothingModeHighSpeed); g.SetInterpolationMode(InterpolationModeLowQuality); g.SetPixelOffsetMode(PixelOffsetModeHighSpeed); g.SetCompositingQuality(CompositingQualityHighSpeed); g.ScaleTransform((REAL)client.Width() / (REAL)m_TotalSize.cx, (REAL)client.Height() / (REAL)m_TotalSize.cy); CString fontName = ""; Gdiplus::REAL fontSize = 0.0; StringFormat fontFormat; SolidBrush fontBrush(static_cast<Gdiplus::ARGB>(Color::White)); Color color; color.SetFromCOLORREF(pMajor->GetDesign()->m_clrGalaxySectorText); fontBrush.SetColor(color); Bitmap* graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Backgrounds\\" + pMajor->GetPrefix() + "diplomacyV3.boj"); // Grafik zeichnen if (graphic) { g.DrawImage(graphic, 0, 0, 1075, 249); graphic = NULL; } // Nur in bestimmten Submenüs werden in der View3 Berichte angezeigt BYTE curIntelSubMenu = resources::pMainFrame->GetSubMenu(RUNTIME_CLASS(CIntelMenuView)); if (curIntelSubMenu == 4 || curIntelSubMenu == 5) { CRect r; r.SetRect(0,0,m_TotalSize.cx,m_TotalSize.cy); short n = pMajor->GetEmpire()->GetIntelligence()->GetIntelReports()->GetActiveReport(); if (n != -1) { CFontLoader::CreateGDIFont(pMajor, 4, fontName, fontSize); fontFormat.SetAlignment(StringAlignmentNear); fontFormat.SetLineAlignment(StringAlignmentNear); fontFormat.SetFormatFlags(StringFormatFlagsNoWrap); CIntelObject* report = pMajor->GetEmpire()->GetIntelligence()->GetIntelReports()->GetReport(n); CString s; if (report->GetIsSpy()) s = CLoc::GetString("SPY"); else s = CLoc::GetString("SABOTAGE"); g.DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 40, r.right-100, r.bottom-20), &fontFormat, &fontBrush); CFontLoader::CreateGDIFont(pMajor, 2, fontName, fontSize); fontBrush.SetColor(Color(200,200,250)); fontFormat.SetFormatFlags(!StringFormatFlagsNoWrap); if (report->GetOwner() == pMajor->GetRaceID()) s = *report->GetOwnerDesc(); else s = *report->GetEnemyDesc(); g.DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 100, r.right-250, r.bottom-20), &fontFormat, &fontBrush); } } g.ReleaseHDC(pDC->GetSafeHdc()); }
void CLMenu::DrawItem(CLMenuItem *item) { CRect r = ItemRect(item); item->dib->Resize(r.Width(), r.Height()); if(!item->dib->Ready()) { return; } Graphics g(item->dib->bmp); g.SetSmoothingMode(SmoothingModeNone); g.SetCompositingMode(CompositingModeSourceCopy); RectF rf(0, 0, (REAL)item->dib->Width(), (REAL)item->dib->Height()); SolidBrush brush(Color(255 * BCKG_OPACITY / 100, 0x10, 0x10, 0x10)); g.FillRectangle(&brush, rf); g.SetCompositingMode(CompositingModeSourceOver); if(item->selected) { //LinearGradientBrush brush(rf, 0xff6fa6de, 0xff1e6cbb, LinearGradientModeVertical); //g.FillRectangle(&brush, rf); RectF rx = rf; rx.Height /= 2; //rx.X++; //rx.Width -= 2; LinearGradientBrush brush(rx, 0xff5b9de1, 0xff3d7ebf, LinearGradientModeVertical); g.FillRectangle(&brush, rx); rx.Y += rx.Height; brush.SetLinearColors(0xff3076bc, 0xff4988c8); g.FillRectangle(&brush, rx); Pen pen(0xff3d7ebf); g.DrawLine(&pen, rx.X /*+ 1*/, rx.Y, rx.X + rx.Width /*- 1*/, rx.Y); } g.SetSmoothingMode(SmoothingModeAntiAlias); if(item->isLine) { Pen pen(0xff909090); g.DrawLine(&pen, rf.X + 2, rf.Y + rf.Height / 2, rf.X + rf.Width - 3, rf.Y + rf.Height / 2); } else { rf.X += 4; rf.Width -= 14; if(item->icon->Ready()) { RectF ri = rf; ri.Width = rf.Height * 0.9f; ri.Height = ri.Width; ri.Y += (rf.Height - ri.Height) / 2; rf.X += rf.Height; rf.Width -= rf.Height; float k = min(ri.Width / item->icon->Width(), ri.Height / item->icon->Height()); g.SetInterpolationMode(InterpolationModeHighQualityBicubic); ri.X += (ri.Width - item->icon->Width() * k) / 2; ri.Y += (ri.Height - item->icon->Height() * k) / 2; ri.Width = item->icon->Width() * k; ri.Height = item->icon->Height() * k; g.DrawImage(item->icon->bmp, ri); } RectF rc = rf; rc.Width = rf.Height * 0.42f; rc.Height = rc.Width; rc.Y += (rf.Height - rc.Height) / 2; if(item->checkbox) { if(item->checked) { Pen pen(0xffffffff); SolidBrush brush(0xffffffff); if(!item->enabled) { pen.SetColor(0xffb0b0b0); brush.SetColor(0xffb0b0b0); } GraphicsPath *path = new GraphicsPath(); path->AddLine(rc.X + rc.Width * 0.4f, rc.Y + rc.Height, rc.X + rc.Width * 0.9f, rc.Y); path->AddLine(rc.X + rc.Width * 0.9f, rc.Y, rc.X + rc.Width * 0.4f, rc.Y + rc.Height * 0.8f); path->AddLine(rc.X + rc.Width * 0.4f, rc.Y + rc.Height * 0.8f, rc.X, rc.Y + rc.Height * 0.6f); path->CloseFigure(); g.FillPath(&brush, path); g.DrawPath(&pen, path); delete path; } } if(!item->icon->Ready()) { rf.X += (rc.Height + 2); rf.Width -= (rc.Height + 2); } SolidBrush brush(0xff000000); Font font(L"Arial", FONT_SIZE); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentNear); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); //rf.Y++; //g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rf, stringFormat, &brush); brush.SetColor(0xffffffff); if(!item->enabled) { brush.SetColor(0xffb0b0b0); } //rf.Y--; g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rf, stringFormat, &brush); if(item->menu->ItemCount(TRUE)) { GraphicsPath *path = new GraphicsPath(); path->AddLine((REAL)(item->dib->Width() - 12), (REAL)(item->dib->Height() * 0.33), (REAL)(item->dib->Width() - 6), (REAL)(item->dib->Height() * 0.5)); path->AddLine((REAL)(item->dib->Width() - 6), (REAL)(item->dib->Height() * 0.5), (REAL)(item->dib->Width() - 12), (REAL)(item->dib->Height() * 0.67)); path->CloseFigure(); g.FillPath(&brush, path); delete path; } delete stringFormat; } }
void CTabsControl::DrawItem(CTabControl *item, Gdiplus::Graphics &g) { CRect rect = ItemRect(item); g.ResetTransform(); g.TranslateTransform((REAL)rect.left, (REAL)rect.top); RectF rf(0.0f, 0.0f, (REAL)rect.Width(), (REAL)rect.Height()); RectF rx; if(item->selected) { #define shadowb 10 CDIB tmp; tmp.Resize(rect.Width() + shadowb * 2, rect.Height() + shadowb * 2); if(tmp.Ready()) { Graphics gt(tmp.bmp); RectF rx(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height()); GraphicsPath *path = new GraphicsPath(); path->AddLine(rx.X + shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb); path->AddLine(rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2, rx.Y); path->AddLine(rx.X + rx.Width - 2, rx.Y, rx.X + rx.Width, rx.Y + rx.Height); path->AddLine(rx.X + rx.Width, rx.Y + rx.Height, rx.X, rx.Y + rx.Height); path->AddLine(rx.X, rx.Y, rx.X + shadowb, rx.Y + rx.Height - shadowb); path->CloseFigure(); SolidBrush brush(0xff000000); gt.FillPath(&brush, path); tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadowb); g.DrawImage(tmp.bmp, rf, shadowb, shadowb, rf.Width, rf.Height, UnitPixel); delete path; } } Font font(L"Arial", item->selected ? 8.0f : 8.0f); StringFormat *stringFormat = new StringFormat(); stringFormat->SetAlignment(StringAlignmentCenter); stringFormat->SetLineAlignment(StringAlignmentCenter); stringFormat->SetTrimming(StringTrimmingEllipsisCharacter); stringFormat->SetFormatFlags(StringFormatFlagsLineLimit); if(item->icon->Ready()) { g.SetInterpolationMode(InterpolationModeBicubic); rx = rf; rx.Y += 6; rx.Height -= (20 + rx.Y); rx.Width = rx.Height; rx.X += (rf.Width - rx.Width) / 2; if(item->selected) { rx.Y++; #define shadow 5 CDIB tmp; tmp.Resize(item->icon->Width(), item->icon->Height()); if(tmp.Ready()) { tmp.Draw(CRect(shadow, shadow, item->icon->Width() - shadow, item->icon->Height() - shadow), item->icon->Rect(), item->icon); DIB_ARGB *p = tmp.scan0; int size = tmp.Width() * tmp.Height(); for(int i = 0; i < size; i++, p++) { p->r = 0; p->g = 0; p->b = 0; } tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadow); g.DrawImage(tmp.bmp, RectF(rx.X, rx.Y + shadow, rx.Width, rx.Height)); } tmp.Assign(item->icon); /*if(tmp.Ready()) { DIB_ARGB *p = tmp.scan0; int size = tmp.Width() * tmp.Height(); for(int i = 0; i < size; i++, p++) { p->r = 0x6f; p->g = 0xa6; p->b = 0xde; } }*/ g.DrawImage(tmp.bmp, rx); } else { g.DrawImage(item->icon->bmp, rx); } } SolidBrush brush(0xff000000); rx = rf; rx.Height = 20; rx.Y = rf.Height - rx.Height; rx.Y++; g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush); brush.SetColor(item->selected && false ? 0xff6fa6de : 0xfff0f0f0); rx.Y--; g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush); delete stringFormat; //POSITION p = items.Find(item); //items.GetNext(p); //if(p) { RectF rx = rf; rx.X += rx.Width - 1; rx.Width = 1; LinearGradientBrush brush(rx, Color(140, 0x69, 0x69, 0x69), Color(0x69, 0x69, 0x69), LinearGradientModeVertical); g.FillRectangle(&brush, rx); } }
void CDiplomacyBottomView::OnDraw(CDC* dc) { CBotEDoc* pDoc = resources::pDoc; AssertBotE(pDoc); if (!pDoc->m_bDataReceived) return; CMajor* pMajor = m_pPlayersRace; AssertBotE(pMajor); if (!pMajor) return; // TODO: add draw code here // Doublebuffering wird initialisiert CMyMemDC pDC(dc); CRect client; GetClientRect(&client); // Graphicsobjekt, in welches gezeichnet wird anlegen Graphics g(pDC->GetSafeHdc()); g.Clear(static_cast<Gdiplus::ARGB>(Color::Black)); g.SetSmoothingMode(SmoothingModeHighSpeed); g.SetInterpolationMode(InterpolationModeLowQuality); g.SetPixelOffsetMode(PixelOffsetModeHighSpeed); g.SetCompositingQuality(CompositingQualityHighSpeed); g.ScaleTransform((REAL)client.Width() / (REAL)m_TotalSize.cx, (REAL)client.Height() / (REAL)m_TotalSize.cy); CString fontName = ""; Gdiplus::REAL fontSize = 0.0; StringFormat fontFormat; SolidBrush fontBrush(static_cast<Gdiplus::ARGB>(Color::White)); // Soll was über die Diplomatie angezeigt werden CRect rect; rect.SetRect(0,0,m_TotalSize.cx,m_TotalSize.cy); CString sPrefix = pMajor->GetPrefix(); Color color; color.SetFromCOLORREF(pMajor->GetDesign()->m_clrGalaxySectorText); fontBrush.SetColor(color); Bitmap* graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Backgrounds\\" + sPrefix + "diplomacyV3.boj"); // Grafik zeichnen if (graphic) { g.DrawImage(graphic, 0, 0, 1075, 249); graphic = NULL; } CFontLoader::CreateGDIFont(pMajor, 4, fontName, fontSize); fontFormat.SetAlignment(StringAlignmentNear); fontFormat.SetLineAlignment(StringAlignmentNear); fontFormat.SetFormatFlags(StringFormatFlagsNoWrap); g.DrawString(CComBSTR(m_strHeadLine), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 30, rect.right, rect.bottom), &fontFormat, &fontBrush); if (m_strText.IsEmpty()) g.DrawString(CComBSTR(CLoc::GetString("NO_DIPLOMATIC_NEWS")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 30, rect.right, rect.bottom), &fontFormat, &fontBrush); m_strHeadLine = ""; CFontLoader::CreateGDIFont(pMajor, 2, fontName, fontSize); fontBrush.SetColor(Color(200,200,250)); fontFormat.SetFormatFlags(!StringFormatFlagsNoWrap); g.DrawString(CComBSTR(m_strText), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 100, rect.right-250, rect.bottom), &fontFormat, &fontBrush); g.ReleaseHDC(pDC->GetSafeHdc()); }
/* ** Draws the string or calculates it's size ** */ bool CMeterString::DrawString(Graphics& graphics, RectF* rect) { if (m_Font == NULL) return false; LPCWSTR string = m_String.c_str(); int stringLen = (int)m_String.length(); StringFormat stringFormat; if (m_AntiAlias) { graphics.SetTextRenderingHint(TextRenderingHintAntiAlias); } else { graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit); } switch (m_Align) { case ALIGN_CENTERCENTER: stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); break; case ALIGN_RIGHTCENTER: stringFormat.SetAlignment(StringAlignmentFar); stringFormat.SetLineAlignment(StringAlignmentCenter); break; case ALIGN_LEFTCENTER: stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentCenter); break; case ALIGN_CENTERBOTTOM: stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentFar); break; case ALIGN_RIGHTBOTTOM: stringFormat.SetAlignment(StringAlignmentFar); stringFormat.SetLineAlignment(StringAlignmentFar); break; case ALIGN_LEFTBOTTOM: stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentFar); break; case ALIGN_CENTER: // Same as CenterTop stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentNear); break; case ALIGN_RIGHT: // Same as RightTop stringFormat.SetAlignment(StringAlignmentFar); stringFormat.SetLineAlignment(StringAlignmentNear); break; case ALIGN_LEFT: // Same as LeftTop stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); break; } if (m_ClipString) { stringFormat.SetTrimming(StringTrimmingEllipsisCharacter); } else { stringFormat.SetTrimming(StringTrimmingNone); stringFormat.SetFormatFlags(StringFormatFlagsNoClip | StringFormatFlagsNoWrap); } CharacterRange range(0, stringLen); stringFormat.SetMeasurableCharacterRanges(1, &range); REAL x = (REAL)GetX(); REAL y = (REAL)GetY(); if (rect) { PointF pos(x, y); graphics.MeasureString(string, stringLen, m_Font, pos, &stringFormat, rect); } else { RectF rcDest(x, y, (REAL)m_W, (REAL)m_H); m_Rect = rcDest; if (m_Angle != 0.0f) { graphics.TranslateTransform((Gdiplus::REAL)CMeter::GetX(), y); graphics.RotateTransform(CONVERT_TO_DEGREES(m_Angle)); graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y); } if (m_Effect != EFFECT_NONE) { SolidBrush solidBrush(m_EffectColor); RectF rcEffect(rcDest); if (m_Effect == EFFECT_SHADOW) { rcEffect.Offset(1, 1); graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush); } else //if (m_Effect == EFFECT_BORDER) { rcEffect.Offset(0, 1); graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush); rcEffect.Offset(1, -1); graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush); rcEffect.Offset(-1, -1); graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush); rcEffect.Offset(-1, 1); graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush); } } SolidBrush solidBrush(m_Color); graphics.DrawString(string, stringLen, m_Font, rcDest, &stringFormat, &solidBrush); if (m_Angle != 0.0f) { graphics.ResetTransform(); } } return true; }
TextDisplay::DisplayTexture TextDisplay::createTexture(const char* text) { DisplayTexture displayTex; size_t textLen = strlen(text); displayTex.text = new char[textLen+1]; strcpy_s(displayTex.text, textLen+1, text); Bitmap* bitmap; Gdiplus::Font* font; { pfc::stringcvt::string_wide_from_utf8 w_text(text); StringFormat strFormat; strFormat.SetAlignment(StringAlignmentCenter); strFormat.SetTrimming(StringTrimmingNone); strFormat.SetFormatFlags(StringFormatFlagsNoFitBlackBox | StringFormatFlagsNoWrap | StringFormatFlagsNoClip); RectF stringSize(0, 0, 1024, 128); { // calculate Text Size Bitmap calcBitmap(5, 5, PixelFormat32bppARGB); Graphics graphics(&calcBitmap); HDC fontDC = graphics.GetHDC(); font = new Gdiplus::Font(fontDC, &(cfgTitleFont.get_value())); graphics.ReleaseHDC(fontDC); if (!font->IsAvailable()){ delete font; font = new Gdiplus::Font(L"Verdana", 8.0f); } graphics.MeasureString(w_text, -1, font, PointF(), &stringSize); } // round to multiples of two, so centering is consistent stringSize.Width = ceil(stringSize.Width / 2.0f) * 2; stringSize.Height = ceil(stringSize.Height); displayTex.texWidth = displayTex.textWidth = (int)stringSize.Width; displayTex.texHeight = displayTex.textHeight = (int)stringSize.Height; // Make the texture size a power of two displayTex.texWidth = 1; while (displayTex.texWidth < displayTex.textWidth) displayTex.texWidth = displayTex.texWidth << 1; displayTex.texHeight = 1; while (displayTex.texHeight < displayTex.textHeight) displayTex.texHeight = displayTex.texHeight << 1; bitmap = new Bitmap(displayTex.texWidth, displayTex.texHeight, PixelFormat32bppARGB); Graphics drawer(bitmap); drawer.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit); Color textColor(255, 255, 255); textColor.SetFromCOLORREF(cfgTitleColor); SolidBrush textBrush(textColor); displayTex.color = cfgTitleColor; drawer.DrawString(w_text, -1, font, stringSize, &strFormat, &textBrush); } { bitmap->RotateFlip(RotateNoneFlipY); Rect rc(0,0,bitmap->GetWidth(),bitmap->GetHeight()); BitmapData bitmapData; bitmap->LockBits(&rc,ImageLockModeRead,PixelFormat32bppARGB,&bitmapData); glGenTextures(1,&displayTex.glTex); glBindTexture(GL_TEXTURE_2D, displayTex.glTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); void* data = bitmapData.Scan0; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, displayTex.texWidth, displayTex.texHeight, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE,data); bitmap->UnlockBits(&bitmapData); } delete bitmap; delete font; return displayTex; }
///////////////////////////////////////////////////////////////////////////////////////// // Hier die Funktion zum Zeichnen des Schiffsdesignmenüs ///////////////////////////////////////////////////////////////////////////////////////// void CShipDesignMenuView::DrawShipDesignMenue(Graphics* g) { CBotEDoc* pDoc = resources::pDoc; ASSERT(pDoc); CMajor* pMajor = m_pPlayersRace; ASSERT(pDoc); if (!pMajor) return; CString fontName = ""; Gdiplus::REAL fontSize = 0.0; // Rassenspezifische Schriftart auswählen CFontLoader::CreateGDIFont(pMajor, 2, fontName, fontSize); // Schriftfarbe wählen Gdiplus::Color normalColor; CFontLoader::GetGDIFontColor(pMajor, 3, normalColor); StringFormat fontFormat; fontFormat.SetAlignment(StringAlignmentNear); fontFormat.SetLineAlignment(StringAlignmentCenter); fontFormat.SetFormatFlags(StringFormatFlagsNoWrap); Color penColor; penColor.SetFromCOLORREF(pMajor->GetDesign()->m_clrListMarkPenColor); Color markColor; markColor.SetFromCOLORREF(pMajor->GetDesign()->m_clrListMarkTextColor); if (bg_designmenu) g->DrawImage(bg_designmenu, 0, 0, 1075, 750); SolidBrush fontBrush(normalColor); // Links im Bild die veränderbaren Schiffklassen zeichnen (bis jetzt darf man keine Stationen verändern, // weil deren Baukosten allein von den Industriekosten berechnet werden. Diese aber nicht steigen wenn // man die Hülle oder Schilde verbessert. Somit könnte man bessere Stationen für den gleichen Preis bauen. // Schiffsinfoarray durchgehen und nach zum Imperium gehörende baubare Schiffe suchen short j = 0; short counter = m_iClickedOnShip - 23 + m_iOldClickedOnShip; short oldClickedShip = m_iClickedOnShip; BYTE researchLevels[6] = { pMajor->GetEmpire()->GetResearch()->GetBioTech(), pMajor->GetEmpire()->GetResearch()->GetEnergyTech(), pMajor->GetEmpire()->GetResearch()->GetCompTech(), pMajor->GetEmpire()->GetResearch()->GetPropulsionTech(), pMajor->GetEmpire()->GetResearch()->GetConstructionTech(), pMajor->GetEmpire()->GetResearch()->GetWeaponTech() }; m_pShownShip = NULL; m_nSizeOfShipDesignList = 0; // Es gehen nur 21 Einträge auf die Seite, deshalb muss abgebrochen werden for (int i = 0; i < pDoc->m_ShipInfoArray.GetSize(); i++) if (pDoc->m_ShipInfoArray.GetAt(i).GetRace() == pMajor->GetRaceShipNumber()) if (!pDoc->m_ShipInfoArray.GetAt(i).IsStation()) if (pDoc->m_ShipInfoArray.GetAt(i).IsThisShipBuildableNow(researchLevels)) { // wurde dieses Schiff durch kein anderes jetzt baubares Schiff schon obsolet? BOOLEAN foundObsolet = FALSE; for (int m = 0; m < pDoc->m_ShipInfoArray.GetSize(); m++) if (pDoc->m_ShipInfoArray.GetAt(m).GetRace() == pMajor->GetRaceShipNumber()) if (pDoc->m_ShipInfoArray.GetAt(m).GetObsoleteShipClass() == pDoc->m_ShipInfoArray.GetAt(i).GetShipClass()) if (pDoc->m_ShipInfoArray.GetAt(m).IsThisShipBuildableNow(researchLevels)) { foundObsolet = TRUE; break; } if (foundObsolet) continue; m_nSizeOfShipDesignList++; if (counter > 0) { m_iClickedOnShip--; counter--; continue; } if (j < 24) { fontBrush.SetColor(normalColor); // Wenn wir ein Schiff gefunden haben, dann zeichnen wir dieses in die Liste (max. 21) // Wenn wir das Schiff markiert haben, dann die Markierung zeichnen, haben wir kein spezielles Schiff // angeklickt, so wird das 1. Schiff in der Liste markiert if (j == m_iClickedOnShip || m_iClickedOnShip == -1) { fontBrush.SetColor(markColor); // Wenn wir nix angeklickt haben und nur das erste Schiff markiert war, dann automatisch m_iClickedOnShip = j; if (oldClickedShip == -1) oldClickedShip = j; m_pShownShip = &pDoc->m_ShipInfoArray.GetAt(i); // Markierung worauf wir geklickt haben g->FillRectangle(&SolidBrush(Color(50,200,200,200)), RectF(15,120+j*25,183,25)); g->DrawLine(&Gdiplus::Pen(penColor), 15, 120+j*25, 198, 120+j*25); g->DrawLine(&Gdiplus::Pen(penColor), 15, 145+j*25, 198, 145+j*25); // Infos in unteren Schiffsdesignansicht aktualisieren if (CShipDesignBottomView* pView = dynamic_cast<CShipDesignBottomView*>(resources::pMainFrame->GetView(RUNTIME_CLASS(CShipDesignBottomView)))) { if (pView->GetCurrentShipInfo() != i) { pView->SetCurrentShipInfo(i); pView->Invalidate(FALSE); } } } CString s = pDoc->m_ShipInfoArray.GetAt(i).GetShipClass(); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(25, 120 + j * 25, 175, 25), &fontFormat, &fontBrush); j++; } } m_iClickedOnShip = oldClickedShip; // Hier jetzt Informationen zum angeklickten Schiff anzeigen if (m_pShownShip) { // Bild des Schiffes zeichnen CString s; s.Format("Ships\\%s.bop",m_pShownShip->GetShipClass()); Bitmap* graphic = pDoc->GetGraphicPool()->GetGDIGraphic(s); if (graphic == NULL) graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Ships\\ImageMissing.bop"); if (graphic) { g->DrawImage(graphic, 388, 90, 200, 150); graphic = NULL; } // allgemeine Schiffsinformationen anzeigen m_pShownShip->DrawShipInformation(g, CRect(220,250,740,440), &Gdiplus::Font(CComBSTR(fontName), fontSize), normalColor, markColor, pMajor->GetEmpire()->GetResearch()); // Baukosten des Schiffes anzeigen fontBrush.SetColor(markColor); fontFormat.SetAlignment(StringAlignmentCenter); fontFormat.SetLineAlignment(StringAlignmentNear); g->DrawString(CComBSTR(CLoc::GetString("BUILDCOSTS")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(190,440,580,25), &fontFormat, &fontBrush); fontBrush.SetColor(normalColor); s.Format("%s: %d %s: %d %s: %d",CLoc::GetString("INDUSTRY"),m_pShownShip->GetNeededIndustry(), CLoc::GetString("TITAN"),m_pShownShip->GetNeededTitan(), CLoc::GetString("DEUTERIUM"),m_pShownShip->GetNeededDeuterium()); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(190,465,580,25), &fontFormat, &fontBrush); s.Format("%s: %d %s: %d %s: %d %s: %d",CLoc::GetString("DURANIUM"),m_pShownShip->GetNeededDuranium(), CLoc::GetString("CRYSTAL"),m_pShownShip->GetNeededCrystal(), CLoc::GetString("IRIDIUM"),m_pShownShip->GetNeededIridium(), CLoc::GetString("DERITIUM"),m_pShownShip->GetNeededDeritium()); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(190,490,580,25), &fontFormat, &fontBrush); // Die Buttons zur Eigenschaftsänderung in der Rechten Seite der Ansicht anzeigen // zuerst überprüfen wir die Beamwaffen, wir können den Typ der Beamwaffe verändern, wenn wir mindst. ein anderes // Schiff des Imperiums finden, welches DIESE Beamwaffe mit einem höheren Typ oder einem niedrigeren Typ besitzt graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Other\\" + pMajor->GetPrefix() + "button_small.bop"); Color btnColor; CFontLoader::GetGDIFontColor(pMajor, 1, btnColor); SolidBrush btnBrush(btnColor); fontFormat.SetAlignment(StringAlignmentCenter); fontFormat.SetLineAlignment(StringAlignmentCenter); // Nach Beamwaffen suchen if (m_pShownShip->GetBeamWeapons()->GetSize() > m_iBeamWeaponNumber) { // gibt es schon von dieser Beamwaffe hier auf dem Schiff einen höheren Typ? USHORT maxTyp = pMajor->GetWeaponObserver()->GetMaxBeamType(m_pShownShip->GetBeamWeapons()->GetAt(m_iBeamWeaponNumber).GetBeamName()); if (maxTyp > m_pShownShip->GetBeamWeapons()->GetAt(m_iBeamWeaponNumber).GetBeamType()) { // Dann können wir den Typ unserer Beamwaffe(n) verbessern if (graphic) g->DrawImage(graphic, 930, 120, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_STRONGER")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(930,120,120,30), &fontFormat, &btnBrush); m_bFoundBetterBeam = TRUE; } // Wenn wir einen größeren Typ als Typ 1 haben, dann können wir diesen verringern if (m_pShownShip->GetBeamWeapons()->GetAt(m_iBeamWeaponNumber).GetBeamType() > 1) { // Dann können wir den Typ unserer Beamwaffe(n) verkleinern if (graphic) g->DrawImage(graphic, 800, 120, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_WEAKER")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(800,120,120,30), &fontFormat, &btnBrush); m_bFoundWorseBeam = TRUE; } // Typ und Name der Beamwaffe zeichnen fontBrush.SetColor(normalColor); s.Format("%s %d %s",CLoc::GetString("TYPE"),m_pShownShip->GetBeamWeapons()->GetAt(m_iBeamWeaponNumber).GetBeamType(),m_pShownShip->GetBeamWeapons()->GetAt(m_iBeamWeaponNumber).GetBeamName()); fontFormat.SetTrimming(StringTrimmingEllipsisCharacter); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(845,80,160,25), &fontFormat, &fontBrush); fontFormat.SetTrimming(StringTrimmingNone); } // Nach anderer Torpedowaffe suchen if (m_pShownShip->GetTorpedoWeapons()->GetSize() > m_iTorpedoWeaponNumber) { // den aktuellen Torpedotyp holen BYTE currentTorpType = m_pShownShip->GetTorpedoWeapons()->GetAt(m_iTorpedoWeaponNumber).GetTorpedoType(); // Torpedoname zeichnen fontBrush.SetColor(normalColor); s.Format("%s (%d°)",m_pShownShip->GetTorpedoWeapons()->GetAt(m_iTorpedoWeaponNumber).GetTupeName(), m_pShownShip->GetTorpedoWeapons()->GetAt(m_iTorpedoWeaponNumber).GetFirearc()->GetAngle()); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(775,170,300,25), &fontFormat, &fontBrush); s.Format("%s (%d)", CTorpedoInfo::GetName(currentTorpType), CTorpedoInfo::GetPower(currentTorpType)); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(775,195,300,25), &fontFormat, &fontBrush); if (graphic) g->DrawImage(graphic, 800, 230, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_LAUNCHER")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(800,230,120,30), &fontFormat, &btnBrush); if (graphic) g->DrawImage(graphic, 930, 230, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_TORPEDO")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(930,230,120,30), &fontFormat, &btnBrush); } // hier Möglichkeit anderes Hüllenmaterial anzubringen eingebaut CString material; switch (m_pShownShip->GetHull()->GetHullMaterial()) { case TITAN: material = CLoc::GetString("TITAN");; break; case DURANIUM: material = CLoc::GetString("DURANIUM");; break; case IRIDIUM: material = CLoc::GetString("IRIDIUM");; break; default: material = ""; } BOOLEAN bDoubleHull = m_pShownShip->GetHull()->GetDoubleHull(); if (bDoubleHull == TRUE) s.Format("%s%s",material, CLoc::GetString("DOUBLE_HULL_ARMOUR")); else s.Format("%s%s",material, CLoc::GetString("HULL_ARMOR")); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(775,380,300,30), &fontFormat, &fontBrush); // Hier kann man den Schildtyp ändern // zuerst Anzeige der jetzt aktuellen Schilde. Beim Romulaner eine schwarze Schriftart wählen. Wenn dies // später auch bei der Föd heller unterlegt ist kann auch dort eine schwarze Schriftfarbe gewählt werden. s.Format("%s %d %s",CLoc::GetString("TYPE"),m_pShownShip->GetShield()->GetShieldType(),CLoc::GetString("SHIELDS")); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(775,490,300,30), &fontFormat, &fontBrush); // Ab jetzt die Buttons zum Ändern der jeweiligen Komponenten if (graphic) g->DrawImage(graphic, 800, 420, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_MATERIAL")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(800,420,120,30), &fontFormat, &btnBrush); // wenn eine Doppelhülle draus gemacht werden soll dann darf die Manövrierbarkeit nicht schon "keine" oder nur 1 sein // wenn eine Einzelhülle draus gemacht werden soll, dann darf die Manövrierbarkeit nicht schon phänomenal sein if ((bDoubleHull == FALSE && m_pShownShip->GetManeuverability() > 1) || (bDoubleHull == TRUE && m_pShownShip->GetManeuverability() < 9)) { if (graphic) g->DrawImage(graphic, 930, 420, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_HULLTYPE")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(930,420,120,30), &fontFormat, &btnBrush); } // Schildtyp schwächer Button einblenden if (m_pShownShip->GetShield()->GetShieldType() > 0) { if (graphic) g->DrawImage(graphic, 800, 540, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_WEAKER")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(800,540,120,30), &fontFormat, &btnBrush); } // Schildtyp stärker Button einblenden if (m_pShownShip->GetShield()->GetShieldType() < pMajor->GetWeaponObserver()->GetMaxShieldType()) { if (graphic) g->DrawImage(graphic, 930, 540, 120, 30); g->DrawString(CComBSTR(CLoc::GetString("BTN_STRONGER")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(930,540,120,30), &fontFormat, &btnBrush); } } // Wenn das Schiff in irgendeinem unserer Systeme gebaut wird, dann großen Text ausgeben, in welchem System das Schiff // gerade gebaut wird CString systemName = CheckIfShipIsBuilding(m_pShownShip); if (!systemName.IsEmpty()) { COverlayBanner *banner = new COverlayBanner(CPoint(200,300), CSize(580, 200), CLoc::GetString("NO_CHANGE_POSSIBLE", FALSE, systemName), RGB(220,0,0)); banner->Draw(g, &Gdiplus::Font(CComBSTR(fontName), fontSize)); delete banner; } // draw Button DisplayAllShips Bitmap* btnDisplayAllShips = pDoc->GetGraphicPool()->GetGDIGraphic("Other\\" + pMajor->GetPrefix() + "button_small.bop");//All-Button zeichnen if(btnDisplayAllShips) g->DrawImage(btnDisplayAllShips,40,750,80,30); CString s; //AfxMessageBox("m_bDisplayAllShips"); if (m_bDisplayAllShips) s=CLoc::GetString("BTN_ALL"); else s=CLoc::GetString("BTN_CURRENTS"); g->DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40,750,80,30), &fontFormat, &fontBrush); // "Schiffsdesign" in der Mitte zeichnen // Rassenspezifische Schriftart auswählen CFontLoader::CreateGDIFont(pMajor, 5, fontName, fontSize); // Schriftfarbe wählen CFontLoader::GetGDIFontColor(pMajor, 3, normalColor); fontBrush.SetColor(normalColor); g->DrawString(CComBSTR(CLoc::GetString("SHIPDESIGN")), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(188,10,600,50), &fontFormat, &fontBrush); }
// CSkinFrameWnd 訊息處理常式 void CSkinFrameWnd::OnNcPaint() { // TODO: 在此加入您的訊息處理常式程式碼 // 不要呼叫圖片訊息的 CFrameWndEx::OnNcPaint() CWindowDC dc(this); if (m_pBkImage == NULL) { return; } CDC MemDC; //記憶體DC //獲取位置 CRect rcWindow; GetWindowRect(&rcWindow); rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top); CRect rcClient; GetClientRect(&rcClient); //剪除掉客戶區 rcClient.OffsetRect(m_nFrameWidth, m_nTitleHeight); dc.ExcludeClipRect(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); MemDC.CreateCompatibleDC(&dc); CBitmap bmp; bmp.CreateCompatibleBitmap(&dc, rcWindow.Width(), rcWindow.Height()); MemDC.SelectObject(&bmp); MemDC.SetBkMode(TRANSPARENT); Gdiplus::Graphics graphics(MemDC.GetSafeHdc()); RectF destRect; //繪製底部和邊框 destRect.X = 0; destRect.Y = rcWindow.Height() - m_nFrameWidth; destRect.Width = rcWindow.Width(); destRect.Height = m_nFrameWidth; graphics.DrawImage(m_pBkImage, destRect, m_nTitleHeight, m_pBkImage->GetHeight() - m_nFrameWidth, m_nFrameWidth, m_nFrameWidth, UnitPixel); destRect.X = rcWindow.right - m_nTitleHeight; destRect.Y = rcWindow.bottom - m_nTitleHeight; destRect.Width = m_nTitleHeight; destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage, destRect, m_pBkImage->GetWidth() - m_nTitleHeight, m_pBkImage->GetHeight() - m_nTitleHeight, m_nTitleHeight, m_nTitleHeight, UnitPixel); destRect.X = 0; destRect.Y = rcWindow.Height() - m_nTitleHeight; destRect.Width = m_nTitleHeight; destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage, destRect, 0, m_pBkImage->GetHeight() - m_nTitleHeight, m_nTitleHeight, m_nTitleHeight, UnitPixel); //左邊框 destRect.X = 0; destRect.Y = m_nTitleHeight; destRect.Width = m_nFrameWidth; destRect.Height = rcWindow.Height() - 2 * m_nTitleHeight; graphics.DrawImage(m_pBkImage, destRect, 0, m_nTitleHeight, m_nFrameWidth, m_nFrameWidth, UnitPixel); //右邊框 destRect.X = rcWindow.Width() - m_nFrameWidth; destRect.Y = m_nTitleHeight; destRect.Width = m_nFrameWidth; destRect.Height = rcWindow.Height() - 2 * m_nTitleHeight; graphics.DrawImage(m_pBkImage, destRect, m_pBkImage->GetWidth() - m_nFrameWidth, m_nTitleHeight, m_nFrameWidth, m_nFrameWidth, UnitPixel); //繪製標題欄 destRect.X = 0; destRect.Y = 0; destRect.Width = rcWindow.Width(); destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage, destRect, 50, 0, 5, m_nTitleHeight, UnitPixel); graphics.DrawImage(m_pBkImage, 0, 0, 0, 0, 50, m_nTitleHeight, UnitPixel); graphics.DrawImage(m_pBkImage, rcWindow.Width() - 50, 0, m_pBkImage->GetWidth() - 50, 0, 50, m_nTitleHeight, UnitPixel); ///*標題列圖標*/ int xPos = 5; int yPos = 5; HICON hIcon = (HICON)GetClassLongPtr(m_hWnd, GCLP_HICONSM); //HICON hIcon = GetIcon(FALSE); if (hIcon) { DrawIconEx(MemDC, xPos, yPos - 2, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL); xPos += GetSystemMetrics(SM_CXSMICON); xPos += 10; } /*標題列文字*/ CString strText; GetWindowText(strText); if (!strText.IsEmpty()) { LOGFONT lfFont; memset(&lfFont, 0, sizeof(lfFont)); lfFont.lfHeight = -12; lfFont.lfWeight |= FW_BOLD; lstrcpy(lfFont.lfFaceName, _T(" 宋体")); Gdiplus::Font font(dc.GetSafeHdc(), &lfFont); StringFormat stringFormat; stringFormat.SetFormatFlags(StringFormatFlagsNoWrap); stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CStringW strTitle(strText); SolidBrush brush((ARGB)Color::White); PointF point; point.X = (Gdiplus::REAL)xPos; point.Y = (Gdiplus::REAL)yPos; graphics.DrawString(strTitle, strTitle.GetLength(), &font, point, &stringFormat, &brush); } dc.BitBlt(0, 0, rcWindow.Width(), rcWindow.Height(), &MemDC, 0, 0, SRCCOPY); dc.SelectClipRgn(NULL); }
void IrisBitmap::IrisDrawText(const IrisFont* fontIris, int x, int y, int width, int height, wstring str, int align){ this->needRefreshTexture = true; if (x > this->width || y > this->height || x < 0 || y < 0) return; //this->needRefreshTexture = true; int size = IrisFont::defaultSize; IrisColor *color; wstring name; bool bold, shadow, italic; if(fontIris == NULL){ name = IrisFont::defaultName; bold = IrisFont::defaultBold; shadow = IrisFont::defaultShadow; italic = IrisFont::defaultItalic; color = IrisFont::defaultColor; } else { name = fontIris->name; bold = fontIris->bold; shadow = fontIris->shadow; italic = fontIris->italic; color = fontIris->color; } // release Gdiplus::Bitmap *tBitmap = this->bitmap->Clone(0, 0, this->bitmap->GetWidth(), this->bitmap->GetHeight(), PixelFormat32bppARGB); Graphics tg(tBitmap); Gdiplus::FontFamily fontFamily(name.c_str()); int fs = FontStyleRegular; if(bold) fs |= FontStyleBold; if(italic) fs |= FontStyleItalic; //lfont.lfWeight = 1000; Gdiplus::Font font(&fontFamily, (REAL)size, fs, UnitPixel); StringFormat strFormat; switch(align){ case 0: strFormat.SetAlignment(StringAlignmentNear); break; case 1: strFormat.SetAlignment(StringAlignmentCenter); break; } Brush *brush; if(shadow) brush = new HatchBrush(HatchStyle90Percent, Color(color->red, color->green, color->blue)); else brush = new SolidBrush(Color(color->red, color->green, color->blue)); strFormat.SetFormatFlags(StringFormatFlagsNoWrap); Gdiplus::RectF r((REAL)x, (REAL)y, (REAL)width, (REAL)height); tg.SetSmoothingMode(SmoothingModeAntiAlias); tg.SetInterpolationMode(InterpolationModeHighQualityBicubic); Gdiplus::GraphicsPath path; path.AddString(str.c_str(), str.size(), &fontFamily, FontStyleRegular, 20, r, &strFormat); Gdiplus::Pen pen(Color(color->red, color->green, color->blue), 2); tg.DrawPath(&pen, &path); tg.FillPath(brush, &path); if(this->bitmap != 0){ delete this->bitmap; this->bitmap = 0; } this->bitmap = tBitmap->Clone(0, 0, tBitmap->GetWidth(), tBitmap->GetHeight(), PixelFormat32bppARGB); //CLSID encoderClsid; //ModuleIrisGraphics::GetEncoderClsid(L"image/png", &encoderClsid); //this->bitmap->Save(L"string.png", &encoderClsid, NULL); delete brush; delete tBitmap; }
void CSkinWndHelper::DoNcPaint() { CDC dc; HDC hdc = GetWindowDC(m_hWnd); dc.Attach(hdc); if (m_pBkImage==NULL) { return; } CDC MemDC; // 获取位置 CRect rcWindow; GetWindowRect(m_hWnd,&rcWindow); rcWindow.OffsetRect( -rcWindow.left, -rcWindow.top); CRect rcClient; GetClientRect(m_hWnd,&rcClient); //剪除掉客户区 rcClient.OffsetRect(m_nFrameWidth, m_nTitleHeight); dc.ExcludeClipRect(rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); MemDC.CreateCompatibleDC(dc); CBitmap bmp; bmp.CreateCompatibleBitmap(dc,rcWindow.Width(),rcWindow.Height()); MemDC.SelectBitmap(bmp); MemDC.SetBkMode(TRANSPARENT); Gdiplus::Graphics graphics(MemDC.m_hDC); RectF destRect; //绘制底部和边框 destRect.X = 0; destRect.Y = rcWindow.Height() - m_nFrameWidth; destRect.Width = rcWindow.Width(); destRect.Height = m_nFrameWidth; graphics.DrawImage(m_pBkImage,destRect,m_nTitleHeight,m_pBkImage->GetHeight()-m_nFrameWidth,m_nFrameWidth,m_nFrameWidth,UnitPixel); destRect.X = rcWindow.right-m_nTitleHeight; destRect.Y = rcWindow.bottom - m_nTitleHeight; destRect.Width = m_nTitleHeight; destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage,destRect,m_pBkImage->GetWidth()-m_nTitleHeight,m_pBkImage->GetHeight()-m_nTitleHeight,m_nTitleHeight,m_nTitleHeight,UnitPixel); destRect.X = 0; destRect.Y = rcWindow.Height() - m_nTitleHeight; destRect.Width = m_nTitleHeight; destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage,destRect,0,m_pBkImage->GetHeight()-m_nTitleHeight,m_nTitleHeight,m_nTitleHeight,UnitPixel); //左边框 destRect.X = 0; destRect.Y = m_nTitleHeight; destRect.Width = m_nFrameWidth; destRect.Height = rcWindow.Height() - 2*m_nTitleHeight; graphics.DrawImage(m_pBkImage,destRect,0,m_nTitleHeight,m_nFrameWidth,m_nFrameWidth,UnitPixel); //右边框 destRect.X = rcWindow.Width() - m_nFrameWidth; destRect.Y = m_nTitleHeight; destRect.Width = m_nFrameWidth; destRect.Height = rcWindow.Height() - 2*m_nTitleHeight; graphics.DrawImage(m_pBkImage,destRect,m_pBkImage->GetWidth()-m_nFrameWidth,m_nTitleHeight,m_nFrameWidth,m_nFrameWidth,UnitPixel); //绘制标题栏 destRect.X = 0; destRect.Y = 0; destRect.Width = rcWindow.Width(); destRect.Height = m_nTitleHeight; graphics.DrawImage(m_pBkImage,destRect,50,0,5,m_nTitleHeight,UnitPixel); graphics.DrawImage(m_pBkImage,0,0,0,0,50,m_nTitleHeight,UnitPixel); graphics.DrawImage(m_pBkImage,rcWindow.Width() - 50,0,m_pBkImage->GetWidth()-50,0,50,m_nTitleHeight,UnitPixel); int xPos = 15; int yPos = 15; HICON hIcon = (HICON)::SendMessage(m_hWnd, WM_GETICON, ICON_SMALL, 0); if (hIcon) { DrawIconEx(MemDC,xPos, yPos-2,hIcon,GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL); xPos += GetSystemMetrics(SM_CXSMICON); xPos += 5; } CString strText; int nLen = ::GetWindowTextLength(m_hWnd); ::GetWindowText(m_hWnd, strText.GetBufferSetLength(nLen), nLen+1); strText.ReleaseBuffer(); if (!strText.IsEmpty()) { //绘制标题 LOGFONT lfFont; memset(&lfFont, 0, sizeof(lfFont)); lfFont.lfHeight = -12; lfFont.lfWeight |= FW_BOLD; lstrcpy(lfFont.lfFaceName, _T("宋体")); Gdiplus::Font font(dc.m_hDC, &lfFont); StringFormat stringFormat; stringFormat.SetFormatFlags( StringFormatFlagsNoWrap); stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CStringW strTitle(strText); SolidBrush brush((ARGB)Color::White); PointF point; point.X=(Gdiplus::REAL)xPos; point.Y=(Gdiplus::REAL)yPos; graphics.DrawString(strTitle, strTitle.GetLength(), &font, point,&stringFormat, &brush); } CRect rcPaint; dc.GetClipBox(&rcPaint); std::map<int,CDUIButton>::iterator iter; for (iter = m_TitleBtn.begin(); iter != m_TitleBtn.end(); iter++) { CDUIButton& dcControl = iter->second; CRect rcControl; dcControl.GetRect(&rcControl); // 判断当前按钮是否需要重绘 if(!rcPaint.IsRectEmpty() && !CRect().IntersectRect(&rcControl, rcPaint)) { continue; } dcControl.DrawButton(graphics); } dc.BitBlt(0,0,rcWindow.Width(),rcWindow.Height(),MemDC,0,0,SRCCOPY); dc.SelectClipRgn(NULL); dc.Detach(); ReleaseDC(m_hWnd,hdc); }
void CResearchBottomView::OnDraw(CDC* dc) { CBotEDoc* pDoc = resources::pDoc; AssertBotE(pDoc); if (!pDoc->m_bDataReceived) return; CMajor* pMajor = m_pPlayersRace; AssertBotE(pMajor); if (!pMajor) return; // TODO: add draw code here // Doublebuffering wird initialisiert CMyMemDC pDC(dc); CRect client; GetClientRect(&client); // Graphicsobjekt, in welches gezeichnet wird anlegen Graphics g(pDC->GetSafeHdc()); g.Clear(static_cast<Gdiplus::ARGB>(Color::Black)); g.SetSmoothingMode(SmoothingModeHighSpeed); g.SetInterpolationMode(InterpolationModeLowQuality); g.SetPixelOffsetMode(PixelOffsetModeHighSpeed); g.SetCompositingQuality(CompositingQualityHighSpeed); g.ScaleTransform((REAL)client.Width() / (REAL)m_TotalSize.cx, (REAL)client.Height() / (REAL)m_TotalSize.cy); CString fontName = ""; Gdiplus::REAL fontSize = 0.0; StringFormat fontFormat; SolidBrush fontBrush(static_cast<Gdiplus::ARGB>(Color::White)); CRect rect; rect.SetRect(0,0,m_TotalSize.cx,m_TotalSize.cy); CString sPrefix = pMajor->GetPrefix(); Color color; color.SetFromCOLORREF(pMajor->GetDesign()->m_clrGalaxySectorText); fontBrush.SetColor(color); Bitmap* graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Backgrounds\\" + sPrefix + "researchV3.boj"); // gibt es keine Spezialforschung zur Auswahl, so wird auf Standardanzeige umgestellt if (m_nCurrentTech == 6 && pMajor->GetEmpire()->GetResearch()->GetUniqueReady() == TRUE) m_nCurrentTech = 0; // Grafik zeichnen if (graphic) { g.DrawImage(graphic, 0, 0, 1075, 249); graphic = NULL; } switch(m_nCurrentTech) { case 0: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\biotech.bop"); break; case 1: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\energytech.bop"); break; case 2: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\computertech.bop"); break; case 3: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\propulsiontech.bop"); break; case 4: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\constructiontech.bop"); break; case 5: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\weapontech.bop"); break; case 6: graphic = pDoc->GetGraphicPool()->GetGDIGraphic("Research\\specialtech.bop"); break; } if (graphic) { g.DrawImage(graphic, 790, 25, 240, 200); graphic = NULL; } // Name und Beschreibung der Forschung anzeigen CFontLoader::CreateGDIFont(pMajor, 4, fontName, fontSize); fontFormat.SetAlignment(StringAlignmentNear); fontFormat.SetLineAlignment(StringAlignmentNear); fontFormat.SetFormatFlags(StringFormatFlagsNoWrap); CString s; if (m_nCurrentTech != 6) s = pMajor->GetEmpire()->GetResearch()->GetResearchInfo()->GetTechName(m_nCurrentTech); else s = pMajor->GetEmpire()->GetResearch()->GetResearchInfo()->GetCurrentResearchComplex()->GetComplexName(); g.DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 30, rect.right-325, rect.bottom), &fontFormat, &fontBrush); CFontLoader::CreateGDIFont(pMajor, 2, fontName, fontSize); fontBrush.SetColor(Color(200,200,250)); fontFormat.SetFormatFlags(!StringFormatFlagsNoWrap); if (m_nCurrentTech != 6) s = pMajor->GetEmpire()->GetResearch()->GetResearchInfo()->GetTechDescription(m_nCurrentTech); else s = pMajor->GetEmpire()->GetResearch()->GetResearchInfo()->GetCurrentResearchComplex()->GetComplexDescription(); g.DrawString(CComBSTR(s), -1, &Gdiplus::Font(CComBSTR(fontName), fontSize), RectF(40, 100, rect.right-325, rect.bottom), &fontFormat, &fontBrush); g.ReleaseHDC(pDC->GetSafeHdc()); }
void CMenuItem::DrawControl(CDC &dc, CRect rcUpdate) { int nWidth = m_rc.Width(); int nHeight = m_rc.Height(); if(!m_bUpdate) { int nImageCount = m_bSelect ? 6 : 4; if(m_nImagePicCount != 4) { // 如果修改过img-count属性,则用此属性设置的图片个数 nImageCount = m_nImagePicCount; } if(m_bIsSeparator) { nImageCount = 1; } UpdateMemDC(dc, nWidth * nImageCount, nHeight); // 刷新图片的大小(因为m_bSelect选项有可能在SetBitmap之后有变化) if(m_pImage != NULL) { if(m_bIsPopup && (m_pImagePopupArrow == NULL)) { m_sizeImage.SetSize(m_pImage->GetWidth() / 2, m_pImage->GetHeight()); }else { m_sizeImage.SetSize(m_pImage->GetWidth() / nImageCount, m_pImage->GetHeight()); } } Graphics graphics(m_memDC); CRect rcTemp(0, 0, nWidth, nHeight); for(int i = 0; i < nImageCount; i++) { m_memDC.BitBlt(i * nWidth, 0, nWidth, nHeight, &dc, m_rc.left ,m_rc.top, SRCCOPY); if(enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i) { // 画菜单项背景 if(m_pImageHover != NULL) { // 使用拉伸模式属性画图 graphics.DrawImage(m_pImageHover, RectF((Gdiplus::REAL)(i * nWidth+m_nFrameWidth), 0, (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)nHeight), 0, 0, (Gdiplus::REAL)m_sizeHover.cx, (Gdiplus::REAL)m_sizeHover.cy, UnitPixel); }else { // 使用颜色填充 SolidBrush brush(m_clrHover);//Color(254, 71, 156, 235)); graphics.FillRectangle(&brush, i * nWidth+m_nFrameWidth, 0, nWidth-m_nFrameWidth*2, nHeight); } } if(m_pImage != NULL) { if(m_bIsSeparator) { // 如果是分隔线,则采用平铺方式画图 TextureBrush tileBrush(m_pImage, WrapModeTile); graphics.FillRectangle(&tileBrush, RectF((Gdiplus::REAL)rcTemp.left, (Gdiplus::REAL)(rcTemp.top + (nHeight - m_sizeImage.cy) / 2), (Gdiplus::REAL)(nWidth-m_nFrameWidth*2), (Gdiplus::REAL)m_sizeImage.cy)); }else if(m_bIsPopup && (m_pImagePopupArrow == NULL)) { // 如果是弹出菜单,并且没有设置菜单的箭头图片,则用菜单图片作为右侧的箭头图片 graphics.DrawImage(m_pImage, Rect(rcTemp.right - m_sizeImage.cx - 6, rcTemp.top + (nHeight - m_sizeImage.cy) / 2, m_sizeImage.cx, m_sizeImage.cy), (i % 2) * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, UnitPixel); }else { // 普通菜单项的图片 graphics.DrawImage(m_pImage, Rect(rcTemp.left + (m_nLeft - m_sizeImage.cx) / 2, 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); } } // 如果是弹出菜单,并且设置了菜单的箭头图片,则画右侧的箭头图片 if(m_bIsPopup && (m_pImagePopupArrow != NULL)) { graphics.DrawImage(m_pImagePopupArrow, Rect(rcTemp.right - m_sizePopupArrow.cx - 6, rcTemp.top + (nHeight - m_sizePopupArrow.cy) / 2, m_sizePopupArrow.cx, m_sizePopupArrow.cy), (i % 2) * m_sizePopupArrow.cx, 0, m_sizePopupArrow.cx, m_sizePopupArrow.cy, UnitPixel); } rcTemp.OffsetRect(nWidth, 0); } if(!m_strTitle.IsEmpty()) { m_memDC.SetBkMode(TRANSPARENT); rcTemp.SetRect(0, 0, nWidth, nHeight); 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 size = GetTextBounds(font, strFormat, m_strTitle); CPoint point = GetOriginPoint(nWidth - m_nLeft, nHeight, size.Width, size.Height, m_uAlignment, m_uVAlignment); for(int i = 0; i < nImageCount; i++) { SolidBrush solidBrush(enBSDisable == i ? Color(254, 128, 128, 128) : (enBSHover == i || (enBSDown == i && !m_bSelect) || enBSHoverDown == i ? Color(254, 255, 255, 255) : Color(254, 56, 56, 56))); RectF rect((Gdiplus::REAL)(m_nLeft + point.x + i * nWidth), (Gdiplus::REAL)point.y, (Gdiplus::REAL)(nWidth - (m_nLeft + point.x)), (Gdiplus::REAL)size.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); }
void CDrawWarn::Draw(CDC* pDC) { ASSERT_VALID(this); CRect rect = m_position; rect.NormalizeRect(); if(rect.Width() < 10 || rect.Height()<10) return; Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); Color crBackColor,crTitleColor,crLineColor,crTextColor ; crBackColor.SetFromCOLORREF(m_ctlBackColor); crTitleColor.SetFromCOLORREF(m_ctlTitleColor ); crLineColor.SetFromCOLORREF(m_ctlLineColor); crTextColor.SetFromCOLORREF(m_ctlTextColor); Graphics graphics (pDC->m_hDC); graphics.SetSmoothingMode (SmoothingModeHighSpeed); Graphics Textgraphics (pDC->m_hDC); SolidBrush solidBrush(crBackColor); SolidBrush TitleBrush(crTitleColor); SolidBrush TextBrush(crTextColor); Pen pen(crLineColor,1); graphics.FillRectangle(&solidBrush,GdiRect); BSTR bstr = m_fontName.AllocSysString(); /// BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName); FontFamily fontFamily(bstr); SysFreeString(bstr); Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint); for(int j =1; j<= m_nColCount; j++) { m_nCellWidth = 0; for(int i=1; i<= m_nRowCount; i++) { CRect rc = rect; if(m_bIsAutoSize) { m_nCellWidth = rect.Width()/m_nRowCount; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().x += (i-1)*m_nCellWidth; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight)); m_CellRect.NormalizeRect(); } else { rc.TopLeft().x += m_nCellWidth; m_nCellWidth += rect.Width()*m_nPercent[i-1]/100; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight)); m_CellRect.NormalizeRect(); } Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); graphics.DrawRectangle(&pen,CellRect); if(j == m_nColCount) //画标题 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); stringFormat.SetTrimming(m_trimmingSyle); CString m_strButton; if(i == 1) m_strButton = "点号"; if(i == 2) m_strButton = "数据"; if(i == 3) m_strButton = "说明"; if(i == 4) m_strButton = "报警原因"; if(i == 5) m_strButton = "时间"; m_strButton.TrimRight(); bstr = m_strButton.AllocSysString(); /// bstr = _com_util::ConvertStringToBSTR(m_strButton); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.FillRectangle(&TitleBrush,theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); SysFreeString(bstr); } else { //画文字 m_CStrWarn pStrWarn StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CString strWarn; /* if(i == 1) strWarn = m_CStrWarn[j].strPoint; if(i == 2) strWarn = m_CStrWarn[j].strDate; if(i == 3) strWarn = m_CStrWarn[j].strTime; if(i == 4) strWarn = m_CStrWarn[j].strText; if(i == 5) strWarn = m_CStrWarn[j].strWarn; */ strWarn.TrimRight(); bstr = strWarn.AllocSysString(); /// bstr = _com_util::ConvertStringToBSTR(strWarn); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); SysFreeString(bstr); } } } graphics.ReleaseHDC(pDC->m_hDC); }