MCPcopy Create free account
hub / github.com/XMuli/ChineseChess / drawChessPieces

Method drawChessPieces

ChessBoard.cpp:330–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328}
329
330void ChessBoard::drawChessPieces(QPainter &painter, int id) //绘画单个具体的棋子
331{
332 if (isDead(id))
333 return;
334
335 QPointF c = center(id);
336 QRectF rect(c.x()-m_nR, c.y()-m_nR, m_nD, m_nD);
337
338 // 棋子阴影
339 painter.setPen(Qt::NoPen);
340 painter.setBrush(QColor(0, 0, 0, 40));
341 painter.drawEllipse(QPointF(c.x()+2, c.y()+2), m_nR, m_nR);
342
343 // 棋子底色:径向渐变
344 QRadialGradient pieceGrad(c, m_nR);
345 if (id < 16) { // 黑方
346 pieceGrad.setColorAt(0, QColor(80, 80, 80));
347 pieceGrad.setColorAt(0.8, QColor(45, 45, 45));
348 pieceGrad.setColorAt(1, QColor(30, 30, 30));
349 } else { // 红方
350 pieceGrad.setColorAt(0, QColor(210, 60, 60));
351 pieceGrad.setColorAt(0.8, QColor(160, 30, 30));
352 pieceGrad.setColorAt(1, QColor(120, 15, 15));
353 }
354 painter.setBrush(pieceGrad);
355
356 // 外圈边框
357 if (m_nSelectID == id)
358 painter.setPen(QPen(QColor(255, 215, 0), 3.0)); // 选中:金色发光
359 else
360 painter.setPen(QPen(QColor(180, 150, 100), 2.5)); // 默认:木色边框
361 painter.drawEllipse(c, m_nR, m_nR);
362
363 // 内圈装饰环
364 painter.setPen(QPen(QColor(200, 175, 130, 160), 1.2));
365 painter.setBrush(Qt::NoBrush);
366 painter.drawEllipse(c, m_nR * 0.82, m_nR * 0.82);
367
368 // 棋子文字
369 painter.setFont(QFont("FangSong", m_nR * 5 / 6, 2700));
370 if (id < 16)
371 painter.setPen(QColor(220, 220, 220)); // 黑方:浅灰文字
372 else
373 painter.setPen(QColor(255, 230, 200)); // 红方:暖白文字
374
375 painter.drawText(rect, m_ChessPieces[id].getnName(m_ChessPieces[id].m_bRed), QTextOption(Qt::AlignCenter));
376}
377
378void ChessBoard::drawStarMarks(QPainter &painter)
379{

Callers

nothing calls this directly

Calls 1

getnNameMethod · 0.80

Tested by

no test coverage detected