Exemple #1
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);
}
void TextSegment::Paint(Graphics &g, TextArea *theTextArea, int theStartChar, int theEndChar, int xpos, int ypos, int lineHeight)
{
	int aSelStartChar = theTextArea->mSelStartChar - mAbsStartChar;
	int aSelEndChar = theTextArea->mSelEndChar - mAbsStartChar;

	if(theStartChar > aSelStartChar)
		aSelStartChar = theStartChar;

	if(theEndChar < aSelEndChar)
		aSelEndChar = theEndChar;

	g.SetColor(mColor);	
	g.SetFont(mFont);
	
	bool fullSelection = aSelStartChar==theStartChar && aSelEndChar==theEndChar;
	if(!fullSelection)
		g.DrawString(mText, theStartChar, theEndChar - theStartChar, xpos, ypos);

	if(aSelEndChar > aSelStartChar)
	{
		int x = xpos + mFont->GetStringWidth(mText,theStartChar,aSelStartChar-theStartChar);
		int aWidth = mFont->GetStringWidth(mText,aSelStartChar,aSelEndChar-aSelStartChar);

		g.SetColor(theTextArea->mSelColor.GetBackgroundColor(g));
		g.FillRect(x,0,aWidth,lineHeight);
		
		g.SetColor(theTextArea->mSelColor.GetForegroundColor(g,mColor));
		g.DrawString(mText,aSelStartChar,aSelEndChar-aSelStartChar,x,ypos);
	}
}
static REAL DrawMessage(Graphics &g, const WCHAR *msg, REAL y, REAL dx, Color color)
{
    ScopedMem<WCHAR> s(str::Dup(msg));

    Font f(L"Impact", 16, FontStyleRegular);
    RectF maxbox(0, y, dx, 0);
    RectF bbox;
    g.MeasureString(s, -1, &f, maxbox, &bbox);

    bbox.X += (dx - bbox.Width) / 2.f;
    StringFormat sft;
    sft.SetAlignment(StringAlignmentCenter);
    if (trans::IsCurrLangRtl())
        sft.SetFormatFlags(StringFormatFlagsDirectionRightToLeft);
#if DRAW_MSG_TEXT_SHADOW
    {
        bbox.X--; bbox.Y++;
        SolidBrush b(Color(0xff, 0xff, 0xff));
        g.DrawString(s, -1, &f, bbox, &sft, &b);
        bbox.X++; bbox.Y--;
    }
#endif
    SolidBrush b(color);
    g.DrawString(s, -1, &f, bbox, &sft, &b);

    return bbox.Height;
}
void CIGPropertyManager::DrawProperty (const pair<wstring,wstring>& prop, const RectF& rcfNameProp, const RectF& rcfValueProp, Graphics& graphics)
{
	static FontFamily fontFamily (L"Times New Roman");
	static Font fontRegular (&fontFamily, 12, FontStyleRegular, UnitPixel);
	static Font fontItalic (&fontFamily, 12, FontStyleItalic, UnitPixel);
	static SolidBrush backgroundBrush (IGPROPERTYMANAGER_COLOR_BACKGROUND);
	static SolidBrush  solidFontBrush (IGPROPERTYMANAGER_COLOR_FONT);
	static StringFormat	format (StringFormat::GenericDefault());
	graphics.FillRectangle (&backgroundBrush, Rect (Point ((int)rcfNameProp.X, (int)rcfNameProp.Y), Size ((int)(rcfNameProp.Width + rcfValueProp.Width), (int)rcfNameProp.Height)));
	graphics.DrawString (prop.first.c_str(), -1, &fontItalic, rcfNameProp, &format, &solidFontBrush);
	graphics.DrawString (prop.second.c_str(), -1, &fontRegular, rcfValueProp, &format, &solidFontBrush);
}
Exemple #5
0
	//*************************************************************************
	// Method:		MeasureDisplayString
	// Description: Gets the size of a string in pixels
	//
	// Parameters:
	//	graphics - the graphics object the string will be measured on
	//	test - the string to measure
	//	font - the font to measure the string in
	//
	// Return Value: the size of the string
	//*************************************************************************
	SizeF StringTools::MeasureDisplayString(Graphics *graphics, String *text, Font *font)
	{
		const int width = 32;

		Bitmap *bitmap = new Bitmap(width, 1, graphics);
		SizeF size = graphics->MeasureString(text, font);
		Graphics *g = Graphics::FromImage(bitmap);

		int measuredWidth = (int)size.Width;
		if (g)
		{
			g->Clear(Color::White);
			g->DrawString(String::Concat(text, "|"), font, Brushes::Black, (float)(width - measuredWidth), (float)(0 - (font->Height / 2)));

			for (int i = width - 1; i >= 0; i--)
			{
				measuredWidth--;
				if (bitmap->GetPixel(i, 0).R == 0)
				{
					break;
				}
			}
		}

		return SizeF((float)measuredWidth, size.Height);
	}
void BadUserItem::Paint(Graphics &g, ListArea *theListArea)
{
	int aColor = theListArea->GetTextColor();
	if(mSelected)
		aColor = theListArea->GetSelColor().GetForegroundColor(g,aColor);

	int aPaintCol = 0;
	bool drawSelection = mSelected;
	if(!mIsSimple)
	{
		aPaintCol = ((MultiListArea*)theListArea)->GetColumnPaintContext();
		if(aPaintCol!=-1)
			drawSelection = false;
	}
	
	
	if(drawSelection)
	{
		g.SetColor(theListArea->GetSelColor().GetBackgroundColor(g));
		g.FillRect(0,0,theListArea->GetPaintColumnWidth(),mFont->GetHeight());
		if(!mIsSimple)
			return;
	}
	if(aPaintCol<0 || aPaintCol>5)
		return;

	g.SetColor(aColor);
	g.SetFont(mFont);
	g.DrawString(mColStr[aPaintCol],0,0);
}
Exemple #7
0
void
MFCInstanceView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	Pen			blackPen(AlphaColor(250, rgb_black), 1);
	Pen			redPen(AlphaColor(250, rgb_red), 1);
	SolidBrush	blueBrush(AlphaColor(100, rgb_blue));
	SolidBrush	blackBrush(AlphaColor(100, rgb_black));

	CRect		clipBounds = bounds;
	if (clipBox.left > bounds.left) clipBounds.left = clipBox.left-1;
	if (clipBox.right < bounds.right) clipBounds.right = clipBox.right+1;

	cerr << "ondraw instance view " << clipBox.left << ", " << clipBox.right << endl;
	dc.FillRectangle(&blueBrush,
			bounds.left, bounds.top, bounds.right-bounds.left, bounds.bottom-bounds.top);
	dc.DrawRectangle(selected?&redPen:&blackPen,
			bounds.left, bounds.top, clipBounds.right-bounds.left, bounds.bottom-bounds.top);
	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = instance->sym->uniqueName();
	while (*cp) { nm.push_back(*cp++); }
	float lbx = bounds.left+2;
#define LBLSEP 200
	if (clipBox.left > lbx) {
		int nld = clipBox.left - lbx;
		nld = nld/LBLSEP;
//		if (nld > 2) lbx += (nld-2)*LBLSEP;
	}
	PointF	p(lbx, clipBounds.top);
	do {
		dc.DrawString(nm.c_str(), -1, &labelFont, p, &blackBrush);
		p.X += LBLSEP;
	} while (p.X < clipBounds.right);
}
void WrappedText::Paint(Graphics &g, int x, int y)
{
	if(mRichText.get()!=NULL)
	{
		ElementPaintInfo anInfo;
		anInfo.mClipX = x;
		anInfo.mClipY = y;
		anInfo.mClipWidth = GetWidth();
		anInfo.mClipHeight = GetHeight();
		anInfo.mStartSelSegment = anInfo.mEndSelSegment = -1;
		mRichText->Paint(g,x,y,anInfo);
		return;
	}

	if(mFont.get()==NULL)
		return;

	g.SetFont(mFont);

	int aYPos = y;
	int aStrPos = 0;
	for(BreakList::iterator anItr = mBreakList.begin(); anItr!=mBreakList.end(); ++anItr)
	{
		if(aStrPos>=mText.length())
			break;

		int aBreakPos = anItr->mBreakPos;
		int anXPos = x;
		if(mIsCentered)
			anXPos += (mWidth - anItr->mWidth)/2;

		g.DrawString(mText, aStrPos, aBreakPos - aStrPos, anXPos, aYPos);
		aYPos += mFont->GetHeight();
		aStrPos = anItr->mNextStartPos;
	}
	if(aStrPos<mText.length())
	{
		if(mIsCentered && !mBreakList.empty())
		{
			int aWidth = mFont->GetStringWidth(mText,aStrPos,mText.length()-aStrPos);
			int anXPos = x + (mWidth - aWidth)/2;
			g.DrawString(mText, aStrPos, mText.length()-aStrPos, anXPos, aYPos);
		}
		else
			g.DrawString(mText, aStrPos, mText.length()-aStrPos, x, aYPos);
	}
}	
void ParticalEffect::draw(Graphics& graphics) {
    for (int x = 0; x < count; x ++) {
        if(partsA[x].active) {
            graphics.DrawString(800,110,"Drawing Partical");
            partsA[x].draw(graphics);
        }
    }
    timeTOLive--;
}
Exemple #10
0
void CArcView::Draw(CDC* pDC, const std::vector<CElement*>& selection, CElement* highlight)
{
	computeCollisionPoints(FALSE);
	computeEnclosingRect(FALSE);

	Graphics g = pDC->GetSafeHdc();
	g.SetSmoothingMode(SmoothingModeAntiAlias);
	Color theColor = ColorToDraw(selection, highlight);
	Pen pen(theColor, static_cast<Gdiplus::REAL>(penWidth));
	GraphicsPath arc;

	Point currentPoint(*pathPoints.begin());
	for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it)
	{
		arc.AddLine(currentPoint, *it);
		currentPoint = *it;
	}

	//Annotation de poids
	if(arcModel->getValuation() != 1)
	{
		//Déterminer le point de mi-chemin
		PointF pathAnnotationPoint = annotationPoint((double(valPosition))/100, valDistance);

		//Elements de dessin pour chaine de caracteres
		CString weight;
		weight.Format(_T("%d"), arcModel->getValuation());
		FontFamily fontFamily(L"Arial");
		Font maxfont(&fontFamily, 16, FontStyleRegular, UnitPixel);
		StringFormat stringFormat;
		SolidBrush brush(ColorToDraw(selection, highlight));

		//Décalage à effectuer
		//Peut-être aurait-il suffit de modifier le StringFormat ?
		RectF boundingBox;
		g.MeasureString(weight,-1,&maxfont,pathAnnotationPoint,&stringFormat,&boundingBox);
		pathAnnotationPoint.X -= boundingBox.Width/2;
		pathAnnotationPoint.Y += boundingBox.Height/2;

		//Translation + Symétrie axiale d'axe des abscisses
		g.TranslateTransform(0, pathAnnotationPoint.Y * 2);
		Matrix matrix;
		matrix.SetElements(1, 0, 0, -1, 0, 0);
		g.MultiplyTransform(&matrix);

		//Affichage du poids de l'arc
		g.DrawString(weight, -1, &maxfont, pathAnnotationPoint, &stringFormat, &brush);
		g.ResetTransform();
	}

	//Dessiner le chemin avec une flèche au bout
	pen.SetCustomEndCap(arrowCap);
	pen.SetLineJoin(LineJoinRound);
	g.DrawPath(&pen, &arc);
}
Exemple #11
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);
}
Exemple #12
0
static void DrawSumatraLetters(Graphics &g, Font *f, Font *fVer, REAL y)
{
    LetterInfo *li;
    WCHAR s[2] = { 0 };
    for (int i = 0; i < dimof(gLetters); i++) {
        li = &gLetters[i];
        s[0] = li->c;
        if (s[0] == ' ')
            return;

        g.RotateTransform(li->rotation, MatrixOrderAppend);
#if DRAW_TEXT_SHADOW
        // draw shadow first
        SolidBrush b2(li->colShadow);
        PointF o2(li->x - 3.f, y + 4.f + li->dyOff);
        g.DrawString(s, 1, f, o2, &b2);
#endif

        SolidBrush b1(li->col);
        PointF o1(li->x, y + li->dyOff);
        g.DrawString(s, 1, f, o1, &b1);
        g.RotateTransform(li->rotation, MatrixOrderAppend);
        g.ResetTransform();
    }

    // draw version number
    REAL x = gLetters[dimof(gLetters)-1].x;
    g.TranslateTransform(x, y);
    g.RotateTransform(45.f);
    REAL x2 = 15;
    REAL y2 = -34;

    WCHAR *ver_s = L"v" CURR_VERSION_STR;
#if DRAW_TEXT_SHADOW
    SolidBrush b1(Color(0, 0, 0));
    g.DrawString(ver_s, -1, fVer, PointF(x2 - 2, y2 - 1), &b1);
#endif
    SolidBrush b2(Color(0xff, 0xff, 0xff));
    g.DrawString(ver_s, -1, fVer, PointF(x2, y2), &b2);
    g.ResetTransform();
}
Exemple #13
0
void IGTabBar::drawTab (HDC hdc, UINT nSize, bool bSelected, bool bOver, const wchar_t *pcwTitle)
{
	Graphics graphics (hdc);
	Color colBackground (Color (GetRValue (m_cBackGround), GetGValue (m_cBackGround), GetBValue (m_cBackGround)));
	SolidBrush solBrushBackground (colBackground);
	graphics.FillRectangle (&solBrushBackground, Rect (0, 0, nSize, BUTTON_HEIGHT - 1));

	SolidBrush solBrushTab (bSelected ? IGTAB_COLORBACKGND : IGTAB_COLOR_UNSELECTED);
	GraphicsPath pathBorder;
	pathBorder.StartFigure();
	pathBorder.AddArc (Rect (0, 0, IGTAB_CORNERDIAM, IGTAB_CORNERDIAM), 180.0f, 90.0f);
	pathBorder.AddArc (Rect (nSize - IGTAB_CORNERDIAM, 0, IGTAB_CORNERDIAM, IGTAB_CORNERDIAM), -90.0f, 90.0f);
	pathBorder.AddLine (Point (nSize, BUTTON_HEIGHT + (bSelected ? 1 : 0)), Point (0, BUTTON_HEIGHT + (bSelected ? 1 : 0)));
	graphics.FillPath (&solBrushTab, &pathBorder);

	if (bOver)
	{
		PathGradientBrush pthGrBrush (&pathBorder);
		pthGrBrush.SetCenterPoint (PointF (0.7f * (float)nSize,
										  0.3f * (float)BUTTON_HEIGHT));
		pthGrBrush.SetCenterColor (IGTAB_COLOR_FRAMEIN);
		Color colors[] = {IGTAB_COLOR_FRAMEOUT};
		int count = 1;
		pthGrBrush.SetSurroundColors (colors, &count);
		graphics.FillPath (&pthGrBrush, &pathBorder);
	}

	FontFamily fontFamily(L"Times New Roman");
	Font font(&fontFamily, 16, FontStyleRegular, UnitPixel);
	PointF      pointF(20.0f, 5.0f);
	SolidBrush  solidFontBrush (bSelected ? IGTAB_COLOR_FONTENABLED : IGTAB_COLOR_FONTDISABLED);
	StringFormat	format(StringFormat::GenericDefault());
	format.SetAlignment (StringAlignmentCenter);
	graphics.DrawString (pcwTitle, -1, &font, RectF (0.0f, 0.0f, (float)nSize, (float)BUTTON_HEIGHT),
							&format, &solidFontBrush);

	Pen penBorder (IGTAB_COLORBORDER, 1);
	GraphicsPath pathBorderOut;
	pathBorderOut.StartFigure();
	pathBorderOut.AddArc (Rect (0, 0, IGTAB_CORNERDIAM + 1, IGTAB_CORNERDIAM + 1), 180.0f, 90.0f);
	pathBorderOut.AddArc (Rect (nSize - IGTAB_CORNERDIAM - 2, 0, IGTAB_CORNERDIAM + 1, IGTAB_CORNERDIAM + 1), -90.0f, 90.0f);
	pathBorderOut.AddLine (Point (nSize - 1, BUTTON_HEIGHT + (bSelected ? 1 : 0)), Point (0, BUTTON_HEIGHT + (bSelected ? 1 : 0)));
	pathBorderOut.CloseFigure();
	graphics.DrawPath (&penBorder, &pathBorderOut);
}
///////////////////////////////////////////////////////////////////////////////
// Paint: Draw the credits.
///////////////////////////////////////////////////////////////////////////////
void ScrollingTextComponent::Paint(Graphics &g)
{
	Component::Paint(g);

	// Draw the background.
	g.SetFont(GetDefaultFont());
	g.SetColor(0xFFFFFF);
	g.FillRect(2,2,Width()-4,Height()-4);

	// Draw the frame.
	g.ApplyColorSchemeColor(StandardColor_3DHilight);
	g.DrawRect(0,0,Width(),Height());
	g.DrawRect(1,1,Width()-1,Height()-1);
	g.ApplyColorSchemeColor(StandardColor_3DShadow);
	g.DrawRect(0, 0,Width()-1,Height()-1);

	// Draw the text.
	int nTop = mScrollTop;
	CreditsList::iterator Itr = mLines.begin();

	while (Itr != mLines.end())
	{
		CreditLineInfo& LineInfo = *Itr;
		int nStrHt = g.GetFont()->GetHeight();

		if (nTop < Height() / 3)
			g.SetColor(DimColor(LineInfo.GetColor(), nTop * 100 / (Height() / 3)));
		else if (Height() - nTop <= nStrHt)
			g.SetColor(0xFFFFFF);
		else if (nTop > (Height() * 2 / 3) - nStrHt)
			g.SetColor(DimColor(LineInfo.GetColor(), ((Height() - (nTop + nStrHt)) * 100 / (Height() / 3))));
		else
			g.SetColor(LineInfo.GetColor());

		if (g.GetColor() != 0xFFFFFF && nTop > 2 && nTop < Height() - nStrHt - 2)
		{
			int nStrWd = g.GetFont()->GetStringWidth(LineInfo.GetLine());
			g.DrawString(LineInfo.GetLine(), (Width() - nStrWd) / 2, nTop);
		}
		nTop += nStrHt;
		++Itr;
	}
	mTotalTextHeight = nTop - mScrollTop;
}
void CToolRegularRuler::DrawRulerMarks(Graphics& graph)
{
	int nNumber = 0;
	int nbegin = m_rcHot.left + 10;
	int nend = m_rcHot.right - 10;

	CString strNumber;
	Font fontNumber(L"Arial", 10);
	SolidBrush brush(Color::Black);
	StringFormat format;
	format.SetAlignment(StringAlignmentCenter);

	Pen penDraw(Color::Black, 1);
	PointF ptBegin((float)nbegin, m_rcHot.top + 1.0f);
	PointF ptEnd = ptBegin;
	graph.SetTextRenderingHint(TextRenderingHintAntiAlias);

	for(int i = nbegin; i < nend; i+= 10)
	{
		ptEnd.X = (float)i;
		ptBegin.X = (float)i;
		if((i - nbegin) % 100 == 0)
		{
			ptEnd.Y = ptBegin.Y + 30;
			graph.DrawLine(&penDraw, ptBegin, ptEnd);
			nNumber = (i - nbegin) / 100;
			strNumber.Format(_T("%d"), nNumber);
			
			graph.DrawString(strNumber, strNumber.GetLength(), &fontNumber, ptEnd, &format, &brush);
		}
		else if((i - nbegin) % 50 == 0)
		{
			ptEnd.Y = ptBegin.Y + 20;
			graph.DrawLine(&penDraw, ptBegin, ptEnd);
		}
		else
		{
			ptEnd.Y = ptBegin.Y + 10;
			graph.DrawLine(&penDraw, ptBegin, ptEnd);
		}
	}
}
Exemple #16
0
void CZoneView::DrawLabel(CDC* pDC, const std::vector<CElement*>& selection, CElement* highlight) const
{
	//Propriétés de la chaine de caractère
	FontFamily fontFamily(L"Times New Roman");
	Font maxfont(&fontFamily, 12, FontStyleRegular, UnitPixel);
	StringFormat stringFormat;
	stringFormat.SetAlignment(StringAlignmentNear);
	stringFormat.SetLineAlignment(StringAlignmentNear);
	SolidBrush brush(Color::Firebrick);
	RectF enclosingRectF(enclosingRect->X + 0.1*GRID_CELL_LENGTH,
		enclosingRect->Y + 0.1*GRID_CELL_LENGTH,
		enclosingRect->Width, enclosingRect->Height);

	//Dessin avec translation + symétrie axiale d'axe des abscisses
	Graphics g = pDC->GetSafeHdc();
	g.TranslateTransform(0, position.Y * 2);
	Matrix matrix;
	matrix.SetElements(1, 0, 0, -1, 0, 0);
	g.MultiplyTransform(&matrix);
	g.DrawString(label, -1, &maxfont, enclosingRectF, &stringFormat, &brush);
	g.ResetTransform();
}
Exemple #17
0
void FontSheet::BuildFontSheetBitmap(Font& font,
												 Graphics& charGraphics, 
												 Bitmap& charBitmap, 
												 Graphics& fontSheetGraphics)
{
	WCHAR charString[2] = {' ', 0};
	SolidBrush whiteBrush(Color(255, 255, 255, 255));
	UINT fontSheetX = 0;
	UINT fontSheetY = 0;
	for(UINT i = 0; i < NumChars; ++i)
	{
		charString[0] = static_cast<WCHAR>(StartChar + i);
		charGraphics.Clear(Color(0, 0, 0, 0));
		charGraphics.DrawString(charString, 1, &font, PointF(0.0f, 0.0f), &whiteBrush);

		// Compute tight char horizontal bounds (ignoring empty space).
		int minX = GetCharMinX(charBitmap);
		int maxX = GetCharMaxX(charBitmap);
		int charWidth = maxX - minX + 1;

		// Move to next row of the font sheet?
		if(fontSheetX + charWidth >= mTexWidth)
		{
			fontSheetX = 0;
			fontSheetY += static_cast<int>(mCharHeight) + 1;
		}

		// Save the rectangle of this character on the texture atlas.
		mCharRects[i] = CD3D11_RECT(fontSheetX, fontSheetY, fontSheetX + charWidth, fontSheetY + mCharHeight);

		// The rectangle subset of the source image to copy.
		fontSheetGraphics.DrawImage(&charBitmap, fontSheetX, fontSheetY, 
			minX, 0, charWidth, mCharHeight, UnitPixel);

		// next char
		fontSheetX += charWidth + 1;
	}
}
Exemple #18
0
unsigned int tabs_impl_win32::draw_tab(Graphics &g, unsigned int a_X, unsigned int a_Y, unsigned int a_Index){
	if(a_X > get_size().m_Width) return a_X;

	Color c = Color(255, 44, 61, 91);

	if(m_ActiveTab == a_Index) c = Color(255, 255, 232, 166);
	else if(m_HoverTab == a_Index) c = Color(255, 100, 110, 117);

	SolidBrush b(c);
	SolidBrush t(m_ActiveTab == a_Index ? Color(255, 255, 248, 225) : c);
	SolidBrush black(Color(255, 0, 0, 0));
	SolidBrush white(Color(255, 255, 255, 255));
	SolidBrush closeDark(Color(255, 117, 99, 61));
	SolidBrush closeLight(Color(255, 206, 212, 221));
	Pen p(Color(255, 0, 0, 0));
	Font font(L"Tahoma", 10);
	PointF origin(a_X + 5, a_Y + 3), originX(a_X + 10, a_Y + 5);

	RectF bb, close;

	std::string s = this->get_child_name(a_Index);
	std::wstring w(s.begin(), s.end());

	// draw tab
	g.MeasureString(w.c_str(), w.size(), &font, origin, &bb);
	bb.Height = 25;
	originX.X += bb.Width + 5;
	close = RectF(originX.X, originX.Y, 15.f, 15.f);
	RectF::Union(bb, bb, close);

	GraphicsPath gp;

	// draw header
	int x = a_X; int y = a_Y;
	int headerHeight = get_size().m_Height / 2;
	int arcSize = 10;
	int width = bb.Width;

	// top part = arc
	gp.AddLine(x, y + headerHeight + arcSize / 2, x, y + arcSize / 2);
	gp.AddArc(x, y, arcSize, arcSize, 180.f, 90.f);
	gp.AddArc(x + width, y, arcSize, arcSize, 270.f, 90.f);
	gp.AddLine(x + width + arcSize, y + arcSize / 2, x + width + arcSize, y + headerHeight + arcSize / 2);

	g.FillPath(&t, &gp);

	bb.Width += arcSize;

	// bottom = rect
	g.FillRectangle(&b, a_X, a_Y + headerHeight, bb.Width, 10.f);

	g.DrawString(w.c_str(), w.size(), &font, origin, m_ActiveTab == a_Index ? &black : &white);

	// draw close button
	if(m_ActiveTab == a_Index || m_HoverTab == a_Index){
		SolidBrush closeBrush(Color(190, 40, 30));
		
		Pen hoverPen(Color::White, 2);
		Pen regularPen(Color(20, 20, 20), 2);

		Pen *p = &regularPen;

		float shrink = 4;

		RectF lines = close;
		lines.X += shrink;
		lines.Y += shrink;
		lines.Width -= shrink * 2;
		lines.Height -= shrink * 2;

		// just get mouse position here instead of passing it through
		// from wm_mousemove
		POINT mouse;
		GetCursorPos(&mouse);
		ScreenToClient(m_hWndTabs, &mouse);
		if(close.Contains(mouse.x, mouse.y)) {
			g.FillEllipse(&closeBrush, close);
			p = &hoverPen;
		}

		g.DrawLine(p, lines.X, lines.Y, lines.X + lines.Width, lines.Y + lines.Height);
		g.DrawLine(p, lines.X + lines.Width, lines.Y, lines.X, lines.Y + lines.Height);
	}

	m_VisibleTabs[a_Index].m_BoundingBox = bb;
	m_VisibleTabs[a_Index].m_CloseBox    = close;

	return bb.Width;
}
//重绘状态栏 , 状态栏的大小会根据窗体的大小变动;
void CMyStatusbarCtrl::DrawStatusBar(HDC my_hdc)
{
	Graphics *mygraphics;
	mygraphics = new Graphics(status_hMemDC);
	mygraphics->SetSmoothingMode(SmoothingModeAntiAlias);
	Pen *myRectangle_pen;
	SolidBrush *BlackBrush;
	SolidBrush *CharacterblkBrush;
	SolidBrush *ProgressblkBrush;
	SolidBrush *HealthGreenBrush;
	SolidBrush *HealthRedBrush;

	SolidBrush  Font_brush(Color(255,0,0,0));
	FontFamily  StaticfontFamily(_T("Arial"));
	Gdiplus::Font        character_font(&StaticfontFamily, 12, FontStyleRegular, UnitPixel);
	PointF      staticpointF(0, 0);

	HealthGreenBrush = new SolidBrush(Color(255,38,182,69));
	HealthRedBrush = new SolidBrush(Color(255,255,0,0));
	ProgressblkBrush = new SolidBrush(Color(255,0,211,39));
	CharacterblkBrush =new SolidBrush(Color(255,183,183,183));
	BlackBrush =new SolidBrush(Color(255,228,228,228));
	mygraphics->FillRectangle(BlackBrush,0,0,status_myRect.right,status_myRect.bottom);


	myRectangle_pen = new Pen(Color(255,0,0,0),1.0f);
	mygraphics->DrawRectangle(myRectangle_pen,1,0,add_width,window_height);
	mygraphics->DrawRectangle(myRectangle_pen,1,0,STATUS_CHARACTER_WIDTH,window_height);
	mygraphics->FillRectangle(CharacterblkBrush,1,0,STATUS_CHARACTER_WIDTH,window_height);

	mygraphics->DrawRectangle(myRectangle_pen,tx_start_pos,0,tx_width,window_height);
	mygraphics->DrawRectangle(myRectangle_pen,tx_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);
	mygraphics->FillRectangle(CharacterblkBrush,tx_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);

	mygraphics->DrawRectangle(myRectangle_pen,rx_start_pos,0,rx_width,window_height);
	mygraphics->DrawRectangle(myRectangle_pen,rx_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);
	mygraphics->FillRectangle(CharacterblkBrush,rx_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);

	mygraphics->DrawRectangle(myRectangle_pen,err_start_pos,0,err_width,window_height);
	mygraphics->DrawRectangle(myRectangle_pen,err_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);
	mygraphics->FillRectangle(CharacterblkBrush,err_start_pos,0,STATUS_CHARACTER_WIDTH,window_height);

	mygraphics->DrawRectangle(myRectangle_pen,health_start_pos,0,health_width,window_height);
	mygraphics->DrawRectangle(myRectangle_pen,health_start_pos,0,STATUS_HEALTH_CHARACTER_WIDTH,window_height);
	mygraphics->FillRectangle(CharacterblkBrush,health_start_pos,0,STATUS_HEALTH_CHARACTER_WIDTH,window_height);

	mygraphics->DrawRectangle(myRectangle_pen,progress_start_pos,0,progress_width - STATUS_ALARM_ICON_WIDTH,window_height);

	CString temp_value;

	

	staticpointF.X = 1;
	staticpointF.Y = 1 ;
	mygraphics->DrawString(_T("Add"), -1, &character_font, staticpointF,&Font_brush);

	staticpointF.X = add_start_pos + STATUS_CHARACTER_VALUE_OFFSET;
	mygraphics->DrawString(Statuspanel, -1, &character_font, staticpointF,&Font_brush);

	

	staticpointF.X = tx_start_pos + 1;
	mygraphics->DrawString(_T("Tx"), -1, &character_font, staticpointF,&Font_brush);

	staticpointF.X = tx_start_pos + STATUS_CHARACTER_VALUE_OFFSET;
	temp_value.Format(_T("%u"),g_llTxCount);
	mygraphics->DrawString(temp_value, -1, &character_font, staticpointF,&Font_brush);


	staticpointF.X = rx_start_pos + 1;
	mygraphics->DrawString(_T("Rx"), -1, &character_font, staticpointF,&Font_brush);

	staticpointF.X = rx_start_pos + STATUS_CHARACTER_VALUE_OFFSET;
	temp_value.Format(_T("%u"),g_llRxCount);
	mygraphics->DrawString(temp_value, -1, &character_font, staticpointF,&Font_brush);


	staticpointF.X = err_start_pos + 1;
	mygraphics->DrawString(_T("Err"), -1, &character_font, staticpointF,&Font_brush);

	staticpointF.X = err_start_pos + STATUS_CHARACTER_VALUE_OFFSET;

	//这一段主要是处理有些命令是设备多余回复出来的,例如 发一条,设备回复两条,这样就不太好计算 error 的个数;
	static int n_err_show_count = 0;
	if(++n_err_show_count == 50)
	{
		n_err_show_count = 0;
		if(g_llTxCount - g_llRxCount < 0)
		{
			g_llRxCount = g_llTxCount;
			g_llerrCount = 0;
		}
		else if(g_llTxCount  < g_llerrCount + g_llRxCount)
		{
			g_llRxCount = g_llTxCount - g_llerrCount;
		}
		else
		{
			g_llerrCount = g_llTxCount - g_llRxCount;
		}
	}
	temp_value.Format(_T("%u"),g_llerrCount);
	mygraphics->DrawString(temp_value, -1, &character_font, staticpointF,&Font_brush);


	if(bac_select_device_online)
	{
		mygraphics->FillRectangle(HealthGreenBrush,health_start_pos + STATUS_HEALTH_CHARACTER_WIDTH + 1,1,health_width - STATUS_HEALTH_CHARACTER_WIDTH - 2,window_height - 2);
		staticpointF.X = health_start_pos + STATUS_HEALTH_VALUE_OFFSET;
		mygraphics->DrawString(_T("100%"),-1, &character_font,staticpointF,&Font_brush);
	}
	else
	{
		mygraphics->FillRectangle(HealthRedBrush,health_start_pos + STATUS_HEALTH_CHARACTER_WIDTH + 1,1,health_width - STATUS_HEALTH_CHARACTER_WIDTH - 2,window_height - 2);
		staticpointF.X = health_start_pos + STATUS_HEALTH_VALUE_OFFSET;
		mygraphics->DrawString(_T("0%"),-1, &character_font,staticpointF,&Font_brush);
	}

	staticpointF.X = health_start_pos + 1;
	mygraphics->DrawString(_T("Health"), -1, &character_font, staticpointF,&Font_brush);

	if(g_progress_persent != 0)
	{
		unsigned int temp_width = (progress_width - STATUS_ALARM_ICON_WIDTH) * g_progress_persent / 100 ;
		CString temp_persent_value;
		temp_persent_value.Format(_T("%d%%"),g_progress_persent);
		mygraphics->FillRectangle(ProgressblkBrush,progress_start_pos,0,temp_width,window_height);
		staticpointF.X = progress_start_pos + progress_width - 60;
		mygraphics->DrawString(temp_persent_value, -1, &character_font, staticpointF,&Font_brush);
		if( g_progress_persent >= 98)
			g_progress_persent = 0;
		//progress_width
	}
	else
	{
		mygraphics->DrawRectangle(myRectangle_pen,progress_start_pos,0,progress_width - STATUS_ALARM_ICON_WIDTH,window_height);
	}

	if(!cs_show_status_info.IsEmpty())
	{
		staticpointF.X = progress_start_pos + 1;
		mygraphics->DrawString(cs_show_status_info, -1, &character_font, staticpointF,&Font_brush);
	}

	

	delete mygraphics;
	delete myRectangle_pen;

	delete BlackBrush;
	delete CharacterblkBrush;
	delete ProgressblkBrush;
}
void MyPaint_Mem(HDC my_hdc)
{
	Graphics *mygraphics;
	mygraphics = new Graphics(my_hdc);
	mygraphics->SetSmoothingMode(SmoothingModeAntiAlias);
	Pen *myRectangle_pen;
	Pen * my_inline_pen;

	Pen * CurePen;

	SolidBrush *BlackBrush;
	

	myRectangle_pen = new Pen(Color(255,0,255,255));
	my_inline_pen = new Pen(Color(255,220,220,220));

	REAL dashValues[2] = {5, 5};
	//Pen blackPen(Color(255, 0, 0, 0), 5);
	my_inline_pen->SetDashPattern(dashValues, 2);


	CurePen = new Pen(Graphic_Color[1],3.0f);
	PointF      pointF(0, 0);

	BlackBrush =new SolidBrush(Color(255,0,0,0));
	mygraphics->FillRectangle(BlackBrush,X_ORIGIN,Y_ORIGIN,X_WIDTH,Y_HIGHT);
	mygraphics->DrawRectangle(myRectangle_pen,X_ORIGIN,Y_ORIGIN,X_WIDTH,Y_HIGHT);

	SolidBrush *Static_blackground_Brush;
	Pen *mystaticRectangle_pen;
	mystaticRectangle_pen = new Pen(Color(255,0,0,0),2.0f);
	Static_blackground_Brush =new SolidBrush(Color(255,187,187,187));
	mygraphics->FillRectangle(Static_blackground_Brush,0,window_hight - 120,window_width,120);
	mygraphics->DrawRectangle(mystaticRectangle_pen,2,window_hight - 110,window_width-15,110 -30);

	SolidBrush  time_brush(Color(255, 225, 225, 225));
	FontFamily  fontFamily(_T("Times New Roman"));
	Gdiplus::Font        time_font(&fontFamily, 18, FontStyleRegular, UnitPixel);
	for(int i=0;i<x_line_scale;i++)				//画网格线
	{
		mygraphics->DrawLine(my_inline_pen,X_ORIGIN+(X_WIDTH/x_line_scale)*(i+1),Y_ORIGIN,X_ORIGIN+(X_WIDTH/x_line_scale)*(i+1),Y_ORIGIN + Y_HIGHT);
		CString strTime ;
		wchar_t temp_char[200];
		//time_t test = old_early_time;
		//CTime timeTest(test);
		time_t test ;
		CTime timeTest;

		switch(scale_type)
		{
		case _6_min:
			break;
		case _1_hour:
			test = old_early_time + i*600;

			timeTest = test ;

			strTime = timeTest.Format("%Y/%m/%d\r\n %H:%M:%S");
			pointF.X = X_ORIGIN - 40 + i*(X_WIDTH/x_line_scale);
			pointF.Y = Y_ORIGIN+Y_HIGHT + 10;
			mygraphics->DrawString(strTime, -1, &time_font, pointF, &time_brush);
			//old_early_time
			break;
		case _4_hour:
			break;
		case _12_hour:
			break;
		case _1_day:
			break;
		}

	}
	SolidBrush  unit_brush(Graphic_Color[1]);
	FontFamily  UnitfontFamily(_T("Times New Roman"));
	Gdiplus::Font        unitfont(&UnitfontFamily, 18, FontStyleRegular, UnitPixel);
	for(int i=0;i<=y_line_scale;i++)				//画网格线
	{
		CString Unit_value;
		if(i!=y_line_scale)
		mygraphics->DrawLine(my_inline_pen,X_ORIGIN,Y_ORIGIN+(Y_HIGHT/y_line_scale)*(1+i),X_WIDTH + X_ORIGIN,Y_ORIGIN+(Y_HIGHT/y_line_scale)*(1+i));

		if(i!=y_line_scale)
		Unit_value.Format(_T("%d"),(Total_SCALE/y_line_scale)*(y_line_scale-i));// = timeTest.Format("%Y/%m/%d\r\n %H:%M:%S");
		else
		Unit_value.Format(_T("%d"),Min_Scale_value);
		pointF.X = X_ORIGIN - 30;
		pointF.Y = Y_ORIGIN+ i*(Y_HIGHT/y_line_scale);
		mygraphics->DrawString(Unit_value, -1, &unitfont, pointF, &unit_brush);
		//swprintf_s(temp_char,200,L"%d",i*5);
		//mygraphics->DrawString(temp_char, -1, &font, pointF, &brush);

	}
	for (int i=1;i<=14;i++)
	{
		CString temp_item;
		temp_item.Format(_T("%x"),i);
		temp_item = temp_item.MakeUpper();

		SolidBrush  static_item_brush(Graphic_Color[i]);
		FontFamily  UnitfontFamily(_T("Arial Black"));
		Gdiplus::Font        unitfont(&UnitfontFamily, 22, FontStyleRegular, UnitPixel);
		pointF.X = Static_Num_Rect[i].left;
		pointF.Y = Static_Num_Rect[i].top;
		mygraphics->DrawString(temp_item, -1, &unitfont, pointF, &static_item_brush);
	}
	

	CPointItem *first_item=NULL,*second_item=NULL,*third_item=NULL;
	first_item = m_pFirstItem;
	//********************************************
	//直线
	for (int i=0;i<60;i=i+1)
	{
		second_item=first_item->GetNext();
		if(second_item==NULL)
			break;
		CurePen->SetStartCap(LineCapArrowAnchor);
		CurePen->SetEndCap(LineCapRoundAnchor);
		mygraphics->DrawLine(CurePen,first_item->GetPoint().x,first_item->GetPoint().y,second_item->GetPoint().x,second_item->GetPoint().y);
		first_item = second_item;

	}
	//********************************************

#if 0
	for (int i=0;i<60;i=i+2)
	//for (int i=0;i<m_monitor_block.index - 1;i=i+2)	//画贝塞尔曲线,使得线条平滑;3个点一画;		TEST
	//for (int i=0;i<Total_count-1;i=i+2)	//画贝塞尔曲线,使得线条平滑;3个点一画;
	{
		second_item=first_item->GetNext();
		third_item = second_item->GetNext();
		if(second_item==NULL)
			break;
		if(third_item == NULL)
		{
			first_item = second_item;
			break;
		}
		//mygraphics->DrawCurve(CurePen,, 3, 1.5f);
		//取3个点给画曲线的GDI函数;
		Point myPointArray[] =
		{Point(first_item->GetPoint().x,first_item->GetPoint().y),
		Point(second_item->GetPoint().x,second_item->GetPoint().y),
		Point(third_item->GetPoint().x,third_item->GetPoint().y)};

		CurePen->SetStartCap(LineCapArrowAnchor);
		CurePen->SetEndCap(LineCapRoundAnchor);


			mygraphics->DrawCurve(CurePen,myPointArray, 3, 1.0f);
			first_item = third_item;

		
	}
#endif

	delete CurePen;
	delete mygraphics;
	delete myRectangle_pen;
	delete my_inline_pen;
	delete BlackBrush;
}
/*
** 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;
}
Exemple #22
0
void
MFCClipItemView::Draw(Graphics &dc, CRect &clipBox)
{
// !!!??? need to clip properly for short instances with long names
	cerr << "clip item draw " << item->sym->name << endl;
	Pen blackPen(Color(250, 0, 0, 0), 1);
	Pen redPen(Color(250, 238, 100, 100), 1);
	Pen orangePen(Color(200, 250, 150, 10), 1);
	SolidBrush blueBrush(Color(100, 100, 100, 238));
	SolidBrush blackBrush(Color(200, 0, 0, 0));
	SolidBrush orangeBrush(Color(190, 250, 150, 10));

	dc.DrawLine( &orangePen, bounds.left, 0, bounds.left, bounds.bottom);
	bool	isMarker = false;
	if (item != NULL && item->duration.ticks <= 0) {
		isMarker = true;
	}
	if (!isMarker) {
		dc.DrawLine( &orangePen, bounds.right, 0, bounds.right, bounds.bottom);
	}

	PointF	tri[3];

	Font	labelFont(L"Arial", 8.0, FontStyleRegular, UnitPoint, NULL);
	wstring nm;
	const char *cp = item->sym->uniqueName();
	while (*cp) {
		nm.push_back(*cp++);
	}
	PointF	p;
	UINT py = 0;
	do {
		if (!isMarker) {
			// a triangle bit
			tri[0].X = bounds.left; tri[0].Y = py;
			tri[1].X = bounds.left+6; tri[1].Y = py+3;
			tri[2].X = bounds.left; tri[2].Y = py+6;
			dc.FillPolygon(&orangeBrush, tri, 3);
		}

		p.X = bounds.left-1;
		p.Y = py+5;
		RectF	box;
		StringFormat	sff = StringFormatFlagsDirectionVertical;
		dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
		dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);

		if (!isMarker) {
			// a nother triangle bit
			tri[0].X = bounds.right;
			tri[1].X = bounds.right-6;
			tri[2].X = bounds.right;
			dc.FillPolygon(&orangeBrush, tri, 3);

			p.X = bounds.right-10;
			p.Y = py+5;
			dc.MeasureString(nm.c_str(), -1, &labelFont, p, &sff, &box);
			dc.DrawString(nm.c_str(), -1, &labelFont, box,	&sff, &blackBrush);
		}
		py += editor->bounds.bottom;
	} while (py < bounds.bottom);

}
void MyPaint_Mem(HDC my_hdc)
{

	Graphics *mygraphics;
	mygraphics = new Graphics(my_hdc);
	mygraphics->SetSmoothingMode(SmoothingModeAntiAlias);
	Pen *myRectangle_pen;
	Pen * my_inline_pen;

	Pen * CurePen;

	SolidBrush *BlackBrush;


	myRectangle_pen = new Pen(Color(255,0,255,255));
	my_inline_pen = new Pen(Color(255,0,128,64));

	CurePen = new Pen(Color(255,0,255,0));

	m_interval = (m_interval++)%5;	//让其向左平移;


	if(runonce < 2)				//初始化时画背景图案;
	{
		runonce ++;
		//Image myImage(L"texture.BMP");
		//TextureBrush myTextureBrush(&myImage);
		//RECT newrect_now;
		//GetWindowRect(myhWnd,&newrect_now);
		//mygraphics->FillRectangle(&myTextureBrush, 0, 0, newrect_now.right, newrect_now.bottom);


		SolidBrush  brush(Color(255, 0, 0, 255));
		FontFamily  fontFamily(_T("Times New Roman"));
		Gdiplus::Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
		PointF      pointF(40.0f, 600.0f);
		for(int i=0;i<=20;i=i+2)				//增加文字 %;
		{
			pointF.Y = 600;
			pointF.Y = pointF.Y - i*30;
			wchar_t temp_char[200];
			//swprintf_s(temp_char,200,L"%d%%",i*5);
			swprintf_s(temp_char,200,L"%d",i*5);
			mygraphics->DrawString(temp_char, -1, &font, pointF, &brush);
		}
		pointF.X = 200;
		pointF.Y = 650;
		//mygraphics->DrawString(L"CPU 使用率", -1, &font, pointF, &brush);

	}


	//BlackBrush =new SolidBrush(Color(255,0,0,0));
	BlackBrush =new SolidBrush(Color(255,0,0,0));
	mygraphics->FillRectangle(BlackBrush,100,10,1200,600);
	mygraphics->DrawRectangle(myRectangle_pen,100,10,1200,600);



	for(int i=0;i<=39;i++)				//画网格线
		mygraphics->DrawLine(my_inline_pen,100+line_interval*(i+1)-m_interval*6,10,100+line_interval*(i+1)-m_interval*6,610);

	for(int i=0;i<19;i++)				//画网格线
		mygraphics->DrawLine(my_inline_pen,100,10+line_interval*(1+i),1300,10+line_interval*(1+i));
#if 0
	CPointItem *first_item=NULL,*second_item=NULL;
	first_item = m_pFirstItem;
	for (int i=0;i<Total_count-1;i++)
	{
		second_item=first_item->GetNext();
		if(second_item==NULL)
			break;
		//mygraphics->DrawCurve(CurePen,, 3, 1.5f);
		//Point myPointArray[] =
		//{Point(first_item->GetPoint().x,first_item->GetPoint().y),Point(second_item->GetPoint().x,second_item->GetPoint().y)};
		//mygraphics->DrawCurve(CurePen,myPointArray, 2, 1.0f);
		//mygraphics->DrawLine(CurePen,first_item->GetPoint().x,first_item->GetPoint().y,second_item->GetPoint().x,second_item->GetPoint().y);
		first_item = second_item;
	}
#endif
#if 1
	CPointItem *first_item=NULL,*second_item=NULL,*third_item=NULL;
	first_item = m_pFirstItem;

	for (int i=0;i<Total_count-1;i=i+2)	//画贝塞尔曲线,使得线条平滑;3个点一画;
	{
		second_item=first_item->GetNext();
		third_item = second_item->GetNext();
		if(second_item==NULL)
			break;
		if(third_item == NULL)
		{
			first_item = second_item;
			break;
		}
		//mygraphics->DrawCurve(CurePen,, 3, 1.5f);
		//取3个点给画曲线的GDI函数;
		Point myPointArray[] =
		{Point(first_item->GetPoint().x,first_item->GetPoint().y),
		Point(second_item->GetPoint().x,second_item->GetPoint().y),
		Point(third_item->GetPoint().x,third_item->GetPoint().y)};
		mygraphics->DrawCurve(CurePen,myPointArray, 3, 1.0f);
		//mygraphics->DrawLine(CurePen,first_item->GetPoint().x,first_item->GetPoint().y,second_item->GetPoint().x,second_item->GetPoint().y);

		first_item = third_item;
	}
#endif
	//	mygraphics->DrawLine(CurePen,)


	delete CurePen;
	delete mygraphics;
	delete myRectangle_pen;
	delete my_inline_pen;
	delete BlackBrush;
}
Exemple #24
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 Listlay::subrender()
{
	Graphics *gfx = Graphics::FromImage(this->image);
	gfx->Clear(CLR_WHITE);

	Cacher *cacher = this->core->getCacher();
	if( cacher != NULL ){
		FwCHAR *string = NULL;
		FwCHAR *name = NULL;
		Cell *cell = NULL;
		int i, x, y;
		bool top, bot, archived = false;

		top = false;
		bot = false;

		x = LST_X;
		y = LST_Y;

		for( i = -CACHE_SIZE; i < CACHE_SIZE; i++ ){
			cacher->lockCache();

			if( cacher->getCache() != NULL ){
				cell = cacher->getCache()->gettoThat(i);
				if( cell != NULL ){
					if( cell->getFile() != NULL ){
						name = cell->getFile()->getFileName();
					}
					if( name != NULL ){
						if( i == 0 )
							gfx->FillRectangle(this->Brush_LiteBack,0,y+1,OVL_SIZE,FONTSIZE+2);
						
						string = name;
						if( cell->getFile()->isArchived() == true ){
							if( archived == false )
								archived = true;

							string = new FwCHAR(L"~");
							string->mergeWith(name);

							x = 3*LST_X;
						}
						else if( archived == true ){
							archived = false;
							x = LST_X;
						}
						gfx->DrawString(string->toWCHAR(),
										string->toLength(),
										this->Font_Default,
										PointF((REAL)x,(REAL)y),
										this->Brush_DarkBack);

						if( archived == true )
							delete string;
					}
					if( i == -1 && cacher->getCache()->isThatHead() == false )
						top = true;
					if( i == 1 && cacher->getCache()->isThatTail() == false )
						bot = true;
				}
			}
			cacher->unlockCache();

			y += (FONTSIZE + 2);
		}
		int size = 3;
		int width = 20;
		int ax = (int)(OVL_SIZE/2);
		int ay = LST_Y;
		int asize = OVL_SIZE - 2*LST_Y;
		Point arrow[3];

		if( top == true ){
			arrow[0].X = ax - width;
			arrow[0].Y = ay;
			arrow[1].X = ax;
			arrow[1].Y = ay - width;
			arrow[2].X = ax + width;
			arrow[2].Y = ay;
			gfx->FillPolygon(this->Brush_LiteBack,arrow,size);
		}
		if( bot == true ){
			arrow[0].X = ax - width;
			arrow[0].Y = ay + asize;
			arrow[1].X = ax;
			arrow[1].Y = ay + asize + width;
			arrow[2].X = ax + width;
			arrow[2].Y = ay + asize;
			gfx->FillPolygon(this->Brush_LiteBack,arrow,size);
		}
	}
	if( this->ticker > TICKER_OFF ){
		int tsize = TICKER_SIZE;
		int tx,ty;
		if( this->ticker == 0 ){
			tx = OVL_SIZE - 2*TICKER_INDENT;
			ty = OVL_SIZE - 2*TICKER_INDENT;
		}
		if( this->ticker == 1 ){
			tx = OVL_SIZE - TICKER_INDENT;
			ty = OVL_SIZE - 2*TICKER_INDENT;
		}
		if( this->ticker == 2 ){
			tx = OVL_SIZE - TICKER_INDENT;
			ty = OVL_SIZE - TICKER_INDENT;
		}
		if( this->ticker == 3 ){
			tx = OVL_SIZE - 2*TICKER_INDENT;
			ty = OVL_SIZE - TICKER_INDENT;
		}
		gfx->FillRectangle(this->Brush_DarkBack,tx,ty,tsize,tsize);
	}
	delete gfx;
}
void MainWindow::saveToFile() {
	std::ofstream outFile(mOutFile, std::ios::binary);
	std::stringstream out;
	uint32 signature = 'FNTI';
	out.write((const char*)&signature, sizeof(uint32));
	
	struct FNTIHeader
	{
		uint32 numPages;
		uint32 ofsPages;
	} header;

	header.numPages = mActiveBlocks.size();
	header.ofsPages = sizeof(FNTIHeader) + sizeof(uint32);
	out.write((const char*)&header, sizeof(FNTIHeader));

	struct FNTIBlockDesc
	{
		uint32 id;
		uint32 numChars;
		uint32 ofsChars;
		uint32 bmpWidth;
		uint32 bmpHeight;
		uint32 ofsBmp;
		wchar_t minChar;
		wchar_t maxChar;
		wchar_t pageName[64];
	};

	std::vector<FNTIBlockDesc> descriptions(mActiveBlocks.size());

	uint32 counter = 0;
	for(auto& block : mActiveBlocks) {
		FNTIBlockDesc desc;
		memset(&desc, 0, sizeof(desc));
		desc.id = block.id;
		desc.bmpWidth = 256;
		desc.bmpHeight = 256;
		desc.minChar = (wchar_t)block.minChar;
		desc.maxChar = (wchar_t)block.maxChar;
		wcsncpy_s(desc.pageName, block.name->c_str(), 64);
		desc.pageName[63] = L'\0';

		out.write((const char*)&desc, sizeof(desc));
		descriptions[counter++] = desc;
	}

	std::vector<Bitmap*> bitmaps(mActiveBlocks.size());

	Bitmap* tmp = new Bitmap(mFontSize * 2, mFontSize);
	Graphics* gchar = Graphics::FromImage(tmp);
	gchar->SetTextRenderingHint(TextRenderingHintAntiAlias);

	for(uint32 i = 0; i < mActiveBlocks.size(); ++i) {
		auto& desc = descriptions[i];
		desc.ofsChars = (uint32)out.tellp();

		Bitmap* bmp = new Bitmap(256, 256);
		bitmaps[i] = bmp;

		Graphics* g = Graphics::FromImage(bmp);
		g->Clear(Color::Transparent);
		g->SetTextRenderingHint(TextRenderingHintAntiAlias);

		uint32 curW = 0, curH = 0;
	
		for(uint32 j = mActiveBlocks[i].minChar; j < mActiveBlocks[i].maxChar; ++j) {
			char c = (char)j;
			wchar_t wc = (wchar_t)j;

			RectF rcChar;
			g->MeasureString(&wc, 1, mDefFont, PointF(0, 0), &rcChar);
			float width = rcChar.Width;
			if(curW + width > bmp->GetWidth()) {
				curW = 0;
				curH += mFontSize + 3;
			}

			g->DrawString(&wc, 1, mDefFont, PointF((float)curW, (float)curH), mWhiteBrush);

			gchar->Clear(Color::Black);
			gchar->DrawString(&wc, 1, mDefFont, PointF(0, 0), mWhiteBrush);

			Color pxl, pxr;
			uint32 ofsl = 0, ofsr = 0;
			bool lfound = false, rfound = false;

			for(uint32 l = 0; l < mFontSize * 2; ++l) {
				for(uint32 h = 0; h < mFontSize; ++h) {
					uint32 r = (2 * mFontSize - 1) - l;

					if(lfound == false) {
						tmp->GetPixel(l, h, &pxl);
						if(pxl.GetRed() > 5) {
							lfound = true;
							ofsl = l;
						}
					}

					if(rfound == false) {
						tmp->GetPixel(r, h, &pxr);
						if(pxr.GetRed() > 5) {
							rfound = true;
							ofsr = r;
						}
					}

					if(lfound && rfound) {
						break;
					}
				}

				if(lfound && rfound) {
					break;
				}
			}

			if(lfound == false || rfound == false || (ofsl >= ofsr)) {
				continue;
			}

			uint16 chrWidth = ofsr - ofsl + 1;

			float txs = (curW + ofsl) / (float)bmp->GetWidth();
			float txe = (curW + width - ofsr) / (float)bmp->GetWidth();
			float tys = curH / (float)bmp->GetHeight();
			float tye = (curH + mFontSize) / (float)bmp->GetHeight();

			curW += (uint32)ceil(width) + 2;

			++desc.numChars;
			out.write((const char*)&wc, sizeof(wchar_t));
			out.write((const char*)&chrWidth, sizeof(uint16));
			out.write((const char*)&txs, sizeof(float));
			out.write((const char*)&txe, sizeof(float));
			out.write((const char*)&tys, sizeof(float));
			out.write((const char*)&tye, sizeof(float));
		}

		delete g;
	}

	delete gchar;
	delete tmp;

	for(uint32 i = 0; i < mActiveBlocks.size(); ++i) {
		auto& desc = descriptions[i];
		desc.ofsBmp = (uint32)out.tellp();
		Bitmap* bmp = bitmaps[i];
		BitmapData data;
		bmp->LockBits(&Rect(0, 0, bmp->GetWidth(), bmp->GetHeight()), 0, PixelFormat32bppARGB, &data);
		out.write((const char*)data.Scan0, bmp->GetWidth() * bmp->GetHeight());
		bmp->UnlockBits(&data);

		delete bmp;
	}

	out.seekp(header.ofsPages, std::ios::beg);
	out.write((const char*)descriptions.data(), descriptions.size() * sizeof(FNTIBlockDesc));

	out.seekp(0, std::ios::end);

	uint32 end = (uint32)out.tellp();
	out.seekg(0, std::ios::beg);

	std::vector<char> content(end);
	out.read(content.data(), end);

	std::vector<char> compressed(end);
	Utils::ZDeflater defl;
	defl.begin();

	uint32 outPos = 0;
	defl.update(content, compressed, outPos);
	compressed.resize(outPos);

	defl.end();

	outFile.write((const char*)&end, sizeof(uint32));
	outFile.write(compressed.data(), compressed.size());
	outFile.close();
}
void CAngleLabel::DrawAngleLabelMark(Graphics& graph)
{
	CPoint pt2((int)m_ptary[1].X, (int)m_ptary[1].Y);
	CPoint pt3((int)m_ptary[2].X, (int)m_ptary[2].Y);

	float fAngle3 = 0.0f;
	float fAngle1 = CalcRotateAngle(pt2, m_ptary[0]) - 90.0f;
	float fAngle2 = CalcRotateAngle(pt3, m_ptary[0]) - 90.0f;

	if(fAngle1 > - 90 && fAngle1 <= 0)
	{
		if(fAngle2 >= 180 && fAngle2 <= 270)
		{
			fAngle2 -= 360;
		}
		else if(fAngle2 - fAngle1 >= 180)
		{
			fAngle1 += 360;
		}
	}
	else if(fAngle1 >= 0 && fAngle1 <= 90)
	{
		if(fAngle2 >= 180)
		{
			if(fAngle2 - fAngle1 >= 180)
			{
				fAngle2 -= 360;
			}
		}
	}
	else if(fAngle1 >= 90 && fAngle1 <= 180)
	{
		if(fAngle2 >= -90 && fAngle2 <= 0)
		{
			if(fAngle1 - fAngle2 >= 180)
			{
				fAngle2 += 360;
			}
		}
	}
	else if(fAngle1 >= 180 && fAngle1 <= 270)
	{
		if(fAngle2 >= 0 && fAngle2 <= 90)
		{
			if(fAngle1 - fAngle2 >= 180)
			{
				fAngle2 += 360;
			}
		}
		else if(fAngle2 >= -90 && fAngle2 <= 0)
		{
			fAngle2 += 360;
		}
	}

	fAngle3 = (fAngle1 + fAngle2) / 2.0f;
	PointF ptDraw;
	ptDraw.Y = m_ptary[0].Y;

	if(fabs(fAngle1 - fAngle2) <= 20)
	{
		ptDraw.X = 100 + m_ptary[0].X;
	}
	else if(fabs(fAngle1 - fAngle2) <= 30)
	{
		ptDraw.X = 80 + m_ptary[0].X;
	}
	else
	{
		ptDraw.X = 60 + m_ptary[0].X;
	}

	Matrix mat;
	mat.RotateAt(fAngle3, m_ptary[0]);
	mat.TransformPoints(&ptDraw, 1);

	Pen penDraw(Color::Blue, 2);
	RectF rcf(m_ptary[0].X - 30, m_ptary[0].Y - 30, 60, 60);
	graph.DrawArc(&penDraw, rcf, fAngle1, fAngle2 - fAngle1);

	Font myFont(_T("Arial"), 12);
	SolidBrush brush(Color::Red);
	StringFormat format;
	format.SetAlignment(StringAlignmentCenter);

	int nAngle = CalLinesAngle();
	m_strAngle.Format(_T("%dбу"), nAngle);

	graph.SetTextRenderingHint(TextRenderingHintAntiAlias);
	graph.DrawString(m_strAngle, m_strAngle.GetLength(), &myFont, ptDraw, &format, &brush);
}
Exemple #28
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);
}
HRESULT FrameSkippingFilter::Transform(IMediaSample *pSample)
{
   using namespace Gdiplus;

    REFERENCE_TIME tStart = 0;
	  REFERENCE_TIME tStop  = 0;

    int skipparram = 2; // parameter to define how many frames to skip


    HRESULT hr = pSample->GetTime(&tStart, &tStop); //get the current time now
    REFERENCE_TIME frameduration = tStop - tStart;

    if (!seenFirstFrame)
    {
      if (SUCCEEDED(hr))
      {
        previousTimestamp = tStart;
        seenFirstFrame = true;
      }
    return S_OK;
    }
    else
    {
      if (SUCCEEDED(hr))
      {
        in_framecount++ ; // counting the incoming samples

        REFERENCE_TIME tDiff = tStart - previousTimestamp;
        // Make sure timestamps are increasing
        if (tDiff > 0)
        {
          if((in_framecount % skipparram)== 0) 
           {
             pSample = NULL;
             return S_FALSE;
           } // skip this frame if it is true


           out_framecount++; // here we count only outgoing samples

         /*  REFERENCE_TIME frameduration = tStop - tStart;*/
           /*REFERENCE_TIME frameduration = tDiff;*/ /// duration in seconds for a single frame to go through the pipeline
                               ///time you want the frame to sleep for.. time in the future

                                 /// or is the length of time the particular frame takes to pass through the pipeline?

            tStart = out_framecount*frameduration;
            tStop = tStart + frameduration;

            hr = pSample->SetTime(&tStart, &tStop); //refer to Smaple Grabber filter
            if (FAILED(hr))
            {
              return hr;
            }
            
            m_qDurations.push_back(out_framecount);
            previousTimestamp = tStart;

        // limit the number of measurements
            if (m_qDurations.size() > MAX_FRAMERATE_INTERVAL_SIZE)
            {
              m_qDurations.pop_front();
            }      
      }
    }
   }

  if (!m_qDurations.empty())
  {
    // calc avg framerate
    REFERENCE_TIME tAvg = std::accumulate(m_qDurations.begin(), m_qDurations.end(), 0) / m_qDurations.size();

     // Avoid div by zero in cases where the timestamps are invalid
    if (tAvg > 0)
    {

         // Create a string.
            std::string skippedFramerate = StringUtil::doubleToString(in_framecount) + " frames";
            wchar_t* wsFramerate = StringUtil::stlToWide(skippedFramerate); 

          // get image properties
            AM_MEDIA_TYPE mt;
            hr = InputPin()->ConnectionMediaType(&mt);
            if (FAILED(hr))
            {
              return hr;
            }

            ASSERT(mt.formattype == FORMAT_VideoInfo);
            BITMAPINFOHEADER *pbmi = HEADER(mt.pbFormat);

            // Get image buffer
            BYTE *pBuffer(NULL);
            hr = pSample->GetPointer(&pBuffer);
            if (FAILED(hr))
            {
              return hr;
            }

            BITMAPINFO bitmapInfo;
            bitmapInfo.bmiHeader = *pbmi;

            Bitmap bm(&bitmapInfo, (void*)pBuffer);
            Graphics* pGraphics = Graphics::FromImage(&bm);

            // Initialize font
            Font myFont(L"Arial", 16);
            RectF layoutRect(0.0f, 0.0f, 200.0f, 50.0f);
            //RectF layoutRect(m_uiX, m_uiY, 200.0f, 50.0f);
            StringFormat format;
            format.SetAlignment(StringAlignmentNear);
            SolidBrush blackBrush(Color(255, 0, 0, 0));
            SolidBrush greenBrush(Color(255, 0, 255, 0));

            // Draw string
            pGraphics->DrawString(
              wsFramerate,
              skippedFramerate.length(),
              &myFont,
              layoutRect,
              &format,
              &greenBrush);

            delete[] wsFramerate;

            // Do we need to delete it?
            delete pGraphics;
            }
          }

	  return S_OK;
}
void CSkinDialog::DrawFrame(Graphics & graphics)
{
    CRect rcWindow;
    GetWindowRect(&rcWindow);

    Rect rc, rc1;

    // Title Left
    rc = m_bActive?m_mapRect["TitleLeftActive"]:m_mapRect["TitleLeft"];
    rc1.X = 0;
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Center
    rc = m_bActive?m_mapRect["TitleCenterActive"]:m_mapRect["TitleCenter"];
    rc1.X = m_mapRect["TitleLeftActive"].Width;
    rc1.Y = 0;
    rc1.Width = rcWindow.Width()-m_mapRect["TitleLeftActive"].Width-m_mapRect["TitleRightActive"].Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Title Right
    rc = m_bActive?m_mapRect["TitleRightActive"]:m_mapRect["TitleRight"];
    rc1.X = rc1.GetRight();
    rc1.Y = 0;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Left
    rc = m_bActive?m_mapRect["BorderLeftActive"]:m_mapRect["BorderLeft"];
    rc1.X = 0;
    rc1.Y = m_mapRect["TitleLeft"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Bottom
    rc = m_bActive?m_mapRect["BorderBotActive"]:m_mapRect["BorderBot"];
    rc1.X = 0;
    rc1.Y = rcWindow.Height()-rc.Height-1;
    rc1.Width = rcWindow.Width();
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Border Right
    rc = m_bActive?m_mapRect["BorderRightActive"]:m_mapRect["BorderRight"];
    rc1.X = rcWindow.Width()-rc.Width-1;
    rc1.Y = m_mapRect["TitleLeftActive"].Height;
    rc1.Width = rc.Width;
    rc1.Height = rcWindow.Height()-m_mapRect["TitleLeftActive"].Height-m_mapRect["BorderBotActive"].Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Close Button
    rc = m_nButtonDown==HT_CLOSE?m_mapRect["NcBtnCloseDown"]:m_mapRect["NcBtnClose"];
    rc1.X = rcWindow.Width()-m_mapRect["NcBtnClosePos"].X;
    rc1.Y = m_mapRect["NcBtnClosePos"].Y;
    rc1.Width = rc.Width;
    rc1.Height = rc.Height;
    graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);

    // Max Button
    if(GetStyle()&WS_MAXIMIZEBOX)
    {
        rc = IsZoomed()?(m_nButtonDown==HT_MAX?m_mapRect["NcBtnResDown"]:m_mapRect["NcBtnRes"]):(m_nButtonDown==HT_MAX?m_mapRect["NcBtnMaxDown"]:m_mapRect["NcBtnMax"]);
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMaxPos"].X;
        rc1.Y = m_mapRect["NcBtnMaxPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    // Min Button
    if(GetStyle()&WS_MINIMIZEBOX)
    {
        rc = m_nButtonDown==HT_MIN?m_mapRect["NcBtnMinDown"]:m_mapRect["NcBtnMin"];
        rc1.X = rcWindow.Width()-m_mapRect["NcBtnMinPos"].X;
        rc1.Y = m_mapRect["NcBtnMinPos"].Y;
        rc1.Width = rc.Width;
        rc1.Height = rc.Height;
        graphics.DrawImage(m_pImg, rc1, rc.GetLeft(), rc.GetTop(), rc.Width, rc.Height, UnitPixel);
    }

    Font myFont(L"宋体", 9);
    Color col(255,0,0,0);
    col.SetFromCOLORREF(m_mapColor["Caption"]);
    SolidBrush blackBrush(col);

    StringFormat format;
    format.SetAlignment(StringAlignmentNear);

    RectF layoutRect(::GetSystemMetrics(SM_CYICON)+m_mapRect["TitleTextStart"].X, m_mapRect["TitleTextStart"].Y, rcWindow.Width(), rcWindow.Height());

    WCHAR string[MAX_PATH] = {0};
    CString str;
    GetWindowText(str);

    MultiByteToWideChar( CP_ACP, 0, str, -1, string, MAX_PATH) ;

    graphics.DrawString(string,	-1, &myFont, layoutRect, &format, &blackBrush);
}