コード例 #1
0
GraphicsPath* GdipCreateRoundRect( RectF& rect, int nRadiusLT, int nRadiusRT, int nRadiusRB, int nRadiusLB )
{
	GraphicsPath roundRect;
	if( nRadiusLT == 0 )
		roundRect.AddLine( rect.GetLeft(), rect.GetTop(), rect.GetRight() - (nRadiusRT<<1), rect.GetTop() );
	else
		roundRect.AddArc( RectF(rect.GetLeft(), rect.GetTop(), (float)(nRadiusLT<<1), (float)(nRadiusLT<<1)), 180, 90 );

	if( nRadiusRT == 0 )
		roundRect.AddLine( rect.GetRight(), rect.GetTop(), rect.GetRight(), rect.GetBottom()-(float)(nRadiusRB<<1) );
	else
		roundRect.AddArc( RectF(rect.GetRight() - (float)(nRadiusRT<<1), rect.GetTop(), (float)(nRadiusRT<<1), (float)(nRadiusRT<<1)), 270, 90 );

	if( nRadiusRB == 0 )
		roundRect.AddLine( rect.GetRight(), rect.GetBottom(), rect.GetLeft()-(float)(nRadiusLB<<1), rect.GetBottom() );
	else
		roundRect.AddArc( RectF(rect.GetRight() - (float)(nRadiusRB<<1), rect.GetBottom() -(float)(nRadiusRB<<1), (float)(nRadiusRB<<1), (float)(nRadiusRB<<1)), 0, 90 );

	if( nRadiusLB == 0 )
		roundRect.AddLine( rect.GetLeft(), rect.GetBottom(), rect.GetLeft(), rect.GetTop()-(float)(nRadiusLT<<1) );
	else
		roundRect.AddArc( RectF(rect.GetLeft(), rect.GetBottom() -(float)(nRadiusLB<<1), (float)(nRadiusLB<<1), (float)(nRadiusLB<<1)), 90, 90 );

	roundRect.CloseFigure();

	return roundRect.Clone();
}
コード例 #2
0
ファイル: Tabs.cpp プロジェクト: jingyu9575/sumatrapdf
    // Calculates tab's elements, based on its width and height.
    // Generates a GraphicsPath, which is used for painting the tab, etc.
    bool Reshape(int dx, int dy) {
        dx--;
        if (width == dx && height == dy)
            return false;
        width = dx;
        height = dy;

        GraphicsPath shape;
        // define tab's body
        shape.AddRectangle(Rect(0, 0, width, height));
        shape.SetMarker();

        // define "x"'s circle
        int c = int((float)height * 0.78f + 0.5f); // size of bounding square for the circle
        int maxC = DpiScaleX(hwnd, 17);
        if (height > maxC) {
            c = DpiScaleX(hwnd, 17);
        }
        Point p(width - c - DpiScaleX(hwnd, 3), (height - c) / 2); // circle's position
        shape.AddEllipse(p.X, p.Y, c, c);
        shape.SetMarker();
        // define "x"
        int o = int((float)c * 0.286f + 0.5f); // "x"'s offset
        shape.AddLine(p.X + o, p.Y + o, p.X + c - o, p.Y + c - o);
        shape.StartFigure();
        shape.AddLine(p.X + c - o, p.Y + o, p.X + o, p.Y + c - o);
        shape.SetMarker();

        delete data;
        data = new PathData();
        shape.GetPathData(data);
        return true;
    }
コード例 #3
0
ファイル: Tabs.cpp プロジェクト: professosaurus/sumatrapdf
    // Calculates tab's elements, based on its width and height.
    // Generates a GraphicsPath, which is used for painting the tab, etc.
    bool Reshape(int dx, int dy) {
        dx--;
        if (width == dx && height == dy)
            return false;
        width = dx; height = dy;

        GraphicsPath shape;
        // define tab's body
        int c = int((float)height * 0.6f + 0.5f); // size of bounding square for the arc
        shape.AddArc(0, 0, c, c, 180.0f, 90.0f);
        shape.AddArc(width - c, 0, c, c, 270.0f, 90.0f);
        shape.AddLine(width, height, 0, height);
        shape.CloseFigure();
        shape.SetMarker();
        // define "x"'s circle
        c = height > 17 ? 14 : int((float)height * 0.78f + 0.5f); // size of bounding square for the circle
        Point p(width - c - 3, (height - c) / 2); // circle's position
        shape.AddEllipse(p.X, p.Y, c, c);
        shape.SetMarker();
        // define "x"
        int o = int((float)c * 0.286f + 0.5f); // "x"'s offset
        shape.AddLine(p.X+o, p.Y+o, p.X+c-o, p.Y+c-o);
        shape.StartFigure();
        shape.AddLine(p.X+c-o, p.Y+o, p.X+o, p.Y+c-o);
        shape.SetMarker();

        delete data;
        data = new PathData();
        shape.GetPathData(data);
        return true;
    }
コード例 #4
0
/*
** Draws the meter on the double buffer
**
*/
bool MeterRoundLine::Draw(Gfx::Canvas& canvas)
{
	if (!Meter::Draw(canvas)) return false;

	Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();

	// Calculate the center of for the line
	int x = GetX();
	int y = GetY();
	double cx = x + m_W / 2.0;
	double cy = y + m_H / 2.0;

	double lineStart = ((m_CntrlLineStart) ? m_LineStartShift * m_Value : 0) + m_LineStart;
	double lineLength = ((m_CntrlLineLength) ? m_LineLengthShift * m_Value : 0) + m_LineLength;

	// Calculate the end point of the line
	double angle = ((m_CntrlAngle) ? m_RotationAngle * m_Value : m_RotationAngle) + m_StartAngle;
	double e_cos = cos(angle);
	double e_sin = sin(angle);

	REAL sx = (REAL)(e_cos * lineStart + cx);
	REAL sy = (REAL)(e_sin * lineStart + cy);
	REAL ex = (REAL)(e_cos * lineLength + cx);
	REAL ey = (REAL)(e_sin * lineLength + cy);

	if (m_Solid)
	{
		REAL startAngle = (REAL)(fmod(CONVERT_TO_DEGREES(m_StartAngle), 360.0));
		REAL sweepAngle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value));

		// Calculate the start point of the line
		double s_cos = cos(m_StartAngle);
		double s_sin = sin(m_StartAngle);

		//Create a path to surround the arc
		GraphicsPath path;
		path.AddArc((REAL)(cx - lineStart), (REAL)(cy - lineStart), (REAL)(lineStart * 2.0), (REAL)(lineStart * 2.0), startAngle, sweepAngle);
		path.AddLine((REAL)(lineStart * s_cos + cx), (REAL)(lineStart * s_sin + cy), (REAL)(lineLength * s_cos + cx), (REAL)(lineLength * s_sin + cy));
		path.AddArc((REAL)(cx - lineLength), (REAL)(cy - lineLength), (REAL)(lineLength * 2.0), (REAL)(lineLength * 2.0), startAngle, sweepAngle);
		path.AddLine(ex, ey, sx, sy);

		SolidBrush solidBrush(m_LineColor);
		graphics.FillPath(&solidBrush, &path);
	}
	else
	{
		Pen pen(m_LineColor, (REAL)m_LineWidth);
		graphics.DrawLine(&pen, sx, sy, ex, ey);
	}

	canvas.EndGdiplusContext();

	return true;
}
コード例 #5
0
ファイル: SvgPath.cpp プロジェクト: DBNinja/sumatrapdf
GraphicsPath *GraphicsPathFromPathData(const char *s)
{
    VecSegmented<SvgPathInstr> instr;
    if (!ParseSvgPathData(s, instr))
        return nullptr;
    GraphicsPath *gp = ::new GraphicsPath();
    PointF prevEnd(0.f, 0.f);
    for (SvgPathInstr& i : instr) {
        PathInstrType type = i.type;

        // convert relative coordinates to absolute based on end position of
        // previous element
        // TODO: support the rest of instructions
        if (MoveRel == type) {
            RelPointToAbs(prevEnd, i.v);
            type = MoveAbs;
        } else if (LineToRel == type) {
            RelPointToAbs(prevEnd, i.v);
            type = LineToAbs;
        } else if (HLineRel == type) {
            RelXToAbs(prevEnd, i.v);
            type = HLineAbs;
        } else if (VLineRel == type) {
            RelYToAbs(prevEnd, i.v);
            type = VLineAbs;
        }

        if (MoveAbs == type) {
            PointF p(i.v[0], i.v[1]);
            prevEnd = p;
            gp->StartFigure();
        } else if (LineToAbs == type) {
            PointF p(i.v[0], i.v[1]);
            gp->AddLine(prevEnd, p);
            prevEnd = p;
        } else if (HLineAbs == type) {
            PointF p(prevEnd);
            p.X = i.v[0];
            gp->AddLine(prevEnd, p);
            prevEnd = p;
        } else if (VLineAbs == type) {
            PointF p(prevEnd);
            p.Y = i.v[0];
            gp->AddLine(prevEnd, p);
            prevEnd = p;
        } else if ((Close == type) || (Close2 == type)) {
            gp->CloseFigure();
        } else {
            CrashIf(true);
        }
    }
    return gp;
}
コード例 #6
0
void CRevisionGraphWnd::DrawRoundedRect (GraphicsDevice& graphics, const Color& penColor, int penWidth, const Pen* pen, const Color& fillColor, const Brush* brush, const RectF& rect, int mask)
{

	enum {POINT_COUNT = 8};

	float radius = CORNER_SIZE * m_fZoomFactor;
	PointF points[POINT_COUNT];
	CutawayPoints (rect, radius, points);

	if (graphics.graphics)
	{
		GraphicsPath path;

		if(mask & ROUND_UP)
		{
			path.AddArc (points[0].X, points[1].Y, radius, radius, 180, 90);
			path.AddArc (points[2].X, points[2].Y, radius, radius, 270, 90);
		}else
		{
			path.AddLine(points[0].X, points[1].Y, points[3].X, points[2].Y);
		}

		if(mask & ROUND_DOWN)
		{
			path.AddArc (points[5].X, points[4].Y, radius, radius, 0, 90);
			path.AddArc (points[7].X, points[7].Y, radius, radius, 90, 90);
		}else
		{
			path.AddLine(points[3].X, points[3].Y, points[4].X, points[5].Y);
			path.AddLine(points[4].X, points[5].Y, points[7].X, points[6].Y);
		}

		points[0].Y -= radius / 2;
		path.AddLine (points[7], points[0]);

		if (brush != NULL)
		{
			graphics.graphics->FillPath (brush, &path);
		}
		if (pen != NULL)
			graphics.graphics->DrawPath (pen, &path);
	}
	else if (graphics.pSVG)
	{
		graphics.pSVG->RoundedRectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height, penColor, penWidth, fillColor, (int)radius, mask);
	}

}
コード例 #7
0
void CDrawFreeObject::Draw(HDC hDC, BOOL bOriginal)
{
	Graphics graphics(hDC);
	graphics.SetSmoothingMode(SmoothingModeAntiAlias);
	Color clrPen;
	clrPen.SetFromCOLORREF(m_logpen.lopnColor);
	Pen penObject(clrPen, m_logpen.lopnWidth.x);

	
	GraphicsPath FreePath;
	Point ptBegin;
	Point ptEnd;
	for (int i = 0; i < m_nPoints; i++)
	{
		if (i == 0)
		{
			//dc.MoveTo(m_points[i]);
			ptBegin.X = m_points[i].x;
			ptBegin.Y = m_points[i].y;
		}
		else
		{
			ptEnd.X = m_points[i].x;
			ptEnd.Y = m_points[i].y;
			//graphics.DrawLine(&penObject, ptBegin, ptEnd);
			FreePath.AddLine(ptBegin, ptEnd);
			ptBegin = ptEnd;
		}
	}
	graphics.DrawPath(&penObject, &FreePath);
}
コード例 #8
0
ファイル: IGTabBar.cpp プロジェクト: Bitlsoft/Imagenius_SDK
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);
}
コード例 #9
0
ファイル: ArcView.cpp プロジェクト: hlobit/SimPetri
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);
}
コード例 #10
0
/*
 * Converts specified int array into GraphicsPath object
 */
static inline GraphicsPath *createGraphicsPath(JNIEnv *env, jfloatArray jpath, jint len, jint winding) 
{
    jfloat *path = (jfloat *)malloc(sizeof(jfloat)*len);
    env->GetFloatArrayRegion(jpath, 0, len, path);

    
    GraphicsPath *res = new GraphicsPath((winding == java_awt_geom_PathIterator_WIND_EVEN_ODD)?FillModeAlternate:FillModeWinding);
    float x1 = 0;
    float y1 = 0;
    float mx = 0;
    float my = 0;
    for (int i = 0; i < len; i++) {
        int seg = (int)path[i];
        switch (seg) {
            case java_awt_geom_PathIterator_SEG_MOVETO:
                res->StartFigure();
                x1 = path[i+1];
                y1 = path[i+2];
                mx = path[i+1];
                my = path[i+2];
                i += 2;
                break;
            case java_awt_geom_PathIterator_SEG_LINETO:
                res->AddLine(x1, y1, path[i+1], path[i+2]);
                x1 = path[i+1];
                y1 = path[i+2];
                i += 2;
                break;
            case java_awt_geom_PathIterator_SEG_CLOSE:
                res->AddLine(x1, y1, mx, my);
                x1 = mx;
                y1 = my;
                res->CloseFigure();
                break;
        }
    }
    
    free(path);
    
    return res;
}    
コード例 #11
0
void CRectangle::DrawRoundRect(Graphics& graph,CRect rc)
{
	Pen penDraw(m_crColor,(float)m_nWidth);
	INT offsetX = (rc.right - rc.left) * 20/100;  
	INT offsetY = (rc.bottom - rc.top) * 20/100;
	GraphicsPath pt;
	pt.AddArc(rc.right - offsetX, rc.top, offsetX, offsetY, 270, 90);
	pt.AddArc(rc.right - offsetX, rc.bottom - offsetY, offsetX, offsetY, 0, 90);
	pt.AddArc(rc.left, rc.bottom - offsetY, offsetX, offsetY, 90, 90);
	pt.AddArc(rc.left, rc.top, offsetX, offsetY, 180, 90);
	pt.AddLine(rc.left + offsetX, rc.top, rc.right - offsetX/2, rc.top);

	graph.DrawPath(&penDraw,&pt);
}
コード例 #12
0
ファイル: Utils.cpp プロジェクト: vladios13/image-uploader
void DrawRoundedRectangle(Gdiplus::Graphics* gr, Gdiplus::Rect r, int d, Gdiplus::Pen* p, Gdiplus::Brush*br){
	using namespace Gdiplus;
	GraphicsPath gp;
//	d = min(min(d, r.Width),r.Height);
	gp.AddArc(r.X, r.Y, d, d, 180, 90);
	gp.AddArc(max(r.X + r.Width - d,r.X), r.Y, d, d, 270, 90);
	gp.AddArc(max(r.X, r.X + r.Width - d), max(r.Y, r.Y + r.Height - d), d, d, 0, 90);
	gp.AddArc(r.X, max(r.Y, r.Y + r.Height - d), d, d, 90, 90);
	gp.AddLine(r.X, max(r.Y, r.Y + r.Height - d), r.X, min(r.Y + d/2, r.GetBottom()));
	gp.CloseFigure();
	if ( br ) {
		gr->FillPath(br, &gp);
	}
	gr->DrawPath(p, &gp);

}
コード例 #13
0
void CRectangle::SetRegion()
{
	float left = min(m_ptary[0].X,m_ptary[1].X);
	float top = min(m_ptary[0].Y,m_ptary[1].Y);
	float width = fabs(m_ptary[0].X - m_ptary[1].X);
	float height = fabs(m_ptary[0].Y - m_ptary[1].Y);
	/*PointF* pPt = m_ptary.GetData();*/

	int nWidth = m_nWidth;
	if(m_nWidth < 6)
	{
		nWidth = 6;
	}

	Pen greenPen(Color(255, 0, 255,  0), (float)nWidth);
	GraphicsPath path;
	if(RS_ROUND == m_nRStyle)
	{
		CRect rc((int)left,(int)top,(int)(left + width),(int)(top + height));
		INT offsetX = (rc.right - rc.left) * 20/100;  
		INT offsetY = (rc.bottom - rc.top) * 20/100;
		path.AddArc(rc.right - offsetX, rc.top, offsetX, offsetY, 270, 90);
		path.AddArc(rc.right - offsetX, rc.bottom - offsetY, offsetX, offsetY, 0, 90);
		path.AddArc(rc.left, rc.bottom - offsetY, offsetX, offsetY, 90, 90);
		path.AddArc(rc.left, rc.top, offsetX, offsetY, 180, 90);
		path.AddLine(rc.left + offsetX, rc.top, rc.right - offsetX/2, rc.top);
	}
	else
	{

		RectF rcf(left,top,width,height);
		path.AddRectangle(rcf);
	}

	path.Widen(&greenPen);
	path.Outline();

	m_Region.MakeEmpty();
	m_Region.Union(&path);
}
コード例 #14
0
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;
	}
}
コード例 #15
0
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);
	}
}
コード例 #16
0
ファイル: MeterLine.cpp プロジェクト: BIGDROP/rainmeter
/*
** Draws the meter on the double buffer
**
*/
bool MeterLine::Draw(Gfx::Canvas& canvas)
{
	int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
	if (!Meter::Draw(canvas) || maxSize <= 0) return false;
	
	Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();

	double maxValue = 0.0;
	int counter = 0;

	// Find the maximum value
	if (m_Autoscale)
	{
		double newValue = 0;
		counter = 0;
		for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
		{
			double scale = m_ScaleValues[counter];
			for (auto j = (*i).cbegin(); j != (*i).cend(); ++j)
			{
				double val = (*j) * scale;
				newValue = max(newValue, val);
			}
			++counter;
		}

		// Scale the value up to nearest power of 2
		if (newValue > DBL_MAX / 2.0)
		{
			maxValue = DBL_MAX;
		}
		else
		{
			maxValue = 2.0;
			while (maxValue < newValue)
			{
				maxValue *= 2.0;
			}
		}
	}
	else
	{
		for (auto i = m_Measures.cbegin(); i != m_Measures.cend(); ++i)
		{
			double val = (*i)->GetMaxValue();
			maxValue = max(maxValue, val);
		}

		if (maxValue == 0.0)
		{
			maxValue = 1.0;
		}
	}

	int x = GetX();
	int y = GetY();

	// Draw the horizontal lines
	if (m_HorizontalLines)
	{
		// Calc the max number of lines we should draw
		int maxLines = m_H / 4;	// one line per 4 pixels is max
		int numOfLines;

		// Check the highest power of 2 that fits in maxLines
		int power = 2;
		while (power < maxLines)
		{
			power *= 2;
		}

		numOfLines = ((int)maxValue % power) + 1;

		Pen pen(m_HorizontalColor);

		REAL Y;
		for (int j = 0; j < numOfLines; ++j)
		{
			Y = (REAL)((j + 1) * m_H / (numOfLines + 1));
			Y = y + m_H - Y - 1;
			graphics.DrawLine(&pen, (REAL)x, Y, (REAL)(x + m_W - 1), Y);	// GDI+
		}
	}

	// Draw all the lines

	if (m_GraphHorizontalOrientation)
	{
		const REAL W = m_W - 1.0f;
		counter = 0;
		for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
		{
			// Draw a line
			REAL X, oldX;

			const double scale = m_ScaleValues[counter] * W / maxValue;

			int pos = m_CurrentPos;

			auto calcX = [&](REAL& _x)
			{
				_x = (REAL)((*i)[pos] * scale);
				_x = min(_x, W);
				_x = max(_x, 0.0f);
				_x = x + (m_GraphStartLeft ? _x : W - _x);
			};

			calcX(oldX);

			// Cache all lines
			GraphicsPath path;
		
			if (!m_Flip)
			{
				for (int j = y + 1, R = y + m_H; j < R; ++j)
				{
					++pos;
					pos %= m_H;

					calcX(X);

					path.AddLine(oldX, (REAL)(j - 1), X, (REAL)j);

					oldX = X;
				}
			}
			else
			{
				for (int j = y + m_H, R = y + 1; j > R; --j)
				{
					++pos;
					pos %= m_H;

					calcX(X);

					path.AddLine(oldX, (REAL)(j - 1), X, (REAL)(j - 2));

					oldX = X;
				}
			}

			// Draw cached lines
			Pen pen(m_Colors[counter], (REAL)m_LineWidth);
			pen.SetLineJoin(LineJoinBevel);
			graphics.DrawPath(&pen, &path);

			++counter;
		}
	}
	else
	{
		const REAL H = m_H - 1.0f;
		counter = 0;
		for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
		{
			// Draw a line
			REAL Y, oldY;

			const double scale = m_ScaleValues[counter] * H / maxValue;

			int pos = m_CurrentPos;

			auto calcY = [&](REAL& _y)
			{
				_y = (REAL)((*i)[pos] * scale);
				_y = min(_y, H);
				_y = max(_y, 0.0f);
				_y = y + (m_Flip ? _y : H - _y);
			};

			calcY(oldY);

			// Cache all lines
			GraphicsPath path;
		
			if (!m_GraphStartLeft)
			{
				for (int j = x + 1, R = x + m_W; j < R; ++j)
				{
					++pos;
					pos %= m_W;

					calcY(Y);

					path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y);

					oldY = Y;
				}
			}
			else
			{
				for (int j = x + m_W, R = x + 1; j > R; --j)
				{
					++pos;
					pos %= m_W;

					calcY(Y);

					path.AddLine((REAL)(j - 1), oldY, (REAL)(j - 2), Y);

					oldY = Y;
				}
			}

			// Draw cached lines
			Pen pen(m_Colors[counter], (REAL)m_LineWidth);
			pen.SetLineJoin(LineJoinBevel);
			graphics.DrawPath(&pen, &path);

			++counter;
		}
	}

	canvas.EndGdiplusContext();

	return true;
}
コード例 #17
0
ファイル: MeterLine.cpp プロジェクト: RichVRed/rainmeter
/*
** Draws the meter on the double buffer
**
*/
bool CMeterLine::Draw(Graphics& graphics)
{
	int maxSize = m_GraphHorizontalOrientation ? m_H : m_W;
	if (!CMeter::Draw(graphics) || maxSize <= 0) return false;

	double maxValue = 0.0;
	int counter = 0;

	// Find the maximum value
	if (m_Autoscale)
	{
		double newValue = 0;
		std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
		counter = 0;
		for (; i != m_AllValues.end(); ++i)
		{
			double scale = m_ScaleValues[counter];
			std::vector<double>::const_iterator j = (*i).begin();
			for (; j != (*i).end(); ++j)
			{
				double val = (*j) * scale;
				newValue = max(newValue, val);
			}
			++counter;
		}

		// Scale the value up to nearest power of 2
		if (newValue > DBL_MAX / 2.0)
		{
			maxValue = DBL_MAX;
		}
		else
		{
			maxValue = 2.0;
			while (maxValue < newValue)
			{
				maxValue *= 2.0;
			}
		}
	}
	else
	{
		if (m_Measure)
		{
			maxValue = m_Measure->GetMaxValue();

			std::vector<CMeasure*>::const_iterator i = m_Measures.begin();
			for (; i != m_Measures.end(); ++i)
			{
				double val = (*i)->GetMaxValue();
				maxValue = max(maxValue, val);
			}
		}

		if (maxValue == 0.0)
		{
			maxValue = 1.0;
		}
	}

	int x = GetX();
	int y = GetY();

	// Draw the horizontal lines
	if (m_HorizontalLines)
	{
		// Calc the max number of lines we should draw
		int maxLines = m_H / 4;	// one line per 4 pixels is max
		int numOfLines;

		// Check the highest power of 2 that fits in maxLines
		int power = 2;
		while (power < maxLines)
		{
			power *= 2;
		}

		numOfLines = ((int)maxValue % power) + 1;

		Pen pen(m_HorizontalColor);

		REAL Y;
		for (int j = 0; j < numOfLines; ++j)
		{
			Y = (REAL)((j + 1) * m_H / (numOfLines + 1));
			Y = y + m_H - Y - 1;
			graphics.DrawLine(&pen, (REAL)x, Y, (REAL)(x + m_W - 1), Y);	// GDI+
		}
	}

	// Draw all the lines

	if (m_GraphHorizontalOrientation)
	{
		const REAL W = m_W - 1.0f;
		counter = 0;
		std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
		for (; i != m_AllValues.end(); ++i)
		{
			// Draw a line
			REAL X, oldX;

			const double scale = m_ScaleValues[counter] * W / maxValue;

			int pos = m_CurrentPos;

			oldX = (REAL)((*i)[pos] * scale);
			oldX = min(oldX, W);
			oldX = max(oldX, 0.0f);
			oldX = x + (m_GraphStartLeft ? oldX : W - oldX);

			// Cache all lines
			GraphicsPath path;
		
			if (!m_Flip)
			{
				for (int j = y + 1, R = y + m_H; j < R; ++j)
				{
					++pos;
					if (pos >= m_H) pos = 0;

					X = (REAL)((*i)[pos] * scale);
					X = min(X, W);
					X = max(X, 0.0f);
					X = x + (m_GraphStartLeft ? X : W - X);

					path.AddLine(oldX, (REAL)(j - 1), X, (REAL)j);

					oldX = X;
				}
			}
			else
			{
				for (int j = y + m_H, R = y + 1; j > R; --j)
				{
					++pos;
					if (pos >= m_H) pos = 0;

					X = (REAL)((*i)[pos] * scale);
					X = min(X, W);
					X = max(X, 0.0f);
					X = x + (m_GraphStartLeft ? X : W - X);

					path.AddLine(oldX, (REAL)(j - 1), X, (REAL)(j - 2));

					oldX = X;
				}
			}

			// Draw cached lines
			Pen pen(m_Colors[counter], (REAL)m_LineWidth);
			pen.SetLineJoin(LineJoinBevel);
			graphics.DrawPath(&pen, &path);

			++counter;
		}
	}
	else
	{
		const REAL H = m_H - 1.0f;
		counter = 0;
		std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
		for (; i != m_AllValues.end(); ++i)
		{
			// Draw a line
			REAL Y, oldY;

			const double scale = m_ScaleValues[counter] * H / maxValue;

			int pos = m_CurrentPos;

			oldY = (REAL)((*i)[pos] * scale);
			oldY = min(oldY, H);
			oldY = max(oldY, 0.0f);
			oldY = y + (m_Flip ? oldY : H - oldY);

			// Cache all lines
			GraphicsPath path;
		
			if (!m_GraphStartLeft)
			{
				for (int j = x + 1, R = x + m_W; j < R; ++j)
				{
					++pos;
					if (pos >= m_W) pos = 0;

					Y = (REAL)((*i)[pos] * scale);
					Y = min(Y, H);
					Y = max(Y, 0.0f);
					Y = y + (m_Flip ? Y : H - Y);

					path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y);

					oldY = Y;
				}
			}
			else
			{
				for (int j = x + m_W, R = x + 1; j > R; --j)
				{
					++pos;
					if (pos >= m_W) pos = 0;

					Y = (REAL)((*i)[pos] * scale);
					Y = min(Y, H);
					Y = max(Y, 0.0f);
					Y = y + (m_Flip ? Y : H - Y);

					path.AddLine((REAL)(j - 1), oldY, (REAL)(j - 2), Y);

					oldY = Y;
				}
			}

			// Draw cached lines
			Pen pen(m_Colors[counter], (REAL)m_LineWidth);
			pen.SetLineJoin(LineJoinBevel);
			graphics.DrawPath(&pen, &path);

			++counter;
		}
	}

	return true;
}
コード例 #18
0
void CLMenu::DrawBckg()
{
	CRect r;
	GetWindowRect(&r);

	bckg->Resize(r.Width(), r.Height());
	if(!bckg->Ready())
	{
		return;
	}

	Graphics g(bckg->dc);
	g.SetSmoothingMode(SmoothingModeAntiAlias);
	g.SetCompositingMode(CompositingModeSourceCopy);

	SolidBrush brush(Color(255 * 70 / 100, 0, 0, 0));

	GraphicsPath *path = new GraphicsPath();

	if(parent)
	{
		path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
		path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
		path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
		path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
	}
	else
	{
		switch(position)
		{
		case DockPositionTop:
			{
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 180, 90);
					
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT + arrowOffset, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE);
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT);
			}
			break;

		case DockPositionBottom:
			{
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 0, 90);
				
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE);
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT);
			}
			break;

		default:
			{
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
			}
			break;
		}
	}

	path->CloseFigure();
	g.FillPath(&brush, path);
	delete path;

	if(parent)
	{
		bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), 
			CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), 
			SHADOW_SIZE);
	}
	else
	{
		switch(position)
		{
		case DockPositionTop:
			{
				bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), 
					CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2 + ARROW_HEIGHT, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), 
					SHADOW_SIZE);
			}
			break;

		case DockPositionBottom:
			{
				bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), 
					CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2 - ARROW_HEIGHT), 
					SHADOW_SIZE);
			}
			break;

		default:
			{
				bckg->Blur(CRect(0, 0, bckg->Width(), bckg->Height()), 
					CRect(SHADOW_SIZE * 2, SHADOW_SIZE * 2, bckg->Width() - SHADOW_SIZE * 2, bckg->Height() - SHADOW_SIZE * 2), 
					SHADOW_SIZE);
			}
			break;
		}
	}
}
コード例 #19
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;
}
コード例 #20
0
ファイル: print_gdiplus.cpp プロジェクト: Budskii/ulib-win
    virtual void onDraw(HDC hdc)
    {
        Graphics graphics(hdc);
        
         USmartDC dc(hdc);
         huys::URectL rect;
         this->getClientRect(rect);
  
         //
         LinearGradientBrush lgb(Point(0, 0), Point(rect.right(), rect.bottom()), Color::Blue, Color::Green);
         //
         graphics.FillRectangle(&lgb, 0, 0, rect.right(), rect.bottom());

        //
        Pen      pen(Color(255, 255, 255, 255));
        graphics.DrawLine(&pen, 0, 0, 200, 100);

        //
        Pen blackPen(Color(255, 255, 0, 0), 5);
        graphics.DrawRectangle(&blackPen, 290, 100, 100, 50);

        //
        Pen blackPen2(Color(255, 0, 0, 0), 1);
        Pen greenPen(Color(255, 0, 255, 0), 10);
        greenPen.SetAlignment(PenAlignmentCenter);

        // Draw the line with the wide green pen.
        graphics.DrawLine(&greenPen, 310, 100, 400, 50);

        // Draw the same line with the thin black pen.
        graphics.DrawLine(&blackPen2, 310, 100, 400, 50);


        greenPen.SetAlignment(PenAlignmentInset);
        // Draw the rectangle with the wide green pen.
        graphics.DrawRectangle(&greenPen, 510, 100, 50, 50);

        // Draw the same rectangle with the thin black pen.
        graphics.DrawRectangle(&blackPen2, 510, 100, 50, 50);

        //
        SolidBrush solidBrush(Color(255, 255, 0, 0));
        graphics.FillEllipse(&solidBrush, 0, 0, 100, 60);

        //
        SolidBrush  brush(Color(255, 0, 0, 255));
        FontFamily  fontFamily(L"Times New Roman");
        Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
        PointF      pointF(10.0f, 20.0f);

        graphics.DrawString(L"Hello World!", -1, &font, pointF, &brush);

        GraphicsPath path;
        Pen penJoin(Color(255, 0, 0, 255), 8);

        path.StartFigure();
        path.AddLine(Point(50, 200), Point(100, 200));
        path.AddLine(Point(100, 200), Point(100, 250));

        penJoin.SetLineJoin(LineJoinBevel);
        graphics.DrawPath(&penJoin, &path);

        pen.SetStartCap(LineCapArrowAnchor);
        pen.SetEndCap(LineCapRoundAnchor);
        graphics.DrawLine(&pen, 20, 175, 300, 175);

        REAL dashValues[4] = {5, 2, 15, 4};
        Pen blackPen3(Color(255, 0, 0, 0), 2);
        blackPen3.SetDashPattern(dashValues, 4);
        graphics.DrawLine(&blackPen3, Point(5, 225), Point(405, 225));

        Image         image(L"Texture.jpg");
        TextureBrush  tBrush(&image);
        Pen           texturedPen(&tBrush, 30);

        graphics.DrawImage(&image, 499, 366, image.GetWidth(), image.GetHeight());
        graphics.DrawEllipse(&texturedPen, 600, 220, 200, 100);

        Pen opaquePen(Color(255, 0, 0, 255), 15);
        Pen semiTransPen(Color(128, 0, 0, 255), 15);
        graphics.DrawLine(&opaquePen, 480, 380, 640, 380);
        graphics.DrawLine(&semiTransPen, 480, 400, 640, 400);
        graphics.SetCompositingQuality(CompositingQualityGammaCorrected);
        graphics.DrawLine(&semiTransPen, 480, 420, 640, 420);

        LinearGradientBrush linGrBrush(
            Point(0, 10),
            Point(200, 10),
            Color(255, 255, 0, 0),   // opaque red
            Color(255, 0, 0, 255));  // opaque blue

        Pen penx(&linGrBrush);

        graphics.DrawLine(&penx, 0, 410, 200, 410);
        graphics.FillEllipse(&linGrBrush, 20, 360, 200, 400);
        graphics.FillRectangle(&linGrBrush, 30, 355, 200, 400);
        
        Point points[] =
        {
          Point(0, 0), Point(100, 200), Point(200, 0), Point(300, 200), Point(400, 00)
        };
        //
        for (int i = 0; i < 4; i++)
        {
            graphics.DrawLine(&Pen(Color::White, 3), points[i], points[i + 1]);
        }
        //
        graphics.DrawCurve(&Pen(Color::Red, 3), points, 5);
    }
コード例 #21
0
void CXTPFlowGraphPaintManager::RecalcConnectionLayout(CXTPFlowGraphDrawContext* /*pDC*/, CXTPFlowGraphConnection* pConnection)
{
	CXTPFlowGraphConnectionPoint* pFrom = pConnection->GetOutputPoint();
	CXTPFlowGraphConnectionPoint* pTo = pConnection->GetInputPoint();

	if (pFrom == NULL)
		return;

	CPoint ptFrom, ptTo;

	ptFrom = pFrom->GetNode()->GetLocation();
	ptFrom.x += pFrom->GetNode()->GetSize().cx;
	ptFrom.y += pFrom->m_rcPoint.CenterPoint().y;

	if (pTo != NULL)
	{
		ptTo = pTo->GetNode()->GetLocation();
		ptTo.y += pTo->m_rcPoint.CenterPoint().y;

		if (pTo->GetType() == xtpFlowGraphPointInputAndOutput)
		{
			if (ptFrom.x > ptTo.x)
				ptTo.x += pTo->GetNode()->GetSize().cx;
		}

		pConnection->m_ptInputPoint = ptTo;
	}
	else
	{
		ptTo = pConnection->m_ptInputPoint;
	}

	if (pFrom->GetType() == xtpFlowGraphPointInputAndOutput)
	{
		if (ptTo.x < ptFrom.x - pFrom->GetNode()->GetSize().cx / 2)
			ptFrom.x -= pFrom->GetNode()->GetSize().cx;
	}


	pConnection->m_ptOutputPoint = ptFrom;

	GraphicsPath* path = new GraphicsPath();

	XTPFlowGraphConnectorType type = pConnection->GetStyle() == -1 ? m_nConnectorType : (XTPFlowGraphConnectorType)pConnection->GetStyle();

	CPoint ptControlPoint = pConnection->GetControlPoint();

	if (type == xtpFlowGraphConnectorStraight)
	{
		if (ptControlPoint != CPoint(-1, -1))
		{
			Point pts[] = {Point(ptFrom.x, ptFrom.y), Point(ptControlPoint.x, ptControlPoint.y), Point(ptTo.x, ptTo.y) };

			path->AddLines(pts, 3);
		}
		else
		{
			path->AddLine(ptFrom.x, ptFrom.y, ptTo.x, ptTo.y);
		}
	}
	else
	{
		if (ptControlPoint != CPoint(-1, -1))
		{
			/*PointF pt[3] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y), PointF((REAL)pConnection->GetControlPoint().x, (REAL)pConnection->GetControlPoint().y),
			PointF((REAL)ptTo.x, (REAL)ptTo.y) };
			path->AddCurve(pt, 3);*/

			PointF pt2[4] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y),
				PointF((REAL)ptControlPoint.x, (REAL)ptFrom.y), PointF((REAL)ptControlPoint.x,  (REAL)ptTo.y),
				PointF((REAL)ptTo.x, (REAL)ptTo.y) };

			path->AddBeziers(pt2, 4);

		}
		else
		{
			PointF pt[4] = {PointF((REAL)ptFrom.x, (REAL)ptFrom.y), PointF((REAL)(ptFrom.x + ptTo.x) / 2, (REAL)ptFrom.y),
				PointF(REAL(ptFrom.x + ptTo.x) / 2, (REAL)ptTo.y), PointF((REAL)ptTo.x, (REAL)ptTo.y) };
			path->AddBeziers(pt, 4);
		}
	}


	SAFE_DELETE(pConnection->m_pPath);
	pConnection->m_pPath = path;

}
コード例 #22
0
void CLMenu::DrawLayer(CDIB *dib)
{
	if(!dib)
	{
		dib = CLMenu::dib;
	}

	CRect r;
	GetWindowRect(&r);

	dib->Assign(bckg);
	//dib.Resize(bckg.Width(), bckg.Height());
	if(!dib->Ready())
	{
		return;
	}

	Graphics g(dib->dc);
	g.SetSmoothingMode(SmoothingModeAntiAlias);
	g.SetCompositingMode(CompositingModeSourceCopy);

	SolidBrush brush(Color(255 * BCKG_OPACITY / 100, 0x10, 0x10, 0x10));
	Pen pen(Color(0xd0, 0xd0, 0xd0), BORDER_SIZE);
	GraphicsPath *path = new GraphicsPath();

	if(parent)
	{
		path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
		path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
		path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
		path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
	}
	else
	{
		switch(position)
		{
		case DockPositionTop:
			{
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE + ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 180, 90);
					
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE);
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)SHADOW_SIZE + ARROW_HEIGHT);
			}
			break;

		case DockPositionBottom:
			{
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE - ARROW_HEIGHT, RADIUS - 1, RADIUS - 1, 0, 90);
				
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT, (REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE);
				path->AddLine((REAL)SHADOW_SIZE + RADIUS / 2 + ARROW_WIDTH / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE, (REAL)SHADOW_SIZE + RADIUS / 2 + arrowOffset, (REAL)bckg->Height() - 1 - SHADOW_SIZE - ARROW_HEIGHT);
			}
			break;

		default:
			{
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 270, 90);
				path->AddArc(bckg->Width() - RADIUS - SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 0, 90);
				path->AddArc(SHADOW_SIZE, bckg->Height() - RADIUS - SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 90, 90);
				path->AddArc(SHADOW_SIZE, SHADOW_SIZE, RADIUS - 1, RADIUS - 1, 180, 90);
			}
			break;
		}
	}

	path->CloseFigure();
	g.FillPath(&brush, path);

	g.SetCompositingMode(CompositingModeSourceOver);
	g.DrawPath(&pen, path);

	delete path;

	g.SetCompositingMode(CompositingModeSourceCopy);

	POSITION p = items.GetHeadPosition();
	while(p)
	{
		UpdateItem(&g, items.GetAt(p));
		items.GetNext(p);
	}
}
コード例 #23
0
/*
** Draws the meter on the double buffer
**
*/
bool MeterSegmentedLine::Draw(Gfx::Canvas& canvas)
{
	int maxSize = m_DataWidth;
	if (!Meter::Draw(canvas) || maxSize <= 0) return false;
	
	Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();

	double maxValue = 0.0;
	int counter = 0;

	// Find the maximum value
	if (m_Autoscale)
	{
		double newValue = 0;
		counter = 0;
		for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
		{
			double scale = m_ScaleValues[counter];
			for (auto j = (*i).cbegin(); j != (*i).cend(); ++j)
			{
				double val = (*j) * scale;
				newValue = max(newValue, val);
			}
			++counter;
		}

		// Scale the value up to nearest power of 2
		if (newValue > DBL_MAX / 2.0)
		{
			maxValue = DBL_MAX;
		}
		else
		{
			maxValue = 2.0;
			while (maxValue < newValue)
			{
				maxValue *= 2.0;
			}
		}
	}
	else
	{
		for (auto i = m_Measures.cbegin(); i != m_Measures.cend(); ++i)
		{
			double val = (*i)->GetMaxValue();
			maxValue = max(maxValue, val);
		}

		if (maxValue == 0.0)
		{
			maxValue = 1.0;
		}
	}

	Gdiplus::Rect meterRect = GetMeterRectPadding();

	// Draw all the lines
	const REAL H = meterRect.Height - 1.0f;
	counter = 0;
	auto pointsBuffer = m_Points.cbegin();
	for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
	{
		// Draw a line
		REAL Y, oldY;

		const double scale = m_ScaleValues[counter] * H / maxValue;

		int pos = m_CurrentPos;

		auto calcY = [&](REAL& _y, REAL stepSize, int currPos)		//TODO: move this lambda elsewhere
		{
			_y = 0;
			switch (m_CurveFitMethod)
			{
				//first value
				case 0:	_y = (REAL)((*i)[currPos]);
						break;

				//maximum value
				case 1: for (int ind = 0; ind < stepSize; ind++)
							_y = max(_y, (REAL)((*i)[(currPos + ind) % m_DataWidth]));
						break;

				//arithmetic mean
				case 2: for (int ind = 0; ind < stepSize; ind++)
							_y += (REAL)((*i)[(currPos + ind) % m_DataWidth]);
						_y /= stepSize;
						break;

				default: _y = (REAL)((*i)[currPos]);
			}
			
			_y *= scale;
			_y = min(_y, H);
			_y = max(_y, 0.0f);
			_y = meterRect.Y + (H - _y);
		};

		// Cache all lines
		GraphicsPath path;
		int segmentInd = 0,
			step,
			divider;

		//compute y values
		step = m_SegmentDividers[m_SegmentDividers.size() - 1];
		divider = m_Segments.size() > 0 ? m_W - m_Segments[m_Segments.size() - 1] : m_W;
		for (int j = 0; j < m_W; ++j)
		{
			calcY(Y, step, pos - pos % step);
			(*pointsBuffer)[j] = Y;

			if (segmentInd < m_Segments.size() && j >= divider)
			{
				segmentInd++;

				step = m_SegmentDividers[m_SegmentDividers.size() - segmentInd - 1];
				divider = segmentInd != m_Segments.size() ? m_W - m_Segments[m_Segments.size() - segmentInd - 1] : m_W;
			}

			pos += step;
			pos %= m_DataWidth;
		}
		
		//draw y values
		segmentInd = 0;
		divider = m_Segments.size() > 0 ? m_W - m_Segments[m_Segments.size() - segmentInd - 1] : m_W;
		if (!m_GraphStartLeft)
		{
			for (int j = 1; j < m_W; ++j)
			{
				if (segmentInd < m_Segments.size() && j >= divider)
				{
					segmentInd++;
					path.SetMarker();
					path.StartFigure();

					divider = segmentInd != m_Segments.size() ? m_W - m_Segments[m_Segments.size() - segmentInd - 1] : m_W;
				}

				path.AddLine((REAL)(meterRect.X + j - 1), (*pointsBuffer)[j - 1], (REAL)(meterRect.X + j), (*pointsBuffer)[j]);
			}
		}
		else
		{
			for (int j = 1; j < m_W; ++j)
			{
				if (segmentInd < m_Segments.size() && j >= divider)
				{
					segmentInd++;
					path.SetMarker();
					path.StartFigure();
					divider = segmentInd != m_Segments.size() ? m_W - m_Segments[m_Segments.size() - segmentInd - 1] : m_W;
				}

				path.AddLine((REAL)(meterRect.X + meterRect.Width - j), (*pointsBuffer)[j - 1], (REAL)(meterRect.X + meterRect.Width - j - 1), (*pointsBuffer)[j]);
			}
		}

		// Draw cached lines
		GraphicsPathIterator pathIter(&path);
		GraphicsPath subPath;
		for (auto color = m_Colors[counter].rbegin(); color != m_Colors[counter].rend(); ++color)
		{
			pathIter.NextMarker(&subPath);

			Pen pen(*color, (REAL)m_LineWidth);
			pen.SetLineJoin(LineJoinRound);
			graphics.DrawPath(&pen, &subPath);
		}

		++counter;
		++pointsBuffer;
	}

	canvas.EndGdiplusContext();

	return true;
}