GDI+ and RoundRect
-
Hi, Does anyone know if the Gdiplus::Graphics class sports a [Fill|Draw]RoundRect() function (or similar.) I know I can use a GraphicsPath object (with lines and arcs) to represent the same shape, but it seems strange that such a basic function could be omitted by the implementation? /Andreas
-
Hi, Does anyone know if the Gdiplus::Graphics class sports a [Fill|Draw]RoundRect() function (or similar.) I know I can use a GraphicsPath object (with lines and arcs) to represent the same shape, but it seems strange that such a basic function could be omitted by the implementation? /Andreas
Nope - not there. I did it like this:
GraphicsPath* CGPaintShape::MakeRoundRect(Point topLeft, Point bottomRight, INT percentageRounded)
{
ASSERT (percentageRounded >= 0 && percentageRounded <= 100);// Like they said in the X Files - Trust No One. Rather than crash and burn, // I just pull out the correct edges from the points given, regardless of if they were wrong. INT left = MIN(topLeft.X, bottomRight.X); INT right = MAX(topLeft.X, bottomRight.X); INT top = MIN(topLeft.Y, bottomRight.Y); INT bottom = MAX(topLeft.Y, bottomRight.Y); INT offsetX = (right-left)\*percentageRounded/100; INT offsetY = (bottom-top)\*percentageRounded/100; GraphicsPath \* path = new GraphicsPath; path->AddArc(right-offsetX, top, offsetX, offsetY, 270, 90); path->AddArc(right-offsetX, bottom-offsetY, offsetX, offsetY, 0, 90); path->AddArc(left, bottom - offsetY, offsetX, offsetY, 90, 90); path->AddArc(left, top, offsetX, offsetY, 180, 90); path->AddLine(left + offsetX, top, right - offsetX/2, top); return path;
}
Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
Nope - not there. I did it like this:
GraphicsPath* CGPaintShape::MakeRoundRect(Point topLeft, Point bottomRight, INT percentageRounded)
{
ASSERT (percentageRounded >= 0 && percentageRounded <= 100);// Like they said in the X Files - Trust No One. Rather than crash and burn, // I just pull out the correct edges from the points given, regardless of if they were wrong. INT left = MIN(topLeft.X, bottomRight.X); INT right = MAX(topLeft.X, bottomRight.X); INT top = MIN(topLeft.Y, bottomRight.Y); INT bottom = MAX(topLeft.Y, bottomRight.Y); INT offsetX = (right-left)\*percentageRounded/100; INT offsetY = (bottom-top)\*percentageRounded/100; GraphicsPath \* path = new GraphicsPath; path->AddArc(right-offsetX, top, offsetX, offsetY, 270, 90); path->AddArc(right-offsetX, bottom-offsetY, offsetX, offsetY, 0, 90); path->AddArc(left, bottom - offsetY, offsetX, offsetY, 90, 90); path->AddArc(left, top, offsetX, offsetY, 180, 90); path->AddLine(left + offsetX, top, right - offsetX/2, top); return path;
}
Christian I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
Ok, that's what I suspected anyway... I have to deal with different vectors for the ARC, but that should not present any problem. Just wan't to make sure I don't reinvent the wheel to many times :-) Thanks for the reply and sample /Andreas