QTfrontend/ui/widget/bgwidget.cpp
changeset 6241 e2c7771162ae
parent 6060 fdfc01419815
child 6242 27297c421bbc
equal deleted inserted replaced
6240:5d8e478916b4 6241:e2c7771162ae
    34 {
    34 {
    35     fX += fXMov;
    35     fX += fXMov;
    36     fY += fYMov;
    36     fY += fYMov;
    37     iAngle += 4;
    37     iAngle += 4;
    38     if (iAngle >= 360) iAngle = 0;
    38     if (iAngle >= 360) iAngle = 0;
    39     if (fY > wParent->height()) reset();
    39     if ((fX - fXMov) > wParent->width()) reset();
       
    40     else if ((fY - fYMov) > wParent->height()) reset();
    40 }
    41 }
    41 
    42 
    42 void SpritePosition::reset()
    43 void SpritePosition::reset()
    43 {
    44 {
    44     fY = -1 * iSpriteHeight;
    45     fY = -1 * iSpriteHeight;
    71 
    72 
    72     setAutoFillBackground(false);
    73     setAutoFillBackground(false);
    73 
    74 
    74     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height());
    75     for (int i = 0; i < SPRITE_MAX; i++) spritePositions[i] = new SpritePosition(this, sprite.height());
    75 
    76 
    76     for (int i = 0; i < 360; i++)
    77     for (int i = 0; i < 90; i++)
    77     {
    78     {
    78         rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
    79         rotatedSprites[i] = new QImage(sprite.width(), sprite.height(), QImage::Format_ARGB32);
    79         rotatedSprites[i]->fill(0);
    80         rotatedSprites[i]->fill(0);
    80 
    81 
    81         QPoint translate(sprite.width()/2, sprite.height()/2);
    82         QPoint translate(sprite.width()/2, sprite.height()/2);
    83         QPainter p;
    84         QPainter p;
    84         p.begin(rotatedSprites[i]);
    85         p.begin(rotatedSprites[i]);
    85     //  p.setRenderHint(QPainter::Antialiasing);
    86     //  p.setRenderHint(QPainter::Antialiasing);
    86         p.setRenderHint(QPainter::SmoothPixmapTransform);
    87         p.setRenderHint(QPainter::SmoothPixmapTransform);
    87         p.translate(translate.x(), translate.y());
    88         p.translate(translate.x(), translate.y());
    88         p.rotate(i);
    89         p.rotate(4 * i);
    89         p.translate(-1*translate.x(), -1*translate.y());
    90         p.translate(-1*translate.x(), -1*translate.y());
    90         p.drawImage(0, 0, sprite);
    91         p.drawImage(0, 0, sprite);
    91     }
    92     }
    92 
    93 
    93     timerAnimation = new QTimer();
    94     timerAnimation = new QTimer();
    96 }
    97 }
    97 
    98 
    98 BGWidget::~BGWidget()
    99 BGWidget::~BGWidget()
    99 {
   100 {
   100     for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i];
   101     for (int i = 0; i < SPRITE_MAX; i++) delete spritePositions[i];
   101     for (int i = 0; i < 360; i++) delete rotatedSprites[i];
   102     for (int i = 0; i < 90; i++) delete rotatedSprites[i];
   102     delete timerAnimation;
   103     delete timerAnimation;
   103 }
   104 }
   104 
   105 
   105 void BGWidget::paintEvent(QPaintEvent *event)
   106 void BGWidget::paintEvent(QPaintEvent *event)
   106 {
   107 {
   107     Q_UNUSED(event);
   108     Q_UNUSED(event);
   108 
   109 
   109     QPainter p;
   110     QPainter p;
       
   111 
   110     p.begin(this);
   112     p.begin(this);
   111     //p.setRenderHint(QPainter::Antialiasing);
   113 
   112     for (int i = 0; i < SPRITE_MAX; i++)
   114     for (int i = 0; i < SPRITE_MAX; i++)
   113     {
   115     {
   114         QPoint point = spritePositions[i]->pos();
   116         QPoint point = spritePositions[i]->pos();
   115         p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()]);
   117         p.drawImage(point.x(), point.y(), *rotatedSprites[spritePositions[i]->getAngle()/4]);
   116     }
   118     }
       
   119 
   117     p.end();
   120     p.end();
   118 }
   121 }
   119 
   122 
   120 void BGWidget::animate()
   123 void BGWidget::animate()
   121 {
   124 {
   122     for (int i = 0; i < SPRITE_MAX; i++)
   125     for (int i = 0; i < SPRITE_MAX; i++)
   123     {
   126     {
   124         // bottom edge of star *seems* clipped, but in fact, if I switch to just plain old repaint()/update() it is still clipped - artifact of transform?  As for 5, is arbitrary number. 4 was noticeably clipping, 5 seemed same as update() - I assume extra room is due to rotation and value really should be calculated proportional to width/height
   127         QPoint oldPos = spritePositions[i]->pos();
   125         update(spritePositions[i]->pos().x(),spritePositions[i]->pos().y(), sprite.width()+5, sprite.height()+5);
       
   126         spritePositions[i]->move();
   128         spritePositions[i]->move();
       
   129         QPoint newPos = spritePositions[i]->pos();
       
   130 
       
   131         int xdiff = newPos.x() - oldPos.x();
       
   132         int ydiff = newPos.y() - oldPos.y();
       
   133         update(oldPos.x(), oldPos.y(), xdiff+sprite.width(), ydiff+sprite.height());
   127     }
   134     }
   128 }
   135 }
   129 
   136 
   130 void BGWidget::startAnimation()
   137 void BGWidget::startAnimation()
   131 {
   138 {