I am trying to figure out, as a beginner, how to change the drawing so that instead of squares, the game draws circles. Can figure out that using Ellipse in the code results in circle outlines, but the fill remains as square color shapes.
The drawing code from the tutorial is below. I would appreciate any help to substitute filled circles for filled squares.
// CSameGameView drawing
void CSameGameView::OnDraw(CDC* pDC)
{
// First get a pointer to the document
CSameGameDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc)
return;
// Save the current state of the device context
int nDCSave = pDC->SaveDC();
// Get the client rectangle
CRect rcClient;
GetClientRect(&rcClient);
// Get the background color of the board
COLORREF clr = pDoc->GetBoardSpace(-1, -1);
// Draw the background first
pDC->FillSolidRect(&rcClient, clr);
// Create the brush for drawing
CBrush br;
br.CreateStockObject(HOLLOW_BRUSH);
CBrush* pbrOld = pDC->SelectObject(&br);
// Draw the squares
for(int row = 0; row < pDoc->GetRows(); row++)
{
for(int col = 0; col < pDoc->GetColumns(); col++)
{
// Get the color for this board space
clr = pDoc->GetBoardSpace(row, col);
// Calculate the size and position of this space
CRect rcBlock;
rcBlock.top = row * pDoc->GetHeight();
rcBlock.left = col * pDoc->GetWidth();
rcBlock.right = rcBlock.left + pDoc->GetWidth();
rcBlock.bottom = rcBlock.top + pDoc->GetHeight();
// Fill in the block with the correct color
pDC->FillSolidRect(&rcBlock, clr);// How to change the fill color and create circles, not squares?
// Draw the block outline
pDC->Rectangle(&rcBlock); //change to Ellipse?
}
}
// Restore the device context settings
pDC->RestoreDC(nDCSave);
br.DeleteObject();
}
I will check the MSDN code item and see if I can figure out how to change the code to draw filled circles instead of squares. (I tried simply omitting line 36 and got a black debug screen. So, I must be doing something wrong as a beginner.)
It seems that line 36 is simply clearing the background. So leave it like it is.
If you want to draw a filled ellipse you need to change of course line 38 and line 20/21.
Instead of HOLLOW_BRUSH you may change it to a solid brush with the color you want.
Thank you again. I don't think that this can be changed easily. The way this is working is to color the background squares and then draw an outline of each square (HOLLOW_BRUSH) above.
So, I think that the code would have to be more completely re-written.