Пример #1
0
//
// draw_label
//
int Component_Decorator_Impl::draw_label (Gdiplus::Graphics * g)
{
  float height = (float)this->location_.height ();
  float px = static_cast <float> (this->location_.x_) + (this->location_.width () / 2.0f);
  float py = static_cast <float> (this->location_.y_) + (height + 15.0f);

  static const Gdiplus::Font font (L"Arial", 10);
  static const Gdiplus::SolidBrush brush (Gdiplus::Color (0, 0, 0));

  Gdiplus::StringFormat format;
  format.SetAlignment (Gdiplus::StringAlignmentCenter);
  format.SetLineAlignment (Gdiplus::StringAlignmentCenter);

  CComBSTR bstr (this->label_.length (), this->label_.c_str ());

  // Draw the label for the element.
  g->DrawString (bstr,
                 this->label_.length (),
                 &font,
                 Gdiplus::PointF (px, py),
                 &format,
                 &brush);

  return 0;
}
Пример #2
0
void StringFormat::SetLineAlignment(StringAlignment sa) {
    Gdiplus::StringFormat* sf =  reinterpret_cast<Gdiplus::StringFormat*>(_private);
    switch(sa) {
    case StringAlignmentNear:
        sf->SetLineAlignment(Gdiplus::StringAlignmentNear);
        break;

    case StringAlignmentFar:
        sf->SetLineAlignment(Gdiplus::StringAlignmentFar);
        break;

    case StringAlignmentCenter:
        sf->SetLineAlignment(Gdiplus::StringAlignmentCenter);
        break;
    }
}
Пример #3
0
bool CanvasGDIP::MeasureTextLinesW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, UINT& lines)
{
	Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
	Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();

	// Set trimming and format temporarily.
	const Gdiplus::StringTrimming stringTrimming = stringFormat.GetTrimming();
	stringFormat.SetTrimming(Gdiplus::StringTrimmingNone);

	const INT stringFormatFlags = stringFormat.GetFormatFlags();
	stringFormat.SetFormatFlags(Gdiplus::StringFormatFlagsNoClip);

	if (m_AccurateText)
	{
		tStringFormat.SetTrimming(stringFormat.GetTrimming());
		tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
		tStringFormat.SetAlignment(stringFormat.GetAlignment());
		tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
	}

	INT linesFilled = 0;
	const Gdiplus::Status status = m_Graphics->MeasureString(
		str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
		m_AccurateText ? &tStringFormat : &stringFormat, &rect, nullptr, &linesFilled);
	lines = linesFilled;

	// Restore old options.
	stringFormat.SetTrimming(stringTrimming);
	stringFormat.SetFormatFlags(stringFormatFlags);

	return status == Gdiplus::Ok;
}
Пример #4
0
void winbox::draw_text_lines()
{
	if (m_lines.empty())
		return;

	Gdiplus::SolidBrush brush(m_log_back_color);
	m_graphics->FillRectangle(&brush, m_log_box);

	Gdiplus::Font font(L"宋体", 12);
	Gdiplus::StringFormat format;
	
	format.SetAlignment(Gdiplus::StringAlignment::StringAlignmentNear);
	format.SetLineAlignment(Gdiplus::StringAlignment::StringAlignmentCenter);

	float line_pos = m_log_box.GetBottom();
	float fontHeight = font.GetHeight(m_graphics) + 3;
	m_graphics->SetClip(m_log_box);
	for (auto it = m_lines.begin(); it != m_lines.end(); ++it)
	{
		if (line_pos < m_log_box.Y)
		{
			m_lines.erase(it, m_lines.end());
			break;
		}
		Gdiplus::RectF rect(m_log_box.X, line_pos - fontHeight, m_log_box.Width, fontHeight);
		brush.SetColor(it->tp == log_type::err ? m_log_err_color : m_log_txt_color);
		m_graphics->DrawString(it->ws.c_str(), (int)it->ws.size(), &font, rect, &format, &brush);
		line_pos -= fontHeight;
	}
	m_graphics->ResetClip();

	Gdiplus::Pen pen(m_log_edge_color);
	m_graphics->DrawRectangle(&pen, m_log_box);
}
Пример #5
0
BOOL GdiplusUtilities::DrawTextOutline(Gdiplus::Graphics& graphics, 
									   LPCTSTR lpchText, int cchText, const RECT* lprc, UINT format, 
									   const LOGFONT& lf, COLORREF fill, COLORREF outline, INT outlineWidth,
									   BOOL bCalcOnly /*= FALSE*/, RECT* rcCalc/* = NULL*/)
{
	HDC hdc = graphics.GetHDC();
	Gdiplus::Font font(hdc, &lf);
	graphics.ReleaseHDC(hdc);
	Gdiplus::StringFormat sFormat;
	if (format & DT_VCENTER)
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
	else if (format & DT_BOTTOM)
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentFar);
	else
		sFormat.SetLineAlignment(Gdiplus::StringAlignmentNear);

	if (format & DT_CENTER)
		sFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	else if (format & DT_RIGHT)
		sFormat.SetAlignment(Gdiplus::StringAlignmentFar);
	else
		sFormat.SetAlignment(Gdiplus::StringAlignmentNear);

	Gdiplus::Rect rcForCalc;
	Gdiplus::Rect* pRCForCalc = &rcForCalc;
	if (rcCalc == NULL)
		pRCForCalc = NULL;
	if (DrawTextOutline(graphics, lpchText, cchText, RECT2GdiplusRect(*lprc), sFormat, font, 
		COLORREF2Color(fill), COLORREF2Color(outline), outlineWidth, bCalcOnly, pRCForCalc))
	{
		if (pRCForCalc != NULL)
			*rcCalc = GdiplusRect2RECT(*pRCForCalc);
		return TRUE;
	}
	return FALSE;

}
Пример #6
0
 // sets the line's mWidth, mHeight, mAscent, mDescent, mLeading
void Line::calcExtents()
{
#if defined( CINDER_MAC )
	CFMutableAttributedStringRef attrStr = ::CFAttributedStringCreateMutable( kCFAllocatorDefault, 0 );

	// Defer internal consistency-checking and coalescing until we're done building this thing
	::CFAttributedStringBeginEditing( attrStr );
	for( vector<Run>::const_iterator runIt = mRuns.begin(); runIt != mRuns.end(); ++runIt ) {
		// create and append this run's CFAttributedString
		::CFAttributedStringRef runStr = cocoa::createCfAttributedString( runIt->mText, runIt->mFont, runIt->mColor );
		::CFAttributedStringReplaceAttributedString( attrStr, ::CFRangeMake( ::CFAttributedStringGetLength( attrStr ), 0 ), runStr );
		::CFRelease( runStr );
	}	
	// all done - coalesce
	::CFAttributedStringEndEditing( attrStr );			
	
	mCTLineRef = ::CTLineCreateWithAttributedString( attrStr );
	::CFRelease( attrStr );
	
	CGFloat ascentCG, descentCG, leadingCG;
	mWidth = ::CTLineGetTypographicBounds( mCTLineRef, &ascentCG, &descentCG, &leadingCG );
	mAscent = ascentCG;
	mDescent = descentCG;
	mLeading = leadingCG;
	mHeight = 0;
#elif defined( CINDER_MSW )
	mHeight = mWidth = mAscent = mDescent = mLeading = 0;
	for( vector<Run>::iterator runIt = mRuns.begin(); runIt != mRuns.end(); ++runIt ) {
		Gdiplus::StringFormat format;
		format.SetAlignment( Gdiplus::StringAlignmentNear ); format.SetLineAlignment( Gdiplus::StringAlignmentNear );
		Gdiplus::RectF sizeRect;
		const Gdiplus::Font *font = runIt->mFont.getGdiplusFont();;
		TextManager::instance()->getGraphics()->MeasureString( &runIt->mWideText[0], -1, font, Gdiplus::PointF( 0, 0 ), &format, &sizeRect );
		
		runIt->mWidth = sizeRect.Width;
		runIt->mAscent = runIt->mFont.getAscent();
		runIt->mDescent = runIt->mFont.getDescent();
		runIt->mLeading = runIt->mFont.getLeading();
		
		mWidth += sizeRect.Width;
		mAscent = std::max( runIt->mFont.getAscent(), mAscent );
		mDescent = std::max( runIt->mFont.getDescent(), mDescent );
		mLeading = std::max( runIt->mFont.getLeading(), mLeading );
		mHeight = std::max( mHeight, sizeRect.Height );
	}
#endif

	mHeight = std::max( mHeight, mAscent + mDescent + mLeading );
}
Пример #7
0
void CanvasGDIP::DrawTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect, const Gdiplus::SolidBrush& brush)
{
	Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
	Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();

	if (m_AccurateText)
	{
		tStringFormat.SetTrimming(stringFormat.GetTrimming());
		tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
		tStringFormat.SetAlignment(stringFormat.GetAlignment());
		tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
	}

	m_Graphics->DrawString(
		str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
		m_AccurateText ? &tStringFormat : &stringFormat, &brush);
}
Пример #8
0
void cgGdiplusRender::DrawUIText( LPCTSTR lpctText, int nTextLen, 
	const cgRectF& rect, cgID font, int space , cgColor color, int style )
{
	Gdiplus::RectF kDrawRect (rect.x, rect.y, rect.w, rect.h);
	Gdiplus::StringFormat kFormat;

	if (style&DT_CENTER)
		kFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	if (style&DT_VCENTER)
		kFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	Gdiplus::Font * pkFont = FindFont(font);
	Gdiplus::SolidBrush brush(Gdiplus::Color((Gdiplus::ARGB)color));

	m_pkGraphics->DrawString(lpctText, nTextLen, pkFont,  kDrawRect, 
		&kFormat, &brush);
}
Пример #9
0
bool CanvasGDIP::MeasureTextW(const WCHAR* str, UINT strLen, const TextFormat& format, Gdiplus::RectF& rect)
{
	Gdiplus::StringFormat& stringFormat = ((TextFormatGDIP&)format).m_StringFormat;
	Gdiplus::StringFormat tStringFormat = Gdiplus::StringFormat::GenericTypographic();

	if (m_AccurateText)
	{
		tStringFormat.SetTrimming(stringFormat.GetTrimming());
		tStringFormat.SetFormatFlags(stringFormat.GetFormatFlags());
		tStringFormat.SetAlignment(stringFormat.GetAlignment());
		tStringFormat.SetLineAlignment(stringFormat.GetLineAlignment());
	}

	const Gdiplus::Status status = m_Graphics->MeasureString(
		str, (INT)strLen, ((TextFormatGDIP&)format).m_Font.get(), rect,
		m_AccurateText ? &tStringFormat : &stringFormat, &rect);

	return status == Gdiplus::Ok;
}
Пример #10
0
/*!
 @brief イメージの取得

 @param [in]    pSelectItem     選択データ
 @param [out]   bitmap          イメージ
 */
BOOL CImageFontDlg::GetBitmapImage(LPVOID pSelectItem, CImage &bitmap)
{
	CRect rect;
	GetClientRect(&rect);

	bitmap.Create(rect.Width(), rect.Height(), 32);

	HDC hDC = bitmap.GetDC();
	Gdiplus::Graphics graphics(hDC);
	graphics.Clear((Gdiplus::ARGB)Gdiplus::Color::White);

	CString strMessage;
	strMessage = _T("1234567890\n");
	strMessage += _T("abcdefghijklmnopqrstuvwxyz\n");
	strMessage += _T("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
	strMessage += _T("あいおえおかきくけこさしすせそたちつてとなにぬねの\n");
	strMessage += _T("はひふへほまみむめもやゆよらりるれろわをん\n");

	LOGFONT *pLogfont = (LOGFONT *) pSelectItem;
	Gdiplus::Font font(hDC, pLogfont);

	Gdiplus::RectF drawLayout(0, 0, (Gdiplus::REAL)rect.Width(), (Gdiplus::REAL)rect.Height());

	Gdiplus::StringFormat stringFormat;
	stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
	stringFormat.SetTrimming(Gdiplus::StringTrimmingNone);

	Gdiplus::SolidBrush brush((Gdiplus::ARGB)Gdiplus::Color::Black);

	graphics.SetTextRenderingHint((Gdiplus::TextRenderingHint) (GetSpaceKeyDownCount() % (int)Gdiplus::TextRenderingHintClearTypeGridFit));
	graphics.DrawString(strMessage, -1, &font, drawLayout, &stringFormat,&brush);


	bitmap.ReleaseDC();

	return TRUE;
}
Пример #11
0
CSize CXTextGdiPlus::Measure( HDC dc, INT nWidthLimit )
{
	Gdiplus::Graphics graph(dc);

	graph.SetTextRenderingHint(m_Rendering);

	Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName));  
	Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel);  
	Gdiplus::StringFormat stringformat;
	stringformat.SetAlignment(m_AlignmentH);
	stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ?
		Gdiplus::StringAlignmentNear : m_AlignmentV);
	stringformat.SetFormatFlags(m_FormatFlags);
	stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
	Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB));

	Gdiplus::RectF rfTargetRect(0, 0, nWidthLimit > 0 ? nWidthLimit : INFINITY, INFINITY);
	CStringW strTextToDraw(XLibST2W(m_strText));

	Gdiplus::RectF rfBoundRect(0, 0, 0, 0);
	graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect);

	return CSize(ceil(rfBoundRect.Width), ceil(rfBoundRect.Height));
}
Пример #12
0
void CClipMonView::ReDrawRemainTime(CDC* pDC)
{
	CRect rcClient;
	TxGetClientRect(rcClient);
	if (m_scBar[SB_VERT].IsShowing())
	{
		rcClient.DeflateRect(0,0,m_scBar[SB_VERT].GetBarWidth(), 0);
	}
	if (m_scBar[SB_HORZ].IsShowing())
	{
		rcClient.DeflateRect(0,0, 0, m_scBar[SB_HORZ].GetBarWidth());
	}
// 	Rect rCet = CRect2Rect(rcClient);
// 	gc.FillRectangle(&bkBrush, rCet);
	CSize szView = GetScrollViewSize();
	CRect rcView(0, 0, szView.cx, szView.cy);
	rcView.OffsetRect(rcClient.left, rcClient.top);

	if (rcView.IsRectEmpty())
	{
		return;
	}
	rcView.OffsetRect(-GetScrollPos(SB_HORZ), -GetScrollPos(SB_VERT));

	int nBegin = (rcClient.top - rcView.top) / m_drawParam.nItemHeight;
	int nCount = rcClient.Height() /m_drawParam.nItemHeight +1;
	VECTMPITEM vData;
	g_monDataMgr.GetRangeData(nBegin, nCount, vData);
	nCount = vData.size();
	if (nCount <= 0)
	{
		return;
	}
	CTxListHeader& headerCtrl = GetListHeader();

	int nLeftPos = rcView.left;
	int nRightPos = 0;
	for (int cIdx = 0;  cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++)
	{

		ENUM_MONTYPE nMonType =  (ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType);
		if (nMonType == MONTYPE_TIMEREMAIN)
		{
			nRightPos = nLeftPos + headerCtrl.GetHeaderWidth(cIdx);
			break;
		}
		else
		{
			nLeftPos += headerCtrl.GetHeaderWidth(cIdx);
		}
	}

	if (nRightPos < rcClient.left || nLeftPos > rcClient.right)
	{
		return;
	}

	CPoint ptOffSetBmp;
	int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight);
	ptOffSetBmp.x = nLeftPos < 0? -nLeftPos:0;
	ptOffSetBmp.y = nTopPos < rcClient.top? rcClient.top - nTopPos: 0;
	CRect rcRemainTimeClient(nLeftPos, rcClient.top, nRightPos-1, rcClient.bottom);
	Graphics gc(m_pBmpRemainTime);
	SolidBrush bkBrush(m_drawParam.bkColor);
	GraphicsContainer container = gc.BeginContainer();
	int nClipHeight = m_drawParam.nItemHeight*nCount;
	if (nClipHeight < rcClient.Height())
	{
		nClipHeight = rcClient.Height();
	}
	Rect rClip(0,0, rcRemainTimeClient.Width(), nClipHeight);
	gc.SetClip(rClip);
	Rect rDes(nLeftPos, nTopPos, rClip.Width, rClip.Height);
	gc.FillRectangle(&bkBrush, rClip);
	Gdiplus::StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetLineAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisCharacter);
	fmt.SetFormatFlags(StringFormatFlagsLineLimit);
	Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0);
	Rect rRowBk(0, 0, rcRemainTimeClient.Width(), m_drawParam.nItemHeight);
	CRect rcItem(0,0, rRowBk.Width,rRowBk.Height);
	for (int i = 0; i < nCount; i++)
	{
		ARGB clr = 0xff000000;
		ARGB clrBk = 0xffffffff;
		vData[i].GetMonColor(clr, clrBk);
		bkBrush.SetColor(clrBk);
		gc.FillRectangle(&bkBrush, rRowBk);
		CString strText = vData[i].GetValue(MONTYPE_TIMEREMAIN);
		GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt);
		//GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0xff000000,0,0,0,0,&fmt);
		gc.DrawLine(&pen, rcItem.left, rcItem.bottom-1, rcItem.right, rcItem.bottom-1);
		nTopPos += m_drawParam.nItemHeight;
		rcItem.OffsetRect(0, m_drawParam.nItemHeight);
		rRowBk.Offset(0, m_drawParam.nItemHeight);
	}

	gc.EndContainer(container);

	Graphics gcDes(pDC->GetSafeHdc());
	CRect rcDesClip(rcRemainTimeClient);
	Rect rDesClip = CRect2Rect(rcDesClip);
	gcDes.SetClip(rDesClip);
	gcDes.DrawImage(m_pBmpRemainTime, rDesClip, ptOffSetBmp.x, ptOffSetBmp.y, (INT)rDesClip.Width, (INT)rDesClip.Height, UnitPixel);

}
Пример #13
0
void CSimplePanelDlg::DrawBk()
{
	CDC* pDC = GetDC();

	CRect rc;
	GetClientRect(&rc);

	int nHeight = m_pImLineBK->GetHeight();
	int nWidth = m_pImLineBK->GetWidth();

	CEsayMemDC* pmemDC = new CEsayMemDC(*pDC, rc);
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);

	Gdiplus::Graphics gr(pmemDC->GetDC());
	gr.FillRectangle(&brush, rc.left, rc.top, rc.Width(), rc.Height());

	//顶部文字
	Gdiplus::SolidBrush brushBkWord(Gdiplus::Color(149,158,168));
	std::wstring str = L"第一辆车";

	Gdiplus::PointF pointFBkWord(60+nWidth, 0);
	Gdiplus::RectF rectBkWord(pointFBkWord, Gdiplus::SizeF(145, 46));
	Gdiplus::Font fontBkWord(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatBkWord;
	stringFormatBkWord.SetAlignment(Gdiplus::StringAlignmentFar);
	stringFormatBkWord.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第二辆车";

	pointFBkWord.X = 60 + nWidth + 145;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第一辆车";

	pointFBkWord.X = 60 + nWidth*2 + 145 * 2+ 100 + 10;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	str = L"第二辆车";

	pointFBkWord.X = 60 + nWidth * 2 + 145 * 3+ 100 + 10;
	rectBkWord.X = pointFBkWord.X;
	gr.DrawString(str.c_str(), str.size(), &fontBkWord, rectBkWord, &stringFormatBkWord, &brushBkWord);

	//底部分割线
	Gdiplus::SolidBrush brushLine(Gdiplus::Color(215, 215, 215));
	Gdiplus::Pen penLine(&brushLine, 1);

	gr.DrawLine(&penLine, Gdiplus::Point(rc.left, rc.bottom-1), Gdiplus::Point(rc.right, rc.bottom-1));

	//中间竖线
	Gdiplus::SolidBrush brushLineM(Gdiplus::Color(215, 215, 215));
	Gdiplus::Pen penLineM(&brushLineM, 2);

	gr.DrawLine(&penLineM, Gdiplus::Point(541, rc.top + 46), Gdiplus::Point(541, rc.top + nHeight*3 + 64));
	pmemDC->BltMem(*pDC);

	delete pmemDC;

	ReleaseDC(pDC);
}
Пример #14
0
BOOL CXTextGdiPlus::RefreashBufferDC(HDC hDCSrc)
{	
	ReleaseBufferDC();

	m_dcBuffer = ::CreateCompatibleDC(hDCSrc);
	m_hBufferOldBmp = ::SelectObject(m_dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(m_rcDst.Width(), m_rcDst.Height()));

	Gdiplus::Graphics graph(m_dcBuffer);
	graph.SetTextRenderingHint(m_Rendering);

	Gdiplus::FontFamily fontFamily(XLibST2W(m_strFontName));  
	Gdiplus::Font font(&fontFamily, m_nSize, m_FontStyle, Gdiplus::UnitPixel);  
	Gdiplus::StringFormat stringformat;
	stringformat.SetAlignment(m_AlignmentH);
	stringformat.SetLineAlignment(m_AlignmentV == Gdiplus::StringAlignmentCenter ?
		Gdiplus::StringAlignmentNear : m_AlignmentV);
	stringformat.SetFormatFlags(m_FormatFlags);
	stringformat.SetTrimming(Gdiplus::StringTrimmingEllipsisWord);
	Gdiplus::SolidBrush brush(Gdiplus::Color(m_cAlpha, m_ColorR, m_ColorG, m_ColorB));

	Gdiplus::RectF rfTargetRect(0, 0, m_rcDst.Width(), m_rcDst.Height());
	CStringW strTextToDraw(XLibST2W(m_strText));

	// When centering texts vertically, gdi+ will put the texts a litter higher, 
	// so we'll handle vertically centering ourselves. 
	if (m_AlignmentV == Gdiplus::StringAlignmentCenter)
	{
		Gdiplus::RectF rfBoundRect(0, 0, 0, 0);
		graph.MeasureString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &rfBoundRect);
		UINT nBufferWidth = rfTargetRect.Width, nBufferHeight = ceil(rfBoundRect.Height);

		UINT32 *pBufferBmp = NULL;
		HDC dcBuffer = ::CreateCompatibleDC(m_dcBuffer);
		HGDIOBJ hOldBmp = ::SelectObject(dcBuffer, (HGDIOBJ)Util::CreateDIBSection32(nBufferWidth, nBufferHeight, (BYTE **)&pBufferBmp));

		Gdiplus::Graphics graBuffer(dcBuffer);
		graBuffer.SetTextRenderingHint(m_Rendering);

		graBuffer.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush);

		CRect rcStrictBound(0, 0, nBufferWidth, nBufferHeight);
		BOOL bTopFound = FALSE, bBottomFound = FALSE;
		for (UINT line = 0; line < nBufferHeight; line++)
		{
			for (UINT col = 0; col < nBufferWidth; col++)
			{
				// bottom bits. 
				if (!bBottomFound && *(pBufferBmp + line * nBufferWidth + col) != 0)
				{
					bBottomFound = TRUE;
					rcStrictBound.bottom -= line;
				}

				// top bits. 
				if (!bTopFound && *(pBufferBmp + (nBufferHeight - line - 1) * nBufferWidth + col) != 0)
				{
					bTopFound = TRUE;
					rcStrictBound.top += line;
				}

				if (bBottomFound && bTopFound) break;
			}

			if (bBottomFound && bTopFound) break;
		}

		CRect rcTarget(0, (m_rcDst.Height() - rcStrictBound.Height()) / 2, 0, 0);
		rcTarget.right = rcTarget.left + rcStrictBound.Width();
		rcTarget.bottom = rcTarget.top + rcStrictBound.Height();

		Util::BitBlt(dcBuffer, rcStrictBound, m_dcBuffer, rcTarget);

		::DeleteObject(::SelectObject(dcBuffer, hOldBmp));
		::DeleteDC(dcBuffer);
	}
	else
		graph.DrawString(strTextToDraw, -1, &font, rfTargetRect, &stringformat, &brush);
	
	return TRUE;
}
Пример #15
0
BOOL CBSObject::DrawText(HDC hDC, const LPRECT lpRect, const CString& strText, 
							  HFONT hFont, COLORREF clrText, UINT uiFormat)
{
	BOOL bResult = FALSE;

#ifdef OSK 
	HFONT hFontOld = (HFONT)::SelectObject(hDC, hFont);
	COLORREF clrTextOld = ::SetTextColor(hDC, clrText);
	int nBkModeOld = ::SetBkMode(hDC, TRANSPARENT);

    if (::DrawText(hDC, strText, strText.GetLength(), lpRect, uiFormat))
	{
		bResult = TRUE;
	}

	if (hFontOld)
	{
		::SelectObject(hDC, hFontOld);
	}
	::SetTextColor(hDC, clrTextOld);
	::SetBkMode(hDC, nBkModeOld);
#else   
    Gdiplus::Graphics graphics(hDC);
    
    Gdiplus::SolidBrush brush(Gdiplus::Color(255, GetRValue(clrText), GetGValue(clrText), GetBValue(clrText)));
    Gdiplus::Font font(hDC, hFont);
    Gdiplus::RectF  rect(lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top);

	graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
	graphics.SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
         
    Gdiplus::StringFormat strformat;
    if (uiFormat & DT_TOP)
    {
        strformat.SetLineAlignment(Gdiplus::StringAlignmentNear);
    }

    if (uiFormat & DT_VCENTER)
    {
        strformat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
    }

    if (uiFormat & DT_BOTTOM)
    {
        strformat.SetLineAlignment(Gdiplus::StringAlignmentFar);
    }

    if (uiFormat & DT_LEFT)
    {
        strformat.SetAlignment(Gdiplus::StringAlignmentNear);
    }

    if (uiFormat & DT_CENTER)
    {
        strformat.SetAlignment(Gdiplus::StringAlignmentCenter);
    }

    if (uiFormat & DT_RIGHT)
    {
        strformat.SetAlignment(Gdiplus::StringAlignmentFar);
    }

    if ((uiFormat & DT_WORDBREAK) == 0)
    {
        strformat.SetFormatFlags(Gdiplus::StringFormatFlagsNoWrap);
    }

    if (uiFormat & DT_SINGLELINE)
    {

    }

    if (uiFormat & DT_WORD_ELLIPSIS)
    {
        strformat.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter);
    }

    if (uiFormat & DT_NOCLIP)
    {
        strformat.SetFormatFlags(Gdiplus::StringFormatFlagsNoClip);
    }

    graphics.DrawString(strText, -1, &font, rect, &strformat, &brush);


#endif
	return bResult;
}
Пример #16
0
void CClipMonView::OnDraw( CDC *pDC)
{
	CRect rcClient;
	TxGetClientRect(rcClient);
	Graphics gc(pDC->GetSafeHdc());
	SolidBrush bkBrush(m_drawParam.bkColor);
	Rect rCet = CRect2Rect(rcClient);
	gc.FillRectangle(&bkBrush, rCet);
	CSize szView = GetScrollViewSize();
	CRect rcView(0, 0, szView.cx, szView.cy);
	rcView.OffsetRect(rcClient.left, rcClient.top);

	if (rcView.IsRectEmpty())
	{
		return;
	}
	rcView.OffsetRect(-GetScrollPos(SB_HORZ), -GetScrollPos(SB_VERT));

	GraphicsContainer container = gc.BeginContainer();
	Rect rClip = CRect2Rect(rcClient);
	gc.SetClip(rClip);
	

	
	if (m_bUseBkBuffer)
	{
		CRect rcBuffToDraw(0,0,rcClient.Width(), rcClient.Height());
		rcBuffToDraw.OffsetRect(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
		if (!IsInRect(rcBuffToDraw, m_rcViewBkBuffer))
		{
			TRACE("\nbufferRedraw %d, %d", rcBuffToDraw.bottom, m_rcViewBkBuffer.bottom);
			ReDrawBkBuffer();
		}
		//draw bkbuffer
		m_BkBufferlock.Lock();
		rcBuffToDraw.OffsetRect(-m_rcViewBkBuffer.left, -m_rcViewBkBuffer.top);
		gc.DrawImage(m_pBmpBackBuffer, rClip, rcBuffToDraw.left, rcBuffToDraw.top, rcBuffToDraw.Width(), rcBuffToDraw.Height(), UnitPixel);
		m_BkBufferlock.Unlock();

	}
	else
	{
		int nBegin = (rcClient.top - rcView.top) / m_drawParam.nItemHeight;
		int nCount = rcClient.Height() /m_drawParam.nItemHeight +1;
		VECTMPITEM vData;
		g_monDataMgr.GetRangeData(nBegin, nCount, vData);
		nCount = vData.size();
		CTxListHeader& headerCtrl = GetListHeader();

		int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight);
		Gdiplus::StringFormat fmt;
		fmt.SetAlignment(StringAlignmentNear);
		fmt.SetLineAlignment(StringAlignmentCenter);
		fmt.SetTrimming(StringTrimmingEllipsisCharacter);
		fmt.SetFormatFlags(StringFormatFlagsLineLimit);
		Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0);
		Rect rRowBk(rcClient.left, nTopPos, rcClient.Width(), m_drawParam.nItemHeight);

		for (int i = 0; i < nCount; i++)
		{
			ARGB clr = 0xff000000;
			ARGB clrBk = 0xffffffff;
			vData[i].GetMonColor(clr, clrBk);
			bkBrush.SetColor(clrBk);
			gc.FillRectangle(&bkBrush, rRowBk);
			int nLeftPos = rcView.left;
			CRect rcItem(nLeftPos,nTopPos, 0, nTopPos + m_drawParam.nItemHeight);
			for (int cIdx = 0;  cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++)
			{
				if (rcItem.left > rcClient.right)
				{
					break;
				}
				rcItem.right = rcItem.left + headerCtrl.GetHeaderWidth(cIdx);
				if (rcItem.right >= rcClient.left)
				{
					CString strText = vData[i].GetValue((ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType));
					GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt);
					//GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0xff000000,0,0,0,0,&fmt);
					//draw separate line
					gc.DrawLine(&pen, rcItem.right-1, rcItem.top, rcItem.right-1, rcItem.bottom);

				}
				rcItem.OffsetRect(rcItem.Width(), 0);

			}
			gc.DrawLine(&pen, rcClient.left, rcItem.bottom-1, rcClient.right, rcItem.bottom-1);
			nTopPos += m_drawParam.nItemHeight;

			rRowBk.Offset(0, m_drawParam.nItemHeight);
		}
	}
	

	//calc In Bound Item
	gc.EndContainer(container);
	ReDrawRemainTime(pDC);

}
Пример #17
0
void CClipMonView::ReDrawBkBuffer()
{
	if (!m_bUseBkBuffer)
	{
		return;
	}
	CSize szView = GetScrollViewSize();
	if (szView.cx == 0 || szView.cy == 0)
	{
		return;
	}
	
	CRect rcClient;
	TxGetClientRect(rcClient);
	CRect rcViewShowBuffer(rcClient);
	rcViewShowBuffer.MoveToXY(0,0);

	rcViewShowBuffer.OffsetRect(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
	
	CRect rcBk(0,0, m_szbmpBackBuffer.cx, m_szbmpBackBuffer.cy);
	rcBk = GetCenterRect(rcViewShowBuffer, rcBk);
	
	if (rcBk.left < 0)
	{
		rcBk.MoveToX(0);
	}
	if (rcBk.top < 0)
	{
		rcBk.MoveToY(0);
	}
	m_rcViewBkBuffer = rcBk;
	m_BkBufferlock.Lock();
	ASSERT(m_pBmpBackBuffer != NULL);
	Graphics gc(m_pBmpBackBuffer);
	SolidBrush bkBrush(m_drawParam.bkColor);
	Rect rCet = CRect2Rect(CRect(0,0, rcBk.Width(),  rcBk.Height()));
	gc.FillRectangle(&bkBrush, rCet);
	CRect rcView(0, 0, szView.cx, szView.cy);
	//calc In Bound Item
	int nBegin = (rcBk.top - rcView.top) / m_drawParam.nItemHeight;
	int nCount = rcBk.Height() /m_drawParam.nItemHeight +1;
	VECTMPITEM vData;
	g_monDataMgr.GetRangeData(nBegin, nCount, vData);
	nCount = vData.size();
	if (nCount == 0)
	{
		return;
	}
	CTxListHeader& headerCtrl = GetListHeader();
	int nTopPos = rcView.top + (nBegin * m_drawParam.nItemHeight)- rcBk.top;
	Gdiplus::StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetLineAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisCharacter);
	fmt.SetFormatFlags(StringFormatFlagsLineLimit|StringFormatFlagsNoWrap);
	Pen pen(g_globalInfo.viewSetting.clrSeparateLine, 1.0);
	Rect rRowBk(0, nTopPos, rcBk.Width(), m_drawParam.nItemHeight);

	for (int i = 0; i < nCount; i++)
	{
		ARGB clr = 0xff000000;
		ARGB clrBk = 0xffffffff;
		vData[i].GetMonColor(clr, clrBk);
		bkBrush.SetColor(clrBk);
		gc.FillRectangle(&bkBrush, rRowBk);
		int nLeftPos = 0-rcBk.left;
		CRect rcItem(nLeftPos,nTopPos, 0, nTopPos + m_drawParam.nItemHeight);
		for (int cIdx = 0;  cIdx < m_ColSetting.m_vTmpCols.size(); cIdx++)
		{
			if (rcItem.left > rcBk.right)
			{
				break;
			}
			rcItem.right = rcItem.left + headerCtrl.GetHeaderWidth(cIdx);
			if (rcItem.right >= rcBk.left)
			{
				ENUM_MONTYPE nMonType = (ENUM_MONTYPE)(m_ColSetting.m_vTmpCols[cIdx].nPosInType);
				if (nMonType != MONTYPE_TIMEREMAIN)
				{
					CString strText = vData[i].GetValue(nMonType);
					GPDrawShadowTextSimple(gc, strText, rcItem, *m_drawParam.pFont, clr, 0, 2,2, &fmt);
					//GPDrawShadowText(gc, strText, rcItem, *m_drawParam.pFont, clr, 0x22000000,0,0,0,0,&fmt);
				}
				//draw separate line
				gc.DrawLine(&pen, rcItem.right-1, rcItem.top, rcItem.right-1, rcItem.bottom);

			}
			rcItem.OffsetRect(rcItem.Width(), 0);

		}
		gc.DrawLine(&pen, rcBk.left, rcItem.bottom-1, rcBk.right, rcItem.bottom-1);
		nTopPos += m_drawParam.nItemHeight;

		rRowBk.Offset(0, m_drawParam.nItemHeight);
	}

	m_BkBufferlock.Unlock();
}
Пример #18
0
void CSimplePanelDlg::DrawArrive(Gdiplus::Graphics& gr, vector<BusArrivalInfo>& vecArrival, CRect& rc, CData* pData)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示线路号
	CString strLineNum = pData->GetLineNumber();
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	if(0 < vecArrival.size())
	{
		//显示第一辆车到站
		BusArrivalInfo& stArrive = vecArrival[0];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

	if(1 < vecArrival.size())
	{
		//显示第二辆车到站
		BusArrivalInfo& stArrive = vecArrival[1];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

}
Пример #19
0
void CSimplePanelDlg::DrawEmpty(Gdiplus::Graphics& gr, CRect& rc)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示--
	CString strLineNum = "--";
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	//第一辆车距离站
	if(1)
	{
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);	
	}


	if(1)
	{
		//第二辆车距离站
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145 + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
	}


}