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;
}
Beispiel #2
0
void GPDrawShadowTextSimple( Graphics&gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ )
{
	Gdiplus::Font& gcfont = fontIn;
	Rect rcText = CRect2Rect(rcIn);
	StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisWord);
	fmt.SetLineAlignment(StringAlignmentCenter);
	StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn;

	GraphicsContainer  gcContainer = gc.BeginContainer();
	gc.SetSmoothingMode(SmoothingModeAntiAlias);
	CComBSTR btrTxtIn(strTxtIn);

	SolidBrush textbrush(ARGB2Color(shadowBrushClrIn));
	RectF rfText = Rect2RectF(rcText);
	if (shadowBrushClrIn != 0)
	{
		rfText.Offset(1.0, 1.0);
		gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
	}

	textbrush.SetColor(ARGB2Color(BrushClrIn));
	gc.DrawString(btrTxtIn, -1, &gcfont, rfText, &fmtUse, &textbrush);
	gc.EndContainer(gcContainer);
}
Beispiel #3
0
void UILabel::onPaintText(Graphics& graphics, Rect rect)
{
    StringFormat stringFormat;
    stringFormat.SetTrimming(m_font.m_trimming);
    stringFormat.SetAlignment(m_font.m_horizen);
    stringFormat.SetLineAlignment(m_font.m_vertical);

    Font font(m_font.m_family, m_font.m_size, m_font.m_style, m_font.m_unit);
    SolidBrush brush(getTrueColor(m_font.m_color));
    graphics.DrawString(m_font.m_text, -1, &font, m_font.m_rect, &stringFormat, &brush);
}
Beispiel #4
0
void GPDrawShadowText( Graphics& gc, CString& strTxtIn, CRect& rcIn, Gdiplus::Font& fontIn, ARGB BrushClrIn, ARGB PenClrIn , ARGB shadowPenClrIn /*= 0xff000000*/, ARGB shadowBrushClrIn /*= 0xff000000*/, int nOffXIn /*= 2*/, int nOffYIn /*= 2*/, StringFormat* fmtIn /*= NULL*/ )
{
	Gdiplus::Font& gcfont = fontIn;
	FontFamily fmy;
	gcfont.GetFamily(&fmy);
	int nfontStyle  = gcfont.GetStyle();
	REAL dFontSize = gcfont.GetSize();
	Rect rcText = CRect2Rect(rcIn);
	StringFormat fmt;
	fmt.SetAlignment(StringAlignmentCenter);
	fmt.SetTrimming(StringTrimmingEllipsisWord);
	fmt.SetLineAlignment(StringAlignmentCenter);
	StringFormat& fmtUse = fmtIn == NULL? fmt:*fmtIn;

	GraphicsContainer  gcContainer = gc.BeginContainer();
	gc.SetSmoothingMode(SmoothingModeAntiAlias);
	CComBSTR btrTxtIn(strTxtIn);
	GraphicsPath textPath;
	textPath.AddString(btrTxtIn, -1,  &fmy, nfontStyle, dFontSize, rcText, &fmtUse);

	Matrix mx;
	mx.Translate(nOffXIn, nOffYIn);
	textPath.Transform(&mx);

	Pen textPen(ARGB2Color(shadowPenClrIn), 1);
	SolidBrush textbrush(ARGB2Color(shadowBrushClrIn));
	textPen.SetLineJoin(LineJoinRound);
	if (shadowBrushClrIn != 0)
	{
		gc.FillPath(&textbrush, &textPath);
	}
	if (shadowPenClrIn != 0)
	{
		gc.DrawPath(&textPen, &textPath);
	}



	mx.Invert();
	textPath.Transform(&mx);
	textPen.SetColor(ARGB2Color(PenClrIn));
	textbrush.SetColor(ARGB2Color(BrushClrIn));
	if (BrushClrIn != 0)
	{
		gc.FillPath(&textbrush, &textPath);
	}
	if (PenClrIn != 0)
	{
		gc.DrawPath(&textPen, &textPath);
	}
	gc.EndContainer(gcContainer);
}
void ProcessDateTime::SetStringFormat(StringFormat &format)
{
	UINT formatFlags;

	formatFlags = Gdiplus::StringFormatFlagsNoFitBlackBox
		| Gdiplus::StringFormatFlagsMeasureTrailingSpaces;


	format.SetFormatFlags(formatFlags);
	format.SetTrimming(Gdiplus::StringTrimmingWord);

	format.SetAlignment(Gdiplus::StringAlignmentNear);


}
void CSkinList::Draw(CDIB &tmp)
{
	CRect r;
	GetClientRect(&r);

	tmp.Resize(r.Width(), r.Height());
	if(!tmp.Ready())
	{
		return;
	}

	RectF rf(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
	RectF rx;

	Graphics g(tmp.dc);
	g.SetCompositingMode(CompositingModeSourceOver);

	if(bckg->Ready())
	{
		tmp.Draw(tmp.Rect(), 0, 0, bckg, DrawFlagsReflectDest);
	}

	if(dib->Ready())
	{
		g.DrawImage(dib->bmp, 0.0f, r.Height() * 0.36f);

		Font font(L"Arial", 9.0f);
		StringFormat *stringFormat = new StringFormat();
		stringFormat->SetAlignment(StringAlignmentCenter);
		stringFormat->SetLineAlignment(StringAlignmentCenter);
		stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);

		CString s;
		s.Format(L"%s\n%s", skin->name.GetBuffer(), skin->description.GetBuffer());
		
		RectF rx(0, 0, (REAL)dib->Width(), r.Height() * 0.36f);

		rx.Y++;
		SolidBrush brush(0xfff0f0f0);
		g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush);

		rx.Y--;
		brush.SetColor(0xff000000);
		g.DrawString(s.GetBuffer(), s.GetLength(), &font, rx, stringFormat, &brush);

		delete stringFormat;
	}
}
int 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;
}
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;
	}
}
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;
}
/*
** 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;
}
Beispiel #11
0
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);
}
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);
	}
}
Beispiel #13
0
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 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;
}
/////////////////////////////////////////////////////////////////////////////////////////
// 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);
}
Beispiel #16
0
void CDrawWarn::Draw(CDC* pDC)
{
	ASSERT_VALID(this);
	CRect rect = m_position;
	rect.NormalizeRect();

	if(rect.Width() < 10 || rect.Height()<10)
		return;

	pStrWarn = new STRWARN[m_nColCount];
	AddWarn("1","2004/12/12","12:00","高报警","电压过低");
	AddWarn("2","2004/12/12","12:00","高报警","电压过低");
	AddWarn("3","2004/12/12","12:00","高报警","电压过低");
	AddWarn("4","2004/12/12","12:00","高报警","电压过低");
	AddWarn("5","2004/12/12","12:00","高报警","电压过低");
	AddWarn("6","2004/12/12","12:00","高报警","电压过低");
	AddWarn("7","2004/12/12","12:00","高报警","电压过低");
	AddWarn("8","2004/12/12","12:00","高报警","电压过低");
	AddWarn("9","2004/12/12","12:00","高报警","电压过低");
	AddWarn("10","2004/12/12","12:00","高报警","电压过低");
	AddWarn("11","2004/12/12","12:00","高报警","电压过低");
	AddWarn("12","2004/12/12","12:00","高报警","电压过低");

	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 Textgraphics (pDC->m_hDC);
	SolidBrush  solidBrush(crBackColor);
	SolidBrush  TitleBrush(crTitleColor);
	SolidBrush  TextBrush(crTextColor);
	Pen pen(crLineColor,1);
	
	graphics.FillRectangle(&solidBrush,GdiRect);

	BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName);
///	WCHAR *fn = new unsigned short[m_fontName.GetLength()+1];;
///	wcscpy(fn,bstr);
				
	FontFamily  fontFamily(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();
///				int len = m_strButton.GetLength();
				bstr = _com_util::ConvertStringToBSTR(m_strButton);
///				WCHAR *strButton = new unsigned short[len];
///				wcscpy(strButton,bstr);
				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);
			}
			else					//画文字
			{
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentNear);
				stringFormat.SetLineAlignment(StringAlignmentNear);

				CString strWarn;
				if(i == 1)
					strWarn = pStrWarn[j].strPoint;
				if(i == 2)
					strWarn = pStrWarn[j].strDate;
				if(i == 3)
					strWarn = pStrWarn[j].strTime;
				if(i == 4)
					strWarn = pStrWarn[j].strText;
				if(i == 5)
					strWarn = pStrWarn[j].strWarn;

				strWarn.TrimRight();
///				int len = strWarn.GetLength();
				bstr = _com_util::ConvertStringToBSTR(strWarn);
///				WCHAR *strButton = new unsigned short[len];
///				wcscpy(strButton,bstr);
				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);
			}
		}
	}
	graphics.ReleaseHDC(pDC->m_hDC);
}