|
-
February 24th, 2010, 06:48 AM
#1
Coordinate problem (an image attached)
I want to reuse DrawPie function to draw 4 same pies, but it was unexpected. I don't understand what have been happening.
I divide the client area by 4, then pass each rect to DrawPie.
application image: http://i240.photobucket.com/albums/f...214/post-1.jpg
Code:
void CMainWindow::DrawPie(CDC *pDC, CRect &rect)
{
// prepare to draw pie
CBrush brush;
brush.CreateHatchBrush(HS_BDIAGONAL, RGB(255, 0, 0));
CBrush *pOldBrush = pDC->SelectObject(&brush);
CPoint startPoint = rect.BottomRight();
CPoint endPoint = rect.BottomRight();
startPoint.y /= 2;
endPoint.x /= 2;
// draw pie
pDC->Pie(&rect, startPoint, endPoint);
pDC->SelectObject(pOldBrush);
}
void CMainWindow::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
int leftCenter = rect.left / 2;
int topCenter = rect.top / 2;
int rightCenter = rect.right / 2;
int bottomCenter = rect.bottom / 2;
COLORREF clrColors[] = {RGB(100, 0, 0), RGB(0, 100, 0), RGB(0, 0, 100), RGB(100, 0, 100)};
int widthIncrement = rect.right / 2;
int heightIncrement = rect.bottom / 2;
int k = 0;
for(int i = 0; i < rect.bottom; i += heightIncrement)
for(int j = 0; j < rect.right; j += widthIncrement)
{
CPoint leftTop(j, i);
CPoint rightBottom(j + widthIncrement, i + heightIncrement);
CRect rect;
rect.TopLeft() = leftTop;
rect.BottomRight() = rightBottom;
CBrush brush;
brush.CreateSolidBrush(clrColors[k++]);
CBrush *pOldBrush = dc.SelectObject(&brush);
dc.Rectangle(rect);
DrawPie(&dc, rect);
dc.SelectObject(pOldBrush);
}
}
Thank you
Last edited by Emerald214; February 24th, 2010 at 06:56 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|