Question: using void DrawingPanel::OnPaint(wxPaintEvent& event) { wxAutoBufferedPaintDC dc(this); dc.Clear(); wxGraphicsContext* context = wxGraphicsContext::Create(dc); if (!context) { return; } wxSize panelSize = GetSize(); int panelWidth = panelSize.GetWidth();
using void DrawingPanel::OnPaint(wxPaintEvent& event) { wxAutoBufferedPaintDC dc(this); dc.Clear(); wxGraphicsContext* context = wxGraphicsContext::Create(dc); if (!context) { return; } wxSize panelSize = GetSize(); int panelWidth = panelSize.GetWidth(); int panelHeight = panelSize.GetHeight(); int cellWidth = panelWidth / Grid_Size; int cellHeight = panelHeight / Grid_Size; { context->SetPen(*wxBLACK_PEN); context->SetBrush(*wxWHITE_BRUSH); for (int row = 0; row < Grid_Size; ++row) { for (int col = 0; col < Grid_Size; ++col) { int x = col * cellWidth; int y = row * cellHeight; context->DrawRectangle(x, y, cellWidth, cellHeight); } } delete context; } } void MainWindow::InitializeGrid() { //resizes outer vector to grid size gameBoard.resize(gridSize); //resizes inner vectors to grid size and sets to 'false' for (int i = 0; i < gridSize; ++i) { gameBoard[i].resize(gridSize, false); } //passes SetGridSize to m_drawingPanel m_drawingPanel->SetGridSize(gridSize); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
