Код: Выделить всё
MoaraClient::MoaraClient(QWidget* parent)
: QMainWindow(parent)
{
ui.setupUi(this);
m_game = std::make_shared();
Init(EBoardType::Normal, EBoardSize::Normal, m_game->GetAllNodes());
ui.baseLayout->addWidget(m_board);
m_board->update();
}
Код: Выделить всё
void NormalBoard::paintEvent(QPaintEvent* event)
{
std::ranges::for_each(m_buttons, [](const auto& button) {
button->update();
});
}
Код: Выделить всё
void NodeButton::paintEvent(QPaintEvent* event) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPoint center(m_position.x, m_position.y);
painter.setBrush(Qt::white);
painter.drawEllipse(center, 20, 20);
if (m_type == EPieceType::Black) {
QRect targetRect(center.x() - 10, center.y() - 10, 20, 20);
painter.drawImage(targetRect, m_imageBlack);
}
else if (m_type == EPieceType::White) {
QRect targetRect(center.x() - 10, center.y() - 10, 20, 20);
painter.drawImage(targetRect, m_imageWhite);
}
}
Код: Выделить всё
NormalBoard::NormalBoard(const Nodes& nodes)
{
for (uint8_t index = 0; index < nodes.size(); index++)
{
NodeButton* nodeButton = new NodeButton(this);
nodeButton->SetNodeIndex(index);
nodeButton->SetType(nodes[index]->GetPieceType());
m_buttons.push_back(nodeButton);
}
auto positions = LoadButtonsPositions(NORMAL_BOARD_POSITIONS);
if (positions.size() != m_buttons.size())
throw std::exception("Number of positions doesn't match number of buttons");
for (size_t index = 0; index < positions.size(); index++)
{
m_buttons[index]->SetPosition(positions[index]);
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... ng-painted