Question: #include DrawingPanel.h #include wx/graphics.h #include wx/dcbuffer.h #include MainWindow.h wxBEGIN_EVENT_TABLE(DrawingPanel, wxPanel) EVT_PAINT(DrawingPanel::OnPaint) wxEND_EVENT_TABLE() DrawingPanel::DrawingPanel(wxWindow* parent) : wxPanel(parent) { this->SetBackgroundStyle(wxBG_STYLE_PAINT); this->Bind(wxEVT_PAINT, &DrawingPanel::OnPaint, this); this->Bind(wxEVT_LEFT_UP, &DrawingPanel::OnMouseUp, this); }
#include "DrawingPanel.h" #include "wx/graphics.h" #include "wx/dcbuffer.h" #include "MainWindow.h" wxBEGIN_EVENT_TABLE(DrawingPanel, wxPanel) EVT_PAINT(DrawingPanel::OnPaint) wxEND_EVENT_TABLE() DrawingPanel::DrawingPanel(wxWindow* parent) : wxPanel(parent) { this->SetBackgroundStyle(wxBG_STYLE_PAINT); this->Bind(wxEVT_PAINT, &DrawingPanel::OnPaint, this); this->Bind(wxEVT_LEFT_UP, &DrawingPanel::OnMouseUp, this); } DrawingPanel::~DrawingPanel() { } void DrawingPanel::SetGridSize(int size) { gridSize = size; Refresh(); } void DrawingPanel::SetSize(const wxSize& size) { wxPanel::SetSize(size); Refresh(); } void DrawingPanel::OnMouseUp(wxMouseEvent& event) { int mouseX = event.GetX(); int mouseY = event.GetY(); int panelWidth = GetSize().GetWidth(); int panelHeight = GetSize().GetHeight(); int cellWidth = panelWidth / gridSize; int cellHeight = panelHeight / gridSize; int col = mouseX / cellWidth; int row = mouseY / cellHeight; if (row < gridSize && col < gridSize) { MainWindow->ToggleCellState(row, col); wxLogMessage("Toggled cell at row %d, column %d", row, col); } Refresh(); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
