예제 #1
0
//原生GDI+ 绘制
void converDemo::drawOnNativeGdi(Graphics &graphics)
{

	GraphicsPath path;
	path.AddEllipse(10, 10, 100, 100);
	path.AddRectangle(RectF(100, 100, 200, 250));
	PathGradientBrush* brush = new PathGradientBrush(&path);
	Color colors[] = {
		Color(0, 0, 255), Color(0, 0, 0), Color(0, 255, 0), Color(255, 0, 0)
	};
	REAL reals[] = {
		0, 0.5, 0.8, 1
	};
	brush->SetInterpolationColors(colors, reals, 4);
	Matrix matrix;
	matrix.Translate(100, 0);
	matrix.Shear(0.15, 0.3);
	matrix.Scale(0.4, 0.2);
	matrix.Rotate(0.5);
//	brush->MultiplyTransform(&matrix, MatrixOrderAppend);
	RectF rect(convertQRectF2GpRectF(QRectF(100.0f, 100.0f, 200.0f, 400.0f)));
	graphics.FillRectangle(brush, rect);
	delete brush;

}
예제 #2
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);
}
HRESULT CIGImageLibrary::OnDraw(ATL_DRAWINFO& di)
{
	Graphics graphics (di.hdcDraw);
	// Middle part
	GraphicsPath path;
	path.AddRectangle (RectF (0, 0,
							IGIMAGELIBRARY_WIDTH, IGIMAGELIBRARY_HEIGHT));
	PathGradientBrush pthGrBrush (&path);
	pthGrBrush.SetCenterPoint (PointF (0.7f * (float)IGIMAGELIBRARY_WIDTH,
									  0.3f * (float)IGIMAGELIBRARY_HEIGHT));
	pthGrBrush.SetCenterColor (IGIMAGELIBRARY_COLOR_FRAMEIN);
	Color colors[] = {IGIMAGELIBRARY_COLOR_FRAMEOUT};
	int count = 1;
	pthGrBrush.SetSurroundColors(colors, &count);
	graphics.FillPath (&pthGrBrush, &path);

	// Left part
	LinearGradientBrush linLeftGrBrush (PointF(0,0), PointF((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0),
							IGIMAGELIBRARY_COLOR_BORDEROUT, IGIMAGELIBRARY_COLOR_BORDERMIDDLE);	
	graphics.FillRectangle (&linLeftGrBrush, RectF (0, 0,
							(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f,
							IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS));
	LinearGradientBrush linLeft2GrBrush (PointF ((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f, 0), PointF (IGIMAGELIBRARY_BORDERWIDTH, 0),
							IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDERIN);	
	graphics.FillRectangle (&linLeft2GrBrush, RectF ((float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0,
							(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f,
							IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS));
	
	// Right part
	LinearGradientBrush linRightGrBrush (PointF(IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_BORDERWIDTH - 1, 0),
										PointF(IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0),
										IGIMAGELIBRARY_COLOR_BORDERIN, IGIMAGELIBRARY_COLOR_BORDERMIDDLE);
	graphics.FillRectangle (&linRightGrBrush, RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_BORDERWIDTH, 0,
							(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f,
							IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS));
	LinearGradientBrush linRight2GrBrush (PointF(IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f, 0),
										PointF(IGIMAGELIBRARY_WIDTH, 0),
										IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDEROUT);
	graphics.FillRectangle (&linRight2GrBrush, RectF (IGIMAGELIBRARY_WIDTH - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f, 0,
							(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f,
							IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS));
	
	// Bottom part
	LinearGradientBrush linBottomGrBrush (PointF (0, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_BORDERWIDTH - 1.0f),
											PointF (0, IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f),
							IGIMAGELIBRARY_COLOR_BORDERIN, IGIMAGELIBRARY_COLOR_BORDERMIDDLE);
	graphics.FillRectangle (&linBottomGrBrush, RectF (IGIMAGELIBRARY_CORNERRADIUS, 
												IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_BORDERWIDTH,
												IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM,
												(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f));
	LinearGradientBrush linBottom2GrBrush (PointF(0,IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f - 1.0f),
											PointF(0,IGIMAGELIBRARY_HEIGHT),
							IGIMAGELIBRARY_COLOR_BORDERMIDDLE, IGIMAGELIBRARY_COLOR_BORDEROUT);
	graphics.FillRectangle (&linBottom2GrBrush, RectF (IGIMAGELIBRARY_CORNERRADIUS, 
												IGIMAGELIBRARY_HEIGHT - (float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f,
												IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM,
												(float)IGIMAGELIBRARY_BORDERWIDTH / 2.0f));

	// Bottom left part
	GraphicsPath pathBottomLeft;
	pathBottomLeft.AddEllipse (RectF (-5, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERDIAM,
										IGIMAGELIBRARY_CORNERDIAM + 10.0f, IGIMAGELIBRARY_CORNERDIAM));
	PathGradientBrush pthGrBrushBottomLeft (&pathBottomLeft);
	Color colorsBottom[] = {IGIMAGELIBRARY_COLOR_BORDEROUT,
								IGIMAGELIBRARY_COLOR_BORDERMIDDLE,
								IGIMAGELIBRARY_COLOR_BORDERIN,
								IGIMAGELIBRARY_COLOR_FRAMEBORDER,
								IGIMAGELIBRARY_COLOR_FRAMEBORDER};
	REAL interpPositionsBottom[] = {   0.0f,
									   0.28f,
									   0.49f,
									   0.50f,
									   1.0f};
	pthGrBrushBottomLeft.SetInterpolationColors (colorsBottom, interpPositionsBottom, 5);
	graphics.FillRectangle (&pthGrBrushBottomLeft, RectF (0, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS,
															IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS));

	// Bottom right part
	REAL interpPositionsBottomRight[] = {   0.0f,
									   		0.30f,
									   		0.54f,
									   		0.55f,
									   		1.0f};
	GraphicsPath pathBottomRight;
	pathBottomRight.AddEllipse (RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERDIAM, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERDIAM - 5,
										IGIMAGELIBRARY_CORNERDIAM, IGIMAGELIBRARY_CORNERDIAM + 10));
	PathGradientBrush pthGrBrushBottomRight (&pathBottomRight);
	pthGrBrushBottomRight.SetInterpolationColors (colorsBottom, interpPositionsBottomRight, 5);
	graphics.FillRectangle (&pthGrBrushBottomRight, RectF (IGIMAGELIBRARY_WIDTH - IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_HEIGHT - IGIMAGELIBRARY_CORNERRADIUS,
															IGIMAGELIBRARY_CORNERRADIUS, IGIMAGELIBRARY_CORNERRADIUS));
	return S_OK;
}