当前位置: 首页>>代码示例>>C++>>正文


C++ Stone::setPixmap方法代码示例

本文整理汇总了C++中Stone::setPixmap方法的典型用法代码示例。如果您正苦于以下问题:C++ Stone::setPixmap方法的具体用法?C++ Stone::setPixmap怎么用?C++ Stone::setPixmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stone的用法示例。


在下文中一共展示了Stone::setPixmap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: drawStones

void BoardView::drawStones()
{
    static QPixmap*      bstone = new QPixmap(":/images/blackstone.gif");
    static QPixmap*      wstone = new QPixmap(":/images/wwstone.gif");
    if (this->_board != 0)
    {
        Coord* lastCoord = 0;
        QBrush lastBrush;
        for (unsigned int i = 0; i < this->_board->getSize(); i++)
        {
            for (unsigned int j = 0; j < this->_board->getSize(); j++)
            {
                QBrush brush;
                if (BoardCell::matchMask(*this->_board->getCell(i, j), WHITE))
                    brush = QBrush(Qt::white);
                else if (BoardCell::matchMask(*this->_board->getCell(i, j), BLACK))
                    brush = QBrush(Qt::black);
                if (!BoardCell::isEmpty(*this->_board->getCell(i, j)))
                {
                    Coord c = this->getCoord(i, j);
                    if (this->_board->getLastPlayed())
                    {
                        Coord lastCell = this->getCoord(this->_board->getLastPlayed()->x, this->_board->getLastPlayed()->y);
                        if (c.x == lastCell.x && c.y == lastCell.y)
                        {
                            lastCoord = new Coord(c.x, c.y);
                            lastBrush = brush;
                        }
                    }
                    if (!lastCoord || lastCoord->x != c.x || lastCoord->y != c.y)
                    {
                        QGraphicsPixmapItem* item;
                        double               width;
                        if (brush.color() == Qt::black)
                        {
                            item = this->_scene.addPixmap(*bstone);
                            width = bstone->width();
                        }
                        else
                        {
                            item = this->_scene.addPixmap(*wstone);
                            width = wstone->width();
                        }
                        item->setPos(c.x, c.y);
                        item->setScale(this->_lineSpacing/width);
                    }
                }
            }
        }
        if (lastCoord)
        {
            Stone* stone = new Stone();
            double width;

            if (lastBrush.color() == Qt::black)
            {
                stone->setPixmap(*bstone);
                width = bstone->width();
            }
            else
            {
                stone->setPixmap(*wstone);
                width = wstone->width();
            }
            stone->initScaleAndOffset(lastCoord->x, lastCoord->y,
                                      this->_lineSpacing/width, this->_lineSpacing/2);
            this->_scene.addItem(stone);
            QPropertyAnimation* animation = new QPropertyAnimation(stone, "scale");
            animation->setDuration(200);
            animation->setStartValue(0.0);
            animation->setEndValue(this->_lineSpacing/width);
            animation->setEasingCurve(QEasingCurve::OutBounce);
            animation->start();
            delete lastCoord;
        }
    }
    else
        std::cout << "drawStones(): Warning: No board set in BoardView" << std::endl;
}
开发者ID:rouffj,项目名称:gomoku,代码行数:79,代码来源:BoardView.cpp


注:本文中的Stone::setPixmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。